1 /*
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
24 #include <binder/Parcel.h>
25 #include <binder/IMemory.h>
26 #include <binder/IPCThreadState.h>
27 #include <binder/IServiceManager.h>
28
29 #include <ui/Point.h>
30 #include <ui/Rect.h>
31
32 #include <gui/ISurface.h>
33 #include <gui/ISurfaceComposerClient.h>
34 #include <private/gui/LayerState.h>
35
36 // ---------------------------------------------------------------------------
37
38 namespace android {
39
40 enum {
41 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
42 DESTROY_SURFACE
43 };
44
45 class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
46 {
47 public:
BpSurfaceComposerClient(const sp<IBinder> & impl)48 BpSurfaceComposerClient(const sp<IBinder>& impl)
49 : BpInterface<ISurfaceComposerClient>(impl)
50 {
51 }
52
createSurface(surface_data_t * params,const String8 & name,uint32_t w,uint32_t h,PixelFormat format,uint32_t flags)53 virtual sp<ISurface> createSurface( surface_data_t* params,
54 const String8& name,
55 uint32_t w,
56 uint32_t h,
57 PixelFormat format,
58 uint32_t flags)
59 {
60 Parcel data, reply;
61 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
62 data.writeString8(name);
63 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 }
71
destroySurface(SurfaceID sid)72 virtual status_t destroySurface(SurfaceID sid)
73 {
74 Parcel data, reply;
75 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
76 data.writeInt32(sid);
77 remote()->transact(DESTROY_SURFACE, data, &reply);
78 return reply.readInt32();
79 }
80 };
81
82 IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
83
84 // ----------------------------------------------------------------------
85
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)86 status_t BnSurfaceComposerClient::onTransact(
87 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
88 {
89 switch(code) {
90 case CREATE_SURFACE: {
91 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
92 surface_data_t params;
93 String8 name = data.readString8();
94 uint32_t w = data.readInt32();
95 uint32_t h = data.readInt32();
96 PixelFormat format = data.readInt32();
97 uint32_t flags = data.readInt32();
98 sp<ISurface> s = createSurface(¶ms, name, w, h,
99 format, flags);
100 params.writeToParcel(reply);
101 reply->writeStrongBinder(s->asBinder());
102 return NO_ERROR;
103 } break;
104 case DESTROY_SURFACE: {
105 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
106 reply->writeInt32( destroySurface( data.readInt32() ) );
107 return NO_ERROR;
108 } break;
109 default:
110 return BBinder::onTransact(code, data, reply, flags);
111 }
112 }
113
114 // ----------------------------------------------------------------------
115
readFromParcel(const Parcel & parcel)116 status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel)
117 {
118 token = parcel.readInt32();
119 identity = parcel.readInt32();
120 return NO_ERROR;
121 }
122
writeToParcel(Parcel * parcel) const123 status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const
124 {
125 parcel->writeInt32(token);
126 parcel->writeInt32(identity);
127 return NO_ERROR;
128 }
129
130 }; // namespace android
131