blob: 18a80e80b92a463e937e4db182bf8a60c7dd40df [file] [log] [blame]
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001/*
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 Hall399184a2014-03-03 15:42:54 -080021#include <utils/NativeHandle.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080022#include <utils/RefBase.h>
Brian Anderson175a7202016-10-10 16:52:56 -070023#include <utils/String8.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080024#include <utils/Timers.h>
Jesse Hall399184a2014-03-03 15:42:54 -080025#include <utils/Vector.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080026
27#include <binder/Parcel.h>
28#include <binder/IInterface.h>
29
Andy McFadden2adaf042012-12-18 09:49:45 -080030#include <gui/IGraphicBufferProducer.h>
Dan Stozaf0eaf252014-03-21 13:05:51 -070031#include <gui/IProducerListener.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080032
33namespace android {
34// ----------------------------------------------------------------------------
35
36enum {
37 REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080038 DEQUEUE_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080039 DETACH_BUFFER,
Dan Stozad9822a32014-03-28 15:25:31 -070040 DETACH_NEXT_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080041 ATTACH_BUFFER,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080042 QUEUE_BUFFER,
43 CANCEL_BUFFER,
Mathias Agopianeafabcd2011-04-20 14:20:59 -070044 QUERY,
Jamie Gennisfe0a87b2011-07-13 19:12:20 -070045 CONNECT,
46 DISCONNECT,
Jesse Hall399184a2014-03-03 15:42:54 -080047 SET_SIDEBAND_STREAM,
Dan Stoza29a3e902014-06-20 13:13:57 -070048 ALLOCATE_BUFFERS,
Dan Stoza9de72932015-04-16 17:28:43 -070049 ALLOW_ALLOCATION,
Dan Stoza812ed062015-06-02 15:45:22 -070050 SET_GENERATION_NUMBER,
Dan Stozac6f30bd2015-06-08 09:32:50 -070051 GET_CONSUMER_NAME,
Pablo Ceballosfa455352015-08-12 17:47:47 -070052 SET_MAX_DEQUEUED_BUFFER_COUNT,
Dan Stoza7dde5992015-05-22 09:51:44 -070053 SET_ASYNC_MODE,
Pablo Ceballos3559fbf2016-03-17 15:50:23 -070054 SET_SHARED_BUFFER_MODE,
Pablo Ceballosff95aab2016-01-13 17:09:58 -080055 SET_AUTO_REFRESH,
Dan Stoza127fc632015-06-30 13:43:32 -070056 SET_DEQUEUE_TIMEOUT,
Dan Stoza50101d02016-04-07 16:53:23 -070057 GET_LAST_QUEUED_BUFFER,
Pablo Ceballosfc352582016-06-30 17:22:20 -070058 GET_FRAME_TIMESTAMPS,
59 GET_UNIQUE_ID
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080060};
61
Andy McFadden2adaf042012-12-18 09:49:45 -080062class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080063{
64public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070065 explicit BpGraphicBufferProducer(const sp<IBinder>& impl)
Andy McFadden2adaf042012-12-18 09:49:45 -080066 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080067 {
68 }
69
Dan Stoza3be1c6b2014-11-18 10:24:03 -080070 virtual ~BpGraphicBufferProducer();
71
Jamie Gennis7b305ff2011-07-19 12:08:33 -070072 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080073 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080074 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080075 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070076 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
77 if (result != NO_ERROR) {
78 return result;
79 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080080 bool nonNull = reply.readInt32();
81 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070082 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080083 result = reply.read(**buf);
84 if(result != NO_ERROR) {
85 (*buf).clear();
86 return result;
87 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080088 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070089 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070090 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080091 }
92
Pablo Ceballosfa455352015-08-12 17:47:47 -070093 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 Ceballos567dbbb2015-08-26 18:59:08 -0700121 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, uint32_t width,
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700122 uint32_t height, PixelFormat format, uint32_t usage,
123 FrameEventHistoryDelta* outTimestamps) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800124 Parcel data, reply;
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700125 bool getFrameTimestamps = (outTimestamps != nullptr);
Brian Andersonbaaad322016-07-22 15:55:13 -0700126
Andy McFadden2adaf042012-12-18 09:49:45 -0800127 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800128 data.writeUint32(width);
129 data.writeUint32(height);
130 data.writeInt32(static_cast<int32_t>(format));
131 data.writeUint32(usage);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700132 data.writeBool(getFrameTimestamps);
Brian Andersonbaaad322016-07-22 15:55:13 -0700133
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700134 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
135 if (result != NO_ERROR) {
136 return result;
137 }
Brian Andersonbaaad322016-07-22 15:55:13 -0700138
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800139 *buf = reply.readInt32();
Brian Andersonbaaad322016-07-22 15:55:13 -0700140 *fence = new Fence();
141 result = reply.read(**fence);
142 if (result != NO_ERROR) {
143 fence->clear();
144 return result;
Jesse Hallf7857542012-06-14 15:26:33 -0700145 }
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700146 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 Gennis8a29ff22011-10-14 15:03:17 -0700154 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800155 return result;
156 }
157
Dan Stoza9f3053d2014-03-06 15:14:33 -0800158 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 Stozad9822a32014-03-28 15:25:31 -0700170 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 Ceballos70636b32016-07-06 15:24:54 -0700190 result = reply.read(**outBuffer);
191 if (result != NO_ERROR) {
192 outBuffer->clear();
193 return result;
194 }
Dan Stozad9822a32014-03-28 15:25:31 -0700195 }
196 nonNull = reply.readInt32();
197 if (nonNull) {
198 *outFence = new Fence;
Pablo Ceballos70636b32016-07-06 15:24:54 -0700199 result = reply.read(**outFence);
200 if (result != NO_ERROR) {
201 outBuffer->clear();
202 outFence->clear();
203 return result;
204 }
Dan Stozad9822a32014-03-28 15:25:31 -0700205 }
206 }
207 return result;
208 }
209
Dan Stoza9f3053d2014-03-06 15:14:33 -0800210 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 Agopianf0bc2f12012-04-09 16:14:01 -0700223 virtual status_t queueBuffer(int buf,
224 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800225 Parcel data, reply;
Brian Andersonbaaad322016-07-22 15:55:13 -0700226
Andy McFadden2adaf042012-12-18 09:49:45 -0800227 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800228 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700229 data.write(input);
Brian Andersonbaaad322016-07-22 15:55:13 -0700230
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700231 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
232 if (result != NO_ERROR) {
233 return result;
234 }
Brian Andersonbaaad322016-07-22 15:55:13 -0700235
236 result = reply.read(*output);
237 if (result != NO_ERROR) {
238 return result;
239 }
240
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700241 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800242 return result;
243 }
244
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700245 virtual status_t cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800246 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800247 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800248 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800249 data.write(*fence.get());
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700250 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 Gennis8ba32fa2010-12-20 11:27:26 -0800256 }
257
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700258 virtual int query(int what, int* value) {
259 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800260 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700261 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700262 status_t result = remote()->transact(QUERY, data, &reply);
263 if (result != NO_ERROR) {
264 return result;
265 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700266 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700267 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700268 return result;
269 }
270
Dan Stozaf0eaf252014-03-21 13:05:51 -0700271 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700272 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700273 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800274 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700275 if (listener != NULL) {
276 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800277 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700278 } else {
279 data.writeInt32(0);
280 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700281 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700282 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700283 status_t result = remote()->transact(CONNECT, data, &reply);
284 if (result != NO_ERROR) {
285 return result;
286 }
Brian Andersonbaaad322016-07-22 15:55:13 -0700287 reply.read(*output);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700288 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700289 return result;
290 }
Mathias Agopian80727112011-05-02 19:51:12 -0700291
Robert Carr97b9c862016-09-08 13:54:35 -0700292 virtual status_t disconnect(int api, DisconnectMode mode) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700293 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800294 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700295 data.writeInt32(api);
Robert Carr97b9c862016-09-08 13:54:35 -0700296 data.writeInt32(static_cast<int32_t>(mode));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700297 status_t result =remote()->transact(DISCONNECT, data, &reply);
298 if (result != NO_ERROR) {
299 return result;
300 }
301 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700302 return result;
303 }
Jesse Hall399184a2014-03-03 15:42:54 -0800304
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 Stoza29a3e902014-06-20 13:13:57 -0700320
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700321 virtual void allocateBuffers(uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800322 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700323 Parcel data, reply;
324 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800325 data.writeUint32(width);
326 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700327 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800328 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700329 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 Stoza9de72932015-04-16 17:28:43 -0700334
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 Stoza812ed062015-06-02 15:45:22 -0700346
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 Stozac6f30bd2015-06-08 09:32:50 -0700357
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 Stoza7dde5992015-05-22 09:51:44 -0700368
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700369 virtual status_t setSharedBufferMode(bool sharedBufferMode) {
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700370 Parcel data, reply;
371 data.writeInterfaceToken(
372 IGraphicBufferProducer::getInterfaceDescriptor());
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700373 data.writeInt32(sharedBufferMode);
374 status_t result = remote()->transact(SET_SHARED_BUFFER_MODE, data,
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700375 &reply);
376 if (result == NO_ERROR) {
377 result = reply.readInt32();
378 }
379 return result;
380 }
Dan Stoza127fc632015-06-30 13:43:32 -0700381
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800382 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 Stoza127fc632015-06-30 13:43:32 -0700394 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 Stoza50101d02016-04-07 16:53:23 -0700405
406 virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
John Reck1a61da52016-04-28 13:18:15 -0700407 sp<Fence>* outFence, float outTransformMatrix[16]) override {
Dan Stoza50101d02016-04-07 16:53:23 -0700408 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 Reckce8e5df2016-04-28 10:12:47 -0700420 bool hasBuffer = reply.readBool();
421 sp<GraphicBuffer> buffer;
422 if (hasBuffer) {
423 buffer = new GraphicBuffer();
424 result = reply.read(*buffer);
John Reck1a61da52016-04-28 13:18:15 -0700425 if (result == NO_ERROR) {
426 result = reply.read(outTransformMatrix, sizeof(float) * 16);
427 }
John Reckce8e5df2016-04-28 10:12:47 -0700428 }
Dan Stoza50101d02016-04-07 16:53:23 -0700429 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 Ceballosce796e72016-02-04 19:10:51 -0800443
Brian Anderson3890c392016-07-25 12:48:08 -0700444 virtual void getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
Pablo Ceballosce796e72016-02-04 19:10:51 -0800445 Parcel data, reply;
446 status_t result = data.writeInterfaceToken(
447 IGraphicBufferProducer::getInterfaceDescriptor());
448 if (result != NO_ERROR) {
Brian Anderson3890c392016-07-25 12:48:08 -0700449 ALOGE("IGBP::getFrameTimestamps failed to write token: %d", result);
450 return;
Pablo Ceballosce796e72016-02-04 19:10:51 -0800451 }
452 result = remote()->transact(GET_FRAME_TIMESTAMPS, data, &reply);
453 if (result != NO_ERROR) {
Brian Anderson3890c392016-07-25 12:48:08 -0700454 ALOGE("IGBP::getFrameTimestamps failed to transact: %d", result);
455 return;
Pablo Ceballosce796e72016-02-04 19:10:51 -0800456 }
Brian Anderson3890c392016-07-25 12:48:08 -0700457 result = reply.read(*outDelta);
Pablo Ceballosce796e72016-02-04 19:10:51 -0800458 if (result != NO_ERROR) {
Brian Anderson3890c392016-07-25 12:48:08 -0700459 ALOGE("IGBP::getFrameTimestamps failed to read timestamps: %d",
460 result);
Pablo Ceballosce796e72016-02-04 19:10:51 -0800461 }
Pablo Ceballosce796e72016-02-04 19:10:51 -0800462 }
Pablo Ceballos6155b402016-06-30 17:01:49 -0700463
Pablo Ceballos8e3e92b2016-06-27 17:56:53 -0700464 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 Gennis8ba32fa2010-12-20 11:27:26 -0800482};
483
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800484// Out-of-line virtual method definition to trigger vtable emission in this
485// translation unit (see clang warning -Wweak-vtables)
486BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
487
Andy McFadden466a1922013-01-08 11:25:51 -0800488IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800489
490// ----------------------------------------------------------------------
491
Andy McFadden2adaf042012-12-18 09:49:45 -0800492status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800493 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
494{
495 switch(code) {
496 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800497 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800498 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700499 sp<GraphicBuffer> buffer;
500 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800501 reply->writeInt32(buffer != 0);
502 if (buffer != 0) {
503 reply->write(*buffer);
504 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700505 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800506 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800507 }
Pablo Ceballosfa455352015-08-12 17:47:47 -0700508 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 Gennis8ba32fa2010-12-20 11:27:26 -0800522 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800523 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800524 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 Anderson7c3ba8a2016-07-25 12:48:08 -0700528 bool getTimestamps = data.readBool();
Brian Andersonbaaad322016-07-22 15:55:13 -0700529
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700530 int buf = 0;
Brian Andersonbaaad322016-07-22 15:55:13 -0700531 sp<Fence> fence = Fence::NO_FENCE;
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700532 FrameEventHistoryDelta frameTimestamps;
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700533 int result = dequeueBuffer(&buf, &fence, width, height, format,
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700534 usage, getTimestamps ? &frameTimestamps : nullptr);
Brian Andersonbaaad322016-07-22 15:55:13 -0700535
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800536 reply->writeInt32(buf);
Brian Andersonbaaad322016-07-22 15:55:13 -0700537 reply->write(*fence);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700538 if (getTimestamps) {
539 reply->write(frameTimestamps);
540 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800541 reply->writeInt32(result);
542 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800543 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800544 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 Stoza3be1c6b2014-11-18 10:24:03 -0800550 }
Dan Stozad9822a32014-03-28 15:25:31 -0700551 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 Stoza3be1c6b2014-11-18 10:24:03 -0800568 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800569 case ATTACH_BUFFER: {
570 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
571 sp<GraphicBuffer> buffer = new GraphicBuffer();
Pablo Ceballos70636b32016-07-06 15:24:54 -0700572 status_t result = data.read(*buffer.get());
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700573 int slot = 0;
Pablo Ceballos70636b32016-07-06 15:24:54 -0700574 if (result == NO_ERROR) {
575 result = attachBuffer(&slot, buffer);
576 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800577 reply->writeInt32(slot);
578 reply->writeInt32(result);
579 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800580 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800581 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800582 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700583
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800584 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700585 QueueBufferInput input(data);
Brian Andersonbaaad322016-07-22 15:55:13 -0700586 QueueBufferOutput output;
587 status_t result = queueBuffer(buf, input, &output);
Brian Andersonbaaad322016-07-22 15:55:13 -0700588 reply->write(output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800589 reply->writeInt32(result);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700590
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800591 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800592 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800593 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800594 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800595 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800596 sp<Fence> fence = new Fence();
Pablo Ceballos70636b32016-07-06 15:24:54 -0700597 status_t result = data.read(*fence.get());
598 if (result == NO_ERROR) {
599 result = cancelBuffer(buf, fence);
600 }
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700601 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800602 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800603 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700604 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800605 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700606 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700607 int what = data.readInt32();
608 int res = query(what, &value);
609 reply->writeInt32(value);
610 reply->writeInt32(res);
611 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800612 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700613 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800614 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700615 sp<IProducerListener> listener;
616 if (data.readInt32() == 1) {
617 listener = IProducerListener::asInterface(data.readStrongBinder());
618 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700619 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700620 bool producerControlledByApp = data.readInt32();
Brian Andersonbaaad322016-07-22 15:55:13 -0700621 QueueBufferOutput output;
622 status_t res = connect(listener, api, producerControlledByApp, &output);
623 reply->write(output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700624 reply->writeInt32(res);
625 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800626 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700627 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800628 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700629 int api = data.readInt32();
Robert Carr97b9c862016-09-08 13:54:35 -0700630 DisconnectMode mode = static_cast<DisconnectMode>(data.readInt32());
631 status_t res = disconnect(api, mode);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700632 reply->writeInt32(res);
633 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800634 }
Jesse Hall399184a2014-03-03 15:42:54 -0800635 case SET_SIDEBAND_STREAM: {
636 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
637 sp<NativeHandle> stream;
638 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900639 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800640 }
641 status_t result = setSidebandStream(stream);
642 reply->writeInt32(result);
643 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800644 }
Dan Stoza9de72932015-04-16 17:28:43 -0700645 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700646 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800647 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 Ceballos567dbbb2015-08-26 18:59:08 -0700651 allocateBuffers(width, height, format, usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700652 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700653 }
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 Stoza812ed062015-06-02 15:45:22 -0700661 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 Stozac6f30bd2015-06-08 09:32:50 -0700668 case GET_CONSUMER_NAME: {
669 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
670 reply->writeString8(getConsumerName());
671 return NO_ERROR;
672 }
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700673 case SET_SHARED_BUFFER_MODE: {
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700674 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700675 bool sharedBufferMode = data.readInt32();
676 status_t result = setSharedBufferMode(sharedBufferMode);
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700677 reply->writeInt32(result);
678 return NO_ERROR;
679 }
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800680 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 Stoza127fc632015-06-30 13:43:32 -0700687 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 Stoza50101d02016-04-07 16:53:23 -0700694 case GET_LAST_QUEUED_BUFFER: {
695 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
696 sp<GraphicBuffer> buffer(nullptr);
697 sp<Fence> fence(Fence::NO_FENCE);
John Reck1a61da52016-04-28 13:18:15 -0700698 float transform[16] = {};
699 status_t result = getLastQueuedBuffer(&buffer, &fence, transform);
Dan Stoza50101d02016-04-07 16:53:23 -0700700 reply->writeInt32(result);
701 if (result != NO_ERROR) {
702 return result;
703 }
John Reckce8e5df2016-04-28 10:12:47 -0700704 if (!buffer.get()) {
705 reply->writeBool(false);
706 } else {
707 reply->writeBool(true);
708 result = reply->write(*buffer);
John Reck1a61da52016-04-28 13:18:15 -0700709 if (result == NO_ERROR) {
710 reply->write(transform, sizeof(float) * 16);
711 }
John Reckce8e5df2016-04-28 10:12:47 -0700712 }
Dan Stoza50101d02016-04-07 16:53:23 -0700713 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 Ceballosce796e72016-02-04 19:10:51 -0800724 case GET_FRAME_TIMESTAMPS: {
725 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Brian Anderson3890c392016-07-25 12:48:08 -0700726 FrameEventHistoryDelta frameTimestamps;
727 getFrameTimestamps(&frameTimestamps);
728 status_t result = reply->write(frameTimestamps);
Pablo Ceballosce796e72016-02-04 19:10:51 -0800729 if (result != NO_ERROR) {
Brian Anderson3890c392016-07-25 12:48:08 -0700730 ALOGE("BnGBP::GET_FRAME_TIMESTAMPS failed to write buffer: %d",
731 result);
Pablo Ceballosce796e72016-02-04 19:10:51 -0800732 return result;
733 }
Pablo Ceballosce796e72016-02-04 19:10:51 -0800734 return NO_ERROR;
735 }
Pablo Ceballos8e3e92b2016-06-27 17:56:53 -0700736 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 Gennis8ba32fa2010-12-20 11:27:26 -0800750 }
751 return BBinder::onTransact(code, data, reply, flags);
752}
753
754// ----------------------------------------------------------------------------
755
Andy McFadden2adaf042012-12-18 09:49:45 -0800756IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700757 parcel.read(*this);
758}
759
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700760constexpr 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 Agopiane1424282013-07-29 21:24:40 -0700771size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700772 return minFlattenedSize() +
773 fence->getFlattenedSize() +
774 surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700775}
776
Mathias Agopiane1424282013-07-29 21:24:40 -0700777size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800778 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700779}
780
Mathias Agopiane1424282013-07-29 21:24:40 -0700781status_t IGraphicBufferProducer::QueueBufferInput::flatten(
782 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700783{
Mathias Agopiane1424282013-07-29 21:24:40 -0700784 if (size < getFlattenedSize()) {
785 return NO_MEMORY;
786 }
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700787
Mathias Agopiane1424282013-07-29 21:24:40 -0700788 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700789 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800790 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700791 FlattenableUtils::write(buffer, size, crop);
792 FlattenableUtils::write(buffer, size, scalingMode);
793 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700794 FlattenableUtils::write(buffer, size, stickyTransform);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700795 FlattenableUtils::write(buffer, size, getFrameTimestamps);
796
Dan Stoza5065a552015-03-17 16:23:42 -0700797 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 Hallc777b0b2012-06-28 12:52:05 -0700802}
803
Mathias Agopiane1424282013-07-29 21:24:40 -0700804status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
805 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700806{
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700807 if (size < minFlattenedSize()) {
Mathias Agopiane1424282013-07-29 21:24:40 -0700808 return NO_MEMORY;
809 }
810
811 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700812 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800813 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700814 FlattenableUtils::read(buffer, size, crop);
815 FlattenableUtils::read(buffer, size, scalingMode);
816 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700817 FlattenableUtils::read(buffer, size, stickyTransform);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700818 FlattenableUtils::read(buffer, size, getFrameTimestamps);
Mathias Agopiane1424282013-07-29 21:24:40 -0700819
Jamie Gennis1df8c342012-12-20 14:05:45 -0800820 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700821 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 Hallc777b0b2012-06-28 12:52:05 -0700826}
827
Brian Andersonbaaad322016-07-22 15:55:13 -0700828// ----------------------------------------------------------------------------
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700829constexpr size_t IGraphicBufferProducer::QueueBufferOutput::minFlattenedSize() {
830 return sizeof(width) +
831 sizeof(height) +
832 sizeof(transformHint) +
833 sizeof(numPendingBuffers) +
834 sizeof(nextFrameNumber);
835}
Brian Andersonbaaad322016-07-22 15:55:13 -0700836
837size_t IGraphicBufferProducer::QueueBufferOutput::getFlattenedSize() const {
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700838 return minFlattenedSize() + frameTimestamps.getFlattenedSize();
Brian Andersonbaaad322016-07-22 15:55:13 -0700839}
840
841size_t IGraphicBufferProducer::QueueBufferOutput::getFdCount() const {
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700842 return frameTimestamps.getFdCount();
Brian Andersonbaaad322016-07-22 15:55:13 -0700843}
844
845status_t IGraphicBufferProducer::QueueBufferOutput::flatten(
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700846 void*& buffer, size_t& size, int*& fds, size_t& count) const
Brian Andersonbaaad322016-07-22 15:55:13 -0700847{
848 if (size < getFlattenedSize()) {
849 return NO_MEMORY;
850 }
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700851
Brian Andersonbaaad322016-07-22 15:55:13 -0700852 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 Anderson7c3ba8a2016-07-25 12:48:08 -0700858 return frameTimestamps.flatten(buffer, size, fds, count);
Brian Andersonbaaad322016-07-22 15:55:13 -0700859}
860
861status_t IGraphicBufferProducer::QueueBufferOutput::unflatten(
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700862 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Brian Andersonbaaad322016-07-22 15:55:13 -0700863{
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700864 if (size < minFlattenedSize()) {
Brian Andersonbaaad322016-07-22 15:55:13 -0700865 return NO_MEMORY;
866 }
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700867
Brian Andersonbaaad322016-07-22 15:55:13 -0700868 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 Anderson7c3ba8a2016-07-25 12:48:08 -0700874 return frameTimestamps.unflatten(buffer, size, fds, count);
Brian Andersonbaaad322016-07-22 15:55:13 -0700875}
876
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800877}; // namespace android