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