Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #include <stdint.h> |
| 18 | #include <sys/types.h> |
| 19 | |
| 20 | #include <utils/Errors.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 21 | #include <utils/NativeHandle.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 22 | #include <utils/RefBase.h> |
Brian Anderson | 175a720 | 2016-10-10 16:52:56 -0700 | [diff] [blame] | 23 | #include <utils/String8.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 24 | #include <utils/Timers.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 25 | #include <utils/Vector.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 26 | |
| 27 | #include <binder/Parcel.h> |
| 28 | #include <binder/IInterface.h> |
| 29 | |
Chia-I Wu | c79a296 | 2017-05-15 10:32:27 -0700 | [diff] [blame] | 30 | #include <gui/BufferQueueDefs.h> |
Ady Abraham | 107788e | 2023-10-17 12:31:08 -0700 | [diff] [blame] | 31 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 32 | #include <gui/IGraphicBufferProducer.h> |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 33 | #include <gui/IProducerListener.h> |
Ady Abraham | 6cdd3fd | 2023-09-07 18:45:58 -0700 | [diff] [blame] | 34 | #include <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h> |
| 35 | #include <gui/bufferqueue/2.0/H2BGraphicBufferProducer.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 36 | |
| 37 | namespace android { |
| 38 | // ---------------------------------------------------------------------------- |
| 39 | |
Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 40 | using H2BGraphicBufferProducerV1_0 = |
| 41 | ::android::hardware::graphics::bufferqueue::V1_0::utils:: |
| 42 | H2BGraphicBufferProducer; |
| 43 | using H2BGraphicBufferProducerV2_0 = |
| 44 | ::android::hardware::graphics::bufferqueue::V2_0::utils:: |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 45 | H2BGraphicBufferProducer; |
| 46 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 47 | enum { |
| 48 | REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 49 | DEQUEUE_BUFFER, |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 50 | DETACH_BUFFER, |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 51 | DETACH_NEXT_BUFFER, |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 52 | ATTACH_BUFFER, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 53 | QUEUE_BUFFER, |
| 54 | CANCEL_BUFFER, |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 55 | QUERY, |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 56 | CONNECT, |
| 57 | DISCONNECT, |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 58 | SET_SIDEBAND_STREAM, |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 59 | ALLOCATE_BUFFERS, |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 60 | ALLOW_ALLOCATION, |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 61 | SET_GENERATION_NUMBER, |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 62 | GET_CONSUMER_NAME, |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 63 | SET_MAX_DEQUEUED_BUFFER_COUNT, |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 64 | SET_ASYNC_MODE, |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 65 | SET_SHARED_BUFFER_MODE, |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 66 | SET_AUTO_REFRESH, |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 67 | SET_DEQUEUE_TIMEOUT, |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 68 | GET_LAST_QUEUED_BUFFER, |
Pablo Ceballos | fc35258 | 2016-06-30 17:22:20 -0700 | [diff] [blame] | 69 | GET_FRAME_TIMESTAMPS, |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 70 | GET_UNIQUE_ID, |
| 71 | GET_CONSUMER_USAGE, |
Sungtak Lee | 3249fb6 | 2019-03-02 16:40:47 -0800 | [diff] [blame] | 72 | SET_LEGACY_BUFFER_DROP, |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 73 | SET_AUTO_PREROTATION, |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 74 | REQUEST_BUFFERS, |
| 75 | DEQUEUE_BUFFERS, |
| 76 | DETACH_BUFFERS, |
| 77 | ATTACH_BUFFERS, |
| 78 | QUEUE_BUFFERS, |
| 79 | CANCEL_BUFFERS, |
| 80 | QUERY_MULTIPLE, |
John Reck | aa5a0b2 | 2021-05-18 00:42:56 -0400 | [diff] [blame] | 81 | GET_LAST_QUEUED_BUFFER2, |
Ady Abraham | 6cdd3fd | 2023-09-07 18:45:58 -0700 | [diff] [blame] | 82 | SET_FRAME_RATE, |
John Reck | db164ff | 2024-04-03 16:59:28 -0400 | [diff] [blame] | 83 | SET_ADDITIONAL_OPTIONS, |
Jim Shargo | 2e614a4 | 2024-10-02 19:31:53 +0000 | [diff] [blame] | 84 | SET_MAX_BUFER_COUNT_EXTENDED, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 87 | class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 88 | { |
| 89 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 90 | explicit BpGraphicBufferProducer(const sp<IBinder>& impl) |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 91 | : BpInterface<IGraphicBufferProducer>(impl) |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 92 | { |
| 93 | } |
| 94 | |
Yi Kong | ca03851 | 2017-05-02 16:55:24 -0700 | [diff] [blame] | 95 | ~BpGraphicBufferProducer() override; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 96 | |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 97 | virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 98 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 99 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 100 | data.writeInt32(bufferIdx); |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 101 | status_t result = remote()->transact(REQUEST_BUFFER, data, &reply); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 102 | if (result != NO_ERROR) { |
| 103 | return result; |
| 104 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 105 | bool nonNull = reply.readInt32(); |
| 106 | if (nonNull) { |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 107 | *buf = sp<GraphicBuffer>::make(); |
Lingyun Zhu | 2aff702 | 2012-11-20 19:24:35 +0800 | [diff] [blame] | 108 | result = reply.read(**buf); |
| 109 | if(result != NO_ERROR) { |
| 110 | (*buf).clear(); |
| 111 | return result; |
| 112 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 113 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 114 | result = reply.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 115 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 118 | virtual status_t requestBuffers( |
| 119 | const std::vector<int32_t>& slots, |
| 120 | std::vector<RequestBufferOutput>* outputs) override { |
| 121 | Parcel data, reply; |
| 122 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 123 | data.writeInt32Vector(slots); |
| 124 | status_t result = remote()->transact(REQUEST_BUFFERS, data, &reply); |
| 125 | if (result != NO_ERROR) { |
| 126 | return result; |
| 127 | } |
| 128 | result = reply.resizeOutVector(outputs); |
| 129 | for (RequestBufferOutput& output : *outputs) { |
| 130 | if (result != NO_ERROR) { |
| 131 | return result; |
| 132 | } |
| 133 | result = reply.read(output); |
| 134 | } |
| 135 | |
| 136 | return result; |
| 137 | } |
| 138 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 139 | virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) { |
| 140 | Parcel data, reply; |
| 141 | data.writeInterfaceToken( |
| 142 | IGraphicBufferProducer::getInterfaceDescriptor()); |
| 143 | data.writeInt32(maxDequeuedBuffers); |
| 144 | status_t result = remote()->transact(SET_MAX_DEQUEUED_BUFFER_COUNT, |
| 145 | data, &reply); |
| 146 | if (result != NO_ERROR) { |
| 147 | return result; |
| 148 | } |
| 149 | result = reply.readInt32(); |
| 150 | return result; |
| 151 | } |
| 152 | |
Jim Shargo | 2e614a4 | 2024-10-02 19:31:53 +0000 | [diff] [blame] | 153 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS) |
| 154 | status_t extendSlotCount(int size) override { |
| 155 | Parcel data, reply; |
| 156 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 157 | data.writeInt32(size); |
| 158 | status_t result = remote()->transact(SET_MAX_BUFER_COUNT_EXTENDED, data, &reply); |
| 159 | if (result != NO_ERROR) { |
| 160 | return result; |
| 161 | } |
| 162 | result = reply.readInt32(); |
| 163 | return result; |
| 164 | } |
| 165 | #endif |
| 166 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 167 | virtual status_t setAsyncMode(bool async) { |
| 168 | Parcel data, reply; |
| 169 | data.writeInterfaceToken( |
| 170 | IGraphicBufferProducer::getInterfaceDescriptor()); |
| 171 | data.writeInt32(async); |
| 172 | status_t result = remote()->transact(SET_ASYNC_MODE, |
| 173 | data, &reply); |
| 174 | if (result != NO_ERROR) { |
| 175 | return result; |
| 176 | } |
| 177 | result = reply.readInt32(); |
| 178 | return result; |
| 179 | } |
| 180 | |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 181 | virtual status_t dequeueBuffer(int* buf, sp<Fence>* fence, uint32_t width, uint32_t height, |
| 182 | PixelFormat format, uint64_t usage, uint64_t* outBufferAge, |
| 183 | FrameEventHistoryDelta* outTimestamps) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 184 | Parcel data, reply; |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 185 | bool getFrameTimestamps = (outTimestamps != nullptr); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 186 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 187 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 188 | data.writeUint32(width); |
| 189 | data.writeUint32(height); |
| 190 | data.writeInt32(static_cast<int32_t>(format)); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 191 | data.writeUint64(usage); |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 192 | data.writeBool(getFrameTimestamps); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 193 | |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 194 | status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); |
| 195 | if (result != NO_ERROR) { |
| 196 | return result; |
| 197 | } |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 198 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 199 | *buf = reply.readInt32(); |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 200 | *fence = sp<Fence>::make(); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 201 | result = reply.read(**fence); |
| 202 | if (result != NO_ERROR) { |
| 203 | fence->clear(); |
| 204 | return result; |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 205 | } |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 206 | if (outBufferAge) { |
| 207 | result = reply.readUint64(outBufferAge); |
| 208 | } else { |
| 209 | // Read the value even if outBufferAge is nullptr: |
| 210 | uint64_t bufferAge; |
| 211 | result = reply.readUint64(&bufferAge); |
| 212 | } |
| 213 | if (result != NO_ERROR) { |
| 214 | ALOGE("IGBP::dequeueBuffer failed to read buffer age: %d", result); |
| 215 | return result; |
| 216 | } |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 217 | if (getFrameTimestamps) { |
| 218 | result = reply.read(*outTimestamps); |
| 219 | if (result != NO_ERROR) { |
| 220 | ALOGE("IGBP::dequeueBuffer failed to read timestamps: %d", |
| 221 | result); |
| 222 | return result; |
| 223 | } |
| 224 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 225 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 226 | return result; |
| 227 | } |
| 228 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 229 | virtual status_t dequeueBuffers( |
| 230 | const std::vector<DequeueBufferInput>& inputs, |
| 231 | std::vector<DequeueBufferOutput>* outputs) { |
| 232 | Parcel data, reply; |
| 233 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 234 | data.writeVectorSize(inputs); |
| 235 | for (const auto& input : inputs) { |
| 236 | data.write(input); |
| 237 | } |
| 238 | status_t result = remote()->transact(DEQUEUE_BUFFERS, data, &reply); |
| 239 | if (result != NO_ERROR) { |
| 240 | return result; |
| 241 | } |
| 242 | result = reply.resizeOutVector(outputs); |
| 243 | for (auto& output : *outputs) { |
| 244 | if (result != NO_ERROR) { |
| 245 | return result; |
| 246 | } |
| 247 | result = reply.read(output); |
| 248 | } |
| 249 | return result; |
| 250 | } |
| 251 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 252 | virtual status_t detachBuffer(int slot) { |
| 253 | Parcel data, reply; |
| 254 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 255 | data.writeInt32(slot); |
| 256 | status_t result = remote()->transact(DETACH_BUFFER, data, &reply); |
| 257 | if (result != NO_ERROR) { |
| 258 | return result; |
| 259 | } |
| 260 | result = reply.readInt32(); |
| 261 | return result; |
| 262 | } |
| 263 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 264 | virtual status_t detachBuffers(const std::vector<int32_t>& slots, |
| 265 | std::vector<status_t>* results) { |
| 266 | Parcel data, reply; |
| 267 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 268 | data.writeInt32Vector(slots); |
| 269 | status_t result = remote()->transact(DETACH_BUFFERS, data, &reply); |
| 270 | if (result != NO_ERROR) { |
| 271 | return result; |
| 272 | } |
| 273 | result = reply.readInt32Vector(results); |
| 274 | return result; |
| 275 | } |
| 276 | |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 277 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, |
| 278 | sp<Fence>* outFence) { |
Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 279 | if (outBuffer == nullptr) { |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 280 | ALOGE("detachNextBuffer: outBuffer must not be NULL"); |
| 281 | return BAD_VALUE; |
Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 282 | } else if (outFence == nullptr) { |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 283 | ALOGE("detachNextBuffer: outFence must not be NULL"); |
| 284 | return BAD_VALUE; |
| 285 | } |
| 286 | Parcel data, reply; |
| 287 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 288 | status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply); |
| 289 | if (result != NO_ERROR) { |
| 290 | return result; |
| 291 | } |
| 292 | result = reply.readInt32(); |
| 293 | if (result == NO_ERROR) { |
| 294 | bool nonNull = reply.readInt32(); |
| 295 | if (nonNull) { |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 296 | *outBuffer = sp<GraphicBuffer>::make(); |
Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 297 | result = reply.read(**outBuffer); |
| 298 | if (result != NO_ERROR) { |
| 299 | outBuffer->clear(); |
| 300 | return result; |
| 301 | } |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 302 | } |
| 303 | nonNull = reply.readInt32(); |
| 304 | if (nonNull) { |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 305 | *outFence = sp<Fence>::make(); |
Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 306 | result = reply.read(**outFence); |
| 307 | if (result != NO_ERROR) { |
| 308 | outBuffer->clear(); |
| 309 | outFence->clear(); |
| 310 | return result; |
| 311 | } |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | return result; |
| 315 | } |
| 316 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 317 | virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) { |
| 318 | Parcel data, reply; |
| 319 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 320 | data.write(*buffer.get()); |
| 321 | status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); |
| 322 | if (result != NO_ERROR) { |
| 323 | return result; |
| 324 | } |
Chia-I Wu | c79a296 | 2017-05-15 10:32:27 -0700 | [diff] [blame] | 325 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 326 | *slot = reply.readInt32(); |
| 327 | result = reply.readInt32(); |
Chia-I Wu | c79a296 | 2017-05-15 10:32:27 -0700 | [diff] [blame] | 328 | if (result == NO_ERROR && |
| 329 | (*slot < 0 || *slot >= BufferQueueDefs::NUM_BUFFER_SLOTS)) { |
| 330 | ALOGE("attachBuffer returned invalid slot %d", *slot); |
| 331 | android_errorWriteLog(0x534e4554, "37478824"); |
| 332 | return UNKNOWN_ERROR; |
| 333 | } |
| 334 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 335 | return result; |
| 336 | } |
| 337 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 338 | virtual status_t attachBuffers( |
| 339 | const std::vector<sp<GraphicBuffer>>& buffers, |
| 340 | std::vector<AttachBufferOutput>* outputs) { |
| 341 | Parcel data, reply; |
| 342 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 343 | data.writeVectorSize(buffers); |
| 344 | for (const sp<GraphicBuffer>& buffer : buffers) { |
| 345 | data.write(*buffer.get()); |
| 346 | } |
| 347 | status_t result = remote()->transact(ATTACH_BUFFERS, data, &reply); |
| 348 | if (result != NO_ERROR) { |
| 349 | return result; |
| 350 | } |
| 351 | result = reply.resizeOutVector(outputs); |
| 352 | for (AttachBufferOutput& output : *outputs) { |
| 353 | if (result != NO_ERROR) { |
| 354 | return result; |
| 355 | } |
| 356 | result = reply.read(output); |
| 357 | } |
| 358 | if (result == NO_ERROR) { |
| 359 | for (AttachBufferOutput& output : *outputs) { |
| 360 | if (output.result == NO_ERROR && output.slot < 0) { |
| 361 | ALOGE("attachBuffers returned invalid slot %d", |
| 362 | output.slot); |
| 363 | android_errorWriteLog(0x534e4554, "37478824"); |
| 364 | output.result = UNKNOWN_ERROR; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | return result; |
| 369 | } |
| 370 | |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 371 | virtual status_t queueBuffer(int buf, |
| 372 | const QueueBufferInput& input, QueueBufferOutput* output) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 373 | Parcel data, reply; |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 374 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 375 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 376 | data.writeInt32(buf); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 377 | data.write(input); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 378 | |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 379 | status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); |
| 380 | if (result != NO_ERROR) { |
| 381 | return result; |
| 382 | } |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 383 | |
| 384 | result = reply.read(*output); |
| 385 | if (result != NO_ERROR) { |
| 386 | return result; |
| 387 | } |
| 388 | |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 389 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 390 | return result; |
| 391 | } |
| 392 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 393 | virtual status_t queueBuffers(const std::vector<QueueBufferInput>& inputs, |
| 394 | std::vector<QueueBufferOutput>* outputs) { |
| 395 | Parcel data, reply; |
| 396 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 397 | data.writeVectorSize(inputs); |
| 398 | for (const QueueBufferInput& input : inputs) { |
| 399 | data.write(input); |
| 400 | } |
| 401 | status_t result = remote()->transact(QUEUE_BUFFERS, data, &reply); |
| 402 | if (result != NO_ERROR) { |
| 403 | return result; |
| 404 | } |
| 405 | result = reply.resizeOutVector(outputs); |
| 406 | for (QueueBufferOutput& output : *outputs) { |
| 407 | if (result != NO_ERROR) { |
| 408 | return result; |
| 409 | } |
| 410 | result = reply.read(output); |
| 411 | } |
| 412 | return result; |
| 413 | } |
| 414 | |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 415 | virtual status_t cancelBuffer(int buf, const sp<Fence>& fence) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 416 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 417 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 418 | data.writeInt32(buf); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 419 | data.write(*fence.get()); |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 420 | status_t result = remote()->transact(CANCEL_BUFFER, data, &reply); |
| 421 | if (result != NO_ERROR) { |
| 422 | return result; |
| 423 | } |
| 424 | result = reply.readInt32(); |
| 425 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 428 | virtual status_t cancelBuffers( |
| 429 | const std::vector<CancelBufferInput>& inputs, |
| 430 | std::vector<status_t>* results) { |
| 431 | Parcel data, reply; |
| 432 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 433 | data.writeVectorSize(inputs); |
| 434 | for (const CancelBufferInput& input : inputs) { |
| 435 | data.write(input); |
| 436 | } |
| 437 | status_t result = remote()->transact(CANCEL_BUFFERS, data, &reply); |
| 438 | if (result != NO_ERROR) { |
| 439 | return result; |
| 440 | } |
| 441 | result = reply.readInt32Vector(results); |
| 442 | return result; |
| 443 | } |
| 444 | |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 445 | virtual int query(int what, int* value) { |
| 446 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 447 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 448 | data.writeInt32(what); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 449 | status_t result = remote()->transact(QUERY, data, &reply); |
| 450 | if (result != NO_ERROR) { |
| 451 | return result; |
| 452 | } |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 453 | value[0] = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 454 | result = reply.readInt32(); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 455 | return result; |
| 456 | } |
| 457 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 458 | virtual status_t query(const std::vector<int32_t> inputs, |
| 459 | std::vector<QueryOutput>* outputs) { |
| 460 | Parcel data, reply; |
| 461 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 462 | data.writeInt32Vector(inputs); |
| 463 | status_t result = remote()->transact(QUERY_MULTIPLE, data, &reply); |
| 464 | if (result != NO_ERROR) { |
| 465 | return result; |
| 466 | } |
| 467 | result = reply.resizeOutVector(outputs); |
| 468 | for (QueryOutput& output : *outputs) { |
| 469 | if (result != NO_ERROR) { |
| 470 | return result; |
| 471 | } |
| 472 | result = reply.read(output); |
| 473 | } |
| 474 | return result; |
| 475 | } |
| 476 | |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 477 | virtual status_t connect(const sp<IProducerListener>& listener, |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 478 | int api, bool producerControlledByApp, QueueBufferOutput* output) { |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 479 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 480 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 481 | if (listener != nullptr) { |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 482 | data.writeInt32(1); |
Marco Nelissen | 097ca27 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 483 | data.writeStrongBinder(IInterface::asBinder(listener)); |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 484 | } else { |
| 485 | data.writeInt32(0); |
| 486 | } |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 487 | data.writeInt32(api); |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 488 | data.writeInt32(producerControlledByApp); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 489 | status_t result = remote()->transact(CONNECT, data, &reply); |
| 490 | if (result != NO_ERROR) { |
| 491 | return result; |
| 492 | } |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 493 | reply.read(*output); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 494 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 495 | return result; |
| 496 | } |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 497 | |
Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 498 | virtual status_t disconnect(int api, DisconnectMode mode) { |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 499 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 500 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 501 | data.writeInt32(api); |
Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 502 | data.writeInt32(static_cast<int32_t>(mode)); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 503 | status_t result =remote()->transact(DISCONNECT, data, &reply); |
| 504 | if (result != NO_ERROR) { |
| 505 | return result; |
| 506 | } |
| 507 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 508 | return result; |
| 509 | } |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 510 | |
| 511 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream) { |
| 512 | Parcel data, reply; |
| 513 | status_t result; |
| 514 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 515 | if (stream.get()) { |
| 516 | data.writeInt32(true); |
| 517 | data.writeNativeHandle(stream->handle()); |
| 518 | } else { |
| 519 | data.writeInt32(false); |
| 520 | } |
| 521 | if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) { |
| 522 | result = reply.readInt32(); |
| 523 | } |
| 524 | return result; |
| 525 | } |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 526 | |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 527 | virtual void allocateBuffers(uint32_t width, uint32_t height, |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 528 | PixelFormat format, uint64_t usage) { |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 529 | Parcel data, reply; |
| 530 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 531 | data.writeUint32(width); |
| 532 | data.writeUint32(height); |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 533 | data.writeInt32(static_cast<int32_t>(format)); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 534 | data.writeUint64(usage); |
Steven Moreland | 366eb42 | 2019-04-01 19:22:32 -0700 | [diff] [blame] | 535 | status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply, IBinder::FLAG_ONEWAY); |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 536 | if (result != NO_ERROR) { |
| 537 | ALOGE("allocateBuffers failed to transact: %d", result); |
| 538 | } |
| 539 | } |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 540 | |
| 541 | virtual status_t allowAllocation(bool allow) { |
| 542 | Parcel data, reply; |
| 543 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 544 | data.writeInt32(static_cast<int32_t>(allow)); |
| 545 | status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply); |
| 546 | if (result != NO_ERROR) { |
| 547 | return result; |
| 548 | } |
| 549 | result = reply.readInt32(); |
| 550 | return result; |
| 551 | } |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 552 | |
| 553 | virtual status_t setGenerationNumber(uint32_t generationNumber) { |
| 554 | Parcel data, reply; |
| 555 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 556 | data.writeUint32(generationNumber); |
| 557 | status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply); |
| 558 | if (result == NO_ERROR) { |
| 559 | result = reply.readInt32(); |
| 560 | } |
| 561 | return result; |
| 562 | } |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 563 | |
| 564 | virtual String8 getConsumerName() const { |
| 565 | Parcel data, reply; |
| 566 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 567 | status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply); |
| 568 | if (result != NO_ERROR) { |
| 569 | ALOGE("getConsumerName failed to transact: %d", result); |
| 570 | return String8("TransactFailed"); |
| 571 | } |
| 572 | return reply.readString8(); |
| 573 | } |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 574 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 575 | virtual status_t setSharedBufferMode(bool sharedBufferMode) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 576 | Parcel data, reply; |
| 577 | data.writeInterfaceToken( |
| 578 | IGraphicBufferProducer::getInterfaceDescriptor()); |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 579 | data.writeInt32(sharedBufferMode); |
| 580 | status_t result = remote()->transact(SET_SHARED_BUFFER_MODE, data, |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 581 | &reply); |
| 582 | if (result == NO_ERROR) { |
| 583 | result = reply.readInt32(); |
| 584 | } |
| 585 | return result; |
| 586 | } |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 587 | |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 588 | virtual status_t setAutoRefresh(bool autoRefresh) { |
| 589 | Parcel data, reply; |
| 590 | data.writeInterfaceToken( |
| 591 | IGraphicBufferProducer::getInterfaceDescriptor()); |
| 592 | data.writeInt32(autoRefresh); |
| 593 | status_t result = remote()->transact(SET_AUTO_REFRESH, data, &reply); |
| 594 | if (result == NO_ERROR) { |
| 595 | result = reply.readInt32(); |
| 596 | } |
| 597 | return result; |
| 598 | } |
| 599 | |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 600 | virtual status_t setDequeueTimeout(nsecs_t timeout) { |
| 601 | Parcel data, reply; |
| 602 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 603 | data.writeInt64(timeout); |
| 604 | status_t result = remote()->transact(SET_DEQUEUE_TIMEOUT, data, &reply); |
| 605 | if (result != NO_ERROR) { |
| 606 | ALOGE("setDequeueTimeout failed to transact: %d", result); |
| 607 | return result; |
| 608 | } |
| 609 | return reply.readInt32(); |
| 610 | } |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 611 | |
Sungtak Lee | 3249fb6 | 2019-03-02 16:40:47 -0800 | [diff] [blame] | 612 | virtual status_t setLegacyBufferDrop(bool drop) { |
| 613 | Parcel data, reply; |
| 614 | data.writeInterfaceToken( |
| 615 | IGraphicBufferProducer::getInterfaceDescriptor()); |
| 616 | data.writeInt32(drop); |
| 617 | status_t result = remote()->transact(SET_LEGACY_BUFFER_DROP, |
| 618 | data, &reply); |
| 619 | if (result != NO_ERROR) { |
| 620 | return result; |
| 621 | } |
| 622 | result = reply.readInt32(); |
| 623 | return result; |
| 624 | } |
| 625 | |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 626 | virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 627 | sp<Fence>* outFence, float outTransformMatrix[16]) override { |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 628 | Parcel data, reply; |
| 629 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 630 | status_t result = remote()->transact(GET_LAST_QUEUED_BUFFER, data, |
| 631 | &reply); |
| 632 | if (result != NO_ERROR) { |
| 633 | ALOGE("getLastQueuedBuffer failed to transact: %d", result); |
| 634 | return result; |
| 635 | } |
| 636 | result = reply.readInt32(); |
| 637 | if (result != NO_ERROR) { |
| 638 | return result; |
| 639 | } |
John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 640 | bool hasBuffer = reply.readBool(); |
| 641 | sp<GraphicBuffer> buffer; |
| 642 | if (hasBuffer) { |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 643 | buffer = sp<GraphicBuffer>::make(); |
John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 644 | result = reply.read(*buffer); |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 645 | if (result == NO_ERROR) { |
| 646 | result = reply.read(outTransformMatrix, sizeof(float) * 16); |
| 647 | } |
John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 648 | } |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 649 | if (result != NO_ERROR) { |
| 650 | ALOGE("getLastQueuedBuffer failed to read buffer: %d", result); |
| 651 | return result; |
| 652 | } |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 653 | sp<Fence> fence = sp<Fence>::make(); |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 654 | result = reply.read(*fence); |
| 655 | if (result != NO_ERROR) { |
| 656 | ALOGE("getLastQueuedBuffer failed to read fence: %d", result); |
| 657 | return result; |
| 658 | } |
| 659 | *outBuffer = buffer; |
| 660 | *outFence = fence; |
| 661 | return result; |
| 662 | } |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 663 | |
John Reck | aa5a0b2 | 2021-05-18 00:42:56 -0400 | [diff] [blame] | 664 | virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence, |
| 665 | Rect* outRect, uint32_t* outTransform) override { |
| 666 | Parcel data, reply; |
| 667 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 668 | status_t result = remote()->transact(GET_LAST_QUEUED_BUFFER2, data, &reply); |
| 669 | if (result != NO_ERROR) { |
| 670 | ALOGE("getLastQueuedBuffer failed to transact: %d", result); |
| 671 | return result; |
| 672 | } |
| 673 | status_t remoteError = NO_ERROR; |
| 674 | result = reply.readInt32(&remoteError); |
| 675 | if (result != NO_ERROR) { |
| 676 | ALOGE("getLastQueuedBuffer failed to read status: %d", result); |
| 677 | return result; |
| 678 | } |
| 679 | if (remoteError != NO_ERROR) { |
| 680 | return remoteError; |
| 681 | } |
| 682 | bool hasBuffer = false; |
| 683 | result = reply.readBool(&hasBuffer); |
| 684 | if (result != NO_ERROR) { |
| 685 | ALOGE("getLastQueuedBuffer failed to read buffer: %d", result); |
| 686 | return result; |
| 687 | } |
| 688 | sp<GraphicBuffer> buffer; |
| 689 | if (hasBuffer) { |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 690 | buffer = sp<GraphicBuffer>::make(); |
John Reck | aa5a0b2 | 2021-05-18 00:42:56 -0400 | [diff] [blame] | 691 | result = reply.read(*buffer); |
| 692 | if (result == NO_ERROR) { |
| 693 | result = reply.read(*outRect); |
| 694 | } |
| 695 | if (result == NO_ERROR) { |
| 696 | result = reply.readUint32(outTransform); |
| 697 | } |
| 698 | } |
| 699 | if (result != NO_ERROR) { |
| 700 | ALOGE("getLastQueuedBuffer failed to read buffer: %d", result); |
| 701 | return result; |
| 702 | } |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 703 | sp<Fence> fence = sp<Fence>::make(); |
John Reck | aa5a0b2 | 2021-05-18 00:42:56 -0400 | [diff] [blame] | 704 | result = reply.read(*fence); |
| 705 | if (result != NO_ERROR) { |
| 706 | ALOGE("getLastQueuedBuffer failed to read fence: %d", result); |
| 707 | return result; |
| 708 | } |
| 709 | *outBuffer = buffer; |
| 710 | *outFence = fence; |
| 711 | return result; |
| 712 | } |
| 713 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 714 | virtual void getFrameTimestamps(FrameEventHistoryDelta* outDelta) { |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 715 | Parcel data, reply; |
| 716 | status_t result = data.writeInterfaceToken( |
| 717 | IGraphicBufferProducer::getInterfaceDescriptor()); |
| 718 | if (result != NO_ERROR) { |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 719 | ALOGE("IGBP::getFrameTimestamps failed to write token: %d", result); |
| 720 | return; |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 721 | } |
| 722 | result = remote()->transact(GET_FRAME_TIMESTAMPS, data, &reply); |
| 723 | if (result != NO_ERROR) { |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 724 | ALOGE("IGBP::getFrameTimestamps failed to transact: %d", result); |
| 725 | return; |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 726 | } |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 727 | result = reply.read(*outDelta); |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 728 | if (result != NO_ERROR) { |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 729 | ALOGE("IGBP::getFrameTimestamps failed to read timestamps: %d", |
| 730 | result); |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 731 | } |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 732 | } |
Pablo Ceballos | 6155b40 | 2016-06-30 17:01:49 -0700 | [diff] [blame] | 733 | |
Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 734 | virtual status_t getUniqueId(uint64_t* outId) const { |
| 735 | Parcel data, reply; |
| 736 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 737 | status_t result = remote()->transact(GET_UNIQUE_ID, data, &reply); |
| 738 | if (result != NO_ERROR) { |
| 739 | ALOGE("getUniqueId failed to transact: %d", result); |
| 740 | } |
| 741 | status_t actualResult = NO_ERROR; |
| 742 | result = reply.readInt32(&actualResult); |
| 743 | if (result != NO_ERROR) { |
| 744 | return result; |
| 745 | } |
| 746 | result = reply.readUint64(outId); |
| 747 | if (result != NO_ERROR) { |
| 748 | return result; |
| 749 | } |
| 750 | return actualResult; |
| 751 | } |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 752 | |
| 753 | virtual status_t getConsumerUsage(uint64_t* outUsage) const { |
| 754 | Parcel data, reply; |
| 755 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 756 | status_t result = remote()->transact(GET_CONSUMER_USAGE, data, &reply); |
| 757 | if (result != NO_ERROR) { |
| 758 | ALOGE("getConsumerUsage failed to transact: %d", result); |
| 759 | } |
| 760 | status_t actualResult = NO_ERROR; |
| 761 | result = reply.readInt32(&actualResult); |
| 762 | if (result != NO_ERROR) { |
| 763 | return result; |
| 764 | } |
| 765 | result = reply.readUint64(outUsage); |
| 766 | if (result != NO_ERROR) { |
| 767 | return result; |
| 768 | } |
| 769 | return actualResult; |
| 770 | } |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 771 | |
| 772 | virtual status_t setAutoPrerotation(bool autoPrerotation) { |
| 773 | Parcel data, reply; |
| 774 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 775 | data.writeBool(autoPrerotation); |
| 776 | status_t result = remote()->transact(SET_AUTO_PREROTATION, data, &reply); |
| 777 | if (result == NO_ERROR) { |
| 778 | result = reply.readInt32(); |
| 779 | } |
| 780 | return result; |
| 781 | } |
Ady Abraham | 107788e | 2023-10-17 12:31:08 -0700 | [diff] [blame] | 782 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) |
Ady Abraham | 6cdd3fd | 2023-09-07 18:45:58 -0700 | [diff] [blame] | 783 | virtual status_t setFrameRate(float frameRate, int8_t compatibility, |
| 784 | int8_t changeFrameRateStrategy) override { |
| 785 | Parcel data, reply; |
| 786 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 787 | data.writeFloat(frameRate); |
| 788 | data.writeInt32(compatibility); |
| 789 | data.writeInt32(changeFrameRateStrategy); |
| 790 | status_t result = remote()->transact(SET_FRAME_RATE, data, &reply); |
| 791 | if (result == NO_ERROR) { |
| 792 | result = reply.readInt32(); |
| 793 | } |
| 794 | return result; |
| 795 | } |
| 796 | #endif |
John Reck | db164ff | 2024-04-03 16:59:28 -0400 | [diff] [blame] | 797 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) |
| 798 | virtual status_t setAdditionalOptions(const std::vector<gui::AdditionalOptions>& options) { |
| 799 | Parcel data, reply; |
| 800 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 801 | if (options.size() > 100) { |
| 802 | return BAD_VALUE; |
| 803 | } |
| 804 | data.writeInt32(options.size()); |
| 805 | for (const auto& it : options) { |
| 806 | data.writeCString(it.name.c_str()); |
| 807 | data.writeInt64(it.value); |
| 808 | } |
| 809 | status_t result = remote()->transact(SET_ADDITIONAL_OPTIONS, data, &reply); |
| 810 | if (result == NO_ERROR) { |
| 811 | result = reply.readInt32(); |
| 812 | } |
| 813 | return result; |
| 814 | } |
| 815 | #endif |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 816 | }; |
| 817 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 818 | // Out-of-line virtual method definition to trigger vtable emission in this |
| 819 | // translation unit (see clang warning -Wweak-vtables) |
| 820 | BpGraphicBufferProducer::~BpGraphicBufferProducer() {} |
| 821 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 822 | class HpGraphicBufferProducer : public HpInterface< |
Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 823 | BpGraphicBufferProducer, |
| 824 | H2BGraphicBufferProducerV1_0, |
| 825 | H2BGraphicBufferProducerV2_0> { |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 826 | public: |
Chih-Hung Hsieh | aaf6216 | 2018-12-20 15:45:04 -0800 | [diff] [blame] | 827 | explicit HpGraphicBufferProducer(const sp<IBinder>& base) : PBase(base) {} |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 828 | |
| 829 | status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) override { |
| 830 | return mBase->requestBuffer(slot, buf); |
| 831 | } |
| 832 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 833 | status_t requestBuffers( |
| 834 | const std::vector<int32_t>& slots, |
| 835 | std::vector<RequestBufferOutput>* outputs) override { |
| 836 | return mBase->requestBuffers(slots, outputs); |
| 837 | } |
| 838 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 839 | status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) override { |
| 840 | return mBase->setMaxDequeuedBufferCount(maxDequeuedBuffers); |
| 841 | } |
| 842 | |
| 843 | status_t setAsyncMode(bool async) override { |
| 844 | return mBase->setAsyncMode(async); |
| 845 | } |
| 846 | |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 847 | status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h, PixelFormat format, |
| 848 | uint64_t usage, uint64_t* outBufferAge, |
| 849 | FrameEventHistoryDelta* outTimestamps) override { |
| 850 | return mBase->dequeueBuffer(slot, fence, w, h, format, usage, outBufferAge, outTimestamps); |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 853 | status_t dequeueBuffers( |
| 854 | const std::vector<DequeueBufferInput>& inputs, |
| 855 | std::vector<DequeueBufferOutput>* outputs) override { |
| 856 | return mBase->dequeueBuffers(inputs, outputs); |
| 857 | } |
| 858 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 859 | status_t detachBuffer(int slot) override { |
| 860 | return mBase->detachBuffer(slot); |
| 861 | } |
| 862 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 863 | status_t detachBuffers(const std::vector<int32_t>& slots, |
| 864 | std::vector<status_t>* results) override { |
| 865 | return mBase->detachBuffers(slots, results); |
| 866 | } |
| 867 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 868 | status_t detachNextBuffer( |
| 869 | sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) override { |
| 870 | return mBase->detachNextBuffer(outBuffer, outFence); |
| 871 | } |
| 872 | |
| 873 | status_t attachBuffer( |
| 874 | int* outSlot, const sp<GraphicBuffer>& buffer) override { |
| 875 | return mBase->attachBuffer(outSlot, buffer); |
| 876 | } |
| 877 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 878 | status_t attachBuffers( |
| 879 | const std::vector<sp<GraphicBuffer>>& buffers, |
| 880 | std::vector<AttachBufferOutput>* outputs) override { |
| 881 | return mBase->attachBuffers(buffers, outputs); |
| 882 | } |
| 883 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 884 | status_t queueBuffer( |
| 885 | int slot, |
| 886 | const QueueBufferInput& input, |
| 887 | QueueBufferOutput* output) override { |
| 888 | return mBase->queueBuffer(slot, input, output); |
| 889 | } |
| 890 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 891 | status_t queueBuffers(const std::vector<QueueBufferInput>& inputs, |
| 892 | std::vector<QueueBufferOutput>* outputs) override { |
| 893 | return mBase->queueBuffers(inputs, outputs); |
| 894 | } |
| 895 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 896 | status_t cancelBuffer(int slot, const sp<Fence>& fence) override { |
| 897 | return mBase->cancelBuffer(slot, fence); |
| 898 | } |
| 899 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 900 | status_t cancelBuffers( |
| 901 | const std::vector<CancelBufferInput>& inputs, |
| 902 | std::vector<status_t>* results) override { |
| 903 | return mBase->cancelBuffers(inputs, results); |
| 904 | } |
| 905 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 906 | int query(int what, int* value) override { |
| 907 | return mBase->query(what, value); |
| 908 | } |
| 909 | |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 910 | status_t query(const std::vector<int32_t> inputs, |
| 911 | std::vector<QueryOutput>* outputs) override { |
| 912 | return mBase->query(inputs, outputs); |
| 913 | } |
| 914 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 915 | status_t connect( |
| 916 | const sp<IProducerListener>& listener, |
| 917 | int api, bool producerControlledByApp, |
| 918 | QueueBufferOutput* output) override { |
| 919 | return mBase->connect(listener, api, producerControlledByApp, output); |
| 920 | } |
| 921 | |
| 922 | status_t disconnect( |
| 923 | int api, DisconnectMode mode = DisconnectMode::Api) override { |
| 924 | return mBase->disconnect(api, mode); |
| 925 | } |
| 926 | |
| 927 | status_t setSidebandStream(const sp<NativeHandle>& stream) override { |
| 928 | return mBase->setSidebandStream(stream); |
| 929 | } |
| 930 | |
| 931 | void allocateBuffers(uint32_t width, uint32_t height, |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 932 | PixelFormat format, uint64_t usage) override { |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 933 | return mBase->allocateBuffers(width, height, format, usage); |
| 934 | } |
| 935 | |
| 936 | status_t allowAllocation(bool allow) override { |
| 937 | return mBase->allowAllocation(allow); |
| 938 | } |
| 939 | |
| 940 | status_t setGenerationNumber(uint32_t generationNumber) override { |
| 941 | return mBase->setGenerationNumber(generationNumber); |
| 942 | } |
| 943 | |
| 944 | String8 getConsumerName() const override { |
| 945 | return mBase->getConsumerName(); |
| 946 | } |
| 947 | |
| 948 | status_t setSharedBufferMode(bool sharedBufferMode) override { |
| 949 | return mBase->setSharedBufferMode(sharedBufferMode); |
| 950 | } |
| 951 | |
| 952 | status_t setAutoRefresh(bool autoRefresh) override { |
| 953 | return mBase->setAutoRefresh(autoRefresh); |
| 954 | } |
| 955 | |
| 956 | status_t setDequeueTimeout(nsecs_t timeout) override { |
| 957 | return mBase->setDequeueTimeout(timeout); |
| 958 | } |
| 959 | |
Sungtak Lee | 3249fb6 | 2019-03-02 16:40:47 -0800 | [diff] [blame] | 960 | status_t setLegacyBufferDrop(bool drop) override { |
| 961 | return mBase->setLegacyBufferDrop(drop); |
| 962 | } |
| 963 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 964 | status_t getLastQueuedBuffer( |
| 965 | sp<GraphicBuffer>* outBuffer, |
| 966 | sp<Fence>* outFence, |
| 967 | float outTransformMatrix[16]) override { |
| 968 | return mBase->getLastQueuedBuffer( |
| 969 | outBuffer, outFence, outTransformMatrix); |
| 970 | } |
| 971 | |
John Reck | aa5a0b2 | 2021-05-18 00:42:56 -0400 | [diff] [blame] | 972 | status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence, Rect* outRect, |
| 973 | uint32_t* outTransform) override { |
| 974 | return mBase->getLastQueuedBuffer(outBuffer, outFence, outRect, outTransform); |
| 975 | } |
| 976 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 977 | void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override { |
| 978 | return mBase->getFrameTimestamps(outDelta); |
| 979 | } |
| 980 | |
| 981 | status_t getUniqueId(uint64_t* outId) const override { |
| 982 | return mBase->getUniqueId(outId); |
| 983 | } |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 984 | |
| 985 | status_t getConsumerUsage(uint64_t* outUsage) const override { |
| 986 | return mBase->getConsumerUsage(outUsage); |
| 987 | } |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 988 | |
| 989 | status_t setAutoPrerotation(bool autoPrerotation) override { |
| 990 | return mBase->setAutoPrerotation(autoPrerotation); |
| 991 | } |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 992 | }; |
| 993 | |
Pawin Vongmasa | 338b81d | 2019-01-31 05:20:07 -0800 | [diff] [blame] | 994 | IMPLEMENT_HYBRID_META_INTERFACE(GraphicBufferProducer, |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 995 | "android.gui.IGraphicBufferProducer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 996 | |
| 997 | // ---------------------------------------------------------------------- |
| 998 | |
Jim Shargo | 2e614a4 | 2024-10-02 19:31:53 +0000 | [diff] [blame] | 999 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS) |
| 1000 | status_t IGraphicBufferProducer::extendSlotCount(int size) { |
| 1001 | // No-op for IGBP other than BufferQueue. |
| 1002 | (void)size; |
| 1003 | return INVALID_OPERATION; |
| 1004 | } |
| 1005 | #endif |
| 1006 | |
Sungtak Lee | 3249fb6 | 2019-03-02 16:40:47 -0800 | [diff] [blame] | 1007 | status_t IGraphicBufferProducer::setLegacyBufferDrop(bool drop) { |
| 1008 | // No-op for IGBP other than BufferQueue. |
| 1009 | (void) drop; |
| 1010 | return INVALID_OPERATION; |
| 1011 | } |
| 1012 | |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 1013 | status_t IGraphicBufferProducer::setAutoPrerotation(bool autoPrerotation) { |
| 1014 | // No-op for IGBP other than BufferQueue. |
| 1015 | (void)autoPrerotation; |
| 1016 | return INVALID_OPERATION; |
| 1017 | } |
| 1018 | |
Ady Abraham | 107788e | 2023-10-17 12:31:08 -0700 | [diff] [blame] | 1019 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) |
Ady Abraham | 6cdd3fd | 2023-09-07 18:45:58 -0700 | [diff] [blame] | 1020 | status_t IGraphicBufferProducer::setFrameRate(float /*frameRate*/, int8_t /*compatibility*/, |
| 1021 | int8_t /*changeFrameRateStrategy*/) { |
| 1022 | // No-op for IGBP other than BufferQueue. |
| 1023 | return INVALID_OPERATION; |
| 1024 | } |
| 1025 | #endif |
| 1026 | |
John Reck | db164ff | 2024-04-03 16:59:28 -0400 | [diff] [blame] | 1027 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) |
| 1028 | status_t IGraphicBufferProducer::setAdditionalOptions(const std::vector<gui::AdditionalOptions>&) { |
| 1029 | // No-op for IGBP other than BufferQueue. |
| 1030 | return INVALID_OPERATION; |
| 1031 | } |
| 1032 | #endif |
| 1033 | |
Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 1034 | status_t IGraphicBufferProducer::exportToParcel(Parcel* parcel) { |
| 1035 | status_t res = OK; |
| 1036 | res = parcel->writeUint32(USE_BUFFER_QUEUE); |
| 1037 | if (res != NO_ERROR) { |
| 1038 | ALOGE("exportToParcel: Cannot write magic, res=%d.", res); |
| 1039 | return res; |
| 1040 | } |
| 1041 | |
| 1042 | return parcel->writeStrongBinder(IInterface::asBinder(this)); |
| 1043 | } |
| 1044 | |
| 1045 | /* static */ |
| 1046 | status_t IGraphicBufferProducer::exportToParcel(const sp<IGraphicBufferProducer>& producer, |
| 1047 | Parcel* parcel) { |
| 1048 | if (parcel == nullptr) { |
| 1049 | ALOGE("exportToParcel: Invalid parcel object."); |
| 1050 | return BAD_VALUE; |
| 1051 | } |
| 1052 | |
| 1053 | if (producer == nullptr) { |
| 1054 | status_t res = OK; |
| 1055 | res = parcel->writeUint32(IGraphicBufferProducer::USE_BUFFER_QUEUE); |
| 1056 | if (res != NO_ERROR) return res; |
| 1057 | return parcel->writeStrongBinder(nullptr); |
| 1058 | } else { |
| 1059 | return producer->exportToParcel(parcel); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | /* static */ |
| 1064 | sp<IGraphicBufferProducer> IGraphicBufferProducer::createFromParcel(const Parcel* parcel) { |
| 1065 | uint32_t outMagic = 0; |
| 1066 | status_t res = NO_ERROR; |
| 1067 | |
| 1068 | res = parcel->readUint32(&outMagic); |
| 1069 | if (res != NO_ERROR) { |
| 1070 | ALOGE("createFromParcel: Failed to read magic, error=%d.", res); |
| 1071 | return nullptr; |
| 1072 | } |
| 1073 | |
| 1074 | switch (outMagic) { |
| 1075 | case USE_BUFFER_QUEUE: { |
| 1076 | sp<IBinder> binder; |
| 1077 | res = parcel->readNullableStrongBinder(&binder); |
| 1078 | if (res != NO_ERROR) { |
| 1079 | ALOGE("createFromParcel: Can't read strong binder."); |
| 1080 | return nullptr; |
| 1081 | } |
| 1082 | return interface_cast<IGraphicBufferProducer>(binder); |
| 1083 | } |
| 1084 | case USE_BUFFER_HUB: { |
| 1085 | ALOGE("createFromParcel: BufferHub not implemented."); |
Jiyong Park | a75d3d6 | 2018-04-09 12:16:30 +0900 | [diff] [blame] | 1086 | return nullptr; |
Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 1087 | } |
| 1088 | default: { |
| 1089 | ALOGE("createFromParcel: Unexpected mgaic: 0x%x.", outMagic); |
| 1090 | return nullptr; |
| 1091 | } |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | // ---------------------------------------------------------------------------- |
| 1096 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1097 | status_t BnGraphicBufferProducer::onTransact( |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1098 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 1099 | { |
| 1100 | switch(code) { |
| 1101 | case REQUEST_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1102 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1103 | int bufferIdx = data.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 1104 | sp<GraphicBuffer> buffer; |
| 1105 | int result = requestBuffer(bufferIdx, &buffer); |
Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1106 | reply->writeInt32(buffer != nullptr); |
| 1107 | if (buffer != nullptr) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1108 | reply->write(*buffer); |
| 1109 | } |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 1110 | reply->writeInt32(result); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1111 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1112 | } |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1113 | case REQUEST_BUFFERS: { |
| 1114 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1115 | std::vector<int32_t> slots; |
| 1116 | std::vector<RequestBufferOutput> outputs; |
| 1117 | status_t result = data.readInt32Vector(&slots); |
| 1118 | if (result != NO_ERROR) { |
| 1119 | return result; |
| 1120 | } |
| 1121 | (void)requestBuffers(slots, &outputs); |
| 1122 | result = reply->writeVectorSize(outputs); |
| 1123 | for (const RequestBufferOutput& output : outputs) { |
| 1124 | if (result != NO_ERROR) { |
| 1125 | return result; |
| 1126 | } |
| 1127 | result = reply->write(output); |
| 1128 | } |
| 1129 | return result; |
| 1130 | } |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 1131 | case SET_MAX_DEQUEUED_BUFFER_COUNT: { |
| 1132 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1133 | int maxDequeuedBuffers = data.readInt32(); |
| 1134 | int result = setMaxDequeuedBufferCount(maxDequeuedBuffers); |
| 1135 | reply->writeInt32(result); |
| 1136 | return NO_ERROR; |
| 1137 | } |
| 1138 | case SET_ASYNC_MODE: { |
| 1139 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1140 | bool async = data.readInt32(); |
| 1141 | int result = setAsyncMode(async); |
| 1142 | reply->writeInt32(result); |
| 1143 | return NO_ERROR; |
| 1144 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1145 | case DEQUEUE_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1146 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1147 | uint32_t width = data.readUint32(); |
| 1148 | uint32_t height = data.readUint32(); |
| 1149 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 1150 | uint64_t usage = data.readUint64(); |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 1151 | uint64_t bufferAge = 0; |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1152 | bool getTimestamps = data.readBool(); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1153 | |
Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 1154 | int buf = 0; |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1155 | sp<Fence> fence = Fence::NO_FENCE; |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1156 | FrameEventHistoryDelta frameTimestamps; |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 1157 | int result = dequeueBuffer(&buf, &fence, width, height, format, usage, &bufferAge, |
| 1158 | getTimestamps ? &frameTimestamps : nullptr); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1159 | |
Tobin Ehlis | 209e5fb | 2019-03-26 14:06:29 -0600 | [diff] [blame] | 1160 | if (fence == nullptr) { |
| 1161 | ALOGE("dequeueBuffer returned a NULL fence, setting to Fence::NO_FENCE"); |
| 1162 | fence = Fence::NO_FENCE; |
| 1163 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1164 | reply->writeInt32(buf); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1165 | reply->write(*fence); |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 1166 | reply->writeUint64(bufferAge); |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1167 | if (getTimestamps) { |
| 1168 | reply->write(frameTimestamps); |
| 1169 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1170 | reply->writeInt32(result); |
| 1171 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1172 | } |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1173 | case DEQUEUE_BUFFERS: { |
| 1174 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1175 | std::vector<DequeueBufferInput> inputs; |
| 1176 | std::vector<DequeueBufferOutput> outputs; |
| 1177 | status_t result = data.resizeOutVector(&inputs); |
| 1178 | if (result != NO_ERROR) { |
| 1179 | return result; |
| 1180 | } |
| 1181 | for (DequeueBufferInput& input : inputs) { |
| 1182 | result = data.read(input); |
| 1183 | if (result != NO_ERROR) { |
| 1184 | return result; |
| 1185 | } |
| 1186 | } |
| 1187 | (void)dequeueBuffers(inputs, &outputs); |
| 1188 | result = reply->writeVectorSize(outputs); |
| 1189 | for (const DequeueBufferOutput& output : outputs) { |
| 1190 | if (result != NO_ERROR) { |
| 1191 | return result; |
| 1192 | } |
| 1193 | result = reply->write(output); |
| 1194 | } |
| 1195 | return result; |
| 1196 | } |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 1197 | case DETACH_BUFFER: { |
| 1198 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1199 | int slot = data.readInt32(); |
| 1200 | int result = detachBuffer(slot); |
| 1201 | reply->writeInt32(result); |
| 1202 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1203 | } |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1204 | case DETACH_BUFFERS: { |
| 1205 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1206 | std::vector<int32_t> slots; |
| 1207 | std::vector<status_t> results; |
| 1208 | status_t result = data.readInt32Vector(&slots); |
| 1209 | if (result != NO_ERROR) { |
| 1210 | return result; |
| 1211 | } |
| 1212 | (void)detachBuffers(slots, &results); |
| 1213 | return reply->writeInt32Vector(results); |
| 1214 | } |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 1215 | case DETACH_NEXT_BUFFER: { |
| 1216 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1217 | sp<GraphicBuffer> buffer; |
| 1218 | sp<Fence> fence; |
| 1219 | int32_t result = detachNextBuffer(&buffer, &fence); |
| 1220 | reply->writeInt32(result); |
| 1221 | if (result == NO_ERROR) { |
Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1222 | reply->writeInt32(buffer != nullptr); |
| 1223 | if (buffer != nullptr) { |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 1224 | reply->write(*buffer); |
| 1225 | } |
Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 1226 | reply->writeInt32(fence != nullptr); |
| 1227 | if (fence != nullptr) { |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 1228 | reply->write(*fence); |
| 1229 | } |
| 1230 | } |
| 1231 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1232 | } |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 1233 | case ATTACH_BUFFER: { |
| 1234 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 1235 | sp<GraphicBuffer> buffer = sp<GraphicBuffer>::make(); |
Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 1236 | status_t result = data.read(*buffer.get()); |
Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 1237 | int slot = 0; |
Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 1238 | if (result == NO_ERROR) { |
| 1239 | result = attachBuffer(&slot, buffer); |
| 1240 | } |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 1241 | reply->writeInt32(slot); |
| 1242 | reply->writeInt32(result); |
| 1243 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1244 | } |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1245 | case ATTACH_BUFFERS: { |
| 1246 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1247 | std::vector<sp<GraphicBuffer>> buffers; |
| 1248 | status_t result = data.resizeOutVector(&buffers); |
| 1249 | if (result != NO_ERROR) { |
| 1250 | return result; |
| 1251 | } |
| 1252 | for (sp<GraphicBuffer>& buffer : buffers) { |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 1253 | buffer = sp<GraphicBuffer>::make(); |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1254 | result = data.read(*buffer.get()); |
| 1255 | if (result != NO_ERROR) { |
| 1256 | return result; |
| 1257 | } |
| 1258 | } |
| 1259 | std::vector<AttachBufferOutput> outputs; |
| 1260 | (void)attachBuffers(buffers, &outputs); |
| 1261 | result = reply->writeVectorSize(outputs); |
| 1262 | for (const AttachBufferOutput& output : outputs) { |
| 1263 | if (result != NO_ERROR) { |
| 1264 | return result; |
| 1265 | } |
| 1266 | result = reply->write(output); |
| 1267 | } |
| 1268 | return result; |
| 1269 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1270 | case QUEUE_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1271 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1272 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1273 | int buf = data.readInt32(); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1274 | QueueBufferInput input(data); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1275 | QueueBufferOutput output; |
| 1276 | status_t result = queueBuffer(buf, input, &output); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1277 | reply->write(output); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1278 | reply->writeInt32(result); |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1279 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1280 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1281 | } |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1282 | case QUEUE_BUFFERS: { |
| 1283 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1284 | std::vector<QueueBufferInput> inputs; |
| 1285 | status_t result = data.resizeOutVector(&inputs); |
| 1286 | if (result != NO_ERROR) { |
| 1287 | return result; |
| 1288 | } |
| 1289 | for (QueueBufferInput& input : inputs) { |
| 1290 | result = data.read(input); |
| 1291 | if (result != NO_ERROR) { |
| 1292 | return result; |
| 1293 | } |
| 1294 | } |
| 1295 | std::vector<QueueBufferOutput> outputs; |
| 1296 | (void)queueBuffers(inputs, &outputs); |
| 1297 | result = reply->writeVectorSize(outputs); |
| 1298 | for (const QueueBufferOutput& output : outputs) { |
| 1299 | if (result != NO_ERROR) { |
| 1300 | return result; |
| 1301 | } |
| 1302 | result = reply->write(output); |
| 1303 | } |
| 1304 | return result; |
| 1305 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1306 | case CANCEL_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1307 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1308 | int buf = data.readInt32(); |
Anton Ivanov | 8ed8659 | 2025-02-20 11:52:50 -0800 | [diff] [blame] | 1309 | sp<Fence> fence = sp<Fence>::make(); |
Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 1310 | status_t result = data.read(*fence.get()); |
| 1311 | if (result == NO_ERROR) { |
| 1312 | result = cancelBuffer(buf, fence); |
| 1313 | } |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 1314 | reply->writeInt32(result); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1315 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1316 | } |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1317 | case CANCEL_BUFFERS: { |
| 1318 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1319 | std::vector<CancelBufferInput> inputs; |
| 1320 | status_t result = data.resizeOutVector(&inputs); |
| 1321 | for (CancelBufferInput& input : inputs) { |
| 1322 | if (result != NO_ERROR) { |
| 1323 | return result; |
| 1324 | } |
| 1325 | result = data.read(input); |
| 1326 | } |
| 1327 | if (result != NO_ERROR) { |
| 1328 | return result; |
| 1329 | } |
| 1330 | std::vector<status_t> results; |
| 1331 | result = cancelBuffers(inputs, &results); |
| 1332 | if (result != NO_ERROR) { |
| 1333 | return result; |
| 1334 | } |
| 1335 | return reply->writeInt32Vector(results); |
| 1336 | } |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1337 | case QUERY: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1338 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 1339 | int value = 0; |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1340 | int what = data.readInt32(); |
| 1341 | int res = query(what, &value); |
| 1342 | reply->writeInt32(value); |
| 1343 | reply->writeInt32(res); |
| 1344 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1345 | } |
Yin-Chia Yeh | 64ee5f5 | 2020-01-02 17:53:18 +0700 | [diff] [blame] | 1346 | case QUERY_MULTIPLE: { |
| 1347 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1348 | std::vector<int32_t> inputs; |
| 1349 | status_t result = data.readInt32Vector(&inputs); |
| 1350 | if (result != NO_ERROR) { |
| 1351 | return result; |
| 1352 | } |
| 1353 | std::vector<QueryOutput> outputs; |
| 1354 | result = query(inputs, &outputs); |
| 1355 | if (result != NO_ERROR) { |
| 1356 | return result; |
| 1357 | } |
| 1358 | result = reply->writeVectorSize(outputs); |
| 1359 | for (const QueryOutput& output : outputs) { |
| 1360 | if (result != NO_ERROR) { |
| 1361 | return result; |
| 1362 | } |
| 1363 | result = reply->write(output); |
| 1364 | } |
| 1365 | return result; |
| 1366 | } |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 1367 | case CONNECT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1368 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 1369 | sp<IProducerListener> listener; |
| 1370 | if (data.readInt32() == 1) { |
| 1371 | listener = IProducerListener::asInterface(data.readStrongBinder()); |
| 1372 | } |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 1373 | int api = data.readInt32(); |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 1374 | bool producerControlledByApp = data.readInt32(); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1375 | QueueBufferOutput output; |
| 1376 | status_t res = connect(listener, api, producerControlledByApp, &output); |
| 1377 | reply->write(output); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 1378 | reply->writeInt32(res); |
| 1379 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1380 | } |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 1381 | case DISCONNECT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1382 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 1383 | int api = data.readInt32(); |
Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 1384 | DisconnectMode mode = static_cast<DisconnectMode>(data.readInt32()); |
| 1385 | status_t res = disconnect(api, mode); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 1386 | reply->writeInt32(res); |
| 1387 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1388 | } |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 1389 | case SET_SIDEBAND_STREAM: { |
| 1390 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1391 | sp<NativeHandle> stream; |
| 1392 | if (data.readInt32()) { |
Wonsik Kim | 0ec54e1 | 2014-03-21 10:46:24 +0900 | [diff] [blame] | 1393 | stream = NativeHandle::create(data.readNativeHandle(), true); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 1394 | } |
| 1395 | status_t result = setSidebandStream(stream); |
| 1396 | reply->writeInt32(result); |
| 1397 | return NO_ERROR; |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1398 | } |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 1399 | case ALLOCATE_BUFFERS: { |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 1400 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 1401 | uint32_t width = data.readUint32(); |
| 1402 | uint32_t height = data.readUint32(); |
| 1403 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 1404 | uint64_t usage = data.readUint64(); |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 1405 | allocateBuffers(width, height, format, usage); |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 1406 | return NO_ERROR; |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 1407 | } |
| 1408 | case ALLOW_ALLOCATION: { |
| 1409 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1410 | bool allow = static_cast<bool>(data.readInt32()); |
| 1411 | status_t result = allowAllocation(allow); |
| 1412 | reply->writeInt32(result); |
| 1413 | return NO_ERROR; |
| 1414 | } |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 1415 | case SET_GENERATION_NUMBER: { |
| 1416 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1417 | uint32_t generationNumber = data.readUint32(); |
| 1418 | status_t result = setGenerationNumber(generationNumber); |
| 1419 | reply->writeInt32(result); |
| 1420 | return NO_ERROR; |
| 1421 | } |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 1422 | case GET_CONSUMER_NAME: { |
| 1423 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1424 | reply->writeString8(getConsumerName()); |
| 1425 | return NO_ERROR; |
| 1426 | } |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1427 | case SET_SHARED_BUFFER_MODE: { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1428 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 1429 | bool sharedBufferMode = data.readInt32(); |
| 1430 | status_t result = setSharedBufferMode(sharedBufferMode); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1431 | reply->writeInt32(result); |
| 1432 | return NO_ERROR; |
| 1433 | } |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 1434 | case SET_AUTO_REFRESH: { |
| 1435 | CHECK_INTERFACE(IGraphicBuffer, data, reply); |
| 1436 | bool autoRefresh = data.readInt32(); |
| 1437 | status_t result = setAutoRefresh(autoRefresh); |
| 1438 | reply->writeInt32(result); |
| 1439 | return NO_ERROR; |
| 1440 | } |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 1441 | case SET_DEQUEUE_TIMEOUT: { |
| 1442 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1443 | nsecs_t timeout = data.readInt64(); |
| 1444 | status_t result = setDequeueTimeout(timeout); |
| 1445 | reply->writeInt32(result); |
| 1446 | return NO_ERROR; |
| 1447 | } |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 1448 | case GET_LAST_QUEUED_BUFFER: { |
| 1449 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1450 | sp<GraphicBuffer> buffer(nullptr); |
| 1451 | sp<Fence> fence(Fence::NO_FENCE); |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 1452 | float transform[16] = {}; |
| 1453 | status_t result = getLastQueuedBuffer(&buffer, &fence, transform); |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 1454 | reply->writeInt32(result); |
| 1455 | if (result != NO_ERROR) { |
| 1456 | return result; |
| 1457 | } |
John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 1458 | if (!buffer.get()) { |
| 1459 | reply->writeBool(false); |
| 1460 | } else { |
| 1461 | reply->writeBool(true); |
| 1462 | result = reply->write(*buffer); |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 1463 | if (result == NO_ERROR) { |
| 1464 | reply->write(transform, sizeof(float) * 16); |
| 1465 | } |
John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 1466 | } |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 1467 | if (result != NO_ERROR) { |
| 1468 | ALOGE("getLastQueuedBuffer failed to write buffer: %d", result); |
| 1469 | return result; |
| 1470 | } |
Tobin Ehlis | 209e5fb | 2019-03-26 14:06:29 -0600 | [diff] [blame] | 1471 | if (fence == nullptr) { |
| 1472 | ALOGE("getLastQueuedBuffer returned a NULL fence, setting to Fence::NO_FENCE"); |
| 1473 | fence = Fence::NO_FENCE; |
| 1474 | } |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 1475 | result = reply->write(*fence); |
| 1476 | if (result != NO_ERROR) { |
| 1477 | ALOGE("getLastQueuedBuffer failed to write fence: %d", result); |
| 1478 | return result; |
| 1479 | } |
| 1480 | return NO_ERROR; |
| 1481 | } |
John Reck | aa5a0b2 | 2021-05-18 00:42:56 -0400 | [diff] [blame] | 1482 | case GET_LAST_QUEUED_BUFFER2: { |
| 1483 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1484 | sp<GraphicBuffer> buffer(nullptr); |
| 1485 | sp<Fence> fence(Fence::NO_FENCE); |
| 1486 | Rect crop; |
| 1487 | uint32_t transform; |
| 1488 | status_t result = getLastQueuedBuffer(&buffer, &fence, &crop, &transform); |
| 1489 | reply->writeInt32(result); |
| 1490 | if (result != NO_ERROR) { |
| 1491 | return result; |
| 1492 | } |
| 1493 | if (!buffer.get()) { |
| 1494 | reply->writeBool(false); |
| 1495 | } else { |
| 1496 | reply->writeBool(true); |
| 1497 | result = reply->write(*buffer); |
| 1498 | if (result == NO_ERROR) { |
| 1499 | result = reply->write(crop); |
| 1500 | } |
| 1501 | if (result == NO_ERROR) { |
| 1502 | result = reply->writeUint32(transform); |
| 1503 | } |
| 1504 | } |
| 1505 | if (result != NO_ERROR) { |
| 1506 | ALOGE("getLastQueuedBuffer failed to write buffer: %d", result); |
| 1507 | return result; |
| 1508 | } |
| 1509 | if (fence == nullptr) { |
| 1510 | ALOGE("getLastQueuedBuffer returned a NULL fence, setting to Fence::NO_FENCE"); |
| 1511 | fence = Fence::NO_FENCE; |
| 1512 | } |
| 1513 | result = reply->write(*fence); |
| 1514 | if (result != NO_ERROR) { |
| 1515 | ALOGE("getLastQueuedBuffer failed to write fence: %d", result); |
| 1516 | return result; |
| 1517 | } |
| 1518 | return NO_ERROR; |
| 1519 | } |
| 1520 | |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1521 | case GET_FRAME_TIMESTAMPS: { |
| 1522 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1523 | FrameEventHistoryDelta frameTimestamps; |
| 1524 | getFrameTimestamps(&frameTimestamps); |
| 1525 | status_t result = reply->write(frameTimestamps); |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1526 | if (result != NO_ERROR) { |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1527 | ALOGE("BnGBP::GET_FRAME_TIMESTAMPS failed to write buffer: %d", |
| 1528 | result); |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1529 | return result; |
| 1530 | } |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 1531 | return NO_ERROR; |
| 1532 | } |
Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 1533 | case GET_UNIQUE_ID: { |
| 1534 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1535 | uint64_t outId = 0; |
| 1536 | status_t actualResult = getUniqueId(&outId); |
| 1537 | status_t result = reply->writeInt32(actualResult); |
| 1538 | if (result != NO_ERROR) { |
| 1539 | return result; |
| 1540 | } |
| 1541 | result = reply->writeUint64(outId); |
| 1542 | if (result != NO_ERROR) { |
| 1543 | return result; |
| 1544 | } |
| 1545 | return NO_ERROR; |
| 1546 | } |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 1547 | case GET_CONSUMER_USAGE: { |
| 1548 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1549 | uint64_t outUsage = 0; |
| 1550 | status_t actualResult = getConsumerUsage(&outUsage); |
| 1551 | status_t result = reply->writeInt32(actualResult); |
| 1552 | if (result != NO_ERROR) { |
| 1553 | return result; |
| 1554 | } |
| 1555 | result = reply->writeUint64(outUsage); |
| 1556 | if (result != NO_ERROR) { |
| 1557 | return result; |
| 1558 | } |
| 1559 | return NO_ERROR; |
| 1560 | } |
Sungtak Lee | 3249fb6 | 2019-03-02 16:40:47 -0800 | [diff] [blame] | 1561 | case SET_LEGACY_BUFFER_DROP: { |
| 1562 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1563 | bool drop = data.readInt32(); |
| 1564 | int result = setLegacyBufferDrop(drop); |
| 1565 | reply->writeInt32(result); |
| 1566 | return NO_ERROR; |
| 1567 | } |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 1568 | case SET_AUTO_PREROTATION: { |
| 1569 | CHECK_INTERFACE(IGraphicBuffer, data, reply); |
| 1570 | bool autoPrerotation = data.readBool(); |
| 1571 | status_t result = setAutoPrerotation(autoPrerotation); |
| 1572 | reply->writeInt32(result); |
| 1573 | return NO_ERROR; |
| 1574 | } |
Ady Abraham | 107788e | 2023-10-17 12:31:08 -0700 | [diff] [blame] | 1575 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) |
Ady Abraham | 6cdd3fd | 2023-09-07 18:45:58 -0700 | [diff] [blame] | 1576 | case SET_FRAME_RATE: { |
| 1577 | CHECK_INTERFACE(IGraphicBuffer, data, reply); |
| 1578 | float frameRate = data.readFloat(); |
| 1579 | int8_t compatibility = data.readInt32(); |
| 1580 | int8_t changeFrameRateStrategy = data.readInt32(); |
| 1581 | status_t result = setFrameRate(frameRate, compatibility, changeFrameRateStrategy); |
| 1582 | reply->writeInt32(result); |
| 1583 | return NO_ERROR; |
| 1584 | } |
| 1585 | #endif |
John Reck | db164ff | 2024-04-03 16:59:28 -0400 | [diff] [blame] | 1586 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) |
| 1587 | case SET_ADDITIONAL_OPTIONS: { |
| 1588 | CHECK_INTERFACE(IGraphicBuffer, data, reply); |
| 1589 | int optionCount = data.readInt32(); |
| 1590 | if (optionCount < 0 || optionCount > 100) { |
| 1591 | return BAD_VALUE; |
| 1592 | } |
| 1593 | std::vector<gui::AdditionalOptions> opts; |
| 1594 | opts.reserve(optionCount); |
| 1595 | for (int i = 0; i < optionCount; i++) { |
| 1596 | const char* name = data.readCString(); |
| 1597 | int64_t value = 0; |
| 1598 | if (name == nullptr || data.readInt64(&value) != NO_ERROR) { |
| 1599 | return BAD_VALUE; |
| 1600 | } |
| 1601 | opts.emplace_back(name, value); |
| 1602 | } |
| 1603 | status_t result = setAdditionalOptions(opts); |
| 1604 | reply->writeInt32(result); |
| 1605 | return NO_ERROR; |
| 1606 | } |
| 1607 | #endif |
Jim Shargo | 2e614a4 | 2024-10-02 19:31:53 +0000 | [diff] [blame] | 1608 | #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS) |
| 1609 | case SET_MAX_BUFER_COUNT_EXTENDED: { |
| 1610 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 1611 | int size = data.readInt32(); |
| 1612 | status_t result = extendSlotCount(size); |
| 1613 | reply->writeInt32(result); |
| 1614 | return NO_ERROR; |
| 1615 | } |
| 1616 | #endif |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1617 | } |
| 1618 | return BBinder::onTransact(code, data, reply, flags); |
| 1619 | } |
| 1620 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1621 | }; // namespace android |