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