1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "BufferQueue"
18 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
19 //#define LOG_NDEBUG 0
20
21 #include <gui/BufferQueue.h>
22 #include <gui/BufferQueueConsumer.h>
23 #include <gui/BufferQueueCore.h>
24 #include <gui/BufferQueueProducer.h>
25
26 namespace android {
27
ProxyConsumerListener(const wp<ConsumerListener> & consumerListener)28 BufferQueue::ProxyConsumerListener::ProxyConsumerListener(
29 const wp<ConsumerListener>& consumerListener):
30 mConsumerListener(consumerListener) {}
31
~ProxyConsumerListener()32 BufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {}
33
onDisconnect()34 void BufferQueue::ProxyConsumerListener::onDisconnect() {
35 sp<ConsumerListener> listener(mConsumerListener.promote());
36 if (listener != NULL) {
37 listener->onDisconnect();
38 }
39 }
40
onFrameAvailable(const BufferItem & item)41 void BufferQueue::ProxyConsumerListener::onFrameAvailable(
42 const BufferItem& item) {
43 sp<ConsumerListener> listener(mConsumerListener.promote());
44 if (listener != NULL) {
45 listener->onFrameAvailable(item);
46 }
47 }
48
onFrameReplaced(const BufferItem & item)49 void BufferQueue::ProxyConsumerListener::onFrameReplaced(
50 const BufferItem& item) {
51 sp<ConsumerListener> listener(mConsumerListener.promote());
52 if (listener != NULL) {
53 listener->onFrameReplaced(item);
54 }
55 }
56
onBuffersReleased()57 void BufferQueue::ProxyConsumerListener::onBuffersReleased() {
58 sp<ConsumerListener> listener(mConsumerListener.promote());
59 if (listener != NULL) {
60 listener->onBuffersReleased();
61 }
62 }
63
onSidebandStreamChanged()64 void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() {
65 sp<ConsumerListener> listener(mConsumerListener.promote());
66 if (listener != NULL) {
67 listener->onSidebandStreamChanged();
68 }
69 }
70
addAndGetFrameTimestamps(const NewFrameEventsEntry * newTimestamps,FrameEventHistoryDelta * outDelta)71 void BufferQueue::ProxyConsumerListener::addAndGetFrameTimestamps(
72 const NewFrameEventsEntry* newTimestamps,
73 FrameEventHistoryDelta* outDelta) {
74 sp<ConsumerListener> listener(mConsumerListener.promote());
75 if (listener != nullptr) {
76 listener->addAndGetFrameTimestamps(newTimestamps, outDelta);
77 }
78 }
79
createBufferQueue(sp<IGraphicBufferProducer> * outProducer,sp<IGraphicBufferConsumer> * outConsumer,bool consumerIsSurfaceFlinger)80 void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
81 sp<IGraphicBufferConsumer>* outConsumer,
82 bool consumerIsSurfaceFlinger) {
83 LOG_ALWAYS_FATAL_IF(outProducer == NULL,
84 "BufferQueue: outProducer must not be NULL");
85 LOG_ALWAYS_FATAL_IF(outConsumer == NULL,
86 "BufferQueue: outConsumer must not be NULL");
87
88 sp<BufferQueueCore> core(new BufferQueueCore());
89 LOG_ALWAYS_FATAL_IF(core == NULL,
90 "BufferQueue: failed to create BufferQueueCore");
91
92 sp<IGraphicBufferProducer> producer(new BufferQueueProducer(core, consumerIsSurfaceFlinger));
93 LOG_ALWAYS_FATAL_IF(producer == NULL,
94 "BufferQueue: failed to create BufferQueueProducer");
95
96 sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core));
97 LOG_ALWAYS_FATAL_IF(consumer == NULL,
98 "BufferQueue: failed to create BufferQueueConsumer");
99
100 *outProducer = producer;
101 *outConsumer = consumer;
102 }
103
104 }; // namespace android
105