xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/gl/egl/DisplayEGL.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2016 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 // DisplayEGL.h: Common across EGL parts of platform specific egl::Display implementations
8 
9 #ifndef LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_
10 #define LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 #include "libANGLE/renderer/gl/DisplayGL.h"
17 #include "libANGLE/renderer/gl/egl/egl_utils.h"
18 
19 namespace rx
20 {
21 
22 class FunctionsEGL;
23 class FunctionsEGLDL;
24 class RendererEGL;
25 
26 class DisplayEGL : public DisplayGL
27 {
28   public:
29     DisplayEGL(const egl::DisplayState &state);
30     ~DisplayEGL() override;
31 
32     ImageImpl *createImage(const egl::ImageState &state,
33                            const gl::Context *context,
34                            EGLenum target,
35                            const egl::AttributeMap &attribs) override;
36 
37     EGLSyncImpl *createSync() override;
38 
39     void setBlobCacheFuncs(EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get) override;
40 
41     virtual void destroyNativeContext(EGLContext context);
42 
43     egl::Error initialize(egl::Display *display) override;
44     void terminate() override;
45 
46     SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
47                                      EGLNativeWindowType window,
48                                      const egl::AttributeMap &attribs) override;
49     SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
50                                       const egl::AttributeMap &attribs) override;
51     SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state,
52                                                EGLenum buftype,
53                                                EGLClientBuffer clientBuffer,
54                                                const egl::AttributeMap &attribs) override;
55     SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state,
56                                      NativePixmapType nativePixmap,
57                                      const egl::AttributeMap &attribs) override;
58 
59     ContextImpl *createContext(const gl::State &state,
60                                gl::ErrorSet *errorSet,
61                                const egl::Config *configuration,
62                                const gl::Context *shareContext,
63                                const egl::AttributeMap &attribs) override;
64 
65     egl::ConfigSet generateConfigs() override;
66 
67     bool testDeviceLost() override;
68     egl::Error restoreLostDevice(const egl::Display *display) override;
69 
70     bool isValidNativeWindow(EGLNativeWindowType window) const override;
71     egl::Error validateClientBuffer(const egl::Config *configuration,
72                                     EGLenum buftype,
73                                     EGLClientBuffer clientBuffer,
74                                     const egl::AttributeMap &attribs) const override;
75 
76     egl::Error waitClient(const gl::Context *context) override;
77     egl::Error waitNative(const gl::Context *context, EGLint engine) override;
78 
79     egl::Error makeCurrent(egl::Display *display,
80                            egl::Surface *drawSurface,
81                            egl::Surface *readSurface,
82                            gl::Context *context) override;
83 
84     gl::Version getMaxSupportedESVersion() const override;
85 
86     void initializeFrontendFeatures(angle::FrontendFeatures *features) const override;
87 
88     void populateFeatureList(angle::FeatureList *features) override;
89 
90     RendererGL *getRenderer() const override;
91 
92     egl::Error validateImageClientBuffer(const gl::Context *context,
93                                          EGLenum target,
94                                          EGLClientBuffer clientBuffer,
95                                          const egl::AttributeMap &attribs) const override;
96 
97     ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context,
98                                                          EGLenum target,
99                                                          EGLClientBuffer buffer,
100                                                          const egl::AttributeMap &attribs) override;
101 
102     const FunctionsEGL *getFunctionsEGL() const;
103 
104     DeviceImpl *createDevice() override;
105 
106     bool supportsDmaBufFormat(EGLint format) const override;
107     egl::Error queryDmaBufFormats(EGLint maxFormats, EGLint *formats, EGLint *numFormats) override;
108     egl::Error queryDmaBufModifiers(EGLint format,
109                                     EGLint maxModifiers,
110                                     EGLuint64KHR *modifiers,
111                                     EGLBoolean *externalOnly,
112                                     EGLint *numModifiers) override;
113 
114   protected:
115     virtual EGLint fixSurfaceType(EGLint surfaceType) const;
116 
117   private:
118     const char *getEGLPath() const;
119 
120     egl::Error initializeContext(EGLContext shareContext,
121                                  const egl::AttributeMap &eglAttributes,
122                                  EGLContext *outContext) const;
123 
124     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
125 
126     egl::Error createRenderer(EGLContext shareContext,
127                               bool makeNewContextCurrent,
128                               bool isExternalContext,
129                               std::shared_ptr<RendererEGL> *outRenderer);
130 
131     egl::Error makeCurrentSurfaceless(gl::Context *context) override;
132 
133     template <typename T>
134     void getConfigAttrib(EGLConfig config, EGLint attribute, T *value) const;
135 
136     template <typename T, typename U>
137     void getConfigAttribIfExtension(EGLConfig config,
138                                     EGLint attribute,
139                                     T *value,
140                                     const char *extension,
141                                     const U &defaultValue) const;
142 
143     egl::Error findConfig(egl::Display *display,
144                           bool forMockPbuffer,
145                           EGLConfig *outConfig,
146                           std::vector<EGLint> *outConfigAttribs);
147 
148     std::shared_ptr<RendererEGL> mRenderer;
149     std::map<EGLAttrib, std::weak_ptr<RendererEGL>> mVirtualizationGroups;
150 
151     FunctionsEGLDL *mEGL = nullptr;
152     EGLConfig mConfig    = EGL_NO_CONFIG_KHR;
153     egl::AttributeMap mDisplayAttributes;
154     std::vector<EGLint> mConfigAttribList;
155 
156     struct CurrentNativeContext
157     {
158         EGLSurface surface = EGL_NO_SURFACE;
159         EGLContext context = EGL_NO_CONTEXT;
160         // True if the current context is an external context. and both surface and context will be
161         // unset when an external context is current.
162         bool isExternalContext = false;
163     };
164     angle::HashMap<uint64_t, CurrentNativeContext> mCurrentNativeContexts;
165 
166     void generateCaps(egl::Caps *outCaps) const override;
167 
168     std::map<EGLint, EGLint> mConfigIds;
169 
170     bool mHasEXTCreateContextRobustness   = false;
171     bool mHasNVRobustnessVideoMemoryPurge = false;
172 
173     bool mSupportsSurfaceless      = false;
174     bool mSupportsNoConfigContexts = false;
175 
176     EGLSurface mMockPbuffer = EGL_NO_SURFACE;
177 
178     // Supported DRM formats
179     bool mSupportsDmaBufImportModifiers = false;
180     bool mNoOpDmaBufImportModifiers     = false;
181     std::vector<EGLint> mDrmFormats;
182     bool mDrmFormatsInitialized = false;
183 };
184 
185 }  // namespace rx
186 
187 #endif  // LIBANGLE_RENDERER_GL_EGL_DISPLAYEGL_H_
188