blob: 8f7bc052cd72242923562e6ceeff60d6783d0e80 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// tag as surfaceflinger
18#define LOG_TAG "SurfaceFlinger"
19
20#include <stdio.h>
21#include <stdint.h>
22#include <sys/types.h>
23
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/Parcel.h>
25#include <binder/IMemory.h>
26#include <binder/IPCThreadState.h>
27#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <ui/Point.h>
30#include <ui/Rect.h>
31
Mathias Agopian90ac7992012-02-25 18:48:35 -080032#include <gui/ISurface.h>
33#include <gui/ISurfaceComposerClient.h>
34#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36// ---------------------------------------------------------------------------
37
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038namespace android {
39
40enum {
Mathias Agopiana67932f2011-04-20 14:20:59 -070041 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
Mathias Agopian698c0872011-06-28 19:09:31 -070042 DESTROY_SURFACE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043};
44
Mathias Agopian7e27f052010-05-28 14:22:23 -070045class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046{
47public:
Mathias Agopian7e27f052010-05-28 14:22:23 -070048 BpSurfaceComposerClient(const sp<IBinder>& impl)
49 : BpInterface<ISurfaceComposerClient>(impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 {
51 }
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 virtual sp<ISurface> createSurface( surface_data_t* params,
Mathias Agopian285dbde2010-03-01 16:09:43 -080054 const String8& name,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055 uint32_t w,
56 uint32_t h,
57 PixelFormat format,
58 uint32_t flags)
59 {
60 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080062 data.writeString8(name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 data.writeInt32(w);
64 data.writeInt32(h);
65 data.writeInt32(format);
66 data.writeInt32(flags);
67 remote()->transact(CREATE_SURFACE, data, &reply);
68 params->readFromParcel(reply);
69 return interface_cast<ISurface>(reply.readStrongBinder());
70 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070071
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080072 virtual status_t destroySurface(SurfaceID sid)
73 {
74 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070075 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 data.writeInt32(sid);
77 remote()->transact(DESTROY_SURFACE, data, &reply);
78 return reply.readInt32();
79 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080};
81
Mathias Agopian7e27f052010-05-28 14:22:23 -070082IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083
84// ----------------------------------------------------------------------
85
Mathias Agopian7e27f052010-05-28 14:22:23 -070086status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080087 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
88{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 switch(code) {
90 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -070091 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092 surface_data_t params;
Mathias Agopian285dbde2010-03-01 16:09:43 -080093 String8 name = data.readString8();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 uint32_t w = data.readInt32();
95 uint32_t h = data.readInt32();
96 PixelFormat format = data.readInt32();
97 uint32_t flags = data.readInt32();
Jeff Brown9d4e3d22012-08-24 20:00:51 -070098 sp<ISurface> s = createSurface(&params, name, w, h,
Mathias Agopian285dbde2010-03-01 16:09:43 -080099 format, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100 params.writeToParcel(reply);
101 reply->writeStrongBinder(s->asBinder());
102 return NO_ERROR;
103 } break;
104 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700105 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 reply->writeInt32( destroySurface( data.readInt32() ) );
107 return NO_ERROR;
108 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 default:
110 return BBinder::onTransact(code, data, reply, flags);
111 }
112}
113
114// ----------------------------------------------------------------------
115
Mathias Agopian7e27f052010-05-28 14:22:23 -0700116status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117{
Mathias Agopian1c97d2e2009-08-19 17:46:26 -0700118 token = parcel.readInt32();
119 identity = parcel.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120 return NO_ERROR;
121}
122
Mathias Agopian7e27f052010-05-28 14:22:23 -0700123status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124{
125 parcel->writeInt32(token);
126 parcel->writeInt32(identity);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127 return NO_ERROR;
128}
129
130}; // namespace android