blob: 51eedab3dec55efa770b735fce8fce3abe5b67c7 [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
Chia-I Wu734ce0a2017-05-15 10:32:27 -070029#include <gui/BufferQueueDefs.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080030#include <gui/IGraphicBufferProducer.h>
Dan Stozaf0eaf252014-03-21 13:05:51 -070031#include <gui/IProducerListener.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080032
33namespace android {
34// ----------------------------------------------------------------------------
35
36enum {
37 REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
38 SET_BUFFER_COUNT,
39 DEQUEUE_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080040 DETACH_BUFFER,
Dan Stozad9822a32014-03-28 15:25:31 -070041 DETACH_NEXT_BUFFER,
Dan Stoza9f3053d2014-03-06 15:14:33 -080042 ATTACH_BUFFER,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080043 QUEUE_BUFFER,
44 CANCEL_BUFFER,
Mathias Agopianeafabcd2011-04-20 14:20:59 -070045 QUERY,
Jamie Gennisfe0a87b2011-07-13 19:12:20 -070046 CONNECT,
47 DISCONNECT,
Jesse Hall399184a2014-03-03 15:42:54 -080048 SET_SIDEBAND_STREAM,
Dan Stoza29a3e902014-06-20 13:13:57 -070049 ALLOCATE_BUFFERS,
Dan Stoza9de72932015-04-16 17:28:43 -070050 ALLOW_ALLOCATION,
Dan Stoza812ed062015-06-02 15:45:22 -070051 SET_GENERATION_NUMBER,
Dan Stozac6f30bd2015-06-08 09:32:50 -070052 GET_CONSUMER_NAME,
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
86 virtual status_t setBufferCount(int bufferCount)
87 {
88 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080089 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080090 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070091 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
92 if (result != NO_ERROR) {
93 return result;
94 }
95 result = reply.readInt32();
96 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080097 }
98
Mathias Agopian7cdd7862013-07-18 22:10:56 -070099 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800100 uint32_t width, uint32_t height, PixelFormat format,
101 uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800102 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800103 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800104 data.writeInt32(static_cast<int32_t>(async));
105 data.writeUint32(width);
106 data.writeUint32(height);
107 data.writeInt32(static_cast<int32_t>(format));
108 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700109 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
110 if (result != NO_ERROR) {
111 return result;
112 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800113 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700114 bool nonNull = reply.readInt32();
115 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700116 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700117 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700118 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700119 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800120 return result;
121 }
122
Dan Stoza9f3053d2014-03-06 15:14:33 -0800123 virtual status_t detachBuffer(int slot) {
124 Parcel data, reply;
125 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
126 data.writeInt32(slot);
127 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
128 if (result != NO_ERROR) {
129 return result;
130 }
131 result = reply.readInt32();
132 return result;
133 }
134
Dan Stozad9822a32014-03-28 15:25:31 -0700135 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
136 sp<Fence>* outFence) {
137 if (outBuffer == NULL) {
138 ALOGE("detachNextBuffer: outBuffer must not be NULL");
139 return BAD_VALUE;
140 } else if (outFence == NULL) {
141 ALOGE("detachNextBuffer: outFence must not be NULL");
142 return BAD_VALUE;
143 }
144 Parcel data, reply;
145 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
146 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
147 if (result != NO_ERROR) {
148 return result;
149 }
150 result = reply.readInt32();
151 if (result == NO_ERROR) {
152 bool nonNull = reply.readInt32();
153 if (nonNull) {
154 *outBuffer = new GraphicBuffer;
155 reply.read(**outBuffer);
156 }
157 nonNull = reply.readInt32();
158 if (nonNull) {
159 *outFence = new Fence;
160 reply.read(**outFence);
161 }
162 }
163 return result;
164 }
165
Dan Stoza9f3053d2014-03-06 15:14:33 -0800166 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
167 Parcel data, reply;
168 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
169 data.write(*buffer.get());
170 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
171 if (result != NO_ERROR) {
172 return result;
173 }
Chia-I Wu734ce0a2017-05-15 10:32:27 -0700174
Dan Stoza9f3053d2014-03-06 15:14:33 -0800175 *slot = reply.readInt32();
176 result = reply.readInt32();
Chia-I Wu734ce0a2017-05-15 10:32:27 -0700177 if (result == NO_ERROR &&
178 (*slot < 0 || *slot >= BufferQueueDefs::NUM_BUFFER_SLOTS)) {
179 ALOGE("attachBuffer returned invalid slot %d", *slot);
180 android_errorWriteLog(0x534e4554, "37478824");
181 return UNKNOWN_ERROR;
182 }
183
Dan Stoza9f3053d2014-03-06 15:14:33 -0800184 return result;
185 }
186
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700187 virtual status_t queueBuffer(int buf,
188 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800189 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800190 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800191 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700192 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700193 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
194 if (result != NO_ERROR) {
195 return result;
196 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700197 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700198 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800199 return result;
200 }
201
Jesse Hall4c00cc12013-03-15 21:34:30 -0700202 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800203 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800204 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800205 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800206 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800207 remote()->transact(CANCEL_BUFFER, data, &reply);
208 }
209
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700210 virtual int query(int what, int* value) {
211 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800212 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700213 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700214 status_t result = remote()->transact(QUERY, data, &reply);
215 if (result != NO_ERROR) {
216 return result;
217 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700218 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700219 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700220 return result;
221 }
222
Dan Stozaf0eaf252014-03-21 13:05:51 -0700223 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700224 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700225 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800226 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700227 if (listener != NULL) {
228 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800229 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700230 } else {
231 data.writeInt32(0);
232 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700233 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700234 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700235 status_t result = remote()->transact(CONNECT, data, &reply);
236 if (result != NO_ERROR) {
237 return result;
238 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700239 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700240 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700241 return result;
242 }
Mathias Agopian80727112011-05-02 19:51:12 -0700243
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700244 virtual status_t disconnect(int api) {
245 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800246 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700247 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700248 status_t result =remote()->transact(DISCONNECT, data, &reply);
249 if (result != NO_ERROR) {
250 return result;
251 }
252 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700253 return result;
254 }
Jesse Hall399184a2014-03-03 15:42:54 -0800255
256 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
257 Parcel data, reply;
258 status_t result;
259 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
260 if (stream.get()) {
261 data.writeInt32(true);
262 data.writeNativeHandle(stream->handle());
263 } else {
264 data.writeInt32(false);
265 }
266 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
267 result = reply.readInt32();
268 }
269 return result;
270 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700271
272 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800273 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700274 Parcel data, reply;
275 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
276 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800277 data.writeUint32(width);
278 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700279 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800280 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700281 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
282 if (result != NO_ERROR) {
283 ALOGE("allocateBuffers failed to transact: %d", result);
284 }
285 }
Dan Stoza9de72932015-04-16 17:28:43 -0700286
287 virtual status_t allowAllocation(bool allow) {
288 Parcel data, reply;
289 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
290 data.writeInt32(static_cast<int32_t>(allow));
291 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
292 if (result != NO_ERROR) {
293 return result;
294 }
295 result = reply.readInt32();
296 return result;
297 }
Dan Stoza812ed062015-06-02 15:45:22 -0700298
299 virtual status_t setGenerationNumber(uint32_t generationNumber) {
300 Parcel data, reply;
301 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
302 data.writeUint32(generationNumber);
303 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
304 if (result == NO_ERROR) {
305 result = reply.readInt32();
306 }
307 return result;
308 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700309
310 virtual String8 getConsumerName() const {
311 Parcel data, reply;
312 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
313 status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
314 if (result != NO_ERROR) {
315 ALOGE("getConsumerName failed to transact: %d", result);
316 return String8("TransactFailed");
317 }
318 return reply.readString8();
319 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800320};
321
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800322// Out-of-line virtual method definition to trigger vtable emission in this
323// translation unit (see clang warning -Wweak-vtables)
324BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
325
Andy McFadden466a1922013-01-08 11:25:51 -0800326IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800327
328// ----------------------------------------------------------------------
329
Andy McFadden2adaf042012-12-18 09:49:45 -0800330status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800331 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
332{
333 switch(code) {
334 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800335 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800336 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700337 sp<GraphicBuffer> buffer;
338 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800339 reply->writeInt32(buffer != 0);
340 if (buffer != 0) {
341 reply->write(*buffer);
342 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700343 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800344 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800345 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800346 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800347 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800348 int bufferCount = data.readInt32();
349 int result = setBufferCount(bufferCount);
350 reply->writeInt32(result);
351 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800352 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800353 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800354 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800355 bool async = static_cast<bool>(data.readInt32());
356 uint32_t width = data.readUint32();
357 uint32_t height = data.readUint32();
358 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
359 uint32_t usage = data.readUint32();
Naveen Leekhac4bd7212015-09-24 15:55:21 -0700360 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700361 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800362 int result = dequeueBuffer(&buf, &fence, async, width, height,
363 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800364 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800365 reply->writeInt32(fence != NULL);
366 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700367 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700368 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800369 reply->writeInt32(result);
370 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800371 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800372 case DETACH_BUFFER: {
373 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
374 int slot = data.readInt32();
375 int result = detachBuffer(slot);
376 reply->writeInt32(result);
377 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800378 }
Dan Stozad9822a32014-03-28 15:25:31 -0700379 case DETACH_NEXT_BUFFER: {
380 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
381 sp<GraphicBuffer> buffer;
382 sp<Fence> fence;
383 int32_t result = detachNextBuffer(&buffer, &fence);
384 reply->writeInt32(result);
385 if (result == NO_ERROR) {
386 reply->writeInt32(buffer != NULL);
387 if (buffer != NULL) {
388 reply->write(*buffer);
389 }
390 reply->writeInt32(fence != NULL);
391 if (fence != NULL) {
392 reply->write(*fence);
393 }
394 }
395 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800396 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800397 case ATTACH_BUFFER: {
398 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
399 sp<GraphicBuffer> buffer = new GraphicBuffer();
400 data.read(*buffer.get());
Naveen Leekhab4142552015-09-22 18:04:44 -0700401 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800402 int result = attachBuffer(&slot, buffer);
403 reply->writeInt32(slot);
404 reply->writeInt32(result);
405 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800406 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800407 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800408 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800409 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700410 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700411 QueueBufferOutput* const output =
412 reinterpret_cast<QueueBufferOutput *>(
413 reply->writeInplace(sizeof(QueueBufferOutput)));
Robert Shih88ae9602016-01-11 15:02:12 -0800414 memset(output, 0, sizeof(QueueBufferOutput));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700415 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800416 reply->writeInt32(result);
417 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800418 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800419 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800420 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800421 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800422 sp<Fence> fence = new Fence();
423 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700424 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800425 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800426 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700427 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800428 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekhac4bd7212015-09-24 15:55:21 -0700429 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700430 int what = data.readInt32();
431 int res = query(what, &value);
432 reply->writeInt32(value);
433 reply->writeInt32(res);
434 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800435 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700436 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800437 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700438 sp<IProducerListener> listener;
439 if (data.readInt32() == 1) {
440 listener = IProducerListener::asInterface(data.readStrongBinder());
441 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700442 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700443 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700444 QueueBufferOutput* const output =
445 reinterpret_cast<QueueBufferOutput *>(
446 reply->writeInplace(sizeof(QueueBufferOutput)));
Pablo Ceballos2d78c182016-03-15 18:10:49 -0700447 memset(output, 0, sizeof(QueueBufferOutput));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700448 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700449 reply->writeInt32(res);
450 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800451 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700452 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800453 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700454 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700455 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700456 reply->writeInt32(res);
457 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800458 }
Jesse Hall399184a2014-03-03 15:42:54 -0800459 case SET_SIDEBAND_STREAM: {
460 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
461 sp<NativeHandle> stream;
462 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900463 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800464 }
465 status_t result = setSidebandStream(stream);
466 reply->writeInt32(result);
467 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800468 }
Dan Stoza9de72932015-04-16 17:28:43 -0700469 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700470 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
471 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800472 uint32_t width = data.readUint32();
473 uint32_t height = data.readUint32();
474 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
475 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700476 allocateBuffers(async, width, height, format, usage);
477 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700478 }
479 case ALLOW_ALLOCATION: {
480 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
481 bool allow = static_cast<bool>(data.readInt32());
482 status_t result = allowAllocation(allow);
483 reply->writeInt32(result);
484 return NO_ERROR;
485 }
Dan Stoza812ed062015-06-02 15:45:22 -0700486 case SET_GENERATION_NUMBER: {
487 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
488 uint32_t generationNumber = data.readUint32();
489 status_t result = setGenerationNumber(generationNumber);
490 reply->writeInt32(result);
491 return NO_ERROR;
492 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700493 case GET_CONSUMER_NAME: {
494 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
495 reply->writeString8(getConsumerName());
496 return NO_ERROR;
497 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800498 }
499 return BBinder::onTransact(code, data, reply, flags);
500}
501
502// ----------------------------------------------------------------------------
503
Andy McFadden2adaf042012-12-18 09:49:45 -0800504IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700505 parcel.read(*this);
506}
507
Mathias Agopiane1424282013-07-29 21:24:40 -0700508size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700509 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700510 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800511 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700512 + sizeof(crop)
513 + sizeof(scalingMode)
514 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700515 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700516 + sizeof(async)
Dan Stoza5065a552015-03-17 16:23:42 -0700517 + fence->getFlattenedSize()
518 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700519}
520
Mathias Agopiane1424282013-07-29 21:24:40 -0700521size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800522 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700523}
524
Mathias Agopiane1424282013-07-29 21:24:40 -0700525status_t IGraphicBufferProducer::QueueBufferInput::flatten(
526 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700527{
Mathias Agopiane1424282013-07-29 21:24:40 -0700528 if (size < getFlattenedSize()) {
529 return NO_MEMORY;
530 }
531 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700532 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800533 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700534 FlattenableUtils::write(buffer, size, crop);
535 FlattenableUtils::write(buffer, size, scalingMode);
536 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700537 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700538 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700539 status_t result = fence->flatten(buffer, size, fds, count);
540 if (result != NO_ERROR) {
541 return result;
542 }
543 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700544}
545
Mathias Agopiane1424282013-07-29 21:24:40 -0700546status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
547 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700548{
Mathias Agopiane1424282013-07-29 21:24:40 -0700549 size_t minNeeded =
550 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700551 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800552 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700553 + sizeof(crop)
554 + sizeof(scalingMode)
555 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700556 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700557 + sizeof(async);
558
559 if (size < minNeeded) {
560 return NO_MEMORY;
561 }
562
563 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700564 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800565 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700566 FlattenableUtils::read(buffer, size, crop);
567 FlattenableUtils::read(buffer, size, scalingMode);
568 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700569 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700570 FlattenableUtils::read(buffer, size, async);
571
Jamie Gennis1df8c342012-12-20 14:05:45 -0800572 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700573 status_t result = fence->unflatten(buffer, size, fds, count);
574 if (result != NO_ERROR) {
575 return result;
576 }
577 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700578}
579
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800580}; // namespace android