blob: 86b6971f6bbb20224c03b3037b856a89ce4a0d28 [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
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700209 virtual status_t 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());
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700214 status_t result = remote()->transact(CANCEL_BUFFER, data, &reply);
215 if (result != NO_ERROR) {
216 return result;
217 }
218 result = reply.readInt32();
219 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800220 }
221
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700222 virtual int query(int what, int* value) {
223 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800224 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700225 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700226 status_t result = remote()->transact(QUERY, data, &reply);
227 if (result != NO_ERROR) {
228 return result;
229 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700230 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700231 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700232 return result;
233 }
234
Dan Stozaf0eaf252014-03-21 13:05:51 -0700235 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700236 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700237 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800238 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700239 if (listener != NULL) {
240 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800241 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700242 } else {
243 data.writeInt32(0);
244 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700245 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700246 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700247 status_t result = remote()->transact(CONNECT, data, &reply);
248 if (result != NO_ERROR) {
249 return result;
250 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700251 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700252 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700253 return result;
254 }
Mathias Agopian80727112011-05-02 19:51:12 -0700255
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700256 virtual status_t disconnect(int api) {
257 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800258 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700259 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700260 status_t result =remote()->transact(DISCONNECT, data, &reply);
261 if (result != NO_ERROR) {
262 return result;
263 }
264 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700265 return result;
266 }
Jesse Hall399184a2014-03-03 15:42:54 -0800267
268 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
269 Parcel data, reply;
270 status_t result;
271 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
272 if (stream.get()) {
273 data.writeInt32(true);
274 data.writeNativeHandle(stream->handle());
275 } else {
276 data.writeInt32(false);
277 }
278 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
279 result = reply.readInt32();
280 }
281 return result;
282 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700283
284 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800285 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700286 Parcel data, reply;
287 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
288 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800289 data.writeUint32(width);
290 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700291 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800292 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700293 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
294 if (result != NO_ERROR) {
295 ALOGE("allocateBuffers failed to transact: %d", result);
296 }
297 }
Dan Stoza9de72932015-04-16 17:28:43 -0700298
299 virtual status_t allowAllocation(bool allow) {
300 Parcel data, reply;
301 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
302 data.writeInt32(static_cast<int32_t>(allow));
303 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
304 if (result != NO_ERROR) {
305 return result;
306 }
307 result = reply.readInt32();
308 return result;
309 }
Dan Stoza812ed062015-06-02 15:45:22 -0700310
311 virtual status_t setGenerationNumber(uint32_t generationNumber) {
312 Parcel data, reply;
313 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
314 data.writeUint32(generationNumber);
315 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
316 if (result == NO_ERROR) {
317 result = reply.readInt32();
318 }
319 return result;
320 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700321
322 virtual String8 getConsumerName() const {
323 Parcel data, reply;
324 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
325 status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
326 if (result != NO_ERROR) {
327 ALOGE("getConsumerName failed to transact: %d", result);
328 return String8("TransactFailed");
329 }
330 return reply.readString8();
331 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800332};
333
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800334// Out-of-line virtual method definition to trigger vtable emission in this
335// translation unit (see clang warning -Wweak-vtables)
336BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
337
Andy McFadden466a1922013-01-08 11:25:51 -0800338IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800339
340// ----------------------------------------------------------------------
341
Andy McFadden2adaf042012-12-18 09:49:45 -0800342status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800343 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
344{
345 switch(code) {
346 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800347 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800348 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700349 sp<GraphicBuffer> buffer;
350 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800351 reply->writeInt32(buffer != 0);
352 if (buffer != 0) {
353 reply->write(*buffer);
354 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700355 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800356 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800357 }
Pablo Ceballosfa455352015-08-12 17:47:47 -0700358 case SET_MAX_DEQUEUED_BUFFER_COUNT: {
359 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
360 int maxDequeuedBuffers = data.readInt32();
361 int result = setMaxDequeuedBufferCount(maxDequeuedBuffers);
362 reply->writeInt32(result);
363 return NO_ERROR;
364 }
365 case SET_ASYNC_MODE: {
366 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
367 bool async = data.readInt32();
368 int result = setAsyncMode(async);
369 reply->writeInt32(result);
370 return NO_ERROR;
371 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800372 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800373 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800374 bool async = static_cast<bool>(data.readInt32());
375 uint32_t width = data.readUint32();
376 uint32_t height = data.readUint32();
377 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
378 uint32_t usage = data.readUint32();
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700379 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700380 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800381 int result = dequeueBuffer(&buf, &fence, async, width, height,
382 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800383 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800384 reply->writeInt32(fence != NULL);
385 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700386 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700387 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800388 reply->writeInt32(result);
389 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800390 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800391 case DETACH_BUFFER: {
392 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
393 int slot = data.readInt32();
394 int result = detachBuffer(slot);
395 reply->writeInt32(result);
396 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800397 }
Dan Stozad9822a32014-03-28 15:25:31 -0700398 case DETACH_NEXT_BUFFER: {
399 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
400 sp<GraphicBuffer> buffer;
401 sp<Fence> fence;
402 int32_t result = detachNextBuffer(&buffer, &fence);
403 reply->writeInt32(result);
404 if (result == NO_ERROR) {
405 reply->writeInt32(buffer != NULL);
406 if (buffer != NULL) {
407 reply->write(*buffer);
408 }
409 reply->writeInt32(fence != NULL);
410 if (fence != NULL) {
411 reply->write(*fence);
412 }
413 }
414 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800415 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800416 case ATTACH_BUFFER: {
417 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
418 sp<GraphicBuffer> buffer = new GraphicBuffer();
419 data.read(*buffer.get());
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700420 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800421 int result = attachBuffer(&slot, buffer);
422 reply->writeInt32(slot);
423 reply->writeInt32(result);
424 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800425 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800426 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800427 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800428 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700429 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700430 QueueBufferOutput* const output =
431 reinterpret_cast<QueueBufferOutput *>(
432 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700433 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800434 reply->writeInt32(result);
435 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800436 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800437 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800438 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800439 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800440 sp<Fence> fence = new Fence();
441 data.read(*fence.get());
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700442 status_t result = cancelBuffer(buf, fence);
443 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800444 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800445 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700446 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800447 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700448 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700449 int what = data.readInt32();
450 int res = query(what, &value);
451 reply->writeInt32(value);
452 reply->writeInt32(res);
453 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800454 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700455 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800456 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700457 sp<IProducerListener> listener;
458 if (data.readInt32() == 1) {
459 listener = IProducerListener::asInterface(data.readStrongBinder());
460 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700461 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700462 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700463 QueueBufferOutput* const output =
464 reinterpret_cast<QueueBufferOutput *>(
465 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700466 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700467 reply->writeInt32(res);
468 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800469 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700470 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800471 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700472 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700473 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700474 reply->writeInt32(res);
475 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800476 }
Jesse Hall399184a2014-03-03 15:42:54 -0800477 case SET_SIDEBAND_STREAM: {
478 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
479 sp<NativeHandle> stream;
480 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900481 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800482 }
483 status_t result = setSidebandStream(stream);
484 reply->writeInt32(result);
485 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800486 }
Dan Stoza9de72932015-04-16 17:28:43 -0700487 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700488 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
489 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800490 uint32_t width = data.readUint32();
491 uint32_t height = data.readUint32();
492 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
493 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700494 allocateBuffers(async, width, height, format, usage);
495 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700496 }
497 case ALLOW_ALLOCATION: {
498 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
499 bool allow = static_cast<bool>(data.readInt32());
500 status_t result = allowAllocation(allow);
501 reply->writeInt32(result);
502 return NO_ERROR;
503 }
Dan Stoza812ed062015-06-02 15:45:22 -0700504 case SET_GENERATION_NUMBER: {
505 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
506 uint32_t generationNumber = data.readUint32();
507 status_t result = setGenerationNumber(generationNumber);
508 reply->writeInt32(result);
509 return NO_ERROR;
510 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700511 case GET_CONSUMER_NAME: {
512 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
513 reply->writeString8(getConsumerName());
514 return NO_ERROR;
515 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800516 }
517 return BBinder::onTransact(code, data, reply, flags);
518}
519
520// ----------------------------------------------------------------------------
521
Andy McFadden2adaf042012-12-18 09:49:45 -0800522IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700523 parcel.read(*this);
524}
525
Mathias Agopiane1424282013-07-29 21:24:40 -0700526size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700527 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700528 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800529 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700530 + sizeof(crop)
531 + sizeof(scalingMode)
532 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700533 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700534 + sizeof(async)
Dan Stoza5065a552015-03-17 16:23:42 -0700535 + fence->getFlattenedSize()
536 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700537}
538
Mathias Agopiane1424282013-07-29 21:24:40 -0700539size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800540 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700541}
542
Mathias Agopiane1424282013-07-29 21:24:40 -0700543status_t IGraphicBufferProducer::QueueBufferInput::flatten(
544 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700545{
Mathias Agopiane1424282013-07-29 21:24:40 -0700546 if (size < getFlattenedSize()) {
547 return NO_MEMORY;
548 }
549 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700550 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800551 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700552 FlattenableUtils::write(buffer, size, crop);
553 FlattenableUtils::write(buffer, size, scalingMode);
554 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700555 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700556 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700557 status_t result = fence->flatten(buffer, size, fds, count);
558 if (result != NO_ERROR) {
559 return result;
560 }
561 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700562}
563
Mathias Agopiane1424282013-07-29 21:24:40 -0700564status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
565 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700566{
Mathias Agopiane1424282013-07-29 21:24:40 -0700567 size_t minNeeded =
568 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700569 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800570 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700571 + sizeof(crop)
572 + sizeof(scalingMode)
573 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700574 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700575 + sizeof(async);
576
577 if (size < minNeeded) {
578 return NO_MEMORY;
579 }
580
581 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700582 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800583 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700584 FlattenableUtils::read(buffer, size, crop);
585 FlattenableUtils::read(buffer, size, scalingMode);
586 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700587 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700588 FlattenableUtils::read(buffer, size, async);
589
Jamie Gennis1df8c342012-12-20 14:05:45 -0800590 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700591 status_t result = fence->unflatten(buffer, size, fds, count);
592 if (result != NO_ERROR) {
593 return result;
594 }
595 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700596}
597
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800598}; // namespace android