blob: 8d874cdc1c980f31dd400478bbe7f5cd5776df27 [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
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700114 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800115 uint32_t width, uint32_t height, PixelFormat format,
116 uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800117 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800118 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800119 data.writeInt32(static_cast<int32_t>(async));
120 data.writeUint32(width);
121 data.writeUint32(height);
122 data.writeInt32(static_cast<int32_t>(format));
123 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700124 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
125 if (result != NO_ERROR) {
126 return result;
127 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800128 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700129 bool nonNull = reply.readInt32();
130 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700131 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700132 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700133 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700134 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800135 return result;
136 }
137
Dan Stoza9f3053d2014-03-06 15:14:33 -0800138 virtual status_t detachBuffer(int slot) {
139 Parcel data, reply;
140 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
141 data.writeInt32(slot);
142 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
143 if (result != NO_ERROR) {
144 return result;
145 }
146 result = reply.readInt32();
147 return result;
148 }
149
Dan Stozad9822a32014-03-28 15:25:31 -0700150 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
151 sp<Fence>* outFence) {
152 if (outBuffer == NULL) {
153 ALOGE("detachNextBuffer: outBuffer must not be NULL");
154 return BAD_VALUE;
155 } else if (outFence == NULL) {
156 ALOGE("detachNextBuffer: outFence must not be NULL");
157 return BAD_VALUE;
158 }
159 Parcel data, reply;
160 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
161 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
162 if (result != NO_ERROR) {
163 return result;
164 }
165 result = reply.readInt32();
166 if (result == NO_ERROR) {
167 bool nonNull = reply.readInt32();
168 if (nonNull) {
169 *outBuffer = new GraphicBuffer;
170 reply.read(**outBuffer);
171 }
172 nonNull = reply.readInt32();
173 if (nonNull) {
174 *outFence = new Fence;
175 reply.read(**outFence);
176 }
177 }
178 return result;
179 }
180
Dan Stoza9f3053d2014-03-06 15:14:33 -0800181 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
182 Parcel data, reply;
183 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
184 data.write(*buffer.get());
185 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
186 if (result != NO_ERROR) {
187 return result;
188 }
189 *slot = reply.readInt32();
190 result = reply.readInt32();
191 return result;
192 }
193
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700194 virtual status_t queueBuffer(int buf,
195 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800196 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800197 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800198 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700199 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700200 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
201 if (result != NO_ERROR) {
202 return result;
203 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700204 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700205 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800206 return result;
207 }
208
Jesse Hall4c00cc12013-03-15 21:34:30 -0700209 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800210 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800211 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800212 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800213 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800214 remote()->transact(CANCEL_BUFFER, data, &reply);
215 }
216
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700217 virtual int query(int what, int* value) {
218 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800219 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700220 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700221 status_t result = remote()->transact(QUERY, data, &reply);
222 if (result != NO_ERROR) {
223 return result;
224 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700225 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700226 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700227 return result;
228 }
229
Dan Stozaf0eaf252014-03-21 13:05:51 -0700230 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700231 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700232 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800233 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700234 if (listener != NULL) {
235 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800236 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700237 } else {
238 data.writeInt32(0);
239 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700240 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700241 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700242 status_t result = remote()->transact(CONNECT, data, &reply);
243 if (result != NO_ERROR) {
244 return result;
245 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700246 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700247 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700248 return result;
249 }
Mathias Agopian80727112011-05-02 19:51:12 -0700250
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700251 virtual status_t disconnect(int api) {
252 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800253 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700254 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700255 status_t result =remote()->transact(DISCONNECT, data, &reply);
256 if (result != NO_ERROR) {
257 return result;
258 }
259 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700260 return result;
261 }
Jesse Hall399184a2014-03-03 15:42:54 -0800262
263 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
264 Parcel data, reply;
265 status_t result;
266 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
267 if (stream.get()) {
268 data.writeInt32(true);
269 data.writeNativeHandle(stream->handle());
270 } else {
271 data.writeInt32(false);
272 }
273 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
274 result = reply.readInt32();
275 }
276 return result;
277 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700278
279 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800280 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700281 Parcel data, reply;
282 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
283 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800284 data.writeUint32(width);
285 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700286 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800287 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700288 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
289 if (result != NO_ERROR) {
290 ALOGE("allocateBuffers failed to transact: %d", result);
291 }
292 }
Dan Stoza9de72932015-04-16 17:28:43 -0700293
294 virtual status_t allowAllocation(bool allow) {
295 Parcel data, reply;
296 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
297 data.writeInt32(static_cast<int32_t>(allow));
298 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
299 if (result != NO_ERROR) {
300 return result;
301 }
302 result = reply.readInt32();
303 return result;
304 }
Dan Stoza812ed062015-06-02 15:45:22 -0700305
306 virtual status_t setGenerationNumber(uint32_t generationNumber) {
307 Parcel data, reply;
308 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
309 data.writeUint32(generationNumber);
310 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
311 if (result == NO_ERROR) {
312 result = reply.readInt32();
313 }
314 return result;
315 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700316
317 virtual String8 getConsumerName() const {
318 Parcel data, reply;
319 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
320 status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
321 if (result != NO_ERROR) {
322 ALOGE("getConsumerName failed to transact: %d", result);
323 return String8("TransactFailed");
324 }
325 return reply.readString8();
326 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800327};
328
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800329// Out-of-line virtual method definition to trigger vtable emission in this
330// translation unit (see clang warning -Wweak-vtables)
331BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
332
Andy McFadden466a1922013-01-08 11:25:51 -0800333IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800334
335// ----------------------------------------------------------------------
336
Andy McFadden2adaf042012-12-18 09:49:45 -0800337status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800338 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
339{
340 switch(code) {
341 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800342 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800343 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700344 sp<GraphicBuffer> buffer;
345 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800346 reply->writeInt32(buffer != 0);
347 if (buffer != 0) {
348 reply->write(*buffer);
349 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700350 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800351 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800352 }
Pablo Ceballosfa455352015-08-12 17:47:47 -0700353 case SET_MAX_DEQUEUED_BUFFER_COUNT: {
354 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
355 int maxDequeuedBuffers = data.readInt32();
356 int result = setMaxDequeuedBufferCount(maxDequeuedBuffers);
357 reply->writeInt32(result);
358 return NO_ERROR;
359 }
360 case SET_ASYNC_MODE: {
361 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
362 bool async = data.readInt32();
363 int result = setAsyncMode(async);
364 reply->writeInt32(result);
365 return NO_ERROR;
366 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800367 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800368 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800369 bool async = static_cast<bool>(data.readInt32());
370 uint32_t width = data.readUint32();
371 uint32_t height = data.readUint32();
372 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
373 uint32_t usage = data.readUint32();
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700374 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700375 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800376 int result = dequeueBuffer(&buf, &fence, async, width, height,
377 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800378 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800379 reply->writeInt32(fence != NULL);
380 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700381 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700382 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800383 reply->writeInt32(result);
384 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800385 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800386 case DETACH_BUFFER: {
387 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
388 int slot = data.readInt32();
389 int result = detachBuffer(slot);
390 reply->writeInt32(result);
391 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800392 }
Dan Stozad9822a32014-03-28 15:25:31 -0700393 case DETACH_NEXT_BUFFER: {
394 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
395 sp<GraphicBuffer> buffer;
396 sp<Fence> fence;
397 int32_t result = detachNextBuffer(&buffer, &fence);
398 reply->writeInt32(result);
399 if (result == NO_ERROR) {
400 reply->writeInt32(buffer != NULL);
401 if (buffer != NULL) {
402 reply->write(*buffer);
403 }
404 reply->writeInt32(fence != NULL);
405 if (fence != NULL) {
406 reply->write(*fence);
407 }
408 }
409 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800410 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800411 case ATTACH_BUFFER: {
412 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
413 sp<GraphicBuffer> buffer = new GraphicBuffer();
414 data.read(*buffer.get());
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700415 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800416 int result = attachBuffer(&slot, buffer);
417 reply->writeInt32(slot);
418 reply->writeInt32(result);
419 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800420 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800421 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800422 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800423 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700424 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700425 QueueBufferOutput* const output =
426 reinterpret_cast<QueueBufferOutput *>(
427 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700428 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800429 reply->writeInt32(result);
430 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800431 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800432 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800433 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800434 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800435 sp<Fence> fence = new Fence();
436 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700437 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800438 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800439 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700440 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800441 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700442 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700443 int what = data.readInt32();
444 int res = query(what, &value);
445 reply->writeInt32(value);
446 reply->writeInt32(res);
447 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800448 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700449 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800450 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700451 sp<IProducerListener> listener;
452 if (data.readInt32() == 1) {
453 listener = IProducerListener::asInterface(data.readStrongBinder());
454 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700455 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700456 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700457 QueueBufferOutput* const output =
458 reinterpret_cast<QueueBufferOutput *>(
459 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700460 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700461 reply->writeInt32(res);
462 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800463 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700464 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800465 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700466 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700467 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700468 reply->writeInt32(res);
469 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800470 }
Jesse Hall399184a2014-03-03 15:42:54 -0800471 case SET_SIDEBAND_STREAM: {
472 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
473 sp<NativeHandle> stream;
474 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900475 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800476 }
477 status_t result = setSidebandStream(stream);
478 reply->writeInt32(result);
479 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800480 }
Dan Stoza9de72932015-04-16 17:28:43 -0700481 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700482 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
483 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800484 uint32_t width = data.readUint32();
485 uint32_t height = data.readUint32();
486 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
487 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700488 allocateBuffers(async, width, height, format, usage);
489 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700490 }
491 case ALLOW_ALLOCATION: {
492 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
493 bool allow = static_cast<bool>(data.readInt32());
494 status_t result = allowAllocation(allow);
495 reply->writeInt32(result);
496 return NO_ERROR;
497 }
Dan Stoza812ed062015-06-02 15:45:22 -0700498 case SET_GENERATION_NUMBER: {
499 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
500 uint32_t generationNumber = data.readUint32();
501 status_t result = setGenerationNumber(generationNumber);
502 reply->writeInt32(result);
503 return NO_ERROR;
504 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700505 case GET_CONSUMER_NAME: {
506 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
507 reply->writeString8(getConsumerName());
508 return NO_ERROR;
509 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800510 }
511 return BBinder::onTransact(code, data, reply, flags);
512}
513
514// ----------------------------------------------------------------------------
515
Andy McFadden2adaf042012-12-18 09:49:45 -0800516IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700517 parcel.read(*this);
518}
519
Mathias Agopiane1424282013-07-29 21:24:40 -0700520size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700521 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700522 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800523 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700524 + sizeof(crop)
525 + sizeof(scalingMode)
526 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700527 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700528 + sizeof(async)
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);
Mathias Agopiane1424282013-07-29 21:24:40 -0700550 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700551 status_t result = fence->flatten(buffer, size, fds, count);
552 if (result != NO_ERROR) {
553 return result;
554 }
555 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700556}
557
Mathias Agopiane1424282013-07-29 21:24:40 -0700558status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
559 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700560{
Mathias Agopiane1424282013-07-29 21:24:40 -0700561 size_t minNeeded =
562 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700563 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800564 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700565 + sizeof(crop)
566 + sizeof(scalingMode)
567 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700568 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700569 + sizeof(async);
570
571 if (size < minNeeded) {
572 return NO_MEMORY;
573 }
574
575 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700576 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800577 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700578 FlattenableUtils::read(buffer, size, crop);
579 FlattenableUtils::read(buffer, size, scalingMode);
580 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700581 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700582 FlattenableUtils::read(buffer, size, async);
583
Jamie Gennis1df8c342012-12-20 14:05:45 -0800584 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700585 status_t result = fence->unflatten(buffer, size, fds, count);
586 if (result != NO_ERROR) {
587 return result;
588 }
589 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700590}
591
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800592}; // namespace android