blob: b6f4e24a2ab01e7a96ac8f666958b3be807c473d [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 <stdint.h>
21#include <sys/types.h>
22
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
24#include <binder/IMemory.h>
25#include <binder/IPCThreadState.h>
26#include <binder/IServiceManager.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <ui/DisplayInfo.h>
29
Mathias Agopian9cce3252010-02-09 17:46:37 -080030#include <surfaceflinger/ISurfaceComposer.h>
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032// ---------------------------------------------------------------------------
33
34#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
35#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
36
37// ---------------------------------------------------------------------------
38
39namespace android {
40
41class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
42{
43public:
44 BpSurfaceComposer(const sp<IBinder>& impl)
45 : BpInterface<ISurfaceComposer>(impl)
46 {
47 }
48
49 virtual sp<ISurfaceFlingerClient> createConnection()
50 {
51 uint32_t n;
52 Parcel data, reply;
53 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
54 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
55 return interface_cast<ISurfaceFlingerClient>(reply.readStrongBinder());
56 }
57
Mathias Agopian7303c6b2009-07-02 18:11:53 -070058 virtual sp<IMemoryHeap> getCblk() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 {
60 Parcel data, reply;
61 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
62 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply);
Mathias Agopian7303c6b2009-07-02 18:11:53 -070063 return interface_cast<IMemoryHeap>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 }
65
66 virtual void openGlobalTransaction()
67 {
68 Parcel data, reply;
69 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
70 remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply);
71 }
72
73 virtual void closeGlobalTransaction()
74 {
75 Parcel data, reply;
76 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
77 remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply);
78 }
79
80 virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags)
81 {
82 Parcel data, reply;
83 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
84 data.writeInt32(dpy);
85 data.writeInt32(flags);
86 remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply);
87 return reply.readInt32();
88 }
89
90 virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags)
91 {
92 Parcel data, reply;
93 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
94 data.writeInt32(dpy);
95 data.writeInt32(flags);
96 remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply);
97 return reply.readInt32();
98 }
99
Mathias Agopianc08731e2009-03-27 18:11:38 -0700100 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101 {
102 Parcel data, reply;
103 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
104 data.writeInt32(dpy);
105 data.writeInt32(orientation);
Mathias Agopianc08731e2009-03-27 18:11:38 -0700106 data.writeInt32(flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107 remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply);
108 return reply.readInt32();
109 }
110
111 virtual void bootFinished()
112 {
113 Parcel data, reply;
114 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
115 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
116 }
117
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 virtual void signal() const
119 {
120 Parcel data, reply;
121 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
122 remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY);
123 }
124};
125
126IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
127
128// ----------------------------------------------------------------------
129
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130status_t BnSurfaceComposer::onTransact(
131 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
132{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 switch(code) {
134 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700135 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136 sp<IBinder> b = createConnection()->asBinder();
137 reply->writeStrongBinder(b);
138 } break;
139 case OPEN_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700140 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141 openGlobalTransaction();
142 } break;
143 case CLOSE_GLOBAL_TRANSACTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700144 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 closeGlobalTransaction();
146 } break;
147 case SET_ORIENTATION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700148 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149 DisplayID dpy = data.readInt32();
150 int orientation = data.readInt32();
Mathias Agopianc08731e2009-03-27 18:11:38 -0700151 uint32_t flags = data.readInt32();
152 reply->writeInt32( setOrientation(dpy, orientation, flags) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153 } break;
154 case FREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700155 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800156 DisplayID dpy = data.readInt32();
157 uint32_t flags = data.readInt32();
158 reply->writeInt32( freezeDisplay(dpy, flags) );
159 } break;
160 case UNFREEZE_DISPLAY: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700161 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162 DisplayID dpy = data.readInt32();
163 uint32_t flags = data.readInt32();
164 reply->writeInt32( unfreezeDisplay(dpy, flags) );
165 } break;
166 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700167 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 bootFinished();
169 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170 case SIGNAL: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700171 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800172 signal();
173 } break;
174 case GET_CBLK: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700175 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176 sp<IBinder> b = getCblk()->asBinder();
177 reply->writeStrongBinder(b);
178 } break;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179 default:
Mathias Agopian83c04462009-05-22 19:00:22 -0700180 return BBinder::onTransact(code, data, reply, flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181 }
182 return NO_ERROR;
183}
184
185// ----------------------------------------------------------------------------
186
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187};