xref: /aosp_15_r20/external/angle/src/libANGLE/Surface.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker // Surface.h: Defines the egl::Surface class, representing a drawing surface
8*8975f5c5SAndroid Build Coastguard Worker // such as the client area of a window, including any back buffers.
9*8975f5c5SAndroid Build Coastguard Worker // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3.
10*8975f5c5SAndroid Build Coastguard Worker 
11*8975f5c5SAndroid Build Coastguard Worker #ifndef LIBANGLE_SURFACE_H_
12*8975f5c5SAndroid Build Coastguard Worker #define LIBANGLE_SURFACE_H_
13*8975f5c5SAndroid Build Coastguard Worker 
14*8975f5c5SAndroid Build Coastguard Worker #include <memory>
15*8975f5c5SAndroid Build Coastguard Worker 
16*8975f5c5SAndroid Build Coastguard Worker #include <EGL/egl.h>
17*8975f5c5SAndroid Build Coastguard Worker 
18*8975f5c5SAndroid Build Coastguard Worker #include "common/PackedEnums.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "common/angleutils.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/AttributeMap.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Debug.h"
22*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Error.h"
23*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/FramebufferAttachment.h"
24*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/RefCountObject.h"
25*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/formatutils.h"
26*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/SurfaceImpl.h"
27*8975f5c5SAndroid Build Coastguard Worker 
28*8975f5c5SAndroid Build Coastguard Worker namespace gl
29*8975f5c5SAndroid Build Coastguard Worker {
30*8975f5c5SAndroid Build Coastguard Worker class Context;
31*8975f5c5SAndroid Build Coastguard Worker class Framebuffer;
32*8975f5c5SAndroid Build Coastguard Worker class Texture;
33*8975f5c5SAndroid Build Coastguard Worker }  // namespace gl
34*8975f5c5SAndroid Build Coastguard Worker 
35*8975f5c5SAndroid Build Coastguard Worker namespace rx
36*8975f5c5SAndroid Build Coastguard Worker {
37*8975f5c5SAndroid Build Coastguard Worker class EGLImplFactory;
38*8975f5c5SAndroid Build Coastguard Worker }
39*8975f5c5SAndroid Build Coastguard Worker 
40*8975f5c5SAndroid Build Coastguard Worker namespace egl
41*8975f5c5SAndroid Build Coastguard Worker {
42*8975f5c5SAndroid Build Coastguard Worker class Display;
43*8975f5c5SAndroid Build Coastguard Worker struct Config;
44*8975f5c5SAndroid Build Coastguard Worker 
45*8975f5c5SAndroid Build Coastguard Worker using SupportedCompositorTiming = angle::PackedEnumBitSet<CompositorTiming>;
46*8975f5c5SAndroid Build Coastguard Worker using SupportedTimestamps       = angle::PackedEnumBitSet<Timestamp>;
47*8975f5c5SAndroid Build Coastguard Worker 
48*8975f5c5SAndroid Build Coastguard Worker struct SurfaceState final : private angle::NonCopyable
49*8975f5c5SAndroid Build Coastguard Worker {
50*8975f5c5SAndroid Build Coastguard Worker     SurfaceState(SurfaceID idIn, const egl::Config *configIn, const AttributeMap &attributesIn);
51*8975f5c5SAndroid Build Coastguard Worker     ~SurfaceState();
52*8975f5c5SAndroid Build Coastguard Worker 
53*8975f5c5SAndroid Build Coastguard Worker     bool isRobustResourceInitEnabled() const;
54*8975f5c5SAndroid Build Coastguard Worker     bool hasProtectedContent() const;
55*8975f5c5SAndroid Build Coastguard Worker     EGLint getPreferredSwapInterval() const;
56*8975f5c5SAndroid Build Coastguard Worker 
57*8975f5c5SAndroid Build Coastguard Worker     SurfaceID id;
58*8975f5c5SAndroid Build Coastguard Worker 
59*8975f5c5SAndroid Build Coastguard Worker     EGLLabelKHR label;
60*8975f5c5SAndroid Build Coastguard Worker     const egl::Config *config;
61*8975f5c5SAndroid Build Coastguard Worker     AttributeMap attributes;
62*8975f5c5SAndroid Build Coastguard Worker 
63*8975f5c5SAndroid Build Coastguard Worker     bool timestampsEnabled;
64*8975f5c5SAndroid Build Coastguard Worker     bool autoRefreshEnabled;
65*8975f5c5SAndroid Build Coastguard Worker     SupportedCompositorTiming supportedCompositorTimings;
66*8975f5c5SAndroid Build Coastguard Worker     SupportedTimestamps supportedTimestamps;
67*8975f5c5SAndroid Build Coastguard Worker     bool directComposition;
68*8975f5c5SAndroid Build Coastguard Worker     EGLenum swapBehavior;
69*8975f5c5SAndroid Build Coastguard Worker };
70*8975f5c5SAndroid Build Coastguard Worker 
71*8975f5c5SAndroid Build Coastguard Worker class Surface : public LabeledObject, public gl::FramebufferAttachmentObject
72*8975f5c5SAndroid Build Coastguard Worker {
73*8975f5c5SAndroid Build Coastguard Worker   public:
getImplementation()74*8975f5c5SAndroid Build Coastguard Worker     rx::SurfaceImpl *getImplementation() const { return mImplementation; }
75*8975f5c5SAndroid Build Coastguard Worker 
76*8975f5c5SAndroid Build Coastguard Worker     void setLabel(EGLLabelKHR label) override;
77*8975f5c5SAndroid Build Coastguard Worker     EGLLabelKHR getLabel() const override;
78*8975f5c5SAndroid Build Coastguard Worker 
79*8975f5c5SAndroid Build Coastguard Worker     EGLint getType() const;
80*8975f5c5SAndroid Build Coastguard Worker 
81*8975f5c5SAndroid Build Coastguard Worker     Error initialize(const Display *display);
82*8975f5c5SAndroid Build Coastguard Worker     Error makeCurrent(const gl::Context *context);
83*8975f5c5SAndroid Build Coastguard Worker     Error unMakeCurrent(const gl::Context *context);
84*8975f5c5SAndroid Build Coastguard Worker     Error prepareSwap(const gl::Context *context);
85*8975f5c5SAndroid Build Coastguard Worker     Error swap(gl::Context *context);
86*8975f5c5SAndroid Build Coastguard Worker     Error swapWithDamage(gl::Context *context, const EGLint *rects, EGLint n_rects);
87*8975f5c5SAndroid Build Coastguard Worker     Error swapWithFrameToken(gl::Context *context, EGLFrameTokenANGLE frameToken);
88*8975f5c5SAndroid Build Coastguard Worker     Error postSubBuffer(const gl::Context *context,
89*8975f5c5SAndroid Build Coastguard Worker                         EGLint x,
90*8975f5c5SAndroid Build Coastguard Worker                         EGLint y,
91*8975f5c5SAndroid Build Coastguard Worker                         EGLint width,
92*8975f5c5SAndroid Build Coastguard Worker                         EGLint height);
93*8975f5c5SAndroid Build Coastguard Worker     Error setPresentationTime(EGLnsecsANDROID time);
94*8975f5c5SAndroid Build Coastguard Worker     Error querySurfacePointerANGLE(EGLint attribute, void **value);
95*8975f5c5SAndroid Build Coastguard Worker     Error bindTexImage(gl::Context *context, gl::Texture *texture, EGLint buffer);
96*8975f5c5SAndroid Build Coastguard Worker     Error releaseTexImage(const gl::Context *context, EGLint buffer);
97*8975f5c5SAndroid Build Coastguard Worker 
98*8975f5c5SAndroid Build Coastguard Worker     Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc);
99*8975f5c5SAndroid Build Coastguard Worker     Error getMscRate(EGLint *numerator, EGLint *denominator);
100*8975f5c5SAndroid Build Coastguard Worker 
101*8975f5c5SAndroid Build Coastguard Worker     EGLint isPostSubBufferSupported() const;
102*8975f5c5SAndroid Build Coastguard Worker 
103*8975f5c5SAndroid Build Coastguard Worker     void setSwapInterval(const Display *display, EGLint interval);
104*8975f5c5SAndroid Build Coastguard Worker     Error onDestroy(const Display *display);
105*8975f5c5SAndroid Build Coastguard Worker 
106*8975f5c5SAndroid Build Coastguard Worker     void setMipmapLevel(EGLint level);
107*8975f5c5SAndroid Build Coastguard Worker     void setMultisampleResolve(EGLenum resolve);
108*8975f5c5SAndroid Build Coastguard Worker     void setSwapBehavior(EGLenum behavior);
109*8975f5c5SAndroid Build Coastguard Worker 
110*8975f5c5SAndroid Build Coastguard Worker     void setFixedWidth(EGLint width);
111*8975f5c5SAndroid Build Coastguard Worker     void setFixedHeight(EGLint height);
112*8975f5c5SAndroid Build Coastguard Worker 
113*8975f5c5SAndroid Build Coastguard Worker     const Config *getConfig() const;
114*8975f5c5SAndroid Build Coastguard Worker 
115*8975f5c5SAndroid Build Coastguard Worker     // width and height can change with client window resizing
116*8975f5c5SAndroid Build Coastguard Worker     EGLint getWidth() const;
117*8975f5c5SAndroid Build Coastguard Worker     EGLint getHeight() const;
118*8975f5c5SAndroid Build Coastguard Worker     // Note: windows cannot be resized on Android.  The approach requires
119*8975f5c5SAndroid Build Coastguard Worker     // calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR.  However, that is
120*8975f5c5SAndroid Build Coastguard Worker     // expensive; and there are troublesome timing issues for other parts of
121*8975f5c5SAndroid Build Coastguard Worker     // ANGLE (which cause test failures and crashes).  Therefore, a
122*8975f5c5SAndroid Build Coastguard Worker     // special-Android-only path is created just for the querying of EGL_WIDTH
123*8975f5c5SAndroid Build Coastguard Worker     // and EGL_HEIGHT.
124*8975f5c5SAndroid Build Coastguard Worker     // https://issuetracker.google.com/issues/153329980
125*8975f5c5SAndroid Build Coastguard Worker     egl::Error getUserWidth(const egl::Display *display, EGLint *value) const;
126*8975f5c5SAndroid Build Coastguard Worker     egl::Error getUserHeight(const egl::Display *display, EGLint *value) const;
127*8975f5c5SAndroid Build Coastguard Worker     EGLint getPixelAspectRatio() const;
128*8975f5c5SAndroid Build Coastguard Worker     EGLenum getRenderBuffer() const;
129*8975f5c5SAndroid Build Coastguard Worker     EGLenum getSwapBehavior() const;
130*8975f5c5SAndroid Build Coastguard Worker     TextureFormat getTextureFormat() const;
131*8975f5c5SAndroid Build Coastguard Worker     EGLenum getTextureTarget() const;
132*8975f5c5SAndroid Build Coastguard Worker     bool getLargestPbuffer() const;
133*8975f5c5SAndroid Build Coastguard Worker     EGLenum getGLColorspace() const;
134*8975f5c5SAndroid Build Coastguard Worker     EGLenum getVGAlphaFormat() const;
135*8975f5c5SAndroid Build Coastguard Worker     EGLenum getVGColorspace() const;
136*8975f5c5SAndroid Build Coastguard Worker     bool getMipmapTexture() const;
137*8975f5c5SAndroid Build Coastguard Worker     EGLint getMipmapLevel() const;
138*8975f5c5SAndroid Build Coastguard Worker     EGLint getHorizontalResolution() const;
139*8975f5c5SAndroid Build Coastguard Worker     EGLint getVerticalResolution() const;
140*8975f5c5SAndroid Build Coastguard Worker     EGLenum getMultisampleResolve() const;
141*8975f5c5SAndroid Build Coastguard Worker     bool hasProtectedContent() const override;
hasFoveatedRendering()142*8975f5c5SAndroid Build Coastguard Worker     bool hasFoveatedRendering() const override { return false; }
getFoveationState()143*8975f5c5SAndroid Build Coastguard Worker     const gl::FoveationState *getFoveationState() const override { return nullptr; }
144*8975f5c5SAndroid Build Coastguard Worker 
145*8975f5c5SAndroid Build Coastguard Worker     // For lock surface buffer
146*8975f5c5SAndroid Build Coastguard Worker     EGLint getBitmapPitch() const;
147*8975f5c5SAndroid Build Coastguard Worker     EGLint getBitmapOrigin() const;
148*8975f5c5SAndroid Build Coastguard Worker     EGLint getRedOffset() const;
149*8975f5c5SAndroid Build Coastguard Worker     EGLint getGreenOffset() const;
150*8975f5c5SAndroid Build Coastguard Worker     EGLint getBlueOffset() const;
151*8975f5c5SAndroid Build Coastguard Worker     EGLint getAlphaOffset() const;
152*8975f5c5SAndroid Build Coastguard Worker     EGLint getLuminanceOffset() const;
153*8975f5c5SAndroid Build Coastguard Worker     EGLint getBitmapPixelSize() const;
154*8975f5c5SAndroid Build Coastguard Worker     EGLAttribKHR getBitmapPointer() const;
155*8975f5c5SAndroid Build Coastguard Worker     egl::Error lockSurfaceKHR(const egl::Display *display, const AttributeMap &attributes);
156*8975f5c5SAndroid Build Coastguard Worker     egl::Error unlockSurfaceKHR(const egl::Display *display);
157*8975f5c5SAndroid Build Coastguard Worker 
158*8975f5c5SAndroid Build Coastguard Worker     bool isLocked() const;
isCurrentOnAnyContext()159*8975f5c5SAndroid Build Coastguard Worker     bool isCurrentOnAnyContext() const { return mIsCurrentOnAnyContext; }
160*8975f5c5SAndroid Build Coastguard Worker 
getBoundTexture()161*8975f5c5SAndroid Build Coastguard Worker     gl::Texture *getBoundTexture() const { return mTexture; }
162*8975f5c5SAndroid Build Coastguard Worker 
163*8975f5c5SAndroid Build Coastguard Worker     EGLint isFixedSize() const;
164*8975f5c5SAndroid Build Coastguard Worker 
165*8975f5c5SAndroid Build Coastguard Worker     // FramebufferAttachmentObject implementation
166*8975f5c5SAndroid Build Coastguard Worker     gl::Extents getAttachmentSize(const gl::ImageIndex &imageIndex) const override;
167*8975f5c5SAndroid Build Coastguard Worker     gl::Format getAttachmentFormat(GLenum binding, const gl::ImageIndex &imageIndex) const override;
168*8975f5c5SAndroid Build Coastguard Worker     GLsizei getAttachmentSamples(const gl::ImageIndex &imageIndex) const override;
169*8975f5c5SAndroid Build Coastguard Worker     bool isRenderable(const gl::Context *context,
170*8975f5c5SAndroid Build Coastguard Worker                       GLenum binding,
171*8975f5c5SAndroid Build Coastguard Worker                       const gl::ImageIndex &imageIndex) const override;
172*8975f5c5SAndroid Build Coastguard Worker     bool isYUV() const override;
173*8975f5c5SAndroid Build Coastguard Worker     bool isExternalImageWithoutIndividualSync() const override;
174*8975f5c5SAndroid Build Coastguard Worker     bool hasFrontBufferUsage() const override;
175*8975f5c5SAndroid Build Coastguard Worker 
onAttach(const gl::Context * context,rx::UniqueSerial framebufferSerial)176*8975f5c5SAndroid Build Coastguard Worker     void onAttach(const gl::Context *context, rx::UniqueSerial framebufferSerial) override {}
onDetach(const gl::Context * context,rx::UniqueSerial framebufferSerial)177*8975f5c5SAndroid Build Coastguard Worker     void onDetach(const gl::Context *context, rx::UniqueSerial framebufferSerial) override {}
id()178*8975f5c5SAndroid Build Coastguard Worker     SurfaceID id() const { return mState.id; }
179*8975f5c5SAndroid Build Coastguard Worker     GLuint getId() const override;
180*8975f5c5SAndroid Build Coastguard Worker 
getOrientation()181*8975f5c5SAndroid Build Coastguard Worker     EGLint getOrientation() const { return mOrientation; }
182*8975f5c5SAndroid Build Coastguard Worker 
directComposition()183*8975f5c5SAndroid Build Coastguard Worker     bool directComposition() const { return mState.directComposition; }
184*8975f5c5SAndroid Build Coastguard Worker 
185*8975f5c5SAndroid Build Coastguard Worker     gl::InitState initState(GLenum binding, const gl::ImageIndex &imageIndex) const override;
186*8975f5c5SAndroid Build Coastguard Worker     void setInitState(GLenum binding,
187*8975f5c5SAndroid Build Coastguard Worker                       const gl::ImageIndex &imageIndex,
188*8975f5c5SAndroid Build Coastguard Worker                       gl::InitState initState) override;
189*8975f5c5SAndroid Build Coastguard Worker 
isRobustResourceInitEnabled()190*8975f5c5SAndroid Build Coastguard Worker     bool isRobustResourceInitEnabled() const { return mRobustResourceInitialization; }
191*8975f5c5SAndroid Build Coastguard Worker 
getBindTexImageFormat()192*8975f5c5SAndroid Build Coastguard Worker     const gl::Format &getBindTexImageFormat() const { return mColorFormat; }
193*8975f5c5SAndroid Build Coastguard Worker 
194*8975f5c5SAndroid Build Coastguard Worker     // EGL_ANDROID_get_frame_timestamps entry points
195*8975f5c5SAndroid Build Coastguard Worker     void setTimestampsEnabled(bool enabled);
196*8975f5c5SAndroid Build Coastguard Worker     bool isTimestampsEnabled() const;
197*8975f5c5SAndroid Build Coastguard Worker 
198*8975f5c5SAndroid Build Coastguard Worker     // EGL_ANDROID_front_buffer_auto_refresh entry points
199*8975f5c5SAndroid Build Coastguard Worker     Error setAutoRefreshEnabled(bool enabled);
200*8975f5c5SAndroid Build Coastguard Worker 
201*8975f5c5SAndroid Build Coastguard Worker     const SupportedCompositorTiming &getSupportedCompositorTimings() const;
202*8975f5c5SAndroid Build Coastguard Worker     Error getCompositorTiming(EGLint numTimestamps,
203*8975f5c5SAndroid Build Coastguard Worker                               const EGLint *names,
204*8975f5c5SAndroid Build Coastguard Worker                               EGLnsecsANDROID *values) const;
205*8975f5c5SAndroid Build Coastguard Worker 
206*8975f5c5SAndroid Build Coastguard Worker     Error getNextFrameId(EGLuint64KHR *frameId) const;
207*8975f5c5SAndroid Build Coastguard Worker     const SupportedTimestamps &getSupportedTimestamps() const;
208*8975f5c5SAndroid Build Coastguard Worker     Error getFrameTimestamps(EGLuint64KHR frameId,
209*8975f5c5SAndroid Build Coastguard Worker                              EGLint numTimestamps,
210*8975f5c5SAndroid Build Coastguard Worker                              const EGLint *timestamps,
211*8975f5c5SAndroid Build Coastguard Worker                              EGLnsecsANDROID *values) const;
212*8975f5c5SAndroid Build Coastguard Worker 
213*8975f5c5SAndroid Build Coastguard Worker     // Returns the offset into the texture backing the surface if specified via texture offset
214*8975f5c5SAndroid Build Coastguard Worker     // attributes (see EGL_ANGLE_d3d_texture_client_buffer extension). Returns zero offset
215*8975f5c5SAndroid Build Coastguard Worker     // otherwise.
getTextureOffset()216*8975f5c5SAndroid Build Coastguard Worker     const gl::Offset &getTextureOffset() const { return mTextureOffset; }
217*8975f5c5SAndroid Build Coastguard Worker 
218*8975f5c5SAndroid Build Coastguard Worker     Error getBufferAge(const gl::Context *context, EGLint *age);
219*8975f5c5SAndroid Build Coastguard Worker 
220*8975f5c5SAndroid Build Coastguard Worker     Error setRenderBuffer(EGLint renderBuffer);
221*8975f5c5SAndroid Build Coastguard Worker 
bufferAgeQueriedSinceLastSwap()222*8975f5c5SAndroid Build Coastguard Worker     bool bufferAgeQueriedSinceLastSwap() const { return mBufferAgeQueriedSinceLastSwap; }
223*8975f5c5SAndroid Build Coastguard Worker     void setDamageRegion(const EGLint *rects, EGLint n_rects);
isDamageRegionSet()224*8975f5c5SAndroid Build Coastguard Worker     bool isDamageRegionSet() const { return mIsDamageRegionSet; }
225*8975f5c5SAndroid Build Coastguard Worker 
addRef()226*8975f5c5SAndroid Build Coastguard Worker     void addRef() { mRefCount++; }
release()227*8975f5c5SAndroid Build Coastguard Worker     void release()
228*8975f5c5SAndroid Build Coastguard Worker     {
229*8975f5c5SAndroid Build Coastguard Worker         ASSERT(mRefCount > 0);
230*8975f5c5SAndroid Build Coastguard Worker         mRefCount--;
231*8975f5c5SAndroid Build Coastguard Worker     }
isReferenced()232*8975f5c5SAndroid Build Coastguard Worker     bool isReferenced() const { return mRefCount > 0; }
233*8975f5c5SAndroid Build Coastguard Worker 
234*8975f5c5SAndroid Build Coastguard Worker   protected:
235*8975f5c5SAndroid Build Coastguard Worker     Surface(EGLint surfaceType,
236*8975f5c5SAndroid Build Coastguard Worker             SurfaceID id,
237*8975f5c5SAndroid Build Coastguard Worker             const egl::Config *config,
238*8975f5c5SAndroid Build Coastguard Worker             const AttributeMap &attributes,
239*8975f5c5SAndroid Build Coastguard Worker             bool forceRobustResourceInit,
240*8975f5c5SAndroid Build Coastguard Worker             EGLenum buftype = EGL_NONE);
241*8975f5c5SAndroid Build Coastguard Worker     ~Surface() override;
242*8975f5c5SAndroid Build Coastguard Worker     rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override;
243*8975f5c5SAndroid Build Coastguard Worker 
244*8975f5c5SAndroid Build Coastguard Worker     // ANGLE-only method, used internally
245*8975f5c5SAndroid Build Coastguard Worker     friend class gl::Texture;
246*8975f5c5SAndroid Build Coastguard Worker     Error releaseTexImageFromTexture(const gl::Context *context);
247*8975f5c5SAndroid Build Coastguard Worker 
248*8975f5c5SAndroid Build Coastguard Worker     SurfaceState mState;
249*8975f5c5SAndroid Build Coastguard Worker     rx::SurfaceImpl *mImplementation;
250*8975f5c5SAndroid Build Coastguard Worker     int mRefCount;
251*8975f5c5SAndroid Build Coastguard Worker     bool mDestroyed;
252*8975f5c5SAndroid Build Coastguard Worker 
253*8975f5c5SAndroid Build Coastguard Worker     EGLint mType;
254*8975f5c5SAndroid Build Coastguard Worker     EGLenum mBuftype;
255*8975f5c5SAndroid Build Coastguard Worker 
256*8975f5c5SAndroid Build Coastguard Worker     bool mPostSubBufferRequested;
257*8975f5c5SAndroid Build Coastguard Worker 
258*8975f5c5SAndroid Build Coastguard Worker     bool mLargestPbuffer;
259*8975f5c5SAndroid Build Coastguard Worker     EGLenum mGLColorspace;
260*8975f5c5SAndroid Build Coastguard Worker     EGLenum mVGAlphaFormat;
261*8975f5c5SAndroid Build Coastguard Worker     EGLenum mVGColorspace;
262*8975f5c5SAndroid Build Coastguard Worker     bool mMipmapTexture;
263*8975f5c5SAndroid Build Coastguard Worker     EGLint mMipmapLevel;
264*8975f5c5SAndroid Build Coastguard Worker     EGLint mHorizontalResolution;
265*8975f5c5SAndroid Build Coastguard Worker     EGLint mVerticalResolution;
266*8975f5c5SAndroid Build Coastguard Worker     EGLenum mMultisampleResolve;
267*8975f5c5SAndroid Build Coastguard Worker 
268*8975f5c5SAndroid Build Coastguard Worker     bool mFixedSize;
269*8975f5c5SAndroid Build Coastguard Worker     size_t mFixedWidth;
270*8975f5c5SAndroid Build Coastguard Worker     size_t mFixedHeight;
271*8975f5c5SAndroid Build Coastguard Worker 
272*8975f5c5SAndroid Build Coastguard Worker     bool mRobustResourceInitialization;
273*8975f5c5SAndroid Build Coastguard Worker 
274*8975f5c5SAndroid Build Coastguard Worker     TextureFormat mTextureFormat;
275*8975f5c5SAndroid Build Coastguard Worker     EGLenum mTextureTarget;
276*8975f5c5SAndroid Build Coastguard Worker 
277*8975f5c5SAndroid Build Coastguard Worker     EGLint mPixelAspectRatio;  // Display aspect ratio
278*8975f5c5SAndroid Build Coastguard Worker     EGLenum mRenderBuffer;     // Render buffer
279*8975f5c5SAndroid Build Coastguard Worker 
280*8975f5c5SAndroid Build Coastguard Worker     EGLint mOrientation;
281*8975f5c5SAndroid Build Coastguard Worker 
282*8975f5c5SAndroid Build Coastguard Worker     // We don't use a binding pointer here. We don't ever want to own an orphaned texture. If a
283*8975f5c5SAndroid Build Coastguard Worker     // Texture is deleted the Surface is unbound in onDestroy.
284*8975f5c5SAndroid Build Coastguard Worker     gl::Texture *mTexture;
285*8975f5c5SAndroid Build Coastguard Worker 
286*8975f5c5SAndroid Build Coastguard Worker     gl::Format mColorFormat;
287*8975f5c5SAndroid Build Coastguard Worker     gl::Format mDSFormat;
288*8975f5c5SAndroid Build Coastguard Worker 
289*8975f5c5SAndroid Build Coastguard Worker     gl::Offset mTextureOffset;
290*8975f5c5SAndroid Build Coastguard Worker 
291*8975f5c5SAndroid Build Coastguard Worker     bool mIsCurrentOnAnyContext;  // The surface is current to a context/client API
292*8975f5c5SAndroid Build Coastguard Worker     uint8_t *mLockBufferPtr;      // Memory owned by backend.
293*8975f5c5SAndroid Build Coastguard Worker     EGLint mLockBufferPitch;
294*8975f5c5SAndroid Build Coastguard Worker 
295*8975f5c5SAndroid Build Coastguard Worker     bool mBufferAgeQueriedSinceLastSwap;
296*8975f5c5SAndroid Build Coastguard Worker     bool mIsDamageRegionSet;
297*8975f5c5SAndroid Build Coastguard Worker 
298*8975f5c5SAndroid Build Coastguard Worker   private:
299*8975f5c5SAndroid Build Coastguard Worker     Error getBufferAgeImpl(const gl::Context *context, EGLint *age) const;
300*8975f5c5SAndroid Build Coastguard Worker 
301*8975f5c5SAndroid Build Coastguard Worker     Error destroyImpl(const Display *display);
302*8975f5c5SAndroid Build Coastguard Worker 
303*8975f5c5SAndroid Build Coastguard Worker     void postSwap(const gl::Context *context);
304*8975f5c5SAndroid Build Coastguard Worker     Error releaseRef(const Display *display);
305*8975f5c5SAndroid Build Coastguard Worker 
306*8975f5c5SAndroid Build Coastguard Worker     // ObserverInterface implementation.
307*8975f5c5SAndroid Build Coastguard Worker     void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
308*8975f5c5SAndroid Build Coastguard Worker 
309*8975f5c5SAndroid Build Coastguard Worker     gl::InitState mColorInitState;
310*8975f5c5SAndroid Build Coastguard Worker     gl::InitState mDepthStencilInitState;
311*8975f5c5SAndroid Build Coastguard Worker     angle::ObserverBinding mImplObserverBinding;
312*8975f5c5SAndroid Build Coastguard Worker };
313*8975f5c5SAndroid Build Coastguard Worker 
314*8975f5c5SAndroid Build Coastguard Worker class WindowSurface final : public Surface
315*8975f5c5SAndroid Build Coastguard Worker {
316*8975f5c5SAndroid Build Coastguard Worker   public:
317*8975f5c5SAndroid Build Coastguard Worker     WindowSurface(rx::EGLImplFactory *implFactory,
318*8975f5c5SAndroid Build Coastguard Worker                   SurfaceID id,
319*8975f5c5SAndroid Build Coastguard Worker                   const Config *config,
320*8975f5c5SAndroid Build Coastguard Worker                   EGLNativeWindowType window,
321*8975f5c5SAndroid Build Coastguard Worker                   const AttributeMap &attribs,
322*8975f5c5SAndroid Build Coastguard Worker                   bool robustResourceInit);
323*8975f5c5SAndroid Build Coastguard Worker     ~WindowSurface() override;
324*8975f5c5SAndroid Build Coastguard Worker };
325*8975f5c5SAndroid Build Coastguard Worker 
326*8975f5c5SAndroid Build Coastguard Worker class PbufferSurface final : public Surface
327*8975f5c5SAndroid Build Coastguard Worker {
328*8975f5c5SAndroid Build Coastguard Worker   public:
329*8975f5c5SAndroid Build Coastguard Worker     PbufferSurface(rx::EGLImplFactory *implFactory,
330*8975f5c5SAndroid Build Coastguard Worker                    SurfaceID id,
331*8975f5c5SAndroid Build Coastguard Worker                    const Config *config,
332*8975f5c5SAndroid Build Coastguard Worker                    const AttributeMap &attribs,
333*8975f5c5SAndroid Build Coastguard Worker                    bool robustResourceInit);
334*8975f5c5SAndroid Build Coastguard Worker     PbufferSurface(rx::EGLImplFactory *implFactory,
335*8975f5c5SAndroid Build Coastguard Worker                    SurfaceID id,
336*8975f5c5SAndroid Build Coastguard Worker                    const Config *config,
337*8975f5c5SAndroid Build Coastguard Worker                    EGLenum buftype,
338*8975f5c5SAndroid Build Coastguard Worker                    EGLClientBuffer clientBuffer,
339*8975f5c5SAndroid Build Coastguard Worker                    const AttributeMap &attribs,
340*8975f5c5SAndroid Build Coastguard Worker                    bool robustResourceInit);
341*8975f5c5SAndroid Build Coastguard Worker 
342*8975f5c5SAndroid Build Coastguard Worker   protected:
343*8975f5c5SAndroid Build Coastguard Worker     ~PbufferSurface() override;
344*8975f5c5SAndroid Build Coastguard Worker };
345*8975f5c5SAndroid Build Coastguard Worker 
346*8975f5c5SAndroid Build Coastguard Worker class PixmapSurface final : public Surface
347*8975f5c5SAndroid Build Coastguard Worker {
348*8975f5c5SAndroid Build Coastguard Worker   public:
349*8975f5c5SAndroid Build Coastguard Worker     PixmapSurface(rx::EGLImplFactory *implFactory,
350*8975f5c5SAndroid Build Coastguard Worker                   SurfaceID id,
351*8975f5c5SAndroid Build Coastguard Worker                   const Config *config,
352*8975f5c5SAndroid Build Coastguard Worker                   NativePixmapType nativePixmap,
353*8975f5c5SAndroid Build Coastguard Worker                   const AttributeMap &attribs,
354*8975f5c5SAndroid Build Coastguard Worker                   bool robustResourceInit);
355*8975f5c5SAndroid Build Coastguard Worker 
356*8975f5c5SAndroid Build Coastguard Worker   protected:
357*8975f5c5SAndroid Build Coastguard Worker     ~PixmapSurface() override;
358*8975f5c5SAndroid Build Coastguard Worker };
359*8975f5c5SAndroid Build Coastguard Worker 
360*8975f5c5SAndroid Build Coastguard Worker class [[nodiscard]] ScopedSurfaceRef
361*8975f5c5SAndroid Build Coastguard Worker {
362*8975f5c5SAndroid Build Coastguard Worker   public:
ScopedSurfaceRef(Surface * surface)363*8975f5c5SAndroid Build Coastguard Worker     ScopedSurfaceRef(Surface *surface) : mSurface(surface)
364*8975f5c5SAndroid Build Coastguard Worker     {
365*8975f5c5SAndroid Build Coastguard Worker         if (mSurface)
366*8975f5c5SAndroid Build Coastguard Worker         {
367*8975f5c5SAndroid Build Coastguard Worker             mSurface->addRef();
368*8975f5c5SAndroid Build Coastguard Worker         }
369*8975f5c5SAndroid Build Coastguard Worker     }
~ScopedSurfaceRef()370*8975f5c5SAndroid Build Coastguard Worker     ~ScopedSurfaceRef()
371*8975f5c5SAndroid Build Coastguard Worker     {
372*8975f5c5SAndroid Build Coastguard Worker         if (mSurface)
373*8975f5c5SAndroid Build Coastguard Worker         {
374*8975f5c5SAndroid Build Coastguard Worker             mSurface->release();
375*8975f5c5SAndroid Build Coastguard Worker         }
376*8975f5c5SAndroid Build Coastguard Worker     }
377*8975f5c5SAndroid Build Coastguard Worker 
378*8975f5c5SAndroid Build Coastguard Worker   private:
379*8975f5c5SAndroid Build Coastguard Worker     Surface *const mSurface;
380*8975f5c5SAndroid Build Coastguard Worker };
381*8975f5c5SAndroid Build Coastguard Worker 
382*8975f5c5SAndroid Build Coastguard Worker class SurfaceDeleter final
383*8975f5c5SAndroid Build Coastguard Worker {
384*8975f5c5SAndroid Build Coastguard Worker   public:
385*8975f5c5SAndroid Build Coastguard Worker     SurfaceDeleter(const Display *display);
386*8975f5c5SAndroid Build Coastguard Worker     ~SurfaceDeleter();
387*8975f5c5SAndroid Build Coastguard Worker     void operator()(Surface *surface);
388*8975f5c5SAndroid Build Coastguard Worker 
389*8975f5c5SAndroid Build Coastguard Worker   private:
390*8975f5c5SAndroid Build Coastguard Worker     const Display *mDisplay;
391*8975f5c5SAndroid Build Coastguard Worker };
392*8975f5c5SAndroid Build Coastguard Worker 
393*8975f5c5SAndroid Build Coastguard Worker using SurfacePointer = std::unique_ptr<Surface, SurfaceDeleter>;
394*8975f5c5SAndroid Build Coastguard Worker 
395*8975f5c5SAndroid Build Coastguard Worker }  // namespace egl
396*8975f5c5SAndroid Build Coastguard Worker 
397*8975f5c5SAndroid Build Coastguard Worker #endif  // LIBANGLE_SURFACE_H_
398