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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "BufferQueue"
|
2012-02-24 03:27:23 +00:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
2012-03-15 21:01:24 +00:00
|
|
|
//#define LOG_NDEBUG 0
|
2012-01-22 23:26:27 +00:00
|
|
|
|
|
|
|
#include <gui/BufferQueue.h>
|
2014-03-03 18:16:19 +00:00
|
|
|
#include <gui/BufferQueueCore.h>
|
2012-01-22 23:26:27 +00:00
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
namespace android {
|
2012-01-22 23:26:27 +00:00
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
BufferQueue::ProxyConsumerListener::ProxyConsumerListener(
|
|
|
|
const wp<ConsumerListener>& consumerListener):
|
|
|
|
mConsumerListener(consumerListener) {}
|
2012-03-02 06:11:25 +00:00
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
BufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {}
|
2012-01-22 23:26:27 +00:00
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
void BufferQueue::ProxyConsumerListener::onFrameAvailable() {
|
|
|
|
sp<ConsumerListener> listener(mConsumerListener.promote());
|
|
|
|
if (listener != NULL) {
|
|
|
|
listener->onFrameAvailable();
|
|
|
|
}
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
void BufferQueue::ProxyConsumerListener::onBuffersReleased() {
|
|
|
|
sp<ConsumerListener> listener(mConsumerListener.promote());
|
|
|
|
if (listener != NULL) {
|
|
|
|
listener->onBuffersReleased();
|
2012-05-10 09:22:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-12 17:17:20 +00:00
|
|
|
void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
|
|
|
|
sp<IGraphicBufferConsumer>* outConsumer,
|
|
|
|
const sp<IGraphicBufferAlloc>& allocator) {
|
|
|
|
LOG_ALWAYS_FATAL_IF(outProducer == NULL,
|
|
|
|
"BufferQueue: outProducer must not be NULL");
|
2014-03-06 23:14:33 +00:00
|
|
|
LOG_ALWAYS_FATAL_IF(outConsumer == NULL,
|
|
|
|
"BufferQueue: outConsumer must not be NULL");
|
|
|
|
|
|
|
|
sp<BufferQueueCore> core(new BufferQueueCore(allocator));
|
2014-04-07 23:33:59 +00:00
|
|
|
LOG_ALWAYS_FATAL_IF(core == NULL,
|
|
|
|
"BufferQueue: failed to create BufferQueueCore");
|
|
|
|
|
|
|
|
sp<IGraphicBufferProducer> producer(new BufferQueueProducer(core));
|
|
|
|
LOG_ALWAYS_FATAL_IF(producer == NULL,
|
|
|
|
"BufferQueue: failed to create BufferQueueProducer");
|
|
|
|
|
|
|
|
sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core));
|
|
|
|
LOG_ALWAYS_FATAL_IF(consumer == NULL,
|
|
|
|
"BufferQueue: failed to create BufferQueueConsumer");
|
|
|
|
|
|
|
|
*outProducer = producer;
|
|
|
|
*outConsumer = consumer;
|
2014-03-06 23:14:33 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:56:09 +00:00
|
|
|
BufferQueue::BufferQueue(const sp<IGraphicBufferAlloc>& allocator) :
|
2014-03-03 18:16:19 +00:00
|
|
|
mProducer(),
|
|
|
|
mConsumer()
|
2012-01-22 23:26:27 +00:00
|
|
|
{
|
2014-03-03 18:16:19 +00:00
|
|
|
sp<BufferQueueCore> core(new BufferQueueCore(allocator));
|
|
|
|
mProducer = new BufferQueueProducer(core);
|
|
|
|
mConsumer = new BufferQueueConsumer(core);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
BufferQueue::~BufferQueue() {}
|
2012-02-23 22:35:13 +00:00
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
void BufferQueue::binderDied(const wp<IBinder>& who) {
|
|
|
|
mProducer->binderDied(who);
|
2012-02-23 22:35:13 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
int BufferQueue::query(int what, int* outValue) {
|
|
|
|
return mProducer->query(what, outValue);
|
2012-02-23 22:35:13 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
status_t BufferQueue::setBufferCount(int bufferCount) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mProducer->setBufferCount(bufferCount);
|
2012-01-30 23:51:27 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
status_t BufferQueue::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mProducer->requestBuffer(slot, buf);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 05:10:56 +00:00
|
|
|
status_t BufferQueue::dequeueBuffer(int *outBuf, sp<Fence>* outFence, bool async,
|
2012-06-14 22:26:33 +00:00
|
|
|
uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mProducer->dequeueBuffer(outBuf, outFence, async, w, h, format, usage);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
status_t BufferQueue::detachProducerBuffer(int slot) {
|
|
|
|
return mProducer->detachBuffer(slot);
|
|
|
|
}
|
|
|
|
|
2014-03-28 22:25:31 +00:00
|
|
|
status_t BufferQueue::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
|
|
|
|
sp<Fence>* outFence) {
|
|
|
|
return mProducer->detachNextBuffer(outBuffer, outFence);
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
status_t BufferQueue::attachProducerBuffer(int* slot,
|
|
|
|
const sp<GraphicBuffer>& buffer) {
|
|
|
|
return mProducer->attachBuffer(slot, buffer);
|
|
|
|
}
|
|
|
|
|
2012-04-09 23:14:01 +00:00
|
|
|
status_t BufferQueue::queueBuffer(int buf,
|
|
|
|
const QueueBufferInput& input, QueueBufferOutput* output) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mProducer->queueBuffer(buf, input, output);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2013-03-16 04:34:30 +00:00
|
|
|
void BufferQueue::cancelBuffer(int buf, const sp<Fence>& fence) {
|
2014-03-03 18:16:19 +00:00
|
|
|
mProducer->cancelBuffer(buf, fence);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-21 20:05:51 +00:00
|
|
|
status_t BufferQueue::connect(const sp<IProducerListener>& listener,
|
2013-09-12 02:35:45 +00:00
|
|
|
int api, bool producerControlledByApp, QueueBufferOutput* output) {
|
2014-03-21 20:05:51 +00:00
|
|
|
return mProducer->connect(listener, api, producerControlledByApp, output);
|
2013-09-12 02:35:45 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
status_t BufferQueue::disconnect(int api) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mProducer->disconnect(api);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 23:42:54 +00:00
|
|
|
status_t BufferQueue::setSidebandStream(const sp<NativeHandle>& stream) {
|
|
|
|
return mProducer->setSidebandStream(stream);
|
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
status_t BufferQueue::acquireBuffer(BufferItem* buffer, nsecs_t presentWhen) {
|
|
|
|
return mConsumer->acquireBuffer(buffer, presentWhen);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
status_t BufferQueue::detachConsumerBuffer(int slot) {
|
|
|
|
return mConsumer->detachBuffer(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t BufferQueue::attachConsumerBuffer(int* slot,
|
|
|
|
const sp<GraphicBuffer>& buffer) {
|
|
|
|
return mConsumer->attachBuffer(slot, buffer);
|
|
|
|
}
|
|
|
|
|
2013-05-03 21:50:50 +00:00
|
|
|
status_t BufferQueue::releaseBuffer(
|
|
|
|
int buf, uint64_t frameNumber, EGLDisplay display,
|
2012-06-28 19:52:05 +00:00
|
|
|
EGLSyncKHR eglFence, const sp<Fence>& fence) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->releaseBuffer(buf, frameNumber, fence, display, eglFence);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 03:09:53 +00:00
|
|
|
status_t BufferQueue::consumerConnect(const sp<IConsumerListener>& consumerListener,
|
2013-07-17 05:56:09 +00:00
|
|
|
bool controlledByApp) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->connect(consumerListener, controlledByApp);
|
2012-03-15 21:01:24 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
status_t BufferQueue::consumerDisconnect() {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->disconnect();
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 23:14:51 +00:00
|
|
|
status_t BufferQueue::getReleasedBuffers(uint64_t* slotMask) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->getReleasedBuffers(slotMask);
|
2012-03-15 21:01:24 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 01:00:53 +00:00
|
|
|
status_t BufferQueue::setDefaultBufferSize(uint32_t w, uint32_t h) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->setDefaultBufferSize(w, h);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-25 00:25:13 +00:00
|
|
|
status_t BufferQueue::setDefaultMaxBufferCount(int bufferCount) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->setDefaultMaxBufferCount(bufferCount);
|
2012-01-22 23:26:27 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 00:28:53 +00:00
|
|
|
status_t BufferQueue::disableAsyncBuffer() {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->disableAsyncBuffer();
|
2013-07-24 00:28:53 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 01:48:37 +00:00
|
|
|
status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) {
|
2014-03-03 18:16:19 +00:00
|
|
|
return mConsumer->setMaxAcquiredBufferCount(maxAcquiredBuffers);
|
2012-08-28 01:48:37 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
void BufferQueue::setConsumerName(const String8& name) {
|
|
|
|
mConsumer->setConsumerName(name);
|
2012-08-25 00:25:13 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
status_t BufferQueue::setDefaultBufferFormat(uint32_t defaultFormat) {
|
|
|
|
return mConsumer->setDefaultBufferFormat(defaultFormat);
|
2012-08-25 03:26:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
status_t BufferQueue::setConsumerUsageBits(uint32_t usage) {
|
|
|
|
return mConsumer->setConsumerUsageBits(usage);
|
2013-05-03 21:50:50 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
status_t BufferQueue::setTransformHint(uint32_t hint) {
|
|
|
|
return mConsumer->setTransformHint(hint);
|
2012-03-15 21:01:24 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 23:42:54 +00:00
|
|
|
sp<NativeHandle> BufferQueue::getSidebandStream() const {
|
|
|
|
return mConsumer->getSidebandStream();
|
|
|
|
}
|
|
|
|
|
2014-03-03 18:16:19 +00:00
|
|
|
void BufferQueue::dump(String8& result, const char* prefix) const {
|
|
|
|
mConsumer->dump(result, prefix);
|
2012-03-15 21:01:24 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 23:42:54 +00:00
|
|
|
void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() {
|
|
|
|
sp<ConsumerListener> listener(mConsumerListener.promote());
|
|
|
|
if (listener != NULL) {
|
|
|
|
listener->onSidebandStreamChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
}; // namespace android
|