The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/Parcel.h> |
| 24 | #include <binder/IMemory.h> |
| 25 | #include <binder/IPCThreadState.h> |
| 26 | #include <binder/IServiceManager.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <ui/DisplayInfo.h> |
| 29 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 30 | #include <surfaceflinger/ISurfaceComposer.h> |
| 31 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | // --------------------------------------------------------------------------- |
| 33 | |
| 34 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 35 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 36 | |
| 37 | // --------------------------------------------------------------------------- |
| 38 | |
| 39 | namespace android { |
| 40 | |
| 41 | class BpSurfaceComposer : public BpInterface<ISurfaceComposer> |
| 42 | { |
| 43 | public: |
| 44 | BpSurfaceComposer(const sp<IBinder>& impl) |
| 45 | : BpInterface<ISurfaceComposer>(impl) |
| 46 | { |
| 47 | } |
| 48 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 49 | virtual sp<ISurfaceComposerClient> createConnection() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | { |
| 51 | uint32_t n; |
| 52 | Parcel data, reply; |
| 53 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 54 | remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply); |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 55 | return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 58 | virtual sp<ISurfaceComposerClient> createClientConnection() |
| 59 | { |
| 60 | uint32_t n; |
| 61 | Parcel data, reply; |
| 62 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 63 | remote()->transact(BnSurfaceComposer::CREATE_CLIENT_CONNECTION, data, &reply); |
| 64 | return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder()); |
| 65 | } |
| 66 | |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame^] | 67 | virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() |
| 68 | { |
| 69 | uint32_t n; |
| 70 | Parcel data, reply; |
| 71 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 72 | remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply); |
| 73 | return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder()); |
| 74 | } |
| 75 | |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 76 | virtual sp<IMemoryHeap> getCblk() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | { |
| 78 | Parcel data, reply; |
| 79 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 80 | remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 81 | return interface_cast<IMemoryHeap>(reply.readStrongBinder()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | virtual void openGlobalTransaction() |
| 85 | { |
| 86 | Parcel data, reply; |
| 87 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 88 | remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply); |
| 89 | } |
| 90 | |
| 91 | virtual void closeGlobalTransaction() |
| 92 | { |
| 93 | Parcel data, reply; |
| 94 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 95 | remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply); |
| 96 | } |
| 97 | |
| 98 | virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags) |
| 99 | { |
| 100 | Parcel data, reply; |
| 101 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 102 | data.writeInt32(dpy); |
| 103 | data.writeInt32(flags); |
| 104 | remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply); |
| 105 | return reply.readInt32(); |
| 106 | } |
| 107 | |
| 108 | virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags) |
| 109 | { |
| 110 | Parcel data, reply; |
| 111 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 112 | data.writeInt32(dpy); |
| 113 | data.writeInt32(flags); |
| 114 | remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply); |
| 115 | return reply.readInt32(); |
| 116 | } |
| 117 | |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 118 | virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | { |
| 120 | Parcel data, reply; |
| 121 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 122 | data.writeInt32(dpy); |
| 123 | data.writeInt32(orientation); |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 124 | data.writeInt32(flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply); |
| 126 | return reply.readInt32(); |
| 127 | } |
| 128 | |
| 129 | virtual void bootFinished() |
| 130 | { |
| 131 | Parcel data, reply; |
| 132 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 133 | remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply); |
| 134 | } |
| 135 | |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 136 | virtual status_t captureScreen(DisplayID dpy, |
| 137 | sp<IMemoryHeap>* heap, |
Mathias Agopian | df85c45 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 138 | uint32_t* width, uint32_t* height, PixelFormat* format, |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 139 | uint32_t reqWidth, uint32_t reqHeight, |
| 140 | uint32_t minLayerZ, uint32_t maxLayerZ) |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 141 | { |
| 142 | Parcel data, reply; |
| 143 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 144 | data.writeInt32(dpy); |
Mathias Agopian | df85c45 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 145 | data.writeInt32(reqWidth); |
| 146 | data.writeInt32(reqHeight); |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 147 | data.writeInt32(minLayerZ); |
| 148 | data.writeInt32(maxLayerZ); |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 149 | remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply); |
| 150 | *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder()); |
| 151 | *width = reply.readInt32(); |
| 152 | *height = reply.readInt32(); |
| 153 | *format = reply.readInt32(); |
| 154 | return reply.readInt32(); |
| 155 | } |
| 156 | |
Mathias Agopian | 59119e6 | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 157 | virtual status_t turnElectronBeamOff(int32_t mode) |
| 158 | { |
| 159 | Parcel data, reply; |
| 160 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 161 | data.writeInt32(mode); |
| 162 | remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply); |
| 163 | return reply.readInt32(); |
| 164 | } |
| 165 | |
Mathias Agopian | 9daa5c9 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 166 | virtual status_t turnElectronBeamOn(int32_t mode) |
| 167 | { |
| 168 | Parcel data, reply; |
| 169 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 170 | data.writeInt32(mode); |
| 171 | remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply); |
| 172 | return reply.readInt32(); |
| 173 | } |
| 174 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | virtual void signal() const |
| 176 | { |
| 177 | Parcel data, reply; |
| 178 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 179 | remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY); |
| 180 | } |
| 181 | }; |
| 182 | |
| 183 | IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer"); |
| 184 | |
| 185 | // ---------------------------------------------------------------------- |
| 186 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | status_t BnSurfaceComposer::onTransact( |
| 188 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 189 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | switch(code) { |
| 191 | case CREATE_CONNECTION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 192 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | sp<IBinder> b = createConnection()->asBinder(); |
| 194 | reply->writeStrongBinder(b); |
| 195 | } break; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 196 | case CREATE_CLIENT_CONNECTION: { |
| 197 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 198 | sp<IBinder> b = createClientConnection()->asBinder(); |
| 199 | reply->writeStrongBinder(b); |
| 200 | } break; |
Jamie Gennis | 9a78c90 | 2011-01-12 18:30:40 -0800 | [diff] [blame^] | 201 | case CREATE_GRAPHIC_BUFFER_ALLOC: { |
| 202 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 203 | sp<IBinder> b = createGraphicBufferAlloc()->asBinder(); |
| 204 | reply->writeStrongBinder(b); |
| 205 | } break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | case OPEN_GLOBAL_TRANSACTION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 207 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | openGlobalTransaction(); |
| 209 | } break; |
| 210 | case CLOSE_GLOBAL_TRANSACTION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 211 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | closeGlobalTransaction(); |
| 213 | } break; |
| 214 | case SET_ORIENTATION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 215 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | DisplayID dpy = data.readInt32(); |
| 217 | int orientation = data.readInt32(); |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 218 | uint32_t flags = data.readInt32(); |
| 219 | reply->writeInt32( setOrientation(dpy, orientation, flags) ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | } break; |
| 221 | case FREEZE_DISPLAY: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 222 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | DisplayID dpy = data.readInt32(); |
| 224 | uint32_t flags = data.readInt32(); |
| 225 | reply->writeInt32( freezeDisplay(dpy, flags) ); |
| 226 | } break; |
| 227 | case UNFREEZE_DISPLAY: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 228 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | DisplayID dpy = data.readInt32(); |
| 230 | uint32_t flags = data.readInt32(); |
| 231 | reply->writeInt32( unfreezeDisplay(dpy, flags) ); |
| 232 | } break; |
| 233 | case BOOT_FINISHED: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 234 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | bootFinished(); |
| 236 | } break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | case SIGNAL: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 238 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | signal(); |
| 240 | } break; |
| 241 | case GET_CBLK: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 242 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | sp<IBinder> b = getCblk()->asBinder(); |
| 244 | reply->writeStrongBinder(b); |
| 245 | } break; |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 246 | case CAPTURE_SCREEN: { |
| 247 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 248 | DisplayID dpy = data.readInt32(); |
Mathias Agopian | df85c45 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 249 | uint32_t reqWidth = data.readInt32(); |
| 250 | uint32_t reqHeight = data.readInt32(); |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 251 | uint32_t minLayerZ = data.readInt32(); |
| 252 | uint32_t maxLayerZ = data.readInt32(); |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 253 | sp<IMemoryHeap> heap; |
| 254 | uint32_t w, h; |
| 255 | PixelFormat f; |
Mathias Agopian | df85c45 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 256 | status_t res = captureScreen(dpy, &heap, &w, &h, &f, |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 257 | reqWidth, reqHeight, minLayerZ, maxLayerZ); |
Mathias Agopian | 1b0b30d | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 258 | reply->writeStrongBinder(heap->asBinder()); |
| 259 | reply->writeInt32(w); |
| 260 | reply->writeInt32(h); |
| 261 | reply->writeInt32(f); |
| 262 | reply->writeInt32(res); |
| 263 | } break; |
Mathias Agopian | 59119e6 | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 264 | case TURN_ELECTRON_BEAM_OFF: { |
| 265 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 266 | int32_t mode = data.readInt32(); |
| 267 | status_t res = turnElectronBeamOff(mode); |
| 268 | reply->writeInt32(res); |
| 269 | } |
Mathias Agopian | 9daa5c9 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 270 | case TURN_ELECTRON_BEAM_ON: { |
| 271 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 272 | int32_t mode = data.readInt32(); |
| 273 | status_t res = turnElectronBeamOn(mode); |
| 274 | reply->writeInt32(res); |
| 275 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | default: |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 277 | return BBinder::onTransact(code, data, reply, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | } |
| 279 | return NO_ERROR; |
| 280 | } |
| 281 | |
| 282 | // ---------------------------------------------------------------------------- |
| 283 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | }; |