blob: d6daca76598bc55b46236451fd3a4fa139142157 [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>
Dan Stoza5065a552015-03-17 16:23:42 -070031#include <ui/Region.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080032
33namespace android {
34// ----------------------------------------------------------------------------
35
Dan Stozaf0eaf252014-03-21 13:05:51 -070036class IProducerListener;
Jesse Hall399184a2014-03-03 15:42:54 -080037class NativeHandle;
Mathias Agopiane3c697f2013-02-14 17:11:02 -080038class Surface;
Mathias Agopianeafabcd2011-04-20 14:20:59 -070039
Andy McFadden0273adb2012-12-12 17:10:08 -080040/*
Andy McFadden466a1922013-01-08 11:25:51 -080041 * This class defines the Binder IPC interface for the producer side of
42 * a queue of graphics buffers. It's used to send graphics data from one
43 * component to another. For example, a class that decodes video for
44 * playback might use this to provide frames. This is typically done
Mathias Agopiane3c697f2013-02-14 17:11:02 -080045 * indirectly, through Surface.
Andy McFadden0273adb2012-12-12 17:10:08 -080046 *
Andy McFadden466a1922013-01-08 11:25:51 -080047 * The underlying mechanism is a BufferQueue, which implements
48 * BnGraphicBufferProducer. In normal operation, the producer calls
49 * dequeueBuffer() to get an empty buffer, fills it with data, then
50 * calls queueBuffer() to make it available to the consumer.
Andy McFadden0273adb2012-12-12 17:10:08 -080051 *
Andy McFadden2adaf042012-12-18 09:49:45 -080052 * This class was previously called ISurfaceTexture.
Andy McFadden0273adb2012-12-12 17:10:08 -080053 */
Andy McFadden2adaf042012-12-18 09:49:45 -080054class IGraphicBufferProducer : public IInterface
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080055{
56public:
Andy McFadden2adaf042012-12-18 09:49:45 -080057 DECLARE_META_INTERFACE(GraphicBufferProducer);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080058
Mathias Agopian80727112011-05-02 19:51:12 -070059 enum {
Igor Murashkin7d2d1602013-11-12 18:02:20 -080060 // A flag returned by dequeueBuffer when the client needs to call
61 // requestBuffer immediately thereafter.
Mathias Agopian80727112011-05-02 19:51:12 -070062 BUFFER_NEEDS_REALLOCATION = 0x1,
Igor Murashkin7d2d1602013-11-12 18:02:20 -080063 // A flag returned by dequeueBuffer when all mirrored slots should be
64 // released by the client. This flag should always be processed first.
Mathias Agopian80727112011-05-02 19:51:12 -070065 RELEASE_ALL_BUFFERS = 0x2,
66 };
Mathias Agopiana5c75c02011-03-31 19:10:24 -070067
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080068 // requestBuffer requests a new buffer for the given index. The server (i.e.
Andy McFadden2adaf042012-12-18 09:49:45 -080069 // the IGraphicBufferProducer implementation) assigns the newly created
70 // buffer to the given slot index, and the client is expected to mirror the
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080071 // slot->buffer mapping so that it's not necessary to transfer a
72 // GraphicBuffer for every dequeue operation.
Igor Murashkin7d2d1602013-11-12 18:02:20 -080073 //
74 // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
75 //
76 // Return of a value other than NO_ERROR means an error has occurred:
Pablo Ceballos583b1b32015-09-03 18:23:52 -070077 // * NO_INIT - the buffer queue has been abandoned or the producer is not
78 // connected.
Igor Murashkin7d2d1602013-11-12 18:02:20 -080079 // * BAD_VALUE - one of the two conditions occurred:
80 // * slot was out of range (see above)
81 // * buffer specified by the slot is not dequeued
Jamie Gennis7b305ff2011-07-19 12:08:33 -070082 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080083
Pablo Ceballosfa455352015-08-12 17:47:47 -070084 // setMaxDequeuedBufferCount sets the maximum number of buffers that can be
85 // dequeued by the producer at one time. If this method succeeds, buffer
86 // slots will be both unallocated and owned by the BufferQueue object (i.e.
87 // they are not owned by the producer or consumer). Calling this will also
88 // cause all buffer slots to be emptied. If the caller is caching the
89 // contents of the buffer slots, it should empty that cache after calling
90 // this method.
91 //
92 // This function should not be called when there are any currently dequeued
93 // buffer slots. Doing so will result in a BAD_VALUE error.
94 //
95 // The buffer count should be at least 1 (inclusive), but at most
96 // (NUM_BUFFER_SLOTS - the minimum undequeued buffer count) (exclusive). The
97 // minimum undequeued buffer count can be obtained by calling
98 // query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS).
99 //
100 // Return of a value other than NO_ERROR means an error has occurred:
101 // * NO_INIT - the buffer queue has been abandoned.
102 // * BAD_VALUE - one of the below conditions occurred:
Pablo Ceballos19e3e062015-08-19 16:16:06 -0700103 // * bufferCount was out of range (see above)
104 // * client has one or more buffers dequeued
105 // * this call would cause the maxBufferCount value to be exceeded
Pablo Ceballosfa455352015-08-12 17:47:47 -0700106 virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) = 0;
107
108 // Set the async flag if the producer intends to asynchronously queue
109 // buffers without blocking. Typically this is used for triple-buffering
110 // and/or when the swap interval is set to zero.
111 //
112 // Enabling async mode will internally allocate an additional buffer to
113 // allow for the asynchronous behavior. If it is not enabled queue/dequeue
114 // calls may block.
115 //
Pablo Ceballosfa455352015-08-12 17:47:47 -0700116 // Return of a value other than NO_ERROR means an error has occurred:
117 // * NO_INIT - the buffer queue has been abandoned.
Pablo Ceballosb687a282015-10-06 11:14:51 -0700118 // * BAD_VALUE - this call would cause the maxBufferCount value to be
119 // exceeded
Pablo Ceballosfa455352015-08-12 17:47:47 -0700120 virtual status_t setAsyncMode(bool async) = 0;
121
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800122 // dequeueBuffer requests a new buffer slot for the client to use. Ownership
123 // of the slot is transfered to the client, meaning that the server will not
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800124 // use the contents of the buffer associated with that slot.
125 //
126 // The slot index returned may or may not contain a buffer (client-side).
127 // If the slot is empty the client should call requestBuffer to assign a new
128 // buffer to that slot.
129 //
130 // Once the client is done filling this buffer, it is expected to transfer
131 // buffer ownership back to the server with either cancelBuffer on
132 // the dequeued slot or to fill in the contents of its associated buffer
133 // contents and call queueBuffer.
134 //
135 // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is
Mathias Agopiana5c75c02011-03-31 19:10:24 -0700136 // expected to call requestBuffer immediately.
Jesse Hallf7857542012-06-14 15:26:33 -0700137 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800138 // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is
139 // expected to release all of the mirrored slot->buffer mappings.
140 //
Jesse Hallf7857542012-06-14 15:26:33 -0700141 // The fence parameter will be updated to hold the fence associated with
142 // the buffer. The contents of the buffer must not be overwritten until the
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800143 // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written
Jesse Hallf7857542012-06-14 15:26:33 -0700144 // immediately.
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700145 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800146 // The width and height parameters must be no greater than the minimum of
147 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
148 // An error due to invalid dimensions might not be reported until
149 // updateTexImage() is called. If width and height are both zero, the
150 // default values specified by setDefaultBufferSize() are used instead.
151 //
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800152 // If the format is 0, the default format will be used.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800153 //
154 // The usage argument specifies gralloc buffer usage flags. The values
155 // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER. These
156 // will be merged with the usage flags specified by
157 // IGraphicBufferConsumer::setConsumerUsageBits.
158 //
159 // This call will block until a buffer is available to be dequeued. If
160 // both the producer and consumer are controlled by the app, then this call
161 // can never block and will return WOULD_BLOCK if no buffer is available.
162 //
163 // A non-negative value with flags set (see above) will be returned upon
164 // success.
165 //
166 // Return of a negative means an error has occurred:
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700167 // * NO_INIT - the buffer queue has been abandoned or the producer is not
168 // connected.
Dan Stoza9f3053d2014-03-06 15:14:33 -0800169 // * BAD_VALUE - both in async mode and buffer count was less than the
170 // max numbers of buffers that can be allocated at once.
171 // * INVALID_OPERATION - cannot attach the buffer because it would cause
172 // too many buffers to be dequeued, either because
173 // the producer already has a single buffer dequeued
174 // and did not set a buffer count, or because a
175 // buffer count was set and this call would cause
176 // it to be exceeded.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800177 // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled
178 // since both the producer/consumer are controlled by app
179 // * NO_MEMORY - out of memory, cannot allocate the graphics buffer.
180 //
181 // All other negative values are an unknown error returned downstream
182 // from the graphics allocator (typically errno).
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700183 virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w,
184 uint32_t h, PixelFormat format, uint32_t usage) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800185
Dan Stoza9f3053d2014-03-06 15:14:33 -0800186 // detachBuffer attempts to remove all ownership of the buffer in the given
187 // slot from the buffer queue. If this call succeeds, the slot will be
188 // freed, and there will be no way to obtain the buffer from this interface.
189 // The freed slot will remain unallocated until either it is selected to
190 // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached
191 // to the slot. The buffer must have already been dequeued, and the caller
192 // must already possesses the sp<GraphicBuffer> (i.e., must have called
193 // requestBuffer).
194 //
195 // Return of a value other than NO_ERROR means an error has occurred:
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700196 // * NO_INIT - the buffer queue has been abandoned or the producer is not
197 // connected.
Dan Stoza9f3053d2014-03-06 15:14:33 -0800198 // * BAD_VALUE - the given slot number is invalid, either because it is
199 // out of the range [0, NUM_BUFFER_SLOTS), or because the slot
200 // it refers to is not currently dequeued and requested.
201 virtual status_t detachBuffer(int slot) = 0;
202
Dan Stozad9822a32014-03-28 15:25:31 -0700203 // detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer,
204 // and detachBuffer in sequence, except for two things:
205 //
206 // 1) It is unnecessary to know the dimensions, format, or usage of the
207 // next buffer.
208 // 2) It will not block, since if it cannot find an appropriate buffer to
209 // return, it will return an error instead.
210 //
211 // Only slots that are free but still contain a GraphicBuffer will be
212 // considered, and the oldest of those will be returned. outBuffer is
213 // equivalent to outBuffer from the requestBuffer call, and outFence is
214 // equivalent to fence from the dequeueBuffer call.
215 //
216 // Return of a value other than NO_ERROR means an error has occurred:
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700217 // * NO_INIT - the buffer queue has been abandoned or the producer is not
218 // connected.
Dan Stozad9822a32014-03-28 15:25:31 -0700219 // * BAD_VALUE - either outBuffer or outFence were NULL.
220 // * NO_MEMORY - no slots were found that were both free and contained a
221 // GraphicBuffer.
222 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
223 sp<Fence>* outFence) = 0;
224
Dan Stoza9f3053d2014-03-06 15:14:33 -0800225 // attachBuffer attempts to transfer ownership of a buffer to the buffer
226 // queue. If this call succeeds, it will be as if this buffer was dequeued
227 // from the returned slot number. As such, this call will fail if attaching
228 // this buffer would cause too many buffers to be simultaneously dequeued.
229 //
230 // If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is
231 // expected to release all of the mirrored slot->buffer mappings.
232 //
233 // A non-negative value with flags set (see above) will be returned upon
234 // success.
235 //
236 // Return of a negative value means an error has occurred:
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700237 // * NO_INIT - the buffer queue has been abandoned or the producer is not
238 // connected.
Dan Stoza812ed062015-06-02 15:45:22 -0700239 // * BAD_VALUE - outSlot or buffer were NULL, invalid combination of
240 // async mode and buffer count override, or the generation
241 // number of the buffer did not match the buffer queue.
Dan Stoza9f3053d2014-03-06 15:14:33 -0800242 // * INVALID_OPERATION - cannot attach the buffer because it would cause
243 // too many buffers to be dequeued, either because
244 // the producer already has a single buffer dequeued
245 // and did not set a buffer count, or because a
246 // buffer count was set and this call would cause
247 // it to be exceeded.
248 // * WOULD_BLOCK - no buffer slot is currently available, and blocking is
249 // disabled since both the producer/consumer are
250 // controlled by the app.
251 virtual status_t attachBuffer(int* outSlot,
252 const sp<GraphicBuffer>& buffer) = 0;
253
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800254 // queueBuffer indicates that the client has finished filling in the
255 // contents of the buffer associated with slot and transfers ownership of
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800256 // that slot back to the server.
257 //
258 // It is not valid to call queueBuffer on a slot that is not owned
259 // by the client or one for which a buffer associated via requestBuffer
260 // (an attempt to do so will fail with a return value of BAD_VALUE).
261 //
262 // In addition, the input must be described by the client (as documented
263 // below). Any other properties (zero point, etc)
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800264 // are client-dependent, and should be documented by the client.
Mathias Agopian97c602c2011-07-19 15:24:46 -0700265 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800266 // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700267 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800268 // Upon success, the output will be filled with meaningful values
269 // (refer to the documentation below).
270 //
271 // Return of a value other than NO_ERROR means an error has occurred:
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700272 // * NO_INIT - the buffer queue has been abandoned or the producer is not
273 // connected.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800274 // * BAD_VALUE - one of the below conditions occurred:
275 // * fence was NULL
276 // * scaling mode was unknown
277 // * both in async mode and buffer count was less than the
278 // max numbers of buffers that can be allocated at once
279 // * slot index was out of range (see above).
280 // * the slot was not in the dequeued state
281 // * the slot was enqueued without requesting a buffer
282 // * crop rect is out of bounds of the buffer dimensions
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700283
Mathias Agopiane1424282013-07-29 21:24:40 -0700284 struct QueueBufferInput : public Flattenable<QueueBufferInput> {
285 friend class Flattenable<QueueBufferInput>;
Jesse Hallc777b0b2012-06-28 12:52:05 -0700286 inline QueueBufferInput(const Parcel& parcel);
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800287 // timestamp - a monotonically increasing value in nanoseconds
288 // isAutoTimestamp - if the timestamp was synthesized at queue time
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800289 // dataSpace - description of the contents, interpretation depends on format
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800290 // crop - a crop rectangle that's used as a hint to the consumer
291 // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h>
292 // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h>
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800293 // fence - a fence that the consumer must wait on before reading the buffer,
294 // set this to Fence::NO_FENCE if the buffer is ready immediately
Ruben Brunk1681d952014-06-27 15:51:55 -0700295 // sticky - the sticky transform set in Surface (only used by the LEGACY
296 // camera mode).
Andy McFadden3c256212013-08-16 14:55:39 -0700297 inline QueueBufferInput(int64_t timestamp, bool isAutoTimestamp,
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800298 android_dataspace dataSpace, const Rect& crop, int scalingMode,
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700299 uint32_t transform, const sp<Fence>& fence, uint32_t sticky = 0)
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800300 : timestamp(timestamp), isAutoTimestamp(isAutoTimestamp),
301 dataSpace(dataSpace), crop(crop), scalingMode(scalingMode),
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700302 transform(transform), stickyTransform(sticky), fence(fence),
303 surfaceDamage() { }
Andy McFadden3c256212013-08-16 14:55:39 -0700304 inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp,
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800305 android_dataspace* outDataSpace,
306 Rect* outCrop, int* outScalingMode,
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700307 uint32_t* outTransform, sp<Fence>* outFence,
Ruben Brunk1681d952014-06-27 15:51:55 -0700308 uint32_t* outStickyTransform = NULL) const {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700309 *outTimestamp = timestamp;
Andy McFadden3c256212013-08-16 14:55:39 -0700310 *outIsAutoTimestamp = bool(isAutoTimestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800311 *outDataSpace = dataSpace;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700312 *outCrop = crop;
313 *outScalingMode = scalingMode;
314 *outTransform = transform;
Jesse Hallc777b0b2012-06-28 12:52:05 -0700315 *outFence = fence;
Ruben Brunk1681d952014-06-27 15:51:55 -0700316 if (outStickyTransform != NULL) {
317 *outStickyTransform = stickyTransform;
318 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700319 }
Jesse Hallc777b0b2012-06-28 12:52:05 -0700320
Mathias Agopiane1424282013-07-29 21:24:40 -0700321 // Flattenable protocol
322 size_t getFlattenedSize() const;
323 size_t getFdCount() const;
324 status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
325 status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
Jesse Hallc777b0b2012-06-28 12:52:05 -0700326
Dan Stoza5065a552015-03-17 16:23:42 -0700327 const Region& getSurfaceDamage() const { return surfaceDamage; }
328 void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; }
329
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700330 private:
331 int64_t timestamp;
Andy McFadden3c256212013-08-16 14:55:39 -0700332 int isAutoTimestamp;
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800333 android_dataspace dataSpace;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700334 Rect crop;
335 int scalingMode;
336 uint32_t transform;
Ruben Brunk1681d952014-06-27 15:51:55 -0700337 uint32_t stickyTransform;
Jesse Hallc777b0b2012-06-28 12:52:05 -0700338 sp<Fence> fence;
Dan Stoza5065a552015-03-17 16:23:42 -0700339 Region surfaceDamage;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700340 };
341
342 // QueueBufferOutput must be a POD structure
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800343 struct __attribute__ ((__packed__)) QueueBufferOutput {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700344 inline QueueBufferOutput() { }
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800345 // outWidth - filled with default width applied to the buffer
346 // outHeight - filled with default height applied to the buffer
347 // outTransformHint - filled with default transform applied to the buffer
348 // outNumPendingBuffers - num buffers queued that haven't yet been acquired
349 // (counting the currently queued buffer)
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700350 inline void deflate(uint32_t* outWidth,
Mathias Agopian2488b202012-04-20 17:19:28 -0700351 uint32_t* outHeight,
352 uint32_t* outTransformHint,
353 uint32_t* outNumPendingBuffers) const {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700354 *outWidth = width;
355 *outHeight = height;
356 *outTransformHint = transformHint;
Mathias Agopian2488b202012-04-20 17:19:28 -0700357 *outNumPendingBuffers = numPendingBuffers;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700358 }
359 inline void inflate(uint32_t inWidth, uint32_t inHeight,
Mathias Agopian2488b202012-04-20 17:19:28 -0700360 uint32_t inTransformHint, uint32_t inNumPendingBuffers) {
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700361 width = inWidth;
362 height = inHeight;
363 transformHint = inTransformHint;
Mathias Agopian2488b202012-04-20 17:19:28 -0700364 numPendingBuffers = inNumPendingBuffers;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700365 }
366 private:
367 uint32_t width;
368 uint32_t height;
369 uint32_t transformHint;
Mathias Agopian2488b202012-04-20 17:19:28 -0700370 uint32_t numPendingBuffers;
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700371 };
372
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700373 virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
374 QueueBufferOutput* output) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800375
376 // cancelBuffer indicates that the client does not wish to fill in the
377 // buffer associated with slot and transfers ownership of the slot back to
378 // the server.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800379 //
380 // The buffer is not queued for use by the consumer.
381 //
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700382 // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
383 //
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800384 // The buffer will not be overwritten until the fence signals. The fence
385 // will usually be the one obtained from dequeueBuffer.
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700386 //
387 // Return of a value other than NO_ERROR means an error has occurred:
388 // * NO_INIT - the buffer queue has been abandoned or the producer is not
389 // connected.
390 // * BAD_VALUE - one of the below conditions occurred:
391 // * fence was NULL
392 // * slot index was out of range (see above).
393 // * the slot was not in the dequeued state
394 virtual status_t cancelBuffer(int slot, const sp<Fence>& fence) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800395
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700396 // query retrieves some information for this surface
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800397 // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h>
398 //
399 // Return of a value other than NO_ERROR means an error has occurred:
400 // * NO_INIT - the buffer queue has been abandoned.
401 // * BAD_VALUE - what was out of range
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700402 virtual int query(int what, int* value) = 0;
Mathias Agopian80727112011-05-02 19:51:12 -0700403
Andy McFadden2adaf042012-12-18 09:49:45 -0800404 // connect attempts to connect a client API to the IGraphicBufferProducer.
405 // This must be called before any other IGraphicBufferProducer methods are
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800406 // called except for getAllocator. A consumer must be already connected.
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700407 //
408 // This method will fail if the connect was previously called on the
Andy McFadden2adaf042012-12-18 09:49:45 -0800409 // IGraphicBufferProducer and no corresponding disconnect call was made.
Mathias Agopian5bfc2452011-08-08 19:14:03 -0700410 //
Dan Stozaf0eaf252014-03-21 13:05:51 -0700411 // The listener is an optional binder callback object that can be used if
412 // the producer wants to be notified when the consumer releases a buffer
413 // back to the BufferQueue. It is also used to detect the death of the
414 // producer. If only the latter functionality is desired, there is a
415 // DummyProducerListener class in IProducerListener.h that can be used.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800416 //
417 // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
418 //
419 // The producerControlledByApp should be set to true if the producer is hosted
420 // by an untrusted process (typically app_process-forked processes). If both
421 // the producer and the consumer are app-controlled then all buffer queues
422 // will operate in async mode regardless of the async flag.
423 //
424 // Upon success, the output will be filled with meaningful data
425 // (refer to QueueBufferOutput documentation above).
426 //
427 // Return of a value other than NO_ERROR means an error has occurred:
428 // * NO_INIT - one of the following occurred:
429 // * the buffer queue was abandoned
430 // * no consumer has yet connected
431 // * BAD_VALUE - one of the following has occurred:
432 // * the producer is already connected
433 // * api was out of range (see above).
Igor Murashkin7ea777f2013-11-18 16:58:36 -0800434 // * output was NULL.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800435 // * DEAD_OBJECT - the token is hosted by an already-dead process
436 //
437 // Additional negative errors may be returned by the internals, they
438 // should be treated as opaque fatal unrecoverable errors.
Dan Stozaf0eaf252014-03-21 13:05:51 -0700439 virtual status_t connect(const sp<IProducerListener>& listener,
Mathias Agopian365857d2013-09-11 19:35:45 -0700440 int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700441
Andy McFadden2adaf042012-12-18 09:49:45 -0800442 // disconnect attempts to disconnect a client API from the
443 // IGraphicBufferProducer. Calling this method will cause any subsequent
444 // calls to other IGraphicBufferProducer methods to fail except for
445 // getAllocator and connect. Successfully calling connect after this will
446 // allow the other methods to succeed again.
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700447 //
Andy McFadden2adaf042012-12-18 09:49:45 -0800448 // This method will fail if the the IGraphicBufferProducer is not currently
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700449 // connected to the specified client API.
Igor Murashkin7d2d1602013-11-12 18:02:20 -0800450 //
451 // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
452 //
453 // Disconnecting from an abandoned IGraphicBufferProducer is legal and
454 // is considered a no-op.
455 //
456 // Return of a value other than NO_ERROR means an error has occurred:
457 // * BAD_VALUE - one of the following has occurred:
458 // * the api specified does not match the one that was connected
459 // * api was out of range (see above).
460 // * DEAD_OBJECT - the token is hosted by an already-dead process
Jamie Gennisfe0a87b2011-07-13 19:12:20 -0700461 virtual status_t disconnect(int api) = 0;
Jesse Hall399184a2014-03-03 15:42:54 -0800462
463 // Attaches a sideband buffer stream to the IGraphicBufferProducer.
464 //
465 // A sideband stream is a device-specific mechanism for passing buffers
466 // from the producer to the consumer without using dequeueBuffer/
467 // queueBuffer. If a sideband stream is present, the consumer can choose
468 // whether to acquire buffers from the sideband stream or from the queued
469 // buffers.
470 //
471 // Passing NULL or a different stream handle will detach the previous
472 // handle if any.
473 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0;
Dan Stoza29a3e902014-06-20 13:13:57 -0700474
475 // Allocates buffers based on the given dimensions/format.
476 //
477 // This function will allocate up to the maximum number of buffers
478 // permitted by the current BufferQueue configuration. It will use the
479 // given format, dimensions, and usage bits, which are interpreted in the
480 // same way as for dequeueBuffer, and the async flag must be set the same
481 // way as for dequeueBuffer to ensure that the correct number of buffers are
482 // allocated. This is most useful to avoid an allocation delay during
483 // dequeueBuffer. If there are already the maximum number of buffers
484 // allocated, this function has no effect.
Pablo Ceballos567dbbb2015-08-26 18:59:08 -0700485 virtual void allocateBuffers(uint32_t width, uint32_t height,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800486 PixelFormat format, uint32_t usage) = 0;
Dan Stoza9de72932015-04-16 17:28:43 -0700487
488 // Sets whether dequeueBuffer is allowed to allocate new buffers.
489 //
490 // Normally dequeueBuffer does not discriminate between free slots which
491 // already have an allocated buffer and those which do not, and will
492 // allocate a new buffer if the slot doesn't have a buffer or if the slot's
493 // buffer doesn't match the requested size, format, or usage. This method
494 // allows the producer to restrict the eligible slots to those which already
495 // have an allocated buffer of the correct size, format, and usage. If no
496 // eligible slot is available, dequeueBuffer will block or return an error
497 // as usual.
498 virtual status_t allowAllocation(bool allow) = 0;
Dan Stoza812ed062015-06-02 15:45:22 -0700499
500 // Sets the current generation number of the BufferQueue.
501 //
502 // This generation number will be inserted into any buffers allocated by the
503 // BufferQueue, and any attempts to attach a buffer with a different
504 // generation number will fail. Buffers already in the queue are not
505 // affected and will retain their current generation number. The generation
506 // number defaults to 0.
507 virtual status_t setGenerationNumber(uint32_t generationNumber) = 0;
Dan Stozac6f30bd2015-06-08 09:32:50 -0700508
509 // Returns the name of the connected consumer.
510 virtual String8 getConsumerName() const = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -0700511
512 // Returns the number of the next frame which will be dequeued.
513 virtual uint64_t getNextFrameNumber() const = 0;
Pablo Ceballosccdfd602015-10-07 15:05:45 -0700514
515 // Used to enable/disable single buffer mode.
516 //
517 // In single buffer mode the last buffer that was dequeued will be cached
518 // and returned to all calls to dequeueBuffer and acquireBuffer. This allows
519 // the producer and consumer to simultaneously access the same buffer.
520 virtual status_t setSingleBufferMode(bool singleBufferMode) = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800521};
522
523// ----------------------------------------------------------------------------
524
Andy McFadden2adaf042012-12-18 09:49:45 -0800525class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800526{
527public:
528 virtual status_t onTransact( uint32_t code,
529 const Parcel& data,
530 Parcel* reply,
531 uint32_t flags = 0);
532};
533
534// ----------------------------------------------------------------------------
535}; // namespace android
536
Andy McFadden2adaf042012-12-18 09:49:45 -0800537#endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H