blob: 8d9a8003274e8a907550194c21cab0555ccb3082 [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();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800307 int buf;
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());
347 int slot;
348 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)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700360 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800361 reply->writeInt32(result);
362 return NO_ERROR;
363 } break;
364 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800365 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800366 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800367 sp<Fence> fence = new Fence();
368 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700369 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800370 return NO_ERROR;
371 } break;
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700372 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800373 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700374 int value;
375 int what = data.readInt32();
376 int res = query(what, &value);
377 reply->writeInt32(value);
378 reply->writeInt32(res);
379 return NO_ERROR;
380 } break;
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700381 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800382 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700383 sp<IProducerListener> listener;
384 if (data.readInt32() == 1) {
385 listener = IProducerListener::asInterface(data.readStrongBinder());
386 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700387 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700388 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700389 QueueBufferOutput* const output =
390 reinterpret_cast<QueueBufferOutput *>(
391 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700392 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700393 reply->writeInt32(res);
394 return NO_ERROR;
395 } break;
396 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800397 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700398 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700399 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700400 reply->writeInt32(res);
401 return NO_ERROR;
402 } break;
Jesse Hall399184a2014-03-03 15:42:54 -0800403 case SET_SIDEBAND_STREAM: {
404 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
405 sp<NativeHandle> stream;
406 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900407 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800408 }
409 status_t result = setSidebandStream(stream);
410 reply->writeInt32(result);
411 return NO_ERROR;
412 } break;
Dan Stoza29a3e902014-06-20 13:13:57 -0700413 case ALLOCATE_BUFFERS:
414 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
415 bool async = static_cast<bool>(data.readInt32());
416 uint32_t width = static_cast<uint32_t>(data.readInt32());
417 uint32_t height = static_cast<uint32_t>(data.readInt32());
418 uint32_t format = static_cast<uint32_t>(data.readInt32());
419 uint32_t usage = static_cast<uint32_t>(data.readInt32());
420 allocateBuffers(async, width, height, format, usage);
421 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800422 }
423 return BBinder::onTransact(code, data, reply, flags);
424}
425
426// ----------------------------------------------------------------------------
427
Andy McFadden2adaf042012-12-18 09:49:45 -0800428IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700429 parcel.read(*this);
430}
431
Mathias Agopiane1424282013-07-29 21:24:40 -0700432size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700433 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700434 + sizeof(isAutoTimestamp)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700435 + sizeof(crop)
436 + sizeof(scalingMode)
437 + sizeof(transform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700438 + sizeof(async)
Jamie Gennis1df8c342012-12-20 14:05:45 -0800439 + fence->getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700440}
441
Mathias Agopiane1424282013-07-29 21:24:40 -0700442size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800443 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700444}
445
Mathias Agopiane1424282013-07-29 21:24:40 -0700446status_t IGraphicBufferProducer::QueueBufferInput::flatten(
447 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700448{
Mathias Agopiane1424282013-07-29 21:24:40 -0700449 if (size < getFlattenedSize()) {
450 return NO_MEMORY;
451 }
452 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700453 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700454 FlattenableUtils::write(buffer, size, crop);
455 FlattenableUtils::write(buffer, size, scalingMode);
456 FlattenableUtils::write(buffer, size, transform);
457 FlattenableUtils::write(buffer, size, async);
458 return fence->flatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700459}
460
Mathias Agopiane1424282013-07-29 21:24:40 -0700461status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
462 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700463{
Mathias Agopiane1424282013-07-29 21:24:40 -0700464 size_t minNeeded =
465 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700466 + sizeof(isAutoTimestamp)
Mathias Agopiane1424282013-07-29 21:24:40 -0700467 + sizeof(crop)
468 + sizeof(scalingMode)
469 + sizeof(transform)
470 + sizeof(async);
471
472 if (size < minNeeded) {
473 return NO_MEMORY;
474 }
475
476 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700477 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700478 FlattenableUtils::read(buffer, size, crop);
479 FlattenableUtils::read(buffer, size, scalingMode);
480 FlattenableUtils::read(buffer, size, transform);
481 FlattenableUtils::read(buffer, size, async);
482
Jamie Gennis1df8c342012-12-20 14:05:45 -0800483 fence = new Fence();
Mathias Agopiane1424282013-07-29 21:24:40 -0700484 return fence->unflatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700485}
486
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800487}; // namespace android