blob: cbfbc470212f69bd32ba5c5e8ef726249d5f1ed1 [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,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080049};
50
Andy McFadden2adaf042012-12-18 09:49:45 -080051class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080052{
53public:
Andy McFadden2adaf042012-12-18 09:49:45 -080054 BpGraphicBufferProducer(const sp<IBinder>& impl)
55 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080056 {
57 }
58
Jamie Gennis7b305ff2011-07-19 12:08:33 -070059 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080060 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080061 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080062 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070063 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
64 if (result != NO_ERROR) {
65 return result;
66 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080067 bool nonNull = reply.readInt32();
68 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070069 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080070 result = reply.read(**buf);
71 if(result != NO_ERROR) {
72 (*buf).clear();
73 return result;
74 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080075 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070076 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070077 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080078 }
79
80 virtual status_t setBufferCount(int bufferCount)
81 {
82 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080083 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080084 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070085 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
86 if (result != NO_ERROR) {
87 return result;
88 }
89 result = reply.readInt32();
90 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080091 }
92
Mathias Agopian7cdd7862013-07-18 22:10:56 -070093 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Jesse Hallf7857542012-06-14 15:26:33 -070094 uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080095 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080096 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopian7cdd7862013-07-18 22:10:56 -070097 data.writeInt32(async);
Mathias Agopianc04f1532011-04-25 20:22:14 -070098 data.writeInt32(w);
99 data.writeInt32(h);
100 data.writeInt32(format);
101 data.writeInt32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700102 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
103 if (result != NO_ERROR) {
104 return result;
105 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800106 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700107 bool nonNull = reply.readInt32();
108 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700109 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700110 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700111 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700112 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800113 return result;
114 }
115
Dan Stoza9f3053d2014-03-06 15:14:33 -0800116 virtual status_t detachBuffer(int slot) {
117 Parcel data, reply;
118 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
119 data.writeInt32(slot);
120 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
121 if (result != NO_ERROR) {
122 return result;
123 }
124 result = reply.readInt32();
125 return result;
126 }
127
Dan Stozad9822a32014-03-28 15:25:31 -0700128 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
129 sp<Fence>* outFence) {
130 if (outBuffer == NULL) {
131 ALOGE("detachNextBuffer: outBuffer must not be NULL");
132 return BAD_VALUE;
133 } else if (outFence == NULL) {
134 ALOGE("detachNextBuffer: outFence must not be NULL");
135 return BAD_VALUE;
136 }
137 Parcel data, reply;
138 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
139 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
140 if (result != NO_ERROR) {
141 return result;
142 }
143 result = reply.readInt32();
144 if (result == NO_ERROR) {
145 bool nonNull = reply.readInt32();
146 if (nonNull) {
147 *outBuffer = new GraphicBuffer;
148 reply.read(**outBuffer);
149 }
150 nonNull = reply.readInt32();
151 if (nonNull) {
152 *outFence = new Fence;
153 reply.read(**outFence);
154 }
155 }
156 return result;
157 }
158
Dan Stoza9f3053d2014-03-06 15:14:33 -0800159 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
160 Parcel data, reply;
161 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
162 data.write(*buffer.get());
163 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
164 if (result != NO_ERROR) {
165 return result;
166 }
167 *slot = reply.readInt32();
168 result = reply.readInt32();
169 return result;
170 }
171
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700172 virtual status_t queueBuffer(int buf,
173 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800174 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800175 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800176 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700177 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700178 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
179 if (result != NO_ERROR) {
180 return result;
181 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700182 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700183 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800184 return result;
185 }
186
Jesse Hall4c00cc12013-03-15 21:34:30 -0700187 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800188 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800189 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800190 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800191 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800192 remote()->transact(CANCEL_BUFFER, data, &reply);
193 }
194
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700195 virtual int query(int what, int* value) {
196 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800197 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700198 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700199 status_t result = remote()->transact(QUERY, data, &reply);
200 if (result != NO_ERROR) {
201 return result;
202 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700203 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700204 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700205 return result;
206 }
207
Dan Stozaf0eaf252014-03-21 13:05:51 -0700208 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700209 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700210 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800211 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700212 if (listener != NULL) {
213 data.writeInt32(1);
214 data.writeStrongBinder(listener->asBinder());
215 } else {
216 data.writeInt32(0);
217 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700218 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700219 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700220 status_t result = remote()->transact(CONNECT, data, &reply);
221 if (result != NO_ERROR) {
222 return result;
223 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700224 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700225 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700226 return result;
227 }
Mathias Agopian80727112011-05-02 19:51:12 -0700228
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700229 virtual status_t disconnect(int api) {
230 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800231 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700232 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700233 status_t result =remote()->transact(DISCONNECT, data, &reply);
234 if (result != NO_ERROR) {
235 return result;
236 }
237 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700238 return result;
239 }
Jesse Hall399184a2014-03-03 15:42:54 -0800240
241 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
242 Parcel data, reply;
243 status_t result;
244 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
245 if (stream.get()) {
246 data.writeInt32(true);
247 data.writeNativeHandle(stream->handle());
248 } else {
249 data.writeInt32(false);
250 }
251 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
252 result = reply.readInt32();
253 }
254 return result;
255 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700256
257 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
258 uint32_t format, uint32_t usage) {
259 Parcel data, reply;
260 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
261 data.writeInt32(static_cast<int32_t>(async));
262 data.writeInt32(static_cast<int32_t>(width));
263 data.writeInt32(static_cast<int32_t>(height));
264 data.writeInt32(static_cast<int32_t>(format));
265 data.writeInt32(static_cast<int32_t>(usage));
266 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
267 if (result != NO_ERROR) {
268 ALOGE("allocateBuffers failed to transact: %d", result);
269 }
270 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800271};
272
Andy McFadden466a1922013-01-08 11:25:51 -0800273IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800274
275// ----------------------------------------------------------------------
276
Andy McFadden2adaf042012-12-18 09:49:45 -0800277status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800278 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
279{
280 switch(code) {
281 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800282 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800283 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700284 sp<GraphicBuffer> buffer;
285 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800286 reply->writeInt32(buffer != 0);
287 if (buffer != 0) {
288 reply->write(*buffer);
289 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700290 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800291 return NO_ERROR;
292 } break;
293 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800294 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800295 int bufferCount = data.readInt32();
296 int result = setBufferCount(bufferCount);
297 reply->writeInt32(result);
298 return NO_ERROR;
299 } break;
300 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800301 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700302 bool async = data.readInt32();
Mathias Agopianc04f1532011-04-25 20:22:14 -0700303 uint32_t w = data.readInt32();
304 uint32_t h = data.readInt32();
305 uint32_t format = data.readInt32();
306 uint32_t usage = data.readInt32();
Naveen Leekha9528f382015-09-22 17:58:21 -0700307 int buf = 0;
Jesse Hallf7857542012-06-14 15:26:33 -0700308 sp<Fence> fence;
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700309 int result = dequeueBuffer(&buf, &fence, async, w, h, format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800310 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800311 reply->writeInt32(fence != NULL);
312 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700313 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700314 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800315 reply->writeInt32(result);
316 return NO_ERROR;
317 } break;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800318 case DETACH_BUFFER: {
319 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
320 int slot = data.readInt32();
321 int result = detachBuffer(slot);
322 reply->writeInt32(result);
323 return NO_ERROR;
324 } break;
Dan Stozad9822a32014-03-28 15:25:31 -0700325 case DETACH_NEXT_BUFFER: {
326 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
327 sp<GraphicBuffer> buffer;
328 sp<Fence> fence;
329 int32_t result = detachNextBuffer(&buffer, &fence);
330 reply->writeInt32(result);
331 if (result == NO_ERROR) {
332 reply->writeInt32(buffer != NULL);
333 if (buffer != NULL) {
334 reply->write(*buffer);
335 }
336 reply->writeInt32(fence != NULL);
337 if (fence != NULL) {
338 reply->write(*fence);
339 }
340 }
341 return NO_ERROR;
342 } break;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800343 case ATTACH_BUFFER: {
344 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
345 sp<GraphicBuffer> buffer = new GraphicBuffer();
346 data.read(*buffer.get());
Naveen Leekha2a7221b2015-09-22 18:04:44 -0700347 int slot = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800348 int result = attachBuffer(&slot, buffer);
349 reply->writeInt32(slot);
350 reply->writeInt32(result);
351 return NO_ERROR;
352 } break;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800353 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800354 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800355 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700356 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700357 QueueBufferOutput* const output =
358 reinterpret_cast<QueueBufferOutput *>(
359 reply->writeInplace(sizeof(QueueBufferOutput)));
Robert Shih231133b2016-01-11 15:02:12 -0800360 memset(output, 0, sizeof(QueueBufferOutput));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700361 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800362 reply->writeInt32(result);
363 return NO_ERROR;
364 } break;
365 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800366 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800367 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800368 sp<Fence> fence = new Fence();
369 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700370 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800371 return NO_ERROR;
372 } break;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700373 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800374 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Naveen Leekha9528f382015-09-22 17:58:21 -0700375 int value = 0;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700376 int what = data.readInt32();
377 int res = query(what, &value);
378 reply->writeInt32(value);
379 reply->writeInt32(res);
380 return NO_ERROR;
381 } break;
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700382 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800383 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700384 sp<IProducerListener> listener;
385 if (data.readInt32() == 1) {
386 listener = IProducerListener::asInterface(data.readStrongBinder());
387 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700388 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700389 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700390 QueueBufferOutput* const output =
391 reinterpret_cast<QueueBufferOutput *>(
392 reply->writeInplace(sizeof(QueueBufferOutput)));
Pablo Ceballos22ca44d2016-03-15 18:10:49 -0700393 memset(output, 0, sizeof(QueueBufferOutput));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700394 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700395 reply->writeInt32(res);
396 return NO_ERROR;
397 } break;
398 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800399 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700400 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700401 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700402 reply->writeInt32(res);
403 return NO_ERROR;
404 } break;
Jesse Hall399184a2014-03-03 15:42:54 -0800405 case SET_SIDEBAND_STREAM: {
406 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
407 sp<NativeHandle> stream;
408 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900409 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800410 }
411 status_t result = setSidebandStream(stream);
412 reply->writeInt32(result);
413 return NO_ERROR;
414 } break;
Dan Stoza29a3e902014-06-20 13:13:57 -0700415 case ALLOCATE_BUFFERS:
416 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
417 bool async = static_cast<bool>(data.readInt32());
418 uint32_t width = static_cast<uint32_t>(data.readInt32());
419 uint32_t height = static_cast<uint32_t>(data.readInt32());
420 uint32_t format = static_cast<uint32_t>(data.readInt32());
421 uint32_t usage = static_cast<uint32_t>(data.readInt32());
422 allocateBuffers(async, width, height, format, usage);
423 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800424 }
425 return BBinder::onTransact(code, data, reply, flags);
426}
427
428// ----------------------------------------------------------------------------
429
Andy McFadden2adaf042012-12-18 09:49:45 -0800430IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700431 parcel.read(*this);
432}
433
Mathias Agopiane1424282013-07-29 21:24:40 -0700434size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700435 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700436 + sizeof(isAutoTimestamp)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700437 + sizeof(crop)
Jeykumar Sankaranfa507ff2014-02-12 16:08:19 -0800438 + sizeof(dirtyRect)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700439 + sizeof(scalingMode)
440 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700441 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700442 + sizeof(async)
Jamie Gennis1df8c342012-12-20 14:05:45 -0800443 + fence->getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700444}
445
Mathias Agopiane1424282013-07-29 21:24:40 -0700446size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800447 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700448}
449
Mathias Agopiane1424282013-07-29 21:24:40 -0700450status_t IGraphicBufferProducer::QueueBufferInput::flatten(
451 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700452{
Mathias Agopiane1424282013-07-29 21:24:40 -0700453 if (size < getFlattenedSize()) {
454 return NO_MEMORY;
455 }
456 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700457 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700458 FlattenableUtils::write(buffer, size, crop);
Jeykumar Sankaranfa507ff2014-02-12 16:08:19 -0800459 FlattenableUtils::write(buffer, size, dirtyRect);
Mathias Agopiane1424282013-07-29 21:24:40 -0700460 FlattenableUtils::write(buffer, size, scalingMode);
461 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700462 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700463 FlattenableUtils::write(buffer, size, async);
464 return fence->flatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700465}
466
Mathias Agopiane1424282013-07-29 21:24:40 -0700467status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
468 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700469{
Mathias Agopiane1424282013-07-29 21:24:40 -0700470 size_t minNeeded =
471 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700472 + sizeof(isAutoTimestamp)
Mathias Agopiane1424282013-07-29 21:24:40 -0700473 + sizeof(crop)
Jeykumar Sankaranfa507ff2014-02-12 16:08:19 -0800474 + sizeof(dirtyRect)
Mathias Agopiane1424282013-07-29 21:24:40 -0700475 + sizeof(scalingMode)
476 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700477 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700478 + sizeof(async);
479
480 if (size < minNeeded) {
481 return NO_MEMORY;
482 }
483
484 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700485 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700486 FlattenableUtils::read(buffer, size, crop);
Jeykumar Sankaranfa507ff2014-02-12 16:08:19 -0800487 FlattenableUtils::read(buffer, size, dirtyRect);
Mathias Agopiane1424282013-07-29 21:24:40 -0700488 FlattenableUtils::read(buffer, size, scalingMode);
489 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700490 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700491 FlattenableUtils::read(buffer, size, async);
492
Jamie Gennis1df8c342012-12-20 14:05:45 -0800493 fence = new Fence();
Mathias Agopiane1424282013-07-29 21:24:40 -0700494 return fence->unflatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700495}
496
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800497}; // namespace android