blob: 2ecb9083ff9aa345bf1680a8df175cf121b46454 [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
Dan Stozad723bd72014-11-18 10:24:03 -080054 virtual ~BpSurfaceComposerClient();
55
56 virtual status_t createSurface(const String8& name, uint32_t width,
57 uint32_t height, PixelFormat format, uint32_t flags,
Mathias Agopian4d9b8222013-03-12 17:11:48 -070058 sp<IBinder>* handle,
59 sp<IGraphicBufferProducer>* gbp) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070061 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopian285dbde2010-03-01 16:09:43 -080062 data.writeString8(name);
Dan Stozad723bd72014-11-18 10:24:03 -080063 data.writeUint32(width);
64 data.writeUint32(height);
65 data.writeInt32(static_cast<int32_t>(format));
66 data.writeUint32(flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 remote()->transact(CREATE_SURFACE, data, &reply);
Mathias Agopian4d9b8222013-03-12 17:11:48 -070068 *handle = reply.readStrongBinder();
69 *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder());
70 return reply.readInt32();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 }
Mathias Agopian7e27f052010-05-28 14:22:23 -070072
Mathias Agopian4d9b8222013-03-12 17:11:48 -070073 virtual status_t destroySurface(const sp<IBinder>& handle) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 Parcel data, reply;
Mathias Agopian7e27f052010-05-28 14:22:23 -070075 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
Mathias Agopianac9fa422013-02-11 16:40:36 -080076 data.writeStrongBinder(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 remote()->transact(DESTROY_SURFACE, data, &reply);
78 return reply.readInt32();
79 }
Svetoslavd85084b2014-03-20 10:28:31 -070080
81 virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const {
82 Parcel data, reply;
83 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
84 data.writeStrongBinder(handle);
85 remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply);
86 return reply.readInt32();
87 }
88
89 virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const {
90 Parcel data, reply;
91 data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
92 data.writeStrongBinder(handle);
93 remote()->transact(GET_LAYER_FRAME_STATS, data, &reply);
94 reply.read(*outStats);
95 return reply.readInt32();
96 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097};
98
Dan Stozad723bd72014-11-18 10:24:03 -080099// Out-of-line virtual method definition to trigger vtable emission in this
100// translation unit (see clang warning -Wweak-vtables)
101BpSurfaceComposerClient::~BpSurfaceComposerClient() {}
102
Mathias Agopian7e27f052010-05-28 14:22:23 -0700103IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104
105// ----------------------------------------------------------------------
106
Mathias Agopian7e27f052010-05-28 14:22:23 -0700107status_t BnSurfaceComposerClient::onTransact(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
109{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 switch(code) {
111 case CREATE_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700112 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800113 String8 name = data.readString8();
Dan Stozad723bd72014-11-18 10:24:03 -0800114 uint32_t width = data.readUint32();
115 uint32_t height = data.readUint32();
116 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
117 uint32_t createFlags = data.readUint32();
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700118 sp<IBinder> handle;
119 sp<IGraphicBufferProducer> gbp;
Dan Stozad723bd72014-11-18 10:24:03 -0800120 status_t result = createSurface(name, width, height, format,
121 createFlags, &handle, &gbp);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700122 reply->writeStrongBinder(handle);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800123 reply->writeStrongBinder(IInterface::asBinder(gbp));
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700124 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800126 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127 case DESTROY_SURFACE: {
Mathias Agopian7e27f052010-05-28 14:22:23 -0700128 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
Svetoslavd85084b2014-03-20 10:28:31 -0700129 reply->writeInt32(destroySurface( data.readStrongBinder() ) );
130 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800131 }
Svetoslavd85084b2014-03-20 10:28:31 -0700132 case CLEAR_LAYER_FRAME_STATS: {
133 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
134 sp<IBinder> handle = data.readStrongBinder();
135 status_t result = clearLayerFrameStats(handle);
136 reply->writeInt32(result);
137 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800138 }
Svetoslavd85084b2014-03-20 10:28:31 -0700139 case GET_LAYER_FRAME_STATS: {
140 CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
141 sp<IBinder> handle = data.readStrongBinder();
142 FrameStats stats;
143 status_t result = getLayerFrameStats(handle, &stats);
144 reply->write(stats);
145 reply->writeInt32(result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800147 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148 default:
149 return BBinder::onTransact(code, data, reply, flags);
150 }
151}
152
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153}; // namespace android