blob: 4d3cd9a29b3990a25f7b1c1a51a84e5dd5cc01d9 [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
Andy McFadden2adaf042012-12-18 09:49:45 -080017#ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
18#define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080019
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Errors.h>
24#include <utils/RefBase.h>
25
26#include <binder/IInterface.h>
27
Jesse Hallf7857542012-06-14 15:26:33 -070028#include <ui/Fence.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080029#include <ui/GraphicBuffer.h>
30#include <ui/Rect.h>
31
32namespace android {
33// ----------------------------------------------------------------------------
34
Dan Stozaf0eaf252014-03-21 13:05:51 -070035class IProducerListener;
Jesse Hall399184a2014-03-03 15:42:54 -080036class NativeHandle;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037class Surface;
Mathias Agopianeafabcd2011-04-20 14:20:59 -070038
Andy McFadden0273adb2012-12-12 17:10:08 -080039/*
Andy McFadden466a1922013-01-08 11:25:51 -080040 * This class defines the Binder IPC interface for the producer side of
41 * a queue of graphics buffers. It's used to send graphics data from one
42 * component to another. For example, a class that decodes video for
43 * playback might use this to provide frames. This is typically done
Mathias Agopiane3c697f2013-02-14 17:11:02 -080044 * indirectly, through Surface.
Andy McFadden0273adb2012-12-12 17:10:08 -080045 *
Andy McFadden466a1922013-01-08 11:25:51 -080046 * The underlying mechanism is a BufferQueue, which implements
47 * BnGraphicBufferProducer. In normal operation, the producer calls
48 * dequeueBuffer() to get an empty buffer, fills it with data, then
49 * calls queueBuffer() to make it available to the consumer.
Andy McFadden0273adb2012-12-12 17:10:08 -080050 *
Andy McFadden2adaf042012-12-18 09:49:45 -080051 * This class was previously called ISurfaceTexture.
Andy McFadden0273adb2012-12-12 17:10:08 -080052 */
Andy McFadden2adaf042012-12-18 09:49:45 -080053class IGraphicBufferProducer : public IInterface
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080054{
55public:
Andy McFadden2adaf042012-12-18 09:49:45 -080056 DECLARE_META_INTERFACE(GraphicBufferProducer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080057
Mathias Agopian80727112011-05-02 19:51:12 -070058 enum {
Igor Murashkin7d2d1602013-11-12 18:02:20 -080059 // A flag returned by dequeueBuffer when the client needs to call
60 // requestBuffer immediately thereafter.
Mathias Agopian80727112011-05-02 19:51:12 -070061 BUFFER_NEEDS_REALLOCATION = 0x1,
Igor Murashkin7d2d1602013-11-12 18:02:20 -080062 // A flag returned by dequeueBuffer when all mirrored slots should be
63 // released by the client. This flag should always be processed first.
Mathias Agopian80727112011-05-02 19:51:12 -070064 RELEASE_ALL_BUFFERS = 0x2,
65 };
Mathias Agopiana5c75c02011-03-31 19:10:24 -070066
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080067 // requestBuffer requests a new buffer for the given index. The server (i.e.
Andy McFadden2adaf042012-12-18 09:49:45 -080068 // the IGraphicBufferProducer implementation) assigns the newly created
69 // buffer to the given slot index, and the client is expected to mirror the
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080070 // slot->buffer mapping so that it's not necessary to transfer a
71 // GraphicBuffer for every dequeue operation.
Igor Murashkin7d2d1602013-11-12 18:02:20 -080072 //
73 // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
74 //
75 // Return of a value other than NO_ERROR means an error has occurred:
76 // * NO_INIT - the buffer queue has been abandoned.
77 // * BAD_VALUE - one of the two conditions occurred:
78 // * slot was out of range (see above)
79 // * buffer specified by the slot is not dequeued
Jamie Gennis7b305ff2011-07-19 12:08:33 -070080 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080081
82 // setBufferCount sets the number of buffer slots available. Calling this
83 // will also cause all buffer slots to be emptied. The caller should empty
84 // its mirrored copy of the buffer slots when calling this method.
Igor Murashkin7d2d1602013-11-12 18:02:20 -080085 //
86 // This function should not be called when there are any dequeued buffer
87 // slots, doing so will result in a BAD_VALUE error returned.
88 //
Igor Murashkin7ea777f2013-11-18 16:58:36 -080089 // The buffer count should be at most NUM_BUFFER_SLOTS (inclusive), but at least
90 // the minimum undequeued buffer count (exclusive). The minimum value
91 // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS).
92 // In particular the range is (minUndequeudBuffers, NUM_BUFFER_SLOTS].
93 //
94 // The buffer count may also be set to 0 (the default), to indicate that
95 // the producer does not wish to set a value.
Igor Murashkin7d2d1602013-11-12 18:02:20 -080096 //
97 // Return of a value other than NO_ERROR means an error has occurred:
98 // * NO_INIT - the buffer queue has been abandoned.
99 // * BAD_VALUE - one of the below conditions occurred:
100 // * bufferCount was out of range (see above)
101 // * client has one or more buffers dequeued
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800102 virtual status_t setBufferCount(int bufferCount) = 0;
103
104 // dequeueBuffer requests a new buffer slot for the client to use. Ownership
105 // of the slot is transfered to the client, meaning that the server will not
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800106 // use the contents of the buffer associated with that slot.
107 //
108 // The slot index returned may or may not contain a buffer (client-side).
109 // If the slot is empty the client should call requestBuffer to assign a new
110 // buffer to that slot.
111 //
112 // Once the client is done filling this buffer, it is expected to transfer
113 // buffer ownership back to the server with either cancelBuffer on
114 // the dequeued slot or to fill in the contents of its associated buffer
115 // contents and call queueBuffer.
116 //
117 // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700118 // expected to call requestBuffer immediately.
Jesse Hallf7857542012-06-14 15:26:33 -0700119 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800120 // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is
121 // expected to release all of the mirrored slot->buffer mappings.
122 //
Jesse Hallf7857542012-06-14 15:26:33 -0700123 // The fence parameter will be updated to hold the fence associated with
124 // the buffer. The contents of the buffer must not be overwritten until the
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800125 // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written
Jesse Hallf7857542012-06-14 15:26:33 -0700126 // immediately.
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700127 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800128 // The async parameter sets whether we're in asynchronous mode for this
129 // dequeueBuffer() call.
130 //
131 // The width and height parameters must be no greater than the minimum of
132 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
133 // An error due to invalid dimensions might not be reported until
134 // updateTexImage() is called. If width and height are both zero, the
135 // default values specified by setDefaultBufferSize() are used instead.
136 //
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800137 // If the format is 0, the default format will be used.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800138 //
139 // The usage argument specifies gralloc buffer usage flags. The values
140 // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER. These
141 // will be merged with the usage flags specified by
142 // IGraphicBufferConsumer::setConsumerUsageBits.
143 //
144 // This call will block until a buffer is available to be dequeued. If
145 // both the producer and consumer are controlled by the app, then this call
146 // can never block and will return WOULD_BLOCK if no buffer is available.
147 //
148 // A non-negative value with flags set (see above) will be returned upon
149 // success.
150 //
151 // Return of a negative means an error has occurred:
152 // * NO_INIT - the buffer queue has been abandoned.
Dan Stoza9f3053d2014-03-06 15:14:33 -0800153 // * BAD_VALUE - both in async mode and buffer count was less than the
154 // max numbers of buffers that can be allocated at once.
155 // * INVALID_OPERATION - cannot attach the buffer because it would cause
156 // too many buffers to be dequeued, either because
157 // the producer already has a single buffer dequeued
158 // and did not set a buffer count, or because a
159 // buffer count was set and this call would cause
160 // it to be exceeded.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800161 // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled
162 // since both the producer/consumer are controlled by app
163 // * NO_MEMORY - out of memory, cannot allocate the graphics buffer.
164 //
165 // All other negative values are an unknown error returned downstream
166 // from the graphics allocator (typically errno).
167 virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, bool async,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800168 uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800169
Dan Stoza9f3053d2014-03-06 15:14:33 -0800170 // detachBuffer attempts to remove all ownership of the buffer in the given
171 // slot from the buffer queue. If this call succeeds, the slot will be
172 // freed, and there will be no way to obtain the buffer from this interface.
173 // The freed slot will remain unallocated until either it is selected to
174 // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached
175 // to the slot. The buffer must have already been dequeued, and the caller
176 // must already possesses the sp<GraphicBuffer> (i.e., must have called
177 // requestBuffer).
178 //
179 // Return of a value other than NO_ERROR means an error has occurred:
180 // * NO_INIT - the buffer queue has been abandoned.
181 // * BAD_VALUE - the given slot number is invalid, either because it is
182 // out of the range [0, NUM_BUFFER_SLOTS), or because the slot
183 // it refers to is not currently dequeued and requested.
184 virtual status_t detachBuffer(int slot) = 0;
185
Dan Stozad9822a32014-03-28 15:25:31 -0700186 // detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer,
187 // and detachBuffer in sequence, except for two things:
188 //
189 // 1) It is unnecessary to know the dimensions, format, or usage of the
190 // next buffer.
191 // 2) It will not block, since if it cannot find an appropriate buffer to
192 // return, it will return an error instead.
193 //
194 // Only slots that are free but still contain a GraphicBuffer will be
195 // considered, and the oldest of those will be returned. outBuffer is
196 // equivalent to outBuffer from the requestBuffer call, and outFence is
197 // equivalent to fence from the dequeueBuffer call.
198 //
199 // Return of a value other than NO_ERROR means an error has occurred:
200 // * NO_INIT - the buffer queue has been abandoned.
201 // * BAD_VALUE - either outBuffer or outFence were NULL.
202 // * NO_MEMORY - no slots were found that were both free and contained a
203 // GraphicBuffer.
204 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
205 sp<Fence>* outFence) = 0;
206
Dan Stoza9f3053d2014-03-06 15:14:33 -0800207 // attachBuffer attempts to transfer ownership of a buffer to the buffer
208 // queue. If this call succeeds, it will be as if this buffer was dequeued
209 // from the returned slot number. As such, this call will fail if attaching
210 // this buffer would cause too many buffers to be simultaneously dequeued.
211 //
212 // If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is
213 // expected to release all of the mirrored slot->buffer mappings.
214 //
215 // A non-negative value with flags set (see above) will be returned upon
216 // success.
217 //
218 // Return of a negative value means an error has occurred:
219 // * NO_INIT - the buffer queue has been abandoned.
220 // * BAD_VALUE - outSlot or buffer were NULL or invalid combination of
221 // async mode and buffer count override.
222 // * INVALID_OPERATION - cannot attach the buffer because it would cause
223 // too many buffers to be dequeued, either because
224 // the producer already has a single buffer dequeued
225 // and did not set a buffer count, or because a
226 // buffer count was set and this call would cause
227 // it to be exceeded.
228 // * WOULD_BLOCK - no buffer slot is currently available, and blocking is
229 // disabled since both the producer/consumer are
230 // controlled by the app.
231 virtual status_t attachBuffer(int* outSlot,
232 const sp<GraphicBuffer>& buffer) = 0;
233
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800234 // queueBuffer indicates that the client has finished filling in the
235 // contents of the buffer associated with slot and transfers ownership of
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800236 // that slot back to the server.
237 //
238 // It is not valid to call queueBuffer on a slot that is not owned
239 // by the client or one for which a buffer associated via requestBuffer
240 // (an attempt to do so will fail with a return value of BAD_VALUE).
241 //
242 // In addition, the input must be described by the client (as documented
243 // below). Any other properties (zero point, etc)
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800244 // are client-dependent, and should be documented by the client.
Mathias Agopian97c602c2011-07-19 15:24:46 -0700245 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800246 // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700247 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800248 // Upon success, the output will be filled with meaningful values
249 // (refer to the documentation below).
250 //
251 // Return of a value other than NO_ERROR means an error has occurred:
252 // * NO_INIT - the buffer queue has been abandoned.
253 // * BAD_VALUE - one of the below conditions occurred:
254 // * fence was NULL
255 // * scaling mode was unknown
256 // * both in async mode and buffer count was less than the
257 // max numbers of buffers that can be allocated at once
258 // * slot index was out of range (see above).
259 // * the slot was not in the dequeued state
260 // * the slot was enqueued without requesting a buffer
261 // * crop rect is out of bounds of the buffer dimensions
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700262
Mathias Agopiane1424282013-07-29 21:24:40 -0700263 struct QueueBufferInput : public Flattenable<QueueBufferInput> {
264 friend class Flattenable<QueueBufferInput>;
Jesse Hallc777b0b2012-06-28 12:52:05 -0700265 inline QueueBufferInput(const Parcel& parcel);
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800266 // timestamp - a monotonically increasing value in nanoseconds
267 // isAutoTimestamp - if the timestamp was synthesized at queue time
268 // crop - a crop rectangle that's used as a hint to the consumer
269 // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h>
270 // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h>
271 // async - if the buffer is queued in asynchronous mode
272 // fence - a fence that the consumer must wait on before reading the buffer,
273 // set this to Fence::NO_FENCE if the buffer is ready immediately
Ruben Brunk1681d952014-06-27 15:51:55 -0700274 // sticky - the sticky transform set in Surface (only used by the LEGACY
275 // camera mode).
Andy McFadden3c256212013-08-16 14:55:39 -0700276 inline QueueBufferInput(int64_t timestamp, bool isAutoTimestamp,
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700277 const Rect& crop, int scalingMode, uint32_t transform, bool async,
Ruben Brunk1681d952014-06-27 15:51:55 -0700278 const sp<Fence>& fence, uint32_t sticky = 0)
Andy McFadden3c256212013-08-16 14:55:39 -0700279 : timestamp(timestamp), isAutoTimestamp(isAutoTimestamp), crop(crop),
Ruben Brunk1681d952014-06-27 15:51:55 -0700280 scalingMode(scalingMode), transform(transform), stickyTransform(sticky),
281 async(async), fence(fence) { }
Andy McFadden3c256212013-08-16 14:55:39 -0700282 inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp,
283 Rect* outCrop, int* outScalingMode, uint32_t* outTransform,
Ruben Brunk1681d952014-06-27 15:51:55 -0700284 bool* outAsync, sp<Fence>* outFence,
285 uint32_t* outStickyTransform = NULL) const {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700286 *outTimestamp = timestamp;
Andy McFadden3c256212013-08-16 14:55:39 -0700287 *outIsAutoTimestamp = bool(isAutoTimestamp);
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700288 *outCrop = crop;
289 *outScalingMode = scalingMode;
290 *outTransform = transform;
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700291 *outAsync = bool(async);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700292 *outFence = fence;
Ruben Brunk1681d952014-06-27 15:51:55 -0700293 if (outStickyTransform != NULL) {
294 *outStickyTransform = stickyTransform;
295 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700296 }
Jesse Hallc777b0b2012-06-28 12:52:05 -0700297
Mathias Agopiane1424282013-07-29 21:24:40 -0700298 // Flattenable protocol
299 size_t getFlattenedSize() const;
300 size_t getFdCount() const;
301 status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
302 status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700303
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700304 private:
305 int64_t timestamp;
Andy McFadden3c256212013-08-16 14:55:39 -0700306 int isAutoTimestamp;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700307 Rect crop;
308 int scalingMode;
309 uint32_t transform;
Ruben Brunk1681d952014-06-27 15:51:55 -0700310 uint32_t stickyTransform;
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700311 int async;
Jesse Hallc777b0b2012-06-28 12:52:05 -0700312 sp<Fence> fence;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700313 };
314
315 // QueueBufferOutput must be a POD structure
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800316 struct __attribute__ ((__packed__)) QueueBufferOutput {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700317 inline QueueBufferOutput() { }
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800318 // outWidth - filled with default width applied to the buffer
319 // outHeight - filled with default height applied to the buffer
320 // outTransformHint - filled with default transform applied to the buffer
321 // outNumPendingBuffers - num buffers queued that haven't yet been acquired
322 // (counting the currently queued buffer)
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700323 inline void deflate(uint32_t* outWidth,
Mathias Agopian2488b202012-04-20 17:19:28 -0700324 uint32_t* outHeight,
325 uint32_t* outTransformHint,
326 uint32_t* outNumPendingBuffers) const {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700327 *outWidth = width;
328 *outHeight = height;
329 *outTransformHint = transformHint;
Mathias Agopian2488b202012-04-20 17:19:28 -0700330 *outNumPendingBuffers = numPendingBuffers;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700331 }
332 inline void inflate(uint32_t inWidth, uint32_t inHeight,
Mathias Agopian2488b202012-04-20 17:19:28 -0700333 uint32_t inTransformHint, uint32_t inNumPendingBuffers) {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700334 width = inWidth;
335 height = inHeight;
336 transformHint = inTransformHint;
Mathias Agopian2488b202012-04-20 17:19:28 -0700337 numPendingBuffers = inNumPendingBuffers;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700338 }
339 private:
340 uint32_t width;
341 uint32_t height;
342 uint32_t transformHint;
Mathias Agopian2488b202012-04-20 17:19:28 -0700343 uint32_t numPendingBuffers;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700344 };
345
346 virtual status_t queueBuffer(int slot,
347 const QueueBufferInput& input, QueueBufferOutput* output) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800348
349 // cancelBuffer indicates that the client does not wish to fill in the
350 // buffer associated with slot and transfers ownership of the slot back to
351 // the server.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800352 //
353 // The buffer is not queued for use by the consumer.
354 //
355 // The buffer will not be overwritten until the fence signals. The fence
356 // will usually be the one obtained from dequeueBuffer.
Jesse Hall4c00cc12013-03-15 21:34:30 -0700357 virtual void cancelBuffer(int slot, const sp<Fence>& fence) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800358
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700359 // query retrieves some information for this surface
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800360 // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h>
361 //
362 // Return of a value other than NO_ERROR means an error has occurred:
363 // * NO_INIT - the buffer queue has been abandoned.
364 // * BAD_VALUE - what was out of range
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700365 virtual int query(int what, int* value) = 0;
Mathias Agopian80727112011-05-02 19:51:12 -0700366
Andy McFadden2adaf042012-12-18 09:49:45 -0800367 // connect attempts to connect a client API to the IGraphicBufferProducer.
368 // This must be called before any other IGraphicBufferProducer methods are
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800369 // called except for getAllocator. A consumer must be already connected.
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700370 //
371 // This method will fail if the connect was previously called on the
Andy McFadden2adaf042012-12-18 09:49:45 -0800372 // IGraphicBufferProducer and no corresponding disconnect call was made.
Mathias Agopian5bfc2452011-08-08 19:14:03 -0700373 //
Dan Stozaf0eaf252014-03-21 13:05:51 -0700374 // The listener is an optional binder callback object that can be used if
375 // the producer wants to be notified when the consumer releases a buffer
376 // back to the BufferQueue. It is also used to detect the death of the
377 // producer. If only the latter functionality is desired, there is a
378 // DummyProducerListener class in IProducerListener.h that can be used.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800379 //
380 // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
381 //
382 // The producerControlledByApp should be set to true if the producer is hosted
383 // by an untrusted process (typically app_process-forked processes). If both
384 // the producer and the consumer are app-controlled then all buffer queues
385 // will operate in async mode regardless of the async flag.
386 //
387 // Upon success, the output will be filled with meaningful data
388 // (refer to QueueBufferOutput documentation above).
389 //
390 // Return of a value other than NO_ERROR means an error has occurred:
391 // * NO_INIT - one of the following occurred:
392 // * the buffer queue was abandoned
393 // * no consumer has yet connected
394 // * BAD_VALUE - one of the following has occurred:
395 // * the producer is already connected
396 // * api was out of range (see above).
Igor Murashkin7ea777f2013-11-18 16:58:36 -0800397 // * output was NULL.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800398 // * DEAD_OBJECT - the token is hosted by an already-dead process
399 //
400 // Additional negative errors may be returned by the internals, they
401 // should be treated as opaque fatal unrecoverable errors.
Dan Stozaf0eaf252014-03-21 13:05:51 -0700402 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700403 int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700404
Andy McFadden2adaf042012-12-18 09:49:45 -0800405 // disconnect attempts to disconnect a client API from the
406 // IGraphicBufferProducer. Calling this method will cause any subsequent
407 // calls to other IGraphicBufferProducer methods to fail except for
408 // getAllocator and connect. Successfully calling connect after this will
409 // allow the other methods to succeed again.
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700410 //
Andy McFadden2adaf042012-12-18 09:49:45 -0800411 // This method will fail if the the IGraphicBufferProducer is not currently
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700412 // connected to the specified client API.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800413 //
414 // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
415 //
416 // Disconnecting from an abandoned IGraphicBufferProducer is legal and
417 // is considered a no-op.
418 //
419 // Return of a value other than NO_ERROR means an error has occurred:
420 // * BAD_VALUE - one of the following has occurred:
421 // * the api specified does not match the one that was connected
422 // * api was out of range (see above).
423 // * DEAD_OBJECT - the token is hosted by an already-dead process
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700424 virtual status_t disconnect(int api) = 0;
Jesse Hall399184a2014-03-03 15:42:54 -0800425
426 // Attaches a sideband buffer stream to the IGraphicBufferProducer.
427 //
428 // A sideband stream is a device-specific mechanism for passing buffers
429 // from the producer to the consumer without using dequeueBuffer/
430 // queueBuffer. If a sideband stream is present, the consumer can choose
431 // whether to acquire buffers from the sideband stream or from the queued
432 // buffers.
433 //
434 // Passing NULL or a different stream handle will detach the previous
435 // handle if any.
436 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0;
Dan Stoza29a3e902014-06-20 13:13:57 -0700437
438 // Allocates buffers based on the given dimensions/format.
439 //
440 // This function will allocate up to the maximum number of buffers
441 // permitted by the current BufferQueue configuration. It will use the
442 // given format, dimensions, and usage bits, which are interpreted in the
443 // same way as for dequeueBuffer, and the async flag must be set the same
444 // way as for dequeueBuffer to ensure that the correct number of buffers are
445 // allocated. This is most useful to avoid an allocation delay during
446 // dequeueBuffer. If there are already the maximum number of buffers
447 // allocated, this function has no effect.
448 virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800449 PixelFormat format, uint32_t usage) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800450};
451
452// ----------------------------------------------------------------------------
453
Andy McFadden2adaf042012-12-18 09:49:45 -0800454class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800455{
456public:
457 virtual status_t onTransact( uint32_t code,
458 const Parcel& data,
459 Parcel* reply,
460 uint32_t flags = 0);
461};
462
463// ----------------------------------------------------------------------------
464}; // namespace android
465
Andy McFadden2adaf042012-12-18 09:49:45 -0800466#endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H