blob: 3327b37720863329c65c35538e9b9ca51b185974 [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;
94 };
95
96
97 // acquireBuffer attempts to acquire ownership of the next pending buffer in
98 // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a
99 // buffer is successfully acquired, the information about the buffer is
100 // returned in BufferItem. If the buffer returned had previously been
101 // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
102 // NULL and it is assumed that the consumer still holds a reference to the
103 // buffer.
104 //
105 // If presentWhen is nonzero, it indicates the time when the buffer will
106 // be displayed on screen. If the buffer's timestamp is farther in the
107 // future, the buffer won't be acquired, and PRESENT_LATER will be
108 // returned. The presentation time is in nanoseconds, and the time base
109 // is CLOCK_MONOTONIC.
110 virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen) = 0;
111
112 // releaseBuffer releases a buffer slot from the consumer back to the
113 // BufferQueue. This may be done while the buffer's contents are still
114 // being accessed. The fence will signal when the buffer is no longer
115 // in use. frameNumber is used to indentify the exact buffer returned.
116 //
117 // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
118 // any references to the just-released buffer that it might have, as if it
119 // had received a onBuffersReleased() call with a mask set for the released
120 // buffer.
121 //
122 // Note that the dependencies on EGL will be removed once we switch to using
123 // the Android HW Sync HAL.
124 virtual status_t releaseBuffer(int buf, uint64_t frameNumber,
125 EGLDisplay display, EGLSyncKHR fence,
126 const sp<Fence>& releaseFence) = 0;
127
128 // consumerConnect connects a consumer to the BufferQueue. Only one
129 // consumer may be connected, and when that consumer disconnects the
130 // BufferQueue is placed into the "abandoned" state, causing most
131 // interactions with the BufferQueue by the producer to fail.
132 // controlledByApp indicates whether the consumer is controlled by
133 // the application.
134 //
135 // consumer may not be NULL.
136 virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) = 0;
137
138 // consumerDisconnect disconnects a consumer from the BufferQueue. All
139 // buffers will be freed and the BufferQueue is placed in the "abandoned"
140 // state, causing most interactions with the BufferQueue by the producer to
141 // fail.
142 virtual status_t consumerDisconnect() = 0;
143
144 // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
145 // indicating which buffer slots have been released by the BufferQueue
146 // but have not yet been released by the consumer.
147 //
148 // This should be called from the onBuffersReleased() callback.
149 virtual status_t getReleasedBuffers(uint32_t* slotMask) = 0;
150
151 // setDefaultBufferSize is used to set the size of buffers returned by
152 // dequeueBuffer when a width and height of zero is requested. Default
153 // is 1x1.
154 virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0;
155
156 // setDefaultMaxBufferCount sets the default value for the maximum buffer
157 // count (the initial default is 2). If the producer has requested a
158 // buffer count using setBufferCount, the default buffer count will only
159 // take effect if the producer sets the count back to zero.
160 //
161 // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
162 virtual status_t setDefaultMaxBufferCount(int bufferCount) = 0;
163
164 // disableAsyncBuffer disables the extra buffer used in async mode
165 // (when both producer and consumer have set their "isControlledByApp"
166 // flag) and has dequeueBuffer() return WOULD_BLOCK instead.
167 //
168 // This can only be called before consumerConnect().
169 virtual status_t disableAsyncBuffer() = 0;
170
171 // setMaxAcquiredBufferCount sets the maximum number of buffers that can
172 // be acquired by the consumer at one time (default 1). This call will
173 // fail if a producer is connected to the BufferQueue.
174 virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0;
175
176 // setConsumerName sets the name used in logging
177 virtual void setConsumerName(const String8& name) = 0;
178
179 // setDefaultBufferFormat allows the BufferQueue to create
180 // GraphicBuffers of a defaultFormat if no format is specified
181 // in dequeueBuffer. Formats are enumerated in graphics.h; the
182 // initial default is HAL_PIXEL_FORMAT_RGBA_8888.
183 virtual status_t setDefaultBufferFormat(uint32_t defaultFormat) = 0;
184
185 // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer.
186 // These are merged with the bits passed to dequeueBuffer. The values are
187 // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
188 virtual status_t setConsumerUsageBits(uint32_t usage) = 0;
189
190 // setTransformHint bakes in rotation to buffers so overlays can be used.
191 // The values are enumerated in window.h, e.g.
192 // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform).
193 virtual status_t setTransformHint(uint32_t hint) = 0;
194
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700195 // dump state into a string
196 virtual void dump(String8& result, const char* prefix) const = 0;
197
Mathias Agopiana4e19522013-07-31 20:09:53 -0700198public:
199 DECLARE_META_INTERFACE(GraphicBufferConsumer);
200};
201
202// ----------------------------------------------------------------------------
203
204class BnGraphicBufferConsumer : public BnInterface<IGraphicBufferConsumer>
205{
206public:
207 virtual status_t onTransact( uint32_t code,
208 const Parcel& data,
209 Parcel* reply,
210 uint32_t flags = 0);
211};
212
213// ----------------------------------------------------------------------------
214}; // namespace android
215
216#endif // ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H