ISurfaceComposerClient.cpp revision 698c0873cf2e07bdc7fd1e72169aee2a19fa40d7
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 <surfaceflinger/ISurface.h>
33#include <surfaceflinger/ISurfaceComposerClient.h>
34#include <private/surfaceflinger/LayerState.h>
35
36// ---------------------------------------------------------------------------
37
38/* ideally AID_GRAPHICS would be in a semi-public header
39 * or there would be a way to map a user/group name to its id
40 */
41#ifndef AID_GRAPHICS
42#define AID_GRAPHICS 1003
43#endif
44
45#define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
46#define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
47
48// ---------------------------------------------------------------------------
49
50namespace android {
51
52enum {
53    CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
54    DESTROY_SURFACE
55};
56
57class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
58{
59public:
60    BpSurfaceComposerClient(const sp<IBinder>& impl)
61        : BpInterface<ISurfaceComposerClient>(impl)
62    {
63    }
64
65    virtual sp<ISurface> createSurface( surface_data_t* params,
66                                        const String8& name,
67                                        DisplayID display,
68                                        uint32_t w,
69                                        uint32_t h,
70                                        PixelFormat format,
71                                        uint32_t flags)
72    {
73        Parcel data, reply;
74        data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
75        data.writeString8(name);
76        data.writeInt32(display);
77        data.writeInt32(w);
78        data.writeInt32(h);
79        data.writeInt32(format);
80        data.writeInt32(flags);
81        remote()->transact(CREATE_SURFACE, data, &reply);
82        params->readFromParcel(reply);
83        return interface_cast<ISurface>(reply.readStrongBinder());
84    }
85
86    virtual status_t destroySurface(SurfaceID sid)
87    {
88        Parcel data, reply;
89        data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
90        data.writeInt32(sid);
91        remote()->transact(DESTROY_SURFACE, data, &reply);
92        return reply.readInt32();
93    }
94};
95
96IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
97
98// ----------------------------------------------------------------------
99
100status_t BnSurfaceComposerClient::onTransact(
101    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
102{
103     switch(code) {
104        case CREATE_SURFACE: {
105            CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
106            surface_data_t params;
107            String8 name = data.readString8();
108            DisplayID display = data.readInt32();
109            uint32_t w = data.readInt32();
110            uint32_t h = data.readInt32();
111            PixelFormat format = data.readInt32();
112            uint32_t flags = data.readInt32();
113            sp<ISurface> s = createSurface(&params, name, display, w, h,
114                    format, flags);
115            params.writeToParcel(reply);
116            reply->writeStrongBinder(s->asBinder());
117            return NO_ERROR;
118        } break;
119        case DESTROY_SURFACE: {
120            CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
121            reply->writeInt32( destroySurface( data.readInt32() ) );
122            return NO_ERROR;
123        } break;
124        default:
125            return BBinder::onTransact(code, data, reply, flags);
126    }
127}
128
129// ----------------------------------------------------------------------
130
131status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel)
132{
133    token    = parcel.readInt32();
134    identity = parcel.readInt32();
135    width    = parcel.readInt32();
136    height   = parcel.readInt32();
137    format   = parcel.readInt32();
138    return NO_ERROR;
139}
140
141status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const
142{
143    parcel->writeInt32(token);
144    parcel->writeInt32(identity);
145    parcel->writeInt32(width);
146    parcel->writeInt32(height);
147    parcel->writeInt32(format);
148    return NO_ERROR;
149}
150
151}; // namespace android
152