| 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, | 
|  | 44 | GET_LAYER_FRAME_STATS | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | }; | 
|  | 46 |  | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 47 | class BpSurfaceComposerClient : public BpInterface<ISurfaceComposerClient> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | { | 
|  | 49 | public: | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 50 | BpSurfaceComposerClient(const sp<IBinder>& impl) | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 51 | : BpInterface<ISurfaceComposerClient>(impl) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 54 | virtual ~BpSurfaceComposerClient(); | 
|  | 55 |  | 
|  | 56 | virtual status_t createSurface(const String8& name, uint32_t width, | 
|  | 57 | uint32_t height, PixelFormat format, uint32_t flags, | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 58 | sp<IBinder>* handle, | 
|  | 59 | sp<IGraphicBufferProducer>* gbp) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | Parcel data, reply; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 61 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 62 | data.writeString8(name); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 63 | data.writeUint32(width); | 
|  | 64 | data.writeUint32(height); | 
|  | 65 | data.writeInt32(static_cast<int32_t>(format)); | 
|  | 66 | data.writeUint32(flags); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | remote()->transact(CREATE_SURFACE, data, &reply); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 68 | *handle = reply.readStrongBinder(); | 
|  | 69 | *gbp = interface_cast<IGraphicBufferProducer>(reply.readStrongBinder()); | 
|  | 70 | return reply.readInt32(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | } | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 72 |  | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 73 | virtual status_t destroySurface(const sp<IBinder>& handle) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | Parcel data, reply; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 75 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 76 | data.writeStrongBinder(handle); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | remote()->transact(DESTROY_SURFACE, data, &reply); | 
|  | 78 | return reply.readInt32(); | 
|  | 79 | } | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 80 |  | 
|  | 81 | virtual status_t clearLayerFrameStats(const sp<IBinder>& handle) const { | 
|  | 82 | Parcel data, reply; | 
|  | 83 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
|  | 84 | data.writeStrongBinder(handle); | 
|  | 85 | remote()->transact(CLEAR_LAYER_FRAME_STATS, data, &reply); | 
|  | 86 | return reply.readInt32(); | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const { | 
|  | 90 | Parcel data, reply; | 
|  | 91 | data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); | 
|  | 92 | data.writeStrongBinder(handle); | 
|  | 93 | remote()->transact(GET_LAYER_FRAME_STATS, data, &reply); | 
|  | 94 | reply.read(*outStats); | 
|  | 95 | return reply.readInt32(); | 
|  | 96 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | }; | 
|  | 98 |  | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 99 | // Out-of-line virtual method definition to trigger vtable emission in this | 
|  | 100 | // translation unit (see clang warning -Wweak-vtables) | 
|  | 101 | BpSurfaceComposerClient::~BpSurfaceComposerClient() {} | 
|  | 102 |  | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 103 | IMPLEMENT_META_INTERFACE(SurfaceComposerClient, "android.ui.ISurfaceComposerClient"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 |  | 
|  | 105 | // ---------------------------------------------------------------------- | 
|  | 106 |  | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 107 | status_t BnSurfaceComposerClient::onTransact( | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 109 | { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | switch(code) { | 
|  | 111 | case CREATE_SURFACE: { | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 112 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 113 | String8 name = data.readString8(); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 114 | uint32_t width = data.readUint32(); | 
|  | 115 | uint32_t height = data.readUint32(); | 
|  | 116 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); | 
|  | 117 | uint32_t createFlags = data.readUint32(); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 118 | sp<IBinder> handle; | 
|  | 119 | sp<IGraphicBufferProducer> gbp; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 120 | status_t result = createSurface(name, width, height, format, | 
|  | 121 | createFlags, &handle, &gbp); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 122 | reply->writeStrongBinder(handle); | 
| Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 123 | reply->writeStrongBinder(IInterface::asBinder(gbp)); | 
| Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 124 | reply->writeInt32(result); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 126 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | case DESTROY_SURFACE: { | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 128 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 129 | reply->writeInt32(destroySurface( data.readStrongBinder() ) ); | 
|  | 130 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 131 | } | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 132 | case CLEAR_LAYER_FRAME_STATS: { | 
|  | 133 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
|  | 134 | sp<IBinder> handle = data.readStrongBinder(); | 
|  | 135 | status_t result = clearLayerFrameStats(handle); | 
|  | 136 | reply->writeInt32(result); | 
|  | 137 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 138 | } | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 139 | case GET_LAYER_FRAME_STATS: { | 
|  | 140 | CHECK_INTERFACE(ISurfaceComposerClient, data, reply); | 
|  | 141 | sp<IBinder> handle = data.readStrongBinder(); | 
|  | 142 | FrameStats stats; | 
|  | 143 | status_t result = getLayerFrameStats(handle, &stats); | 
|  | 144 | reply->write(stats); | 
|  | 145 | reply->writeInt32(result); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | return NO_ERROR; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 147 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | default: | 
|  | 149 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 150 | } | 
|  | 151 | } | 
|  | 152 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | }; // namespace android |