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 23 #include <binder/Parcel.h> 24 #include <binder/IMemory.h> 25 #include <binder/IPCThreadState.h> 26 #include <binder/IServiceManager.h> 27 28 #include <ui/DisplayInfo.h> 29 30 #include <surfaceflinger/ISurfaceComposer.h> 31 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 49 virtual sp<ISurfaceComposerClient> 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<ISurfaceComposerClient>(reply.readStrongBinder()); 56 } 57 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 67 virtual sp<IMemoryHeap> getCblk() const 68 { 69 Parcel data, reply; 70 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 71 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); 72 return interface_cast<IMemoryHeap>(reply.readStrongBinder()); 73 } 74 75 virtual void openGlobalTransaction() 76 { 77 Parcel data, reply; 78 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 79 remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply); 80 } 81 82 virtual void closeGlobalTransaction() 83 { 84 Parcel data, reply; 85 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 86 remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply); 87 } 88 89 virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags) 90 { 91 Parcel data, reply; 92 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 93 data.writeInt32(dpy); 94 data.writeInt32(flags); 95 remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply); 96 return reply.readInt32(); 97 } 98 99 virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags) 100 { 101 Parcel data, reply; 102 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 103 data.writeInt32(dpy); 104 data.writeInt32(flags); 105 remote()->transact(BnSurfaceComposer::UNFREEZE_DISPLAY, data, &reply); 106 return reply.readInt32(); 107 } 108 109 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) 110 { 111 Parcel data, reply; 112 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 113 data.writeInt32(dpy); 114 data.writeInt32(orientation); 115 data.writeInt32(flags); 116 remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply); 117 return reply.readInt32(); 118 } 119 120 virtual void bootFinished() 121 { 122 Parcel data, reply; 123 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 124 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply); 125 } 126 127 virtual status_t captureScreen(DisplayID dpy, 128 sp<IMemoryHeap>* heap, 129 uint32_t* width, uint32_t* height, PixelFormat* format, 130 uint32_t reqWidth, uint32_t reqHeight) 131 { 132 Parcel data, reply; 133 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 134 data.writeInt32(dpy); 135 data.writeInt32(reqWidth); 136 data.writeInt32(reqHeight); 137 remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply); 138 *heap = interface_cast<IMemoryHeap>(reply.readStrongBinder()); 139 *width = reply.readInt32(); 140 *height = reply.readInt32(); 141 *format = reply.readInt32(); 142 return reply.readInt32(); 143 } 144 145 virtual status_t turnElectronBeamOff(int32_t mode) 146 { 147 Parcel data, reply; 148 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 149 data.writeInt32(mode); 150 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply); 151 return reply.readInt32(); 152 } 153 154 virtual status_t turnElectronBeamOn(int32_t mode) 155 { 156 Parcel data, reply; 157 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 158 data.writeInt32(mode); 159 remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_ON, data, &reply); 160 return reply.readInt32(); 161 } 162 163 virtual void signal() const 164 { 165 Parcel data, reply; 166 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 167 remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY); 168 } 169 }; 170 171 IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer"); 172 173 // ---------------------------------------------------------------------- 174 175 status_t BnSurfaceComposer::onTransact( 176 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 177 { 178 switch(code) { 179 case CREATE_CONNECTION: { 180 CHECK_INTERFACE(ISurfaceComposer, data, reply); 181 sp<IBinder> b = createConnection()->asBinder(); 182 reply->writeStrongBinder(b); 183 } break; 184 case CREATE_CLIENT_CONNECTION: { 185 CHECK_INTERFACE(ISurfaceComposer, data, reply); 186 sp<IBinder> b = createClientConnection()->asBinder(); 187 reply->writeStrongBinder(b); 188 } break; 189 case OPEN_GLOBAL_TRANSACTION: { 190 CHECK_INTERFACE(ISurfaceComposer, data, reply); 191 openGlobalTransaction(); 192 } break; 193 case CLOSE_GLOBAL_TRANSACTION: { 194 CHECK_INTERFACE(ISurfaceComposer, data, reply); 195 closeGlobalTransaction(); 196 } break; 197 case SET_ORIENTATION: { 198 CHECK_INTERFACE(ISurfaceComposer, data, reply); 199 DisplayID dpy = data.readInt32(); 200 int orientation = data.readInt32(); 201 uint32_t flags = data.readInt32(); 202 reply->writeInt32( setOrientation(dpy, orientation, flags) ); 203 } break; 204 case FREEZE_DISPLAY: { 205 CHECK_INTERFACE(ISurfaceComposer, data, reply); 206 DisplayID dpy = data.readInt32(); 207 uint32_t flags = data.readInt32(); 208 reply->writeInt32( freezeDisplay(dpy, flags) ); 209 } break; 210 case UNFREEZE_DISPLAY: { 211 CHECK_INTERFACE(ISurfaceComposer, data, reply); 212 DisplayID dpy = data.readInt32(); 213 uint32_t flags = data.readInt32(); 214 reply->writeInt32( unfreezeDisplay(dpy, flags) ); 215 } break; 216 case BOOT_FINISHED: { 217 CHECK_INTERFACE(ISurfaceComposer, data, reply); 218 bootFinished(); 219 } break; 220 case SIGNAL: { 221 CHECK_INTERFACE(ISurfaceComposer, data, reply); 222 signal(); 223 } break; 224 case GET_CBLK: { 225 CHECK_INTERFACE(ISurfaceComposer, data, reply); 226 sp<IBinder> b = getCblk()->asBinder(); 227 reply->writeStrongBinder(b); 228 } break; 229 case CAPTURE_SCREEN: { 230 CHECK_INTERFACE(ISurfaceComposer, data, reply); 231 DisplayID dpy = data.readInt32(); 232 uint32_t reqWidth = data.readInt32(); 233 uint32_t reqHeight = data.readInt32(); 234 sp<IMemoryHeap> heap; 235 uint32_t w, h; 236 PixelFormat f; 237 status_t res = captureScreen(dpy, &heap, &w, &h, &f, 238 reqWidth, reqHeight); 239 reply->writeStrongBinder(heap->asBinder()); 240 reply->writeInt32(w); 241 reply->writeInt32(h); 242 reply->writeInt32(f); 243 reply->writeInt32(res); 244 } break; 245 case TURN_ELECTRON_BEAM_OFF: { 246 CHECK_INTERFACE(ISurfaceComposer, data, reply); 247 int32_t mode = data.readInt32(); 248 status_t res = turnElectronBeamOff(mode); 249 reply->writeInt32(res); 250 } 251 case TURN_ELECTRON_BEAM_ON: { 252 CHECK_INTERFACE(ISurfaceComposer, data, reply); 253 int32_t mode = data.readInt32(); 254 status_t res = turnElectronBeamOn(mode); 255 reply->writeInt32(res); 256 } 257 default: 258 return BBinder::onTransact(code, data, reply, flags); 259 } 260 return NO_ERROR; 261 } 262 263 // ---------------------------------------------------------------------------- 264 265 }; 266