| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #include <stdint.h> | 
|  | 18 | #include <sys/types.h> | 
|  | 19 |  | 
|  | 20 | #include <utils/Errors.h> | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 21 | #include <utils/NativeHandle.h> | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 22 | #include <utils/RefBase.h> | 
| Brian Anderson | 175a720 | 2016-10-10 16:52:56 -0700 | [diff] [blame] | 23 | #include <utils/String8.h> | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 24 | #include <utils/Timers.h> | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 25 | #include <utils/Vector.h> | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 26 |  | 
|  | 27 | #include <binder/Parcel.h> | 
|  | 28 | #include <binder/IInterface.h> | 
|  | 29 |  | 
| Jiyong Park | a75d3d6 | 2018-04-09 12:16:30 +0900 | [diff] [blame] | 30 | #ifndef NO_BUFFERHUB | 
| Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 31 | #include <gui/BufferHubProducer.h> | 
| Jiyong Park | a75d3d6 | 2018-04-09 12:16:30 +0900 | [diff] [blame] | 32 | #endif | 
| Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 33 |  | 
|  | 34 | #include <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h> | 
|  | 35 | #include <gui/bufferqueue/2.0/H2BGraphicBufferProducer.h> | 
| Chia-I Wu | c79a296 | 2017-05-15 10:32:27 -0700 | [diff] [blame] | 36 | #include <gui/BufferQueueDefs.h> | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 37 | #include <gui/IGraphicBufferProducer.h> | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 38 | #include <gui/IProducerListener.h> | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 39 |  | 
|  | 40 | namespace android { | 
|  | 41 | // ---------------------------------------------------------------------------- | 
|  | 42 |  | 
| Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 43 | using H2BGraphicBufferProducerV1_0 = | 
|  | 44 | ::android::hardware::graphics::bufferqueue::V1_0::utils:: | 
|  | 45 | H2BGraphicBufferProducer; | 
|  | 46 | using H2BGraphicBufferProducerV2_0 = | 
|  | 47 | ::android::hardware::graphics::bufferqueue::V2_0::utils:: | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 48 | H2BGraphicBufferProducer; | 
|  | 49 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 50 | enum { | 
|  | 51 | REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 52 | DEQUEUE_BUFFER, | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 53 | DETACH_BUFFER, | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 54 | DETACH_NEXT_BUFFER, | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 55 | ATTACH_BUFFER, | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 56 | QUEUE_BUFFER, | 
|  | 57 | CANCEL_BUFFER, | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 58 | QUERY, | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 59 | CONNECT, | 
|  | 60 | DISCONNECT, | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 61 | SET_SIDEBAND_STREAM, | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 62 | ALLOCATE_BUFFERS, | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 63 | ALLOW_ALLOCATION, | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 64 | SET_GENERATION_NUMBER, | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 65 | GET_CONSUMER_NAME, | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 66 | SET_MAX_DEQUEUED_BUFFER_COUNT, | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 67 | SET_ASYNC_MODE, | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 68 | SET_SHARED_BUFFER_MODE, | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 69 | SET_AUTO_REFRESH, | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 70 | SET_DEQUEUE_TIMEOUT, | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 71 | GET_LAST_QUEUED_BUFFER, | 
| Pablo Ceballos | fc35258 | 2016-06-30 17:22:20 -0700 | [diff] [blame] | 72 | GET_FRAME_TIMESTAMPS, | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 73 | GET_UNIQUE_ID, | 
|  | 74 | GET_CONSUMER_USAGE, | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 75 | }; | 
|  | 76 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 77 | class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 78 | { | 
|  | 79 | public: | 
| Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 80 | explicit BpGraphicBufferProducer(const sp<IBinder>& impl) | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 81 | : BpInterface<IGraphicBufferProducer>(impl) | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 82 | { | 
|  | 83 | } | 
|  | 84 |  | 
| Yi Kong | ca03851 | 2017-05-02 16:55:24 -0700 | [diff] [blame] | 85 | ~BpGraphicBufferProducer() override; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 86 |  | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 87 | virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 88 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 89 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 90 | data.writeInt32(bufferIdx); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 91 | status_t result =remote()->transact(REQUEST_BUFFER, data, &reply); | 
|  | 92 | if (result != NO_ERROR) { | 
|  | 93 | return result; | 
|  | 94 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 95 | bool nonNull = reply.readInt32(); | 
|  | 96 | if (nonNull) { | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 97 | *buf = new GraphicBuffer(); | 
| Lingyun Zhu | 2aff702 | 2012-11-20 19:24:35 +0800 | [diff] [blame] | 98 | result = reply.read(**buf); | 
|  | 99 | if(result != NO_ERROR) { | 
|  | 100 | (*buf).clear(); | 
|  | 101 | return result; | 
|  | 102 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 103 | } | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 104 | result = reply.readInt32(); | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 105 | return result; | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 106 | } | 
|  | 107 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 108 | virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) { | 
|  | 109 | Parcel data, reply; | 
|  | 110 | data.writeInterfaceToken( | 
|  | 111 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 112 | data.writeInt32(maxDequeuedBuffers); | 
|  | 113 | status_t result = remote()->transact(SET_MAX_DEQUEUED_BUFFER_COUNT, | 
|  | 114 | data, &reply); | 
|  | 115 | if (result != NO_ERROR) { | 
|  | 116 | return result; | 
|  | 117 | } | 
|  | 118 | result = reply.readInt32(); | 
|  | 119 | return result; | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | virtual status_t setAsyncMode(bool async) { | 
|  | 123 | Parcel data, reply; | 
|  | 124 | data.writeInterfaceToken( | 
|  | 125 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 126 | data.writeInt32(async); | 
|  | 127 | status_t result = remote()->transact(SET_ASYNC_MODE, | 
|  | 128 | data, &reply); | 
|  | 129 | if (result != NO_ERROR) { | 
|  | 130 | return result; | 
|  | 131 | } | 
|  | 132 | result = reply.readInt32(); | 
|  | 133 | return result; | 
|  | 134 | } | 
|  | 135 |  | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 136 | virtual status_t dequeueBuffer(int* buf, sp<Fence>* fence, uint32_t width, uint32_t height, | 
|  | 137 | PixelFormat format, uint64_t usage, uint64_t* outBufferAge, | 
|  | 138 | FrameEventHistoryDelta* outTimestamps) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 139 | Parcel data, reply; | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 140 | bool getFrameTimestamps = (outTimestamps != nullptr); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 141 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 142 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 143 | data.writeUint32(width); | 
|  | 144 | data.writeUint32(height); | 
|  | 145 | data.writeInt32(static_cast<int32_t>(format)); | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 146 | data.writeUint64(usage); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 147 | data.writeBool(getFrameTimestamps); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 148 |  | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 149 | status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); | 
|  | 150 | if (result != NO_ERROR) { | 
|  | 151 | return result; | 
|  | 152 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 153 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 154 | *buf = reply.readInt32(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 155 | *fence = new Fence(); | 
|  | 156 | result = reply.read(**fence); | 
|  | 157 | if (result != NO_ERROR) { | 
|  | 158 | fence->clear(); | 
|  | 159 | return result; | 
| Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 160 | } | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 161 | if (outBufferAge) { | 
|  | 162 | result = reply.readUint64(outBufferAge); | 
|  | 163 | } else { | 
|  | 164 | // Read the value even if outBufferAge is nullptr: | 
|  | 165 | uint64_t bufferAge; | 
|  | 166 | result = reply.readUint64(&bufferAge); | 
|  | 167 | } | 
|  | 168 | if (result != NO_ERROR) { | 
|  | 169 | ALOGE("IGBP::dequeueBuffer failed to read buffer age: %d", result); | 
|  | 170 | return result; | 
|  | 171 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 172 | if (getFrameTimestamps) { | 
|  | 173 | result = reply.read(*outTimestamps); | 
|  | 174 | if (result != NO_ERROR) { | 
|  | 175 | ALOGE("IGBP::dequeueBuffer failed to read timestamps: %d", | 
|  | 176 | result); | 
|  | 177 | return result; | 
|  | 178 | } | 
|  | 179 | } | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 180 | result = reply.readInt32(); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 181 | return result; | 
|  | 182 | } | 
|  | 183 |  | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 184 | virtual status_t detachBuffer(int slot) { | 
|  | 185 | Parcel data, reply; | 
|  | 186 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 187 | data.writeInt32(slot); | 
|  | 188 | status_t result = remote()->transact(DETACH_BUFFER, data, &reply); | 
|  | 189 | if (result != NO_ERROR) { | 
|  | 190 | return result; | 
|  | 191 | } | 
|  | 192 | result = reply.readInt32(); | 
|  | 193 | return result; | 
|  | 194 | } | 
|  | 195 |  | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 196 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, | 
|  | 197 | sp<Fence>* outFence) { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 198 | if (outBuffer == nullptr) { | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 199 | ALOGE("detachNextBuffer: outBuffer must not be NULL"); | 
|  | 200 | return BAD_VALUE; | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 201 | } else if (outFence == nullptr) { | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 202 | ALOGE("detachNextBuffer: outFence must not be NULL"); | 
|  | 203 | return BAD_VALUE; | 
|  | 204 | } | 
|  | 205 | Parcel data, reply; | 
|  | 206 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 207 | status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply); | 
|  | 208 | if (result != NO_ERROR) { | 
|  | 209 | return result; | 
|  | 210 | } | 
|  | 211 | result = reply.readInt32(); | 
|  | 212 | if (result == NO_ERROR) { | 
|  | 213 | bool nonNull = reply.readInt32(); | 
|  | 214 | if (nonNull) { | 
|  | 215 | *outBuffer = new GraphicBuffer; | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 216 | result = reply.read(**outBuffer); | 
|  | 217 | if (result != NO_ERROR) { | 
|  | 218 | outBuffer->clear(); | 
|  | 219 | return result; | 
|  | 220 | } | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 221 | } | 
|  | 222 | nonNull = reply.readInt32(); | 
|  | 223 | if (nonNull) { | 
|  | 224 | *outFence = new Fence; | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 225 | result = reply.read(**outFence); | 
|  | 226 | if (result != NO_ERROR) { | 
|  | 227 | outBuffer->clear(); | 
|  | 228 | outFence->clear(); | 
|  | 229 | return result; | 
|  | 230 | } | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 231 | } | 
|  | 232 | } | 
|  | 233 | return result; | 
|  | 234 | } | 
|  | 235 |  | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 236 | virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) { | 
|  | 237 | Parcel data, reply; | 
|  | 238 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 239 | data.write(*buffer.get()); | 
|  | 240 | status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); | 
|  | 241 | if (result != NO_ERROR) { | 
|  | 242 | return result; | 
|  | 243 | } | 
| Chia-I Wu | c79a296 | 2017-05-15 10:32:27 -0700 | [diff] [blame] | 244 |  | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 245 | *slot = reply.readInt32(); | 
|  | 246 | result = reply.readInt32(); | 
| Chia-I Wu | c79a296 | 2017-05-15 10:32:27 -0700 | [diff] [blame] | 247 | if (result == NO_ERROR && | 
|  | 248 | (*slot < 0 || *slot >= BufferQueueDefs::NUM_BUFFER_SLOTS)) { | 
|  | 249 | ALOGE("attachBuffer returned invalid slot %d", *slot); | 
|  | 250 | android_errorWriteLog(0x534e4554, "37478824"); | 
|  | 251 | return UNKNOWN_ERROR; | 
|  | 252 | } | 
|  | 253 |  | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 254 | return result; | 
|  | 255 | } | 
|  | 256 |  | 
| Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 257 | virtual status_t queueBuffer(int buf, | 
|  | 258 | const QueueBufferInput& input, QueueBufferOutput* output) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 259 | Parcel data, reply; | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 260 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 261 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 262 | data.writeInt32(buf); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 263 | data.write(input); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 264 |  | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 265 | status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); | 
|  | 266 | if (result != NO_ERROR) { | 
|  | 267 | return result; | 
|  | 268 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 269 |  | 
|  | 270 | result = reply.read(*output); | 
|  | 271 | if (result != NO_ERROR) { | 
|  | 272 | return result; | 
|  | 273 | } | 
|  | 274 |  | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 275 | result = reply.readInt32(); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 276 | return result; | 
|  | 277 | } | 
|  | 278 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 279 | virtual status_t cancelBuffer(int buf, const sp<Fence>& fence) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 280 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 281 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 282 | data.writeInt32(buf); | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 283 | data.write(*fence.get()); | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 284 | status_t result = remote()->transact(CANCEL_BUFFER, data, &reply); | 
|  | 285 | if (result != NO_ERROR) { | 
|  | 286 | return result; | 
|  | 287 | } | 
|  | 288 | result = reply.readInt32(); | 
|  | 289 | return result; | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 290 | } | 
|  | 291 |  | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 292 | virtual int query(int what, int* value) { | 
|  | 293 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 294 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 295 | data.writeInt32(what); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 296 | status_t result = remote()->transact(QUERY, data, &reply); | 
|  | 297 | if (result != NO_ERROR) { | 
|  | 298 | return result; | 
|  | 299 | } | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 300 | value[0] = reply.readInt32(); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 301 | result = reply.readInt32(); | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 302 | return result; | 
|  | 303 | } | 
|  | 304 |  | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 305 | virtual status_t connect(const sp<IProducerListener>& listener, | 
| Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 306 | int api, bool producerControlledByApp, QueueBufferOutput* output) { | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 307 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 308 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 309 | if (listener != nullptr) { | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 310 | data.writeInt32(1); | 
| Marco Nelissen | 097ca27 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 311 | data.writeStrongBinder(IInterface::asBinder(listener)); | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 312 | } else { | 
|  | 313 | data.writeInt32(0); | 
|  | 314 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 315 | data.writeInt32(api); | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 316 | data.writeInt32(producerControlledByApp); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 317 | status_t result = remote()->transact(CONNECT, data, &reply); | 
|  | 318 | if (result != NO_ERROR) { | 
|  | 319 | return result; | 
|  | 320 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 321 | reply.read(*output); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 322 | result = reply.readInt32(); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 323 | return result; | 
|  | 324 | } | 
| Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 325 |  | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 326 | virtual status_t disconnect(int api, DisconnectMode mode) { | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 327 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 328 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 329 | data.writeInt32(api); | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 330 | data.writeInt32(static_cast<int32_t>(mode)); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 331 | status_t result =remote()->transact(DISCONNECT, data, &reply); | 
|  | 332 | if (result != NO_ERROR) { | 
|  | 333 | return result; | 
|  | 334 | } | 
|  | 335 | result = reply.readInt32(); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 336 | return result; | 
|  | 337 | } | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 338 |  | 
|  | 339 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream) { | 
|  | 340 | Parcel data, reply; | 
|  | 341 | status_t result; | 
|  | 342 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 343 | if (stream.get()) { | 
|  | 344 | data.writeInt32(true); | 
|  | 345 | data.writeNativeHandle(stream->handle()); | 
|  | 346 | } else { | 
|  | 347 | data.writeInt32(false); | 
|  | 348 | } | 
|  | 349 | if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) { | 
|  | 350 | result = reply.readInt32(); | 
|  | 351 | } | 
|  | 352 | return result; | 
|  | 353 | } | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 354 |  | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 355 | virtual void allocateBuffers(uint32_t width, uint32_t height, | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 356 | PixelFormat format, uint64_t usage) { | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 357 | Parcel data, reply; | 
|  | 358 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 359 | data.writeUint32(width); | 
|  | 360 | data.writeUint32(height); | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 361 | data.writeInt32(static_cast<int32_t>(format)); | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 362 | data.writeUint64(usage); | 
| Jorim Jaggi | 0a3e784 | 2018-07-17 13:48:33 +0200 | [diff] [blame] | 363 | status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply, TF_ONE_WAY); | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 364 | if (result != NO_ERROR) { | 
|  | 365 | ALOGE("allocateBuffers failed to transact: %d", result); | 
|  | 366 | } | 
|  | 367 | } | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 368 |  | 
|  | 369 | virtual status_t allowAllocation(bool allow) { | 
|  | 370 | Parcel data, reply; | 
|  | 371 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 372 | data.writeInt32(static_cast<int32_t>(allow)); | 
|  | 373 | status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply); | 
|  | 374 | if (result != NO_ERROR) { | 
|  | 375 | return result; | 
|  | 376 | } | 
|  | 377 | result = reply.readInt32(); | 
|  | 378 | return result; | 
|  | 379 | } | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 380 |  | 
|  | 381 | virtual status_t setGenerationNumber(uint32_t generationNumber) { | 
|  | 382 | Parcel data, reply; | 
|  | 383 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 384 | data.writeUint32(generationNumber); | 
|  | 385 | status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply); | 
|  | 386 | if (result == NO_ERROR) { | 
|  | 387 | result = reply.readInt32(); | 
|  | 388 | } | 
|  | 389 | return result; | 
|  | 390 | } | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 391 |  | 
|  | 392 | virtual String8 getConsumerName() const { | 
|  | 393 | Parcel data, reply; | 
|  | 394 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 395 | status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply); | 
|  | 396 | if (result != NO_ERROR) { | 
|  | 397 | ALOGE("getConsumerName failed to transact: %d", result); | 
|  | 398 | return String8("TransactFailed"); | 
|  | 399 | } | 
|  | 400 | return reply.readString8(); | 
|  | 401 | } | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 402 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 403 | virtual status_t setSharedBufferMode(bool sharedBufferMode) { | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 404 | Parcel data, reply; | 
|  | 405 | data.writeInterfaceToken( | 
|  | 406 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 407 | data.writeInt32(sharedBufferMode); | 
|  | 408 | status_t result = remote()->transact(SET_SHARED_BUFFER_MODE, data, | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 409 | &reply); | 
|  | 410 | if (result == NO_ERROR) { | 
|  | 411 | result = reply.readInt32(); | 
|  | 412 | } | 
|  | 413 | return result; | 
|  | 414 | } | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 415 |  | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 416 | virtual status_t setAutoRefresh(bool autoRefresh) { | 
|  | 417 | Parcel data, reply; | 
|  | 418 | data.writeInterfaceToken( | 
|  | 419 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 420 | data.writeInt32(autoRefresh); | 
|  | 421 | status_t result = remote()->transact(SET_AUTO_REFRESH, data, &reply); | 
|  | 422 | if (result == NO_ERROR) { | 
|  | 423 | result = reply.readInt32(); | 
|  | 424 | } | 
|  | 425 | return result; | 
|  | 426 | } | 
|  | 427 |  | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 428 | virtual status_t setDequeueTimeout(nsecs_t timeout) { | 
|  | 429 | Parcel data, reply; | 
|  | 430 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 431 | data.writeInt64(timeout); | 
|  | 432 | status_t result = remote()->transact(SET_DEQUEUE_TIMEOUT, data, &reply); | 
|  | 433 | if (result != NO_ERROR) { | 
|  | 434 | ALOGE("setDequeueTimeout failed to transact: %d", result); | 
|  | 435 | return result; | 
|  | 436 | } | 
|  | 437 | return reply.readInt32(); | 
|  | 438 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 439 |  | 
|  | 440 | virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 441 | sp<Fence>* outFence, float outTransformMatrix[16]) override { | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 442 | Parcel data, reply; | 
|  | 443 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 444 | status_t result = remote()->transact(GET_LAST_QUEUED_BUFFER, data, | 
|  | 445 | &reply); | 
|  | 446 | if (result != NO_ERROR) { | 
|  | 447 | ALOGE("getLastQueuedBuffer failed to transact: %d", result); | 
|  | 448 | return result; | 
|  | 449 | } | 
|  | 450 | result = reply.readInt32(); | 
|  | 451 | if (result != NO_ERROR) { | 
|  | 452 | return result; | 
|  | 453 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 454 | bool hasBuffer = reply.readBool(); | 
|  | 455 | sp<GraphicBuffer> buffer; | 
|  | 456 | if (hasBuffer) { | 
|  | 457 | buffer = new GraphicBuffer(); | 
|  | 458 | result = reply.read(*buffer); | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 459 | if (result == NO_ERROR) { | 
|  | 460 | result = reply.read(outTransformMatrix, sizeof(float) * 16); | 
|  | 461 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 462 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 463 | if (result != NO_ERROR) { | 
|  | 464 | ALOGE("getLastQueuedBuffer failed to read buffer: %d", result); | 
|  | 465 | return result; | 
|  | 466 | } | 
|  | 467 | sp<Fence> fence(new Fence); | 
|  | 468 | result = reply.read(*fence); | 
|  | 469 | if (result != NO_ERROR) { | 
|  | 470 | ALOGE("getLastQueuedBuffer failed to read fence: %d", result); | 
|  | 471 | return result; | 
|  | 472 | } | 
|  | 473 | *outBuffer = buffer; | 
|  | 474 | *outFence = fence; | 
|  | 475 | return result; | 
|  | 476 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 477 |  | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 478 | virtual void getFrameTimestamps(FrameEventHistoryDelta* outDelta) { | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 479 | Parcel data, reply; | 
|  | 480 | status_t result = data.writeInterfaceToken( | 
|  | 481 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 482 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 483 | ALOGE("IGBP::getFrameTimestamps failed to write token: %d", result); | 
|  | 484 | return; | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 485 | } | 
|  | 486 | result = remote()->transact(GET_FRAME_TIMESTAMPS, data, &reply); | 
|  | 487 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 488 | ALOGE("IGBP::getFrameTimestamps failed to transact: %d", result); | 
|  | 489 | return; | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 490 | } | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 491 | result = reply.read(*outDelta); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 492 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 493 | ALOGE("IGBP::getFrameTimestamps failed to read timestamps: %d", | 
|  | 494 | result); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 495 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 496 | } | 
| Pablo Ceballos | 6155b40 | 2016-06-30 17:01:49 -0700 | [diff] [blame] | 497 |  | 
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 498 | virtual status_t getUniqueId(uint64_t* outId) const { | 
|  | 499 | Parcel data, reply; | 
|  | 500 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 501 | status_t result = remote()->transact(GET_UNIQUE_ID, data, &reply); | 
|  | 502 | if (result != NO_ERROR) { | 
|  | 503 | ALOGE("getUniqueId failed to transact: %d", result); | 
|  | 504 | } | 
|  | 505 | status_t actualResult = NO_ERROR; | 
|  | 506 | result = reply.readInt32(&actualResult); | 
|  | 507 | if (result != NO_ERROR) { | 
|  | 508 | return result; | 
|  | 509 | } | 
|  | 510 | result = reply.readUint64(outId); | 
|  | 511 | if (result != NO_ERROR) { | 
|  | 512 | return result; | 
|  | 513 | } | 
|  | 514 | return actualResult; | 
|  | 515 | } | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 516 |  | 
|  | 517 | virtual status_t getConsumerUsage(uint64_t* outUsage) const { | 
|  | 518 | Parcel data, reply; | 
|  | 519 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 520 | status_t result = remote()->transact(GET_CONSUMER_USAGE, data, &reply); | 
|  | 521 | if (result != NO_ERROR) { | 
|  | 522 | ALOGE("getConsumerUsage failed to transact: %d", result); | 
|  | 523 | } | 
|  | 524 | status_t actualResult = NO_ERROR; | 
|  | 525 | result = reply.readInt32(&actualResult); | 
|  | 526 | if (result != NO_ERROR) { | 
|  | 527 | return result; | 
|  | 528 | } | 
|  | 529 | result = reply.readUint64(outUsage); | 
|  | 530 | if (result != NO_ERROR) { | 
|  | 531 | return result; | 
|  | 532 | } | 
|  | 533 | return actualResult; | 
|  | 534 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 535 | }; | 
|  | 536 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 537 | // Out-of-line virtual method definition to trigger vtable emission in this | 
|  | 538 | // translation unit (see clang warning -Wweak-vtables) | 
|  | 539 | BpGraphicBufferProducer::~BpGraphicBufferProducer() {} | 
|  | 540 |  | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 541 | class HpGraphicBufferProducer : public HpInterface< | 
| Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 542 | BpGraphicBufferProducer, | 
|  | 543 | H2BGraphicBufferProducerV1_0, | 
|  | 544 | H2BGraphicBufferProducerV2_0> { | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 545 | public: | 
| Chih-Hung Hsieh | aaf6216 | 2018-12-20 15:45:04 -0800 | [diff] [blame] | 546 | explicit HpGraphicBufferProducer(const sp<IBinder>& base) : PBase(base) {} | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 547 |  | 
|  | 548 | status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) override { | 
|  | 549 | return mBase->requestBuffer(slot, buf); | 
|  | 550 | } | 
|  | 551 |  | 
|  | 552 | status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) override { | 
|  | 553 | return mBase->setMaxDequeuedBufferCount(maxDequeuedBuffers); | 
|  | 554 | } | 
|  | 555 |  | 
|  | 556 | status_t setAsyncMode(bool async) override { | 
|  | 557 | return mBase->setAsyncMode(async); | 
|  | 558 | } | 
|  | 559 |  | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 560 | status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h, PixelFormat format, | 
|  | 561 | uint64_t usage, uint64_t* outBufferAge, | 
|  | 562 | FrameEventHistoryDelta* outTimestamps) override { | 
|  | 563 | return mBase->dequeueBuffer(slot, fence, w, h, format, usage, outBufferAge, outTimestamps); | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 564 | } | 
|  | 565 |  | 
|  | 566 | status_t detachBuffer(int slot) override { | 
|  | 567 | return mBase->detachBuffer(slot); | 
|  | 568 | } | 
|  | 569 |  | 
|  | 570 | status_t detachNextBuffer( | 
|  | 571 | sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) override { | 
|  | 572 | return mBase->detachNextBuffer(outBuffer, outFence); | 
|  | 573 | } | 
|  | 574 |  | 
|  | 575 | status_t attachBuffer( | 
|  | 576 | int* outSlot, const sp<GraphicBuffer>& buffer) override { | 
|  | 577 | return mBase->attachBuffer(outSlot, buffer); | 
|  | 578 | } | 
|  | 579 |  | 
|  | 580 | status_t queueBuffer( | 
|  | 581 | int slot, | 
|  | 582 | const QueueBufferInput& input, | 
|  | 583 | QueueBufferOutput* output) override { | 
|  | 584 | return mBase->queueBuffer(slot, input, output); | 
|  | 585 | } | 
|  | 586 |  | 
|  | 587 | status_t cancelBuffer(int slot, const sp<Fence>& fence) override { | 
|  | 588 | return mBase->cancelBuffer(slot, fence); | 
|  | 589 | } | 
|  | 590 |  | 
|  | 591 | int query(int what, int* value) override { | 
|  | 592 | return mBase->query(what, value); | 
|  | 593 | } | 
|  | 594 |  | 
|  | 595 | status_t connect( | 
|  | 596 | const sp<IProducerListener>& listener, | 
|  | 597 | int api, bool producerControlledByApp, | 
|  | 598 | QueueBufferOutput* output) override { | 
|  | 599 | return mBase->connect(listener, api, producerControlledByApp, output); | 
|  | 600 | } | 
|  | 601 |  | 
|  | 602 | status_t disconnect( | 
|  | 603 | int api, DisconnectMode mode = DisconnectMode::Api) override { | 
|  | 604 | return mBase->disconnect(api, mode); | 
|  | 605 | } | 
|  | 606 |  | 
|  | 607 | status_t setSidebandStream(const sp<NativeHandle>& stream) override { | 
|  | 608 | return mBase->setSidebandStream(stream); | 
|  | 609 | } | 
|  | 610 |  | 
|  | 611 | void allocateBuffers(uint32_t width, uint32_t height, | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 612 | PixelFormat format, uint64_t usage) override { | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 613 | return mBase->allocateBuffers(width, height, format, usage); | 
|  | 614 | } | 
|  | 615 |  | 
|  | 616 | status_t allowAllocation(bool allow) override { | 
|  | 617 | return mBase->allowAllocation(allow); | 
|  | 618 | } | 
|  | 619 |  | 
|  | 620 | status_t setGenerationNumber(uint32_t generationNumber) override { | 
|  | 621 | return mBase->setGenerationNumber(generationNumber); | 
|  | 622 | } | 
|  | 623 |  | 
|  | 624 | String8 getConsumerName() const override { | 
|  | 625 | return mBase->getConsumerName(); | 
|  | 626 | } | 
|  | 627 |  | 
|  | 628 | status_t setSharedBufferMode(bool sharedBufferMode) override { | 
|  | 629 | return mBase->setSharedBufferMode(sharedBufferMode); | 
|  | 630 | } | 
|  | 631 |  | 
|  | 632 | status_t setAutoRefresh(bool autoRefresh) override { | 
|  | 633 | return mBase->setAutoRefresh(autoRefresh); | 
|  | 634 | } | 
|  | 635 |  | 
|  | 636 | status_t setDequeueTimeout(nsecs_t timeout) override { | 
|  | 637 | return mBase->setDequeueTimeout(timeout); | 
|  | 638 | } | 
|  | 639 |  | 
|  | 640 | status_t getLastQueuedBuffer( | 
|  | 641 | sp<GraphicBuffer>* outBuffer, | 
|  | 642 | sp<Fence>* outFence, | 
|  | 643 | float outTransformMatrix[16]) override { | 
|  | 644 | return mBase->getLastQueuedBuffer( | 
|  | 645 | outBuffer, outFence, outTransformMatrix); | 
|  | 646 | } | 
|  | 647 |  | 
|  | 648 | void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override { | 
|  | 649 | return mBase->getFrameTimestamps(outDelta); | 
|  | 650 | } | 
|  | 651 |  | 
|  | 652 | status_t getUniqueId(uint64_t* outId) const override { | 
|  | 653 | return mBase->getUniqueId(outId); | 
|  | 654 | } | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 655 |  | 
|  | 656 | status_t getConsumerUsage(uint64_t* outUsage) const override { | 
|  | 657 | return mBase->getConsumerUsage(outUsage); | 
|  | 658 | } | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 659 | }; | 
|  | 660 |  | 
| Pawin Vongmasa | 338b81d | 2019-01-31 05:20:07 -0800 | [diff] [blame] | 661 | IMPLEMENT_HYBRID_META_INTERFACE(GraphicBufferProducer, | 
| Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 662 | "android.gui.IGraphicBufferProducer"); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 663 |  | 
|  | 664 | // ---------------------------------------------------------------------- | 
|  | 665 |  | 
| Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 666 | status_t IGraphicBufferProducer::exportToParcel(Parcel* parcel) { | 
|  | 667 | status_t res = OK; | 
|  | 668 | res = parcel->writeUint32(USE_BUFFER_QUEUE); | 
|  | 669 | if (res != NO_ERROR) { | 
|  | 670 | ALOGE("exportToParcel: Cannot write magic, res=%d.", res); | 
|  | 671 | return res; | 
|  | 672 | } | 
|  | 673 |  | 
|  | 674 | return parcel->writeStrongBinder(IInterface::asBinder(this)); | 
|  | 675 | } | 
|  | 676 |  | 
|  | 677 | /* static */ | 
|  | 678 | status_t IGraphicBufferProducer::exportToParcel(const sp<IGraphicBufferProducer>& producer, | 
|  | 679 | Parcel* parcel) { | 
|  | 680 | if (parcel == nullptr) { | 
|  | 681 | ALOGE("exportToParcel: Invalid parcel object."); | 
|  | 682 | return BAD_VALUE; | 
|  | 683 | } | 
|  | 684 |  | 
|  | 685 | if (producer == nullptr) { | 
|  | 686 | status_t res = OK; | 
|  | 687 | res = parcel->writeUint32(IGraphicBufferProducer::USE_BUFFER_QUEUE); | 
|  | 688 | if (res != NO_ERROR) return res; | 
|  | 689 | return parcel->writeStrongBinder(nullptr); | 
|  | 690 | } else { | 
|  | 691 | return producer->exportToParcel(parcel); | 
|  | 692 | } | 
|  | 693 | } | 
|  | 694 |  | 
|  | 695 | /* static */ | 
|  | 696 | sp<IGraphicBufferProducer> IGraphicBufferProducer::createFromParcel(const Parcel* parcel) { | 
|  | 697 | uint32_t outMagic = 0; | 
|  | 698 | status_t res = NO_ERROR; | 
|  | 699 |  | 
|  | 700 | res = parcel->readUint32(&outMagic); | 
|  | 701 | if (res != NO_ERROR) { | 
|  | 702 | ALOGE("createFromParcel: Failed to read magic, error=%d.", res); | 
|  | 703 | return nullptr; | 
|  | 704 | } | 
|  | 705 |  | 
|  | 706 | switch (outMagic) { | 
|  | 707 | case USE_BUFFER_QUEUE: { | 
|  | 708 | sp<IBinder> binder; | 
|  | 709 | res = parcel->readNullableStrongBinder(&binder); | 
|  | 710 | if (res != NO_ERROR) { | 
|  | 711 | ALOGE("createFromParcel: Can't read strong binder."); | 
|  | 712 | return nullptr; | 
|  | 713 | } | 
|  | 714 | return interface_cast<IGraphicBufferProducer>(binder); | 
|  | 715 | } | 
|  | 716 | case USE_BUFFER_HUB: { | 
|  | 717 | ALOGE("createFromParcel: BufferHub not implemented."); | 
| Jiyong Park | a75d3d6 | 2018-04-09 12:16:30 +0900 | [diff] [blame] | 718 | #ifndef NO_BUFFERHUB | 
| Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 719 | dvr::ProducerQueueParcelable producerParcelable; | 
|  | 720 | res = producerParcelable.readFromParcel(parcel); | 
|  | 721 | if (res != NO_ERROR) { | 
|  | 722 | ALOGE("createFromParcel: Failed to read from parcel, error=%d", res); | 
|  | 723 | return nullptr; | 
|  | 724 | } | 
|  | 725 | return BufferHubProducer::Create(std::move(producerParcelable)); | 
| Jiyong Park | a75d3d6 | 2018-04-09 12:16:30 +0900 | [diff] [blame] | 726 | #else | 
|  | 727 | return nullptr; | 
|  | 728 | #endif | 
| Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 729 | } | 
|  | 730 | default: { | 
|  | 731 | ALOGE("createFromParcel: Unexpected mgaic: 0x%x.", outMagic); | 
|  | 732 | return nullptr; | 
|  | 733 | } | 
|  | 734 | } | 
|  | 735 | } | 
|  | 736 |  | 
|  | 737 | // ---------------------------------------------------------------------------- | 
|  | 738 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 739 | status_t BnGraphicBufferProducer::onTransact( | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 740 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 741 | { | 
|  | 742 | switch(code) { | 
|  | 743 | case REQUEST_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 744 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 745 | int bufferIdx   = data.readInt32(); | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 746 | sp<GraphicBuffer> buffer; | 
|  | 747 | int result = requestBuffer(bufferIdx, &buffer); | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 748 | reply->writeInt32(buffer != nullptr); | 
|  | 749 | if (buffer != nullptr) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 750 | reply->write(*buffer); | 
|  | 751 | } | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 752 | reply->writeInt32(result); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 753 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 754 | } | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 755 | case SET_MAX_DEQUEUED_BUFFER_COUNT: { | 
|  | 756 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 757 | int maxDequeuedBuffers = data.readInt32(); | 
|  | 758 | int result = setMaxDequeuedBufferCount(maxDequeuedBuffers); | 
|  | 759 | reply->writeInt32(result); | 
|  | 760 | return NO_ERROR; | 
|  | 761 | } | 
|  | 762 | case SET_ASYNC_MODE: { | 
|  | 763 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 764 | bool async = data.readInt32(); | 
|  | 765 | int result = setAsyncMode(async); | 
|  | 766 | reply->writeInt32(result); | 
|  | 767 | return NO_ERROR; | 
|  | 768 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 769 | case DEQUEUE_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 770 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 771 | uint32_t width = data.readUint32(); | 
|  | 772 | uint32_t height = data.readUint32(); | 
|  | 773 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 774 | uint64_t usage = data.readUint64(); | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 775 | uint64_t bufferAge = 0; | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 776 | bool getTimestamps = data.readBool(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 777 |  | 
| Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 778 | int buf = 0; | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 779 | sp<Fence> fence = Fence::NO_FENCE; | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 780 | FrameEventHistoryDelta frameTimestamps; | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 781 | int result = dequeueBuffer(&buf, &fence, width, height, format, usage, &bufferAge, | 
|  | 782 | getTimestamps ? &frameTimestamps : nullptr); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 783 |  | 
| Tobin Ehlis | 209e5fb | 2019-03-26 14:06:29 -0600 | [diff] [blame] | 784 | if (fence == nullptr) { | 
|  | 785 | ALOGE("dequeueBuffer returned a NULL fence, setting to Fence::NO_FENCE"); | 
|  | 786 | fence = Fence::NO_FENCE; | 
|  | 787 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 788 | reply->writeInt32(buf); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 789 | reply->write(*fence); | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 790 | reply->writeUint64(bufferAge); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 791 | if (getTimestamps) { | 
|  | 792 | reply->write(frameTimestamps); | 
|  | 793 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 794 | reply->writeInt32(result); | 
|  | 795 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 796 | } | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 797 | case DETACH_BUFFER: { | 
|  | 798 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 799 | int slot = data.readInt32(); | 
|  | 800 | int result = detachBuffer(slot); | 
|  | 801 | reply->writeInt32(result); | 
|  | 802 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 803 | } | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 804 | case DETACH_NEXT_BUFFER: { | 
|  | 805 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 806 | sp<GraphicBuffer> buffer; | 
|  | 807 | sp<Fence> fence; | 
|  | 808 | int32_t result = detachNextBuffer(&buffer, &fence); | 
|  | 809 | reply->writeInt32(result); | 
|  | 810 | if (result == NO_ERROR) { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 811 | reply->writeInt32(buffer != nullptr); | 
|  | 812 | if (buffer != nullptr) { | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 813 | reply->write(*buffer); | 
|  | 814 | } | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 815 | reply->writeInt32(fence != nullptr); | 
|  | 816 | if (fence != nullptr) { | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 817 | reply->write(*fence); | 
|  | 818 | } | 
|  | 819 | } | 
|  | 820 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 821 | } | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 822 | case ATTACH_BUFFER: { | 
|  | 823 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 824 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 825 | status_t result = data.read(*buffer.get()); | 
| Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 826 | int slot = 0; | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 827 | if (result == NO_ERROR) { | 
|  | 828 | result = attachBuffer(&slot, buffer); | 
|  | 829 | } | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 830 | reply->writeInt32(slot); | 
|  | 831 | reply->writeInt32(result); | 
|  | 832 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 833 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 834 | case QUEUE_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 835 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 836 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 837 | int buf = data.readInt32(); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 838 | QueueBufferInput input(data); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 839 | QueueBufferOutput output; | 
|  | 840 | status_t result = queueBuffer(buf, input, &output); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 841 | reply->write(output); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 842 | reply->writeInt32(result); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 843 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 844 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 845 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 846 | case CANCEL_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 847 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 848 | int buf = data.readInt32(); | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 849 | sp<Fence> fence = new Fence(); | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 850 | status_t result = data.read(*fence.get()); | 
|  | 851 | if (result == NO_ERROR) { | 
|  | 852 | result = cancelBuffer(buf, fence); | 
|  | 853 | } | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 854 | reply->writeInt32(result); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 855 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 856 | } | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 857 | case QUERY: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 858 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 859 | int value = 0; | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 860 | int what = data.readInt32(); | 
|  | 861 | int res = query(what, &value); | 
|  | 862 | reply->writeInt32(value); | 
|  | 863 | reply->writeInt32(res); | 
|  | 864 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 865 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 866 | case CONNECT: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 867 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 868 | sp<IProducerListener> listener; | 
|  | 869 | if (data.readInt32() == 1) { | 
|  | 870 | listener = IProducerListener::asInterface(data.readStrongBinder()); | 
|  | 871 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 872 | int api = data.readInt32(); | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 873 | bool producerControlledByApp = data.readInt32(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 874 | QueueBufferOutput output; | 
|  | 875 | status_t res = connect(listener, api, producerControlledByApp, &output); | 
|  | 876 | reply->write(output); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 877 | reply->writeInt32(res); | 
|  | 878 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 879 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 880 | case DISCONNECT: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 881 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 882 | int api = data.readInt32(); | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 883 | DisconnectMode mode = static_cast<DisconnectMode>(data.readInt32()); | 
|  | 884 | status_t res = disconnect(api, mode); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 885 | reply->writeInt32(res); | 
|  | 886 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 887 | } | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 888 | case SET_SIDEBAND_STREAM: { | 
|  | 889 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 890 | sp<NativeHandle> stream; | 
|  | 891 | if (data.readInt32()) { | 
| Wonsik Kim | 0ec54e1 | 2014-03-21 10:46:24 +0900 | [diff] [blame] | 892 | stream = NativeHandle::create(data.readNativeHandle(), true); | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 893 | } | 
|  | 894 | status_t result = setSidebandStream(stream); | 
|  | 895 | reply->writeInt32(result); | 
|  | 896 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 897 | } | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 898 | case ALLOCATE_BUFFERS: { | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 899 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 900 | uint32_t width = data.readUint32(); | 
|  | 901 | uint32_t height = data.readUint32(); | 
|  | 902 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 903 | uint64_t usage = data.readUint64(); | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 904 | allocateBuffers(width, height, format, usage); | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 905 | return NO_ERROR; | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 906 | } | 
|  | 907 | case ALLOW_ALLOCATION: { | 
|  | 908 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 909 | bool allow = static_cast<bool>(data.readInt32()); | 
|  | 910 | status_t result = allowAllocation(allow); | 
|  | 911 | reply->writeInt32(result); | 
|  | 912 | return NO_ERROR; | 
|  | 913 | } | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 914 | case SET_GENERATION_NUMBER: { | 
|  | 915 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 916 | uint32_t generationNumber = data.readUint32(); | 
|  | 917 | status_t result = setGenerationNumber(generationNumber); | 
|  | 918 | reply->writeInt32(result); | 
|  | 919 | return NO_ERROR; | 
|  | 920 | } | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 921 | case GET_CONSUMER_NAME: { | 
|  | 922 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 923 | reply->writeString8(getConsumerName()); | 
|  | 924 | return NO_ERROR; | 
|  | 925 | } | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 926 | case SET_SHARED_BUFFER_MODE: { | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 927 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 928 | bool sharedBufferMode = data.readInt32(); | 
|  | 929 | status_t result = setSharedBufferMode(sharedBufferMode); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 930 | reply->writeInt32(result); | 
|  | 931 | return NO_ERROR; | 
|  | 932 | } | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 933 | case SET_AUTO_REFRESH: { | 
|  | 934 | CHECK_INTERFACE(IGraphicBuffer, data, reply); | 
|  | 935 | bool autoRefresh = data.readInt32(); | 
|  | 936 | status_t result = setAutoRefresh(autoRefresh); | 
|  | 937 | reply->writeInt32(result); | 
|  | 938 | return NO_ERROR; | 
|  | 939 | } | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 940 | case SET_DEQUEUE_TIMEOUT: { | 
|  | 941 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 942 | nsecs_t timeout = data.readInt64(); | 
|  | 943 | status_t result = setDequeueTimeout(timeout); | 
|  | 944 | reply->writeInt32(result); | 
|  | 945 | return NO_ERROR; | 
|  | 946 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 947 | case GET_LAST_QUEUED_BUFFER: { | 
|  | 948 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 949 | sp<GraphicBuffer> buffer(nullptr); | 
|  | 950 | sp<Fence> fence(Fence::NO_FENCE); | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 951 | float transform[16] = {}; | 
|  | 952 | status_t result = getLastQueuedBuffer(&buffer, &fence, transform); | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 953 | reply->writeInt32(result); | 
|  | 954 | if (result != NO_ERROR) { | 
|  | 955 | return result; | 
|  | 956 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 957 | if (!buffer.get()) { | 
|  | 958 | reply->writeBool(false); | 
|  | 959 | } else { | 
|  | 960 | reply->writeBool(true); | 
|  | 961 | result = reply->write(*buffer); | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 962 | if (result == NO_ERROR) { | 
|  | 963 | reply->write(transform, sizeof(float) * 16); | 
|  | 964 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 965 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 966 | if (result != NO_ERROR) { | 
|  | 967 | ALOGE("getLastQueuedBuffer failed to write buffer: %d", result); | 
|  | 968 | return result; | 
|  | 969 | } | 
| Tobin Ehlis | 209e5fb | 2019-03-26 14:06:29 -0600 | [diff] [blame] | 970 | if (fence == nullptr) { | 
|  | 971 | ALOGE("getLastQueuedBuffer returned a NULL fence, setting to Fence::NO_FENCE"); | 
|  | 972 | fence = Fence::NO_FENCE; | 
|  | 973 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 974 | result = reply->write(*fence); | 
|  | 975 | if (result != NO_ERROR) { | 
|  | 976 | ALOGE("getLastQueuedBuffer failed to write fence: %d", result); | 
|  | 977 | return result; | 
|  | 978 | } | 
|  | 979 | return NO_ERROR; | 
|  | 980 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 981 | case GET_FRAME_TIMESTAMPS: { | 
|  | 982 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 983 | FrameEventHistoryDelta frameTimestamps; | 
|  | 984 | getFrameTimestamps(&frameTimestamps); | 
|  | 985 | status_t result = reply->write(frameTimestamps); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 986 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 987 | ALOGE("BnGBP::GET_FRAME_TIMESTAMPS failed to write buffer: %d", | 
|  | 988 | result); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 989 | return result; | 
|  | 990 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 991 | return NO_ERROR; | 
|  | 992 | } | 
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 993 | case GET_UNIQUE_ID: { | 
|  | 994 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 995 | uint64_t outId = 0; | 
|  | 996 | status_t actualResult = getUniqueId(&outId); | 
|  | 997 | status_t result = reply->writeInt32(actualResult); | 
|  | 998 | if (result != NO_ERROR) { | 
|  | 999 | return result; | 
|  | 1000 | } | 
|  | 1001 | result = reply->writeUint64(outId); | 
|  | 1002 | if (result != NO_ERROR) { | 
|  | 1003 | return result; | 
|  | 1004 | } | 
|  | 1005 | return NO_ERROR; | 
|  | 1006 | } | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 1007 | case GET_CONSUMER_USAGE: { | 
|  | 1008 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 1009 | uint64_t outUsage = 0; | 
|  | 1010 | status_t actualResult = getConsumerUsage(&outUsage); | 
|  | 1011 | status_t result = reply->writeInt32(actualResult); | 
|  | 1012 | if (result != NO_ERROR) { | 
|  | 1013 | return result; | 
|  | 1014 | } | 
|  | 1015 | result = reply->writeUint64(outUsage); | 
|  | 1016 | if (result != NO_ERROR) { | 
|  | 1017 | return result; | 
|  | 1018 | } | 
|  | 1019 | return NO_ERROR; | 
|  | 1020 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1021 | } | 
|  | 1022 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 1023 | } | 
|  | 1024 |  | 
|  | 1025 | // ---------------------------------------------------------------------------- | 
|  | 1026 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 1027 | IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) { | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1028 | parcel.read(*this); | 
|  | 1029 | } | 
|  | 1030 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1031 | constexpr size_t IGraphicBufferProducer::QueueBufferInput::minFlattenedSize() { | 
|  | 1032 | return sizeof(timestamp) + | 
|  | 1033 | sizeof(isAutoTimestamp) + | 
|  | 1034 | sizeof(dataSpace) + | 
|  | 1035 | sizeof(crop) + | 
|  | 1036 | sizeof(scalingMode) + | 
|  | 1037 | sizeof(transform) + | 
|  | 1038 | sizeof(stickyTransform) + | 
|  | 1039 | sizeof(getFrameTimestamps); | 
|  | 1040 | } | 
|  | 1041 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1042 | size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1043 | return minFlattenedSize() + | 
|  | 1044 | fence->getFlattenedSize() + | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 1045 | surfaceDamage.getFlattenedSize() + | 
|  | 1046 | hdrMetadata.getFlattenedSize(); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1047 | } | 
|  | 1048 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1049 | size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const { | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 1050 | return fence->getFdCount(); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1051 | } | 
|  | 1052 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1053 | status_t IGraphicBufferProducer::QueueBufferInput::flatten( | 
|  | 1054 | void*& buffer, size_t& size, int*& fds, size_t& count) const | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1055 | { | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1056 | if (size < getFlattenedSize()) { | 
|  | 1057 | return NO_MEMORY; | 
|  | 1058 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1059 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1060 | FlattenableUtils::write(buffer, size, timestamp); | 
| Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 1061 | FlattenableUtils::write(buffer, size, isAutoTimestamp); | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 1062 | FlattenableUtils::write(buffer, size, dataSpace); | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1063 | FlattenableUtils::write(buffer, size, crop); | 
|  | 1064 | FlattenableUtils::write(buffer, size, scalingMode); | 
|  | 1065 | FlattenableUtils::write(buffer, size, transform); | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1066 | FlattenableUtils::write(buffer, size, stickyTransform); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1067 | FlattenableUtils::write(buffer, size, getFrameTimestamps); | 
|  | 1068 |  | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1069 | status_t result = fence->flatten(buffer, size, fds, count); | 
|  | 1070 | if (result != NO_ERROR) { | 
|  | 1071 | return result; | 
|  | 1072 | } | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 1073 | result = surfaceDamage.flatten(buffer, size); | 
|  | 1074 | if (result != NO_ERROR) { | 
|  | 1075 | return result; | 
|  | 1076 | } | 
|  | 1077 | FlattenableUtils::advance(buffer, size, surfaceDamage.getFlattenedSize()); | 
|  | 1078 | return hdrMetadata.flatten(buffer, size); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1079 | } | 
|  | 1080 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1081 | status_t IGraphicBufferProducer::QueueBufferInput::unflatten( | 
|  | 1082 | void const*& buffer, size_t& size, int const*& fds, size_t& count) | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1083 | { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1084 | if (size < minFlattenedSize()) { | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1085 | return NO_MEMORY; | 
|  | 1086 | } | 
|  | 1087 |  | 
|  | 1088 | FlattenableUtils::read(buffer, size, timestamp); | 
| Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 1089 | FlattenableUtils::read(buffer, size, isAutoTimestamp); | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 1090 | FlattenableUtils::read(buffer, size, dataSpace); | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1091 | FlattenableUtils::read(buffer, size, crop); | 
|  | 1092 | FlattenableUtils::read(buffer, size, scalingMode); | 
|  | 1093 | FlattenableUtils::read(buffer, size, transform); | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 1094 | FlattenableUtils::read(buffer, size, stickyTransform); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1095 | FlattenableUtils::read(buffer, size, getFrameTimestamps); | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 1096 |  | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 1097 | fence = new Fence(); | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 1098 | status_t result = fence->unflatten(buffer, size, fds, count); | 
|  | 1099 | if (result != NO_ERROR) { | 
|  | 1100 | return result; | 
|  | 1101 | } | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 1102 | result = surfaceDamage.unflatten(buffer, size); | 
|  | 1103 | if (result != NO_ERROR) { | 
|  | 1104 | return result; | 
|  | 1105 | } | 
|  | 1106 | FlattenableUtils::advance(buffer, size, surfaceDamage.getFlattenedSize()); | 
|  | 1107 | return hdrMetadata.unflatten(buffer, size); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 1108 | } | 
|  | 1109 |  | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1110 | // ---------------------------------------------------------------------------- | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1111 | constexpr size_t IGraphicBufferProducer::QueueBufferOutput::minFlattenedSize() { | 
|  | 1112 | return sizeof(width) + | 
|  | 1113 | sizeof(height) + | 
|  | 1114 | sizeof(transformHint) + | 
|  | 1115 | sizeof(numPendingBuffers) + | 
| Shuzhen Wang | 22f842b | 2017-01-18 23:02:36 -0800 | [diff] [blame] | 1116 | sizeof(nextFrameNumber) + | 
|  | 1117 | sizeof(bufferReplaced); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1118 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1119 |  | 
|  | 1120 | size_t IGraphicBufferProducer::QueueBufferOutput::getFlattenedSize() const { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1121 | return minFlattenedSize() + frameTimestamps.getFlattenedSize(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1122 | } | 
|  | 1123 |  | 
|  | 1124 | size_t IGraphicBufferProducer::QueueBufferOutput::getFdCount() const { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1125 | return frameTimestamps.getFdCount(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1126 | } | 
|  | 1127 |  | 
|  | 1128 | status_t IGraphicBufferProducer::QueueBufferOutput::flatten( | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1129 | void*& buffer, size_t& size, int*& fds, size_t& count) const | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1130 | { | 
|  | 1131 | if (size < getFlattenedSize()) { | 
|  | 1132 | return NO_MEMORY; | 
|  | 1133 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1134 |  | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1135 | FlattenableUtils::write(buffer, size, width); | 
|  | 1136 | FlattenableUtils::write(buffer, size, height); | 
|  | 1137 | FlattenableUtils::write(buffer, size, transformHint); | 
|  | 1138 | FlattenableUtils::write(buffer, size, numPendingBuffers); | 
|  | 1139 | FlattenableUtils::write(buffer, size, nextFrameNumber); | 
| Shuzhen Wang | 22f842b | 2017-01-18 23:02:36 -0800 | [diff] [blame] | 1140 | FlattenableUtils::write(buffer, size, bufferReplaced); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1141 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1142 | return frameTimestamps.flatten(buffer, size, fds, count); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1143 | } | 
|  | 1144 |  | 
|  | 1145 | status_t IGraphicBufferProducer::QueueBufferOutput::unflatten( | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1146 | void const*& buffer, size_t& size, int const*& fds, size_t& count) | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1147 | { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1148 | if (size < minFlattenedSize()) { | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1149 | return NO_MEMORY; | 
|  | 1150 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1151 |  | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1152 | FlattenableUtils::read(buffer, size, width); | 
|  | 1153 | FlattenableUtils::read(buffer, size, height); | 
|  | 1154 | FlattenableUtils::read(buffer, size, transformHint); | 
|  | 1155 | FlattenableUtils::read(buffer, size, numPendingBuffers); | 
|  | 1156 | FlattenableUtils::read(buffer, size, nextFrameNumber); | 
| Shuzhen Wang | 22f842b | 2017-01-18 23:02:36 -0800 | [diff] [blame] | 1157 | FlattenableUtils::read(buffer, size, bufferReplaced); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1158 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1159 | return frameTimestamps.unflatten(buffer, size, fds, count); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 1160 | } | 
|  | 1161 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1162 | }; // namespace android |