Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Dan Stoza | 1d0359c | 2017-04-05 16:23:19 -0700 | [diff] [blame] | 17 | #include <gui/IGraphicBufferConsumer.h> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 18 | |
Dan Stoza | de7100a | 2015-03-11 16:38:47 -0700 | [diff] [blame] | 19 | #include <gui/BufferItem.h> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 20 | #include <gui/IConsumerListener.h> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 21 | |
Dan Stoza | 1d0359c | 2017-04-05 16:23:19 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
| 23 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 24 | #include <ui/Fence.h> |
Dan Stoza | 1d0359c | 2017-04-05 16:23:19 -0700 | [diff] [blame] | 25 | #include <ui/GraphicBuffer.h> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 26 | |
Dan Stoza | 1d0359c | 2017-04-05 16:23:19 -0700 | [diff] [blame] | 27 | #include <utils/NativeHandle.h> |
| 28 | #include <utils/String8.h> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 31 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 32 | namespace { // Anonymous namespace |
| 33 | |
| 34 | enum class Tag : uint32_t { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 35 | ACQUIRE_BUFFER = IBinder::FIRST_CALL_TRANSACTION, |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 36 | DETACH_BUFFER, |
| 37 | ATTACH_BUFFER, |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 38 | RELEASE_BUFFER, |
| 39 | CONSUMER_CONNECT, |
| 40 | CONSUMER_DISCONNECT, |
| 41 | GET_RELEASED_BUFFERS, |
| 42 | SET_DEFAULT_BUFFER_SIZE, |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 43 | SET_MAX_BUFFER_COUNT, |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 44 | SET_MAX_ACQUIRED_BUFFER_COUNT, |
| 45 | SET_CONSUMER_NAME, |
| 46 | SET_DEFAULT_BUFFER_FORMAT, |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 47 | SET_DEFAULT_BUFFER_DATA_SPACE, |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 48 | SET_CONSUMER_USAGE_BITS, |
Jiwen 'Steve' Cai | 2041913 | 2017-04-21 18:49:53 -0700 | [diff] [blame] | 49 | SET_CONSUMER_IS_PROTECTED, |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 50 | SET_TRANSFORM_HINT, |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 51 | GET_SIDEBAND_STREAM, |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 52 | GET_OCCUPANCY_HISTORY, |
Eino-Ville Talvala | bc2df65 | 2016-07-21 17:06:58 -0700 | [diff] [blame] | 53 | DISCARD_FREE_BUFFERS, |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 54 | DUMP_STATE, |
| 55 | LAST = DUMP_STATE, |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 58 | } // Anonymous namespace |
| 59 | |
| 60 | class BpGraphicBufferConsumer : public SafeBpInterface<IGraphicBufferConsumer> { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 61 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 62 | explicit BpGraphicBufferConsumer(const sp<IBinder>& impl) |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 63 | : SafeBpInterface<IGraphicBufferConsumer>(impl, "BpGraphicBufferConsumer") {} |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 64 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 65 | ~BpGraphicBufferConsumer() override; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 66 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 67 | status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen, |
| 68 | uint64_t maxFrameNumber) override { |
| 69 | using Signature = decltype(&IGraphicBufferConsumer::acquireBuffer); |
| 70 | return callRemote<Signature>(Tag::ACQUIRE_BUFFER, buffer, presentWhen, maxFrameNumber); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 73 | status_t detachBuffer(int slot) override { |
| 74 | using Signature = decltype(&IGraphicBufferConsumer::detachBuffer); |
| 75 | return callRemote<Signature>(Tag::DETACH_BUFFER, slot); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 78 | status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) override { |
| 79 | using Signature = decltype(&IGraphicBufferConsumer::attachBuffer); |
| 80 | return callRemote<Signature>(Tag::ATTACH_BUFFER, slot, buffer); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 83 | status_t releaseBuffer(int buf, uint64_t frameNumber, |
| 84 | EGLDisplay display __attribute__((unused)), |
| 85 | EGLSyncKHR fence __attribute__((unused)), |
| 86 | const sp<Fence>& releaseFence) override { |
| 87 | return callRemote<ReleaseBuffer>(Tag::RELEASE_BUFFER, buf, frameNumber, releaseFence); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 90 | status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) override { |
| 91 | using Signature = decltype(&IGraphicBufferConsumer::consumerConnect); |
| 92 | return callRemote<Signature>(Tag::CONSUMER_CONNECT, consumer, controlledByApp); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 95 | status_t consumerDisconnect() override { |
| 96 | return callRemote<decltype(&IGraphicBufferConsumer::consumerDisconnect)>( |
| 97 | Tag::CONSUMER_DISCONNECT); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 100 | status_t getReleasedBuffers(uint64_t* slotMask) override { |
| 101 | using Signature = decltype(&IGraphicBufferConsumer::getReleasedBuffers); |
| 102 | return callRemote<Signature>(Tag::GET_RELEASED_BUFFERS, slotMask); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 105 | status_t setDefaultBufferSize(uint32_t width, uint32_t height) override { |
| 106 | using Signature = decltype(&IGraphicBufferConsumer::setDefaultBufferSize); |
| 107 | return callRemote<Signature>(Tag::SET_DEFAULT_BUFFER_SIZE, width, height); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 110 | status_t setMaxBufferCount(int bufferCount) override { |
| 111 | using Signature = decltype(&IGraphicBufferConsumer::setMaxBufferCount); |
| 112 | return callRemote<Signature>(Tag::SET_MAX_BUFFER_COUNT, bufferCount); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 115 | status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) override { |
| 116 | using Signature = decltype(&IGraphicBufferConsumer::setMaxAcquiredBufferCount); |
| 117 | return callRemote<Signature>(Tag::SET_MAX_ACQUIRED_BUFFER_COUNT, maxAcquiredBuffers); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 120 | status_t setConsumerName(const String8& name) override { |
| 121 | using Signature = decltype(&IGraphicBufferConsumer::setConsumerName); |
| 122 | return callRemote<Signature>(Tag::SET_CONSUMER_NAME, name); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 125 | status_t setDefaultBufferFormat(PixelFormat defaultFormat) override { |
| 126 | using Signature = decltype(&IGraphicBufferConsumer::setDefaultBufferFormat); |
| 127 | return callRemote<Signature>(Tag::SET_DEFAULT_BUFFER_FORMAT, defaultFormat); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 130 | status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) override { |
| 131 | using Signature = decltype(&IGraphicBufferConsumer::setDefaultBufferDataSpace); |
| 132 | return callRemote<Signature>(Tag::SET_DEFAULT_BUFFER_DATA_SPACE, defaultDataSpace); |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame^] | 135 | status_t setConsumerUsageBits(uint64_t usage) override { |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 136 | using Signature = decltype(&IGraphicBufferConsumer::setConsumerUsageBits); |
| 137 | return callRemote<Signature>(Tag::SET_CONSUMER_USAGE_BITS, usage); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Jiwen 'Steve' Cai | 2041913 | 2017-04-21 18:49:53 -0700 | [diff] [blame] | 140 | status_t setConsumerIsProtected(bool isProtected) override { |
| 141 | using Signature = decltype(&IGraphicBufferConsumer::setConsumerIsProtected); |
| 142 | return callRemote<Signature>(Tag::SET_CONSUMER_IS_PROTECTED, isProtected); |
| 143 | } |
| 144 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 145 | status_t setTransformHint(uint32_t hint) override { |
| 146 | using Signature = decltype(&IGraphicBufferConsumer::setTransformHint); |
| 147 | return callRemote<Signature>(Tag::SET_TRANSFORM_HINT, hint); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 148 | } |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 149 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 150 | status_t getSidebandStream(sp<NativeHandle>* outStream) const override { |
| 151 | using Signature = decltype(&IGraphicBufferConsumer::getSidebandStream); |
| 152 | return callRemote<Signature>(Tag::GET_SIDEBAND_STREAM, outStream); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 155 | status_t getOccupancyHistory(bool forceFlush, |
| 156 | std::vector<OccupancyTracker::Segment>* outHistory) override { |
| 157 | using Signature = decltype(&IGraphicBufferConsumer::getOccupancyHistory); |
| 158 | return callRemote<Signature>(Tag::GET_OCCUPANCY_HISTORY, forceFlush, outHistory); |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 161 | status_t discardFreeBuffers() override { |
| 162 | return callRemote<decltype(&IGraphicBufferConsumer::discardFreeBuffers)>( |
| 163 | Tag::DISCARD_FREE_BUFFERS); |
Eino-Ville Talvala | bc2df65 | 2016-07-21 17:06:58 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 166 | status_t dumpState(const String8& prefix, String8* outResult) const override { |
| 167 | using Signature = status_t (IGraphicBufferConsumer::*)(const String8&, String8*) const; |
| 168 | return callRemote<Signature>(Tag::DUMP_STATE, prefix, outResult); |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 169 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
Dan Stoza | 1d0359c | 2017-04-05 16:23:19 -0700 | [diff] [blame] | 172 | // Out-of-line virtual method definition to trigger vtable emission in this translation unit |
| 173 | // (see clang warning -Wweak-vtables) |
| 174 | BpGraphicBufferConsumer::~BpGraphicBufferConsumer() = default; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 175 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 176 | IMPLEMENT_META_INTERFACE(GraphicBufferConsumer, "android.gui.IGraphicBufferConsumer"); |
| 177 | |
Dan Stoza | 1d0359c | 2017-04-05 16:23:19 -0700 | [diff] [blame] | 178 | status_t BnGraphicBufferConsumer::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 179 | uint32_t flags) { |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 180 | if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) { |
| 181 | return BBinder::onTransact(code, data, reply, flags); |
| 182 | } |
| 183 | auto tag = static_cast<Tag>(code); |
| 184 | switch (tag) { |
| 185 | case Tag::ACQUIRE_BUFFER: |
| 186 | return callLocal(data, reply, &IGraphicBufferConsumer::acquireBuffer); |
| 187 | case Tag::DETACH_BUFFER: |
| 188 | return callLocal(data, reply, &IGraphicBufferConsumer::detachBuffer); |
| 189 | case Tag::ATTACH_BUFFER: |
| 190 | return callLocal(data, reply, &IGraphicBufferConsumer::attachBuffer); |
| 191 | case Tag::RELEASE_BUFFER: |
| 192 | return callLocal(data, reply, &IGraphicBufferConsumer::releaseHelper); |
| 193 | case Tag::CONSUMER_CONNECT: |
| 194 | return callLocal(data, reply, &IGraphicBufferConsumer::consumerConnect); |
| 195 | case Tag::CONSUMER_DISCONNECT: |
| 196 | return callLocal(data, reply, &IGraphicBufferConsumer::consumerDisconnect); |
| 197 | case Tag::GET_RELEASED_BUFFERS: |
| 198 | return callLocal(data, reply, &IGraphicBufferConsumer::getReleasedBuffers); |
| 199 | case Tag::SET_DEFAULT_BUFFER_SIZE: |
| 200 | return callLocal(data, reply, &IGraphicBufferConsumer::setDefaultBufferSize); |
| 201 | case Tag::SET_MAX_BUFFER_COUNT: |
| 202 | return callLocal(data, reply, &IGraphicBufferConsumer::setMaxBufferCount); |
| 203 | case Tag::SET_MAX_ACQUIRED_BUFFER_COUNT: |
| 204 | return callLocal(data, reply, &IGraphicBufferConsumer::setMaxAcquiredBufferCount); |
| 205 | case Tag::SET_CONSUMER_NAME: |
| 206 | return callLocal(data, reply, &IGraphicBufferConsumer::setConsumerName); |
| 207 | case Tag::SET_DEFAULT_BUFFER_FORMAT: |
| 208 | return callLocal(data, reply, &IGraphicBufferConsumer::setDefaultBufferFormat); |
| 209 | case Tag::SET_DEFAULT_BUFFER_DATA_SPACE: |
| 210 | return callLocal(data, reply, &IGraphicBufferConsumer::setDefaultBufferDataSpace); |
| 211 | case Tag::SET_CONSUMER_USAGE_BITS: |
| 212 | return callLocal(data, reply, &IGraphicBufferConsumer::setConsumerUsageBits); |
Jiwen 'Steve' Cai | 2041913 | 2017-04-21 18:49:53 -0700 | [diff] [blame] | 213 | case Tag::SET_CONSUMER_IS_PROTECTED: |
| 214 | return callLocal(data, reply, &IGraphicBufferConsumer::setConsumerIsProtected); |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 215 | case Tag::SET_TRANSFORM_HINT: |
| 216 | return callLocal(data, reply, &IGraphicBufferConsumer::setTransformHint); |
| 217 | case Tag::GET_SIDEBAND_STREAM: |
| 218 | return callLocal(data, reply, &IGraphicBufferConsumer::getSidebandStream); |
| 219 | case Tag::GET_OCCUPANCY_HISTORY: |
| 220 | return callLocal(data, reply, &IGraphicBufferConsumer::getOccupancyHistory); |
| 221 | case Tag::DISCARD_FREE_BUFFERS: |
| 222 | return callLocal(data, reply, &IGraphicBufferConsumer::discardFreeBuffers); |
| 223 | case Tag::DUMP_STATE: { |
| 224 | using Signature = status_t (IGraphicBufferConsumer::*)(const String8&, String8*) const; |
| 225 | return callLocal<Signature>(data, reply, &IGraphicBufferConsumer::dumpState); |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 226 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 227 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Dan Stoza | 4b5fbdb | 2017-04-10 13:41:53 -0700 | [diff] [blame] | 230 | } // namespace android |