blob: cfe726bc0b02e0a21c5baffbaf4926ff920d690e [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,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080051};
52
Andy McFadden2adaf042012-12-18 09:49:45 -080053class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080054{
55public:
Andy McFadden2adaf042012-12-18 09:49:45 -080056 BpGraphicBufferProducer(const sp<IBinder>& impl)
57 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080058 {
59 }
60
Dan Stoza3be1c6b2014-11-18 10:24:03 -080061 virtual ~BpGraphicBufferProducer();
62
Jamie Gennis7b305ff2011-07-19 12:08:33 -070063 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080064 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080065 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080066 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070067 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
68 if (result != NO_ERROR) {
69 return result;
70 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080071 bool nonNull = reply.readInt32();
72 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070073 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080074 result = reply.read(**buf);
75 if(result != NO_ERROR) {
76 (*buf).clear();
77 return result;
78 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080079 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070080 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070081 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080082 }
83
84 virtual status_t setBufferCount(int bufferCount)
85 {
86 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080087 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080088 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070089 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
90 if (result != NO_ERROR) {
91 return result;
92 }
93 result = reply.readInt32();
94 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080095 }
96
Mathias Agopian7cdd7862013-07-18 22:10:56 -070097 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -080098 uint32_t width, uint32_t height, PixelFormat format,
99 uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800100 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800101 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800102 data.writeInt32(static_cast<int32_t>(async));
103 data.writeUint32(width);
104 data.writeUint32(height);
105 data.writeInt32(static_cast<int32_t>(format));
106 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700107 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
108 if (result != NO_ERROR) {
109 return result;
110 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800111 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700112 bool nonNull = reply.readInt32();
113 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700114 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700115 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700116 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700117 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800118 return result;
119 }
120
Dan Stoza9f3053d2014-03-06 15:14:33 -0800121 virtual status_t detachBuffer(int slot) {
122 Parcel data, reply;
123 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
124 data.writeInt32(slot);
125 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
126 if (result != NO_ERROR) {
127 return result;
128 }
129 result = reply.readInt32();
130 return result;
131 }
132
Dan Stozad9822a32014-03-28 15:25:31 -0700133 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
134 sp<Fence>* outFence) {
135 if (outBuffer == NULL) {
136 ALOGE("detachNextBuffer: outBuffer must not be NULL");
137 return BAD_VALUE;
138 } else if (outFence == NULL) {
139 ALOGE("detachNextBuffer: outFence must not be NULL");
140 return BAD_VALUE;
141 }
142 Parcel data, reply;
143 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
144 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
145 if (result != NO_ERROR) {
146 return result;
147 }
148 result = reply.readInt32();
149 if (result == NO_ERROR) {
150 bool nonNull = reply.readInt32();
151 if (nonNull) {
152 *outBuffer = new GraphicBuffer;
153 reply.read(**outBuffer);
154 }
155 nonNull = reply.readInt32();
156 if (nonNull) {
157 *outFence = new Fence;
158 reply.read(**outFence);
159 }
160 }
161 return result;
162 }
163
Dan Stoza9f3053d2014-03-06 15:14:33 -0800164 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
165 Parcel data, reply;
166 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
167 data.write(*buffer.get());
168 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
169 if (result != NO_ERROR) {
170 return result;
171 }
172 *slot = reply.readInt32();
173 result = reply.readInt32();
174 return result;
175 }
176
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700177 virtual status_t queueBuffer(int buf,
178 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800179 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800180 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800181 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700182 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700183 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
184 if (result != NO_ERROR) {
185 return result;
186 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700187 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700188 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800189 return result;
190 }
191
Jesse Hall4c00cc12013-03-15 21:34:30 -0700192 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800193 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800194 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800195 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800196 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800197 remote()->transact(CANCEL_BUFFER, data, &reply);
198 }
199
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700200 virtual int query(int what, int* value) {
201 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800202 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700203 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700204 status_t result = remote()->transact(QUERY, data, &reply);
205 if (result != NO_ERROR) {
206 return result;
207 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700208 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700209 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700210 return result;
211 }
212
Dan Stozaf0eaf252014-03-21 13:05:51 -0700213 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700214 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700215 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800216 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700217 if (listener != NULL) {
218 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800219 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700220 } else {
221 data.writeInt32(0);
222 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700223 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700224 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700225 status_t result = remote()->transact(CONNECT, data, &reply);
226 if (result != NO_ERROR) {
227 return result;
228 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700229 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700230 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700231 return result;
232 }
Mathias Agopian80727112011-05-02 19:51:12 -0700233
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700234 virtual status_t disconnect(int api) {
235 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800236 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700237 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700238 status_t result =remote()->transact(DISCONNECT, data, &reply);
239 if (result != NO_ERROR) {
240 return result;
241 }
242 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700243 return result;
244 }
Jesse Hall399184a2014-03-03 15:42:54 -0800245
246 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
247 Parcel data, reply;
248 status_t result;
249 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
250 if (stream.get()) {
251 data.writeInt32(true);
252 data.writeNativeHandle(stream->handle());
253 } else {
254 data.writeInt32(false);
255 }
256 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
257 result = reply.readInt32();
258 }
259 return result;
260 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700261
262 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800263 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700264 Parcel data, reply;
265 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
266 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800267 data.writeUint32(width);
268 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700269 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800270 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700271 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
272 if (result != NO_ERROR) {
273 ALOGE("allocateBuffers failed to transact: %d", result);
274 }
275 }
Dan Stoza9de72932015-04-16 17:28:43 -0700276
277 virtual status_t allowAllocation(bool allow) {
278 Parcel data, reply;
279 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
280 data.writeInt32(static_cast<int32_t>(allow));
281 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
282 if (result != NO_ERROR) {
283 return result;
284 }
285 result = reply.readInt32();
286 return result;
287 }
Dan Stoza812ed062015-06-02 15:45:22 -0700288
289 virtual status_t setGenerationNumber(uint32_t generationNumber) {
290 Parcel data, reply;
291 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
292 data.writeUint32(generationNumber);
293 status_t result = remote()->transact(SET_GENERATION_NUMBER, data, &reply);
294 if (result == NO_ERROR) {
295 result = reply.readInt32();
296 }
297 return result;
298 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800299};
300
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800301// Out-of-line virtual method definition to trigger vtable emission in this
302// translation unit (see clang warning -Wweak-vtables)
303BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
304
Andy McFadden466a1922013-01-08 11:25:51 -0800305IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800306
307// ----------------------------------------------------------------------
308
Andy McFadden2adaf042012-12-18 09:49:45 -0800309status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800310 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
311{
312 switch(code) {
313 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800314 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800315 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700316 sp<GraphicBuffer> buffer;
317 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800318 reply->writeInt32(buffer != 0);
319 if (buffer != 0) {
320 reply->write(*buffer);
321 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700322 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800323 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800324 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800325 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800326 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800327 int bufferCount = data.readInt32();
328 int result = setBufferCount(bufferCount);
329 reply->writeInt32(result);
330 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800331 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800332 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800333 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800334 bool async = static_cast<bool>(data.readInt32());
335 uint32_t width = data.readUint32();
336 uint32_t height = data.readUint32();
337 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
338 uint32_t usage = data.readUint32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800339 int buf;
Jesse Hallf7857542012-06-14 15:26:33 -0700340 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800341 int result = dequeueBuffer(&buf, &fence, async, width, height,
342 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800343 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800344 reply->writeInt32(fence != NULL);
345 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700346 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700347 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800348 reply->writeInt32(result);
349 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800350 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800351 case DETACH_BUFFER: {
352 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
353 int slot = data.readInt32();
354 int result = detachBuffer(slot);
355 reply->writeInt32(result);
356 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800357 }
Dan Stozad9822a32014-03-28 15:25:31 -0700358 case DETACH_NEXT_BUFFER: {
359 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
360 sp<GraphicBuffer> buffer;
361 sp<Fence> fence;
362 int32_t result = detachNextBuffer(&buffer, &fence);
363 reply->writeInt32(result);
364 if (result == NO_ERROR) {
365 reply->writeInt32(buffer != NULL);
366 if (buffer != NULL) {
367 reply->write(*buffer);
368 }
369 reply->writeInt32(fence != NULL);
370 if (fence != NULL) {
371 reply->write(*fence);
372 }
373 }
374 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800375 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800376 case ATTACH_BUFFER: {
377 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
378 sp<GraphicBuffer> buffer = new GraphicBuffer();
379 data.read(*buffer.get());
380 int slot;
381 int result = attachBuffer(&slot, buffer);
382 reply->writeInt32(slot);
383 reply->writeInt32(result);
384 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800385 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800386 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800387 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800388 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700389 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700390 QueueBufferOutput* const output =
391 reinterpret_cast<QueueBufferOutput *>(
392 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700393 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800394 reply->writeInt32(result);
395 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800396 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800397 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800398 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800399 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800400 sp<Fence> fence = new Fence();
401 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700402 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800403 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800404 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700405 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800406 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700407 int value;
408 int what = data.readInt32();
409 int res = query(what, &value);
410 reply->writeInt32(value);
411 reply->writeInt32(res);
412 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800413 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700414 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800415 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700416 sp<IProducerListener> listener;
417 if (data.readInt32() == 1) {
418 listener = IProducerListener::asInterface(data.readStrongBinder());
419 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700420 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700421 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700422 QueueBufferOutput* const output =
423 reinterpret_cast<QueueBufferOutput *>(
424 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700425 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700426 reply->writeInt32(res);
427 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800428 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700429 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800430 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700431 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700432 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700433 reply->writeInt32(res);
434 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800435 }
Jesse Hall399184a2014-03-03 15:42:54 -0800436 case SET_SIDEBAND_STREAM: {
437 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
438 sp<NativeHandle> stream;
439 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900440 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800441 }
442 status_t result = setSidebandStream(stream);
443 reply->writeInt32(result);
444 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800445 }
Dan Stoza9de72932015-04-16 17:28:43 -0700446 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700447 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
448 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800449 uint32_t width = data.readUint32();
450 uint32_t height = data.readUint32();
451 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
452 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700453 allocateBuffers(async, width, height, format, usage);
454 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700455 }
456 case ALLOW_ALLOCATION: {
457 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
458 bool allow = static_cast<bool>(data.readInt32());
459 status_t result = allowAllocation(allow);
460 reply->writeInt32(result);
461 return NO_ERROR;
462 }
Dan Stoza812ed062015-06-02 15:45:22 -0700463 case SET_GENERATION_NUMBER: {
464 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
465 uint32_t generationNumber = data.readUint32();
466 status_t result = setGenerationNumber(generationNumber);
467 reply->writeInt32(result);
468 return NO_ERROR;
469 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800470 }
471 return BBinder::onTransact(code, data, reply, flags);
472}
473
474// ----------------------------------------------------------------------------
475
Andy McFadden2adaf042012-12-18 09:49:45 -0800476IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700477 parcel.read(*this);
478}
479
Mathias Agopiane1424282013-07-29 21:24:40 -0700480size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700481 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700482 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800483 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700484 + sizeof(crop)
485 + sizeof(scalingMode)
486 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700487 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700488 + sizeof(async)
Dan Stoza5065a552015-03-17 16:23:42 -0700489 + fence->getFlattenedSize()
490 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700491}
492
Mathias Agopiane1424282013-07-29 21:24:40 -0700493size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800494 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700495}
496
Mathias Agopiane1424282013-07-29 21:24:40 -0700497status_t IGraphicBufferProducer::QueueBufferInput::flatten(
498 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700499{
Mathias Agopiane1424282013-07-29 21:24:40 -0700500 if (size < getFlattenedSize()) {
501 return NO_MEMORY;
502 }
503 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700504 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800505 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700506 FlattenableUtils::write(buffer, size, crop);
507 FlattenableUtils::write(buffer, size, scalingMode);
508 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700509 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700510 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700511 status_t result = fence->flatten(buffer, size, fds, count);
512 if (result != NO_ERROR) {
513 return result;
514 }
515 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700516}
517
Mathias Agopiane1424282013-07-29 21:24:40 -0700518status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
519 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700520{
Mathias Agopiane1424282013-07-29 21:24:40 -0700521 size_t minNeeded =
522 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700523 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800524 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700525 + sizeof(crop)
526 + sizeof(scalingMode)
527 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700528 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700529 + sizeof(async);
530
531 if (size < minNeeded) {
532 return NO_MEMORY;
533 }
534
535 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700536 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800537 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700538 FlattenableUtils::read(buffer, size, crop);
539 FlattenableUtils::read(buffer, size, scalingMode);
540 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700541 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700542 FlattenableUtils::read(buffer, size, async);
543
Jamie Gennis1df8c342012-12-20 14:05:45 -0800544 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700545 status_t result = fence->unflatten(buffer, size, fds, count);
546 if (result != NO_ERROR) {
547 return result;
548 }
549 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700550}
551
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800552}; // namespace android