blob: 63d881efdacf49063bf767a714ba6c43c04ce084 [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
Dan Stoza3be1c6b2014-11-18 10:24:03 -080059 virtual ~BpGraphicBufferProducer();
60
Jamie Gennis7b305ff2011-07-19 12:08:33 -070061 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080062 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080063 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080064 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070065 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
66 if (result != NO_ERROR) {
67 return result;
68 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080069 bool nonNull = reply.readInt32();
70 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070071 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080072 result = reply.read(**buf);
73 if(result != NO_ERROR) {
74 (*buf).clear();
75 return result;
76 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080077 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070078 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070079 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080080 }
81
82 virtual status_t setBufferCount(int bufferCount)
83 {
84 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080085 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080086 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070087 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
88 if (result != NO_ERROR) {
89 return result;
90 }
91 result = reply.readInt32();
92 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080093 }
94
Mathias Agopian7cdd7862013-07-18 22:10:56 -070095 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -080096 uint32_t width, uint32_t height, PixelFormat format,
97 uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080098 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080099 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800100 data.writeInt32(static_cast<int32_t>(async));
101 data.writeUint32(width);
102 data.writeUint32(height);
103 data.writeInt32(static_cast<int32_t>(format));
104 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700105 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
106 if (result != NO_ERROR) {
107 return result;
108 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800109 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700110 bool nonNull = reply.readInt32();
111 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700112 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700113 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700114 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700115 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800116 return result;
117 }
118
Dan Stoza9f3053d2014-03-06 15:14:33 -0800119 virtual status_t detachBuffer(int slot) {
120 Parcel data, reply;
121 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
122 data.writeInt32(slot);
123 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
124 if (result != NO_ERROR) {
125 return result;
126 }
127 result = reply.readInt32();
128 return result;
129 }
130
Dan Stozad9822a32014-03-28 15:25:31 -0700131 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
132 sp<Fence>* outFence) {
133 if (outBuffer == NULL) {
134 ALOGE("detachNextBuffer: outBuffer must not be NULL");
135 return BAD_VALUE;
136 } else if (outFence == NULL) {
137 ALOGE("detachNextBuffer: outFence must not be NULL");
138 return BAD_VALUE;
139 }
140 Parcel data, reply;
141 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
142 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
143 if (result != NO_ERROR) {
144 return result;
145 }
146 result = reply.readInt32();
147 if (result == NO_ERROR) {
148 bool nonNull = reply.readInt32();
149 if (nonNull) {
150 *outBuffer = new GraphicBuffer;
151 reply.read(**outBuffer);
152 }
153 nonNull = reply.readInt32();
154 if (nonNull) {
155 *outFence = new Fence;
156 reply.read(**outFence);
157 }
158 }
159 return result;
160 }
161
Dan Stoza9f3053d2014-03-06 15:14:33 -0800162 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
163 Parcel data, reply;
164 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
165 data.write(*buffer.get());
166 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
167 if (result != NO_ERROR) {
168 return result;
169 }
170 *slot = reply.readInt32();
171 result = reply.readInt32();
172 return result;
173 }
174
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700175 virtual status_t queueBuffer(int buf,
176 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800177 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800178 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800179 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700180 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700181 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
182 if (result != NO_ERROR) {
183 return result;
184 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700185 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700186 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800187 return result;
188 }
189
Jesse Hall4c00cc12013-03-15 21:34:30 -0700190 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800191 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800192 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800193 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800194 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800195 remote()->transact(CANCEL_BUFFER, data, &reply);
196 }
197
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700198 virtual int query(int what, int* value) {
199 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800200 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700201 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700202 status_t result = remote()->transact(QUERY, data, &reply);
203 if (result != NO_ERROR) {
204 return result;
205 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700206 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700207 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700208 return result;
209 }
210
Dan Stozaf0eaf252014-03-21 13:05:51 -0700211 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700212 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700213 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800214 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700215 if (listener != NULL) {
216 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800217 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700218 } else {
219 data.writeInt32(0);
220 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700221 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700222 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700223 status_t result = remote()->transact(CONNECT, data, &reply);
224 if (result != NO_ERROR) {
225 return result;
226 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700227 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700228 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700229 return result;
230 }
Mathias Agopian80727112011-05-02 19:51:12 -0700231
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700232 virtual status_t disconnect(int api) {
233 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800234 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700235 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700236 status_t result =remote()->transact(DISCONNECT, data, &reply);
237 if (result != NO_ERROR) {
238 return result;
239 }
240 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700241 return result;
242 }
Jesse Hall399184a2014-03-03 15:42:54 -0800243
244 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
245 Parcel data, reply;
246 status_t result;
247 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
248 if (stream.get()) {
249 data.writeInt32(true);
250 data.writeNativeHandle(stream->handle());
251 } else {
252 data.writeInt32(false);
253 }
254 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
255 result = reply.readInt32();
256 }
257 return result;
258 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700259
260 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800261 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700262 Parcel data, reply;
263 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
264 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800265 data.writeUint32(width);
266 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700267 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800268 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700269 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
270 if (result != NO_ERROR) {
271 ALOGE("allocateBuffers failed to transact: %d", result);
272 }
273 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800274};
275
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800276// Out-of-line virtual method definition to trigger vtable emission in this
277// translation unit (see clang warning -Wweak-vtables)
278BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
279
Andy McFadden466a1922013-01-08 11:25:51 -0800280IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800281
282// ----------------------------------------------------------------------
283
Andy McFadden2adaf042012-12-18 09:49:45 -0800284status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800285 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
286{
287 switch(code) {
288 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800289 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800290 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700291 sp<GraphicBuffer> buffer;
292 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800293 reply->writeInt32(buffer != 0);
294 if (buffer != 0) {
295 reply->write(*buffer);
296 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700297 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800298 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800299 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800300 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800301 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800302 int bufferCount = data.readInt32();
303 int result = setBufferCount(bufferCount);
304 reply->writeInt32(result);
305 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800306 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800307 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800308 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800309 bool async = static_cast<bool>(data.readInt32());
310 uint32_t width = data.readUint32();
311 uint32_t height = data.readUint32();
312 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
313 uint32_t usage = data.readUint32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800314 int buf;
Jesse Hallf7857542012-06-14 15:26:33 -0700315 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800316 int result = dequeueBuffer(&buf, &fence, async, width, height,
317 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800318 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800319 reply->writeInt32(fence != NULL);
320 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700321 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700322 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800323 reply->writeInt32(result);
324 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800325 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800326 case DETACH_BUFFER: {
327 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
328 int slot = data.readInt32();
329 int result = detachBuffer(slot);
330 reply->writeInt32(result);
331 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800332 }
Dan Stozad9822a32014-03-28 15:25:31 -0700333 case DETACH_NEXT_BUFFER: {
334 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
335 sp<GraphicBuffer> buffer;
336 sp<Fence> fence;
337 int32_t result = detachNextBuffer(&buffer, &fence);
338 reply->writeInt32(result);
339 if (result == NO_ERROR) {
340 reply->writeInt32(buffer != NULL);
341 if (buffer != NULL) {
342 reply->write(*buffer);
343 }
344 reply->writeInt32(fence != NULL);
345 if (fence != NULL) {
346 reply->write(*fence);
347 }
348 }
349 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800350 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800351 case ATTACH_BUFFER: {
352 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
353 sp<GraphicBuffer> buffer = new GraphicBuffer();
354 data.read(*buffer.get());
355 int slot;
356 int result = attachBuffer(&slot, buffer);
357 reply->writeInt32(slot);
358 reply->writeInt32(result);
359 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800360 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800361 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800362 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800363 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700364 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700365 QueueBufferOutput* const output =
366 reinterpret_cast<QueueBufferOutput *>(
367 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700368 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800369 reply->writeInt32(result);
370 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800371 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800372 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800373 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800374 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800375 sp<Fence> fence = new Fence();
376 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700377 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800378 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800379 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700380 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800381 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700382 int value;
383 int what = data.readInt32();
384 int res = query(what, &value);
385 reply->writeInt32(value);
386 reply->writeInt32(res);
387 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800388 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700389 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800390 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700391 sp<IProducerListener> listener;
392 if (data.readInt32() == 1) {
393 listener = IProducerListener::asInterface(data.readStrongBinder());
394 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700395 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700396 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700397 QueueBufferOutput* const output =
398 reinterpret_cast<QueueBufferOutput *>(
399 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700400 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700401 reply->writeInt32(res);
402 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800403 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700404 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800405 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700406 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700407 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700408 reply->writeInt32(res);
409 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800410 }
Jesse Hall399184a2014-03-03 15:42:54 -0800411 case SET_SIDEBAND_STREAM: {
412 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
413 sp<NativeHandle> stream;
414 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900415 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800416 }
417 status_t result = setSidebandStream(stream);
418 reply->writeInt32(result);
419 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800420 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700421 case ALLOCATE_BUFFERS:
422 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
423 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800424 uint32_t width = data.readUint32();
425 uint32_t height = data.readUint32();
426 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
427 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700428 allocateBuffers(async, width, height, format, usage);
429 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800430 }
431 return BBinder::onTransact(code, data, reply, flags);
432}
433
434// ----------------------------------------------------------------------------
435
Andy McFadden2adaf042012-12-18 09:49:45 -0800436IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700437 parcel.read(*this);
438}
439
Mathias Agopiane1424282013-07-29 21:24:40 -0700440size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700441 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700442 + sizeof(isAutoTimestamp)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700443 + sizeof(crop)
444 + sizeof(scalingMode)
445 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700446 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700447 + sizeof(async)
Jamie Gennis1df8c342012-12-20 14:05:45 -0800448 + fence->getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700449}
450
Mathias Agopiane1424282013-07-29 21:24:40 -0700451size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800452 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700453}
454
Mathias Agopiane1424282013-07-29 21:24:40 -0700455status_t IGraphicBufferProducer::QueueBufferInput::flatten(
456 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700457{
Mathias Agopiane1424282013-07-29 21:24:40 -0700458 if (size < getFlattenedSize()) {
459 return NO_MEMORY;
460 }
461 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700462 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700463 FlattenableUtils::write(buffer, size, crop);
464 FlattenableUtils::write(buffer, size, scalingMode);
465 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700466 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700467 FlattenableUtils::write(buffer, size, async);
468 return fence->flatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700469}
470
Mathias Agopiane1424282013-07-29 21:24:40 -0700471status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
472 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700473{
Mathias Agopiane1424282013-07-29 21:24:40 -0700474 size_t minNeeded =
475 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700476 + sizeof(isAutoTimestamp)
Mathias Agopiane1424282013-07-29 21:24:40 -0700477 + sizeof(crop)
478 + sizeof(scalingMode)
479 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700480 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700481 + sizeof(async);
482
483 if (size < minNeeded) {
484 return NO_MEMORY;
485 }
486
487 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700488 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Mathias Agopiane1424282013-07-29 21:24:40 -0700489 FlattenableUtils::read(buffer, size, crop);
490 FlattenableUtils::read(buffer, size, scalingMode);
491 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700492 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700493 FlattenableUtils::read(buffer, size, async);
494
Jamie Gennis1df8c342012-12-20 14:05:45 -0800495 fence = new Fence();
Mathias Agopiane1424282013-07-29 21:24:40 -0700496 return fence->unflatten(buffer, size, fds, count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700497}
498
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800499}; // namespace android