2010-12-20 19:27:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
#ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|
|
|
|
#define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/RefBase.h>
|
|
|
|
|
|
|
|
#include <binder/IInterface.h>
|
|
|
|
|
2012-06-14 22:26:33 +00:00
|
|
|
#include <ui/Fence.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
#include <ui/Rect.h>
|
2015-03-17 23:23:42 +00:00
|
|
|
#include <ui/Region.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-21 20:05:51 +00:00
|
|
|
class IProducerListener;
|
2014-03-03 23:42:54 +00:00
|
|
|
class NativeHandle;
|
2013-02-15 01:11:02 +00:00
|
|
|
class Surface;
|
2011-04-20 21:20:59 +00:00
|
|
|
|
2012-12-13 01:10:08 +00:00
|
|
|
/*
|
2013-01-08 19:25:51 +00:00
|
|
|
* This class defines the Binder IPC interface for the producer side of
|
|
|
|
* a queue of graphics buffers. It's used to send graphics data from one
|
|
|
|
* component to another. For example, a class that decodes video for
|
|
|
|
* playback might use this to provide frames. This is typically done
|
2013-02-15 01:11:02 +00:00
|
|
|
* indirectly, through Surface.
|
2012-12-13 01:10:08 +00:00
|
|
|
*
|
2013-01-08 19:25:51 +00:00
|
|
|
* The underlying mechanism is a BufferQueue, which implements
|
|
|
|
* BnGraphicBufferProducer. In normal operation, the producer calls
|
|
|
|
* dequeueBuffer() to get an empty buffer, fills it with data, then
|
|
|
|
* calls queueBuffer() to make it available to the consumer.
|
2012-12-13 01:10:08 +00:00
|
|
|
*
|
2012-12-18 17:49:45 +00:00
|
|
|
* This class was previously called ISurfaceTexture.
|
2012-12-13 01:10:08 +00:00
|
|
|
*/
|
2012-12-18 17:49:45 +00:00
|
|
|
class IGraphicBufferProducer : public IInterface
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-12-18 17:49:45 +00:00
|
|
|
DECLARE_META_INTERFACE(GraphicBufferProducer);
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-05-03 02:51:12 +00:00
|
|
|
enum {
|
2013-11-13 02:02:20 +00:00
|
|
|
// A flag returned by dequeueBuffer when the client needs to call
|
|
|
|
// requestBuffer immediately thereafter.
|
2011-05-03 02:51:12 +00:00
|
|
|
BUFFER_NEEDS_REALLOCATION = 0x1,
|
2013-11-13 02:02:20 +00:00
|
|
|
// A flag returned by dequeueBuffer when all mirrored slots should be
|
|
|
|
// released by the client. This flag should always be processed first.
|
2011-05-03 02:51:12 +00:00
|
|
|
RELEASE_ALL_BUFFERS = 0x2,
|
|
|
|
};
|
2011-04-01 02:10:24 +00:00
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
// requestBuffer requests a new buffer for the given index. The server (i.e.
|
2012-12-18 17:49:45 +00:00
|
|
|
// the IGraphicBufferProducer implementation) assigns the newly created
|
|
|
|
// buffer to the given slot index, and the client is expected to mirror the
|
2010-12-20 19:27:26 +00:00
|
|
|
// slot->buffer mapping so that it's not necessary to transfer a
|
|
|
|
// GraphicBuffer for every dequeue operation.
|
2013-11-13 02:02:20 +00:00
|
|
|
//
|
|
|
|
// The slot must be in the range of [0, NUM_BUFFER_SLOTS).
|
|
|
|
//
|
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
|
|
|
// * BAD_VALUE - one of the two conditions occurred:
|
|
|
|
// * slot was out of range (see above)
|
|
|
|
// * buffer specified by the slot is not dequeued
|
2011-07-19 19:08:33 +00:00
|
|
|
virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// setBufferCount sets the number of buffer slots available. Calling this
|
|
|
|
// will also cause all buffer slots to be emptied. The caller should empty
|
|
|
|
// its mirrored copy of the buffer slots when calling this method.
|
2013-11-13 02:02:20 +00:00
|
|
|
//
|
|
|
|
// This function should not be called when there are any dequeued buffer
|
|
|
|
// slots, doing so will result in a BAD_VALUE error returned.
|
|
|
|
//
|
2013-11-19 00:58:36 +00:00
|
|
|
// The buffer count should be at most NUM_BUFFER_SLOTS (inclusive), but at least
|
|
|
|
// the minimum undequeued buffer count (exclusive). The minimum value
|
|
|
|
// can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS).
|
|
|
|
// In particular the range is (minUndequeudBuffers, NUM_BUFFER_SLOTS].
|
|
|
|
//
|
|
|
|
// The buffer count may also be set to 0 (the default), to indicate that
|
|
|
|
// the producer does not wish to set a value.
|
2013-11-13 02:02:20 +00:00
|
|
|
//
|
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
|
|
|
// * BAD_VALUE - one of the below conditions occurred:
|
|
|
|
// * bufferCount was out of range (see above)
|
|
|
|
// * client has one or more buffers dequeued
|
2010-12-20 19:27:26 +00:00
|
|
|
virtual status_t setBufferCount(int bufferCount) = 0;
|
|
|
|
|
|
|
|
// dequeueBuffer requests a new buffer slot for the client to use. Ownership
|
|
|
|
// of the slot is transfered to the client, meaning that the server will not
|
2013-11-13 02:02:20 +00:00
|
|
|
// use the contents of the buffer associated with that slot.
|
|
|
|
//
|
|
|
|
// The slot index returned may or may not contain a buffer (client-side).
|
|
|
|
// If the slot is empty the client should call requestBuffer to assign a new
|
|
|
|
// buffer to that slot.
|
|
|
|
//
|
|
|
|
// Once the client is done filling this buffer, it is expected to transfer
|
|
|
|
// buffer ownership back to the server with either cancelBuffer on
|
|
|
|
// the dequeued slot or to fill in the contents of its associated buffer
|
|
|
|
// contents and call queueBuffer.
|
|
|
|
//
|
|
|
|
// If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is
|
2011-04-01 02:10:24 +00:00
|
|
|
// expected to call requestBuffer immediately.
|
2012-06-14 22:26:33 +00:00
|
|
|
//
|
2013-11-13 02:02:20 +00:00
|
|
|
// If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is
|
|
|
|
// expected to release all of the mirrored slot->buffer mappings.
|
|
|
|
//
|
2012-06-14 22:26:33 +00:00
|
|
|
// The fence parameter will be updated to hold the fence associated with
|
|
|
|
// the buffer. The contents of the buffer must not be overwritten until the
|
2013-11-13 02:02:20 +00:00
|
|
|
// fence signals. If the fence is Fence::NO_FENCE, the buffer may be written
|
2012-06-14 22:26:33 +00:00
|
|
|
// immediately.
|
2013-07-19 05:10:56 +00:00
|
|
|
//
|
2013-11-13 02:02:20 +00:00
|
|
|
// The async parameter sets whether we're in asynchronous mode for this
|
|
|
|
// dequeueBuffer() call.
|
|
|
|
//
|
|
|
|
// The width and height parameters must be no greater than the minimum of
|
|
|
|
// GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
|
|
|
|
// An error due to invalid dimensions might not be reported until
|
|
|
|
// updateTexImage() is called. If width and height are both zero, the
|
|
|
|
// default values specified by setDefaultBufferSize() are used instead.
|
|
|
|
//
|
2014-11-18 18:24:03 +00:00
|
|
|
// If the format is 0, the default format will be used.
|
2013-11-13 02:02:20 +00:00
|
|
|
//
|
|
|
|
// The usage argument specifies gralloc buffer usage flags. The values
|
|
|
|
// are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER. These
|
|
|
|
// will be merged with the usage flags specified by
|
|
|
|
// IGraphicBufferConsumer::setConsumerUsageBits.
|
|
|
|
//
|
|
|
|
// This call will block until a buffer is available to be dequeued. If
|
|
|
|
// both the producer and consumer are controlled by the app, then this call
|
|
|
|
// can never block and will return WOULD_BLOCK if no buffer is available.
|
|
|
|
//
|
|
|
|
// A non-negative value with flags set (see above) will be returned upon
|
|
|
|
// success.
|
|
|
|
//
|
|
|
|
// Return of a negative means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
2014-03-06 23:14:33 +00:00
|
|
|
// * BAD_VALUE - both in async mode and buffer count was less than the
|
|
|
|
// max numbers of buffers that can be allocated at once.
|
|
|
|
// * INVALID_OPERATION - cannot attach the buffer because it would cause
|
|
|
|
// too many buffers to be dequeued, either because
|
|
|
|
// the producer already has a single buffer dequeued
|
|
|
|
// and did not set a buffer count, or because a
|
|
|
|
// buffer count was set and this call would cause
|
|
|
|
// it to be exceeded.
|
2013-11-13 02:02:20 +00:00
|
|
|
// * WOULD_BLOCK - no buffer is currently available, and blocking is disabled
|
|
|
|
// since both the producer/consumer are controlled by app
|
|
|
|
// * NO_MEMORY - out of memory, cannot allocate the graphics buffer.
|
|
|
|
//
|
|
|
|
// All other negative values are an unknown error returned downstream
|
|
|
|
// from the graphics allocator (typically errno).
|
|
|
|
virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, bool async,
|
2014-11-18 18:24:03 +00:00
|
|
|
uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
// detachBuffer attempts to remove all ownership of the buffer in the given
|
|
|
|
// slot from the buffer queue. If this call succeeds, the slot will be
|
|
|
|
// freed, and there will be no way to obtain the buffer from this interface.
|
|
|
|
// The freed slot will remain unallocated until either it is selected to
|
|
|
|
// hold a freshly allocated buffer in dequeueBuffer or a buffer is attached
|
|
|
|
// to the slot. The buffer must have already been dequeued, and the caller
|
|
|
|
// must already possesses the sp<GraphicBuffer> (i.e., must have called
|
|
|
|
// requestBuffer).
|
|
|
|
//
|
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
|
|
|
// * BAD_VALUE - the given slot number is invalid, either because it is
|
|
|
|
// out of the range [0, NUM_BUFFER_SLOTS), or because the slot
|
|
|
|
// it refers to is not currently dequeued and requested.
|
|
|
|
virtual status_t detachBuffer(int slot) = 0;
|
|
|
|
|
2014-03-28 22:25:31 +00:00
|
|
|
// detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer,
|
|
|
|
// and detachBuffer in sequence, except for two things:
|
|
|
|
//
|
|
|
|
// 1) It is unnecessary to know the dimensions, format, or usage of the
|
|
|
|
// next buffer.
|
|
|
|
// 2) It will not block, since if it cannot find an appropriate buffer to
|
|
|
|
// return, it will return an error instead.
|
|
|
|
//
|
|
|
|
// Only slots that are free but still contain a GraphicBuffer will be
|
|
|
|
// considered, and the oldest of those will be returned. outBuffer is
|
|
|
|
// equivalent to outBuffer from the requestBuffer call, and outFence is
|
|
|
|
// equivalent to fence from the dequeueBuffer call.
|
|
|
|
//
|
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
|
|
|
// * BAD_VALUE - either outBuffer or outFence were NULL.
|
|
|
|
// * NO_MEMORY - no slots were found that were both free and contained a
|
|
|
|
// GraphicBuffer.
|
|
|
|
virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
|
|
|
|
sp<Fence>* outFence) = 0;
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
// attachBuffer attempts to transfer ownership of a buffer to the buffer
|
|
|
|
// queue. If this call succeeds, it will be as if this buffer was dequeued
|
|
|
|
// from the returned slot number. As such, this call will fail if attaching
|
|
|
|
// this buffer would cause too many buffers to be simultaneously dequeued.
|
|
|
|
//
|
|
|
|
// If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is
|
|
|
|
// expected to release all of the mirrored slot->buffer mappings.
|
|
|
|
//
|
|
|
|
// A non-negative value with flags set (see above) will be returned upon
|
|
|
|
// success.
|
|
|
|
//
|
|
|
|
// Return of a negative value means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
|
|
|
// * BAD_VALUE - outSlot or buffer were NULL or invalid combination of
|
|
|
|
// async mode and buffer count override.
|
|
|
|
// * INVALID_OPERATION - cannot attach the buffer because it would cause
|
|
|
|
// too many buffers to be dequeued, either because
|
|
|
|
// the producer already has a single buffer dequeued
|
|
|
|
// and did not set a buffer count, or because a
|
|
|
|
// buffer count was set and this call would cause
|
|
|
|
// it to be exceeded.
|
|
|
|
// * WOULD_BLOCK - no buffer slot is currently available, and blocking is
|
|
|
|
// disabled since both the producer/consumer are
|
|
|
|
// controlled by the app.
|
|
|
|
virtual status_t attachBuffer(int* outSlot,
|
|
|
|
const sp<GraphicBuffer>& buffer) = 0;
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
// queueBuffer indicates that the client has finished filling in the
|
|
|
|
// contents of the buffer associated with slot and transfers ownership of
|
2013-11-13 02:02:20 +00:00
|
|
|
// that slot back to the server.
|
|
|
|
//
|
|
|
|
// It is not valid to call queueBuffer on a slot that is not owned
|
|
|
|
// by the client or one for which a buffer associated via requestBuffer
|
|
|
|
// (an attempt to do so will fail with a return value of BAD_VALUE).
|
|
|
|
//
|
|
|
|
// In addition, the input must be described by the client (as documented
|
|
|
|
// below). Any other properties (zero point, etc)
|
2011-02-18 19:02:42 +00:00
|
|
|
// are client-dependent, and should be documented by the client.
|
2011-07-19 22:24:46 +00:00
|
|
|
//
|
2013-11-13 02:02:20 +00:00
|
|
|
// The slot must be in the range of [0, NUM_BUFFER_SLOTS).
|
|
|
|
//
|
|
|
|
// Upon success, the output will be filled with meaningful values
|
|
|
|
// (refer to the documentation below).
|
2013-07-19 05:10:56 +00:00
|
|
|
//
|
2013-11-13 02:02:20 +00:00
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
|
|
|
// * BAD_VALUE - one of the below conditions occurred:
|
|
|
|
// * fence was NULL
|
|
|
|
// * scaling mode was unknown
|
|
|
|
// * both in async mode and buffer count was less than the
|
|
|
|
// max numbers of buffers that can be allocated at once
|
|
|
|
// * slot index was out of range (see above).
|
|
|
|
// * the slot was not in the dequeued state
|
|
|
|
// * the slot was enqueued without requesting a buffer
|
|
|
|
// * crop rect is out of bounds of the buffer dimensions
|
2012-04-09 23:14:01 +00:00
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
struct QueueBufferInput : public Flattenable<QueueBufferInput> {
|
|
|
|
friend class Flattenable<QueueBufferInput>;
|
2012-06-28 19:52:05 +00:00
|
|
|
inline QueueBufferInput(const Parcel& parcel);
|
2013-11-13 02:02:20 +00:00
|
|
|
// timestamp - a monotonically increasing value in nanoseconds
|
|
|
|
// isAutoTimestamp - if the timestamp was synthesized at queue time
|
2015-02-20 00:10:43 +00:00
|
|
|
// dataSpace - description of the contents, interpretation depends on format
|
2013-11-13 02:02:20 +00:00
|
|
|
// crop - a crop rectangle that's used as a hint to the consumer
|
|
|
|
// scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h>
|
|
|
|
// transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h>
|
|
|
|
// async - if the buffer is queued in asynchronous mode
|
|
|
|
// fence - a fence that the consumer must wait on before reading the buffer,
|
|
|
|
// set this to Fence::NO_FENCE if the buffer is ready immediately
|
2014-06-27 22:51:55 +00:00
|
|
|
// sticky - the sticky transform set in Surface (only used by the LEGACY
|
|
|
|
// camera mode).
|
2013-08-16 21:55:39 +00:00
|
|
|
inline QueueBufferInput(int64_t timestamp, bool isAutoTimestamp,
|
2015-02-20 00:10:43 +00:00
|
|
|
android_dataspace dataSpace, const Rect& crop, int scalingMode,
|
|
|
|
uint32_t transform, bool async, const sp<Fence>& fence,
|
|
|
|
uint32_t sticky = 0)
|
|
|
|
: timestamp(timestamp), isAutoTimestamp(isAutoTimestamp),
|
|
|
|
dataSpace(dataSpace), crop(crop), scalingMode(scalingMode),
|
|
|
|
transform(transform), stickyTransform(sticky),
|
2015-03-17 23:23:42 +00:00
|
|
|
async(async), fence(fence), surfaceDamage() { }
|
2013-08-16 21:55:39 +00:00
|
|
|
inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp,
|
2015-02-20 00:10:43 +00:00
|
|
|
android_dataspace* outDataSpace,
|
|
|
|
Rect* outCrop, int* outScalingMode,
|
|
|
|
uint32_t* outTransform, bool* outAsync, sp<Fence>* outFence,
|
2014-06-27 22:51:55 +00:00
|
|
|
uint32_t* outStickyTransform = NULL) const {
|
2012-04-09 23:14:01 +00:00
|
|
|
*outTimestamp = timestamp;
|
2013-08-16 21:55:39 +00:00
|
|
|
*outIsAutoTimestamp = bool(isAutoTimestamp);
|
2015-02-20 00:10:43 +00:00
|
|
|
*outDataSpace = dataSpace;
|
2012-04-09 23:14:01 +00:00
|
|
|
*outCrop = crop;
|
|
|
|
*outScalingMode = scalingMode;
|
|
|
|
*outTransform = transform;
|
2013-07-19 05:10:56 +00:00
|
|
|
*outAsync = bool(async);
|
2012-06-28 19:52:05 +00:00
|
|
|
*outFence = fence;
|
2014-06-27 22:51:55 +00:00
|
|
|
if (outStickyTransform != NULL) {
|
|
|
|
*outStickyTransform = stickyTransform;
|
|
|
|
}
|
2012-04-09 23:14:01 +00:00
|
|
|
}
|
2012-06-28 19:52:05 +00:00
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
// Flattenable protocol
|
|
|
|
size_t getFlattenedSize() const;
|
|
|
|
size_t getFdCount() const;
|
|
|
|
status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
|
|
|
|
status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
|
2012-06-28 19:52:05 +00:00
|
|
|
|
2015-03-17 23:23:42 +00:00
|
|
|
const Region& getSurfaceDamage() const { return surfaceDamage; }
|
|
|
|
void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; }
|
|
|
|
|
2012-04-09 23:14:01 +00:00
|
|
|
private:
|
|
|
|
int64_t timestamp;
|
2013-08-16 21:55:39 +00:00
|
|
|
int isAutoTimestamp;
|
2015-02-20 00:10:43 +00:00
|
|
|
android_dataspace dataSpace;
|
2012-04-09 23:14:01 +00:00
|
|
|
Rect crop;
|
|
|
|
int scalingMode;
|
|
|
|
uint32_t transform;
|
2014-06-27 22:51:55 +00:00
|
|
|
uint32_t stickyTransform;
|
2013-07-19 05:10:56 +00:00
|
|
|
int async;
|
2012-06-28 19:52:05 +00:00
|
|
|
sp<Fence> fence;
|
2015-03-17 23:23:42 +00:00
|
|
|
Region surfaceDamage;
|
2012-04-09 23:14:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// QueueBufferOutput must be a POD structure
|
2013-11-13 02:02:20 +00:00
|
|
|
struct __attribute__ ((__packed__)) QueueBufferOutput {
|
2012-04-09 23:14:01 +00:00
|
|
|
inline QueueBufferOutput() { }
|
2013-11-13 02:02:20 +00:00
|
|
|
// outWidth - filled with default width applied to the buffer
|
|
|
|
// outHeight - filled with default height applied to the buffer
|
|
|
|
// outTransformHint - filled with default transform applied to the buffer
|
|
|
|
// outNumPendingBuffers - num buffers queued that haven't yet been acquired
|
|
|
|
// (counting the currently queued buffer)
|
2012-04-09 23:14:01 +00:00
|
|
|
inline void deflate(uint32_t* outWidth,
|
2012-04-21 00:19:28 +00:00
|
|
|
uint32_t* outHeight,
|
|
|
|
uint32_t* outTransformHint,
|
|
|
|
uint32_t* outNumPendingBuffers) const {
|
2012-04-09 23:14:01 +00:00
|
|
|
*outWidth = width;
|
|
|
|
*outHeight = height;
|
|
|
|
*outTransformHint = transformHint;
|
2012-04-21 00:19:28 +00:00
|
|
|
*outNumPendingBuffers = numPendingBuffers;
|
2012-04-09 23:14:01 +00:00
|
|
|
}
|
|
|
|
inline void inflate(uint32_t inWidth, uint32_t inHeight,
|
2012-04-21 00:19:28 +00:00
|
|
|
uint32_t inTransformHint, uint32_t inNumPendingBuffers) {
|
2012-04-09 23:14:01 +00:00
|
|
|
width = inWidth;
|
|
|
|
height = inHeight;
|
|
|
|
transformHint = inTransformHint;
|
2012-04-21 00:19:28 +00:00
|
|
|
numPendingBuffers = inNumPendingBuffers;
|
2012-04-09 23:14:01 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t transformHint;
|
2012-04-21 00:19:28 +00:00
|
|
|
uint32_t numPendingBuffers;
|
2012-04-09 23:14:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual status_t queueBuffer(int slot,
|
|
|
|
const QueueBufferInput& input, QueueBufferOutput* output) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// cancelBuffer indicates that the client does not wish to fill in the
|
|
|
|
// buffer associated with slot and transfers ownership of the slot back to
|
|
|
|
// the server.
|
2013-11-13 02:02:20 +00:00
|
|
|
//
|
|
|
|
// The buffer is not queued for use by the consumer.
|
|
|
|
//
|
|
|
|
// The buffer will not be overwritten until the fence signals. The fence
|
|
|
|
// will usually be the one obtained from dequeueBuffer.
|
2013-03-16 04:34:30 +00:00
|
|
|
virtual void cancelBuffer(int slot, const sp<Fence>& fence) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
// query retrieves some information for this surface
|
2013-11-13 02:02:20 +00:00
|
|
|
// 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h>
|
|
|
|
//
|
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * NO_INIT - the buffer queue has been abandoned.
|
|
|
|
// * BAD_VALUE - what was out of range
|
2011-04-20 21:20:59 +00:00
|
|
|
virtual int query(int what, int* value) = 0;
|
2011-05-03 02:51:12 +00:00
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
// connect attempts to connect a client API to the IGraphicBufferProducer.
|
|
|
|
// This must be called before any other IGraphicBufferProducer methods are
|
2013-11-13 02:02:20 +00:00
|
|
|
// called except for getAllocator. A consumer must be already connected.
|
2011-07-14 02:12:20 +00:00
|
|
|
//
|
|
|
|
// This method will fail if the connect was previously called on the
|
2012-12-18 17:49:45 +00:00
|
|
|
// IGraphicBufferProducer and no corresponding disconnect call was made.
|
2011-08-09 02:14:03 +00:00
|
|
|
//
|
2014-03-21 20:05:51 +00:00
|
|
|
// The listener is an optional binder callback object that can be used if
|
|
|
|
// the producer wants to be notified when the consumer releases a buffer
|
|
|
|
// back to the BufferQueue. It is also used to detect the death of the
|
|
|
|
// producer. If only the latter functionality is desired, there is a
|
|
|
|
// DummyProducerListener class in IProducerListener.h that can be used.
|
2013-11-13 02:02:20 +00:00
|
|
|
//
|
|
|
|
// The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
|
|
|
|
//
|
|
|
|
// The producerControlledByApp should be set to true if the producer is hosted
|
|
|
|
// by an untrusted process (typically app_process-forked processes). If both
|
|
|
|
// the producer and the consumer are app-controlled then all buffer queues
|
|
|
|
// will operate in async mode regardless of the async flag.
|
|
|
|
//
|
|
|
|
// Upon success, the output will be filled with meaningful data
|
|
|
|
// (refer to QueueBufferOutput documentation above).
|
|
|
|
//
|
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * NO_INIT - one of the following occurred:
|
|
|
|
// * the buffer queue was abandoned
|
|
|
|
// * no consumer has yet connected
|
|
|
|
// * BAD_VALUE - one of the following has occurred:
|
|
|
|
// * the producer is already connected
|
|
|
|
// * api was out of range (see above).
|
2013-11-19 00:58:36 +00:00
|
|
|
// * output was NULL.
|
2013-11-13 02:02:20 +00:00
|
|
|
// * DEAD_OBJECT - the token is hosted by an already-dead process
|
|
|
|
//
|
|
|
|
// Additional negative errors may be returned by the internals, they
|
|
|
|
// should be treated as opaque fatal unrecoverable errors.
|
2014-03-21 20:05:51 +00:00
|
|
|
virtual status_t connect(const sp<IProducerListener>& listener,
|
2013-09-12 02:35:45 +00:00
|
|
|
int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
|
2011-07-14 02:12:20 +00:00
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
// disconnect attempts to disconnect a client API from the
|
|
|
|
// IGraphicBufferProducer. Calling this method will cause any subsequent
|
|
|
|
// calls to other IGraphicBufferProducer methods to fail except for
|
|
|
|
// getAllocator and connect. Successfully calling connect after this will
|
|
|
|
// allow the other methods to succeed again.
|
2011-07-14 02:12:20 +00:00
|
|
|
//
|
2012-12-18 17:49:45 +00:00
|
|
|
// This method will fail if the the IGraphicBufferProducer is not currently
|
2011-07-14 02:12:20 +00:00
|
|
|
// connected to the specified client API.
|
2013-11-13 02:02:20 +00:00
|
|
|
//
|
|
|
|
// The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
|
|
|
|
//
|
|
|
|
// Disconnecting from an abandoned IGraphicBufferProducer is legal and
|
|
|
|
// is considered a no-op.
|
|
|
|
//
|
|
|
|
// Return of a value other than NO_ERROR means an error has occurred:
|
|
|
|
// * BAD_VALUE - one of the following has occurred:
|
|
|
|
// * the api specified does not match the one that was connected
|
|
|
|
// * api was out of range (see above).
|
|
|
|
// * DEAD_OBJECT - the token is hosted by an already-dead process
|
2011-07-14 02:12:20 +00:00
|
|
|
virtual status_t disconnect(int api) = 0;
|
2014-03-03 23:42:54 +00:00
|
|
|
|
|
|
|
// Attaches a sideband buffer stream to the IGraphicBufferProducer.
|
|
|
|
//
|
|
|
|
// A sideband stream is a device-specific mechanism for passing buffers
|
|
|
|
// from the producer to the consumer without using dequeueBuffer/
|
|
|
|
// queueBuffer. If a sideband stream is present, the consumer can choose
|
|
|
|
// whether to acquire buffers from the sideband stream or from the queued
|
|
|
|
// buffers.
|
|
|
|
//
|
|
|
|
// Passing NULL or a different stream handle will detach the previous
|
|
|
|
// handle if any.
|
|
|
|
virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0;
|
2014-06-20 20:13:57 +00:00
|
|
|
|
|
|
|
// Allocates buffers based on the given dimensions/format.
|
|
|
|
//
|
|
|
|
// This function will allocate up to the maximum number of buffers
|
|
|
|
// permitted by the current BufferQueue configuration. It will use the
|
|
|
|
// given format, dimensions, and usage bits, which are interpreted in the
|
|
|
|
// same way as for dequeueBuffer, and the async flag must be set the same
|
|
|
|
// way as for dequeueBuffer to ensure that the correct number of buffers are
|
|
|
|
// allocated. This is most useful to avoid an allocation delay during
|
|
|
|
// dequeueBuffer. If there are already the maximum number of buffers
|
|
|
|
// allocated, this function has no effect.
|
|
|
|
virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
|
2014-11-18 18:24:03 +00:00
|
|
|
PixelFormat format, uint32_t usage) = 0;
|
2015-04-17 00:28:43 +00:00
|
|
|
|
|
|
|
// Sets whether dequeueBuffer is allowed to allocate new buffers.
|
|
|
|
//
|
|
|
|
// Normally dequeueBuffer does not discriminate between free slots which
|
|
|
|
// already have an allocated buffer and those which do not, and will
|
|
|
|
// allocate a new buffer if the slot doesn't have a buffer or if the slot's
|
|
|
|
// buffer doesn't match the requested size, format, or usage. This method
|
|
|
|
// allows the producer to restrict the eligible slots to those which already
|
|
|
|
// have an allocated buffer of the correct size, format, and usage. If no
|
|
|
|
// eligible slot is available, dequeueBuffer will block or return an error
|
|
|
|
// as usual.
|
|
|
|
virtual status_t allowAllocation(bool allow) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual status_t onTransact( uint32_t code,
|
|
|
|
const Parcel& data,
|
|
|
|
Parcel* reply,
|
|
|
|
uint32_t flags = 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
#endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|