xref: /aosp_15_r20/frameworks/native/include/gui/IGraphicBufferConsumer.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2013 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <gui/OccupancyTracker.h>
20*38e8c45fSAndroid Build Coastguard Worker 
21*38e8c45fSAndroid Build Coastguard Worker #include <binder/IInterface.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <binder/SafeInterface.h>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include <EGL/egl.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <EGL/eglext.h>
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker #include <ui/PixelFormat.h>
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker #include <utils/Errors.h>
30*38e8c45fSAndroid Build Coastguard Worker 
31*38e8c45fSAndroid Build Coastguard Worker namespace android {
32*38e8c45fSAndroid Build Coastguard Worker 
33*38e8c45fSAndroid Build Coastguard Worker class BufferItem;
34*38e8c45fSAndroid Build Coastguard Worker class Fence;
35*38e8c45fSAndroid Build Coastguard Worker class GraphicBuffer;
36*38e8c45fSAndroid Build Coastguard Worker class IConsumerListener;
37*38e8c45fSAndroid Build Coastguard Worker class NativeHandle;
38*38e8c45fSAndroid Build Coastguard Worker #ifndef NO_BINDER
39*38e8c45fSAndroid Build Coastguard Worker class IGraphicBufferConsumer : public IInterface {
40*38e8c45fSAndroid Build Coastguard Worker public:
41*38e8c45fSAndroid Build Coastguard Worker     DECLARE_META_INTERFACE(GraphicBufferConsumer)
42*38e8c45fSAndroid Build Coastguard Worker #else
43*38e8c45fSAndroid Build Coastguard Worker class IGraphicBufferConsumer : public RefBase {
44*38e8c45fSAndroid Build Coastguard Worker public:
45*38e8c45fSAndroid Build Coastguard Worker #endif
46*38e8c45fSAndroid Build Coastguard Worker 
47*38e8c45fSAndroid Build Coastguard Worker     enum {
48*38e8c45fSAndroid Build Coastguard Worker         // Returned by releaseBuffer, after which the consumer must free any references to the
49*38e8c45fSAndroid Build Coastguard Worker         // just-released buffer that it might have.
50*38e8c45fSAndroid Build Coastguard Worker         STALE_BUFFER_SLOT = 1,
51*38e8c45fSAndroid Build Coastguard Worker         // Returned by dequeueBuffer if there are no pending buffers available.
52*38e8c45fSAndroid Build Coastguard Worker         NO_BUFFER_AVAILABLE,
53*38e8c45fSAndroid Build Coastguard Worker         // Returned by dequeueBuffer if it's too early for the buffer to be acquired.
54*38e8c45fSAndroid Build Coastguard Worker         PRESENT_LATER,
55*38e8c45fSAndroid Build Coastguard Worker     };
56*38e8c45fSAndroid Build Coastguard Worker 
57*38e8c45fSAndroid Build Coastguard Worker     // acquireBuffer attempts to acquire ownership of the next pending buffer in the BufferQueue.
58*38e8c45fSAndroid Build Coastguard Worker     // If no buffer is pending then it returns NO_BUFFER_AVAILABLE. If a buffer is successfully
59*38e8c45fSAndroid Build Coastguard Worker     // acquired, the information about the buffer is returned in BufferItem.
60*38e8c45fSAndroid Build Coastguard Worker     //
61*38e8c45fSAndroid Build Coastguard Worker     // If the buffer returned had previously been acquired then the BufferItem::mGraphicBuffer field
62*38e8c45fSAndroid Build Coastguard Worker     // of buffer is set to NULL and it is assumed that the consumer still holds a reference to the
63*38e8c45fSAndroid Build Coastguard Worker     // buffer.
64*38e8c45fSAndroid Build Coastguard Worker     //
65*38e8c45fSAndroid Build Coastguard Worker     // If presentWhen is non-zero, it indicates the time when the buffer will be displayed on
66*38e8c45fSAndroid Build Coastguard Worker     // screen. If the buffer's timestamp is farther in the future, the buffer won't be acquired, and
67*38e8c45fSAndroid Build Coastguard Worker     // PRESENT_LATER will be returned. The presentation time is in nanoseconds, and the time base
68*38e8c45fSAndroid Build Coastguard Worker     // is CLOCK_MONOTONIC.
69*38e8c45fSAndroid Build Coastguard Worker     //
70*38e8c45fSAndroid Build Coastguard Worker     // If maxFrameNumber is non-zero, it indicates that acquireBuffer should only return a buffer
71*38e8c45fSAndroid Build Coastguard Worker     // with a frame number less than or equal to maxFrameNumber. If no such frame is available
72*38e8c45fSAndroid Build Coastguard Worker     // (such as when a buffer has been replaced but the consumer has not received the
73*38e8c45fSAndroid Build Coastguard Worker     // onFrameReplaced callback), then PRESENT_LATER will be returned.
74*38e8c45fSAndroid Build Coastguard Worker     //
75*38e8c45fSAndroid Build Coastguard Worker     // Return of NO_ERROR means the operation completed as normal.
76*38e8c45fSAndroid Build Coastguard Worker     //
77*38e8c45fSAndroid Build Coastguard Worker     // Return of a positive value means the operation could not be completed at this time, but the
78*38e8c45fSAndroid Build Coastguard Worker     // user should try again later:
79*38e8c45fSAndroid Build Coastguard Worker     // * NO_BUFFER_AVAILABLE - no buffer is pending (nothing queued by producer)
80*38e8c45fSAndroid Build Coastguard Worker     // * PRESENT_LATER - the buffer's timestamp is farther in the future
81*38e8c45fSAndroid Build Coastguard Worker     //
82*38e8c45fSAndroid Build Coastguard Worker     // Return of a negative value means an error has occurred:
83*38e8c45fSAndroid Build Coastguard Worker     // * INVALID_OPERATION - too many buffers have been acquired
84*38e8c45fSAndroid Build Coastguard Worker     virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen,
85*38e8c45fSAndroid Build Coastguard Worker                                    uint64_t maxFrameNumber = 0) = 0;
86*38e8c45fSAndroid Build Coastguard Worker 
87*38e8c45fSAndroid Build Coastguard Worker     // detachBuffer attempts to remove all ownership of the buffer in the given slot from the buffer
88*38e8c45fSAndroid Build Coastguard Worker     // queue. If this call succeeds, the slot will be freed, and there will be no way to obtain the
89*38e8c45fSAndroid Build Coastguard Worker     // buffer from this interface. The freed slot will remain unallocated until either it is
90*38e8c45fSAndroid Build Coastguard Worker     // selected to hold a freshly allocated buffer in dequeueBuffer or a buffer is attached to the
91*38e8c45fSAndroid Build Coastguard Worker     // slot. The buffer must have already been acquired.
92*38e8c45fSAndroid Build Coastguard Worker     //
93*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
94*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - the given slot number is invalid, either because it is out of the range
95*38e8c45fSAndroid Build Coastguard Worker     //               [0, NUM_BUFFER_SLOTS) or because the slot it refers to is not
96*38e8c45fSAndroid Build Coastguard Worker     //               currently acquired.
97*38e8c45fSAndroid Build Coastguard Worker     virtual status_t detachBuffer(int slot) = 0;
98*38e8c45fSAndroid Build Coastguard Worker 
99*38e8c45fSAndroid Build Coastguard Worker     // attachBuffer attempts to transfer ownership of a buffer to the BufferQueue. If this call
100*38e8c45fSAndroid Build Coastguard Worker     // succeeds, it will be as if this buffer was acquired from the returned slot number. As such,
101*38e8c45fSAndroid Build Coastguard Worker     // this call will fail if attaching this buffer would cause too many buffers to be
102*38e8c45fSAndroid Build Coastguard Worker     // simultaneously acquired.
103*38e8c45fSAndroid Build Coastguard Worker     //
104*38e8c45fSAndroid Build Coastguard Worker     // If the buffer is successfully attached, its frameNumber is initialized to 0. This must be
105*38e8c45fSAndroid Build Coastguard Worker     // passed into the releaseBuffer call or else the buffer will be deallocated as stale.
106*38e8c45fSAndroid Build Coastguard Worker     //
107*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
108*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - outSlot or buffer were NULL, or the generation number of the buffer did not
109*38e8c45fSAndroid Build Coastguard Worker     //               match the BufferQueue.
110*38e8c45fSAndroid Build Coastguard Worker     // * INVALID_OPERATION - cannot attach the buffer because it would cause too many buffers
111*38e8c45fSAndroid Build Coastguard Worker     //                       to be acquired.
112*38e8c45fSAndroid Build Coastguard Worker     // * NO_MEMORY - no free slots available
113*38e8c45fSAndroid Build Coastguard Worker     virtual status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer) = 0;
114*38e8c45fSAndroid Build Coastguard Worker 
115*38e8c45fSAndroid Build Coastguard Worker     // releaseBuffer releases a buffer slot from the consumer back to the BufferQueue. This may be
116*38e8c45fSAndroid Build Coastguard Worker     // done while the buffer's contents are still being accessed. The fence will signal when the
117*38e8c45fSAndroid Build Coastguard Worker     // buffer is no longer in use. frameNumber is used to identify the exact buffer returned.
118*38e8c45fSAndroid Build Coastguard Worker     //
119*38e8c45fSAndroid Build Coastguard Worker     // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free any references to the
120*38e8c45fSAndroid Build Coastguard Worker     // just-released buffer that it might have, as if it had received a onBuffersReleased() call
121*38e8c45fSAndroid Build Coastguard Worker     // with a mask set for the released buffer.
122*38e8c45fSAndroid Build Coastguard Worker     //
123*38e8c45fSAndroid Build Coastguard Worker     // Note that the dependencies on EGL will be removed once we switch to using the Android HW
124*38e8c45fSAndroid Build Coastguard Worker     // Sync HAL.
125*38e8c45fSAndroid Build Coastguard Worker     //
126*38e8c45fSAndroid Build Coastguard Worker     // Return of NO_ERROR means the operation completed as normal.
127*38e8c45fSAndroid Build Coastguard Worker     //
128*38e8c45fSAndroid Build Coastguard Worker     // Return of a positive value means the operation could not be completed at this time, but the
129*38e8c45fSAndroid Build Coastguard Worker     // user should try again later:
130*38e8c45fSAndroid Build Coastguard Worker     // * STALE_BUFFER_SLOT - see above (second paragraph)
131*38e8c45fSAndroid Build Coastguard Worker     //
132*38e8c45fSAndroid Build Coastguard Worker     // Return of a negative value means an error has occurred:
133*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - one of the following could've happened:
134*38e8c45fSAndroid Build Coastguard Worker     //               * the buffer slot was invalid
135*38e8c45fSAndroid Build Coastguard Worker     //               * the fence was NULL
136*38e8c45fSAndroid Build Coastguard Worker     //               * the buffer slot specified is not in the acquired state
137*38e8c45fSAndroid Build Coastguard Worker     virtual status_t releaseBuffer(int buf, uint64_t frameNumber, EGLDisplay display,
138*38e8c45fSAndroid Build Coastguard Worker                                    EGLSyncKHR fence, const sp<Fence>& releaseFence) = 0;
139*38e8c45fSAndroid Build Coastguard Worker 
releaseBuffer(int buf,uint64_t frameNumber,const sp<Fence> & releaseFence)140*38e8c45fSAndroid Build Coastguard Worker     status_t releaseBuffer(int buf, uint64_t frameNumber, const sp<Fence>& releaseFence) {
141*38e8c45fSAndroid Build Coastguard Worker         return releaseBuffer(buf, frameNumber, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, releaseFence);
142*38e8c45fSAndroid Build Coastguard Worker     }
143*38e8c45fSAndroid Build Coastguard Worker 
144*38e8c45fSAndroid Build Coastguard Worker     // consumerConnect connects a consumer to the BufferQueue. Only one consumer may be connected,
145*38e8c45fSAndroid Build Coastguard Worker     // and when that consumer disconnects the BufferQueue is placed into the "abandoned" state,
146*38e8c45fSAndroid Build Coastguard Worker     // causing most interactions with the BufferQueue by the producer to fail. controlledByApp
147*38e8c45fSAndroid Build Coastguard Worker     // indicates whether the consumer is controlled by the application.
148*38e8c45fSAndroid Build Coastguard Worker     //
149*38e8c45fSAndroid Build Coastguard Worker     // consumer may not be NULL.
150*38e8c45fSAndroid Build Coastguard Worker     //
151*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
152*38e8c45fSAndroid Build Coastguard Worker     // * NO_INIT - the BufferQueue has been abandoned
153*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - a NULL consumer was provided
154*38e8c45fSAndroid Build Coastguard Worker     virtual status_t consumerConnect(const sp<IConsumerListener>& consumer,
155*38e8c45fSAndroid Build Coastguard Worker                                      bool controlledByApp) = 0;
156*38e8c45fSAndroid Build Coastguard Worker 
157*38e8c45fSAndroid Build Coastguard Worker     // consumerDisconnect disconnects a consumer from the BufferQueue. All buffers will be freed and
158*38e8c45fSAndroid Build Coastguard Worker     // the BufferQueue is placed in the "abandoned" state, causing most interactions with the
159*38e8c45fSAndroid Build Coastguard Worker     // BufferQueue by the producer to fail.
160*38e8c45fSAndroid Build Coastguard Worker     //
161*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
162*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - no consumer is currently connected
163*38e8c45fSAndroid Build Coastguard Worker     virtual status_t consumerDisconnect() = 0;
164*38e8c45fSAndroid Build Coastguard Worker 
165*38e8c45fSAndroid Build Coastguard Worker     // getReleasedBuffers sets the value pointed to by slotMask to a bit set. Each bit index with a
166*38e8c45fSAndroid Build Coastguard Worker     // 1 corresponds to a released buffer slot with that index value. In particular, a released
167*38e8c45fSAndroid Build Coastguard Worker     // buffer is one that has been released by the BufferQueue but has not yet been released by
168*38e8c45fSAndroid Build Coastguard Worker     // the consumer.
169*38e8c45fSAndroid Build Coastguard Worker     //
170*38e8c45fSAndroid Build Coastguard Worker     // This should be called from the onBuffersReleased() callback.
171*38e8c45fSAndroid Build Coastguard Worker     //
172*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
173*38e8c45fSAndroid Build Coastguard Worker     // * NO_INIT - the BufferQueue has been abandoned.
174*38e8c45fSAndroid Build Coastguard Worker     virtual status_t getReleasedBuffers(uint64_t* slotMask) = 0;
175*38e8c45fSAndroid Build Coastguard Worker 
176*38e8c45fSAndroid Build Coastguard Worker     // setDefaultBufferSize is used to set the size of buffers returned by dequeueBuffer when a
177*38e8c45fSAndroid Build Coastguard Worker     // width and height of zero is requested. Default is 1x1.
178*38e8c45fSAndroid Build Coastguard Worker     //
179*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
180*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - either w or h was zero
181*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0;
182*38e8c45fSAndroid Build Coastguard Worker 
183*38e8c45fSAndroid Build Coastguard Worker     // setMaxBufferCount sets the maximum value for the number of buffers used in the BufferQueue
184*38e8c45fSAndroid Build Coastguard Worker     // (the initial default is NUM_BUFFER_SLOTS). If a call to setMaxAcquiredBufferCount (by the
185*38e8c45fSAndroid Build Coastguard Worker     // consumer), or a call to setAsyncMode or setMaxDequeuedBufferCount (by the producer), would
186*38e8c45fSAndroid Build Coastguard Worker     // cause this value to be exceeded then that call will fail. This call will fail if a producer
187*38e8c45fSAndroid Build Coastguard Worker     // is connected to the BufferQueue.
188*38e8c45fSAndroid Build Coastguard Worker     //
189*38e8c45fSAndroid Build Coastguard Worker     // The count must be between 1 and NUM_BUFFER_SLOTS, inclusive. The count cannot be less than
190*38e8c45fSAndroid Build Coastguard Worker     // maxAcquiredBufferCount.
191*38e8c45fSAndroid Build Coastguard Worker     //
192*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
193*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - one of the below conditions occurred:
194*38e8c45fSAndroid Build Coastguard Worker     //               * bufferCount was out of range (see above).
195*38e8c45fSAndroid Build Coastguard Worker     //               * failure to adjust the number of available slots.
196*38e8c45fSAndroid Build Coastguard Worker     // * INVALID_OPERATION - attempting to call this after a producer connected.
197*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setMaxBufferCount(int bufferCount) = 0;
198*38e8c45fSAndroid Build Coastguard Worker 
199*38e8c45fSAndroid Build Coastguard Worker     // setMaxAcquiredBufferCount sets the maximum number of buffers that can be acquired by the
200*38e8c45fSAndroid Build Coastguard Worker     // consumer at one time (default 1). If this method succeeds, any new buffer slots will be both
201*38e8c45fSAndroid Build Coastguard Worker     // unallocated and owned by the BufferQueue object (i.e. they are not owned by the producer or
202*38e8c45fSAndroid Build Coastguard Worker     // consumer). Calling this may also cause some buffer slots to be emptied.
203*38e8c45fSAndroid Build Coastguard Worker     //
204*38e8c45fSAndroid Build Coastguard Worker     // This function should not be called with a value of maxAcquiredBuffers that is less than the
205*38e8c45fSAndroid Build Coastguard Worker     // number of currently acquired buffer slots. Doing so will result in a BAD_VALUE error.
206*38e8c45fSAndroid Build Coastguard Worker     //
207*38e8c45fSAndroid Build Coastguard Worker     // maxAcquiredBuffers must be (inclusive) between 1 and MAX_MAX_ACQUIRED_BUFFERS. It also cannot
208*38e8c45fSAndroid Build Coastguard Worker     // cause the maxBufferCount value to be exceeded.
209*38e8c45fSAndroid Build Coastguard Worker     //
210*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an error has occurred:
211*38e8c45fSAndroid Build Coastguard Worker     // * NO_INIT - the BufferQueue has been abandoned
212*38e8c45fSAndroid Build Coastguard Worker     // * BAD_VALUE - one of the below conditions occurred:
213*38e8c45fSAndroid Build Coastguard Worker     //               * maxAcquiredBuffers was out of range (see above).
214*38e8c45fSAndroid Build Coastguard Worker     //               * failure to adjust the number of available slots.
215*38e8c45fSAndroid Build Coastguard Worker     //               * client would have more than the requested number of acquired buffers after
216*38e8c45fSAndroid Build Coastguard Worker     //                 this call
217*38e8c45fSAndroid Build Coastguard Worker     // * INVALID_OPERATION - attempting to call this after a producer connected.
218*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0;
219*38e8c45fSAndroid Build Coastguard Worker 
220*38e8c45fSAndroid Build Coastguard Worker     // setConsumerName sets the name used in logging
221*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setConsumerName(const String8& name) = 0;
222*38e8c45fSAndroid Build Coastguard Worker 
223*38e8c45fSAndroid Build Coastguard Worker     // setDefaultBufferFormat allows the BufferQueue to create GraphicBuffers of a defaultFormat if
224*38e8c45fSAndroid Build Coastguard Worker     // no format is specified in dequeueBuffer. The initial default is PIXEL_FORMAT_RGBA_8888.
225*38e8c45fSAndroid Build Coastguard Worker     //
226*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an unknown error has occurred.
227*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) = 0;
228*38e8c45fSAndroid Build Coastguard Worker 
229*38e8c45fSAndroid Build Coastguard Worker     // setDefaultBufferDataSpace is a request to the producer to provide buffers of the indicated
230*38e8c45fSAndroid Build Coastguard Worker     // dataSpace. The producer may ignore this request. The initial default is
231*38e8c45fSAndroid Build Coastguard Worker     // HAL_DATASPACE_UNKNOWN.
232*38e8c45fSAndroid Build Coastguard Worker     //
233*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an unknown error has occurred.
234*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace) = 0;
235*38e8c45fSAndroid Build Coastguard Worker 
236*38e8c45fSAndroid Build Coastguard Worker     // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. These are merged
237*38e8c45fSAndroid Build Coastguard Worker     // with the bits passed to dequeueBuffer. The values are enumerated in gralloc.h,
238*38e8c45fSAndroid Build Coastguard Worker     // e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
239*38e8c45fSAndroid Build Coastguard Worker     //
240*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an unknown error has occurred.
241*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setConsumerUsageBits(uint64_t usage) = 0;
242*38e8c45fSAndroid Build Coastguard Worker 
243*38e8c45fSAndroid Build Coastguard Worker     // setConsumerIsProtected will turn on an internal bit that indicates whether
244*38e8c45fSAndroid Build Coastguard Worker     // the consumer can handle protected gralloc buffers (i.e. with
245*38e8c45fSAndroid Build Coastguard Worker     // GRALLOC_USAGE_PROTECTED set). IGraphicBufferProducer can query this
246*38e8c45fSAndroid Build Coastguard Worker     // capability using NATIVE_WINDOW_CONSUMER_IS_PROTECTED.
247*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setConsumerIsProtected(bool isProtected) = 0;
248*38e8c45fSAndroid Build Coastguard Worker 
249*38e8c45fSAndroid Build Coastguard Worker     // setTransformHint bakes in rotation to buffers so overlays can be used. The values are
250*38e8c45fSAndroid Build Coastguard Worker     // enumerated in window.h, e.g. NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0
251*38e8c45fSAndroid Build Coastguard Worker     // (no transform).
252*38e8c45fSAndroid Build Coastguard Worker     //
253*38e8c45fSAndroid Build Coastguard Worker     // Return of a value other than NO_ERROR means an unknown error has occurred.
254*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setTransformHint(uint32_t hint) = 0;
255*38e8c45fSAndroid Build Coastguard Worker 
256*38e8c45fSAndroid Build Coastguard Worker     // Retrieve the sideband buffer stream, if any.
257*38e8c45fSAndroid Build Coastguard Worker     virtual status_t getSidebandStream(sp<NativeHandle>* outStream) const = 0;
258*38e8c45fSAndroid Build Coastguard Worker 
259*38e8c45fSAndroid Build Coastguard Worker     // Retrieves any stored segments of the occupancy history of this BufferQueue and clears them.
260*38e8c45fSAndroid Build Coastguard Worker     // Optionally closes out the pending segment if forceFlush is true.
261*38e8c45fSAndroid Build Coastguard Worker     virtual status_t getOccupancyHistory(bool forceFlush,
262*38e8c45fSAndroid Build Coastguard Worker                                          std::vector<OccupancyTracker::Segment>* outHistory) = 0;
263*38e8c45fSAndroid Build Coastguard Worker 
264*38e8c45fSAndroid Build Coastguard Worker     // discardFreeBuffers releases all currently-free buffers held by the BufferQueue, in order to
265*38e8c45fSAndroid Build Coastguard Worker     // reduce the memory consumption of the BufferQueue to the minimum possible without
266*38e8c45fSAndroid Build Coastguard Worker     // discarding data.
267*38e8c45fSAndroid Build Coastguard Worker     // The consumer invoking this method is responsible for calling getReleasedBuffers() after this
268*38e8c45fSAndroid Build Coastguard Worker     // call to free up any of its locally cached buffers.
269*38e8c45fSAndroid Build Coastguard Worker     virtual status_t discardFreeBuffers() = 0;
270*38e8c45fSAndroid Build Coastguard Worker 
271*38e8c45fSAndroid Build Coastguard Worker     // dump state into a string
272*38e8c45fSAndroid Build Coastguard Worker     virtual status_t dumpState(const String8& prefix, String8* outResult) const = 0;
273*38e8c45fSAndroid Build Coastguard Worker 
274*38e8c45fSAndroid Build Coastguard Worker     // Provide backwards source compatibility
dumpState(String8 & result,const char * prefix)275*38e8c45fSAndroid Build Coastguard Worker     void dumpState(String8& result, const char* prefix) {
276*38e8c45fSAndroid Build Coastguard Worker         String8 returned;
277*38e8c45fSAndroid Build Coastguard Worker         dumpState(String8(prefix), &returned);
278*38e8c45fSAndroid Build Coastguard Worker         result.append(returned);
279*38e8c45fSAndroid Build Coastguard Worker     }
280*38e8c45fSAndroid Build Coastguard Worker };
281*38e8c45fSAndroid Build Coastguard Worker 
282*38e8c45fSAndroid Build Coastguard Worker #ifndef NO_BINDER
283*38e8c45fSAndroid Build Coastguard Worker class BnGraphicBufferConsumer : public SafeBnInterface<IGraphicBufferConsumer> {
284*38e8c45fSAndroid Build Coastguard Worker public:
BnGraphicBufferConsumer()285*38e8c45fSAndroid Build Coastguard Worker     BnGraphicBufferConsumer()
286*38e8c45fSAndroid Build Coastguard Worker           : SafeBnInterface<IGraphicBufferConsumer>("BnGraphicBufferConsumer") {}
287*38e8c45fSAndroid Build Coastguard Worker 
288*38e8c45fSAndroid Build Coastguard Worker     status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
289*38e8c45fSAndroid Build Coastguard Worker                         uint32_t flags = 0) override;
290*38e8c45fSAndroid Build Coastguard Worker };
291*38e8c45fSAndroid Build Coastguard Worker #else
292*38e8c45fSAndroid Build Coastguard Worker class BnGraphicBufferConsumer : public IGraphicBufferConsumer {
293*38e8c45fSAndroid Build Coastguard Worker };
294*38e8c45fSAndroid Build Coastguard Worker #endif
295*38e8c45fSAndroid Build Coastguard Worker 
296*38e8c45fSAndroid Build Coastguard Worker } // namespace android
297