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