The Android Open Source Project | edbf3b6 | 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 | c5b2c0b | 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 | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <ui/DisplayInfo.h> |
| 29 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame^] | 30 | #include <surfaceflinger/ISurfaceComposer.h> |
| 31 | |
The Android Open Source Project | edbf3b6 | 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 | |
| 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 | |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 58 | virtual sp<IMemoryHeap> getCblk() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | { |
| 60 | Parcel data, reply; |
| 61 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 62 | remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply); |
Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 63 | return interface_cast<IMemoryHeap>(reply.readStrongBinder()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 100 | virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | { |
| 102 | Parcel data, reply; |
| 103 | data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); |
| 104 | data.writeInt32(dpy); |
| 105 | data.writeInt32(orientation); |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 106 | data.writeInt32(flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 126 | IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer"); |
| 127 | |
| 128 | // ---------------------------------------------------------------------- |
| 129 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | status_t BnSurfaceComposer::onTransact( |
| 131 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 132 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | switch(code) { |
| 134 | case CREATE_CONNECTION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 135 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | sp<IBinder> b = createConnection()->asBinder(); |
| 137 | reply->writeStrongBinder(b); |
| 138 | } break; |
| 139 | case OPEN_GLOBAL_TRANSACTION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 140 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | openGlobalTransaction(); |
| 142 | } break; |
| 143 | case CLOSE_GLOBAL_TRANSACTION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 144 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | closeGlobalTransaction(); |
| 146 | } break; |
| 147 | case SET_ORIENTATION: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 148 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | DisplayID dpy = data.readInt32(); |
| 150 | int orientation = data.readInt32(); |
Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 151 | uint32_t flags = data.readInt32(); |
| 152 | reply->writeInt32( setOrientation(dpy, orientation, flags) ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | } break; |
| 154 | case FREEZE_DISPLAY: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 155 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | DisplayID dpy = data.readInt32(); |
| 157 | uint32_t flags = data.readInt32(); |
| 158 | reply->writeInt32( freezeDisplay(dpy, flags) ); |
| 159 | } break; |
| 160 | case UNFREEZE_DISPLAY: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 161 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | DisplayID dpy = data.readInt32(); |
| 163 | uint32_t flags = data.readInt32(); |
| 164 | reply->writeInt32( unfreezeDisplay(dpy, flags) ); |
| 165 | } break; |
| 166 | case BOOT_FINISHED: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 167 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | bootFinished(); |
| 169 | } break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | case SIGNAL: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 171 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | signal(); |
| 173 | } break; |
| 174 | case GET_CBLK: { |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 175 | CHECK_INTERFACE(ISurfaceComposer, data, reply); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | sp<IBinder> b = getCblk()->asBinder(); |
| 177 | reply->writeStrongBinder(b); |
| 178 | } break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | default: |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 180 | return BBinder::onTransact(code, data, reply, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | } |
| 182 | return NO_ERROR; |
| 183 | } |
| 184 | |
| 185 | // ---------------------------------------------------------------------------- |
| 186 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | }; |