blob: d5310bdccd1d1b5a3d53cf2add556085f6d33363 [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,
Dan Stoza7dde5992015-05-22 09:51:44 -070052 SET_ASYNC_MODE,
Pablo Ceballosccdfd602015-10-07 15:05:45 -070053 GET_NEXT_FRAME_NUMBER,
54 SET_SINGLE_BUFFER_MODE
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080055};
56
Andy McFadden2adaf042012-12-18 09:49:45 -080057class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080058{
59public:
Andy McFadden2adaf042012-12-18 09:49:45 -080060 BpGraphicBufferProducer(const sp<IBinder>& impl)
61 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080062 {
63 }
64
Dan Stoza3be1c6b2014-11-18 10:24:03 -080065 virtual ~BpGraphicBufferProducer();
66
Jamie Gennis7b305ff2011-07-19 12:08:33 -070067 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080068 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080069 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080070 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070071 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
72 if (result != NO_ERROR) {
73 return result;
74 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080075 bool nonNull = reply.readInt32();
76 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070077 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080078 result = reply.read(**buf);
79 if(result != NO_ERROR) {
80 (*buf).clear();
81 return result;
82 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080083 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070084 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070085 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080086 }
87
Pablo Ceballosfa455352015-08-12 17:47:47 -070088 virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) {
89 Parcel data, reply;
90 data.writeInterfaceToken(
91 IGraphicBufferProducer::getInterfaceDescriptor());
92 data.writeInt32(maxDequeuedBuffers);
93 status_t result = remote()->transact(SET_MAX_DEQUEUED_BUFFER_COUNT,
94 data, &reply);
95 if (result != NO_ERROR) {
96 return result;
97 }
98 result = reply.readInt32();
99 return result;
100 }
101
102 virtual status_t setAsyncMode(bool async) {
103 Parcel data, reply;
104 data.writeInterfaceToken(
105 IGraphicBufferProducer::getInterfaceDescriptor());
106 data.writeInt32(async);
107 status_t result = remote()->transact(SET_ASYNC_MODE,
108 data, &reply);
109 if (result != NO_ERROR) {
110 return result;
111 }
112 result = reply.readInt32();
113 return result;
114 }
115
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700116 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, uint32_t width,
117 uint32_t height, PixelFormat format, uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800118 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800119 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800120 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
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700284 virtual void allocateBuffers(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());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800288 data.writeUint32(width);
289 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700290 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800291 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700292 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
293 if (result != NO_ERROR) {
294 ALOGE("allocateBuffers failed to transact: %d", result);
295 }
296 }
Dan Stoza9de72932015-04-16 17:28:43 -0700297
298 virtual status_t allowAllocation(bool allow) {
299 Parcel data, reply;
300 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
301 data.writeInt32(static_cast<int32_t>(allow));
302 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
303 if (result != NO_ERROR) {
304 return result;
305 }
306 result = reply.readInt32();
307 return result;
308 }
Dan Stoza812ed062015-06-02 15:45:22 -0700309
310 virtual status_t setGenerationNumber(uint32_t generationNumber) {
311 Parcel data, reply;
312 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
313 data.writeUint32(generationNumber);
314 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
315 if (result == NO_ERROR) {
316 result = reply.readInt32();
317 }
318 return result;
319 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700320
321 virtual String8 getConsumerName() const {
322 Parcel data, reply;
323 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
324 status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
325 if (result != NO_ERROR) {
326 ALOGE("getConsumerName failed to transact: %d", result);
327 return String8("TransactFailed");
328 }
329 return reply.readString8();
330 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700331
332 virtual uint64_t getNextFrameNumber() const {
333 Parcel data, reply;
334 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
335 status_t result = remote()->transact(GET_NEXT_FRAME_NUMBER, data, &reply);
336 if (result != NO_ERROR) {
337 ALOGE("getNextFrameNumber failed to transact: %d", result);
338 return 0;
339 }
340 uint64_t frameNumber = reply.readUint64();
341 return frameNumber;
342 }
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700343
344 virtual status_t setSingleBufferMode(bool singleBufferMode) {
345 Parcel data, reply;
346 data.writeInterfaceToken(
347 IGraphicBufferProducer::getInterfaceDescriptor());
348 data.writeInt32(singleBufferMode);
349 status_t result = remote()->transact(SET_SINGLE_BUFFER_MODE, data,
350 &reply);
351 if (result == NO_ERROR) {
352 result = reply.readInt32();
353 }
354 return result;
355 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800356};
357
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800358// Out-of-line virtual method definition to trigger vtable emission in this
359// translation unit (see clang warning -Wweak-vtables)
360BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
361
Andy McFadden466a1922013-01-08 11:25:51 -0800362IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800363
364// ----------------------------------------------------------------------
365
Andy McFadden2adaf042012-12-18 09:49:45 -0800366status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800367 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
368{
369 switch(code) {
370 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800371 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800372 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700373 sp<GraphicBuffer> buffer;
374 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800375 reply->writeInt32(buffer != 0);
376 if (buffer != 0) {
377 reply->write(*buffer);
378 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700379 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800380 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800381 }
Pablo Ceballosfa455352015-08-12 17:47:47 -0700382 case SET_MAX_DEQUEUED_BUFFER_COUNT: {
383 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
384 int maxDequeuedBuffers = data.readInt32();
385 int result = setMaxDequeuedBufferCount(maxDequeuedBuffers);
386 reply->writeInt32(result);
387 return NO_ERROR;
388 }
389 case SET_ASYNC_MODE: {
390 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
391 bool async = data.readInt32();
392 int result = setAsyncMode(async);
393 reply->writeInt32(result);
394 return NO_ERROR;
395 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800396 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800397 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800398 uint32_t width = data.readUint32();
399 uint32_t height = data.readUint32();
400 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
401 uint32_t usage = data.readUint32();
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700402 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700403 sp<Fence> fence;
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700404 int result = dequeueBuffer(&buf, &fence, width, height, format,
405 usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800406 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800407 reply->writeInt32(fence != NULL);
408 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700409 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700410 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800411 reply->writeInt32(result);
412 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800413 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800414 case DETACH_BUFFER: {
415 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
416 int slot = data.readInt32();
417 int result = detachBuffer(slot);
418 reply->writeInt32(result);
419 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800420 }
Dan Stozad9822a32014-03-28 15:25:31 -0700421 case DETACH_NEXT_BUFFER: {
422 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
423 sp<GraphicBuffer> buffer;
424 sp<Fence> fence;
425 int32_t result = detachNextBuffer(&buffer, &fence);
426 reply->writeInt32(result);
427 if (result == NO_ERROR) {
428 reply->writeInt32(buffer != NULL);
429 if (buffer != NULL) {
430 reply->write(*buffer);
431 }
432 reply->writeInt32(fence != NULL);
433 if (fence != NULL) {
434 reply->write(*fence);
435 }
436 }
437 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800438 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800439 case ATTACH_BUFFER: {
440 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
441 sp<GraphicBuffer> buffer = new GraphicBuffer();
442 data.read(*buffer.get());
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700443 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800444 int result = attachBuffer(&slot, buffer);
445 reply->writeInt32(slot);
446 reply->writeInt32(result);
447 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800448 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800449 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800450 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800451 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700452 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700453 QueueBufferOutput* const output =
454 reinterpret_cast<QueueBufferOutput *>(
455 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700456 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800457 reply->writeInt32(result);
458 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800459 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800460 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800461 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800462 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800463 sp<Fence> fence = new Fence();
464 data.read(*fence.get());
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700465 status_t result = cancelBuffer(buf, fence);
466 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800467 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800468 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700469 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800470 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekha12ba0f52015-09-21 17:28:04 -0700471 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700472 int what = data.readInt32();
473 int res = query(what, &value);
474 reply->writeInt32(value);
475 reply->writeInt32(res);
476 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800477 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700478 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800479 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700480 sp<IProducerListener> listener;
481 if (data.readInt32() == 1) {
482 listener = IProducerListener::asInterface(data.readStrongBinder());
483 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700484 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700485 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700486 QueueBufferOutput* const output =
487 reinterpret_cast<QueueBufferOutput *>(
488 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700489 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700490 reply->writeInt32(res);
491 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800492 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700493 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800494 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700495 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700496 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700497 reply->writeInt32(res);
498 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800499 }
Jesse Hall399184a2014-03-03 15:42:54 -0800500 case SET_SIDEBAND_STREAM: {
501 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
502 sp<NativeHandle> stream;
503 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900504 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800505 }
506 status_t result = setSidebandStream(stream);
507 reply->writeInt32(result);
508 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800509 }
Dan Stoza9de72932015-04-16 17:28:43 -0700510 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700511 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800512 uint32_t width = data.readUint32();
513 uint32_t height = data.readUint32();
514 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
515 uint32_t usage = data.readUint32();
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700516 allocateBuffers(width, height, format, usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700517 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700518 }
519 case ALLOW_ALLOCATION: {
520 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
521 bool allow = static_cast<bool>(data.readInt32());
522 status_t result = allowAllocation(allow);
523 reply->writeInt32(result);
524 return NO_ERROR;
525 }
Dan Stoza812ed062015-06-02 15:45:22 -0700526 case SET_GENERATION_NUMBER: {
527 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
528 uint32_t generationNumber = data.readUint32();
529 status_t result = setGenerationNumber(generationNumber);
530 reply->writeInt32(result);
531 return NO_ERROR;
532 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700533 case GET_CONSUMER_NAME: {
534 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
535 reply->writeString8(getConsumerName());
536 return NO_ERROR;
537 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700538 case GET_NEXT_FRAME_NUMBER: {
539 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
540 uint64_t frameNumber = getNextFrameNumber();
541 reply->writeUint64(frameNumber);
542 return NO_ERROR;
543 }
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700544 case SET_SINGLE_BUFFER_MODE: {
545 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
546 bool singleBufferMode = data.readInt32();
547 status_t result = setSingleBufferMode(singleBufferMode);
548 reply->writeInt32(result);
549 return NO_ERROR;
550 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800551 }
552 return BBinder::onTransact(code, data, reply, flags);
553}
554
555// ----------------------------------------------------------------------------
556
Andy McFadden2adaf042012-12-18 09:49:45 -0800557IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700558 parcel.read(*this);
559}
560
Mathias Agopiane1424282013-07-29 21:24:40 -0700561size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700562 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700563 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800564 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700565 + sizeof(crop)
566 + sizeof(scalingMode)
567 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700568 + sizeof(stickyTransform)
Dan Stoza5065a552015-03-17 16:23:42 -0700569 + fence->getFlattenedSize()
570 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700571}
572
Mathias Agopiane1424282013-07-29 21:24:40 -0700573size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800574 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700575}
576
Mathias Agopiane1424282013-07-29 21:24:40 -0700577status_t IGraphicBufferProducer::QueueBufferInput::flatten(
578 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700579{
Mathias Agopiane1424282013-07-29 21:24:40 -0700580 if (size < getFlattenedSize()) {
581 return NO_MEMORY;
582 }
583 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700584 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800585 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700586 FlattenableUtils::write(buffer, size, crop);
587 FlattenableUtils::write(buffer, size, scalingMode);
588 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700589 FlattenableUtils::write(buffer, size, stickyTransform);
Dan Stoza5065a552015-03-17 16:23:42 -0700590 status_t result = fence->flatten(buffer, size, fds, count);
591 if (result != NO_ERROR) {
592 return result;
593 }
594 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700595}
596
Mathias Agopiane1424282013-07-29 21:24:40 -0700597status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
598 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700599{
Mathias Agopiane1424282013-07-29 21:24:40 -0700600 size_t minNeeded =
601 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700602 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800603 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700604 + sizeof(crop)
605 + sizeof(scalingMode)
606 + sizeof(transform)
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700607 + sizeof(stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700608
609 if (size < minNeeded) {
610 return NO_MEMORY;
611 }
612
613 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700614 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800615 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700616 FlattenableUtils::read(buffer, size, crop);
617 FlattenableUtils::read(buffer, size, scalingMode);
618 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700619 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700620
Jamie Gennis1df8c342012-12-20 14:05:45 -0800621 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700622 status_t result = fence->unflatten(buffer, size, fds, count);
623 if (result != NO_ERROR) {
624 return result;
625 }
626 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700627}
628
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800629}; // namespace android