blob: e91a8e1ae6de0edada7db040a8a646c6e92f32ea [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:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070057 explicit BpGraphicBufferProducer(const sp<IBinder>& impl)
Andy McFadden2adaf042012-12-18 09:49:45 -080058 : 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)));
Robert Shihd06421f2016-01-11 15:02:12 -0800405 memset(output, 0, sizeof(QueueBufferOutput));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700406 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800407 reply->writeInt32(result);
408 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800409 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800410 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800411 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800412 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800413 sp<Fence> fence = new Fence();
414 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700415 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800416 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800417 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700418 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800419 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekhac4bd7212015-09-24 15:55:21 -0700420 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700421 int what = data.readInt32();
422 int res = query(what, &value);
423 reply->writeInt32(value);
424 reply->writeInt32(res);
425 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800426 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700427 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800428 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700429 sp<IProducerListener> listener;
430 if (data.readInt32() == 1) {
431 listener = IProducerListener::asInterface(data.readStrongBinder());
432 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700433 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700434 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700435 QueueBufferOutput* const output =
436 reinterpret_cast<QueueBufferOutput *>(
437 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700438 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700439 reply->writeInt32(res);
440 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800441 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700442 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800443 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700444 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700445 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700446 reply->writeInt32(res);
447 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800448 }
Jesse Hall399184a2014-03-03 15:42:54 -0800449 case SET_SIDEBAND_STREAM: {
450 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
451 sp<NativeHandle> stream;
452 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900453 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800454 }
455 status_t result = setSidebandStream(stream);
456 reply->writeInt32(result);
457 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800458 }
Dan Stoza9de72932015-04-16 17:28:43 -0700459 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700460 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
461 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800462 uint32_t width = data.readUint32();
463 uint32_t height = data.readUint32();
464 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
465 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700466 allocateBuffers(async, width, height, format, usage);
467 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700468 }
469 case ALLOW_ALLOCATION: {
470 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
471 bool allow = static_cast<bool>(data.readInt32());
472 status_t result = allowAllocation(allow);
473 reply->writeInt32(result);
474 return NO_ERROR;
475 }
Dan Stoza812ed062015-06-02 15:45:22 -0700476 case SET_GENERATION_NUMBER: {
477 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
478 uint32_t generationNumber = data.readUint32();
479 status_t result = setGenerationNumber(generationNumber);
480 reply->writeInt32(result);
481 return NO_ERROR;
482 }
Dan Stozac6f30bd2015-06-08 09:32:50 -0700483 case GET_CONSUMER_NAME: {
484 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
485 reply->writeString8(getConsumerName());
486 return NO_ERROR;
487 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800488 }
489 return BBinder::onTransact(code, data, reply, flags);
490}
491
492// ----------------------------------------------------------------------------
493
Andy McFadden2adaf042012-12-18 09:49:45 -0800494IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700495 parcel.read(*this);
496}
497
Mathias Agopiane1424282013-07-29 21:24:40 -0700498size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700499 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700500 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800501 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700502 + sizeof(crop)
503 + sizeof(scalingMode)
504 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700505 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700506 + sizeof(async)
Dan Stoza5065a552015-03-17 16:23:42 -0700507 + fence->getFlattenedSize()
508 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700509}
510
Mathias Agopiane1424282013-07-29 21:24:40 -0700511size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800512 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700513}
514
Mathias Agopiane1424282013-07-29 21:24:40 -0700515status_t IGraphicBufferProducer::QueueBufferInput::flatten(
516 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700517{
Mathias Agopiane1424282013-07-29 21:24:40 -0700518 if (size < getFlattenedSize()) {
519 return NO_MEMORY;
520 }
521 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700522 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800523 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700524 FlattenableUtils::write(buffer, size, crop);
525 FlattenableUtils::write(buffer, size, scalingMode);
526 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700527 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700528 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700529 status_t result = fence->flatten(buffer, size, fds, count);
530 if (result != NO_ERROR) {
531 return result;
532 }
533 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700534}
535
Mathias Agopiane1424282013-07-29 21:24:40 -0700536status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
537 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700538{
Mathias Agopiane1424282013-07-29 21:24:40 -0700539 size_t minNeeded =
540 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700541 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800542 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700543 + sizeof(crop)
544 + sizeof(scalingMode)
545 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700546 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700547 + sizeof(async);
548
549 if (size < minNeeded) {
550 return NO_MEMORY;
551 }
552
553 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700554 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800555 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700556 FlattenableUtils::read(buffer, size, crop);
557 FlattenableUtils::read(buffer, size, scalingMode);
558 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700559 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700560 FlattenableUtils::read(buffer, size, async);
561
Jamie Gennis1df8c342012-12-20 14:05:45 -0800562 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700563 status_t result = fence->unflatten(buffer, size, fds, count);
564 if (result != NO_ERROR) {
565 return result;
566 }
567 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700568}
569
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800570}; // namespace android