blob: 8ab963d8db8fbe946f1206824933085b4e8def06 [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
Andy McFadden2adaf042012-12-18 09:49:45 -080029#include <gui/IGraphicBufferProducer.h>
Dan Stozaf0eaf252014-03-21 13:05:51 -070030#include <gui/IProducerListener.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080031
32namespace android {
33// ----------------------------------------------------------------------------
34
35enum {
36 REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080037 DEQUEUE_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080038 DETACH_BUFFER,
Dan Stozad9822a32014-03-28 15:25:31 -070039 DETACH_NEXT_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080040 ATTACH_BUFFER,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080041 QUEUE_BUFFER,
42 CANCEL_BUFFER,
Mathias Agopianeafabcd2011-04-20 14:20:59 -070043 QUERY,
Jamie Gennisfe0a87b2011-07-13 19:12:20 -070044 CONNECT,
45 DISCONNECT,
Jesse Hall399184a2014-03-03 15:42:54 -080046 SET_SIDEBAND_STREAM,
Dan Stoza29a3e902014-06-20 13:13:57 -070047 ALLOCATE_BUFFERS,
Dan Stoza9de72932015-04-16 17:28:43 -070048 ALLOW_ALLOCATION,
Dan Stoza812ed062015-06-02 15:45:22 -070049 SET_GENERATION_NUMBER,
Dan Stozac6f30bd2015-06-08 09:32:50 -070050 GET_CONSUMER_NAME,
Pablo Ceballosfa455352015-08-12 17:47:47 -070051 SET_MAX_DEQUEUED_BUFFER_COUNT,
52 SET_ASYNC_MODE
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080053};
54
Andy McFadden2adaf042012-12-18 09:49:45 -080055class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080056{
57public:
Andy McFadden2adaf042012-12-18 09:49:45 -080058 BpGraphicBufferProducer(const sp<IBinder>& impl)
59 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080060 {
61 }
62
Dan Stoza3be1c6b2014-11-18 10:24:03 -080063 virtual ~BpGraphicBufferProducer();
64
Jamie Gennis7b305ff2011-07-19 12:08:33 -070065 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080066 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080067 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080068 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070069 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
70 if (result != NO_ERROR) {
71 return result;
72 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080073 bool nonNull = reply.readInt32();
74 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070075 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080076 result = reply.read(**buf);
77 if(result != NO_ERROR) {
78 (*buf).clear();
79 return result;
80 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080081 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070082 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070083 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080084 }
85
Pablo Ceballosfa455352015-08-12 17:47:47 -070086 virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) {
87 Parcel data, reply;
88 data.writeInterfaceToken(
89 IGraphicBufferProducer::getInterfaceDescriptor());
90 data.writeInt32(maxDequeuedBuffers);
91 status_t result = remote()->transact(SET_MAX_DEQUEUED_BUFFER_COUNT,
92 data, &reply);
93 if (result != NO_ERROR) {
94 return result;
95 }
96 result = reply.readInt32();
97 return result;
98 }
99
100 virtual status_t setAsyncMode(bool async) {
101 Parcel data, reply;
102 data.writeInterfaceToken(
103 IGraphicBufferProducer::getInterfaceDescriptor());
104 data.writeInt32(async);
105 status_t result = remote()->transact(SET_ASYNC_MODE,
106 data, &reply);
107 if (result != NO_ERROR) {
108 return result;
109 }
110 result = reply.readInt32();
111 return result;
112 }
113
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700114 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, uint32_t width,
115 uint32_t height, PixelFormat format, uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800116 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800117 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800118 data.writeUint32(width);
119 data.writeUint32(height);
120 data.writeInt32(static_cast<int32_t>(format));
121 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700122 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
123 if (result != NO_ERROR) {
124 return result;
125 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800126 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700127 bool nonNull = reply.readInt32();
128 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700129 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700130 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700131 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700132 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800133 return result;
134 }
135
Dan Stoza9f3053d2014-03-06 15:14:33 -0800136 virtual status_t detachBuffer(int slot) {
137 Parcel data, reply;
138 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
139 data.writeInt32(slot);
140 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
141 if (result != NO_ERROR) {
142 return result;
143 }
144 result = reply.readInt32();
145 return result;
146 }
147
Dan Stozad9822a32014-03-28 15:25:31 -0700148 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
149 sp<Fence>* outFence) {
150 if (outBuffer == NULL) {
151 ALOGE("detachNextBuffer: outBuffer must not be NULL");
152 return BAD_VALUE;
153 } else if (outFence == NULL) {
154 ALOGE("detachNextBuffer: outFence must not be NULL");
155 return BAD_VALUE;
156 }
157 Parcel data, reply;
158 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
159 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
160 if (result != NO_ERROR) {
161 return result;
162 }
163 result = reply.readInt32();
164 if (result == NO_ERROR) {
165 bool nonNull = reply.readInt32();
166 if (nonNull) {
167 *outBuffer = new GraphicBuffer;
168 reply.read(**outBuffer);
169 }
170 nonNull = reply.readInt32();
171 if (nonNull) {
172 *outFence = new Fence;
173 reply.read(**outFence);
174 }
175 }
176 return result;
177 }
178
Dan Stoza9f3053d2014-03-06 15:14:33 -0800179 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
180 Parcel data, reply;
181 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
182 data.write(*buffer.get());
183 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
184 if (result != NO_ERROR) {
185 return result;
186 }
187 *slot = reply.readInt32();
188 result = reply.readInt32();
189 return result;
190 }
191
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700192 virtual status_t queueBuffer(int buf,
193 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800194 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800195 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800196 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700197 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700198 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
199 if (result != NO_ERROR) {
200 return result;
201 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700202 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700203 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800204 return result;
205 }
206
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700207 virtual status_t cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800208 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800209 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800210 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800211 data.write(*fence.get());
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700212 status_t result = remote()->transact(CANCEL_BUFFER, data, &reply);
213 if (result != NO_ERROR) {
214 return result;
215 }
216 result = reply.readInt32();
217 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800218 }
219
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700220 virtual int query(int what, int* value) {
221 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800222 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700223 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700224 status_t result = remote()->transact(QUERY, data, &reply);
225 if (result != NO_ERROR) {
226 return result;
227 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700228 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700229 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700230 return result;
231 }
232
Dan Stozaf0eaf252014-03-21 13:05:51 -0700233 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700234 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700235 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800236 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700237 if (listener != NULL) {
238 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800239 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700240 } else {
241 data.writeInt32(0);
242 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700243 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700244 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700245 status_t result = remote()->transact(CONNECT, data, &reply);
246 if (result != NO_ERROR) {
247 return result;
248 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700249 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700250 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700251 return result;
252 }
Mathias Agopian80727112011-05-02 19:51:12 -0700253
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700254 virtual status_t disconnect(int api) {
255 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800256 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700257 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700258 status_t result =remote()->transact(DISCONNECT, data, &reply);
259 if (result != NO_ERROR) {
260 return result;
261 }
262 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700263 return result;
264 }
Jesse Hall399184a2014-03-03 15:42:54 -0800265
266 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
267 Parcel data, reply;
268 status_t result;
269 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
270 if (stream.get()) {
271 data.writeInt32(true);
272 data.writeNativeHandle(stream->handle());
273 } else {
274 data.writeInt32(false);
275 }
276 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
277 result = reply.readInt32();
278 }
279 return result;
280 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700281
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700282 virtual void allocateBuffers(uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800283 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700284 Parcel data, reply;
285 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800286 data.writeUint32(width);
287 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700288 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800289 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700290 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
291 if (result != NO_ERROR) {
292 ALOGE("allocateBuffers failed to transact: %d", result);
293 }
294 }
Dan Stoza9de72932015-04-16 17:28:43 -0700295
296 virtual status_t allowAllocation(bool allow) {
297 Parcel data, reply;
298 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
299 data.writeInt32(static_cast<int32_t>(allow));
300 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
301 if (result != NO_ERROR) {
302 return result;
303 }
304 result = reply.readInt32();
305 return result;
306 }
Dan Stoza812ed062015-06-02 15:45:22 -0700307
308 virtual status_t setGenerationNumber(uint32_t generationNumber) {
309 Parcel data, reply;
310 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
311 data.writeUint32(generationNumber);
312 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
313 if (result == NO_ERROR) {
314 result = reply.readInt32();
315 }
316 return result;
317 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700318
319 virtual String8 getConsumerName() const {
320 Parcel data, reply;
321 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
322 status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
323 if (result != NO_ERROR) {
324 ALOGE("getConsumerName failed to transact: %d", result);
325 return String8("TransactFailed");
326 }
327 return reply.readString8();
328 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800329};
330
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800331// Out-of-line virtual method definition to trigger vtable emission in this
332// translation unit (see clang warning -Wweak-vtables)
333BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
334
Andy McFadden466a1922013-01-08 11:25:51 -0800335IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800336
337// ----------------------------------------------------------------------
338
Andy McFadden2adaf042012-12-18 09:49:45 -0800339status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800340 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
341{
342 switch(code) {
343 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800344 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800345 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700346 sp<GraphicBuffer> buffer;
347 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800348 reply->writeInt32(buffer != 0);
349 if (buffer != 0) {
350 reply->write(*buffer);
351 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700352 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800353 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800354 }
Pablo Ceballosfa455352015-08-12 17:47:47 -0700355 case SET_MAX_DEQUEUED_BUFFER_COUNT: {
356 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
357 int maxDequeuedBuffers = data.readInt32();
358 int result = setMaxDequeuedBufferCount(maxDequeuedBuffers);
359 reply->writeInt32(result);
360 return NO_ERROR;
361 }
362 case SET_ASYNC_MODE: {
363 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
364 bool async = data.readInt32();
365 int result = setAsyncMode(async);
366 reply->writeInt32(result);
367 return NO_ERROR;
368 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800369 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800370 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800371 uint32_t width = data.readUint32();
372 uint32_t height = data.readUint32();
373 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
374 uint32_t usage = data.readUint32();
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700375 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700376 sp<Fence> fence;
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700377 int result = dequeueBuffer(&buf, &fence, width, height, format,
378 usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800379 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800380 reply->writeInt32(fence != NULL);
381 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700382 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700383 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800384 reply->writeInt32(result);
385 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800386 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800387 case DETACH_BUFFER: {
388 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
389 int slot = data.readInt32();
390 int result = detachBuffer(slot);
391 reply->writeInt32(result);
392 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800393 }
Dan Stozad9822a32014-03-28 15:25:31 -0700394 case DETACH_NEXT_BUFFER: {
395 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
396 sp<GraphicBuffer> buffer;
397 sp<Fence> fence;
398 int32_t result = detachNextBuffer(&buffer, &fence);
399 reply->writeInt32(result);
400 if (result == NO_ERROR) {
401 reply->writeInt32(buffer != NULL);
402 if (buffer != NULL) {
403 reply->write(*buffer);
404 }
405 reply->writeInt32(fence != NULL);
406 if (fence != NULL) {
407 reply->write(*fence);
408 }
409 }
410 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800411 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800412 case ATTACH_BUFFER: {
413 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
414 sp<GraphicBuffer> buffer = new GraphicBuffer();
415 data.read(*buffer.get());
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700416 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800417 int result = attachBuffer(&slot, buffer);
418 reply->writeInt32(slot);
419 reply->writeInt32(result);
420 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800421 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800422 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800423 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800424 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700425 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700426 QueueBufferOutput* const output =
427 reinterpret_cast<QueueBufferOutput *>(
428 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700429 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800430 reply->writeInt32(result);
431 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800432 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800433 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800434 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800435 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800436 sp<Fence> fence = new Fence();
437 data.read(*fence.get());
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700438 status_t result = cancelBuffer(buf, fence);
439 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800440 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800441 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700442 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800443 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700444 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700445 int what = data.readInt32();
446 int res = query(what, &value);
447 reply->writeInt32(value);
448 reply->writeInt32(res);
449 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800450 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700451 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800452 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700453 sp<IProducerListener> listener;
454 if (data.readInt32() == 1) {
455 listener = IProducerListener::asInterface(data.readStrongBinder());
456 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700457 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700458 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700459 QueueBufferOutput* const output =
460 reinterpret_cast<QueueBufferOutput *>(
461 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700462 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700463 reply->writeInt32(res);
464 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800465 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700466 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800467 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700468 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700469 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700470 reply->writeInt32(res);
471 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800472 }
Jesse Hall399184a2014-03-03 15:42:54 -0800473 case SET_SIDEBAND_STREAM: {
474 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
475 sp<NativeHandle> stream;
476 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900477 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800478 }
479 status_t result = setSidebandStream(stream);
480 reply->writeInt32(result);
481 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800482 }
Dan Stoza9de72932015-04-16 17:28:43 -0700483 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700484 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800485 uint32_t width = data.readUint32();
486 uint32_t height = data.readUint32();
487 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
488 uint32_t usage = data.readUint32();
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700489 allocateBuffers(width, height, format, usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700490 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700491 }
492 case ALLOW_ALLOCATION: {
493 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
494 bool allow = static_cast<bool>(data.readInt32());
495 status_t result = allowAllocation(allow);
496 reply->writeInt32(result);
497 return NO_ERROR;
498 }
Dan Stoza812ed062015-06-02 15:45:22 -0700499 case SET_GENERATION_NUMBER: {
500 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
501 uint32_t generationNumber = data.readUint32();
502 status_t result = setGenerationNumber(generationNumber);
503 reply->writeInt32(result);
504 return NO_ERROR;
505 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700506 case GET_CONSUMER_NAME: {
507 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
508 reply->writeString8(getConsumerName());
509 return NO_ERROR;
510 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800511 }
512 return BBinder::onTransact(code, data, reply, flags);
513}
514
515// ----------------------------------------------------------------------------
516
Andy McFadden2adaf042012-12-18 09:49:45 -0800517IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700518 parcel.read(*this);
519}
520
Mathias Agopiane1424282013-07-29 21:24:40 -0700521size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700522 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700523 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800524 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700525 + sizeof(crop)
526 + sizeof(scalingMode)
527 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700528 + sizeof(stickyTransform)
Dan Stoza5065a552015-03-17 16:23:42 -0700529 + fence->getFlattenedSize()
530 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700531}
532
Mathias Agopiane1424282013-07-29 21:24:40 -0700533size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800534 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700535}
536
Mathias Agopiane1424282013-07-29 21:24:40 -0700537status_t IGraphicBufferProducer::QueueBufferInput::flatten(
538 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700539{
Mathias Agopiane1424282013-07-29 21:24:40 -0700540 if (size < getFlattenedSize()) {
541 return NO_MEMORY;
542 }
543 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700544 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800545 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700546 FlattenableUtils::write(buffer, size, crop);
547 FlattenableUtils::write(buffer, size, scalingMode);
548 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700549 FlattenableUtils::write(buffer, size, stickyTransform);
Dan Stoza5065a552015-03-17 16:23:42 -0700550 status_t result = fence->flatten(buffer, size, fds, count);
551 if (result != NO_ERROR) {
552 return result;
553 }
554 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700555}
556
Mathias Agopiane1424282013-07-29 21:24:40 -0700557status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
558 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700559{
Mathias Agopiane1424282013-07-29 21:24:40 -0700560 size_t minNeeded =
561 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700562 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800563 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700564 + sizeof(crop)
565 + sizeof(scalingMode)
566 + sizeof(transform)
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700567 + sizeof(stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700568
569 if (size < minNeeded) {
570 return NO_MEMORY;
571 }
572
573 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700574 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800575 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700576 FlattenableUtils::read(buffer, size, crop);
577 FlattenableUtils::read(buffer, size, scalingMode);
578 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700579 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700580
Jamie Gennis1df8c342012-12-20 14:05:45 -0800581 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700582 status_t result = fence->unflatten(buffer, size, fds, count);
583 if (result != NO_ERROR) {
584 return result;
585 }
586 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700587}
588
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800589}; // namespace android