blob: 4a6badabd15f5208b7e9f27d6c75575d4b50381e [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,
37 SET_BUFFER_COUNT,
38 DEQUEUE_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080039 DETACH_BUFFER,
Dan Stozad9822a32014-03-28 15:25:31 -070040 DETACH_NEXT_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080041 ATTACH_BUFFER,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080042 QUEUE_BUFFER,
43 CANCEL_BUFFER,
Mathias Agopianeafabcd2011-04-20 14:20:59 -070044 QUERY,
Jamie Gennisfe0a87b2011-07-13 19:12:20 -070045 CONNECT,
46 DISCONNECT,
Jesse Hall399184a2014-03-03 15:42:54 -080047 SET_SIDEBAND_STREAM,
Dan Stoza29a3e902014-06-20 13:13:57 -070048 ALLOCATE_BUFFERS,
Dan Stoza9de72932015-04-16 17:28:43 -070049 ALLOW_ALLOCATION,
Dan Stoza812ed062015-06-02 15:45:22 -070050 SET_GENERATION_NUMBER,
Dan Stozac6f30bd2015-06-08 09:32:50 -070051 GET_CONSUMER_NAME,
Pablo Ceballosfa455352015-08-12 17:47:47 -070052 SET_MAX_DEQUEUED_BUFFER_COUNT,
53 SET_ASYNC_MODE
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080054};
55
Andy McFadden2adaf042012-12-18 09:49:45 -080056class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080057{
58public:
Andy McFadden2adaf042012-12-18 09:49:45 -080059 BpGraphicBufferProducer(const sp<IBinder>& impl)
60 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080061 {
62 }
63
Dan Stoza3be1c6b2014-11-18 10:24:03 -080064 virtual ~BpGraphicBufferProducer();
65
Jamie Gennis7b305ff2011-07-19 12:08:33 -070066 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080067 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080068 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080069 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070070 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
71 if (result != NO_ERROR) {
72 return result;
73 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080074 bool nonNull = reply.readInt32();
75 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070076 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080077 result = reply.read(**buf);
78 if(result != NO_ERROR) {
79 (*buf).clear();
80 return result;
81 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080082 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070083 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070084 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080085 }
86
87 virtual status_t setBufferCount(int bufferCount)
88 {
89 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080090 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080091 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070092 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
93 if (result != NO_ERROR) {
94 return result;
95 }
96 result = reply.readInt32();
97 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080098 }
99
Pablo Ceballosfa455352015-08-12 17:47:47 -0700100 virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) {
101 Parcel data, reply;
102 data.writeInterfaceToken(
103 IGraphicBufferProducer::getInterfaceDescriptor());
104 data.writeInt32(maxDequeuedBuffers);
105 status_t result = remote()->transact(SET_MAX_DEQUEUED_BUFFER_COUNT,
106 data, &reply);
107 if (result != NO_ERROR) {
108 return result;
109 }
110 result = reply.readInt32();
111 return result;
112 }
113
114 virtual status_t setAsyncMode(bool async) {
115 Parcel data, reply;
116 data.writeInterfaceToken(
117 IGraphicBufferProducer::getInterfaceDescriptor());
118 data.writeInt32(async);
119 status_t result = remote()->transact(SET_ASYNC_MODE,
120 data, &reply);
121 if (result != NO_ERROR) {
122 return result;
123 }
124 result = reply.readInt32();
125 return result;
126 }
127
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700128 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800129 uint32_t width, uint32_t height, PixelFormat format,
130 uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800131 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800132 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800133 data.writeInt32(static_cast<int32_t>(async));
134 data.writeUint32(width);
135 data.writeUint32(height);
136 data.writeInt32(static_cast<int32_t>(format));
137 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700138 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
139 if (result != NO_ERROR) {
140 return result;
141 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800142 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700143 bool nonNull = reply.readInt32();
144 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700145 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700146 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700147 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700148 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800149 return result;
150 }
151
Dan Stoza9f3053d2014-03-06 15:14:33 -0800152 virtual status_t detachBuffer(int slot) {
153 Parcel data, reply;
154 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
155 data.writeInt32(slot);
156 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
157 if (result != NO_ERROR) {
158 return result;
159 }
160 result = reply.readInt32();
161 return result;
162 }
163
Dan Stozad9822a32014-03-28 15:25:31 -0700164 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
165 sp<Fence>* outFence) {
166 if (outBuffer == NULL) {
167 ALOGE("detachNextBuffer: outBuffer must not be NULL");
168 return BAD_VALUE;
169 } else if (outFence == NULL) {
170 ALOGE("detachNextBuffer: outFence must not be NULL");
171 return BAD_VALUE;
172 }
173 Parcel data, reply;
174 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
175 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
176 if (result != NO_ERROR) {
177 return result;
178 }
179 result = reply.readInt32();
180 if (result == NO_ERROR) {
181 bool nonNull = reply.readInt32();
182 if (nonNull) {
183 *outBuffer = new GraphicBuffer;
184 reply.read(**outBuffer);
185 }
186 nonNull = reply.readInt32();
187 if (nonNull) {
188 *outFence = new Fence;
189 reply.read(**outFence);
190 }
191 }
192 return result;
193 }
194
Dan Stoza9f3053d2014-03-06 15:14:33 -0800195 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
196 Parcel data, reply;
197 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
198 data.write(*buffer.get());
199 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
200 if (result != NO_ERROR) {
201 return result;
202 }
203 *slot = reply.readInt32();
204 result = reply.readInt32();
205 return result;
206 }
207
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700208 virtual status_t queueBuffer(int buf,
209 const QueueBufferInput& input, QueueBufferOutput* output) {
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);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700213 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700214 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
215 if (result != NO_ERROR) {
216 return result;
217 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700218 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700219 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800220 return result;
221 }
222
Jesse Hall4c00cc12013-03-15 21:34:30 -0700223 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800224 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800225 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800226 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800227 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800228 remote()->transact(CANCEL_BUFFER, data, &reply);
229 }
230
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700231 virtual int query(int what, int* value) {
232 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800233 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700234 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700235 status_t result = remote()->transact(QUERY, data, &reply);
236 if (result != NO_ERROR) {
237 return result;
238 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700239 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700240 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700241 return result;
242 }
243
Dan Stozaf0eaf252014-03-21 13:05:51 -0700244 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700245 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700246 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800247 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700248 if (listener != NULL) {
249 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800250 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700251 } else {
252 data.writeInt32(0);
253 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700254 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700255 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700256 status_t result = remote()->transact(CONNECT, data, &reply);
257 if (result != NO_ERROR) {
258 return result;
259 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700260 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700261 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700262 return result;
263 }
Mathias Agopian80727112011-05-02 19:51:12 -0700264
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700265 virtual status_t disconnect(int api) {
266 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800267 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700268 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700269 status_t result =remote()->transact(DISCONNECT, data, &reply);
270 if (result != NO_ERROR) {
271 return result;
272 }
273 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700274 return result;
275 }
Jesse Hall399184a2014-03-03 15:42:54 -0800276
277 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
278 Parcel data, reply;
279 status_t result;
280 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
281 if (stream.get()) {
282 data.writeInt32(true);
283 data.writeNativeHandle(stream->handle());
284 } else {
285 data.writeInt32(false);
286 }
287 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
288 result = reply.readInt32();
289 }
290 return result;
291 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700292
293 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800294 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700295 Parcel data, reply;
296 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
297 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800298 data.writeUint32(width);
299 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700300 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800301 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700302 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
303 if (result != NO_ERROR) {
304 ALOGE("allocateBuffers failed to transact: %d", result);
305 }
306 }
Dan Stoza9de72932015-04-16 17:28:43 -0700307
308 virtual status_t allowAllocation(bool allow) {
309 Parcel data, reply;
310 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
311 data.writeInt32(static_cast<int32_t>(allow));
312 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
313 if (result != NO_ERROR) {
314 return result;
315 }
316 result = reply.readInt32();
317 return result;
318 }
Dan Stoza812ed062015-06-02 15:45:22 -0700319
320 virtual status_t setGenerationNumber(uint32_t generationNumber) {
321 Parcel data, reply;
322 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
323 data.writeUint32(generationNumber);
324 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
325 if (result == NO_ERROR) {
326 result = reply.readInt32();
327 }
328 return result;
329 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700330
331 virtual String8 getConsumerName() const {
332 Parcel data, reply;
333 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
334 status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
335 if (result != NO_ERROR) {
336 ALOGE("getConsumerName failed to transact: %d", result);
337 return String8("TransactFailed");
338 }
339 return reply.readString8();
340 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800341};
342
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800343// Out-of-line virtual method definition to trigger vtable emission in this
344// translation unit (see clang warning -Wweak-vtables)
345BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
346
Andy McFadden466a1922013-01-08 11:25:51 -0800347IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800348
349// ----------------------------------------------------------------------
350
Andy McFadden2adaf042012-12-18 09:49:45 -0800351status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800352 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
353{
354 switch(code) {
355 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800356 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800357 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700358 sp<GraphicBuffer> buffer;
359 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800360 reply->writeInt32(buffer != 0);
361 if (buffer != 0) {
362 reply->write(*buffer);
363 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700364 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800365 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800366 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800367 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800368 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800369 int bufferCount = data.readInt32();
370 int result = setBufferCount(bufferCount);
371 reply->writeInt32(result);
372 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800373 }
Pablo Ceballosfa455352015-08-12 17:47:47 -0700374 case SET_MAX_DEQUEUED_BUFFER_COUNT: {
375 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
376 int maxDequeuedBuffers = data.readInt32();
377 int result = setMaxDequeuedBufferCount(maxDequeuedBuffers);
378 reply->writeInt32(result);
379 return NO_ERROR;
380 }
381 case SET_ASYNC_MODE: {
382 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
383 bool async = data.readInt32();
384 int result = setAsyncMode(async);
385 reply->writeInt32(result);
386 return NO_ERROR;
387 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800388 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800389 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800390 bool async = static_cast<bool>(data.readInt32());
391 uint32_t width = data.readUint32();
392 uint32_t height = data.readUint32();
393 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
394 uint32_t usage = data.readUint32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800395 int buf;
Jesse Hallf7857542012-06-14 15:26:33 -0700396 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800397 int result = dequeueBuffer(&buf, &fence, async, width, height,
398 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800399 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800400 reply->writeInt32(fence != NULL);
401 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700402 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700403 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800404 reply->writeInt32(result);
405 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800406 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800407 case DETACH_BUFFER: {
408 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
409 int slot = data.readInt32();
410 int result = detachBuffer(slot);
411 reply->writeInt32(result);
412 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800413 }
Dan Stozad9822a32014-03-28 15:25:31 -0700414 case DETACH_NEXT_BUFFER: {
415 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
416 sp<GraphicBuffer> buffer;
417 sp<Fence> fence;
418 int32_t result = detachNextBuffer(&buffer, &fence);
419 reply->writeInt32(result);
420 if (result == NO_ERROR) {
421 reply->writeInt32(buffer != NULL);
422 if (buffer != NULL) {
423 reply->write(*buffer);
424 }
425 reply->writeInt32(fence != NULL);
426 if (fence != NULL) {
427 reply->write(*fence);
428 }
429 }
430 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800431 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800432 case ATTACH_BUFFER: {
433 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
434 sp<GraphicBuffer> buffer = new GraphicBuffer();
435 data.read(*buffer.get());
436 int slot;
437 int result = attachBuffer(&slot, buffer);
438 reply->writeInt32(slot);
439 reply->writeInt32(result);
440 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800441 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800442 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800443 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800444 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700445 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700446 QueueBufferOutput* const output =
447 reinterpret_cast<QueueBufferOutput *>(
448 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700449 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800450 reply->writeInt32(result);
451 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800452 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800453 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800454 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800455 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800456 sp<Fence> fence = new Fence();
457 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700458 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800459 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800460 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700461 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800462 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700463 int value;
464 int what = data.readInt32();
465 int res = query(what, &value);
466 reply->writeInt32(value);
467 reply->writeInt32(res);
468 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800469 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700470 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800471 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700472 sp<IProducerListener> listener;
473 if (data.readInt32() == 1) {
474 listener = IProducerListener::asInterface(data.readStrongBinder());
475 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700476 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700477 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700478 QueueBufferOutput* const output =
479 reinterpret_cast<QueueBufferOutput *>(
480 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700481 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700482 reply->writeInt32(res);
483 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800484 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700485 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800486 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700487 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700488 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700489 reply->writeInt32(res);
490 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800491 }
Jesse Hall399184a2014-03-03 15:42:54 -0800492 case SET_SIDEBAND_STREAM: {
493 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
494 sp<NativeHandle> stream;
495 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900496 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800497 }
498 status_t result = setSidebandStream(stream);
499 reply->writeInt32(result);
500 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800501 }
Dan Stoza9de72932015-04-16 17:28:43 -0700502 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700503 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
504 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800505 uint32_t width = data.readUint32();
506 uint32_t height = data.readUint32();
507 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
508 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700509 allocateBuffers(async, width, height, format, usage);
510 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700511 }
512 case ALLOW_ALLOCATION: {
513 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
514 bool allow = static_cast<bool>(data.readInt32());
515 status_t result = allowAllocation(allow);
516 reply->writeInt32(result);
517 return NO_ERROR;
518 }
Dan Stoza812ed062015-06-02 15:45:22 -0700519 case SET_GENERATION_NUMBER: {
520 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
521 uint32_t generationNumber = data.readUint32();
522 status_t result = setGenerationNumber(generationNumber);
523 reply->writeInt32(result);
524 return NO_ERROR;
525 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700526 case GET_CONSUMER_NAME: {
527 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
528 reply->writeString8(getConsumerName());
529 return NO_ERROR;
530 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800531 }
532 return BBinder::onTransact(code, data, reply, flags);
533}
534
535// ----------------------------------------------------------------------------
536
Andy McFadden2adaf042012-12-18 09:49:45 -0800537IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700538 parcel.read(*this);
539}
540
Mathias Agopiane1424282013-07-29 21:24:40 -0700541size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700542 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700543 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800544 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700545 + sizeof(crop)
546 + sizeof(scalingMode)
547 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700548 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700549 + sizeof(async)
Dan Stoza5065a552015-03-17 16:23:42 -0700550 + fence->getFlattenedSize()
551 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700552}
553
Mathias Agopiane1424282013-07-29 21:24:40 -0700554size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800555 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700556}
557
Mathias Agopiane1424282013-07-29 21:24:40 -0700558status_t IGraphicBufferProducer::QueueBufferInput::flatten(
559 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700560{
Mathias Agopiane1424282013-07-29 21:24:40 -0700561 if (size < getFlattenedSize()) {
562 return NO_MEMORY;
563 }
564 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700565 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800566 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700567 FlattenableUtils::write(buffer, size, crop);
568 FlattenableUtils::write(buffer, size, scalingMode);
569 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700570 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700571 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700572 status_t result = fence->flatten(buffer, size, fds, count);
573 if (result != NO_ERROR) {
574 return result;
575 }
576 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700577}
578
Mathias Agopiane1424282013-07-29 21:24:40 -0700579status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
580 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700581{
Mathias Agopiane1424282013-07-29 21:24:40 -0700582 size_t minNeeded =
583 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700584 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800585 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700586 + sizeof(crop)
587 + sizeof(scalingMode)
588 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700589 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700590 + sizeof(async);
591
592 if (size < minNeeded) {
593 return NO_MEMORY;
594 }
595
596 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700597 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800598 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700599 FlattenableUtils::read(buffer, size, crop);
600 FlattenableUtils::read(buffer, size, scalingMode);
601 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700602 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700603 FlattenableUtils::read(buffer, size, async);
604
Jamie Gennis1df8c342012-12-20 14:05:45 -0800605 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700606 status_t result = fence->unflatten(buffer, size, fds, count);
607 if (result != NO_ERROR) {
608 return result;
609 }
610 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700611}
612
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800613}; // namespace android