2012-08-21 20:37:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_GUI_BUFFERITEMCONSUMER_H
|
|
|
|
#define ANDROID_GUI_BUFFERITEMCONSUMER_H
|
|
|
|
|
|
|
|
#include <gui/ConsumerBase.h>
|
|
|
|
|
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
|
|
|
|
#include <utils/String8.h>
|
|
|
|
#include <utils/Vector.h>
|
|
|
|
#include <utils/threads.h>
|
|
|
|
|
|
|
|
#define ANDROID_GRAPHICS_BUFFERITEMCONSUMER_JNI_ID "mBufferItemConsumer"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2013-07-13 05:06:26 +00:00
|
|
|
class BufferQueue;
|
|
|
|
|
2012-08-21 20:37:35 +00:00
|
|
|
/**
|
|
|
|
* BufferItemConsumer is a BufferQueue consumer endpoint that allows clients
|
|
|
|
* access to the whole BufferItem entry from BufferQueue. Multiple buffers may
|
|
|
|
* be acquired at once, to be used concurrently by the client. This consumer can
|
|
|
|
* operate either in synchronous or asynchronous mode.
|
|
|
|
*/
|
|
|
|
class BufferItemConsumer: public ConsumerBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
|
|
|
|
|
|
|
|
typedef BufferQueue::BufferItem BufferItem;
|
|
|
|
|
|
|
|
enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT };
|
|
|
|
enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };
|
|
|
|
|
|
|
|
// Create a new buffer item consumer. The consumerUsage parameter determines
|
|
|
|
// the consumer usage flags passed to the graphics allocator. The
|
|
|
|
// bufferCount parameter specifies how many buffers can be locked for user
|
|
|
|
// access at the same time.
|
2013-07-17 05:56:09 +00:00
|
|
|
// controlledByApp tells whether this consumer is controlled by the
|
|
|
|
// application.
|
2013-07-13 05:06:26 +00:00
|
|
|
BufferItemConsumer(const sp<BufferQueue>& bq, uint32_t consumerUsage,
|
2012-08-21 20:37:35 +00:00
|
|
|
int bufferCount = BufferQueue::MIN_UNDEQUEUED_BUFFERS,
|
2013-07-17 05:56:09 +00:00
|
|
|
bool controlledByApp = false);
|
2012-08-21 20:37:35 +00:00
|
|
|
|
|
|
|
virtual ~BufferItemConsumer();
|
|
|
|
|
|
|
|
// set the name of the BufferItemConsumer that will be used to identify it in
|
|
|
|
// log messages.
|
|
|
|
void setName(const String8& name);
|
|
|
|
|
|
|
|
// Gets the next graphics buffer from the producer, filling out the
|
|
|
|
// passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue
|
|
|
|
// of buffers is empty, and INVALID_OPERATION if the maximum number of
|
|
|
|
// buffers is already acquired.
|
|
|
|
//
|
|
|
|
// Only a fixed number of buffers can be acquired at a time, determined by
|
|
|
|
// the construction-time bufferCount parameter. If INVALID_OPERATION is
|
|
|
|
// returned by acquireBuffer, then old buffers must be returned to the
|
|
|
|
// queue by calling releaseBuffer before more buffers can be acquired.
|
|
|
|
//
|
|
|
|
// If waitForFence is true, and the acquired BufferItem has a valid fence object,
|
|
|
|
// acquireBuffer will wait on the fence with no timeout before returning.
|
2013-06-28 20:52:40 +00:00
|
|
|
status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen,
|
|
|
|
bool waitForFence = true);
|
2012-08-21 20:37:35 +00:00
|
|
|
|
|
|
|
// Returns an acquired buffer to the queue, allowing it to be reused. Since
|
|
|
|
// only a fixed number of buffers may be acquired at a time, old buffers
|
|
|
|
// must be released by calling releaseBuffer to ensure new buffers can be
|
|
|
|
// acquired by acquireBuffer. Once a BufferItem is released, the caller must
|
|
|
|
// not access any members of the BufferItem, and should immediately remove
|
|
|
|
// all of its references to the BufferItem itself.
|
|
|
|
status_t releaseBuffer(const BufferItem &item,
|
|
|
|
const sp<Fence>& releaseFence = Fence::NO_FENCE);
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
sp<IGraphicBufferProducer> getProducerInterface() const { return getBufferQueue(); }
|
2012-08-21 20:37:35 +00:00
|
|
|
|
2013-04-16 18:24:40 +00:00
|
|
|
// setDefaultBufferSize is used to set the size of buffers returned by
|
|
|
|
// requestBuffers when a with and height of zero is requested.
|
|
|
|
status_t setDefaultBufferSize(uint32_t w, uint32_t h);
|
|
|
|
|
|
|
|
// setDefaultBufferFormat allows the BufferQueue to create
|
|
|
|
// GraphicBuffers of a defaultFormat if no format is specified
|
|
|
|
// in dequeueBuffer
|
|
|
|
status_t setDefaultBufferFormat(uint32_t defaultFormat);
|
2012-08-21 20:37:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_GUI_CPUCONSUMER_H
|