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 | #ifndef ANDROID_GUI_BUFFERQUEUE_H |
| 18 | #define ANDROID_GUI_BUFFERQUEUE_H |
| 19 | |
Dan Stoza | e0d5862 | 2014-04-22 14:12:55 -0700 | [diff] [blame] | 20 | #include <gui/BufferQueueDefs.h> |
| 21 | #include <gui/IGraphicBufferConsumer.h> |
| 22 | #include <gui/IGraphicBufferProducer.h> |
Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 23 | #include <gui/IConsumerListener.h> |
| 24 | |
| 25 | // These are only required to keep other parts of the framework with incomplete |
| 26 | // dependencies building successfully |
| 27 | #include <gui/IGraphicBufferAlloc.h> |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 28 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 29 | namespace android { |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 30 | |
Dan Stoza | e0d5862 | 2014-04-22 14:12:55 -0700 | [diff] [blame] | 31 | class BufferQueue { |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 32 | public: |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 33 | // BufferQueue will keep track of at most this value of buffers. |
| 34 | // Attempts at runtime to increase the number of buffers past this will fail. |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 35 | enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS }; |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 36 | // Used as a placeholder slot# when the value isn't pointing to an existing buffer. |
| 37 | enum { INVALID_BUFFER_SLOT = IGraphicBufferConsumer::BufferItem::INVALID_BUFFER_SLOT }; |
| 38 | // Alias to <IGraphicBufferConsumer.h> -- please scope from there in future code! |
| 39 | enum { |
| 40 | NO_BUFFER_AVAILABLE = IGraphicBufferConsumer::NO_BUFFER_AVAILABLE, |
| 41 | PRESENT_LATER = IGraphicBufferConsumer::PRESENT_LATER, |
| 42 | }; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 43 | |
Jamie Gennis | c68f2ec | 2012-08-30 18:36:22 -0700 | [diff] [blame] | 44 | // When in async mode we reserve two slots in order to guarantee that the |
| 45 | // producer and consumer can run asynchronously. |
| 46 | enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; |
| 47 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 48 | // for backward source compatibility |
| 49 | typedef ::android::ConsumerListener ConsumerListener; |
Dan Stoza | e0d5862 | 2014-04-22 14:12:55 -0700 | [diff] [blame] | 50 | typedef IGraphicBufferConsumer::BufferItem BufferItem; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 51 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 52 | // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak |
| 53 | // reference to the actual consumer object. It forwards all calls to that |
| 54 | // consumer object so long as it exists. |
| 55 | // |
| 56 | // This class exists to avoid having a circular reference between the |
| 57 | // BufferQueue object and the consumer object. The reason this can't be a weak |
| 58 | // reference in the BufferQueue class is because we're planning to expose the |
| 59 | // consumer side of a BufferQueue as a binder interface, which doesn't support |
| 60 | // weak references. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 61 | class ProxyConsumerListener : public BnConsumerListener { |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 62 | public: |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 63 | ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 64 | virtual ~ProxyConsumerListener(); |
Dan Stoza | 8dc5539 | 2014-11-04 11:37:46 -0800 | [diff] [blame] | 65 | virtual void onFrameAvailable(const android::BufferItem& item); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 66 | virtual void onBuffersReleased(); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 67 | virtual void onSidebandStreamChanged(); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 68 | private: |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 69 | // mConsumerListener is a weak reference to the IConsumerListener. This is |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 70 | // the raison d'etre of ProxyConsumerListener. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 71 | wp<ConsumerListener> mConsumerListener; |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 74 | // BufferQueue manages a pool of gralloc memory slots to be used by |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 75 | // producers and consumers. allocator is used to allocate all the |
| 76 | // needed gralloc buffers. |
Dan Stoza | f522af7 | 2014-03-12 10:17:20 -0700 | [diff] [blame] | 77 | static void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, |
| 78 | sp<IGraphicBufferConsumer>* outConsumer, |
| 79 | const sp<IGraphicBufferAlloc>& allocator = NULL); |
| 80 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 81 | private: |
Dan Stoza | e0d5862 | 2014-04-22 14:12:55 -0700 | [diff] [blame] | 82 | BufferQueue(); // Create through createBufferQueue |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | // ---------------------------------------------------------------------------- |
| 86 | }; // namespace android |
| 87 | |
| 88 | #endif // ANDROID_GUI_BUFFERQUEUE_H |