blob: 1adc134e4044a9adac659777177b127c87c1c2a0 [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 Agopian4d9b8222013-03-12 17:11:48 -070032#include <gui/IGraphicBufferProducer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080033#include <gui/ISurfaceComposerClient.h>
34#include <private/gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36// ---------------------------------------------------------------------------
37
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038namespace android {
39
40enum {
Mathias Agopiana67932f2011-04-20 14:20:59 -070041 CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION,
Mathias Agopian698c0872011-06-28 19:09:31 -070042 DESTROY_SURFACE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043};
44
Mathias Agopian7e27f052010-05-28 14:22:23 -070045class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046{
47public:
Mathias Agopian7e27f052010-05-28 14:22:23 -070048 BpSurfaceComposerClient(const sp<IBinder>& impl)
Mathias Agopian4d9b8222013-03-12 17:11:48 -070049 : BpInterface<ISurfaceComposerClient>(impl) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 }
51
Mathias Agopian4d9b8222013-03-12 17:11:48 -070052 virtual status_t createSurface(const String8& name, uint32_t w,
53 uint32_t h, PixelFormat format, uint32_t flags,
54 sp<IBinder>* handle,
55 sp<IGraphicBufferProducer>* gbp) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070057 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080058 data.writeString8(name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 data.writeInt32(w);
60 data.writeInt32(h);
61 data.writeInt32(format);
62 data.writeInt32(flags);
63 remote()->transact(CREATE_SURFACE, data, &reply);
Mathias Agopian4d9b8222013-03-12 17:11:48 -070064 *handle = reply.readStrongBinder();
65 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
66 return reply.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070068
Mathias Agopian4d9b8222013-03-12 17:11:48 -070069 virtual status_t destroySurface(const sp<IBinder>& handle) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070071 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopianac9fa422013-02-11 16:40:36 -080072 data.writeStrongBinder(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 remote()->transact(DESTROY_SURFACE, data, &reply);
74 return reply.readInt32();
75 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076};
77
Mathias Agopian7e27f052010-05-28 14:22:23 -070078IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079
80// ----------------------------------------------------------------------
81
Mathias Agopian7e27f052010-05-28 14:22:23 -070082status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
84{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 switch(code) {
86 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -070087 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Mathias Agopian285dbde2010-03-01 16:09:43 -080088 String8 name = data.readString8();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 uint32_t w = data.readInt32();
90 uint32_t h = data.readInt32();
91 PixelFormat format = data.readInt32();
92 uint32_t flags = data.readInt32();
Mathias Agopian4d9b8222013-03-12 17:11:48 -070093 sp<IBinder> handle;
94 sp<IGraphicBufferProducer> gbp;
95 status_t result = createSurface(name, w, h, format, flags,
96 &handle, &gbp);
97 reply->writeStrongBinder(handle);
98 reply->writeStrongBinder(gbp->asBinder());
99 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100 return NO_ERROR;
101 } break;
102 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700103 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800104 reply->writeInt32( destroySurface( data.readStrongBinder() ) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 return NO_ERROR;
106 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107 default:
108 return BBinder::onTransact(code, data, reply, flags);
109 }
110}
111
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112}; // namespace android