• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 != nullptr) {
37         listener->onDisconnect();
38     }
39 }
40 
onFrameDequeued(const uint64_t bufferId)41 void BufferQueue::ProxyConsumerListener::onFrameDequeued(const uint64_t bufferId) {
42     sp<ConsumerListener> listener(mConsumerListener.promote());
43     if (listener != nullptr) {
44         listener->onFrameDequeued(bufferId);
45     }
46 }
47 
onFrameCancelled(const uint64_t bufferId)48 void BufferQueue::ProxyConsumerListener::onFrameCancelled(const uint64_t bufferId) {
49     sp<ConsumerListener> listener(mConsumerListener.promote());
50     if (listener != nullptr) {
51         listener->onFrameCancelled(bufferId);
52     }
53 }
54 
onFrameDetached(const uint64_t bufferId)55 void BufferQueue::ProxyConsumerListener::onFrameDetached(const uint64_t bufferId) {
56     sp<ConsumerListener> listener(mConsumerListener.promote());
57     if (listener != nullptr) {
58         listener->onFrameDetached(bufferId);
59     }
60 }
61 
onFrameAvailable(const BufferItem & item)62 void BufferQueue::ProxyConsumerListener::onFrameAvailable(
63         const BufferItem& item) {
64     sp<ConsumerListener> listener(mConsumerListener.promote());
65     if (listener != nullptr) {
66         listener->onFrameAvailable(item);
67     }
68 }
69 
onFrameReplaced(const BufferItem & item)70 void BufferQueue::ProxyConsumerListener::onFrameReplaced(
71         const BufferItem& item) {
72     sp<ConsumerListener> listener(mConsumerListener.promote());
73     if (listener != nullptr) {
74         listener->onFrameReplaced(item);
75     }
76 }
77 
onBuffersReleased()78 void BufferQueue::ProxyConsumerListener::onBuffersReleased() {
79     sp<ConsumerListener> listener(mConsumerListener.promote());
80     if (listener != nullptr) {
81         listener->onBuffersReleased();
82     }
83 }
84 
onSidebandStreamChanged()85 void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() {
86     sp<ConsumerListener> listener(mConsumerListener.promote());
87     if (listener != nullptr) {
88         listener->onSidebandStreamChanged();
89     }
90 }
91 
addAndGetFrameTimestamps(const NewFrameEventsEntry * newTimestamps,FrameEventHistoryDelta * outDelta)92 void BufferQueue::ProxyConsumerListener::addAndGetFrameTimestamps(
93         const NewFrameEventsEntry* newTimestamps,
94         FrameEventHistoryDelta* outDelta) {
95     sp<ConsumerListener> listener(mConsumerListener.promote());
96     if (listener != nullptr) {
97         listener->addAndGetFrameTimestamps(newTimestamps, outDelta);
98     }
99 }
100 
101 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE)
onSetFrameRate(float frameRate,int8_t compatibility,int8_t changeFrameRateStrategy)102 void BufferQueue::ProxyConsumerListener::onSetFrameRate(float frameRate, int8_t compatibility,
103                                                         int8_t changeFrameRateStrategy) {
104     sp<ConsumerListener> listener(mConsumerListener.promote());
105     if (listener != nullptr) {
106         listener->onSetFrameRate(frameRate, compatibility, changeFrameRateStrategy);
107     }
108 }
109 #endif
110 
createBufferQueue(sp<IGraphicBufferProducer> * outProducer,sp<IGraphicBufferConsumer> * outConsumer,bool consumerIsSurfaceFlinger)111 void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
112         sp<IGraphicBufferConsumer>* outConsumer,
113         bool consumerIsSurfaceFlinger) {
114     LOG_ALWAYS_FATAL_IF(outProducer == nullptr,
115             "BufferQueue: outProducer must not be NULL");
116     LOG_ALWAYS_FATAL_IF(outConsumer == nullptr,
117             "BufferQueue: outConsumer must not be NULL");
118 
119     sp<BufferQueueCore> core(new BufferQueueCore());
120     LOG_ALWAYS_FATAL_IF(core == nullptr,
121             "BufferQueue: failed to create BufferQueueCore");
122 
123     sp<IGraphicBufferProducer> producer(new BufferQueueProducer(core, consumerIsSurfaceFlinger));
124     LOG_ALWAYS_FATAL_IF(producer == nullptr,
125             "BufferQueue: failed to create BufferQueueProducer");
126 
127     sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core));
128     LOG_ALWAYS_FATAL_IF(consumer == nullptr,
129             "BufferQueue: failed to create BufferQueueConsumer");
130 
131     *outProducer = producer;
132     *outConsumer = consumer;
133 }
134 
135 }; // namespace android
136