blob: 8bdbc22ec96a5a8591f2c3619a82d96b52d509a5 [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,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080052};
53
Andy McFadden2adaf042012-12-18 09:49:45 -080054class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080055{
56public:
Andy McFadden2adaf042012-12-18 09:49:45 -080057 BpGraphicBufferProducer(const sp<IBinder>& impl)
58 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080059 {
60 }
61
Dan Stoza3be1c6b2014-11-18 10:24:03 -080062 virtual ~BpGraphicBufferProducer();
63
Jamie Gennis7b305ff2011-07-19 12:08:33 -070064 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080065 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080066 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080067 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070068 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
69 if (result != NO_ERROR) {
70 return result;
71 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080072 bool nonNull = reply.readInt32();
73 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070074 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080075 result = reply.read(**buf);
76 if(result != NO_ERROR) {
77 (*buf).clear();
78 return result;
79 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080080 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070081 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070082 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080083 }
84
85 virtual status_t setBufferCount(int bufferCount)
86 {
87 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080088 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080089 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070090 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
91 if (result != NO_ERROR) {
92 return result;
93 }
94 result = reply.readInt32();
95 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080096 }
97
Mathias Agopian7cdd7862013-07-18 22:10:56 -070098 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -080099 uint32_t width, uint32_t height, PixelFormat format,
100 uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800101 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800102 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800103 data.writeInt32(static_cast<int32_t>(async));
104 data.writeUint32(width);
105 data.writeUint32(height);
106 data.writeInt32(static_cast<int32_t>(format));
107 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700108 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
109 if (result != NO_ERROR) {
110 return result;
111 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800112 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700113 bool nonNull = reply.readInt32();
114 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700115 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700116 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700117 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700118 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800119 return result;
120 }
121
Dan Stoza9f3053d2014-03-06 15:14:33 -0800122 virtual status_t detachBuffer(int slot) {
123 Parcel data, reply;
124 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
125 data.writeInt32(slot);
126 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
127 if (result != NO_ERROR) {
128 return result;
129 }
130 result = reply.readInt32();
131 return result;
132 }
133
Dan Stozad9822a32014-03-28 15:25:31 -0700134 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
135 sp<Fence>* outFence) {
136 if (outBuffer == NULL) {
137 ALOGE("detachNextBuffer: outBuffer must not be NULL");
138 return BAD_VALUE;
139 } else if (outFence == NULL) {
140 ALOGE("detachNextBuffer: outFence must not be NULL");
141 return BAD_VALUE;
142 }
143 Parcel data, reply;
144 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
145 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
146 if (result != NO_ERROR) {
147 return result;
148 }
149 result = reply.readInt32();
150 if (result == NO_ERROR) {
151 bool nonNull = reply.readInt32();
152 if (nonNull) {
153 *outBuffer = new GraphicBuffer;
154 reply.read(**outBuffer);
155 }
156 nonNull = reply.readInt32();
157 if (nonNull) {
158 *outFence = new Fence;
159 reply.read(**outFence);
160 }
161 }
162 return result;
163 }
164
Dan Stoza9f3053d2014-03-06 15:14:33 -0800165 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
166 Parcel data, reply;
167 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
168 data.write(*buffer.get());
169 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
170 if (result != NO_ERROR) {
171 return result;
172 }
173 *slot = reply.readInt32();
174 result = reply.readInt32();
175 return result;
176 }
177
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700178 virtual status_t queueBuffer(int buf,
179 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800180 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800181 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800182 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700183 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700184 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
185 if (result != NO_ERROR) {
186 return result;
187 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700188 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700189 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800190 return result;
191 }
192
Jesse Hall4c00cc12013-03-15 21:34:30 -0700193 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800194 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800195 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800196 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800197 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800198 remote()->transact(CANCEL_BUFFER, data, &reply);
199 }
200
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700201 virtual int query(int what, int* value) {
202 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800203 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700204 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700205 status_t result = remote()->transact(QUERY, data, &reply);
206 if (result != NO_ERROR) {
207 return result;
208 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700209 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700210 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700211 return result;
212 }
213
Dan Stozaf0eaf252014-03-21 13:05:51 -0700214 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700215 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700216 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800217 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700218 if (listener != NULL) {
219 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800220 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700221 } else {
222 data.writeInt32(0);
223 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700224 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700225 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700226 status_t result = remote()->transact(CONNECT, data, &reply);
227 if (result != NO_ERROR) {
228 return result;
229 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700230 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700231 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700232 return result;
233 }
Mathias Agopian80727112011-05-02 19:51:12 -0700234
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700235 virtual status_t disconnect(int api) {
236 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800237 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700238 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700239 status_t result =remote()->transact(DISCONNECT, data, &reply);
240 if (result != NO_ERROR) {
241 return result;
242 }
243 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700244 return result;
245 }
Jesse Hall399184a2014-03-03 15:42:54 -0800246
247 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
248 Parcel data, reply;
249 status_t result;
250 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
251 if (stream.get()) {
252 data.writeInt32(true);
253 data.writeNativeHandle(stream->handle());
254 } else {
255 data.writeInt32(false);
256 }
257 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
258 result = reply.readInt32();
259 }
260 return result;
261 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700262
263 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800264 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700265 Parcel data, reply;
266 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
267 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800268 data.writeUint32(width);
269 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700270 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800271 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700272 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
273 if (result != NO_ERROR) {
274 ALOGE("allocateBuffers failed to transact: %d", result);
275 }
276 }
Dan Stoza9de72932015-04-16 17:28:43 -0700277
278 virtual status_t allowAllocation(bool allow) {
279 Parcel data, reply;
280 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
281 data.writeInt32(static_cast<int32_t>(allow));
282 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
283 if (result != NO_ERROR) {
284 return result;
285 }
286 result = reply.readInt32();
287 return result;
288 }
Dan Stoza812ed062015-06-02 15:45:22 -0700289
290 virtual status_t setGenerationNumber(uint32_t generationNumber) {
291 Parcel data, reply;
292 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
293 data.writeUint32(generationNumber);
294 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
295 if (result == NO_ERROR) {
296 result = reply.readInt32();
297 }
298 return result;
299 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700300
301 virtual String8 getConsumerName() const {
302 Parcel data, reply;
303 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
304 status_t result = remote()->transact(GET_CONSUMER_NAME, data, &reply);
305 if (result != NO_ERROR) {
306 ALOGE("getConsumerName failed to transact: %d", result);
307 return String8("TransactFailed");
308 }
309 return reply.readString8();
310 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800311};
312
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800313// Out-of-line virtual method definition to trigger vtable emission in this
314// translation unit (see clang warning -Wweak-vtables)
315BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
316
Andy McFadden466a1922013-01-08 11:25:51 -0800317IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800318
319// ----------------------------------------------------------------------
320
Andy McFadden2adaf042012-12-18 09:49:45 -0800321status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800322 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
323{
324 switch(code) {
325 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800326 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800327 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700328 sp<GraphicBuffer> buffer;
329 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800330 reply->writeInt32(buffer != 0);
331 if (buffer != 0) {
332 reply->write(*buffer);
333 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700334 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800335 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800336 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800337 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800338 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800339 int bufferCount = data.readInt32();
340 int result = setBufferCount(bufferCount);
341 reply->writeInt32(result);
342 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800343 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800344 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800345 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800346 bool async = static_cast<bool>(data.readInt32());
347 uint32_t width = data.readUint32();
348 uint32_t height = data.readUint32();
349 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
350 uint32_t usage = data.readUint32();
Naveen Leekhac4bd7212015-09-24 15:55:21 -0700351 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700352 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800353 int result = dequeueBuffer(&buf, &fence, async, width, height,
354 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800355 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800356 reply->writeInt32(fence != NULL);
357 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700358 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700359 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800360 reply->writeInt32(result);
361 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800362 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800363 case DETACH_BUFFER: {
364 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
365 int slot = data.readInt32();
366 int result = detachBuffer(slot);
367 reply->writeInt32(result);
368 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800369 }
Dan Stozad9822a32014-03-28 15:25:31 -0700370 case DETACH_NEXT_BUFFER: {
371 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
372 sp<GraphicBuffer> buffer;
373 sp<Fence> fence;
374 int32_t result = detachNextBuffer(&buffer, &fence);
375 reply->writeInt32(result);
376 if (result == NO_ERROR) {
377 reply->writeInt32(buffer != NULL);
378 if (buffer != NULL) {
379 reply->write(*buffer);
380 }
381 reply->writeInt32(fence != NULL);
382 if (fence != NULL) {
383 reply->write(*fence);
384 }
385 }
386 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800387 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800388 case ATTACH_BUFFER: {
389 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
390 sp<GraphicBuffer> buffer = new GraphicBuffer();
391 data.read(*buffer.get());
Naveen Leekhab4142552015-09-22 18:04:44 -0700392 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800393 int result = attachBuffer(&slot, buffer);
394 reply->writeInt32(slot);
395 reply->writeInt32(result);
396 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800397 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800398 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800399 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800400 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700401 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700402 QueueBufferOutput* const output =
403 reinterpret_cast<QueueBufferOutput *>(
404 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700405 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800406 reply->writeInt32(result);
407 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800408 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800409 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800410 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800411 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800412 sp<Fence> fence = new Fence();
413 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700414 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800415 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800416 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700417 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800418 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekhac4bd7212015-09-24 15:55:21 -0700419 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700420 int what = data.readInt32();
421 int res = query(what, &value);
422 reply->writeInt32(value);
423 reply->writeInt32(res);
424 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800425 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700426 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800427 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700428 sp<IProducerListener> listener;
429 if (data.readInt32() == 1) {
430 listener = IProducerListener::asInterface(data.readStrongBinder());
431 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700432 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700433 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700434 QueueBufferOutput* const output =
435 reinterpret_cast<QueueBufferOutput *>(
436 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700437 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700438 reply->writeInt32(res);
439 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800440 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700441 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800442 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700443 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700444 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700445 reply->writeInt32(res);
446 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800447 }
Jesse Hall399184a2014-03-03 15:42:54 -0800448 case SET_SIDEBAND_STREAM: {
449 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
450 sp<NativeHandle> stream;
451 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900452 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800453 }
454 status_t result = setSidebandStream(stream);
455 reply->writeInt32(result);
456 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800457 }
Dan Stoza9de72932015-04-16 17:28:43 -0700458 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700459 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
460 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800461 uint32_t width = data.readUint32();
462 uint32_t height = data.readUint32();
463 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
464 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700465 allocateBuffers(async, width, height, format, usage);
466 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700467 }
468 case ALLOW_ALLOCATION: {
469 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
470 bool allow = static_cast<bool>(data.readInt32());
471 status_t result = allowAllocation(allow);
472 reply->writeInt32(result);
473 return NO_ERROR;
474 }
Dan Stoza812ed062015-06-02 15:45:22 -0700475 case SET_GENERATION_NUMBER: {
476 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
477 uint32_t generationNumber = data.readUint32();
478 status_t result = setGenerationNumber(generationNumber);
479 reply->writeInt32(result);
480 return NO_ERROR;
481 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700482 case GET_CONSUMER_NAME: {
483 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
484 reply->writeString8(getConsumerName());
485 return NO_ERROR;
486 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800487 }
488 return BBinder::onTransact(code, data, reply, flags);
489}
490
491// ----------------------------------------------------------------------------
492
Andy McFadden2adaf042012-12-18 09:49:45 -0800493IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700494 parcel.read(*this);
495}
496
Mathias Agopiane1424282013-07-29 21:24:40 -0700497size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700498 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700499 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800500 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700501 + sizeof(crop)
502 + sizeof(scalingMode)
503 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700504 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700505 + sizeof(async)
Dan Stoza5065a552015-03-17 16:23:42 -0700506 + fence->getFlattenedSize()
507 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700508}
509
Mathias Agopiane1424282013-07-29 21:24:40 -0700510size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800511 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700512}
513
Mathias Agopiane1424282013-07-29 21:24:40 -0700514status_t IGraphicBufferProducer::QueueBufferInput::flatten(
515 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700516{
Mathias Agopiane1424282013-07-29 21:24:40 -0700517 if (size < getFlattenedSize()) {
518 return NO_MEMORY;
519 }
520 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700521 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800522 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700523 FlattenableUtils::write(buffer, size, crop);
524 FlattenableUtils::write(buffer, size, scalingMode);
525 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700526 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700527 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700528 status_t result = fence->flatten(buffer, size, fds, count);
529 if (result != NO_ERROR) {
530 return result;
531 }
532 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700533}
534
Mathias Agopiane1424282013-07-29 21:24:40 -0700535status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
536 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700537{
Mathias Agopiane1424282013-07-29 21:24:40 -0700538 size_t minNeeded =
539 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700540 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800541 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700542 + sizeof(crop)
543 + sizeof(scalingMode)
544 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700545 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700546 + sizeof(async);
547
548 if (size < minNeeded) {
549 return NO_MEMORY;
550 }
551
552 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700553 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800554 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700555 FlattenableUtils::read(buffer, size, crop);
556 FlattenableUtils::read(buffer, size, scalingMode);
557 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700558 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700559 FlattenableUtils::read(buffer, size, async);
560
Jamie Gennis1df8c342012-12-20 14:05:45 -0800561 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700562 status_t result = fence->unflatten(buffer, size, fds, count);
563 if (result != NO_ERROR) {
564 return result;
565 }
566 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700567}
568
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800569}; // namespace android