blob: de4d8c18a6710561b49cdc79862ef865509fb4fa [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,
Svetoslavd85084b2014-03-20 10:28:31 -070042 DESTROY_SURFACE,
43 CLEAR_LAYER_FRAME_STATS,
44 GET_LAYER_FRAME_STATS
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045};
46
Mathias Agopian7e27f052010-05-28 14:22:23 -070047class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048{
49public:
Mathias Agopian7e27f052010-05-28 14:22:23 -070050 BpSurfaceComposerClient(const sp<IBinder>& impl)
Mathias Agopian4d9b8222013-03-12 17:11:48 -070051 : BpInterface<ISurfaceComposerClient>(impl) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 }
53
Mathias Agopian4d9b8222013-03-12 17:11:48 -070054 virtual status_t createSurface(const String8& name, uint32_t w,
55 uint32_t h, PixelFormat format, uint32_t flags,
56 sp<IBinder>* handle,
57 sp<IGraphicBufferProducer>* gbp) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070059 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080060 data.writeString8(name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 data.writeInt32(w);
62 data.writeInt32(h);
63 data.writeInt32(format);
64 data.writeInt32(flags);
65 remote()->transact(CREATE_SURFACE, data, &reply);
Mathias Agopian4d9b8222013-03-12 17:11:48 -070066 *handle = reply.readStrongBinder();
67 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
68 return reply.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070070
Mathias Agopian4d9b8222013-03-12 17:11:48 -070071 virtual status_t destroySurface(const sp<IBinder>& handle) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080072 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070073 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopianac9fa422013-02-11 16:40:36 -080074 data.writeStrongBinder(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075 remote()->transact(DESTROY_SURFACE, data, &reply);
76 return reply.readInt32();
77 }
Svetoslavd85084b2014-03-20 10:28:31 -070078
79 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
80 Parcel data, reply;
81 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
82 data.writeStrongBinder(handle);
83 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
84 return reply.readInt32();
85 }
86
87 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
88 Parcel data, reply;
89 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
90 data.writeStrongBinder(handle);
91 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
92 reply.read(*outStats);
93 return reply.readInt32();
94 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095};
96
Mathias Agopian7e27f052010-05-28 14:22:23 -070097IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098
99// ----------------------------------------------------------------------
100
Mathias Agopian7e27f052010-05-28 14:22:23 -0700101status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
103{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 switch(code) {
105 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700106 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800107 String8 name = data.readString8();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108 uint32_t w = data.readInt32();
109 uint32_t h = data.readInt32();
110 PixelFormat format = data.readInt32();
111 uint32_t flags = data.readInt32();
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700112 sp<IBinder> handle;
113 sp<IGraphicBufferProducer> gbp;
114 status_t result = createSurface(name, w, h, format, flags,
115 &handle, &gbp);
116 reply->writeStrongBinder(handle);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800117 reply->writeStrongBinder(IInterface::asBinder(gbp));
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700118 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800119 return NO_ERROR;
120 } break;
121 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700122 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Svetoslavd85084b2014-03-20 10:28:31 -0700123 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
124 return NO_ERROR;
125 } break;
126 case CLEAR_LAYER_FRAME_STATS: {
127 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
128 sp<IBinder> handle = data.readStrongBinder();
129 status_t result = clearLayerFrameStats(handle);
130 reply->writeInt32(result);
131 return NO_ERROR;
132 } break;
133 case GET_LAYER_FRAME_STATS: {
134 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
135 sp<IBinder> handle = data.readStrongBinder();
136 FrameStats stats;
137 status_t result = getLayerFrameStats(handle, &stats);
138 reply->write(stats);
139 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140 return NO_ERROR;
141 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 default:
143 return BBinder::onTransact(code, data, reply, flags);
144 }
145}
146
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147}; // namespace android