| 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 <stdio.h> | 
|  | 21 | #include <stdint.h> | 
|  | 22 | #include <sys/types.h> | 
|  | 23 |  | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 24 | #include <binder/Parcel.h> | 
|  | 25 | #include <binder/IMemory.h> | 
|  | 26 | #include <binder/IPCThreadState.h> | 
|  | 27 | #include <binder/IServiceManager.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <ui/Point.h> | 
|  | 30 | #include <ui/Rect.h> | 
|  | 31 |  | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 32 | #include <gui/IGraphicBufferProducer.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 33 | #include <gui/ISurfaceComposerClient.h> | 
|  | 34 | #include <private/gui/LayerState.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 |  | 
|  | 36 | // --------------------------------------------------------------------------- | 
|  | 37 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | namespace android { | 
|  | 39 |  | 
|  | 40 | enum { | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 41 | CREATE_SURFACE = IBinder::FIRST_CALL_TRANSACTION, | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 42 | DESTROY_SURFACE, | 
|  | 43 | CLEAR_LAYER_FRAME_STATS, | 
| Robert Carr | 367c568 | 2016-06-20 11:55:28 -0700 | [diff] [blame] | 44 | GET_LAYER_FRAME_STATS, | 
|  | 45 | GET_TRANSFORM_TO_DISPLAY_INVERSE | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | }; | 
|  | 47 |  | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 48 | class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | { | 
|  | 50 | public: | 
| Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 51 | explicit BpSurfaceComposerClient(const sp<IBinder>& impl) | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 52 | : BpInterface<ISurfaceComposerClient>(impl) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | } | 
|  | 54 |  | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 55 | virtual ~BpSurfaceComposerClient(); | 
|  | 56 |  | 
|  | 57 | virtual status_t createSurface(const String8& name, uint32_t width, | 
|  | 58 | uint32_t height, PixelFormat format, uint32_t flags, | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 59 | sp<IBinder>* handle, | 
|  | 60 | sp<IGraphicBufferProducer>* gbp) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | Parcel data, reply; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 62 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 63 | data.writeString8(name); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 64 | data.writeUint32(width); | 
|  | 65 | data.writeUint32(height); | 
|  | 66 | data.writeInt32(static_cast<int32_t>(format)); | 
|  | 67 | data.writeUint32(flags); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | remote()->transact(CREATE_SURFACE, data, &reply); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 69 | *handle = reply.readStrongBinder(); | 
|  | 70 | *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder()); | 
|  | 71 | return reply.readInt32(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | } | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 73 |  | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 74 | virtual status_t destroySurface(const sp<IBinder>& handle) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | Parcel data, reply; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 76 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 77 | data.writeStrongBinder(handle); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | remote()->transact(DESTROY_SURFACE, data, &reply); | 
|  | 79 | return reply.readInt32(); | 
|  | 80 | } | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 81 |  | 
|  | 82 | virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const { | 
|  | 83 | Parcel data, reply; | 
|  | 84 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
|  | 85 | data.writeStrongBinder(handle); | 
|  | 86 | remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply); | 
|  | 87 | return reply.readInt32(); | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const { | 
|  | 91 | Parcel data, reply; | 
|  | 92 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
|  | 93 | data.writeStrongBinder(handle); | 
|  | 94 | remote()->transact(GET_LAYER_FRAME_STATS, data, &reply); | 
|  | 95 | reply.read(*outStats); | 
|  | 96 | return reply.readInt32(); | 
|  | 97 | } | 
| Robert Carr | 367c568 | 2016-06-20 11:55:28 -0700 | [diff] [blame] | 98 |  | 
|  | 99 | virtual status_t getTransformToDisplayInverse(const sp<IBinder>& handle, | 
|  | 100 | bool* outTransformToDisplayInverse) const { | 
|  | 101 | Parcel data, reply; | 
|  | 102 | status_t result = | 
|  | 103 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
|  | 104 | if (result != NO_ERROR) { | 
|  | 105 | return result; | 
|  | 106 | } | 
|  | 107 | result = data.writeStrongBinder(handle); | 
|  | 108 | if (result != NO_ERROR) { | 
|  | 109 | return result; | 
|  | 110 | } | 
|  | 111 | result = remote()->transact(GET_TRANSFORM_TO_DISPLAY_INVERSE, data, &reply); | 
|  | 112 | if (result != NO_ERROR) { | 
|  | 113 | return result; | 
|  | 114 | } | 
|  | 115 | int transformInverse; | 
|  | 116 | result = reply.readInt32(&transformInverse); | 
|  | 117 | if (result != NO_ERROR) { | 
|  | 118 | return result; | 
|  | 119 | } | 
|  | 120 | *outTransformToDisplayInverse = transformInverse != 0 ? true : false; | 
|  | 121 | status_t result2 = reply.readInt32(&result); | 
|  | 122 | if (result2 != NO_ERROR) { | 
|  | 123 | return result2; | 
|  | 124 | } | 
|  | 125 | return result; | 
|  | 126 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | }; | 
|  | 128 |  | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 129 | // Out-of-line virtual method definition to trigger vtable emission in this | 
|  | 130 | // translation unit (see clang warning -Wweak-vtables) | 
|  | 131 | BpSurfaceComposerClient::~BpSurfaceComposerClient() {} | 
|  | 132 |  | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 133 | IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 |  | 
|  | 135 | // ---------------------------------------------------------------------- | 
|  | 136 |  | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 137 | status_t BnSurfaceComposerClient::onTransact( | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 139 | { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | switch(code) { | 
|  | 141 | case CREATE_SURFACE: { | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 142 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 143 | String8 name = data.readString8(); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 144 | uint32_t width = data.readUint32(); | 
|  | 145 | uint32_t height = data.readUint32(); | 
|  | 146 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); | 
|  | 147 | uint32_t createFlags = data.readUint32(); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 148 | sp<IBinder> handle; | 
|  | 149 | sp<IGraphicBufferProducer> gbp; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 150 | status_t result = createSurface(name, width, height, format, | 
|  | 151 | createFlags, &handle, &gbp); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 152 | reply->writeStrongBinder(handle); | 
| Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 153 | reply->writeStrongBinder(IInterface::asBinder(gbp)); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 154 | reply->writeInt32(result); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 156 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | case DESTROY_SURFACE: { | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 158 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 159 | reply->writeInt32(destroySurface( data.readStrongBinder() ) ); | 
|  | 160 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 161 | } | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 162 | case CLEAR_LAYER_FRAME_STATS: { | 
|  | 163 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
|  | 164 | sp<IBinder> handle = data.readStrongBinder(); | 
|  | 165 | status_t result = clearLayerFrameStats(handle); | 
|  | 166 | reply->writeInt32(result); | 
|  | 167 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 168 | } | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 169 | case GET_LAYER_FRAME_STATS: { | 
|  | 170 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
|  | 171 | sp<IBinder> handle = data.readStrongBinder(); | 
|  | 172 | FrameStats stats; | 
|  | 173 | status_t result = getLayerFrameStats(handle, &stats); | 
|  | 174 | reply->write(stats); | 
|  | 175 | reply->writeInt32(result); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 177 | } | 
| Robert Carr | 367c568 | 2016-06-20 11:55:28 -0700 | [diff] [blame] | 178 | case GET_TRANSFORM_TO_DISPLAY_INVERSE: { | 
|  | 179 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
|  | 180 | sp<IBinder> handle; | 
|  | 181 | status_t result = data.readStrongBinder(&handle); | 
|  | 182 | if (result != NO_ERROR) { | 
|  | 183 | return result; | 
|  | 184 | } | 
|  | 185 | bool transformInverse = false; | 
|  | 186 | result = getTransformToDisplayInverse(handle, &transformInverse); | 
|  | 187 | if (result != NO_ERROR) { | 
|  | 188 | return result; | 
|  | 189 | } | 
|  | 190 | result = reply->writeInt32(transformInverse ? 1 : 0); | 
|  | 191 | if (result != NO_ERROR) { | 
|  | 192 | return result; | 
|  | 193 | } | 
|  | 194 | result = reply->writeInt32(NO_ERROR); | 
|  | 195 | return result; | 
|  | 196 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | default: | 
|  | 198 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 199 | } | 
|  | 200 | } | 
|  | 201 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | }; // namespace android |