| 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 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 30 | #include <gui/IGraphicBufferProducer.h> | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 31 | #include <gui/IProducerListener.h> | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 32 |  | 
|  | 33 | namespace android { | 
|  | 34 | // ---------------------------------------------------------------------------- | 
|  | 35 |  | 
|  | 36 | enum { | 
|  | 37 | REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 38 | DEQUEUE_BUFFER, | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 39 | DETACH_BUFFER, | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 40 | DETACH_NEXT_BUFFER, | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 41 | ATTACH_BUFFER, | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 42 | QUEUE_BUFFER, | 
|  | 43 | CANCEL_BUFFER, | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 44 | QUERY, | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 45 | CONNECT, | 
|  | 46 | DISCONNECT, | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 47 | SET_SIDEBAND_STREAM, | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 48 | ALLOCATE_BUFFERS, | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 49 | ALLOW_ALLOCATION, | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 50 | SET_GENERATION_NUMBER, | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 51 | GET_CONSUMER_NAME, | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 52 | SET_MAX_DEQUEUED_BUFFER_COUNT, | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 53 | SET_ASYNC_MODE, | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 54 | SET_SHARED_BUFFER_MODE, | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 55 | SET_AUTO_REFRESH, | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 56 | SET_DEQUEUE_TIMEOUT, | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 57 | GET_LAST_QUEUED_BUFFER, | 
| Pablo Ceballos | fc35258 | 2016-06-30 17:22:20 -0700 | [diff] [blame] | 58 | GET_FRAME_TIMESTAMPS, | 
|  | 59 | GET_UNIQUE_ID | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 60 | }; | 
|  | 61 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 62 | class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 63 | { | 
|  | 64 | public: | 
| Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 65 | explicit BpGraphicBufferProducer(const sp<IBinder>& impl) | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 66 | : BpInterface<IGraphicBufferProducer>(impl) | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 67 | { | 
|  | 68 | } | 
|  | 69 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 70 | virtual ~BpGraphicBufferProducer(); | 
|  | 71 |  | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 72 | virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 73 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 74 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 75 | data.writeInt32(bufferIdx); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 76 | status_t result =remote()->transact(REQUEST_BUFFER, data, &reply); | 
|  | 77 | if (result != NO_ERROR) { | 
|  | 78 | return result; | 
|  | 79 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 80 | bool nonNull = reply.readInt32(); | 
|  | 81 | if (nonNull) { | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 82 | *buf = new GraphicBuffer(); | 
| Lingyun Zhu | 2aff702 | 2012-11-20 19:24:35 +0800 | [diff] [blame] | 83 | result = reply.read(**buf); | 
|  | 84 | if(result != NO_ERROR) { | 
|  | 85 | (*buf).clear(); | 
|  | 86 | return result; | 
|  | 87 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 88 | } | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 89 | result = reply.readInt32(); | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 90 | return result; | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 93 | virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) { | 
|  | 94 | Parcel data, reply; | 
|  | 95 | data.writeInterfaceToken( | 
|  | 96 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 97 | data.writeInt32(maxDequeuedBuffers); | 
|  | 98 | status_t result = remote()->transact(SET_MAX_DEQUEUED_BUFFER_COUNT, | 
|  | 99 | data, &reply); | 
|  | 100 | if (result != NO_ERROR) { | 
|  | 101 | return result; | 
|  | 102 | } | 
|  | 103 | result = reply.readInt32(); | 
|  | 104 | return result; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | virtual status_t setAsyncMode(bool async) { | 
|  | 108 | Parcel data, reply; | 
|  | 109 | data.writeInterfaceToken( | 
|  | 110 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 111 | data.writeInt32(async); | 
|  | 112 | status_t result = remote()->transact(SET_ASYNC_MODE, | 
|  | 113 | data, &reply); | 
|  | 114 | if (result != NO_ERROR) { | 
|  | 115 | return result; | 
|  | 116 | } | 
|  | 117 | result = reply.readInt32(); | 
|  | 118 | return result; | 
|  | 119 | } | 
|  | 120 |  | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 121 | virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, uint32_t width, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 122 | uint32_t height, PixelFormat format, uint32_t usage, | 
|  | 123 | FrameEventHistoryDelta* outTimestamps) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 124 | Parcel data, reply; | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 125 | bool getFrameTimestamps = (outTimestamps != nullptr); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 126 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 127 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 128 | data.writeUint32(width); | 
|  | 129 | data.writeUint32(height); | 
|  | 130 | data.writeInt32(static_cast<int32_t>(format)); | 
|  | 131 | data.writeUint32(usage); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 132 | data.writeBool(getFrameTimestamps); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 133 |  | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 134 | status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); | 
|  | 135 | if (result != NO_ERROR) { | 
|  | 136 | return result; | 
|  | 137 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 138 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 139 | *buf = reply.readInt32(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 140 | *fence = new Fence(); | 
|  | 141 | result = reply.read(**fence); | 
|  | 142 | if (result != NO_ERROR) { | 
|  | 143 | fence->clear(); | 
|  | 144 | return result; | 
| Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 145 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 146 | if (getFrameTimestamps) { | 
|  | 147 | result = reply.read(*outTimestamps); | 
|  | 148 | if (result != NO_ERROR) { | 
|  | 149 | ALOGE("IGBP::dequeueBuffer failed to read timestamps: %d", | 
|  | 150 | result); | 
|  | 151 | return result; | 
|  | 152 | } | 
|  | 153 | } | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 154 | result = reply.readInt32(); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 155 | return result; | 
|  | 156 | } | 
|  | 157 |  | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 158 | virtual status_t detachBuffer(int slot) { | 
|  | 159 | Parcel data, reply; | 
|  | 160 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 161 | data.writeInt32(slot); | 
|  | 162 | status_t result = remote()->transact(DETACH_BUFFER, data, &reply); | 
|  | 163 | if (result != NO_ERROR) { | 
|  | 164 | return result; | 
|  | 165 | } | 
|  | 166 | result = reply.readInt32(); | 
|  | 167 | return result; | 
|  | 168 | } | 
|  | 169 |  | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 170 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, | 
|  | 171 | sp<Fence>* outFence) { | 
|  | 172 | if (outBuffer == NULL) { | 
|  | 173 | ALOGE("detachNextBuffer: outBuffer must not be NULL"); | 
|  | 174 | return BAD_VALUE; | 
|  | 175 | } else if (outFence == NULL) { | 
|  | 176 | ALOGE("detachNextBuffer: outFence must not be NULL"); | 
|  | 177 | return BAD_VALUE; | 
|  | 178 | } | 
|  | 179 | Parcel data, reply; | 
|  | 180 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 181 | status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply); | 
|  | 182 | if (result != NO_ERROR) { | 
|  | 183 | return result; | 
|  | 184 | } | 
|  | 185 | result = reply.readInt32(); | 
|  | 186 | if (result == NO_ERROR) { | 
|  | 187 | bool nonNull = reply.readInt32(); | 
|  | 188 | if (nonNull) { | 
|  | 189 | *outBuffer = new GraphicBuffer; | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 190 | result = reply.read(**outBuffer); | 
|  | 191 | if (result != NO_ERROR) { | 
|  | 192 | outBuffer->clear(); | 
|  | 193 | return result; | 
|  | 194 | } | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 195 | } | 
|  | 196 | nonNull = reply.readInt32(); | 
|  | 197 | if (nonNull) { | 
|  | 198 | *outFence = new Fence; | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 199 | result = reply.read(**outFence); | 
|  | 200 | if (result != NO_ERROR) { | 
|  | 201 | outBuffer->clear(); | 
|  | 202 | outFence->clear(); | 
|  | 203 | return result; | 
|  | 204 | } | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 205 | } | 
|  | 206 | } | 
|  | 207 | return result; | 
|  | 208 | } | 
|  | 209 |  | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 210 | virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) { | 
|  | 211 | Parcel data, reply; | 
|  | 212 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 213 | data.write(*buffer.get()); | 
|  | 214 | status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); | 
|  | 215 | if (result != NO_ERROR) { | 
|  | 216 | return result; | 
|  | 217 | } | 
|  | 218 | *slot = reply.readInt32(); | 
|  | 219 | result = reply.readInt32(); | 
|  | 220 | return result; | 
|  | 221 | } | 
|  | 222 |  | 
| Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 223 | virtual status_t queueBuffer(int buf, | 
|  | 224 | const QueueBufferInput& input, QueueBufferOutput* output) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 225 | Parcel data, reply; | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 226 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 227 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 228 | data.writeInt32(buf); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 229 | data.write(input); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 230 |  | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 231 | status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); | 
|  | 232 | if (result != NO_ERROR) { | 
|  | 233 | return result; | 
|  | 234 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 235 |  | 
|  | 236 | result = reply.read(*output); | 
|  | 237 | if (result != NO_ERROR) { | 
|  | 238 | return result; | 
|  | 239 | } | 
|  | 240 |  | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 241 | result = reply.readInt32(); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 242 | return result; | 
|  | 243 | } | 
|  | 244 |  | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 245 | virtual status_t cancelBuffer(int buf, const sp<Fence>& fence) { | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 246 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 247 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 248 | data.writeInt32(buf); | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 249 | data.write(*fence.get()); | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 250 | status_t result = remote()->transact(CANCEL_BUFFER, data, &reply); | 
|  | 251 | if (result != NO_ERROR) { | 
|  | 252 | return result; | 
|  | 253 | } | 
|  | 254 | result = reply.readInt32(); | 
|  | 255 | return result; | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 256 | } | 
|  | 257 |  | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 258 | virtual int query(int what, int* value) { | 
|  | 259 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 260 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 261 | data.writeInt32(what); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 262 | status_t result = remote()->transact(QUERY, data, &reply); | 
|  | 263 | if (result != NO_ERROR) { | 
|  | 264 | return result; | 
|  | 265 | } | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 266 | value[0] = reply.readInt32(); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 267 | result = reply.readInt32(); | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 268 | return result; | 
|  | 269 | } | 
|  | 270 |  | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 271 | virtual status_t connect(const sp<IProducerListener>& listener, | 
| Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 272 | int api, bool producerControlledByApp, QueueBufferOutput* output) { | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 273 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 274 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 275 | if (listener != NULL) { | 
|  | 276 | data.writeInt32(1); | 
| Marco Nelissen | 097ca27 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 277 | data.writeStrongBinder(IInterface::asBinder(listener)); | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 278 | } else { | 
|  | 279 | data.writeInt32(0); | 
|  | 280 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 281 | data.writeInt32(api); | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 282 | data.writeInt32(producerControlledByApp); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 283 | status_t result = remote()->transact(CONNECT, data, &reply); | 
|  | 284 | if (result != NO_ERROR) { | 
|  | 285 | return result; | 
|  | 286 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 287 | reply.read(*output); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 288 | result = reply.readInt32(); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 289 | return result; | 
|  | 290 | } | 
| Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 291 |  | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 292 | virtual status_t disconnect(int api, DisconnectMode mode) { | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 293 | Parcel data, reply; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 294 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 295 | data.writeInt32(api); | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 296 | data.writeInt32(static_cast<int32_t>(mode)); | 
| Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 297 | status_t result =remote()->transact(DISCONNECT, data, &reply); | 
|  | 298 | if (result != NO_ERROR) { | 
|  | 299 | return result; | 
|  | 300 | } | 
|  | 301 | result = reply.readInt32(); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 302 | return result; | 
|  | 303 | } | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 304 |  | 
|  | 305 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream) { | 
|  | 306 | Parcel data, reply; | 
|  | 307 | status_t result; | 
|  | 308 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 309 | if (stream.get()) { | 
|  | 310 | data.writeInt32(true); | 
|  | 311 | data.writeNativeHandle(stream->handle()); | 
|  | 312 | } else { | 
|  | 313 | data.writeInt32(false); | 
|  | 314 | } | 
|  | 315 | if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) { | 
|  | 316 | result = reply.readInt32(); | 
|  | 317 | } | 
|  | 318 | return result; | 
|  | 319 | } | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 320 |  | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 321 | virtual void allocateBuffers(uint32_t width, uint32_t height, | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 322 | PixelFormat format, uint32_t usage) { | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 323 | Parcel data, reply; | 
|  | 324 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 325 | data.writeUint32(width); | 
|  | 326 | data.writeUint32(height); | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 327 | data.writeInt32(static_cast<int32_t>(format)); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 328 | data.writeUint32(usage); | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 329 | status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply); | 
|  | 330 | if (result != NO_ERROR) { | 
|  | 331 | ALOGE("allocateBuffers failed to transact: %d", result); | 
|  | 332 | } | 
|  | 333 | } | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 334 |  | 
|  | 335 | virtual status_t allowAllocation(bool allow) { | 
|  | 336 | Parcel data, reply; | 
|  | 337 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 338 | data.writeInt32(static_cast<int32_t>(allow)); | 
|  | 339 | status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply); | 
|  | 340 | if (result != NO_ERROR) { | 
|  | 341 | return result; | 
|  | 342 | } | 
|  | 343 | result = reply.readInt32(); | 
|  | 344 | return result; | 
|  | 345 | } | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 346 |  | 
|  | 347 | virtual status_t setGenerationNumber(uint32_t generationNumber) { | 
|  | 348 | Parcel data, reply; | 
|  | 349 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 350 | data.writeUint32(generationNumber); | 
|  | 351 | status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply); | 
|  | 352 | if (result == NO_ERROR) { | 
|  | 353 | result = reply.readInt32(); | 
|  | 354 | } | 
|  | 355 | return result; | 
|  | 356 | } | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 357 |  | 
|  | 358 | virtual String8 getConsumerName() const { | 
|  | 359 | Parcel data, reply; | 
|  | 360 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 361 | status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply); | 
|  | 362 | if (result != NO_ERROR) { | 
|  | 363 | ALOGE("getConsumerName failed to transact: %d", result); | 
|  | 364 | return String8("TransactFailed"); | 
|  | 365 | } | 
|  | 366 | return reply.readString8(); | 
|  | 367 | } | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 368 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 369 | virtual status_t setSharedBufferMode(bool sharedBufferMode) { | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 370 | Parcel data, reply; | 
|  | 371 | data.writeInterfaceToken( | 
|  | 372 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 373 | data.writeInt32(sharedBufferMode); | 
|  | 374 | status_t result = remote()->transact(SET_SHARED_BUFFER_MODE, data, | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 375 | &reply); | 
|  | 376 | if (result == NO_ERROR) { | 
|  | 377 | result = reply.readInt32(); | 
|  | 378 | } | 
|  | 379 | return result; | 
|  | 380 | } | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 381 |  | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 382 | virtual status_t setAutoRefresh(bool autoRefresh) { | 
|  | 383 | Parcel data, reply; | 
|  | 384 | data.writeInterfaceToken( | 
|  | 385 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 386 | data.writeInt32(autoRefresh); | 
|  | 387 | status_t result = remote()->transact(SET_AUTO_REFRESH, data, &reply); | 
|  | 388 | if (result == NO_ERROR) { | 
|  | 389 | result = reply.readInt32(); | 
|  | 390 | } | 
|  | 391 | return result; | 
|  | 392 | } | 
|  | 393 |  | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 394 | virtual status_t setDequeueTimeout(nsecs_t timeout) { | 
|  | 395 | Parcel data, reply; | 
|  | 396 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 397 | data.writeInt64(timeout); | 
|  | 398 | status_t result = remote()->transact(SET_DEQUEUE_TIMEOUT, data, &reply); | 
|  | 399 | if (result != NO_ERROR) { | 
|  | 400 | ALOGE("setDequeueTimeout failed to transact: %d", result); | 
|  | 401 | return result; | 
|  | 402 | } | 
|  | 403 | return reply.readInt32(); | 
|  | 404 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 405 |  | 
|  | 406 | virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 407 | sp<Fence>* outFence, float outTransformMatrix[16]) override { | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 408 | Parcel data, reply; | 
|  | 409 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 410 | status_t result = remote()->transact(GET_LAST_QUEUED_BUFFER, data, | 
|  | 411 | &reply); | 
|  | 412 | if (result != NO_ERROR) { | 
|  | 413 | ALOGE("getLastQueuedBuffer failed to transact: %d", result); | 
|  | 414 | return result; | 
|  | 415 | } | 
|  | 416 | result = reply.readInt32(); | 
|  | 417 | if (result != NO_ERROR) { | 
|  | 418 | return result; | 
|  | 419 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 420 | bool hasBuffer = reply.readBool(); | 
|  | 421 | sp<GraphicBuffer> buffer; | 
|  | 422 | if (hasBuffer) { | 
|  | 423 | buffer = new GraphicBuffer(); | 
|  | 424 | result = reply.read(*buffer); | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 425 | if (result == NO_ERROR) { | 
|  | 426 | result = reply.read(outTransformMatrix, sizeof(float) * 16); | 
|  | 427 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 428 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 429 | if (result != NO_ERROR) { | 
|  | 430 | ALOGE("getLastQueuedBuffer failed to read buffer: %d", result); | 
|  | 431 | return result; | 
|  | 432 | } | 
|  | 433 | sp<Fence> fence(new Fence); | 
|  | 434 | result = reply.read(*fence); | 
|  | 435 | if (result != NO_ERROR) { | 
|  | 436 | ALOGE("getLastQueuedBuffer failed to read fence: %d", result); | 
|  | 437 | return result; | 
|  | 438 | } | 
|  | 439 | *outBuffer = buffer; | 
|  | 440 | *outFence = fence; | 
|  | 441 | return result; | 
|  | 442 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 443 |  | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 444 | virtual void getFrameTimestamps(FrameEventHistoryDelta* outDelta) { | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 445 | Parcel data, reply; | 
|  | 446 | status_t result = data.writeInterfaceToken( | 
|  | 447 | IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 448 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 449 | ALOGE("IGBP::getFrameTimestamps failed to write token: %d", result); | 
|  | 450 | return; | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 451 | } | 
|  | 452 | result = remote()->transact(GET_FRAME_TIMESTAMPS, data, &reply); | 
|  | 453 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 454 | ALOGE("IGBP::getFrameTimestamps failed to transact: %d", result); | 
|  | 455 | return; | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 456 | } | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 457 | result = reply.read(*outDelta); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 458 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 459 | ALOGE("IGBP::getFrameTimestamps failed to read timestamps: %d", | 
|  | 460 | result); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 461 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 462 | } | 
| Pablo Ceballos | 6155b40 | 2016-06-30 17:01:49 -0700 | [diff] [blame] | 463 |  | 
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 464 | virtual status_t getUniqueId(uint64_t* outId) const { | 
|  | 465 | Parcel data, reply; | 
|  | 466 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); | 
|  | 467 | status_t result = remote()->transact(GET_UNIQUE_ID, data, &reply); | 
|  | 468 | if (result != NO_ERROR) { | 
|  | 469 | ALOGE("getUniqueId failed to transact: %d", result); | 
|  | 470 | } | 
|  | 471 | status_t actualResult = NO_ERROR; | 
|  | 472 | result = reply.readInt32(&actualResult); | 
|  | 473 | if (result != NO_ERROR) { | 
|  | 474 | return result; | 
|  | 475 | } | 
|  | 476 | result = reply.readUint64(outId); | 
|  | 477 | if (result != NO_ERROR) { | 
|  | 478 | return result; | 
|  | 479 | } | 
|  | 480 | return actualResult; | 
|  | 481 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 482 | }; | 
|  | 483 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 484 | // Out-of-line virtual method definition to trigger vtable emission in this | 
|  | 485 | // translation unit (see clang warning -Wweak-vtables) | 
|  | 486 | BpGraphicBufferProducer::~BpGraphicBufferProducer() {} | 
|  | 487 |  | 
| Andy McFadden | 466a192 | 2013-01-08 11:25:51 -0800 | [diff] [blame] | 488 | IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer"); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 489 |  | 
|  | 490 | // ---------------------------------------------------------------------- | 
|  | 491 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 492 | status_t BnGraphicBufferProducer::onTransact( | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 493 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 494 | { | 
|  | 495 | switch(code) { | 
|  | 496 | case REQUEST_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 497 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 498 | int bufferIdx   = data.readInt32(); | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 499 | sp<GraphicBuffer> buffer; | 
|  | 500 | int result = requestBuffer(bufferIdx, &buffer); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 501 | reply->writeInt32(buffer != 0); | 
|  | 502 | if (buffer != 0) { | 
|  | 503 | reply->write(*buffer); | 
|  | 504 | } | 
| Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 505 | reply->writeInt32(result); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 506 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 507 | } | 
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 508 | case SET_MAX_DEQUEUED_BUFFER_COUNT: { | 
|  | 509 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 510 | int maxDequeuedBuffers = data.readInt32(); | 
|  | 511 | int result = setMaxDequeuedBufferCount(maxDequeuedBuffers); | 
|  | 512 | reply->writeInt32(result); | 
|  | 513 | return NO_ERROR; | 
|  | 514 | } | 
|  | 515 | case SET_ASYNC_MODE: { | 
|  | 516 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 517 | bool async = data.readInt32(); | 
|  | 518 | int result = setAsyncMode(async); | 
|  | 519 | reply->writeInt32(result); | 
|  | 520 | return NO_ERROR; | 
|  | 521 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 522 | case DEQUEUE_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 523 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 524 | uint32_t width = data.readUint32(); | 
|  | 525 | uint32_t height = data.readUint32(); | 
|  | 526 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); | 
|  | 527 | uint32_t usage = data.readUint32(); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 528 | bool getTimestamps = data.readBool(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 529 |  | 
| Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 530 | int buf = 0; | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 531 | sp<Fence> fence = Fence::NO_FENCE; | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 532 | FrameEventHistoryDelta frameTimestamps; | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 533 | int result = dequeueBuffer(&buf, &fence, width, height, format, | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 534 | usage, getTimestamps ? &frameTimestamps : nullptr); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 535 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 536 | reply->writeInt32(buf); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 537 | reply->write(*fence); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 538 | if (getTimestamps) { | 
|  | 539 | reply->write(frameTimestamps); | 
|  | 540 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 541 | reply->writeInt32(result); | 
|  | 542 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 543 | } | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 544 | case DETACH_BUFFER: { | 
|  | 545 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 546 | int slot = data.readInt32(); | 
|  | 547 | int result = detachBuffer(slot); | 
|  | 548 | reply->writeInt32(result); | 
|  | 549 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 550 | } | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 551 | case DETACH_NEXT_BUFFER: { | 
|  | 552 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 553 | sp<GraphicBuffer> buffer; | 
|  | 554 | sp<Fence> fence; | 
|  | 555 | int32_t result = detachNextBuffer(&buffer, &fence); | 
|  | 556 | reply->writeInt32(result); | 
|  | 557 | if (result == NO_ERROR) { | 
|  | 558 | reply->writeInt32(buffer != NULL); | 
|  | 559 | if (buffer != NULL) { | 
|  | 560 | reply->write(*buffer); | 
|  | 561 | } | 
|  | 562 | reply->writeInt32(fence != NULL); | 
|  | 563 | if (fence != NULL) { | 
|  | 564 | reply->write(*fence); | 
|  | 565 | } | 
|  | 566 | } | 
|  | 567 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 568 | } | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 569 | case ATTACH_BUFFER: { | 
|  | 570 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 571 | sp<GraphicBuffer> buffer = new GraphicBuffer(); | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 572 | status_t result = data.read(*buffer.get()); | 
| Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 573 | int slot = 0; | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 574 | if (result == NO_ERROR) { | 
|  | 575 | result = attachBuffer(&slot, buffer); | 
|  | 576 | } | 
| Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 577 | reply->writeInt32(slot); | 
|  | 578 | reply->writeInt32(result); | 
|  | 579 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 580 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 581 | case QUEUE_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 582 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 583 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 584 | int buf = data.readInt32(); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 585 | QueueBufferInput input(data); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 586 | QueueBufferOutput output; | 
|  | 587 | status_t result = queueBuffer(buf, input, &output); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 588 | reply->write(output); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 589 | reply->writeInt32(result); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 590 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 591 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 592 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 593 | case CANCEL_BUFFER: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 594 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 595 | int buf = data.readInt32(); | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 596 | sp<Fence> fence = new Fence(); | 
| Pablo Ceballos | 70636b3 | 2016-07-06 15:24:54 -0700 | [diff] [blame] | 597 | status_t result = data.read(*fence.get()); | 
|  | 598 | if (result == NO_ERROR) { | 
|  | 599 | result = cancelBuffer(buf, fence); | 
|  | 600 | } | 
| Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 601 | reply->writeInt32(result); | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 602 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 603 | } | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 604 | case QUERY: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 605 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Naveen Leekha | 12ba0f5 | 2015-09-21 17:28:04 -0700 | [diff] [blame] | 606 | int value = 0; | 
| Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 607 | int what = data.readInt32(); | 
|  | 608 | int res = query(what, &value); | 
|  | 609 | reply->writeInt32(value); | 
|  | 610 | reply->writeInt32(res); | 
|  | 611 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 612 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 613 | case CONNECT: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 614 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 615 | sp<IProducerListener> listener; | 
|  | 616 | if (data.readInt32() == 1) { | 
|  | 617 | listener = IProducerListener::asInterface(data.readStrongBinder()); | 
|  | 618 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 619 | int api = data.readInt32(); | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 620 | bool producerControlledByApp = data.readInt32(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 621 | QueueBufferOutput output; | 
|  | 622 | status_t res = connect(listener, api, producerControlledByApp, &output); | 
|  | 623 | reply->write(output); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 624 | reply->writeInt32(res); | 
|  | 625 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 626 | } | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 627 | case DISCONNECT: { | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 628 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 629 | int api = data.readInt32(); | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 630 | DisconnectMode mode = static_cast<DisconnectMode>(data.readInt32()); | 
|  | 631 | status_t res = disconnect(api, mode); | 
| Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 632 | reply->writeInt32(res); | 
|  | 633 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 634 | } | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 635 | case SET_SIDEBAND_STREAM: { | 
|  | 636 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 637 | sp<NativeHandle> stream; | 
|  | 638 | if (data.readInt32()) { | 
| Wonsik Kim | 0ec54e1 | 2014-03-21 10:46:24 +0900 | [diff] [blame] | 639 | stream = NativeHandle::create(data.readNativeHandle(), true); | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 640 | } | 
|  | 641 | status_t result = setSidebandStream(stream); | 
|  | 642 | reply->writeInt32(result); | 
|  | 643 | return NO_ERROR; | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 644 | } | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 645 | case ALLOCATE_BUFFERS: { | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 646 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 647 | uint32_t width = data.readUint32(); | 
|  | 648 | uint32_t height = data.readUint32(); | 
|  | 649 | PixelFormat format = static_cast<PixelFormat>(data.readInt32()); | 
|  | 650 | uint32_t usage = data.readUint32(); | 
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 651 | allocateBuffers(width, height, format, usage); | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 652 | return NO_ERROR; | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 653 | } | 
|  | 654 | case ALLOW_ALLOCATION: { | 
|  | 655 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 656 | bool allow = static_cast<bool>(data.readInt32()); | 
|  | 657 | status_t result = allowAllocation(allow); | 
|  | 658 | reply->writeInt32(result); | 
|  | 659 | return NO_ERROR; | 
|  | 660 | } | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 661 | case SET_GENERATION_NUMBER: { | 
|  | 662 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 663 | uint32_t generationNumber = data.readUint32(); | 
|  | 664 | status_t result = setGenerationNumber(generationNumber); | 
|  | 665 | reply->writeInt32(result); | 
|  | 666 | return NO_ERROR; | 
|  | 667 | } | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 668 | case GET_CONSUMER_NAME: { | 
|  | 669 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 670 | reply->writeString8(getConsumerName()); | 
|  | 671 | return NO_ERROR; | 
|  | 672 | } | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 673 | case SET_SHARED_BUFFER_MODE: { | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 674 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 675 | bool sharedBufferMode = data.readInt32(); | 
|  | 676 | status_t result = setSharedBufferMode(sharedBufferMode); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 677 | reply->writeInt32(result); | 
|  | 678 | return NO_ERROR; | 
|  | 679 | } | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 680 | case SET_AUTO_REFRESH: { | 
|  | 681 | CHECK_INTERFACE(IGraphicBuffer, data, reply); | 
|  | 682 | bool autoRefresh = data.readInt32(); | 
|  | 683 | status_t result = setAutoRefresh(autoRefresh); | 
|  | 684 | reply->writeInt32(result); | 
|  | 685 | return NO_ERROR; | 
|  | 686 | } | 
| Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 687 | case SET_DEQUEUE_TIMEOUT: { | 
|  | 688 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 689 | nsecs_t timeout = data.readInt64(); | 
|  | 690 | status_t result = setDequeueTimeout(timeout); | 
|  | 691 | reply->writeInt32(result); | 
|  | 692 | return NO_ERROR; | 
|  | 693 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 694 | case GET_LAST_QUEUED_BUFFER: { | 
|  | 695 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 696 | sp<GraphicBuffer> buffer(nullptr); | 
|  | 697 | sp<Fence> fence(Fence::NO_FENCE); | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 698 | float transform[16] = {}; | 
|  | 699 | status_t result = getLastQueuedBuffer(&buffer, &fence, transform); | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 700 | reply->writeInt32(result); | 
|  | 701 | if (result != NO_ERROR) { | 
|  | 702 | return result; | 
|  | 703 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 704 | if (!buffer.get()) { | 
|  | 705 | reply->writeBool(false); | 
|  | 706 | } else { | 
|  | 707 | reply->writeBool(true); | 
|  | 708 | result = reply->write(*buffer); | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 709 | if (result == NO_ERROR) { | 
|  | 710 | reply->write(transform, sizeof(float) * 16); | 
|  | 711 | } | 
| John Reck | ce8e5df | 2016-04-28 10:12:47 -0700 | [diff] [blame] | 712 | } | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 713 | if (result != NO_ERROR) { | 
|  | 714 | ALOGE("getLastQueuedBuffer failed to write buffer: %d", result); | 
|  | 715 | return result; | 
|  | 716 | } | 
|  | 717 | result = reply->write(*fence); | 
|  | 718 | if (result != NO_ERROR) { | 
|  | 719 | ALOGE("getLastQueuedBuffer failed to write fence: %d", result); | 
|  | 720 | return result; | 
|  | 721 | } | 
|  | 722 | return NO_ERROR; | 
|  | 723 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 724 | case GET_FRAME_TIMESTAMPS: { | 
|  | 725 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 726 | FrameEventHistoryDelta frameTimestamps; | 
|  | 727 | getFrameTimestamps(&frameTimestamps); | 
|  | 728 | status_t result = reply->write(frameTimestamps); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 729 | if (result != NO_ERROR) { | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 730 | ALOGE("BnGBP::GET_FRAME_TIMESTAMPS failed to write buffer: %d", | 
|  | 731 | result); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 732 | return result; | 
|  | 733 | } | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 734 | return NO_ERROR; | 
|  | 735 | } | 
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 736 | case GET_UNIQUE_ID: { | 
|  | 737 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); | 
|  | 738 | uint64_t outId = 0; | 
|  | 739 | status_t actualResult = getUniqueId(&outId); | 
|  | 740 | status_t result = reply->writeInt32(actualResult); | 
|  | 741 | if (result != NO_ERROR) { | 
|  | 742 | return result; | 
|  | 743 | } | 
|  | 744 | result = reply->writeUint64(outId); | 
|  | 745 | if (result != NO_ERROR) { | 
|  | 746 | return result; | 
|  | 747 | } | 
|  | 748 | return NO_ERROR; | 
|  | 749 | } | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 750 | } | 
|  | 751 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 752 | } | 
|  | 753 |  | 
|  | 754 | // ---------------------------------------------------------------------------- | 
|  | 755 |  | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 756 | IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) { | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 757 | parcel.read(*this); | 
|  | 758 | } | 
|  | 759 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 760 | constexpr size_t IGraphicBufferProducer::QueueBufferInput::minFlattenedSize() { | 
|  | 761 | return sizeof(timestamp) + | 
|  | 762 | sizeof(isAutoTimestamp) + | 
|  | 763 | sizeof(dataSpace) + | 
|  | 764 | sizeof(crop) + | 
|  | 765 | sizeof(scalingMode) + | 
|  | 766 | sizeof(transform) + | 
|  | 767 | sizeof(stickyTransform) + | 
|  | 768 | sizeof(getFrameTimestamps); | 
|  | 769 | } | 
|  | 770 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 771 | size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 772 | return minFlattenedSize() + | 
|  | 773 | fence->getFlattenedSize() + | 
|  | 774 | surfaceDamage.getFlattenedSize(); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 775 | } | 
|  | 776 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 777 | size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const { | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 778 | return fence->getFdCount(); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 779 | } | 
|  | 780 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 781 | status_t IGraphicBufferProducer::QueueBufferInput::flatten( | 
|  | 782 | void*& buffer, size_t& size, int*& fds, size_t& count) const | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 783 | { | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 784 | if (size < getFlattenedSize()) { | 
|  | 785 | return NO_MEMORY; | 
|  | 786 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 787 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 788 | FlattenableUtils::write(buffer, size, timestamp); | 
| Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 789 | FlattenableUtils::write(buffer, size, isAutoTimestamp); | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 790 | FlattenableUtils::write(buffer, size, dataSpace); | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 791 | FlattenableUtils::write(buffer, size, crop); | 
|  | 792 | FlattenableUtils::write(buffer, size, scalingMode); | 
|  | 793 | FlattenableUtils::write(buffer, size, transform); | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 794 | FlattenableUtils::write(buffer, size, stickyTransform); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 795 | FlattenableUtils::write(buffer, size, getFrameTimestamps); | 
|  | 796 |  | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 797 | status_t result = fence->flatten(buffer, size, fds, count); | 
|  | 798 | if (result != NO_ERROR) { | 
|  | 799 | return result; | 
|  | 800 | } | 
|  | 801 | return surfaceDamage.flatten(buffer, size); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 802 | } | 
|  | 803 |  | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 804 | status_t IGraphicBufferProducer::QueueBufferInput::unflatten( | 
|  | 805 | void const*& buffer, size_t& size, int const*& fds, size_t& count) | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 806 | { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 807 | if (size < minFlattenedSize()) { | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 808 | return NO_MEMORY; | 
|  | 809 | } | 
|  | 810 |  | 
|  | 811 | FlattenableUtils::read(buffer, size, timestamp); | 
| Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 812 | FlattenableUtils::read(buffer, size, isAutoTimestamp); | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 813 | FlattenableUtils::read(buffer, size, dataSpace); | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 814 | FlattenableUtils::read(buffer, size, crop); | 
|  | 815 | FlattenableUtils::read(buffer, size, scalingMode); | 
|  | 816 | FlattenableUtils::read(buffer, size, transform); | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 817 | FlattenableUtils::read(buffer, size, stickyTransform); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 818 | FlattenableUtils::read(buffer, size, getFrameTimestamps); | 
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 819 |  | 
| Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 820 | fence = new Fence(); | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 821 | status_t result = fence->unflatten(buffer, size, fds, count); | 
|  | 822 | if (result != NO_ERROR) { | 
|  | 823 | return result; | 
|  | 824 | } | 
|  | 825 | return surfaceDamage.unflatten(buffer, size); | 
| Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 826 | } | 
|  | 827 |  | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 828 | // ---------------------------------------------------------------------------- | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 829 | constexpr size_t IGraphicBufferProducer::QueueBufferOutput::minFlattenedSize() { | 
|  | 830 | return sizeof(width) + | 
|  | 831 | sizeof(height) + | 
|  | 832 | sizeof(transformHint) + | 
|  | 833 | sizeof(numPendingBuffers) + | 
|  | 834 | sizeof(nextFrameNumber); | 
|  | 835 | } | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 836 |  | 
|  | 837 | size_t IGraphicBufferProducer::QueueBufferOutput::getFlattenedSize() const { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 838 | return minFlattenedSize() + frameTimestamps.getFlattenedSize(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 839 | } | 
|  | 840 |  | 
|  | 841 | size_t IGraphicBufferProducer::QueueBufferOutput::getFdCount() const { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 842 | return frameTimestamps.getFdCount(); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 843 | } | 
|  | 844 |  | 
|  | 845 | status_t IGraphicBufferProducer::QueueBufferOutput::flatten( | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 846 | void*& buffer, size_t& size, int*& fds, size_t& count) const | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 847 | { | 
|  | 848 | if (size < getFlattenedSize()) { | 
|  | 849 | return NO_MEMORY; | 
|  | 850 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 851 |  | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 852 | FlattenableUtils::write(buffer, size, width); | 
|  | 853 | FlattenableUtils::write(buffer, size, height); | 
|  | 854 | FlattenableUtils::write(buffer, size, transformHint); | 
|  | 855 | FlattenableUtils::write(buffer, size, numPendingBuffers); | 
|  | 856 | FlattenableUtils::write(buffer, size, nextFrameNumber); | 
|  | 857 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 858 | return frameTimestamps.flatten(buffer, size, fds, count); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 859 | } | 
|  | 860 |  | 
|  | 861 | status_t IGraphicBufferProducer::QueueBufferOutput::unflatten( | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 862 | void const*& buffer, size_t& size, int const*& fds, size_t& count) | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 863 | { | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 864 | if (size < minFlattenedSize()) { | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 865 | return NO_MEMORY; | 
|  | 866 | } | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 867 |  | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 868 | FlattenableUtils::read(buffer, size, width); | 
|  | 869 | FlattenableUtils::read(buffer, size, height); | 
|  | 870 | FlattenableUtils::read(buffer, size, transformHint); | 
|  | 871 | FlattenableUtils::read(buffer, size, numPendingBuffers); | 
|  | 872 | FlattenableUtils::read(buffer, size, nextFrameNumber); | 
|  | 873 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 874 | return frameTimestamps.unflatten(buffer, size, fds, count); | 
| Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 875 | } | 
|  | 876 |  | 
| Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 877 | }; // namespace android |