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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <ui/DisplayInfo.h> |
| 29 | |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -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 | // --------------------------------------------------------------------------- |
| 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 | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 49 | virtual sp<ISurfaceComposerClient> createConnection() |
The Android Open Source Project | 9066cfe | 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 | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 55 | return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Mathias Agopian | 7623da4 | 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 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 67 | virtual sp<IMemoryHeap> getCblk() const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | { |
| 69 | Parcel data, reply; |
| 70 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 71 | remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 72 | return interface_cast<IMemoryHeap>(reply.readStrongBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 109 | virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | { |
| 111 | Parcel data, reply; |
| 112 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 113 | data.writeInt32(dpy); |
| 114 | data.writeInt32(orientation); |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 115 | data.writeInt32(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | virtual void signal() const |
| 128 | { |
| 129 | Parcel data, reply; |
| 130 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 131 | remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY); |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer"); |
| 136 | |
| 137 | // ---------------------------------------------------------------------- |
| 138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | status_t BnSurfaceComposer::onTransact( |
| 140 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 141 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | switch(code) { |
| 143 | case CREATE_CONNECTION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 144 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | sp<IBinder> b = createConnection()->asBinder(); |
| 146 | reply->writeStrongBinder(b); |
| 147 | } break; |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 148 | case CREATE_CLIENT_CONNECTION: { |
| 149 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
| 150 | sp<IBinder> b = createClientConnection()->asBinder(); |
| 151 | reply->writeStrongBinder(b); |
| 152 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | case OPEN_GLOBAL_TRANSACTION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 154 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | openGlobalTransaction(); |
| 156 | } break; |
| 157 | case CLOSE_GLOBAL_TRANSACTION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 158 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | closeGlobalTransaction(); |
| 160 | } break; |
| 161 | case SET_ORIENTATION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 162 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | DisplayID dpy = data.readInt32(); |
| 164 | int orientation = data.readInt32(); |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 165 | uint32_t flags = data.readInt32(); |
| 166 | reply->writeInt32( setOrientation(dpy, orientation, flags) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | } break; |
| 168 | case FREEZE_DISPLAY: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 169 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | DisplayID dpy = data.readInt32(); |
| 171 | uint32_t flags = data.readInt32(); |
| 172 | reply->writeInt32( freezeDisplay(dpy, flags) ); |
| 173 | } break; |
| 174 | case UNFREEZE_DISPLAY: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 175 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | DisplayID dpy = data.readInt32(); |
| 177 | uint32_t flags = data.readInt32(); |
| 178 | reply->writeInt32( unfreezeDisplay(dpy, flags) ); |
| 179 | } break; |
| 180 | case BOOT_FINISHED: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 181 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | bootFinished(); |
| 183 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | case SIGNAL: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 185 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | signal(); |
| 187 | } break; |
| 188 | case GET_CBLK: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 189 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | sp<IBinder> b = getCblk()->asBinder(); |
| 191 | reply->writeStrongBinder(b); |
| 192 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | default: |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 194 | return BBinder::onTransact(code, data, reply, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | } |
| 196 | return NO_ERROR; |
| 197 | } |
| 198 | |
| 199 | // ---------------------------------------------------------------------------- |
| 200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | }; |