The Android Open Source Project | 9066cfe | 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 | 0795272 | 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 | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 28 | #include <private/surfaceflinger/LayerState.h> |
| 29 | |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 30 | #include <surfaceflinger/ISurfaceComposer.h> |
| 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include <ui/DisplayInfo.h> |
| 33 | |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 34 | #include <gui/ISurfaceTexture.h> |
| 35 | |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 36 | #include <utils/Log.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | // --------------------------------------------------------------------------- |
| 39 | |
| 40 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 41 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 42 | |
| 43 | // --------------------------------------------------------------------------- |
| 44 | |
| 45 | namespace android { |
| 46 | |
| 47 | class BpSurfaceComposer : public BpInterface<ISurfaceComposer> |
| 48 | { |
| 49 | public: |
| 50 | BpSurfaceComposer(const sp<IBinder>& impl) |
| 51 | : BpInterface<ISurfaceComposer>(impl) |
| 52 | { |
| 53 | } |
| 54 | |
Mathias Agopian | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 55 | virtual sp<ISurfaceComposerClient> createConnection() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | { |
| 57 | uint32_t n; |
| 58 | Parcel data, reply; |
| 59 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 60 | remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply); |
Mathias Agopian | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 61 | return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 64 | virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() |
| 65 | { |
| 66 | uint32_t n; |
| 67 | Parcel data, reply; |
| 68 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 69 | remote()->transact(BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, data, &reply); |
| 70 | return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder()); |
| 71 | } |
| 72 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 73 | virtual sp<IMemoryHeap> getCblk() const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | { |
| 75 | Parcel data, reply; |
| 76 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 77 | remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 78 | return interface_cast<IMemoryHeap>(reply.readStrongBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 81 | virtual void setTransactionState(const Vector<ComposerState>& state, |
Jamie Gennis | 122aa6b | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 82 | int orientation, uint32_t flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | { |
| 84 | Parcel data, reply; |
| 85 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 86 | Vector<ComposerState>::const_iterator b(state.begin()); |
| 87 | Vector<ComposerState>::const_iterator e(state.end()); |
| 88 | data.writeInt32(state.size()); |
| 89 | for ( ; b != e ; ++b ) { |
| 90 | b->write(data); |
| 91 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | data.writeInt32(orientation); |
Jamie Gennis | 122aa6b | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 93 | data.writeInt32(flags); |
Jamie Gennis | e2909e1 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 94 | remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | virtual void bootFinished() |
| 98 | { |
| 99 | Parcel data, reply; |
| 100 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 101 | remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply); |
| 102 | } |
| 103 | |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 104 | virtual status_t captureScreen(DisplayID dpy, |
| 105 | sp<IMemoryHeap>* heap, |
Mathias Agopian | 597c7f6 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 106 | uint32_t* width, uint32_t* height, PixelFormat* format, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 107 | uint32_t reqWidth, uint32_t reqHeight, |
| 108 | uint32_t minLayerZ, uint32_t maxLayerZ) |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 109 | { |
| 110 | Parcel data, reply; |
| 111 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 112 | data.writeInt32(dpy); |
Mathias Agopian | 597c7f6 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 113 | data.writeInt32(reqWidth); |
| 114 | data.writeInt32(reqHeight); |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 115 | data.writeInt32(minLayerZ); |
| 116 | data.writeInt32(maxLayerZ); |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 117 | remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply); |
| 118 | *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder()); |
| 119 | *width = reply.readInt32(); |
| 120 | *height = reply.readInt32(); |
| 121 | *format = reply.readInt32(); |
| 122 | return reply.readInt32(); |
| 123 | } |
| 124 | |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 125 | virtual status_t turnElectronBeamOff(int32_t mode) |
| 126 | { |
| 127 | Parcel data, reply; |
| 128 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 129 | data.writeInt32(mode); |
| 130 | remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply); |
| 131 | return reply.readInt32(); |
| 132 | } |
| 133 | |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 134 | virtual status_t turnElectronBeamOn(int32_t mode) |
| 135 | { |
| 136 | Parcel data, reply; |
| 137 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 138 | data.writeInt32(mode); |
| 139 | remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply); |
| 140 | return reply.readInt32(); |
| 141 | } |
| 142 | |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 143 | virtual bool authenticateSurfaceTexture( |
| 144 | const sp<ISurfaceTexture>& surfaceTexture) const |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 145 | { |
| 146 | Parcel data, reply; |
| 147 | int err = NO_ERROR; |
| 148 | err = data.writeInterfaceToken( |
| 149 | ISurfaceComposer::getInterfaceDescriptor()); |
| 150 | if (err != NO_ERROR) { |
Steve Block | c6aacce | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 151 | ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing " |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 152 | "interface descriptor: %s (%d)", strerror(-err), -err); |
| 153 | return false; |
| 154 | } |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 155 | err = data.writeStrongBinder(surfaceTexture->asBinder()); |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 156 | if (err != NO_ERROR) { |
Steve Block | c6aacce | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 157 | ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing " |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 158 | "strong binder to parcel: %s (%d)", strerror(-err), -err); |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 159 | return false; |
| 160 | } |
| 161 | err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data, |
| 162 | &reply); |
| 163 | if (err != NO_ERROR) { |
Steve Block | c6aacce | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 164 | ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error " |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 165 | "performing transaction: %s (%d)", strerror(-err), -err); |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 166 | return false; |
| 167 | } |
| 168 | int32_t result = 0; |
| 169 | err = reply.readInt32(&result); |
| 170 | if (err != NO_ERROR) { |
Steve Block | c6aacce | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 171 | ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error " |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 172 | "retrieving result: %s (%d)", strerror(-err), -err); |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 173 | return false; |
| 174 | } |
| 175 | return result != 0; |
| 176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer"); |
| 180 | |
| 181 | // ---------------------------------------------------------------------- |
| 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | status_t BnSurfaceComposer::onTransact( |
| 184 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 185 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | switch(code) { |
| 187 | case CREATE_CONNECTION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 188 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | sp<IBinder> b = createConnection()->asBinder(); |
| 190 | reply->writeStrongBinder(b); |
| 191 | } break; |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 192 | case CREATE_GRAPHIC_BUFFER_ALLOC: { |
| 193 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 194 | sp<IBinder> b = createGraphicBufferAlloc()->asBinder(); |
| 195 | reply->writeStrongBinder(b); |
| 196 | } break; |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 197 | case SET_TRANSACTION_STATE: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 198 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 199 | size_t count = data.readInt32(); |
| 200 | ComposerState s; |
| 201 | Vector<ComposerState> state; |
| 202 | state.setCapacity(count); |
| 203 | for (size_t i=0 ; i<count ; i++) { |
| 204 | s.read(data); |
| 205 | state.add(s); |
| 206 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | int orientation = data.readInt32(); |
Jamie Gennis | 122aa6b | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 208 | uint32_t flags = data.readInt32(); |
| 209 | setTransactionState(state, orientation, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | } break; |
| 211 | case BOOT_FINISHED: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 212 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | bootFinished(); |
| 214 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | case GET_CBLK: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 216 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | sp<IBinder> b = getCblk()->asBinder(); |
| 218 | reply->writeStrongBinder(b); |
| 219 | } break; |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 220 | case CAPTURE_SCREEN: { |
| 221 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 222 | DisplayID dpy = data.readInt32(); |
Mathias Agopian | 597c7f6 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 223 | uint32_t reqWidth = data.readInt32(); |
| 224 | uint32_t reqHeight = data.readInt32(); |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 225 | uint32_t minLayerZ = data.readInt32(); |
| 226 | uint32_t maxLayerZ = data.readInt32(); |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 227 | sp<IMemoryHeap> heap; |
| 228 | uint32_t w, h; |
| 229 | PixelFormat f; |
Mathias Agopian | 597c7f6 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 230 | status_t res = captureScreen(dpy, &heap, &w, &h, &f, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 231 | reqWidth, reqHeight, minLayerZ, maxLayerZ); |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 232 | reply->writeStrongBinder(heap->asBinder()); |
| 233 | reply->writeInt32(w); |
| 234 | reply->writeInt32(h); |
| 235 | reply->writeInt32(f); |
| 236 | reply->writeInt32(res); |
| 237 | } break; |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 238 | case TURN_ELECTRON_BEAM_OFF: { |
| 239 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 240 | int32_t mode = data.readInt32(); |
| 241 | status_t res = turnElectronBeamOff(mode); |
| 242 | reply->writeInt32(res); |
Jamie Gennis | 96fceaf | 2010-12-20 11:05:18 -0800 | [diff] [blame] | 243 | } break; |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 244 | case TURN_ELECTRON_BEAM_ON: { |
| 245 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 246 | int32_t mode = data.readInt32(); |
| 247 | status_t res = turnElectronBeamOn(mode); |
| 248 | reply->writeInt32(res); |
Jamie Gennis | 96fceaf | 2010-12-20 11:05:18 -0800 | [diff] [blame] | 249 | } break; |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 250 | case AUTHENTICATE_SURFACE: { |
| 251 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 252 | sp<ISurfaceTexture> surfaceTexture = |
| 253 | interface_cast<ISurfaceTexture>(data.readStrongBinder()); |
| 254 | int32_t result = authenticateSurfaceTexture(surfaceTexture) ? 1 : 0; |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 255 | reply->writeInt32(result); |
| 256 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | default: |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 258 | return BBinder::onTransact(code, data, reply, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | return NO_ERROR; |
| 261 | } |
| 262 | |
| 263 | // ---------------------------------------------------------------------------- |
| 264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | }; |