blob: 7093ffaa1ef66a2050fb860e09a20d67d212f9a7 [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,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080050};
51
Andy McFadden2adaf042012-12-18 09:49:45 -080052class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080053{
54public:
Andy McFadden2adaf042012-12-18 09:49:45 -080055 BpGraphicBufferProducer(const sp<IBinder>& impl)
56 : BpInterface<IGraphicBufferProducer>(impl)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080057 {
58 }
59
Dan Stoza3be1c6b2014-11-18 10:24:03 -080060 virtual ~BpGraphicBufferProducer();
61
Jamie Gennis7b305ff2011-07-19 12:08:33 -070062 virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080063 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080064 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080065 data.writeInt32(bufferIdx);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070066 status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
67 if (result != NO_ERROR) {
68 return result;
69 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080070 bool nonNull = reply.readInt32();
71 if (nonNull) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -070072 *buf = new GraphicBuffer();
Lingyun Zhu2aff7022012-11-20 19:24:35 +080073 result = reply.read(**buf);
74 if(result != NO_ERROR) {
75 (*buf).clear();
76 return result;
77 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080078 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -070079 result = reply.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -070080 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080081 }
82
83 virtual status_t setBufferCount(int bufferCount)
84 {
85 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -080086 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080087 data.writeInt32(bufferCount);
Jamie Gennis8a29ff22011-10-14 15:03:17 -070088 status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
89 if (result != NO_ERROR) {
90 return result;
91 }
92 result = reply.readInt32();
93 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080094 }
95
Mathias Agopian7cdd7862013-07-18 22:10:56 -070096 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -080097 uint32_t width, uint32_t height, PixelFormat format,
98 uint32_t usage) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080099 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800100 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800101 data.writeInt32(static_cast<int32_t>(async));
102 data.writeUint32(width);
103 data.writeUint32(height);
104 data.writeInt32(static_cast<int32_t>(format));
105 data.writeUint32(usage);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700106 status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
107 if (result != NO_ERROR) {
108 return result;
109 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800110 *buf = reply.readInt32();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700111 bool nonNull = reply.readInt32();
112 if (nonNull) {
Jesse Hall4c00cc12013-03-15 21:34:30 -0700113 *fence = new Fence();
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700114 reply.read(**fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700115 }
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700116 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800117 return result;
118 }
119
Dan Stoza9f3053d2014-03-06 15:14:33 -0800120 virtual status_t detachBuffer(int slot) {
121 Parcel data, reply;
122 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
123 data.writeInt32(slot);
124 status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
125 if (result != NO_ERROR) {
126 return result;
127 }
128 result = reply.readInt32();
129 return result;
130 }
131
Dan Stozad9822a32014-03-28 15:25:31 -0700132 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
133 sp<Fence>* outFence) {
134 if (outBuffer == NULL) {
135 ALOGE("detachNextBuffer: outBuffer must not be NULL");
136 return BAD_VALUE;
137 } else if (outFence == NULL) {
138 ALOGE("detachNextBuffer: outFence must not be NULL");
139 return BAD_VALUE;
140 }
141 Parcel data, reply;
142 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
143 status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
144 if (result != NO_ERROR) {
145 return result;
146 }
147 result = reply.readInt32();
148 if (result == NO_ERROR) {
149 bool nonNull = reply.readInt32();
150 if (nonNull) {
151 *outBuffer = new GraphicBuffer;
152 reply.read(**outBuffer);
153 }
154 nonNull = reply.readInt32();
155 if (nonNull) {
156 *outFence = new Fence;
157 reply.read(**outFence);
158 }
159 }
160 return result;
161 }
162
Dan Stoza9f3053d2014-03-06 15:14:33 -0800163 virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
164 Parcel data, reply;
165 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
166 data.write(*buffer.get());
167 status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
168 if (result != NO_ERROR) {
169 return result;
170 }
171 *slot = reply.readInt32();
172 result = reply.readInt32();
173 return result;
174 }
175
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700176 virtual status_t queueBuffer(int buf,
177 const QueueBufferInput& input, QueueBufferOutput* output) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800178 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800179 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800180 data.writeInt32(buf);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700181 data.write(input);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700182 status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
183 if (result != NO_ERROR) {
184 return result;
185 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700186 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700187 result = reply.readInt32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800188 return result;
189 }
190
Jesse Hall4c00cc12013-03-15 21:34:30 -0700191 virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800192 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800193 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800194 data.writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800195 data.write(*fence.get());
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800196 remote()->transact(CANCEL_BUFFER, data, &reply);
197 }
198
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700199 virtual int query(int what, int* value) {
200 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800201 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700202 data.writeInt32(what);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700203 status_t result = remote()->transact(QUERY, data, &reply);
204 if (result != NO_ERROR) {
205 return result;
206 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700207 value[0] = reply.readInt32();
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700208 result = reply.readInt32();
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700209 return result;
210 }
211
Dan Stozaf0eaf252014-03-21 13:05:51 -0700212 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700213 int api, bool producerControlledByApp, QueueBufferOutput* output) {
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700214 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800215 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Dan Stozaf0eaf252014-03-21 13:05:51 -0700216 if (listener != NULL) {
217 data.writeInt32(1);
Marco Nelissen097ca272014-11-14 08:01:01 -0800218 data.writeStrongBinder(IInterface::asBinder(listener));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700219 } else {
220 data.writeInt32(0);
221 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700222 data.writeInt32(api);
Mathias Agopian595264f2013-07-16 22:56:09 -0700223 data.writeInt32(producerControlledByApp);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700224 status_t result = remote()->transact(CONNECT, data, &reply);
225 if (result != NO_ERROR) {
226 return result;
227 }
Mathias Agopian24202f52012-04-23 14:28:58 -0700228 memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700229 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700230 return result;
231 }
Mathias Agopian80727112011-05-02 19:51:12 -0700232
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700233 virtual status_t disconnect(int api) {
234 Parcel data, reply;
Andy McFadden2adaf042012-12-18 09:49:45 -0800235 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700236 data.writeInt32(api);
Jamie Gennis8a29ff22011-10-14 15:03:17 -0700237 status_t result =remote()->transact(DISCONNECT, data, &reply);
238 if (result != NO_ERROR) {
239 return result;
240 }
241 result = reply.readInt32();
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700242 return result;
243 }
Jesse Hall399184a2014-03-03 15:42:54 -0800244
245 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
246 Parcel data, reply;
247 status_t result;
248 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
249 if (stream.get()) {
250 data.writeInt32(true);
251 data.writeNativeHandle(stream->handle());
252 } else {
253 data.writeInt32(false);
254 }
255 if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
256 result = reply.readInt32();
257 }
258 return result;
259 }
Dan Stoza29a3e902014-06-20 13:13:57 -0700260
261 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800262 PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700263 Parcel data, reply;
264 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
265 data.writeInt32(static_cast<int32_t>(async));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800266 data.writeUint32(width);
267 data.writeUint32(height);
Dan Stoza29a3e902014-06-20 13:13:57 -0700268 data.writeInt32(static_cast<int32_t>(format));
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800269 data.writeUint32(usage);
Dan Stoza29a3e902014-06-20 13:13:57 -0700270 status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
271 if (result != NO_ERROR) {
272 ALOGE("allocateBuffers failed to transact: %d", result);
273 }
274 }
Dan Stoza9de72932015-04-16 17:28:43 -0700275
276 virtual status_t allowAllocation(bool allow) {
277 Parcel data, reply;
278 data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
279 data.writeInt32(static_cast<int32_t>(allow));
280 status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
281 if (result != NO_ERROR) {
282 return result;
283 }
284 result = reply.readInt32();
285 return result;
286 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800287};
288
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800289// Out-of-line virtual method definition to trigger vtable emission in this
290// translation unit (see clang warning -Wweak-vtables)
291BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
292
Andy McFadden466a1922013-01-08 11:25:51 -0800293IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800294
295// ----------------------------------------------------------------------
296
Andy McFadden2adaf042012-12-18 09:49:45 -0800297status_t BnGraphicBufferProducer::onTransact(
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800298 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
299{
300 switch(code) {
301 case REQUEST_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800302 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800303 int bufferIdx = data.readInt32();
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700304 sp<GraphicBuffer> buffer;
305 int result = requestBuffer(bufferIdx, &buffer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800306 reply->writeInt32(buffer != 0);
307 if (buffer != 0) {
308 reply->write(*buffer);
309 }
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700310 reply->writeInt32(result);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800311 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800312 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800313 case SET_BUFFER_COUNT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800314 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800315 int bufferCount = data.readInt32();
316 int result = setBufferCount(bufferCount);
317 reply->writeInt32(result);
318 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800319 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800320 case DEQUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800321 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800322 bool async = static_cast<bool>(data.readInt32());
323 uint32_t width = data.readUint32();
324 uint32_t height = data.readUint32();
325 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
326 uint32_t usage = data.readUint32();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800327 int buf;
Jesse Hallf7857542012-06-14 15:26:33 -0700328 sp<Fence> fence;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800329 int result = dequeueBuffer(&buf, &fence, async, width, height,
330 format, usage);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800331 reply->writeInt32(buf);
Jamie Gennis1df8c342012-12-20 14:05:45 -0800332 reply->writeInt32(fence != NULL);
333 if (fence != NULL) {
Mathias Agopianba93b3f2013-08-01 15:48:40 -0700334 reply->write(*fence);
Jesse Hallf7857542012-06-14 15:26:33 -0700335 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800336 reply->writeInt32(result);
337 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800338 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800339 case DETACH_BUFFER: {
340 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
341 int slot = data.readInt32();
342 int result = detachBuffer(slot);
343 reply->writeInt32(result);
344 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800345 }
Dan Stozad9822a32014-03-28 15:25:31 -0700346 case DETACH_NEXT_BUFFER: {
347 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
348 sp<GraphicBuffer> buffer;
349 sp<Fence> fence;
350 int32_t result = detachNextBuffer(&buffer, &fence);
351 reply->writeInt32(result);
352 if (result == NO_ERROR) {
353 reply->writeInt32(buffer != NULL);
354 if (buffer != NULL) {
355 reply->write(*buffer);
356 }
357 reply->writeInt32(fence != NULL);
358 if (fence != NULL) {
359 reply->write(*fence);
360 }
361 }
362 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800363 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800364 case ATTACH_BUFFER: {
365 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
366 sp<GraphicBuffer> buffer = new GraphicBuffer();
367 data.read(*buffer.get());
368 int slot;
369 int result = attachBuffer(&slot, buffer);
370 reply->writeInt32(slot);
371 reply->writeInt32(result);
372 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800373 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800374 case QUEUE_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800375 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800376 int buf = data.readInt32();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700377 QueueBufferInput input(data);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700378 QueueBufferOutput* const output =
379 reinterpret_cast<QueueBufferOutput *>(
380 reply->writeInplace(sizeof(QueueBufferOutput)));
Jesse Hallc777b0b2012-06-28 12:52:05 -0700381 status_t result = queueBuffer(buf, input, output);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800382 reply->writeInt32(result);
383 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800384 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800385 case CANCEL_BUFFER: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800386 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800387 int buf = data.readInt32();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800388 sp<Fence> fence = new Fence();
389 data.read(*fence.get());
Jesse Hallc777b0b2012-06-28 12:52:05 -0700390 cancelBuffer(buf, fence);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800391 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800392 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700393 case QUERY: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800394 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700395 int value;
396 int what = data.readInt32();
397 int res = query(what, &value);
398 reply->writeInt32(value);
399 reply->writeInt32(res);
400 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800401 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700402 case CONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800403 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Dan Stozaf0eaf252014-03-21 13:05:51 -0700404 sp<IProducerListener> listener;
405 if (data.readInt32() == 1) {
406 listener = IProducerListener::asInterface(data.readStrongBinder());
407 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700408 int api = data.readInt32();
Mathias Agopian595264f2013-07-16 22:56:09 -0700409 bool producerControlledByApp = data.readInt32();
Mathias Agopian24202f52012-04-23 14:28:58 -0700410 QueueBufferOutput* const output =
411 reinterpret_cast<QueueBufferOutput *>(
412 reply->writeInplace(sizeof(QueueBufferOutput)));
Dan Stozaf0eaf252014-03-21 13:05:51 -0700413 status_t res = connect(listener, api, producerControlledByApp, output);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700414 reply->writeInt32(res);
415 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800416 }
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700417 case DISCONNECT: {
Andy McFadden2adaf042012-12-18 09:49:45 -0800418 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700419 int api = data.readInt32();
Mathias Agopian27730042011-07-14 20:20:58 -0700420 status_t res = disconnect(api);
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700421 reply->writeInt32(res);
422 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800423 }
Jesse Hall399184a2014-03-03 15:42:54 -0800424 case SET_SIDEBAND_STREAM: {
425 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
426 sp<NativeHandle> stream;
427 if (data.readInt32()) {
Wonsik Kim0ec54e12014-03-21 10:46:24 +0900428 stream = NativeHandle::create(data.readNativeHandle(), true);
Jesse Hall399184a2014-03-03 15:42:54 -0800429 }
430 status_t result = setSidebandStream(stream);
431 reply->writeInt32(result);
432 return NO_ERROR;
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800433 }
Dan Stoza9de72932015-04-16 17:28:43 -0700434 case ALLOCATE_BUFFERS: {
Dan Stoza29a3e902014-06-20 13:13:57 -0700435 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
436 bool async = static_cast<bool>(data.readInt32());
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800437 uint32_t width = data.readUint32();
438 uint32_t height = data.readUint32();
439 PixelFormat format = static_cast<PixelFormat>(data.readInt32());
440 uint32_t usage = data.readUint32();
Dan Stoza29a3e902014-06-20 13:13:57 -0700441 allocateBuffers(async, width, height, format, usage);
442 return NO_ERROR;
Dan Stoza9de72932015-04-16 17:28:43 -0700443 }
444 case ALLOW_ALLOCATION: {
445 CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
446 bool allow = static_cast<bool>(data.readInt32());
447 status_t result = allowAllocation(allow);
448 reply->writeInt32(result);
449 return NO_ERROR;
450 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800451 }
452 return BBinder::onTransact(code, data, reply, flags);
453}
454
455// ----------------------------------------------------------------------------
456
Andy McFadden2adaf042012-12-18 09:49:45 -0800457IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700458 parcel.read(*this);
459}
460
Mathias Agopiane1424282013-07-29 21:24:40 -0700461size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
Jesse Hallc777b0b2012-06-28 12:52:05 -0700462 return sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700463 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800464 + sizeof(dataSpace)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700465 + sizeof(crop)
466 + sizeof(scalingMode)
467 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700468 + sizeof(stickyTransform)
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700469 + sizeof(async)
Dan Stoza5065a552015-03-17 16:23:42 -0700470 + fence->getFlattenedSize()
471 + surfaceDamage.getFlattenedSize();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700472}
473
Mathias Agopiane1424282013-07-29 21:24:40 -0700474size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
Jamie Gennis1df8c342012-12-20 14:05:45 -0800475 return fence->getFdCount();
Jesse Hallc777b0b2012-06-28 12:52:05 -0700476}
477
Mathias Agopiane1424282013-07-29 21:24:40 -0700478status_t IGraphicBufferProducer::QueueBufferInput::flatten(
479 void*& buffer, size_t& size, int*& fds, size_t& count) const
Jesse Hallc777b0b2012-06-28 12:52:05 -0700480{
Mathias Agopiane1424282013-07-29 21:24:40 -0700481 if (size < getFlattenedSize()) {
482 return NO_MEMORY;
483 }
484 FlattenableUtils::write(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700485 FlattenableUtils::write(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800486 FlattenableUtils::write(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700487 FlattenableUtils::write(buffer, size, crop);
488 FlattenableUtils::write(buffer, size, scalingMode);
489 FlattenableUtils::write(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700490 FlattenableUtils::write(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700491 FlattenableUtils::write(buffer, size, async);
Dan Stoza5065a552015-03-17 16:23:42 -0700492 status_t result = fence->flatten(buffer, size, fds, count);
493 if (result != NO_ERROR) {
494 return result;
495 }
496 return surfaceDamage.flatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700497}
498
Mathias Agopiane1424282013-07-29 21:24:40 -0700499status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
500 void const*& buffer, size_t& size, int const*& fds, size_t& count)
Jesse Hallc777b0b2012-06-28 12:52:05 -0700501{
Mathias Agopiane1424282013-07-29 21:24:40 -0700502 size_t minNeeded =
503 sizeof(timestamp)
Andy McFadden3c256212013-08-16 14:55:39 -0700504 + sizeof(isAutoTimestamp)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800505 + sizeof(dataSpace)
Mathias Agopiane1424282013-07-29 21:24:40 -0700506 + sizeof(crop)
507 + sizeof(scalingMode)
508 + sizeof(transform)
Ruben Brunk1681d952014-06-27 15:51:55 -0700509 + sizeof(stickyTransform)
Mathias Agopiane1424282013-07-29 21:24:40 -0700510 + sizeof(async);
511
512 if (size < minNeeded) {
513 return NO_MEMORY;
514 }
515
516 FlattenableUtils::read(buffer, size, timestamp);
Andy McFadden3c256212013-08-16 14:55:39 -0700517 FlattenableUtils::read(buffer, size, isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800518 FlattenableUtils::read(buffer, size, dataSpace);
Mathias Agopiane1424282013-07-29 21:24:40 -0700519 FlattenableUtils::read(buffer, size, crop);
520 FlattenableUtils::read(buffer, size, scalingMode);
521 FlattenableUtils::read(buffer, size, transform);
Ruben Brunk1681d952014-06-27 15:51:55 -0700522 FlattenableUtils::read(buffer, size, stickyTransform);
Mathias Agopiane1424282013-07-29 21:24:40 -0700523 FlattenableUtils::read(buffer, size, async);
524
Jamie Gennis1df8c342012-12-20 14:05:45 -0800525 fence = new Fence();
Dan Stoza5065a552015-03-17 16:23:42 -0700526 status_t result = fence->unflatten(buffer, size, fds, count);
527 if (result != NO_ERROR) {
528 return result;
529 }
530 return surfaceDamage.unflatten(buffer, size);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700531}
532
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800533}; // namespace android