• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // Surface.h: Defines the egl::Surface class, representing a drawing surface
8 // such as the client area of a window, including any back buffers.
9 // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3.
10 
11 #ifndef LIBANGLE_SURFACE_H_
12 #define LIBANGLE_SURFACE_H_
13 
14 #include <EGL/egl.h>
15 
16 #include "common/PackedEnums.h"
17 #include "common/angleutils.h"
18 #include "libANGLE/AttributeMap.h"
19 #include "libANGLE/Debug.h"
20 #include "libANGLE/Error.h"
21 #include "libANGLE/FramebufferAttachment.h"
22 #include "libANGLE/RefCountObject.h"
23 #include "libANGLE/formatutils.h"
24 #include "libANGLE/renderer/SurfaceImpl.h"
25 
26 namespace gl
27 {
28 class Context;
29 class Framebuffer;
30 class Texture;
31 }  // namespace gl
32 
33 namespace rx
34 {
35 class EGLImplFactory;
36 }
37 
38 namespace egl
39 {
40 class Display;
41 struct Config;
42 
43 using SupportedCompositorTiming = angle::PackedEnumBitSet<CompositorTiming>;
44 using SupportedTimestamps       = angle::PackedEnumBitSet<Timestamp>;
45 
46 struct SurfaceState final : private angle::NonCopyable
47 {
48     SurfaceState(const egl::Config *configIn, const AttributeMap &attributesIn);
49     ~SurfaceState();
50 
51     EGLLabelKHR label;
52     const egl::Config *config;
53     AttributeMap attributes;
54 
55     bool timestampsEnabled;
56     SupportedCompositorTiming supportedCompositorTimings;
57     SupportedTimestamps supportedTimestamps;
58     bool directComposition;
59 };
60 
61 class Surface : public LabeledObject, public gl::FramebufferAttachmentObject
62 {
63   public:
getImplementation()64     rx::SurfaceImpl *getImplementation() const { return mImplementation; }
65 
66     void setLabel(EGLLabelKHR label) override;
67     EGLLabelKHR getLabel() const override;
68 
69     EGLint getType() const;
70 
71     Error initialize(const Display *display);
72     Error makeCurrent(const gl::Context *context);
73     Error unMakeCurrent(const gl::Context *context);
74     Error swap(const gl::Context *context);
75     Error swapWithDamage(const gl::Context *context, EGLint *rects, EGLint n_rects);
76     Error swapWithFrameToken(const gl::Context *context, EGLFrameTokenANGLE frameToken);
77     Error postSubBuffer(const gl::Context *context,
78                         EGLint x,
79                         EGLint y,
80                         EGLint width,
81                         EGLint height);
82     Error setPresentationTime(EGLnsecsANDROID time);
83     Error querySurfacePointerANGLE(EGLint attribute, void **value);
84     Error bindTexImage(gl::Context *context, gl::Texture *texture, EGLint buffer);
85     Error releaseTexImage(const gl::Context *context, EGLint buffer);
86 
87     Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc);
88     Error getMscRate(EGLint *numerator, EGLint *denominator);
89 
90     EGLint isPostSubBufferSupported() const;
91 
92     void setSwapInterval(EGLint interval);
93     Error onDestroy(const Display *display);
94 
95     void setMipmapLevel(EGLint level);
96     void setMultisampleResolve(EGLenum resolve);
97     void setSwapBehavior(EGLenum behavior);
98 
99     void setFixedWidth(EGLint width);
100     void setFixedHeight(EGLint height);
101 
102     gl::Framebuffer *createDefaultFramebuffer(const gl::Context *context,
103                                               egl::Surface *readSurface);
104 
105     const Config *getConfig() const;
106 
107     // width and height can change with client window resizing
108     EGLint getWidth() const;
109     EGLint getHeight() const;
110     EGLint getPixelAspectRatio() const;
111     EGLenum getRenderBuffer() const;
112     EGLenum getSwapBehavior() const;
113     TextureFormat getTextureFormat() const;
114     EGLenum getTextureTarget() const;
115     bool getLargestPbuffer() const;
116     EGLenum getGLColorspace() const;
117     EGLenum getVGAlphaFormat() const;
118     EGLenum getVGColorspace() const;
119     bool getMipmapTexture() const;
120     EGLint getMipmapLevel() const;
121     EGLint getHorizontalResolution() const;
122     EGLint getVerticalResolution() const;
123     EGLenum getMultisampleResolve() const;
124 
getBoundTexture()125     gl::Texture *getBoundTexture() const { return mTexture; }
126 
127     EGLint isFixedSize() const;
128 
129     // FramebufferAttachmentObject implementation
130     gl::Extents getAttachmentSize(const gl::ImageIndex &imageIndex) const override;
131     gl::Format getAttachmentFormat(GLenum binding, const gl::ImageIndex &imageIndex) const override;
132     GLsizei getAttachmentSamples(const gl::ImageIndex &imageIndex) const override;
133     bool isRenderable(const gl::Context *context,
134                       GLenum binding,
135                       const gl::ImageIndex &imageIndex) const override;
136 
onAttach(const gl::Context * context)137     void onAttach(const gl::Context *context) override {}
onDetach(const gl::Context * context)138     void onDetach(const gl::Context *context) override {}
139     GLuint getId() const override;
140 
flexibleSurfaceCompatibilityRequested()141     bool flexibleSurfaceCompatibilityRequested() const
142     {
143         return mFlexibleSurfaceCompatibilityRequested;
144     }
getOrientation()145     EGLint getOrientation() const { return mOrientation; }
146 
directComposition()147     bool directComposition() const { return mState.directComposition; }
148 
149     gl::InitState initState(const gl::ImageIndex &imageIndex) const override;
150     void setInitState(const gl::ImageIndex &imageIndex, gl::InitState initState) override;
151 
isRobustResourceInitEnabled()152     bool isRobustResourceInitEnabled() const { return mRobustResourceInitialization; }
153 
getBindTexImageFormat()154     const gl::Format &getBindTexImageFormat() const { return mColorFormat; }
155 
156     // EGL_ANDROID_get_frame_timestamps entry points
157     void setTimestampsEnabled(bool enabled);
158     bool isTimestampsEnabled() const;
159 
160     const SupportedCompositorTiming &getSupportedCompositorTimings() const;
161     Error getCompositorTiming(EGLint numTimestamps,
162                               const EGLint *names,
163                               EGLnsecsANDROID *values) const;
164 
165     Error getNextFrameId(EGLuint64KHR *frameId) const;
166     const SupportedTimestamps &getSupportedTimestamps() const;
167     Error getFrameTimestamps(EGLuint64KHR frameId,
168                              EGLint numTimestamps,
169                              const EGLint *timestamps,
170                              EGLnsecsANDROID *values) const;
171 
172   protected:
173     Surface(EGLint surfaceType,
174             const egl::Config *config,
175             const AttributeMap &attributes,
176             EGLenum buftype = EGL_NONE);
177     ~Surface() override;
178     rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override;
179 
180     gl::Framebuffer *createDefaultFramebuffer(const Display *display);
181 
182     // ANGLE-only method, used internally
183     friend class gl::Texture;
184     Error releaseTexImageFromTexture(const gl::Context *context);
185 
186     SurfaceState mState;
187     rx::SurfaceImpl *mImplementation;
188     int mRefCount;
189     bool mDestroyed;
190 
191     EGLint mType;
192     EGLenum mBuftype;
193 
194     bool mPostSubBufferRequested;
195     bool mFlexibleSurfaceCompatibilityRequested;
196 
197     bool mLargestPbuffer;
198     EGLenum mGLColorspace;
199     EGLenum mVGAlphaFormat;
200     EGLenum mVGColorspace;
201     bool mMipmapTexture;
202     EGLint mMipmapLevel;
203     EGLint mHorizontalResolution;
204     EGLint mVerticalResolution;
205     EGLenum mMultisampleResolve;
206 
207     bool mFixedSize;
208     size_t mFixedWidth;
209     size_t mFixedHeight;
210 
211     bool mRobustResourceInitialization;
212 
213     TextureFormat mTextureFormat;
214     EGLenum mTextureTarget;
215 
216     EGLint mPixelAspectRatio;  // Display aspect ratio
217     EGLenum mRenderBuffer;     // Render buffer
218     EGLenum mSwapBehavior;     // Buffer swap behavior
219 
220     EGLint mOrientation;
221 
222     // We don't use a binding pointer here. We don't ever want to own an orphaned texture. If a
223     // Texture is deleted the Surface is unbound in onDestroy.
224     gl::Texture *mTexture;
225 
226     gl::Format mColorFormat;
227     gl::Format mDSFormat;
228 
229   private:
230     Error destroyImpl(const Display *display);
231 
232     void postSwap(const gl::Context *context);
233     Error releaseRef(const Display *display);
234 
235     gl::InitState mInitState;
236 };
237 
238 class WindowSurface final : public Surface
239 {
240   public:
241     WindowSurface(rx::EGLImplFactory *implFactory,
242                   const Config *config,
243                   EGLNativeWindowType window,
244                   const AttributeMap &attribs);
245     ~WindowSurface() override;
246 };
247 
248 class PbufferSurface final : public Surface
249 {
250   public:
251     PbufferSurface(rx::EGLImplFactory *implFactory,
252                    const Config *config,
253                    const AttributeMap &attribs);
254     PbufferSurface(rx::EGLImplFactory *implFactory,
255                    const Config *config,
256                    EGLenum buftype,
257                    EGLClientBuffer clientBuffer,
258                    const AttributeMap &attribs);
259 
260   protected:
261     ~PbufferSurface() override;
262 };
263 
264 class PixmapSurface final : public Surface
265 {
266   public:
267     PixmapSurface(rx::EGLImplFactory *implFactory,
268                   const Config *config,
269                   NativePixmapType nativePixmap,
270                   const AttributeMap &attribs);
271 
272   protected:
273     ~PixmapSurface() override;
274 };
275 
276 class SurfaceDeleter final
277 {
278   public:
279     SurfaceDeleter(const Display *display);
280     ~SurfaceDeleter();
281     void operator()(Surface *surface);
282 
283   private:
284     const Display *mDisplay;
285 };
286 
287 using SurfacePointer = angle::UniqueObjectPointerBase<Surface, SurfaceDeleter>;
288 
289 }  // namespace egl
290 
291 #endif  // LIBANGLE_SURFACE_H_
292