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