blob: b12d6ca3e0ad67fe8f25429acdd0c0671972e2aa [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>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080023#include <utils/Timers.h>
Jesse Hall399184a2014-03-03 15:42:54 -080024#include <utils/Vector.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080025
26#include <binder/Parcel.h>
27#include <binder/IInterface.h>
28
Chia-I Wuc79a2962017-05-15 10:32:27 -070029#include <gui/BufferQueueDefs.h>
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,
38 SET_BUFFER_COUNT,
39 DEQUEUE_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080040 DETACH_BUFFER,
Dan Stozad9822a32014-03-28 15:25:31 -070041 DETACH_NEXT_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080042 ATTACH_BUFFER,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080043 QUEUE_BUFFER,
44 CANCEL_BUFFER,
Mathias Agopianeafabcd2011-04-20 14:20:59 -070045 QUERY,
Jamie Gennisfe0a87b2011-07-13 19:12:20 -070046 CONNECT,
47 DISCONNECT,
Jesse Hall399184a2014-03-03 15:42:54 -080048 SET_SIDEBAND_STREAM,
Dan Stoza29a3e902014-06-20 13:13:57 -070049 ALLOCATE_BUFFERS,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080050};
51
Andy McFadden2adaf042012-12-18 09:49:45 -080052class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080053{
54public:
Andy McFadden2adaf042012-12-18 09:49:45 -080055 BpGraphicBufferProducer(const sp<IBinder>& impl)
56 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080057 {
58 }
59
Jamie Gennis7b305ff2011-07-19 12:08:33 -070060 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080061 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080062 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080063 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070064 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
65 if (result != NO_ERROR) {
66 return result;
67 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080068 bool nonNull = reply.readInt32();
69 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070070 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080071 result = reply.read(**buf);
72 if(result != NO_ERROR) {
73 (*buf).clear();
74 return result;
75 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080076 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070077 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070078 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080079 }
80
81 virtual status_t setBufferCount(int bufferCount)
82 {
83 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080084 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080085 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070086 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
87 if (result != NO_ERROR) {
88 return result;
89 }
90 result = reply.readInt32();
91 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080092 }
93
Mathias Agopian7cdd7862013-07-18 22:10:56 -070094 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Jesse Hallf7857542012-06-14 15:26:33 -070095 uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080096 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080097 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopian7cdd7862013-07-18 22:10:56 -070098 data.writeInt32(async);
Mathias Agopianc04f1532011-04-25 20:22:14 -070099 data.writeInt32(w);
100 data.writeInt32(h);
101 data.writeInt32(format);
102 data.writeInt32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700103 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
104 if (result != NO_ERROR) {
105 return result;
106 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800107 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700108 bool nonNull = reply.readInt32();
109 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700110 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700111 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700112 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700113 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800114 return result;
115 }
116
Dan Stoza9f3053d2014-03-06 15:14:33 -0800117 virtual status_t detachBuffer(int slot) {
118 Parcel data, reply;
119 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
120 data.writeInt32(slot);
121 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
122 if (result != NO_ERROR) {
123 return result;
124 }
125 result = reply.readInt32();
126 return result;
127 }
128
Dan Stozad9822a32014-03-28 15:25:31 -0700129 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
130 sp<Fence>* outFence) {
131 if (outBuffer == NULL) {
132 ALOGE("detachNextBuffer: outBuffer must not be NULL");
133 return BAD_VALUE;
134 } else if (outFence == NULL) {
135 ALOGE("detachNextBuffer: outFence must not be NULL");
136 return BAD_VALUE;
137 }
138 Parcel data, reply;
139 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
140 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
141 if (result != NO_ERROR) {
142 return result;
143 }
144 result = reply.readInt32();
145 if (result == NO_ERROR) {
146 bool nonNull = reply.readInt32();
147 if (nonNull) {
148 *outBuffer = new GraphicBuffer;
149 reply.read(**outBuffer);
150 }
151 nonNull = reply.readInt32();
152 if (nonNull) {
153 *outFence = new Fence;
154 reply.read(**outFence);
155 }
156 }
157 return result;
158 }
159
Dan Stoza9f3053d2014-03-06 15:14:33 -0800160 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
161 Parcel data, reply;
162 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
163 data.write(*buffer.get());
164 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
165 if (result != NO_ERROR) {
166 return result;
167 }
Chia-I Wuc79a2962017-05-15 10:32:27 -0700168
Dan Stoza9f3053d2014-03-06 15:14:33 -0800169 *slot = reply.readInt32();
170 result = reply.readInt32();
Chia-I Wuc79a2962017-05-15 10:32:27 -0700171 if (result == NO_ERROR &&
172 (*slot < 0 || *slot >= BufferQueueDefs::NUM_BUFFER_SLOTS)) {
173 ALOGE("attachBuffer returned invalid slot %d", *slot);
174 android_errorWriteLog(0x534e4554, "37478824");
175 return UNKNOWN_ERROR;
176 }
177
Dan Stoza9f3053d2014-03-06 15:14:33 -0800178 return result;
179 }
180
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700181 virtual status_t queueBuffer(int buf,
182 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800183 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800184 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800185 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700186 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700187 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
188 if (result != NO_ERROR) {
189 return result;
190 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700191 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700192 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800193 return result;
194 }
195
Jesse Hall4c00cc12013-03-15 21:34:30 -0700196 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800197 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800198 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800199 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800200 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800201 remote()->transact(CANCEL_BUFFER, data, &reply);
202 }
203
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700204 virtual int query(int what, int* value) {
205 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800206 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700207 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700208 status_t result = remote()->transact(QUERY, data, &reply);
209 if (result != NO_ERROR) {
210 return result;
211 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700212 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700213 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700214 return result;
215 }
216
Dan Stozaf0eaf252014-03-21 13:05:51 -0700217 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700218 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700219 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800220 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700221 if (listener != NULL) {
222 data.writeInt32(1);
223 data.writeStrongBinder(listener->asBinder());
224 } else {
225 data.writeInt32(0);
226 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700227 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700228 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700229 status_t result = remote()->transact(CONNECT, data, &reply);
230 if (result != NO_ERROR) {
231 return result;
232 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700233 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700234 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700235 return result;
236 }
Mathias Agopian80727112011-05-02 19:51:12 -0700237
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700238 virtual status_t disconnect(int api) {
239 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800240 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700241 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700242 status_t result =remote()->transact(DISCONNECT, data, &reply);
243 if (result != NO_ERROR) {
244 return result;
245 }
246 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700247 return result;
248 }
Jesse Hall399184a2014-03-03 15:42:54 -0800249
250 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
251 Parcel data, reply;
252 status_t result;
253 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
254 if (stream.get()) {
255 data.writeInt32(true);
256 data.writeNativeHandle(stream->handle());
257 } else {
258 data.writeInt32(false);
259 }
260 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
261 result = reply.readInt32();
262 }
263 return result;
264 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700265
266 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
267 uint32_t format, uint32_t usage) {
268 Parcel data, reply;
269 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
270 data.writeInt32(static_cast<int32_t>(async));
271 data.writeInt32(static_cast<int32_t>(width));
272 data.writeInt32(static_cast<int32_t>(height));
273 data.writeInt32(static_cast<int32_t>(format));
274 data.writeInt32(static_cast<int32_t>(usage));
275 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
276 if (result != NO_ERROR) {
277 ALOGE("allocateBuffers failed to transact: %d", result);
278 }
279 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800280};
281
Andy McFadden466a1922013-01-08 11:25:51 -0800282IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800283
284// ----------------------------------------------------------------------
285
Andy McFadden2adaf042012-12-18 09:49:45 -0800286status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800287 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
288{
289 switch(code) {
290 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800291 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800292 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700293 sp<GraphicBuffer> buffer;
294 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800295 reply->writeInt32(buffer != 0);
296 if (buffer != 0) {
297 reply->write(*buffer);
298 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700299 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800300 return NO_ERROR;
301 } break;
302 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800303 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800304 int bufferCount = data.readInt32();
305 int result = setBufferCount(bufferCount);
306 reply->writeInt32(result);
307 return NO_ERROR;
308 } break;
309 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800310 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700311 bool async = data.readInt32();
Mathias Agopianc04f1532011-04-25 20:22:14 -0700312 uint32_t w = data.readInt32();
313 uint32_t h = data.readInt32();
314 uint32_t format = data.readInt32();
315 uint32_t usage = data.readInt32();
Naveen Leekhac1e6fbb2015-09-22 17:58:21 -0700316 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700317 sp<Fence> fence;
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700318 int result = dequeueBuffer(&buf, &fence, async, w, h, format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800319 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800320 reply->writeInt32(fence != NULL);
321 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700322 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700323 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800324 reply->writeInt32(result);
325 return NO_ERROR;
326 } break;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800327 case DETACH_BUFFER: {
328 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
329 int slot = data.readInt32();
330 int result = detachBuffer(slot);
331 reply->writeInt32(result);
332 return NO_ERROR;
333 } break;
Dan Stozad9822a32014-03-28 15:25:31 -0700334 case DETACH_NEXT_BUFFER: {
335 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
336 sp<GraphicBuffer> buffer;
337 sp<Fence> fence;
338 int32_t result = detachNextBuffer(&buffer, &fence);
339 reply->writeInt32(result);
340 if (result == NO_ERROR) {
341 reply->writeInt32(buffer != NULL);
342 if (buffer != NULL) {
343 reply->write(*buffer);
344 }
345 reply->writeInt32(fence != NULL);
346 if (fence != NULL) {
347 reply->write(*fence);
348 }
349 }
350 return NO_ERROR;
351 } break;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800352 case ATTACH_BUFFER: {
353 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
354 sp<GraphicBuffer> buffer = new GraphicBuffer();
355 data.read(*buffer.get());
Naveen Leekhab4142552015-09-22 18:04:44 -0700356 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800357 int result = attachBuffer(&slot, buffer);
358 reply->writeInt32(slot);
359 reply->writeInt32(result);
360 return NO_ERROR;
361 } break;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800362 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800363 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800364 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700365 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700366 QueueBufferOutput* const output =
367 reinterpret_cast<QueueBufferOutput *>(
368 reply->writeInplace(sizeof(QueueBufferOutput)));
Robert Shihd06421f2016-01-11 15:02:12 -0800369 memset(output, 0, sizeof(QueueBufferOutput));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700370 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800371 reply->writeInt32(result);
372 return NO_ERROR;
373 } break;
374 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800375 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800376 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800377 sp<Fence> fence = new Fence();
378 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700379 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800380 return NO_ERROR;
381 } break;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700382 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800383 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekhac1e6fbb2015-09-22 17:58:21 -0700384 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700385 int what = data.readInt32();
386 int res = query(what, &value);
387 reply->writeInt32(value);
388 reply->writeInt32(res);
389 return NO_ERROR;
390 } break;
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700391 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800392 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700393 sp<IProducerListener> listener;
394 if (data.readInt32() == 1) {
395 listener = IProducerListener::asInterface(data.readStrongBinder());
396 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700397 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700398 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700399 QueueBufferOutput* const output =
400 reinterpret_cast<QueueBufferOutput *>(
401 reply->writeInplace(sizeof(QueueBufferOutput)));
Pablo Ceballos93c617f2016-03-15 18:10:49 -0700402 memset(output, 0, sizeof(QueueBufferOutput));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700403 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700404 reply->writeInt32(res);
405 return NO_ERROR;
406 } break;
407 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800408 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700409 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700410 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700411 reply->writeInt32(res);
412 return NO_ERROR;
413 } break;
Jesse Hall399184a2014-03-03 15:42:54 -0800414 case SET_SIDEBAND_STREAM: {
415 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
416 sp<NativeHandle> stream;
417 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900418 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800419 }
420 status_t result = setSidebandStream(stream);
421 reply->writeInt32(result);
422 return NO_ERROR;
423 } break;
Dan Stoza29a3e902014-06-20 13:13:57 -0700424 case ALLOCATE_BUFFERS:
425 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
426 bool async = static_cast<bool>(data.readInt32());
427 uint32_t width = static_cast<uint32_t>(data.readInt32());
428 uint32_t height = static_cast<uint32_t>(data.readInt32());
429 uint32_t format = static_cast<uint32_t>(data.readInt32());
430 uint32_t usage = static_cast<uint32_t>(data.readInt32());
431 allocateBuffers(async, width, height, format, usage);
432 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800433 }
434 return BBinder::onTransact(code, data, reply, flags);
435}
436
437// ----------------------------------------------------------------------------
438
Andy McFadden2adaf042012-12-18 09:49:45 -0800439IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700440 parcel.read(*this);
441}
442
Mathias Agopiane1424282013-07-29 21:24:40 -0700443size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700444 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700445 + sizeof(isAutoTimestamp)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700446 + sizeof(crop)
447 + sizeof(scalingMode)
448 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700449 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700450 + sizeof(async)
Jamie Gennis1df8c342012-12-20 14:05:45 -0800451 + fence->getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700452}
453
Mathias Agopiane1424282013-07-29 21:24:40 -0700454size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800455 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700456}
457
Mathias Agopiane1424282013-07-29 21:24:40 -0700458status_t IGraphicBufferProducer::QueueBufferInput::flatten(
459 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700460{
Mathias Agopiane1424282013-07-29 21:24:40 -0700461 if (size < getFlattenedSize()) {
462 return NO_MEMORY;
463 }
464 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700465 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700466 FlattenableUtils::write(buffer, size, crop);
467 FlattenableUtils::write(buffer, size, scalingMode);
468 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700469 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700470 FlattenableUtils::write(buffer, size, async);
471 return fence->flatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700472}
473
Mathias Agopiane1424282013-07-29 21:24:40 -0700474status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
475 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700476{
Mathias Agopiane1424282013-07-29 21:24:40 -0700477 size_t minNeeded =
478 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700479 + sizeof(isAutoTimestamp)
Mathias Agopiane1424282013-07-29 21:24:40 -0700480 + sizeof(crop)
481 + sizeof(scalingMode)
482 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700483 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700484 + sizeof(async);
485
486 if (size < minNeeded) {
487 return NO_MEMORY;
488 }
489
490 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700491 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700492 FlattenableUtils::read(buffer, size, crop);
493 FlattenableUtils::read(buffer, size, scalingMode);
494 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700495 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700496 FlattenableUtils::read(buffer, size, async);
497
Jamie Gennis1df8c342012-12-20 14:05:45 -0800498 fence = new Fence();
Mathias Agopiane1424282013-07-29 21:24:40 -0700499 return fence->unflatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700500}
501
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800502}; // namespace android