| 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 |  | 
| Dan Stoza | f522af7 | 2014-03-12 10:17:20 -0700 | [diff] [blame] | 64 | void BufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer, | 
|  | 65 | sp<IGraphicBufferConsumer>* outConsumer, | 
|  | 66 | const sp<IGraphicBufferAlloc>& allocator) { | 
|  | 67 | LOG_ALWAYS_FATAL_IF(outProducer == NULL, | 
|  | 68 | "BufferQueue: outProducer must not be NULL"); | 
|  | 69 | LOG_ALWAYS_FATAL_IF(outConsumer == NULL, | 
|  | 70 | "BufferQueue: outConsumer must not be NULL"); | 
|  | 71 |  | 
|  | 72 | sp<BufferQueueCore> core(new BufferQueueCore(allocator)); | 
| Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 73 | LOG_ALWAYS_FATAL_IF(core == NULL, | 
|  | 74 | "BufferQueue: failed to create BufferQueueCore"); | 
|  | 75 |  | 
|  | 76 | sp<IGraphicBufferProducer> producer(new BufferQueueProducer(core)); | 
|  | 77 | LOG_ALWAYS_FATAL_IF(producer == NULL, | 
|  | 78 | "BufferQueue: failed to create BufferQueueProducer"); | 
|  | 79 |  | 
|  | 80 | sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core)); | 
|  | 81 | LOG_ALWAYS_FATAL_IF(consumer == NULL, | 
|  | 82 | "BufferQueue: failed to create BufferQueueConsumer"); | 
|  | 83 |  | 
|  | 84 | *outProducer = producer; | 
|  | 85 | *outConsumer = consumer; | 
| Dan Stoza | f522af7 | 2014-03-12 10:17:20 -0700 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
| Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 88 | }; // namespace android |