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 28 BufferQueue::ProxyConsumerListener::ProxyConsumerListener( 29 const wp<ConsumerListener>& consumerListener): 30 mConsumerListener(consumerListener) {} 31 32 BufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {} 33 34 void BufferQueue::ProxyConsumerListener::onFrameAvailable( 35 const BufferItem& item) { 36 sp<ConsumerListener> listener(mConsumerListener.promote()); 37 if (listener != NULL) { 38 listener->onFrameAvailable(item); 39 } 40 } 41 42 void BufferQueue::ProxyConsumerListener::onFrameReplaced( 43 const BufferItem& item) { 44 sp<ConsumerListener> listener(mConsumerListener.promote()); 45 if (listener != NULL) { 46 listener->onFrameReplaced(item); 47 } 48 } 49 50 void BufferQueue::ProxyConsumerListener::onBuffersReleased() { 51 sp<ConsumerListener> listener(mConsumerListener.promote()); 52 if (listener != NULL) { 53 listener->onBuffersReleased(); 54 } 55 } 56 57 void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() { 58 sp<ConsumerListener> listener(mConsumerListener.promote()); 59 if (listener != NULL) { 60 listener->onSidebandStreamChanged(); 61 } 62 } 63 64 bool BufferQueue::ProxyConsumerListener::getFrameTimestamps( 65 uint64_t frameNumber, FrameTimestamps* outTimestamps) const { 66 sp<ConsumerListener> listener(mConsumerListener.promote()); 67 if (listener != NULL) { 68 return listener->getFrameTimestamps(frameNumber, outTimestamps); 69 } 70 return false; 71 } 72 73 void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer, 74 sp<IGraphicBufferConsumer>* outConsumer, 75 const sp<IGraphicBufferAlloc>& allocator) { 76 LOG_ALWAYS_FATAL_IF(outProducer == NULL, 77 "BufferQueue: outProducer must not be NULL"); 78 LOG_ALWAYS_FATAL_IF(outConsumer == NULL, 79 "BufferQueue: outConsumer must not be NULL"); 80 81 sp<BufferQueueCore> core(new BufferQueueCore(allocator)); 82 LOG_ALWAYS_FATAL_IF(core == NULL, 83 "BufferQueue: failed to create BufferQueueCore"); 84 85 sp<IGraphicBufferProducer> producer(new BufferQueueProducer(core)); 86 LOG_ALWAYS_FATAL_IF(producer == NULL, 87 "BufferQueue: failed to create BufferQueueProducer"); 88 89 sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core)); 90 LOG_ALWAYS_FATAL_IF(consumer == NULL, 91 "BufferQueue: failed to create BufferQueueConsumer"); 92 93 *outProducer = producer; 94 *outConsumer = consumer; 95 } 96 97 }; // namespace android 98