Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 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" |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 20 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 21 | #include <gui/BufferQueue.h> |
Dan Stoza | e0d5862 | 2014-04-22 14:12:55 -0700 | [diff] [blame] | 22 | #include <gui/BufferQueueConsumer.h> |
Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 23 | #include <gui/BufferQueueCore.h> |
Dan Stoza | e0d5862 | 2014-04-22 14:12:55 -0700 | [diff] [blame] | 24 | #include <gui/BufferQueueProducer.h> |
Mathias Agopian | 546ed2d | 2012-03-01 22:11:25 -0800 | [diff] [blame] | 25 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 28 | BufferQueue::ProxyConsumerListener::ProxyConsumerListener( |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 29 | const wp<ConsumerListener>& consumerListener): |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 30 | mConsumerListener(consumerListener) {} |
| 31 | |
| 32 | BufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {} |
| 33 | |
Dan Stoza | 8dc5539 | 2014-11-04 11:37:46 -0800 | [diff] [blame] | 34 | void BufferQueue::ProxyConsumerListener::onFrameAvailable( |
Dan Stoza | 5471631 | 2015-03-13 14:40:34 -0700 | [diff] [blame] | 35 | const BufferItem& item) { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 36 | sp<ConsumerListener> listener(mConsumerListener.promote()); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 37 | if (listener != NULL) { |
Dan Stoza | 8dc5539 | 2014-11-04 11:37:46 -0800 | [diff] [blame] | 38 | listener->onFrameAvailable(item); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
Dan Stoza | dc13c5b | 2015-05-11 15:33:01 -0700 | [diff] [blame] | 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 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 50 | void BufferQueue::ProxyConsumerListener::onBuffersReleased() { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 51 | sp<ConsumerListener> listener(mConsumerListener.promote()); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 52 | if (listener != NULL) { |
| 53 | listener->onBuffersReleased(); |
| 54 | } |
| 55 | } |
| 56 | |
Dan Stoza | e0d5862 | 2014-04-22 14:12:55 -0700 | [diff] [blame] | 57 | void BufferQueue::ProxyConsumerListener::onSidebandStreamChanged() { |
| 58 | sp<ConsumerListener> listener(mConsumerListener.promote()); |
| 59 | if (listener != NULL) { |
| 60 | listener->onSidebandStreamChanged(); |
| 61 | } |
| 62 | } |
| 63 | |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame^] | 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 | |
Dan Stoza | f522af7 | 2014-03-12 10:17:20 -0700 | [diff] [blame] | 73 | void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer, |
Dan Stoza | 70982a5 | 2016-01-11 23:40:44 +0000 | [diff] [blame] | 74 | sp<IGraphicBufferConsumer>* outConsumer, |
| 75 | const sp<IGraphicBufferAlloc>& allocator) { |
Dan Stoza | f522af7 | 2014-03-12 10:17:20 -0700 | [diff] [blame] | 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 | |
Dan Stoza | 70982a5 | 2016-01-11 23:40:44 +0000 | [diff] [blame] | 81 | sp<BufferQueueCore> core(new BufferQueueCore(allocator)); |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 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; |
Dan Stoza | f522af7 | 2014-03-12 10:17:20 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 97 | }; // namespace android |