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