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 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 58 virtual sp<IMemoryHeap> getCblk() const 59 { 60 Parcel data, reply; 61 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 62 remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); 63 return interface_cast<IMemoryHeap>(reply.readStrongBinder()); 64 } 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 100 virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) 101 { 102 Parcel data, reply; 103 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); 104 data.writeInt32(dpy); 105 data.writeInt32(orientation); 106 data.writeInt32(flags); 107 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 118 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 130status_t BnSurfaceComposer::onTransact( 131 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 132{ 133 switch(code) { 134 case CREATE_CONNECTION: { 135 CHECK_INTERFACE(ISurfaceComposer, data, reply); 136 sp<IBinder> b = createConnection()->asBinder(); 137 reply->writeStrongBinder(b); 138 } break; 139 case OPEN_GLOBAL_TRANSACTION: { 140 CHECK_INTERFACE(ISurfaceComposer, data, reply); 141 openGlobalTransaction(); 142 } break; 143 case CLOSE_GLOBAL_TRANSACTION: { 144 CHECK_INTERFACE(ISurfaceComposer, data, reply); 145 closeGlobalTransaction(); 146 } break; 147 case SET_ORIENTATION: { 148 CHECK_INTERFACE(ISurfaceComposer, data, reply); 149 DisplayID dpy = data.readInt32(); 150 int orientation = data.readInt32(); 151 uint32_t flags = data.readInt32(); 152 reply->writeInt32( setOrientation(dpy, orientation, flags) ); 153 } break; 154 case FREEZE_DISPLAY: { 155 CHECK_INTERFACE(ISurfaceComposer, data, reply); 156 DisplayID dpy = data.readInt32(); 157 uint32_t flags = data.readInt32(); 158 reply->writeInt32( freezeDisplay(dpy, flags) ); 159 } break; 160 case UNFREEZE_DISPLAY: { 161 CHECK_INTERFACE(ISurfaceComposer, data, reply); 162 DisplayID dpy = data.readInt32(); 163 uint32_t flags = data.readInt32(); 164 reply->writeInt32( unfreezeDisplay(dpy, flags) ); 165 } break; 166 case BOOT_FINISHED: { 167 CHECK_INTERFACE(ISurfaceComposer, data, reply); 168 bootFinished(); 169 } break; 170 case SIGNAL: { 171 CHECK_INTERFACE(ISurfaceComposer, data, reply); 172 signal(); 173 } break; 174 case GET_CBLK: { 175 CHECK_INTERFACE(ISurfaceComposer, data, reply); 176 sp<IBinder> b = getCblk()->asBinder(); 177 reply->writeStrongBinder(b); 178 } break; 179 default: 180 return BBinder::onTransact(code, data, reply, flags); 181 } 182 return NO_ERROR; 183} 184 185// ---------------------------------------------------------------------------- 186 187}; 188