2012-01-22 23:26:27 +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_BUFFERQUEUE_H
|
|
|
|
#define ANDROID_GUI_BUFFERQUEUE_H
|
|
|
|
|
2014-04-22 21:12:55 +00:00
|
|
|
#include <gui/BufferQueueDefs.h>
|
|
|
|
#include <gui/IGraphicBufferConsumer.h>
|
|
|
|
#include <gui/IGraphicBufferProducer.h>
|
2013-08-01 03:09:53 +00:00
|
|
|
#include <gui/IConsumerListener.h>
|
2012-01-22 23:26:27 +00:00
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
// These are only required to keep other parts of the framework with incomplete
|
|
|
|
// dependencies building successfully
|
|
|
|
#include <gui/IGraphicBufferAlloc.h>
|
2012-01-22 23:26:27 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2014-04-22 21:12:55 +00:00
|
|
|
class BufferQueue {
|
2012-01-22 23:26:27 +00:00
|
|
|
public:
|
2013-11-13 02:02:20 +00:00
|
|
|
// BufferQueue will keep track of at most this value of buffers.
|
|
|
|
// Attempts at runtime to increase the number of buffers past this will fail.
|
2014-04-09 23:14:51 +00:00
|
|
|
enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
|
2013-11-13 02:02:20 +00:00
|
|
|
// Used as a placeholder slot# when the value isn't pointing to an existing buffer.
|
|
|
|
enum { INVALID_BUFFER_SLOT = IGraphicBufferConsumer::BufferItem::INVALID_BUFFER_SLOT };
|
|
|
|
// Alias to <IGraphicBufferConsumer.h> -- please scope from there in future code!
|
|
|
|
enum {
|
|
|
|
NO_BUFFER_AVAILABLE = IGraphicBufferConsumer::NO_BUFFER_AVAILABLE,
|
|
|
|
PRESENT_LATER = IGraphicBufferConsumer::PRESENT_LATER,
|
|
|
|
};
|
2012-01-22 23:26:27 +00:00
|
|
|
|
2012-08-31 01:36:22 +00:00
|
|
|
// When in async mode we reserve two slots in order to guarantee that the
|
|
|
|
// producer and consumer can run asynchronously.
|
|
|
|
enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 };
|
|
|
|
|
2013-08-01 03:09:53 +00:00
|
|
|
// for backward source compatibility
|
|
|
|
typedef ::android::ConsumerListener ConsumerListener;
|
2014-04-22 21:12:55 +00:00
|
|
|
typedef IGraphicBufferConsumer::BufferItem BufferItem;
|
2012-03-15 21:01:24 +00:00
|
|
|
|
|
|
|
// ProxyConsumerListener is a ConsumerListener implementation that keeps a weak
|
|
|
|
// reference to the actual consumer object. It forwards all calls to that
|
|
|
|
// consumer object so long as it exists.
|
|
|
|
//
|
|
|
|
// This class exists to avoid having a circular reference between the
|
|
|
|
// BufferQueue object and the consumer object. The reason this can't be a weak
|
|
|
|
// reference in the BufferQueue class is because we're planning to expose the
|
|
|
|
// consumer side of a BufferQueue as a binder interface, which doesn't support
|
|
|
|
// weak references.
|
2013-08-01 03:09:53 +00:00
|
|
|
class ProxyConsumerListener : public BnConsumerListener {
|
2012-03-15 21:01:24 +00:00
|
|
|
public:
|
2013-08-01 03:09:53 +00:00
|
|
|
ProxyConsumerListener(const wp<ConsumerListener>& consumerListener);
|
2012-03-15 21:01:24 +00:00
|
|
|
virtual ~ProxyConsumerListener();
|
|
|
|
virtual void onFrameAvailable();
|
|
|
|
virtual void onBuffersReleased();
|
2014-03-03 23:42:54 +00:00
|
|
|
virtual void onSidebandStreamChanged();
|
2012-03-15 21:01:24 +00:00
|
|
|
private:
|
2013-08-01 03:09:53 +00:00
|
|
|
// mConsumerListener is a weak reference to the IConsumerListener. This is
|
2012-03-15 21:01:24 +00:00
|
|
|
// the raison d'etre of ProxyConsumerListener.
|
2013-08-01 03:09:53 +00:00
|
|
|
wp<ConsumerListener> mConsumerListener;
|
2012-01-22 23:26:27 +00:00
|
|
|
};
|
|
|
|
|
2012-08-28 01:48:37 +00:00
|
|
|
// BufferQueue manages a pool of gralloc memory slots to be used by
|
2013-07-17 05:56:09 +00:00
|
|
|
// producers and consumers. allocator is used to allocate all the
|
|
|
|
// needed gralloc buffers.
|
2014-03-12 17:17:20 +00:00
|
|
|
static void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
|
|
|
|
sp<IGraphicBufferConsumer>* outConsumer,
|
|
|
|
const sp<IGraphicBufferAlloc>& allocator = NULL);
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
private:
|
2014-04-22 21:12:55 +00:00
|
|
|
BufferQueue(); // Create through createBufferQueue
|
2012-01-22 23:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_GUI_BUFFERQUEUE_H
|