blob: 0e35f1371e56d452ea44b56fb40b202b65cc4f7e [file] [log] [blame]
Mathias Agopiana4e19522013-07-31 20:09:53 -07001/*
2 * Copyright (C) 2013 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_IGRAPHICBUFFERCONSUMER_H
18#define ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Errors.h>
24#include <utils/RefBase.h>
25#include <utils/Timers.h>
26
27#include <binder/IInterface.h>
28#include <ui/Rect.h>
29
30namespace android {
31// ----------------------------------------------------------------------------
32
33class IConsumerListener;
34class GraphicBuffer;
35class Fence;
36
37class IGraphicBufferConsumer : public IInterface {
38
39public:
40
41 // public facing structure for BufferSlot
42 class BufferItem : public Flattenable<BufferItem> {
43 friend class Flattenable<BufferItem>;
44 size_t getPodSize() const;
45 size_t getFlattenedSize() const;
46 size_t getFdCount() const;
47 status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
48 status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
49
50 public:
51 enum { INVALID_BUFFER_SLOT = -1 };
52 BufferItem();
53
54 // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
55 // if the buffer in this slot has been acquired in the past (see
56 // BufferSlot.mAcquireCalled).
57 sp<GraphicBuffer> mGraphicBuffer;
58
59 // mFence is a fence that will signal when the buffer is idle.
60 sp<Fence> mFence;
61
62 // mCrop is the current crop rectangle for this buffer slot.
63 Rect mCrop;
64
65 // mTransform is the current transform flags for this buffer slot.
66 uint32_t mTransform;
67
68 // mScalingMode is the current scaling mode for this buffer slot.
69 uint32_t mScalingMode;
70
71 // mTimestamp is the current timestamp for this buffer slot. This gets
72 // to set by queueBuffer each time this slot is queued.
73 int64_t mTimestamp;
74
Andy McFadden3c256212013-08-16 14:55:39 -070075 // mIsAutoTimestamp indicates whether mTimestamp was generated
76 // automatically when the buffer was queued.
77 bool mIsAutoTimestamp;
78
Mathias Agopiana4e19522013-07-31 20:09:53 -070079 // mFrameNumber is the number of the queued frame for this slot.
80 uint64_t mFrameNumber;
81
82 // mBuf is the slot index of this buffer
83 int mBuf;
84
85 // mIsDroppable whether this buffer was queued with the
86 // property that it can be replaced by a new buffer for the purpose of
87 // making sure dequeueBuffer() won't block.
88 // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer
89 // was queued.
90 bool mIsDroppable;
91
92 // Indicates whether this buffer has been seen by a consumer yet
93 bool mAcquireCalled;
Mathias Agopianc1c05de2013-09-17 23:45:22 -070094
95 // Indicates this buffer must be transformed by the inverse transform of the screen
96 // it is displayed onto. This is applied after mTransform.
97 bool mTransformToDisplayInverse;
Mathias Agopiana4e19522013-07-31 20:09:53 -070098 };
99
100
101 // acquireBuffer attempts to acquire ownership of the next pending buffer in
102 // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a
103 // buffer is successfully acquired, the information about the buffer is
104 // returned in BufferItem. If the buffer returned had previously been
105 // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
106 // NULL and it is assumed that the consumer still holds a reference to the
107 // buffer.
108 //
109 // If presentWhen is nonzero, it indicates the time when the buffer will
110 // be displayed on screen. If the buffer's timestamp is farther in the
111 // future, the buffer won't be acquired, and PRESENT_LATER will be
112 // returned. The presentation time is in nanoseconds, and the time base
113 // is CLOCK_MONOTONIC.
114 virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen) = 0;
115
116 // releaseBuffer releases a buffer slot from the consumer back to the
117 // BufferQueue. This may be done while the buffer's contents are still
118 // being accessed. The fence will signal when the buffer is no longer
119 // in use. frameNumber is used to indentify the exact buffer returned.
120 //
121 // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
122 // any references to the just-released buffer that it might have, as if it
123 // had received a onBuffersReleased() call with a mask set for the released
124 // buffer.
125 //
126 // Note that the dependencies on EGL will be removed once we switch to using
127 // the Android HW Sync HAL.
128 virtual status_t releaseBuffer(int buf, uint64_t frameNumber,
129 EGLDisplay display, EGLSyncKHR fence,
130 const sp<Fence>& releaseFence) = 0;
131
132 // consumerConnect connects a consumer to the BufferQueue. Only one
133 // consumer may be connected, and when that consumer disconnects the
134 // BufferQueue is placed into the "abandoned" state, causing most
135 // interactions with the BufferQueue by the producer to fail.
136 // controlledByApp indicates whether the consumer is controlled by
137 // the application.
138 //
139 // consumer may not be NULL.
140 virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) = 0;
141
142 // consumerDisconnect disconnects a consumer from the BufferQueue. All
143 // buffers will be freed and the BufferQueue is placed in the "abandoned"
144 // state, causing most interactions with the BufferQueue by the producer to
145 // fail.
146 virtual status_t consumerDisconnect() = 0;
147
148 // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
149 // indicating which buffer slots have been released by the BufferQueue
150 // but have not yet been released by the consumer.
151 //
152 // This should be called from the onBuffersReleased() callback.
153 virtual status_t getReleasedBuffers(uint32_t* slotMask) = 0;
154
155 // setDefaultBufferSize is used to set the size of buffers returned by
156 // dequeueBuffer when a width and height of zero is requested. Default
157 // is 1x1.
158 virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0;
159
160 // setDefaultMaxBufferCount sets the default value for the maximum buffer
161 // count (the initial default is 2). If the producer has requested a
162 // buffer count using setBufferCount, the default buffer count will only
163 // take effect if the producer sets the count back to zero.
164 //
165 // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
166 virtual status_t setDefaultMaxBufferCount(int bufferCount) = 0;
167
168 // disableAsyncBuffer disables the extra buffer used in async mode
169 // (when both producer and consumer have set their "isControlledByApp"
170 // flag) and has dequeueBuffer() return WOULD_BLOCK instead.
171 //
172 // This can only be called before consumerConnect().
173 virtual status_t disableAsyncBuffer() = 0;
174
175 // setMaxAcquiredBufferCount sets the maximum number of buffers that can
176 // be acquired by the consumer at one time (default 1). This call will
177 // fail if a producer is connected to the BufferQueue.
178 virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0;
179
180 // setConsumerName sets the name used in logging
181 virtual void setConsumerName(const String8& name) = 0;
182
183 // setDefaultBufferFormat allows the BufferQueue to create
184 // GraphicBuffers of a defaultFormat if no format is specified
185 // in dequeueBuffer. Formats are enumerated in graphics.h; the
186 // initial default is HAL_PIXEL_FORMAT_RGBA_8888.
187 virtual status_t setDefaultBufferFormat(uint32_t defaultFormat) = 0;
188
189 // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer.
190 // These are merged with the bits passed to dequeueBuffer. The values are
191 // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
192 virtual status_t setConsumerUsageBits(uint32_t usage) = 0;
193
194 // setTransformHint bakes in rotation to buffers so overlays can be used.
195 // The values are enumerated in window.h, e.g.
196 // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform).
197 virtual status_t setTransformHint(uint32_t hint) = 0;
198
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700199 // dump state into a string
200 virtual void dump(String8& result, const char* prefix) const = 0;
201
Mathias Agopiana4e19522013-07-31 20:09:53 -0700202public:
203 DECLARE_META_INTERFACE(GraphicBufferConsumer);
204};
205
206// ----------------------------------------------------------------------------
207
208class BnGraphicBufferConsumer : public BnInterface<IGraphicBufferConsumer>
209{
210public:
211 virtual status_t onTransact( uint32_t code,
212 const Parcel& data,
213 Parcel* reply,
214 uint32_t flags = 0);
215};
216
217// ----------------------------------------------------------------------------
218}; // namespace android
219
220#endif // ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H