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 
onFrameAvailable(const android::BufferItem & item)34 void BufferQueue::ProxyConsumerListener::onFrameAvailable(
35         const android::BufferItem& item) {
36     sp<ConsumerListener> listener(mConsumerListener.promote());
37     if (listener != NULL) {
38         listener->onFrameAvailable(item);
39     }
40 }
41 
onBuffersReleased()42 void BufferQueue::ProxyConsumerListener::onBuffersReleased() {
43     sp<ConsumerListener> listener(mConsumerListener.promote());
44     if (listener != NULL) {
45         listener->onBuffersReleased();
46     }
47 }
48 
onSidebandStreamChanged()49 void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() {
50     sp<ConsumerListener> listener(mConsumerListener.promote());
51     if (listener != NULL) {
52         listener->onSidebandStreamChanged();
53     }
54 }
55 
createBufferQueue(sp<IGraphicBufferProducer> * outProducer,sp<IGraphicBufferConsumer> * outConsumer,const sp<IGraphicBufferAlloc> & allocator)56 void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
57         sp<IGraphicBufferConsumer>* outConsumer,
58         const sp<IGraphicBufferAlloc>& allocator) {
59     LOG_ALWAYS_FATAL_IF(outProducer == NULL,
60             "BufferQueue: outProducer must not be NULL");
61     LOG_ALWAYS_FATAL_IF(outConsumer == NULL,
62             "BufferQueue: outConsumer must not be NULL");
63 
64     sp<BufferQueueCore> core(new BufferQueueCore(allocator));
65     LOG_ALWAYS_FATAL_IF(core == NULL,
66             "BufferQueue: failed to create BufferQueueCore");
67 
68     sp<IGraphicBufferProducer> producer(new BufferQueueProducer(core));
69     LOG_ALWAYS_FATAL_IF(producer == NULL,
70             "BufferQueue: failed to create BufferQueueProducer");
71 
72     sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core));
73     LOG_ALWAYS_FATAL_IF(consumer == NULL,
74             "BufferQueue: failed to create BufferQueueConsumer");
75 
76     *outProducer = producer;
77     *outConsumer = consumer;
78 }
79 
80 }; // namespace android
81