blob: 5bf9acbe11cd3a62dff283ac4ee54be31631c356 [file] [log] [blame]
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -07001/*
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
30namespace android {
31
32/**
33 * BufferItemConsumer is a BufferQueue consumer endpoint that allows clients
34 * access to the whole BufferItem entry from BufferQueue. Multiple buffers may
35 * be acquired at once, to be used concurrently by the client. This consumer can
36 * operate either in synchronous or asynchronous mode.
37 */
38class BufferItemConsumer: public ConsumerBase
39{
40 public:
41 typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
42
43 typedef BufferQueue::BufferItem BufferItem;
44
45 enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT };
46 enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };
47
48 // Create a new buffer item consumer. The consumerUsage parameter determines
49 // the consumer usage flags passed to the graphics allocator. The
50 // bufferCount parameter specifies how many buffers can be locked for user
51 // access at the same time.
52 BufferItemConsumer(uint32_t consumerUsage,
53 int bufferCount = BufferQueue::MIN_UNDEQUEUED_BUFFERS,
54 bool synchronousMode = false);
55
56 virtual ~BufferItemConsumer();
57
58 // set the name of the BufferItemConsumer that will be used to identify it in
59 // log messages.
60 void setName(const String8& name);
61
62 // Gets the next graphics buffer from the producer, filling out the
63 // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue
64 // of buffers is empty, and INVALID_OPERATION if the maximum number of
65 // buffers is already acquired.
66 //
67 // Only a fixed number of buffers can be acquired at a time, determined by
68 // the construction-time bufferCount parameter. If INVALID_OPERATION is
69 // returned by acquireBuffer, then old buffers must be returned to the
70 // queue by calling releaseBuffer before more buffers can be acquired.
71 //
72 // If waitForFence is true, and the acquired BufferItem has a valid fence object,
73 // acquireBuffer will wait on the fence with no timeout before returning.
Andy McFadden1585c4d2013-06-28 13:52:40 -070074 status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen,
75 bool waitForFence = true);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070076
77 // Returns an acquired buffer to the queue, allowing it to be reused. Since
78 // only a fixed number of buffers may be acquired at a time, old buffers
79 // must be released by calling releaseBuffer to ensure new buffers can be
80 // acquired by acquireBuffer. Once a BufferItem is released, the caller must
81 // not access any members of the BufferItem, and should immediately remove
82 // all of its references to the BufferItem itself.
83 status_t releaseBuffer(const BufferItem &item,
84 const sp<Fence>& releaseFence = Fence::NO_FENCE);
85
Andy McFadden2adaf042012-12-18 09:49:45 -080086 sp<IGraphicBufferProducer> getProducerInterface() const { return getBufferQueue(); }
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070087
Igor Murashkin87d1e342013-04-16 11:24:40 -070088 // setDefaultBufferSize is used to set the size of buffers returned by
89 // requestBuffers when a with and height of zero is requested.
90 status_t setDefaultBufferSize(uint32_t w, uint32_t h);
91
92 // setDefaultBufferFormat allows the BufferQueue to create
93 // GraphicBuffers of a defaultFormat if no format is specified
94 // in dequeueBuffer
95 status_t setDefaultBufferFormat(uint32_t defaultFormat);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070096};
97
98} // namespace android
99
100#endif // ANDROID_GUI_CPUCONSUMER_H