xref: /aosp_15_r20/frameworks/native/include/gui/GLConsumer.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2010 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 #ifndef ANDROID_GUI_CONSUMER_H
18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_GUI_CONSUMER_H
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <EGL/egl.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <EGL/eglext.h>
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker #include <com_android_graphics_libgui_flags.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <gui/BufferQueueDefs.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <gui/ConsumerBase.h>
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker #include <ui/FenceTime.h>
28*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicBuffer.h>
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker #include <utils/String8.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <utils/Vector.h>
32*38e8c45fSAndroid Build Coastguard Worker #include <utils/threads.h>
33*38e8c45fSAndroid Build Coastguard Worker 
34*38e8c45fSAndroid Build Coastguard Worker namespace android {
35*38e8c45fSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------
36*38e8c45fSAndroid Build Coastguard Worker 
37*38e8c45fSAndroid Build Coastguard Worker 
38*38e8c45fSAndroid Build Coastguard Worker class String8;
39*38e8c45fSAndroid Build Coastguard Worker 
40*38e8c45fSAndroid Build Coastguard Worker /*
41*38e8c45fSAndroid Build Coastguard Worker  * GLConsumer consumes buffers of graphics data from a BufferQueue,
42*38e8c45fSAndroid Build Coastguard Worker  * and makes them available to OpenGL as a texture.
43*38e8c45fSAndroid Build Coastguard Worker  *
44*38e8c45fSAndroid Build Coastguard Worker  * A typical usage pattern is to set up the GLConsumer with the
45*38e8c45fSAndroid Build Coastguard Worker  * desired options, and call updateTexImage() when a new frame is desired.
46*38e8c45fSAndroid Build Coastguard Worker  * If a new frame is available, the texture will be updated.  If not,
47*38e8c45fSAndroid Build Coastguard Worker  * the previous contents are retained.
48*38e8c45fSAndroid Build Coastguard Worker  *
49*38e8c45fSAndroid Build Coastguard Worker  * By default, the texture is attached to the GL_TEXTURE_EXTERNAL_OES
50*38e8c45fSAndroid Build Coastguard Worker  * texture target, in the EGL context of the first thread that calls
51*38e8c45fSAndroid Build Coastguard Worker  * updateTexImage().
52*38e8c45fSAndroid Build Coastguard Worker  *
53*38e8c45fSAndroid Build Coastguard Worker  * This class was previously called SurfaceTexture.
54*38e8c45fSAndroid Build Coastguard Worker  */
55*38e8c45fSAndroid Build Coastguard Worker class GLConsumer : public ConsumerBase {
56*38e8c45fSAndroid Build Coastguard Worker public:
57*38e8c45fSAndroid Build Coastguard Worker     enum { TEXTURE_EXTERNAL = 0x8D65 }; // GL_TEXTURE_EXTERNAL_OES
58*38e8c45fSAndroid Build Coastguard Worker     typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
59*38e8c45fSAndroid Build Coastguard Worker 
60*38e8c45fSAndroid Build Coastguard Worker     // GLConsumer constructs a new GLConsumer object. If the constructor with
61*38e8c45fSAndroid Build Coastguard Worker     // the tex parameter is used, tex indicates the name of the OpenGL ES
62*38e8c45fSAndroid Build Coastguard Worker     // texture to which images are to be streamed. texTarget specifies the
63*38e8c45fSAndroid Build Coastguard Worker     // OpenGL ES texture target to which the texture will be bound in
64*38e8c45fSAndroid Build Coastguard Worker     // updateTexImage. useFenceSync specifies whether fences should be used to
65*38e8c45fSAndroid Build Coastguard Worker     // synchronize access to buffers if that behavior is enabled at
66*38e8c45fSAndroid Build Coastguard Worker     // compile-time.
67*38e8c45fSAndroid Build Coastguard Worker     //
68*38e8c45fSAndroid Build Coastguard Worker     // A GLConsumer may be detached from one OpenGL ES context and then
69*38e8c45fSAndroid Build Coastguard Worker     // attached to a different context using the detachFromContext and
70*38e8c45fSAndroid Build Coastguard Worker     // attachToContext methods, respectively. The intention of these methods is
71*38e8c45fSAndroid Build Coastguard Worker     // purely to allow a GLConsumer to be transferred from one consumer
72*38e8c45fSAndroid Build Coastguard Worker     // context to another. If such a transfer is not needed there is no
73*38e8c45fSAndroid Build Coastguard Worker     // requirement that either of these methods be called.
74*38e8c45fSAndroid Build Coastguard Worker     //
75*38e8c45fSAndroid Build Coastguard Worker     // If the constructor with the tex parameter is used, the GLConsumer is
76*38e8c45fSAndroid Build Coastguard Worker     // created in a state where it is considered attached to an OpenGL ES
77*38e8c45fSAndroid Build Coastguard Worker     // context for the purposes of the attachToContext and detachFromContext
78*38e8c45fSAndroid Build Coastguard Worker     // methods. However, despite being considered "attached" to a context, the
79*38e8c45fSAndroid Build Coastguard Worker     // specific OpenGL ES context doesn't get latched until the first call to
80*38e8c45fSAndroid Build Coastguard Worker     // updateTexImage. After that point, all calls to updateTexImage must be
81*38e8c45fSAndroid Build Coastguard Worker     // made with the same OpenGL ES context current.
82*38e8c45fSAndroid Build Coastguard Worker     //
83*38e8c45fSAndroid Build Coastguard Worker     // If the constructor without the tex parameter is used, the GLConsumer is
84*38e8c45fSAndroid Build Coastguard Worker     // created in a detached state, and attachToContext must be called before
85*38e8c45fSAndroid Build Coastguard Worker     // calls to updateTexImage.
86*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
87*38e8c45fSAndroid Build Coastguard Worker     GLConsumer(uint32_t tex, uint32_t textureTarget, bool useFenceSync, bool isControlledByApp);
88*38e8c45fSAndroid Build Coastguard Worker 
89*38e8c45fSAndroid Build Coastguard Worker     GLConsumer(uint32_t textureTarget, bool useFenceSync, bool isControlledByApp);
90*38e8c45fSAndroid Build Coastguard Worker 
91*38e8c45fSAndroid Build Coastguard Worker     GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t tex, uint32_t textureTarget,
92*38e8c45fSAndroid Build Coastguard Worker                bool useFenceSync, bool isControlledByApp)
93*38e8c45fSAndroid Build Coastguard Worker             __attribute((deprecated("Prefer ctors that create their own surface and consumer.")));
94*38e8c45fSAndroid Build Coastguard Worker 
95*38e8c45fSAndroid Build Coastguard Worker     GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t textureTarget, bool useFenceSync,
96*38e8c45fSAndroid Build Coastguard Worker                bool isControlledByApp)
97*38e8c45fSAndroid Build Coastguard Worker             __attribute((deprecated("Prefer ctors that create their own surface and consumer.")));
98*38e8c45fSAndroid Build Coastguard Worker #else
99*38e8c45fSAndroid Build Coastguard Worker     GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t tex, uint32_t textureTarget,
100*38e8c45fSAndroid Build Coastguard Worker                bool useFenceSync, bool isControlledByApp);
101*38e8c45fSAndroid Build Coastguard Worker 
102*38e8c45fSAndroid Build Coastguard Worker     GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t textureTarget, bool useFenceSync,
103*38e8c45fSAndroid Build Coastguard Worker                bool isControlledByApp);
104*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
105*38e8c45fSAndroid Build Coastguard Worker 
106*38e8c45fSAndroid Build Coastguard Worker     // updateTexImage acquires the most recently queued buffer, and sets the
107*38e8c45fSAndroid Build Coastguard Worker     // image contents of the target texture to it.
108*38e8c45fSAndroid Build Coastguard Worker     //
109*38e8c45fSAndroid Build Coastguard Worker     // This call may only be made while the OpenGL ES context to which the
110*38e8c45fSAndroid Build Coastguard Worker     // target texture belongs is bound to the calling thread.
111*38e8c45fSAndroid Build Coastguard Worker     //
112*38e8c45fSAndroid Build Coastguard Worker     // This calls doGLFenceWait to ensure proper synchronization.
113*38e8c45fSAndroid Build Coastguard Worker     status_t updateTexImage();
114*38e8c45fSAndroid Build Coastguard Worker 
115*38e8c45fSAndroid Build Coastguard Worker     // releaseTexImage releases the texture acquired in updateTexImage().
116*38e8c45fSAndroid Build Coastguard Worker     // This is intended to be used in single buffer mode.
117*38e8c45fSAndroid Build Coastguard Worker     //
118*38e8c45fSAndroid Build Coastguard Worker     // This call may only be made while the OpenGL ES context to which the
119*38e8c45fSAndroid Build Coastguard Worker     // target texture belongs is bound to the calling thread.
120*38e8c45fSAndroid Build Coastguard Worker     status_t releaseTexImage();
121*38e8c45fSAndroid Build Coastguard Worker 
122*38e8c45fSAndroid Build Coastguard Worker     // setReleaseFence stores a fence that will signal when the current buffer
123*38e8c45fSAndroid Build Coastguard Worker     // is no longer being read. This fence will be returned to the producer
124*38e8c45fSAndroid Build Coastguard Worker     // when the current buffer is released by updateTexImage(). Multiple
125*38e8c45fSAndroid Build Coastguard Worker     // fences can be set for a given buffer; they will be merged into a single
126*38e8c45fSAndroid Build Coastguard Worker     // union fence.
127*38e8c45fSAndroid Build Coastguard Worker     virtual void setReleaseFence(const sp<Fence>& fence);
128*38e8c45fSAndroid Build Coastguard Worker 
129*38e8c45fSAndroid Build Coastguard Worker     // getTransformMatrix retrieves the 4x4 texture coordinate transform matrix
130*38e8c45fSAndroid Build Coastguard Worker     // associated with the texture image set by the most recent call to
131*38e8c45fSAndroid Build Coastguard Worker     // updateTexImage.
132*38e8c45fSAndroid Build Coastguard Worker     //
133*38e8c45fSAndroid Build Coastguard Worker     // This transform matrix maps 2D homogeneous texture coordinates of the form
134*38e8c45fSAndroid Build Coastguard Worker     // (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture
135*38e8c45fSAndroid Build Coastguard Worker     // coordinate that should be used to sample that location from the texture.
136*38e8c45fSAndroid Build Coastguard Worker     // Sampling the texture outside of the range of this transform is undefined.
137*38e8c45fSAndroid Build Coastguard Worker     //
138*38e8c45fSAndroid Build Coastguard Worker     // This transform is necessary to compensate for transforms that the stream
139*38e8c45fSAndroid Build Coastguard Worker     // content producer may implicitly apply to the content. By forcing users of
140*38e8c45fSAndroid Build Coastguard Worker     // a GLConsumer to apply this transform we avoid performing an extra
141*38e8c45fSAndroid Build Coastguard Worker     // copy of the data that would be needed to hide the transform from the
142*38e8c45fSAndroid Build Coastguard Worker     // user.
143*38e8c45fSAndroid Build Coastguard Worker     //
144*38e8c45fSAndroid Build Coastguard Worker     // The matrix is stored in column-major order so that it may be passed
145*38e8c45fSAndroid Build Coastguard Worker     // directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv
146*38e8c45fSAndroid Build Coastguard Worker     // functions.
147*38e8c45fSAndroid Build Coastguard Worker     void getTransformMatrix(float mtx[16]);
148*38e8c45fSAndroid Build Coastguard Worker 
149*38e8c45fSAndroid Build Coastguard Worker     // Computes the transform matrix documented by getTransformMatrix
150*38e8c45fSAndroid Build Coastguard Worker     // from the BufferItem sub parts.
151*38e8c45fSAndroid Build Coastguard Worker     static void computeTransformMatrix(float outTransform[16],
152*38e8c45fSAndroid Build Coastguard Worker             const sp<GraphicBuffer>& buf, const Rect& cropRect,
153*38e8c45fSAndroid Build Coastguard Worker             uint32_t transform, bool filtering);
154*38e8c45fSAndroid Build Coastguard Worker 
155*38e8c45fSAndroid Build Coastguard Worker     static void computeTransformMatrix(float outTransform[16], float bufferWidth,
156*38e8c45fSAndroid Build Coastguard Worker                                        float bufferHeight, PixelFormat pixelFormat,
157*38e8c45fSAndroid Build Coastguard Worker                                        const Rect& cropRect, uint32_t transform, bool filtering);
158*38e8c45fSAndroid Build Coastguard Worker 
159*38e8c45fSAndroid Build Coastguard Worker     // Scale the crop down horizontally or vertically such that it has the
160*38e8c45fSAndroid Build Coastguard Worker     // same aspect ratio as the buffer does.
161*38e8c45fSAndroid Build Coastguard Worker     static Rect scaleDownCrop(const Rect& crop, uint32_t bufferWidth,
162*38e8c45fSAndroid Build Coastguard Worker             uint32_t bufferHeight);
163*38e8c45fSAndroid Build Coastguard Worker 
164*38e8c45fSAndroid Build Coastguard Worker     // getTimestamp retrieves the timestamp associated with the texture image
165*38e8c45fSAndroid Build Coastguard Worker     // set by the most recent call to updateTexImage.
166*38e8c45fSAndroid Build Coastguard Worker     //
167*38e8c45fSAndroid Build Coastguard Worker     // The timestamp is in nanoseconds, and is monotonically increasing. Its
168*38e8c45fSAndroid Build Coastguard Worker     // other semantics (zero point, etc) are source-dependent and should be
169*38e8c45fSAndroid Build Coastguard Worker     // documented by the source.
170*38e8c45fSAndroid Build Coastguard Worker     int64_t getTimestamp();
171*38e8c45fSAndroid Build Coastguard Worker 
172*38e8c45fSAndroid Build Coastguard Worker     // getDataSpace retrieves the DataSpace associated with the texture image
173*38e8c45fSAndroid Build Coastguard Worker     // set by the most recent call to updateTexImage.
174*38e8c45fSAndroid Build Coastguard Worker     android_dataspace getCurrentDataSpace();
175*38e8c45fSAndroid Build Coastguard Worker 
176*38e8c45fSAndroid Build Coastguard Worker     // getFrameNumber retrieves the frame number associated with the texture
177*38e8c45fSAndroid Build Coastguard Worker     // image set by the most recent call to updateTexImage.
178*38e8c45fSAndroid Build Coastguard Worker     //
179*38e8c45fSAndroid Build Coastguard Worker     // The frame number is an incrementing counter set to 0 at the creation of
180*38e8c45fSAndroid Build Coastguard Worker     // the BufferQueue associated with this consumer.
181*38e8c45fSAndroid Build Coastguard Worker     uint64_t getFrameNumber();
182*38e8c45fSAndroid Build Coastguard Worker 
183*38e8c45fSAndroid Build Coastguard Worker     // setDefaultBufferSize is used to set the size of buffers returned by
184*38e8c45fSAndroid Build Coastguard Worker     // requestBuffers when a with and height of zero is requested.
185*38e8c45fSAndroid Build Coastguard Worker     // A call to setDefaultBufferSize() may trigger requestBuffers() to
186*38e8c45fSAndroid Build Coastguard Worker     // be called from the client.
187*38e8c45fSAndroid Build Coastguard Worker     // The width and height parameters must be no greater than the minimum of
188*38e8c45fSAndroid Build Coastguard Worker     // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
189*38e8c45fSAndroid Build Coastguard Worker     // An error due to invalid dimensions might not be reported until
190*38e8c45fSAndroid Build Coastguard Worker     // updateTexImage() is called.
191*38e8c45fSAndroid Build Coastguard Worker     status_t setDefaultBufferSize(uint32_t width, uint32_t height);
192*38e8c45fSAndroid Build Coastguard Worker 
193*38e8c45fSAndroid Build Coastguard Worker     // setFilteringEnabled sets whether the transform matrix should be computed
194*38e8c45fSAndroid Build Coastguard Worker     // for use with bilinear filtering.
195*38e8c45fSAndroid Build Coastguard Worker     void setFilteringEnabled(bool enabled);
196*38e8c45fSAndroid Build Coastguard Worker 
197*38e8c45fSAndroid Build Coastguard Worker     // getCurrentBuffer returns the buffer associated with the current image.
198*38e8c45fSAndroid Build Coastguard Worker     // When outSlot is not nullptr, the current buffer slot index is also
199*38e8c45fSAndroid Build Coastguard Worker     // returned.
200*38e8c45fSAndroid Build Coastguard Worker     sp<GraphicBuffer> getCurrentBuffer(int* outSlot = nullptr) const;
201*38e8c45fSAndroid Build Coastguard Worker 
202*38e8c45fSAndroid Build Coastguard Worker     // getCurrentTextureTarget returns the texture target of the current
203*38e8c45fSAndroid Build Coastguard Worker     // texture as returned by updateTexImage().
204*38e8c45fSAndroid Build Coastguard Worker     uint32_t getCurrentTextureTarget() const;
205*38e8c45fSAndroid Build Coastguard Worker 
206*38e8c45fSAndroid Build Coastguard Worker     // getCurrentCrop returns the cropping rectangle of the current buffer.
207*38e8c45fSAndroid Build Coastguard Worker     Rect getCurrentCrop() const;
208*38e8c45fSAndroid Build Coastguard Worker 
209*38e8c45fSAndroid Build Coastguard Worker     // getCurrentTransform returns the transform of the current buffer.
210*38e8c45fSAndroid Build Coastguard Worker     uint32_t getCurrentTransform() const;
211*38e8c45fSAndroid Build Coastguard Worker 
212*38e8c45fSAndroid Build Coastguard Worker     // getCurrentScalingMode returns the scaling mode of the current buffer.
213*38e8c45fSAndroid Build Coastguard Worker     uint32_t getCurrentScalingMode() const;
214*38e8c45fSAndroid Build Coastguard Worker 
215*38e8c45fSAndroid Build Coastguard Worker     // getCurrentFence returns the fence indicating when the current buffer is
216*38e8c45fSAndroid Build Coastguard Worker     // ready to be read from.
217*38e8c45fSAndroid Build Coastguard Worker     sp<Fence> getCurrentFence() const;
218*38e8c45fSAndroid Build Coastguard Worker 
219*38e8c45fSAndroid Build Coastguard Worker     // getCurrentFence returns the FenceTime indicating when the current
220*38e8c45fSAndroid Build Coastguard Worker     // buffer is ready to be read from.
221*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<FenceTime> getCurrentFenceTime() const;
222*38e8c45fSAndroid Build Coastguard Worker 
223*38e8c45fSAndroid Build Coastguard Worker     // setConsumerUsageBits overrides the ConsumerBase method to OR
224*38e8c45fSAndroid Build Coastguard Worker     // DEFAULT_USAGE_FLAGS to usage.
225*38e8c45fSAndroid Build Coastguard Worker     status_t setConsumerUsageBits(uint64_t usage);
226*38e8c45fSAndroid Build Coastguard Worker 
227*38e8c45fSAndroid Build Coastguard Worker     // detachFromContext detaches the GLConsumer from the calling thread's
228*38e8c45fSAndroid Build Coastguard Worker     // current OpenGL ES context.  This context must be the same as the context
229*38e8c45fSAndroid Build Coastguard Worker     // that was current for previous calls to updateTexImage.
230*38e8c45fSAndroid Build Coastguard Worker     //
231*38e8c45fSAndroid Build Coastguard Worker     // Detaching a GLConsumer from an OpenGL ES context will result in the
232*38e8c45fSAndroid Build Coastguard Worker     // deletion of the OpenGL ES texture object into which the images were being
233*38e8c45fSAndroid Build Coastguard Worker     // streamed.  After a GLConsumer has been detached from the OpenGL ES
234*38e8c45fSAndroid Build Coastguard Worker     // context calls to updateTexImage will fail returning INVALID_OPERATION
235*38e8c45fSAndroid Build Coastguard Worker     // until the GLConsumer is attached to a new OpenGL ES context using the
236*38e8c45fSAndroid Build Coastguard Worker     // attachToContext method.
237*38e8c45fSAndroid Build Coastguard Worker     status_t detachFromContext();
238*38e8c45fSAndroid Build Coastguard Worker 
239*38e8c45fSAndroid Build Coastguard Worker     // attachToContext attaches a GLConsumer that is currently in the
240*38e8c45fSAndroid Build Coastguard Worker     // 'detached' state to the current OpenGL ES context.  A GLConsumer is
241*38e8c45fSAndroid Build Coastguard Worker     // in the 'detached' state iff detachFromContext has successfully been
242*38e8c45fSAndroid Build Coastguard Worker     // called and no calls to attachToContext have succeeded since the last
243*38e8c45fSAndroid Build Coastguard Worker     // detachFromContext call.  Calls to attachToContext made on a
244*38e8c45fSAndroid Build Coastguard Worker     // GLConsumer that is not in the 'detached' state will result in an
245*38e8c45fSAndroid Build Coastguard Worker     // INVALID_OPERATION error.
246*38e8c45fSAndroid Build Coastguard Worker     //
247*38e8c45fSAndroid Build Coastguard Worker     // The tex argument specifies the OpenGL ES texture object name in the
248*38e8c45fSAndroid Build Coastguard Worker     // new context into which the image contents will be streamed.  A successful
249*38e8c45fSAndroid Build Coastguard Worker     // call to attachToContext will result in this texture object being bound to
250*38e8c45fSAndroid Build Coastguard Worker     // the texture target and populated with the image contents that were
251*38e8c45fSAndroid Build Coastguard Worker     // current at the time of the last call to detachFromContext.
252*38e8c45fSAndroid Build Coastguard Worker     status_t attachToContext(uint32_t tex);
253*38e8c45fSAndroid Build Coastguard Worker 
254*38e8c45fSAndroid Build Coastguard Worker protected:
255*38e8c45fSAndroid Build Coastguard Worker 
256*38e8c45fSAndroid Build Coastguard Worker     // abandonLocked overrides the ConsumerBase method to clear
257*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTextureImage in addition to the ConsumerBase behavior.
258*38e8c45fSAndroid Build Coastguard Worker     virtual void abandonLocked();
259*38e8c45fSAndroid Build Coastguard Worker 
260*38e8c45fSAndroid Build Coastguard Worker     // dumpLocked overrides the ConsumerBase method to dump GLConsumer-
261*38e8c45fSAndroid Build Coastguard Worker     // specific info in addition to the ConsumerBase behavior.
262*38e8c45fSAndroid Build Coastguard Worker     virtual void dumpLocked(String8& result, const char* prefix) const;
263*38e8c45fSAndroid Build Coastguard Worker 
264*38e8c45fSAndroid Build Coastguard Worker     // acquireBufferLocked overrides the ConsumerBase method to update the
265*38e8c45fSAndroid Build Coastguard Worker     // mEglSlots array in addition to the ConsumerBase behavior.
266*38e8c45fSAndroid Build Coastguard Worker     virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen,
267*38e8c45fSAndroid Build Coastguard Worker             uint64_t maxFrameNumber = 0) override;
268*38e8c45fSAndroid Build Coastguard Worker 
269*38e8c45fSAndroid Build Coastguard Worker     // releaseBufferLocked overrides the ConsumerBase method to update the
270*38e8c45fSAndroid Build Coastguard Worker     // mEglSlots array in addition to the ConsumerBase.
271*38e8c45fSAndroid Build Coastguard Worker     virtual status_t releaseBufferLocked(int slot, const sp<GraphicBuffer> graphicBuffer,
272*38e8c45fSAndroid Build Coastguard Worker                                          EGLDisplay display = EGL_NO_DISPLAY,
273*38e8c45fSAndroid Build Coastguard Worker                                          EGLSyncKHR eglFence = EGL_NO_SYNC_KHR) override;
274*38e8c45fSAndroid Build Coastguard Worker 
releaseBufferLocked(int slot,const sp<GraphicBuffer> graphicBuffer,EGLSyncKHR eglFence)275*38e8c45fSAndroid Build Coastguard Worker     status_t releaseBufferLocked(int slot,
276*38e8c45fSAndroid Build Coastguard Worker             const sp<GraphicBuffer> graphicBuffer, EGLSyncKHR eglFence) {
277*38e8c45fSAndroid Build Coastguard Worker         return releaseBufferLocked(slot, graphicBuffer, mEglDisplay, eglFence);
278*38e8c45fSAndroid Build Coastguard Worker     }
279*38e8c45fSAndroid Build Coastguard Worker 
280*38e8c45fSAndroid Build Coastguard Worker     struct PendingRelease {
PendingReleasePendingRelease281*38e8c45fSAndroid Build Coastguard Worker         PendingRelease() : isPending(false), currentTexture(-1),
282*38e8c45fSAndroid Build Coastguard Worker                 graphicBuffer(), display(nullptr), fence(nullptr) {}
283*38e8c45fSAndroid Build Coastguard Worker 
284*38e8c45fSAndroid Build Coastguard Worker         bool isPending;
285*38e8c45fSAndroid Build Coastguard Worker         int currentTexture;
286*38e8c45fSAndroid Build Coastguard Worker         sp<GraphicBuffer> graphicBuffer;
287*38e8c45fSAndroid Build Coastguard Worker         EGLDisplay display;
288*38e8c45fSAndroid Build Coastguard Worker         EGLSyncKHR fence;
289*38e8c45fSAndroid Build Coastguard Worker     };
290*38e8c45fSAndroid Build Coastguard Worker 
291*38e8c45fSAndroid Build Coastguard Worker     // This releases the buffer in the slot referenced by mCurrentTexture,
292*38e8c45fSAndroid Build Coastguard Worker     // then updates state to refer to the BufferItem, which must be a
293*38e8c45fSAndroid Build Coastguard Worker     // newly-acquired buffer. If pendingRelease is not null, the parameters
294*38e8c45fSAndroid Build Coastguard Worker     // which would have been passed to releaseBufferLocked upon the successful
295*38e8c45fSAndroid Build Coastguard Worker     // completion of the method will instead be returned to the caller, so that
296*38e8c45fSAndroid Build Coastguard Worker     // it may call releaseBufferLocked itself later.
297*38e8c45fSAndroid Build Coastguard Worker     status_t updateAndReleaseLocked(const BufferItem& item,
298*38e8c45fSAndroid Build Coastguard Worker             PendingRelease* pendingRelease = nullptr);
299*38e8c45fSAndroid Build Coastguard Worker 
300*38e8c45fSAndroid Build Coastguard Worker     // Binds mTexName and the current buffer to mTexTarget.  Uses
301*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTexture if it's set, mCurrentTextureImage if not.  If the
302*38e8c45fSAndroid Build Coastguard Worker     // bind succeeds, this calls doGLFenceWait.
303*38e8c45fSAndroid Build Coastguard Worker     status_t bindTextureImageLocked();
304*38e8c45fSAndroid Build Coastguard Worker 
305*38e8c45fSAndroid Build Coastguard Worker     // Gets the current EGLDisplay and EGLContext values, and compares them
306*38e8c45fSAndroid Build Coastguard Worker     // to mEglDisplay and mEglContext.  If the fields have been previously
307*38e8c45fSAndroid Build Coastguard Worker     // set, the values must match; if not, the fields are set to the current
308*38e8c45fSAndroid Build Coastguard Worker     // values.
309*38e8c45fSAndroid Build Coastguard Worker     // The contextCheck argument is used to ensure that a GL context is
310*38e8c45fSAndroid Build Coastguard Worker     // properly set; when set to false, the check is not performed.
311*38e8c45fSAndroid Build Coastguard Worker     status_t checkAndUpdateEglStateLocked(bool contextCheck = false);
312*38e8c45fSAndroid Build Coastguard Worker 
313*38e8c45fSAndroid Build Coastguard Worker private:
314*38e8c45fSAndroid Build Coastguard Worker     // EglImage is a utility class for tracking and creating EGLImageKHRs. There
315*38e8c45fSAndroid Build Coastguard Worker     // is primarily just one image per slot, but there is also special cases:
316*38e8c45fSAndroid Build Coastguard Worker     //  - For releaseTexImage, we use a debug image (mReleasedTexImage)
317*38e8c45fSAndroid Build Coastguard Worker     //  - After freeBuffer, we must still keep the current image/buffer
318*38e8c45fSAndroid Build Coastguard Worker     // Reference counting EGLImages lets us handle all these cases easily while
319*38e8c45fSAndroid Build Coastguard Worker     // also only creating new EGLImages from buffers when required.
320*38e8c45fSAndroid Build Coastguard Worker     class EglImage : public LightRefBase<EglImage>  {
321*38e8c45fSAndroid Build Coastguard Worker     public:
322*38e8c45fSAndroid Build Coastguard Worker         explicit EglImage(sp<GraphicBuffer> graphicBuffer);
323*38e8c45fSAndroid Build Coastguard Worker 
324*38e8c45fSAndroid Build Coastguard Worker         // createIfNeeded creates an EGLImage if required (we haven't created
325*38e8c45fSAndroid Build Coastguard Worker         // one yet, or the EGLDisplay or crop-rect has changed).
326*38e8c45fSAndroid Build Coastguard Worker         status_t createIfNeeded(EGLDisplay display,
327*38e8c45fSAndroid Build Coastguard Worker                                 bool forceCreate = false);
328*38e8c45fSAndroid Build Coastguard Worker 
329*38e8c45fSAndroid Build Coastguard Worker         // This calls glEGLImageTargetTexture2DOES to bind the image to the
330*38e8c45fSAndroid Build Coastguard Worker         // texture in the specified texture target.
331*38e8c45fSAndroid Build Coastguard Worker         void bindToTextureTarget(uint32_t texTarget);
332*38e8c45fSAndroid Build Coastguard Worker 
graphicBuffer()333*38e8c45fSAndroid Build Coastguard Worker         const sp<GraphicBuffer>& graphicBuffer() { return mGraphicBuffer; }
graphicBufferHandle()334*38e8c45fSAndroid Build Coastguard Worker         const native_handle* graphicBufferHandle() {
335*38e8c45fSAndroid Build Coastguard Worker             return mGraphicBuffer == nullptr ? nullptr : mGraphicBuffer->handle;
336*38e8c45fSAndroid Build Coastguard Worker         }
337*38e8c45fSAndroid Build Coastguard Worker 
338*38e8c45fSAndroid Build Coastguard Worker     private:
339*38e8c45fSAndroid Build Coastguard Worker         // Only allow instantiation using ref counting.
340*38e8c45fSAndroid Build Coastguard Worker         friend class LightRefBase<EglImage>;
341*38e8c45fSAndroid Build Coastguard Worker         virtual ~EglImage();
342*38e8c45fSAndroid Build Coastguard Worker 
343*38e8c45fSAndroid Build Coastguard Worker         // createImage creates a new EGLImage from a GraphicBuffer.
344*38e8c45fSAndroid Build Coastguard Worker         EGLImageKHR createImage(EGLDisplay dpy,
345*38e8c45fSAndroid Build Coastguard Worker                 const sp<GraphicBuffer>& graphicBuffer);
346*38e8c45fSAndroid Build Coastguard Worker 
347*38e8c45fSAndroid Build Coastguard Worker         // Disallow copying
348*38e8c45fSAndroid Build Coastguard Worker         EglImage(const EglImage& rhs);
349*38e8c45fSAndroid Build Coastguard Worker         void operator = (const EglImage& rhs);
350*38e8c45fSAndroid Build Coastguard Worker 
351*38e8c45fSAndroid Build Coastguard Worker         // mGraphicBuffer is the buffer that was used to create this image.
352*38e8c45fSAndroid Build Coastguard Worker         sp<GraphicBuffer> mGraphicBuffer;
353*38e8c45fSAndroid Build Coastguard Worker 
354*38e8c45fSAndroid Build Coastguard Worker         // mEglImage is the EGLImage created from mGraphicBuffer.
355*38e8c45fSAndroid Build Coastguard Worker         EGLImageKHR mEglImage;
356*38e8c45fSAndroid Build Coastguard Worker 
357*38e8c45fSAndroid Build Coastguard Worker         // mEGLDisplay is the EGLDisplay that was used to create mEglImage.
358*38e8c45fSAndroid Build Coastguard Worker         EGLDisplay mEglDisplay;
359*38e8c45fSAndroid Build Coastguard Worker 
360*38e8c45fSAndroid Build Coastguard Worker         // mCropRect is the crop rectangle passed to EGL when mEglImage
361*38e8c45fSAndroid Build Coastguard Worker         // was created.
362*38e8c45fSAndroid Build Coastguard Worker         Rect mCropRect;
363*38e8c45fSAndroid Build Coastguard Worker     };
364*38e8c45fSAndroid Build Coastguard Worker 
365*38e8c45fSAndroid Build Coastguard Worker     // freeBufferLocked frees up the given buffer slot. If the slot has been
366*38e8c45fSAndroid Build Coastguard Worker     // initialized this will release the reference to the GraphicBuffer in that
367*38e8c45fSAndroid Build Coastguard Worker     // slot and destroy the EGLImage in that slot.  Otherwise it has no effect.
368*38e8c45fSAndroid Build Coastguard Worker     //
369*38e8c45fSAndroid Build Coastguard Worker     // This method must be called with mMutex locked.
370*38e8c45fSAndroid Build Coastguard Worker     virtual void freeBufferLocked(int slotIndex);
371*38e8c45fSAndroid Build Coastguard Worker 
372*38e8c45fSAndroid Build Coastguard Worker     // computeCurrentTransformMatrixLocked computes the transform matrix for the
373*38e8c45fSAndroid Build Coastguard Worker     // current texture.  It uses mCurrentTransform and the current GraphicBuffer
374*38e8c45fSAndroid Build Coastguard Worker     // to compute this matrix and stores it in mCurrentTransformMatrix.
375*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTextureImage must not be NULL.
376*38e8c45fSAndroid Build Coastguard Worker     void computeCurrentTransformMatrixLocked();
377*38e8c45fSAndroid Build Coastguard Worker 
378*38e8c45fSAndroid Build Coastguard Worker     // doGLFenceWaitLocked inserts a wait command into the OpenGL ES command
379*38e8c45fSAndroid Build Coastguard Worker     // stream to ensure that it is safe for future OpenGL ES commands to
380*38e8c45fSAndroid Build Coastguard Worker     // access the current texture buffer.
381*38e8c45fSAndroid Build Coastguard Worker     status_t doGLFenceWaitLocked() const;
382*38e8c45fSAndroid Build Coastguard Worker 
383*38e8c45fSAndroid Build Coastguard Worker     // syncForReleaseLocked performs the synchronization needed to release the
384*38e8c45fSAndroid Build Coastguard Worker     // current slot from an OpenGL ES context.  If needed it will set the
385*38e8c45fSAndroid Build Coastguard Worker     // current slot's fence to guard against a producer accessing the buffer
386*38e8c45fSAndroid Build Coastguard Worker     // before the outstanding accesses have completed.
387*38e8c45fSAndroid Build Coastguard Worker     status_t syncForReleaseLocked(EGLDisplay dpy);
388*38e8c45fSAndroid Build Coastguard Worker 
389*38e8c45fSAndroid Build Coastguard Worker     // returns a graphic buffer used when the texture image has been released
390*38e8c45fSAndroid Build Coastguard Worker     static sp<GraphicBuffer> getDebugTexImageBuffer();
391*38e8c45fSAndroid Build Coastguard Worker 
392*38e8c45fSAndroid Build Coastguard Worker     // The default consumer usage flags that GLConsumer always sets on its
393*38e8c45fSAndroid Build Coastguard Worker     // BufferQueue instance; these will be OR:d with any additional flags passed
394*38e8c45fSAndroid Build Coastguard Worker     // from the GLConsumer user. In particular, GLConsumer will always
395*38e8c45fSAndroid Build Coastguard Worker     // consume buffers as hardware textures.
396*38e8c45fSAndroid Build Coastguard Worker     static const uint64_t DEFAULT_USAGE_FLAGS = GraphicBuffer::USAGE_HW_TEXTURE;
397*38e8c45fSAndroid Build Coastguard Worker 
398*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTextureImage is the EglImage/buffer of the current texture. It's
399*38e8c45fSAndroid Build Coastguard Worker     // possible that this buffer is not associated with any buffer slot, so we
400*38e8c45fSAndroid Build Coastguard Worker     // must track it separately in order to support the getCurrentBuffer method.
401*38e8c45fSAndroid Build Coastguard Worker     sp<EglImage> mCurrentTextureImage;
402*38e8c45fSAndroid Build Coastguard Worker 
403*38e8c45fSAndroid Build Coastguard Worker     // mCurrentCrop is the crop rectangle that applies to the current texture.
404*38e8c45fSAndroid Build Coastguard Worker     // It gets set each time updateTexImage is called.
405*38e8c45fSAndroid Build Coastguard Worker     Rect mCurrentCrop;
406*38e8c45fSAndroid Build Coastguard Worker 
407*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTransform is the transform identifier for the current texture. It
408*38e8c45fSAndroid Build Coastguard Worker     // gets set each time updateTexImage is called.
409*38e8c45fSAndroid Build Coastguard Worker     uint32_t mCurrentTransform;
410*38e8c45fSAndroid Build Coastguard Worker 
411*38e8c45fSAndroid Build Coastguard Worker     // mCurrentScalingMode is the scaling mode for the current texture. It gets
412*38e8c45fSAndroid Build Coastguard Worker     // set each time updateTexImage is called.
413*38e8c45fSAndroid Build Coastguard Worker     uint32_t mCurrentScalingMode;
414*38e8c45fSAndroid Build Coastguard Worker 
415*38e8c45fSAndroid Build Coastguard Worker     // mCurrentFence is the fence received from BufferQueue in updateTexImage.
416*38e8c45fSAndroid Build Coastguard Worker     sp<Fence> mCurrentFence;
417*38e8c45fSAndroid Build Coastguard Worker 
418*38e8c45fSAndroid Build Coastguard Worker     // The FenceTime wrapper around mCurrentFence.
419*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<FenceTime> mCurrentFenceTime{FenceTime::NO_FENCE};
420*38e8c45fSAndroid Build Coastguard Worker 
421*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTransformMatrix is the transform matrix for the current texture.
422*38e8c45fSAndroid Build Coastguard Worker     // It gets computed by computeTransformMatrix each time updateTexImage is
423*38e8c45fSAndroid Build Coastguard Worker     // called.
424*38e8c45fSAndroid Build Coastguard Worker     float mCurrentTransformMatrix[16];
425*38e8c45fSAndroid Build Coastguard Worker 
426*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTimestamp is the timestamp for the current texture. It
427*38e8c45fSAndroid Build Coastguard Worker     // gets set each time updateTexImage is called.
428*38e8c45fSAndroid Build Coastguard Worker     int64_t mCurrentTimestamp;
429*38e8c45fSAndroid Build Coastguard Worker 
430*38e8c45fSAndroid Build Coastguard Worker     // mCurrentDataSpace is the dataspace for the current texture. It
431*38e8c45fSAndroid Build Coastguard Worker     // gets set each time updateTexImage is called.
432*38e8c45fSAndroid Build Coastguard Worker     android_dataspace mCurrentDataSpace;
433*38e8c45fSAndroid Build Coastguard Worker 
434*38e8c45fSAndroid Build Coastguard Worker     // mCurrentFrameNumber is the frame counter for the current texture.
435*38e8c45fSAndroid Build Coastguard Worker     // It gets set each time updateTexImage is called.
436*38e8c45fSAndroid Build Coastguard Worker     uint64_t mCurrentFrameNumber;
437*38e8c45fSAndroid Build Coastguard Worker 
438*38e8c45fSAndroid Build Coastguard Worker     uint32_t mDefaultWidth, mDefaultHeight;
439*38e8c45fSAndroid Build Coastguard Worker 
440*38e8c45fSAndroid Build Coastguard Worker     // mFilteringEnabled indicates whether the transform matrix is computed for
441*38e8c45fSAndroid Build Coastguard Worker     // use with bilinear filtering. It defaults to true and is changed by
442*38e8c45fSAndroid Build Coastguard Worker     // setFilteringEnabled().
443*38e8c45fSAndroid Build Coastguard Worker     bool mFilteringEnabled;
444*38e8c45fSAndroid Build Coastguard Worker 
445*38e8c45fSAndroid Build Coastguard Worker     // mTexName is the name of the OpenGL texture to which streamed images will
446*38e8c45fSAndroid Build Coastguard Worker     // be bound when updateTexImage is called. It is set at construction time
447*38e8c45fSAndroid Build Coastguard Worker     // and can be changed with a call to attachToContext.
448*38e8c45fSAndroid Build Coastguard Worker     uint32_t mTexName;
449*38e8c45fSAndroid Build Coastguard Worker 
450*38e8c45fSAndroid Build Coastguard Worker     // mUseFenceSync indicates whether creation of the EGL_KHR_fence_sync
451*38e8c45fSAndroid Build Coastguard Worker     // extension should be used to prevent buffers from being dequeued before
452*38e8c45fSAndroid Build Coastguard Worker     // it's safe for them to be written. It gets set at construction time and
453*38e8c45fSAndroid Build Coastguard Worker     // never changes.
454*38e8c45fSAndroid Build Coastguard Worker     const bool mUseFenceSync;
455*38e8c45fSAndroid Build Coastguard Worker 
456*38e8c45fSAndroid Build Coastguard Worker     // mTexTarget is the GL texture target with which the GL texture object is
457*38e8c45fSAndroid Build Coastguard Worker     // associated.  It is set in the constructor and never changed.  It is
458*38e8c45fSAndroid Build Coastguard Worker     // almost always GL_TEXTURE_EXTERNAL_OES except for one use case in Android
459*38e8c45fSAndroid Build Coastguard Worker     // Browser.  In that case it is set to GL_TEXTURE_2D to allow
460*38e8c45fSAndroid Build Coastguard Worker     // glCopyTexSubImage to read from the texture.  This is a hack to work
461*38e8c45fSAndroid Build Coastguard Worker     // around a GL driver limitation on the number of FBO attachments, which the
462*38e8c45fSAndroid Build Coastguard Worker     // browser's tile cache exceeds.
463*38e8c45fSAndroid Build Coastguard Worker     const uint32_t mTexTarget;
464*38e8c45fSAndroid Build Coastguard Worker 
465*38e8c45fSAndroid Build Coastguard Worker     // EGLSlot contains the information and object references that
466*38e8c45fSAndroid Build Coastguard Worker     // GLConsumer maintains about a BufferQueue buffer slot.
467*38e8c45fSAndroid Build Coastguard Worker     struct EglSlot {
EglSlotEglSlot468*38e8c45fSAndroid Build Coastguard Worker         EglSlot() : mEglFence(EGL_NO_SYNC_KHR) {}
469*38e8c45fSAndroid Build Coastguard Worker 
470*38e8c45fSAndroid Build Coastguard Worker         // mEglImage is the EGLImage created from mGraphicBuffer.
471*38e8c45fSAndroid Build Coastguard Worker         sp<EglImage> mEglImage;
472*38e8c45fSAndroid Build Coastguard Worker 
473*38e8c45fSAndroid Build Coastguard Worker         // mFence is the EGL sync object that must signal before the buffer
474*38e8c45fSAndroid Build Coastguard Worker         // associated with this buffer slot may be dequeued. It is initialized
475*38e8c45fSAndroid Build Coastguard Worker         // to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
476*38e8c45fSAndroid Build Coastguard Worker         // on a compile-time option) set to a new sync object in updateTexImage.
477*38e8c45fSAndroid Build Coastguard Worker         EGLSyncKHR mEglFence;
478*38e8c45fSAndroid Build Coastguard Worker     };
479*38e8c45fSAndroid Build Coastguard Worker 
480*38e8c45fSAndroid Build Coastguard Worker     // mEglDisplay is the EGLDisplay with which this GLConsumer is currently
481*38e8c45fSAndroid Build Coastguard Worker     // associated.  It is intialized to EGL_NO_DISPLAY and gets set to the
482*38e8c45fSAndroid Build Coastguard Worker     // current display when updateTexImage is called for the first time and when
483*38e8c45fSAndroid Build Coastguard Worker     // attachToContext is called.
484*38e8c45fSAndroid Build Coastguard Worker     EGLDisplay mEglDisplay;
485*38e8c45fSAndroid Build Coastguard Worker 
486*38e8c45fSAndroid Build Coastguard Worker     // mEglContext is the OpenGL ES context with which this GLConsumer is
487*38e8c45fSAndroid Build Coastguard Worker     // currently associated.  It is initialized to EGL_NO_CONTEXT and gets set
488*38e8c45fSAndroid Build Coastguard Worker     // to the current GL context when updateTexImage is called for the first
489*38e8c45fSAndroid Build Coastguard Worker     // time and when attachToContext is called.
490*38e8c45fSAndroid Build Coastguard Worker     EGLContext mEglContext;
491*38e8c45fSAndroid Build Coastguard Worker 
492*38e8c45fSAndroid Build Coastguard Worker     // mEGLSlots stores the buffers that have been allocated by the BufferQueue
493*38e8c45fSAndroid Build Coastguard Worker     // for each buffer slot.  It is initialized to null pointers, and gets
494*38e8c45fSAndroid Build Coastguard Worker     // filled in with the result of BufferQueue::acquire when the
495*38e8c45fSAndroid Build Coastguard Worker     // client dequeues a buffer from a
496*38e8c45fSAndroid Build Coastguard Worker     // slot that has not yet been used. The buffer allocated to a slot will also
497*38e8c45fSAndroid Build Coastguard Worker     // be replaced if the requested buffer usage or geometry differs from that
498*38e8c45fSAndroid Build Coastguard Worker     // of the buffer allocated to a slot.
499*38e8c45fSAndroid Build Coastguard Worker     EglSlot mEglSlots[BufferQueueDefs::NUM_BUFFER_SLOTS];
500*38e8c45fSAndroid Build Coastguard Worker 
501*38e8c45fSAndroid Build Coastguard Worker     // mCurrentTexture is the buffer slot index of the buffer that is currently
502*38e8c45fSAndroid Build Coastguard Worker     // bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT,
503*38e8c45fSAndroid Build Coastguard Worker     // indicating that no buffer slot is currently bound to the texture. Note,
504*38e8c45fSAndroid Build Coastguard Worker     // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean
505*38e8c45fSAndroid Build Coastguard Worker     // that no buffer is bound to the texture. A call to setBufferCount will
506*38e8c45fSAndroid Build Coastguard Worker     // reset mCurrentTexture to INVALID_BUFFER_SLOT.
507*38e8c45fSAndroid Build Coastguard Worker     int mCurrentTexture;
508*38e8c45fSAndroid Build Coastguard Worker 
509*38e8c45fSAndroid Build Coastguard Worker     // mAttached indicates whether the ConsumerBase is currently attached to
510*38e8c45fSAndroid Build Coastguard Worker     // an OpenGL ES context.  For legacy reasons, this is initialized to true,
511*38e8c45fSAndroid Build Coastguard Worker     // indicating that the ConsumerBase is considered to be attached to
512*38e8c45fSAndroid Build Coastguard Worker     // whatever context is current at the time of the first updateTexImage call.
513*38e8c45fSAndroid Build Coastguard Worker     // It is set to false by detachFromContext, and then set to true again by
514*38e8c45fSAndroid Build Coastguard Worker     // attachToContext.
515*38e8c45fSAndroid Build Coastguard Worker     bool mAttached;
516*38e8c45fSAndroid Build Coastguard Worker 
517*38e8c45fSAndroid Build Coastguard Worker     // protects static initialization
518*38e8c45fSAndroid Build Coastguard Worker     static Mutex sStaticInitLock;
519*38e8c45fSAndroid Build Coastguard Worker 
520*38e8c45fSAndroid Build Coastguard Worker     // mReleasedTexImageBuffer is a buffer placeholder used when in single buffer
521*38e8c45fSAndroid Build Coastguard Worker     // mode and releaseTexImage() has been called
522*38e8c45fSAndroid Build Coastguard Worker     static sp<GraphicBuffer> sReleasedTexImageBuffer;
523*38e8c45fSAndroid Build Coastguard Worker     sp<EglImage> mReleasedTexImage;
524*38e8c45fSAndroid Build Coastguard Worker };
525*38e8c45fSAndroid Build Coastguard Worker 
526*38e8c45fSAndroid Build Coastguard Worker // ----------------------------------------------------------------------------
527*38e8c45fSAndroid Build Coastguard Worker }; // namespace android
528*38e8c45fSAndroid Build Coastguard Worker 
529*38e8c45fSAndroid Build Coastguard Worker #endif // ANDROID_GUI_CONSUMER_H
530