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