OSDN Git Service

101292d945c7ede65c51d761547caa8c636ce3be
[android-x86/frameworks-native.git] / libs / gui / ISurfaceComposerClient.cpp
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:
48     BpSurfaceComposerClient(const sp<IBinder>& impl)
49         : BpInterface<ISurfaceComposerClient>(impl)
50     {
51     }
52
53     virtual sp<ISurface> createSurface( const String8& name,
54                                         uint32_t w,
55                                         uint32_t h,
56                                         PixelFormat format,
57                                         uint32_t flags)
58     {
59         Parcel data, reply;
60         data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
61         data.writeString8(name);
62         data.writeInt32(w);
63         data.writeInt32(h);
64         data.writeInt32(format);
65         data.writeInt32(flags);
66         remote()->transact(CREATE_SURFACE, data, &reply);
67         return interface_cast<ISurface>(reply.readStrongBinder());
68     }
69
70     virtual status_t destroySurface(const sp<IBinder>& handle)
71     {
72         Parcel data, reply;
73         data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
74         data.writeStrongBinder(handle);
75         remote()->transact(DESTROY_SURFACE, data, &reply);
76         return reply.readInt32();
77     }
78 };
79
80 IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
81
82 // ----------------------------------------------------------------------
83
84 status_t BnSurfaceComposerClient::onTransact(
85     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
86 {
87      switch(code) {
88         case CREATE_SURFACE: {
89             CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
90             String8 name = data.readString8();
91             uint32_t w = data.readInt32();
92             uint32_t h = data.readInt32();
93             PixelFormat format = data.readInt32();
94             uint32_t flags = data.readInt32();
95             sp<ISurface> s = createSurface(name, w, h, format, flags);
96             reply->writeStrongBinder(s->asBinder());
97             return NO_ERROR;
98         } break;
99         case DESTROY_SURFACE: {
100             CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
101             reply->writeInt32( destroySurface( data.readStrongBinder() ) );
102             return NO_ERROR;
103         } break;
104         default:
105             return BBinder::onTransact(code, data, reply, flags);
106     }
107 }
108
109 }; // namespace android