blob: 56c7a3f46382f20bdb1960e4fb60100ab49b369a [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
Mathias Agopian8f938a52013-07-12 22:06:26 -070032class BufferQueue;
33
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070034/**
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 */
40class BufferItemConsumer: public ConsumerBase
41{
42 public:
43 typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
44
Dan Stozafe50d2a2014-03-12 14:32:29 -070045 enum { DEFAULT_MAX_BUFFERS = -1 };
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070046 enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT };
47 enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };
48
49 // Create a new buffer item consumer. The consumerUsage parameter determines
50 // the consumer usage flags passed to the graphics allocator. The
51 // bufferCount parameter specifies how many buffers can be locked for user
52 // access at the same time.
Mathias Agopian595264f2013-07-16 22:56:09 -070053 // controlledByApp tells whether this consumer is controlled by the
54 // application.
Dan Stozafe50d2a2014-03-12 14:32:29 -070055 BufferItemConsumer(const sp<IGraphicBufferConsumer>& consumer,
56 uint32_t consumerUsage, int bufferCount = DEFAULT_MAX_BUFFERS,
Mathias Agopian595264f2013-07-16 22:56:09 -070057 bool controlledByApp = false);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070058
59 virtual ~BufferItemConsumer();
60
61 // set the name of the BufferItemConsumer that will be used to identify it in
62 // log messages.
63 void setName(const String8& name);
64
65 // Gets the next graphics buffer from the producer, filling out the
66 // passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue
67 // of buffers is empty, and INVALID_OPERATION if the maximum number of
68 // buffers is already acquired.
69 //
70 // Only a fixed number of buffers can be acquired at a time, determined by
71 // the construction-time bufferCount parameter. If INVALID_OPERATION is
72 // returned by acquireBuffer, then old buffers must be returned to the
73 // queue by calling releaseBuffer before more buffers can be acquired.
74 //
75 // If waitForFence is true, and the acquired BufferItem has a valid fence object,
76 // acquireBuffer will wait on the fence with no timeout before returning.
Dan Stoza54716312015-03-13 14:40:34 -070077 status_t acquireBuffer(BufferItem* item, nsecs_t presentWhen,
Dan Stozadd264162015-03-12 13:58:47 -070078 bool waitForFence = true);
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070079
80 // Returns an acquired buffer to the queue, allowing it to be reused. Since
81 // only a fixed number of buffers may be acquired at a time, old buffers
82 // must be released by calling releaseBuffer to ensure new buffers can be
83 // acquired by acquireBuffer. Once a BufferItem is released, the caller must
84 // not access any members of the BufferItem, and should immediately remove
85 // all of its references to the BufferItem itself.
86 status_t releaseBuffer(const BufferItem &item,
87 const sp<Fence>& releaseFence = Fence::NO_FENCE);
88
Eino-Ville Talvalae232fdc2012-08-21 13:37:35 -070089};
90
91} // namespace android
92
93#endif // ANDROID_GUI_CPUCONSUMER_H