xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/SurfaceImpl.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2014 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 // SurfaceImpl.h: Implementation methods of egl::Surface
8 
9 #ifndef LIBANGLE_RENDERER_SURFACEIMPL_H_
10 #define LIBANGLE_RENDERER_SURFACEIMPL_H_
11 
12 #include <EGL/egl.h>
13 #include <EGL/eglext.h>
14 
15 #include "common/angleutils.h"
16 #include "libANGLE/Error.h"
17 #include "libANGLE/FramebufferAttachment.h"
18 #include "libANGLE/renderer/FramebufferAttachmentObjectImpl.h"
19 
20 namespace angle
21 {
22 struct Format;
23 }
24 
25 namespace gl
26 {
27 class Context;
28 class FramebufferState;
29 }  // namespace gl
30 
31 namespace egl
32 {
33 class Display;
34 struct Config;
35 struct SurfaceState;
36 class Thread;
37 
38 using SupportedTimestamps        = angle::PackedEnumBitSet<Timestamp>;
39 using SupportedCompositorTimings = angle::PackedEnumBitSet<CompositorTiming>;
40 }  // namespace egl
41 
42 namespace rx
43 {
44 class SurfaceImpl : public FramebufferAttachmentObjectImpl
45 {
46   public:
47     SurfaceImpl(const egl::SurfaceState &surfaceState);
48     ~SurfaceImpl() override;
destroy(const egl::Display * display)49     virtual void destroy(const egl::Display *display) {}
50 
51     virtual egl::Error initialize(const egl::Display *display) = 0;
52     virtual egl::Error makeCurrent(const gl::Context *context);
53     virtual egl::Error unMakeCurrent(const gl::Context *context);
54     virtual egl::Error prepareSwap(const gl::Context *);
55     virtual egl::Error swap(const gl::Context *context) = 0;
56     virtual egl::Error swapWithDamage(const gl::Context *context,
57                                       const EGLint *rects,
58                                       EGLint n_rects);
59     virtual egl::Error swapWithFrameToken(const gl::Context *context,
60                                           EGLFrameTokenANGLE frameToken);
61     virtual egl::Error postSubBuffer(const gl::Context *context,
62                                      EGLint x,
63                                      EGLint y,
64                                      EGLint width,
65                                      EGLint height);
66     virtual egl::Error setPresentationTime(EGLnsecsANDROID time);
67     virtual egl::Error querySurfacePointerANGLE(EGLint attribute, void **value);
68     virtual egl::Error bindTexImage(const gl::Context *context,
69                                     gl::Texture *texture,
70                                     EGLint buffer)                                = 0;
71     virtual egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) = 0;
72     virtual egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc);
73     virtual egl::Error getMscRate(EGLint *numerator, EGLint *denominator);
74     virtual void setSwapInterval(const egl::Display *display, EGLint interval) = 0;
75     virtual void setFixedWidth(EGLint width);
76     virtual void setFixedHeight(EGLint height);
77 
78     // width and height can change with client window resizing
79     virtual EGLint getWidth() const  = 0;
80     virtual EGLint getHeight() const = 0;
81     // Note: windows cannot be resized on Android.  The approach requires
82     // calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR.  However, that is
83     // expensive; and there are troublesome timing issues for other parts of
84     // ANGLE (which cause test failures and crashes).  Therefore, a
85     // special-Android-only path is created just for the querying of EGL_WIDTH
86     // and EGL_HEIGHT.
87     // https://issuetracker.google.com/issues/153329980
88     virtual egl::Error getUserWidth(const egl::Display *display, EGLint *value) const;
89     virtual egl::Error getUserHeight(const egl::Display *display, EGLint *value) const;
90 
91     virtual EGLint isPostSubBufferSupported() const;
92     virtual EGLint getSwapBehavior() const = 0;
93 
94     virtual egl::Error attachToFramebuffer(const gl::Context *context,
95                                            gl::Framebuffer *framebuffer)   = 0;
96     virtual egl::Error detachFromFramebuffer(const gl::Context *context,
97                                              gl::Framebuffer *framebuffer) = 0;
98 
99     // Used to query color format from pbuffers created from D3D textures.
100     virtual const angle::Format *getD3DTextureColorFormat() const;
101 
102     // EGL_ANDROID_get_frame_timestamps
103     virtual void setTimestampsEnabled(bool enabled);
104     virtual egl::SupportedCompositorTimings getSupportedCompositorTimings() const;
105     virtual egl::Error getCompositorTiming(EGLint numTimestamps,
106                                            const EGLint *names,
107                                            EGLnsecsANDROID *values) const;
108     virtual egl::Error getNextFrameId(EGLuint64KHR *frameId) const;
109     virtual egl::SupportedTimestamps getSupportedTimestamps() const;
110     virtual egl::Error getFrameTimestamps(EGLuint64KHR frameId,
111                                           EGLint numTimestamps,
112                                           const EGLint *timestamps,
113                                           EGLnsecsANDROID *values) const;
114     virtual egl::Error getBufferAge(const gl::Context *context, EGLint *age);
115 
116     // EGL_ANDROID_front_buffer_auto_refresh
117     virtual egl::Error setAutoRefreshEnabled(bool enabled);
118 
119     // EGL_KHR_lock_surface3
120     virtual egl::Error lockSurface(const egl::Display *display,
121                                    EGLint usageHint,
122                                    bool preservePixels,
123                                    uint8_t **bufferPtrOut,
124                                    EGLint *bufferPitchOut);
125     virtual egl::Error unlockSurface(const egl::Display *display, bool preservePixels);
126     virtual EGLint origin() const;
127 
128     virtual egl::Error setRenderBuffer(EGLint renderBuffer);
129 
130   protected:
131     const egl::SurfaceState &mState;
132 };
133 
134 }  // namespace rx
135 
136 #endif  // LIBANGLE_RENDERER_SURFACEIMPL_H_
137