| Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [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_BUFFERITEMCONSUMER_H | 
|  | 18 | #define ANDROID_GUI_BUFFERITEMCONSUMER_H | 
|  | 19 |  | 
|  | 20 | #include <gui/ConsumerBase.h> | 
|  | 21 |  | 
|  | 22 | #include <ui/GraphicBuffer.h> | 
|  | 23 |  | 
|  | 24 | #include <utils/String8.h> | 
|  | 25 | #include <utils/Vector.h> | 
|  | 26 | #include <utils/threads.h> | 
|  | 27 |  | 
|  | 28 | #define ANDROID_GRAPHICS_BUFFERITEMCONSUMER_JNI_ID "mBufferItemConsumer" | 
|  | 29 |  | 
|  | 30 | namespace android { | 
|  | 31 |  | 
| Mathias Agopian | 8f938a5 | 2013-07-12 22:06:26 -0700 | [diff] [blame] | 32 | class BufferQueue; | 
|  | 33 |  | 
| Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 34 | /** | 
|  | 35 | * BufferItemConsumer is a BufferQueue consumer endpoint that allows clients | 
|  | 36 | * access to the whole BufferItem entry from BufferQueue. Multiple buffers may | 
|  | 37 | * be acquired at once, to be used concurrently by the client. This consumer can | 
|  | 38 | * operate either in synchronous or asynchronous mode. | 
|  | 39 | */ | 
|  | 40 | class BufferItemConsumer: public ConsumerBase | 
|  | 41 | { | 
|  | 42 | public: | 
|  | 43 | typedef ConsumerBase::FrameAvailableListener FrameAvailableListener; | 
|  | 44 |  | 
|  | 45 | typedef BufferQueue::BufferItem BufferItem; | 
|  | 46 |  | 
| Dan Stoza | fe50d2a | 2014-03-12 14:32:29 -0700 | [diff] [blame] | 47 | enum { DEFAULT_MAX_BUFFERS = -1 }; | 
| Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 48 | enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT }; | 
|  | 49 | enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE }; | 
|  | 50 |  | 
|  | 51 | // Create a new buffer item consumer. The consumerUsage parameter determines | 
|  | 52 | // the consumer usage flags passed to the graphics allocator. The | 
|  | 53 | // bufferCount parameter specifies how many buffers can be locked for user | 
|  | 54 | // access at the same time. | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 55 | // controlledByApp tells whether this consumer is controlled by the | 
|  | 56 | // application. | 
| Dan Stoza | fe50d2a | 2014-03-12 14:32:29 -0700 | [diff] [blame] | 57 | BufferItemConsumer(const sp<IGraphicBufferConsumer>& consumer, | 
|  | 58 | uint32_t consumerUsage, int bufferCount = DEFAULT_MAX_BUFFERS, | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 59 | bool controlledByApp = false); | 
| Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 60 |  | 
|  | 61 | virtual ~BufferItemConsumer(); | 
|  | 62 |  | 
|  | 63 | // set the name of the BufferItemConsumer that will be used to identify it in | 
|  | 64 | // log messages. | 
|  | 65 | void setName(const String8& name); | 
|  | 66 |  | 
|  | 67 | // Gets the next graphics buffer from the producer, filling out the | 
|  | 68 | // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue | 
|  | 69 | // of buffers is empty, and INVALID_OPERATION if the maximum number of | 
|  | 70 | // buffers is already acquired. | 
|  | 71 | // | 
|  | 72 | // Only a fixed number of buffers can be acquired at a time, determined by | 
|  | 73 | // the construction-time bufferCount parameter. If INVALID_OPERATION is | 
|  | 74 | // returned by acquireBuffer, then old buffers must be returned to the | 
|  | 75 | // queue by calling releaseBuffer before more buffers can be acquired. | 
|  | 76 | // | 
|  | 77 | // If waitForFence is true, and the acquired BufferItem has a valid fence object, | 
|  | 78 | // acquireBuffer will wait on the fence with no timeout before returning. | 
| Eino-Ville Talvala | 6c45010 | 2015-02-19 16:10:43 -0800 | [diff] [blame^] | 79 | status_t acquireBuffer(BufferQueue::BufferItem *item, nsecs_t presentWhen, | 
|  | 80 | bool waitForFence = true); | 
|  | 81 | status_t acquireBuffer(android::BufferItem* item, nsecs_t presentWhen, | 
|  | 82 | bool waitForFence = true); | 
| Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 83 |  | 
|  | 84 | // Returns an acquired buffer to the queue, allowing it to be reused. Since | 
|  | 85 | // only a fixed number of buffers may be acquired at a time, old buffers | 
|  | 86 | // must be released by calling releaseBuffer to ensure new buffers can be | 
|  | 87 | // acquired by acquireBuffer. Once a BufferItem is released, the caller must | 
|  | 88 | // not access any members of the BufferItem, and should immediately remove | 
|  | 89 | // all of its references to the BufferItem itself. | 
|  | 90 | status_t releaseBuffer(const BufferItem &item, | 
|  | 91 | const sp<Fence>& releaseFence = Fence::NO_FENCE); | 
|  | 92 |  | 
| Igor Murashkin | 87d1e34 | 2013-04-16 11:24:40 -0700 | [diff] [blame] | 93 | // setDefaultBufferSize is used to set the size of buffers returned by | 
|  | 94 | // requestBuffers when a with and height of zero is requested. | 
|  | 95 | status_t setDefaultBufferSize(uint32_t w, uint32_t h); | 
|  | 96 |  | 
|  | 97 | // setDefaultBufferFormat allows the BufferQueue to create | 
|  | 98 | // GraphicBuffers of a defaultFormat if no format is specified | 
|  | 99 | // in dequeueBuffer | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 100 | status_t setDefaultBufferFormat(PixelFormat defaultFormat); | 
| Eino-Ville Talvala | 6c45010 | 2015-02-19 16:10:43 -0800 | [diff] [blame^] | 101 |  | 
|  | 102 | // setDefaultBufferDataSpace allows the BufferQueue to create | 
|  | 103 | // GraphicBuffers of a defaultDataSpace if no data space is specified | 
|  | 104 | // in queueBuffer. | 
|  | 105 | // The initial default is HAL_DATASPACE_UNKNOWN | 
|  | 106 | status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace); | 
|  | 107 |  | 
| Eino-Ville Talvala | e232fdc | 2012-08-21 13:37:35 -0700 | [diff] [blame] | 108 | }; | 
|  | 109 |  | 
|  | 110 | } // namespace android | 
|  | 111 |  | 
|  | 112 | #endif // ANDROID_GUI_CPUCONSUMER_H |