blob: 8d8339258860f25b43767fcba7b9a1d87efee9fe [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 Agopian9cce3252010-02-09 17:46:37 -080032#include <surfaceflinger/ISurface.h>
Mathias Agopian7e27f052010-05-28 14:22:23 -070033#include <surfaceflinger/ISurfaceComposerClient.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080034#include <private/surfaceflinger/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36// ---------------------------------------------------------------------------
37
Mathias Agopiana1ecca92009-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 Projectedbf3b62009-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 Agopiana67932f2011-04-20 14:20:59 -070053 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054 DESTROY_SURFACE,
55 SET_STATE
56};
57
Mathias Agopian7e27f052010-05-28 14:22:23 -070058class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059{
60public:
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 BpSurfaceComposerClient(const sp<IBinder>& impl)
62 : BpInterface<ISurfaceComposerClient>(impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 {
64 }
65
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 virtual sp<ISurface> createSurface( surface_data_t* params,
Mathias Agopian285dbde2010-03-01 16:09:43 -080067 const String8& name,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 DisplayID display,
69 uint32_t w,
70 uint32_t h,
71 PixelFormat format,
72 uint32_t flags)
73 {
74 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070075 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080076 data.writeString8(name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 data.writeInt32(display);
78 data.writeInt32(w);
79 data.writeInt32(h);
80 data.writeInt32(format);
81 data.writeInt32(flags);
82 remote()->transact(CREATE_SURFACE, data, &reply);
83 params->readFromParcel(reply);
84 return interface_cast<ISurface>(reply.readStrongBinder());
85 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070086
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080087 virtual status_t destroySurface(SurfaceID sid)
88 {
89 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070090 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 data.writeInt32(sid);
92 remote()->transact(DESTROY_SURFACE, data, &reply);
93 return reply.readInt32();
94 }
95
96 virtual status_t setState(int32_t count, const layer_state_t* states)
97 {
98 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070099 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100 data.writeInt32(count);
101 for (int i=0 ; i<count ; i++)
102 states[i].write(data);
103 remote()->transact(SET_STATE, data, &reply);
104 return reply.readInt32();
105 }
106};
107
Mathias Agopian7e27f052010-05-28 14:22:23 -0700108IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109
110// ----------------------------------------------------------------------
111
Mathias Agopian7e27f052010-05-28 14:22:23 -0700112status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
114{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115 switch(code) {
116 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700117 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 surface_data_t params;
Mathias Agopian285dbde2010-03-01 16:09:43 -0800119 String8 name = data.readString8();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120 DisplayID display = data.readInt32();
121 uint32_t w = data.readInt32();
122 uint32_t h = data.readInt32();
123 PixelFormat format = data.readInt32();
124 uint32_t flags = data.readInt32();
Mathias Agopian0ef4e152011-04-20 14:19:32 -0700125 sp<ISurface> s = createSurface(&params, name, display, w, h,
Mathias Agopian285dbde2010-03-01 16:09:43 -0800126 format, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127 params.writeToParcel(reply);
128 reply->writeStrongBinder(s->asBinder());
129 return NO_ERROR;
130 } break;
131 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700132 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 reply->writeInt32( destroySurface( data.readInt32() ) );
134 return NO_ERROR;
135 } break;
136 case SET_STATE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700137 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138 int32_t count = data.readInt32();
139 layer_state_t* states = new layer_state_t[count];
140 for (int i=0 ; i<count ; i++)
141 states[i].read(data);
142 status_t err = setState(count, states);
143 delete [] states;
144 reply->writeInt32(err);
145 return NO_ERROR;
146 } break;
147 default:
148 return BBinder::onTransact(code, data, reply, flags);
149 }
150}
151
152// ----------------------------------------------------------------------
153
Mathias Agopian7e27f052010-05-28 14:22:23 -0700154status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155{
Mathias Agopian1c97d2e2009-08-19 17:46:26 -0700156 token = parcel.readInt32();
157 identity = parcel.readInt32();
158 width = parcel.readInt32();
159 height = parcel.readInt32();
160 format = parcel.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 return NO_ERROR;
162}
163
Mathias Agopian7e27f052010-05-28 14:22:23 -0700164status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165{
166 parcel->writeInt32(token);
167 parcel->writeInt32(identity);
Mathias Agopian1c97d2e2009-08-19 17:46:26 -0700168 parcel->writeInt32(width);
169 parcel->writeInt32(height);
170 parcel->writeInt32(format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171 return NO_ERROR;
172}
173
174}; // namespace android