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 | |
| 28 | #include <ui/ISurfaceComposer.h> |
| 29 | #include <ui/DisplayInfo.h> |
| 30 | |
| 31 | // --------------------------------------------------------------------------- |
| 32 | |
| 33 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 34 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 35 | |
| 36 | // --------------------------------------------------------------------------- |
| 37 | |
| 38 | namespace android { |
| 39 | |
| 40 | class BpSurfaceComposer : public BpInterface<ISurfaceComposer> |
| 41 | { |
| 42 | public: |
| 43 | BpSurfaceComposer(const sp<IBinder>& impl) |
| 44 | : BpInterface<ISurfaceComposer>(impl) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | virtual sp<ISurfaceFlingerClient> createConnection() |
| 49 | { |
| 50 | uint32_t n; |
| 51 | Parcel data, reply; |
| 52 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 53 | remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply); |
| 54 | return interface_cast<ISurfaceFlingerClient>(reply.readStrongBinder()); |
| 55 | } |
| 56 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 57 | virtual sp<IMemoryHeap> getCblk() const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | { |
| 59 | Parcel data, reply; |
| 60 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 61 | remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 62 | return interface_cast<IMemoryHeap>(reply.readStrongBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | virtual void openGlobalTransaction() |
| 66 | { |
| 67 | Parcel data, reply; |
| 68 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 69 | remote()->transact(BnSurfaceComposer::OPEN_GLOBAL_TRANSACTION, data, &reply); |
| 70 | } |
| 71 | |
| 72 | virtual void closeGlobalTransaction() |
| 73 | { |
| 74 | Parcel data, reply; |
| 75 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 76 | remote()->transact(BnSurfaceComposer::CLOSE_GLOBAL_TRANSACTION, data, &reply); |
| 77 | } |
| 78 | |
| 79 | virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags) |
| 80 | { |
| 81 | Parcel data, reply; |
| 82 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 83 | data.writeInt32(dpy); |
| 84 | data.writeInt32(flags); |
| 85 | remote()->transact(BnSurfaceComposer::FREEZE_DISPLAY, data, &reply); |
| 86 | return reply.readInt32(); |
| 87 | } |
| 88 | |
| 89 | virtual status_t unfreezeDisplay(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::UNFREEZE_DISPLAY, data, &reply); |
| 96 | return reply.readInt32(); |
| 97 | } |
| 98 | |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 99 | 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] | 100 | { |
| 101 | Parcel data, reply; |
| 102 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 103 | data.writeInt32(dpy); |
| 104 | data.writeInt32(orientation); |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 105 | data.writeInt32(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | remote()->transact(BnSurfaceComposer::SET_ORIENTATION, data, &reply); |
| 107 | return reply.readInt32(); |
| 108 | } |
| 109 | |
| 110 | virtual void bootFinished() |
| 111 | { |
| 112 | Parcel data, reply; |
| 113 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 114 | remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply); |
| 115 | } |
| 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | virtual void signal() const |
| 118 | { |
| 119 | Parcel data, reply; |
| 120 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 121 | remote()->transact(BnSurfaceComposer::SIGNAL, data, &reply, IBinder::FLAG_ONEWAY); |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer"); |
| 126 | |
| 127 | // ---------------------------------------------------------------------- |
| 128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | status_t BnSurfaceComposer::onTransact( |
| 130 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 131 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | switch(code) { |
| 133 | case CREATE_CONNECTION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 134 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | sp<IBinder> b = createConnection()->asBinder(); |
| 136 | reply->writeStrongBinder(b); |
| 137 | } break; |
| 138 | case OPEN_GLOBAL_TRANSACTION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 139 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | openGlobalTransaction(); |
| 141 | } break; |
| 142 | case CLOSE_GLOBAL_TRANSACTION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 143 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | closeGlobalTransaction(); |
| 145 | } break; |
| 146 | case SET_ORIENTATION: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 147 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | DisplayID dpy = data.readInt32(); |
| 149 | int orientation = data.readInt32(); |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 150 | uint32_t flags = data.readInt32(); |
| 151 | reply->writeInt32( setOrientation(dpy, orientation, flags) ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | } break; |
| 153 | case FREEZE_DISPLAY: { |
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 | DisplayID dpy = data.readInt32(); |
| 156 | uint32_t flags = data.readInt32(); |
| 157 | reply->writeInt32( freezeDisplay(dpy, flags) ); |
| 158 | } break; |
| 159 | case UNFREEZE_DISPLAY: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 160 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | DisplayID dpy = data.readInt32(); |
| 162 | uint32_t flags = data.readInt32(); |
| 163 | reply->writeInt32( unfreezeDisplay(dpy, flags) ); |
| 164 | } break; |
| 165 | case BOOT_FINISHED: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 166 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | bootFinished(); |
| 168 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | case SIGNAL: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 170 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | signal(); |
| 172 | } break; |
| 173 | case GET_CBLK: { |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 174 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | sp<IBinder> b = getCblk()->asBinder(); |
| 176 | reply->writeStrongBinder(b); |
| 177 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | default: |
Mathias Agopian | aaf834a | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 179 | return BBinder::onTransact(code, data, reply, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | } |
| 181 | return NO_ERROR; |
| 182 | } |
| 183 | |
| 184 | // ---------------------------------------------------------------------------- |
| 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | }; |