blob: ace16aaae47caeabcbf7859d80008dc2e7398246 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Agopian07952722009-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 Project9066cfe2009-03-03 19:31:44 -080028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029#include <ui/Point.h>
30#include <ui/Rect.h>
31
Mathias Agopian000479f2010-02-09 17:46:37 -080032#include <surfaceflinger/ISurface.h>
Mathias Agopian770492c2010-05-28 14:22:23 -070033#include <surfaceflinger/ISurfaceComposerClient.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080034#include <private/surfaceflinger/LayerState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36// ---------------------------------------------------------------------------
37
Mathias Agopian627e7b52009-05-21 19:21:59 -070038/* 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
46#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
47
48// ---------------------------------------------------------------------------
49
50namespace android {
51
52enum {
Mathias Agopian7bb843c2011-04-20 14:20:59 -070053 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
Mathias Agopian439863f2011-06-28 19:09:31 -070054 DESTROY_SURFACE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055};
56
Mathias Agopian770492c2010-05-28 14:22:23 -070057class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058{
59public:
Mathias Agopian770492c2010-05-28 14:22:23 -070060 BpSurfaceComposerClient(const sp<IBinder>& impl)
61 : BpInterface<ISurfaceComposerClient>(impl)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 {
63 }
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 virtual sp<ISurface> createSurface( surface_data_t* params,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080066 const String8& name,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 DisplayID display,
68 uint32_t w,
69 uint32_t h,
70 PixelFormat format,
71 uint32_t flags)
72 {
73 Parcel data, reply;
Mathias Agopian770492c2010-05-28 14:22:23 -070074 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian5d26c1e2010-03-01 16:09:43 -080075 data.writeString8(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 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 }
Mathias Agopian770492c2010-05-28 14:22:23 -070085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 virtual status_t destroySurface(SurfaceID sid)
87 {
88 Parcel data, reply;
Mathias Agopian770492c2010-05-28 14:22:23 -070089 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 data.writeInt32(sid);
91 remote()->transact(DESTROY_SURFACE, data, &reply);
92 return reply.readInt32();
93 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094};
95
Mathias Agopian770492c2010-05-28 14:22:23 -070096IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097
98// ----------------------------------------------------------------------
99
Mathias Agopian770492c2010-05-28 14:22:23 -0700100status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
102{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 switch(code) {
104 case CREATE_SURFACE: {
Mathias Agopian770492c2010-05-28 14:22:23 -0700105 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 surface_data_t params;
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800107 String8 name = data.readString8();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 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();
Mathias Agopian9638e5c2011-04-20 14:19:32 -0700113 sp<ISurface> s = createSurface(&params, name, display, w, h,
Mathias Agopian5d26c1e2010-03-01 16:09:43 -0800114 format, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 params.writeToParcel(reply);
116 reply->writeStrongBinder(s->asBinder());
117 return NO_ERROR;
118 } break;
119 case DESTROY_SURFACE: {
Mathias Agopian770492c2010-05-28 14:22:23 -0700120 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 reply->writeInt32( destroySurface( data.readInt32() ) );
122 return NO_ERROR;
123 } break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 default:
125 return BBinder::onTransact(code, data, reply, flags);
126 }
127}
128
129// ----------------------------------------------------------------------
130
Mathias Agopian770492c2010-05-28 14:22:23 -0700131status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132{
Mathias Agopian18b6b492009-08-19 17:46:26 -0700133 token = parcel.readInt32();
134 identity = parcel.readInt32();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 return NO_ERROR;
136}
137
Mathias Agopian770492c2010-05-28 14:22:23 -0700138status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139{
140 parcel->writeInt32(token);
141 parcel->writeInt32(identity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 return NO_ERROR;
143}
144
145}; // namespace android