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-04-22 21:12:55 +00:00
|
|
|
#include <gui/BufferQueueConsumer.h>
|
2014-03-03 18:16:19 +00:00
|
|
|
#include <gui/BufferQueueCore.h>
|
2014-04-22 21:12:55 +00:00
|
|
|
#include <gui/BufferQueueProducer.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-11-04 19:37:46 +00:00
|
|
|
void BufferQueue::ProxyConsumerListener::onFrameAvailable(
|
2015-03-13 21:40:34 +00:00
|
|
|
const BufferItem& item) {
|
2014-03-03 18:16:19 +00:00
|
|
|
sp<ConsumerListener> listener(mConsumerListener.promote());
|
|
|
|
if (listener != NULL) {
|
2014-11-04 19:37:46 +00:00
|
|
|
listener->onFrameAvailable(item);
|
2014-03-03 18:16:19 +00:00
|
|
|
}
|
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-04-22 21:12:55 +00:00
|
|
|
void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() {
|
|
|
|
sp<ConsumerListener> listener(mConsumerListener.promote());
|
|
|
|
if (listener != NULL) {
|
|
|
|
listener->onSidebandStreamChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-01-22 23:26:27 +00:00
|
|
|
}; // namespace android
|