• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef UTIL_EGLWINDOW_H_
8 #define UTIL_EGLWINDOW_H_
9 
10 #include <stdint.h>
11 #include <list>
12 #include <memory>
13 #include <string>
14 
15 #include "common/Optional.h"
16 #include "common/PackedEnums.h"
17 #include "common/angleutils.h"
18 #include "util/EGLPlatformParameters.h"
19 #include "util/util_export.h"
20 #include "util/util_gl.h"
21 
22 class OSWindow;
23 
24 namespace angle
25 {
26 class Library;
27 struct PlatformMethods;
28 using GenericProc = void (*)();
29 }  // namespace angle
30 
31 struct ANGLE_UTIL_EXPORT ConfigParameters
32 {
33     ConfigParameters();
34     ~ConfigParameters();
35 
36     void reset();
37 
38     // Surface and Context parameters.
39     int redBits;
40     int greenBits;
41     int blueBits;
42     int alphaBits;
43     int depthBits;
44     int stencilBits;
45 
46     Optional<bool> webGLCompatibility;
47     Optional<bool> robustResourceInit;
48 
49     // EGLWindow-specific.
50     EGLenum componentType;
51     bool multisample;
52     bool debug;
53     bool noError;
54     Optional<bool> extensionsEnabled;
55     bool bindGeneratesResource;
56     bool clientArraysEnabled;
57     bool robustAccess;
58     bool mutableRenderBuffer;
59     EGLint samples;
60     Optional<bool> contextProgramCacheEnabled;
61     EGLenum resetStrategy;
62     EGLenum colorSpace;
63     EGLint swapInterval;
64 };
65 
66 using GLWindowContext = struct GLWindowHandleContext_T *;
67 
68 enum class GLWindowResult
69 {
70     NoError,
71     NoColorspaceSupport,
72     NoMutableRenderBufferSupport,
73     Error,
74 };
75 
76 class ANGLE_UTIL_EXPORT GLWindowBase : angle::NonCopyable
77 {
78   public:
79     static void Delete(GLWindowBase **window);
80 
81     using Image        = void *;
82     using ClientBuffer = void *;
83     using Enum         = unsigned int;
84     using Attrib       = intptr_t;
85     using AttribKHR    = khronos_int32_t;
86     using Boolean      = unsigned int;
87     using Surface      = void *;
88     using Sync         = void *;
89     using Display      = void *;
90 
91     // It should also be possible to set multisample and floating point framebuffers.
getClientMajorVersion()92     EGLint getClientMajorVersion() const { return mClientMajorVersion; }
getClientMinorVersion()93     EGLint getClientMinorVersion() const { return mClientMinorVersion; }
getClientType()94     EGLenum getClientType() const { return mClientType; }
getProfileMask()95     EGLint getProfileMask() const { return mProfileMask; }
96 
97     virtual bool initializeGL(OSWindow *osWindow,
98                               angle::Library *glWindowingLibrary,
99                               angle::GLESDriverType driverType,
100                               const EGLPlatformParameters &platformParams,
101                               const ConfigParameters &configParams) = 0;
102 
103     virtual GLWindowResult initializeGLWithResult(OSWindow *osWindow,
104                                                   angle::Library *glWindowingLibrary,
105                                                   angle::GLESDriverType driverType,
106                                                   const EGLPlatformParameters &platformParams,
107                                                   const ConfigParameters &configParams) = 0;
108 
109     virtual bool isGLInitialized() const                        = 0;
110     virtual void swap()                                         = 0;
111     virtual void destroyGL()                                    = 0;
112     virtual bool makeCurrent()                                  = 0;
113     virtual bool hasError() const                               = 0;
114     virtual bool setSwapInterval(EGLint swapInterval)           = 0;
115     virtual angle::GenericProc getProcAddress(const char *name) = 0;
116     // EGLContext and HGLRC (WGL) are both "handles", which are implemented as pointers.
117     // Use void* here and let the underlying implementation handle interpreting the type correctly.
118     virtual GLWindowContext getCurrentContextGeneric()                  = 0;
119     virtual GLWindowContext createContextGeneric(GLWindowContext share) = 0;
120     virtual bool makeCurrentGeneric(GLWindowContext context)            = 0;
121     virtual Image createImage(GLWindowContext context,
122                               Enum target,
123                               ClientBuffer buffer,
124                               const Attrib *attrib_list)                = 0;
125     virtual Image createImageKHR(GLWindowContext context,
126                                  Enum target,
127                                  ClientBuffer buffer,
128                                  const AttribKHR *attrib_list)          = 0;
129     virtual EGLBoolean destroyImage(Image image)                        = 0;
130     virtual EGLBoolean destroyImageKHR(Image image)                     = 0;
131 
132     virtual Sync createSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list)        = 0;
133     virtual Sync createSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)        = 0;
134     virtual EGLBoolean destroySync(EGLDisplay dpy, Sync sync)                                  = 0;
135     virtual EGLBoolean destroySyncKHR(EGLDisplay dpy, Sync sync)                               = 0;
136     virtual EGLint clientWaitSync(EGLDisplay dpy, Sync sync, EGLint flags, EGLTimeKHR timeout) = 0;
137     virtual EGLint clientWaitSyncKHR(EGLDisplay dpy,
138                                      Sync sync,
139                                      EGLint flags,
140                                      EGLTimeKHR timeout)                                       = 0;
141 
142     virtual EGLint getEGLError()                                    = 0;
143     virtual Display getCurrentDisplay()                             = 0;
144     virtual Surface createPbufferSurface(const EGLint *attrib_list) = 0;
145     virtual EGLBoolean destroySurface(Surface surface)              = 0;
146 
147     virtual EGLBoolean bindTexImage(EGLSurface surface, EGLint buffer)    = 0;
148     virtual EGLBoolean releaseTexImage(EGLSurface surface, EGLint buffer) = 0;
149 
150     virtual bool makeCurrent(EGLSurface draw, EGLSurface read, EGLContext context) = 0;
151 
isMultisample()152     bool isMultisample() const { return mConfigParams.multisample; }
isDebugEnabled()153     bool isDebugEnabled() const { return mConfigParams.debug; }
154 
getPlatformMethods()155     const angle::PlatformMethods *getPlatformMethods() const { return mPlatform.platformMethods; }
156 
getPlatform()157     const EGLPlatformParameters &getPlatform() const { return mPlatform; }
getConfigParams()158     const ConfigParameters &getConfigParams() const { return mConfigParams; }
159 
isFeatureEnabled(angle::Feature feature)160     virtual bool isFeatureEnabled(angle::Feature feature) { return false; }
161 
162   protected:
163     GLWindowBase(EGLenum clientType,
164                  EGLint glesMajorVersion,
165                  EGLint glesMinorVersion,
166                  EGLint profileMask);
167     virtual ~GLWindowBase();
168 
169     EGLenum mClientType;
170     EGLint mClientMajorVersion;
171     EGLint mClientMinorVersion;
172     EGLint mProfileMask;
173     EGLPlatformParameters mPlatform;
174     ConfigParameters mConfigParams;
175 };
176 
177 enum class ANGLEFeatureStatus
178 {
179     Enabled,
180     Disabled,
181     Unknown,
182 };
183 using ANGLEFeatureArray = angle::PackedEnumMap<angle::Feature, ANGLEFeatureStatus>;
184 
185 class ANGLE_UTIL_EXPORT EGLWindow : public GLWindowBase
186 {
187   public:
188     static EGLWindow *New(EGLenum clientType,
189                           EGLint glesMajorVersion,
190                           EGLint glesMinorVersion,
191                           EGLint profileMask);
192     static void Delete(EGLWindow **window);
193 
194     static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
195 
196     EGLConfig getConfig() const;
197     EGLDisplay getDisplay() const;
198     EGLSurface getSurface() const;
199     EGLContext getContext() const;
200 
201     bool isContextVersion(EGLint glesMajorVersion, EGLint glesMinorVersion) const;
202 
203     // Internally initializes the Display, Surface and Context.
204     bool initializeGL(OSWindow *osWindow,
205                       angle::Library *glWindowingLibrary,
206                       angle::GLESDriverType driverType,
207                       const EGLPlatformParameters &platformParams,
208                       const ConfigParameters &configParams) override;
209 
210     GLWindowResult initializeGLWithResult(OSWindow *osWindow,
211                                           angle::Library *glWindowingLibrary,
212                                           angle::GLESDriverType driverType,
213                                           const EGLPlatformParameters &platformParams,
214                                           const ConfigParameters &configParams) override;
215 
216     bool isGLInitialized() const override;
217     void swap() override;
218     void destroyGL() override;
219     bool makeCurrent() override;
220     bool hasError() const override;
221     bool setSwapInterval(EGLint swapInterval) override;
222     angle::GenericProc getProcAddress(const char *name) override;
223     // Initializes EGL resources.
224     GLWindowContext getCurrentContextGeneric() override;
225     GLWindowContext createContextGeneric(GLWindowContext share) override;
226     bool makeCurrentGeneric(GLWindowContext context) override;
227 
228     // Only initializes the Display.
229     bool initializeDisplay(OSWindow *osWindow,
230                            angle::Library *glWindowingLibrary,
231                            angle::GLESDriverType driverType,
232                            const EGLPlatformParameters &params);
233 
234     // Only initializes the Surface.
235     GLWindowResult initializeSurface(OSWindow *osWindow,
236                                      angle::Library *glWindowingLibrary,
237                                      const ConfigParameters &params);
238 
239     // Create an EGL context with this window's configuration
240     EGLContext createContext(EGLContext share, EGLint *extraAttributes);
241     // Make the EGL context current
242     bool makeCurrent(EGLContext context);
243 
244     Image createImage(GLWindowContext context,
245                       Enum target,
246                       ClientBuffer buffer,
247                       const Attrib *attrib_list) override;
248     Image createImageKHR(GLWindowContext context,
249                          Enum target,
250                          ClientBuffer buffer,
251                          const AttribKHR *attrib_list) override;
252 
253     EGLBoolean destroyImage(Image image) override;
254     EGLBoolean destroyImageKHR(Image image) override;
255 
256     Sync createSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) override;
257     Sync createSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) override;
258     EGLBoolean destroySync(EGLDisplay dpy, Sync sync) override;
259     EGLBoolean destroySyncKHR(EGLDisplay dpy, Sync sync) override;
260     EGLint clientWaitSync(EGLDisplay dpy, Sync sync, EGLint flags, EGLTimeKHR timeout) override;
261     EGLint clientWaitSyncKHR(EGLDisplay dpy, Sync sync, EGLint flags, EGLTimeKHR timeout) override;
262 
263     EGLint getEGLError() override;
264     Display getCurrentDisplay() override;
265     Surface createPbufferSurface(const EGLint *attrib_list) override;
266     EGLBoolean destroySurface(Surface surface) override;
267 
268     EGLBoolean bindTexImage(EGLSurface surface, EGLint buffer) override;
269     EGLBoolean releaseTexImage(EGLSurface surface, EGLint buffer) override;
270     bool makeCurrent(EGLSurface draw, EGLSurface read, EGLContext context) override;
271 
272     // Only initializes the Context.
273     bool initializeContext();
274 
275     void destroySurface();
276     void destroyContext();
277 
isDisplayInitialized()278     bool isDisplayInitialized() const { return mDisplay != EGL_NO_DISPLAY; }
279 
280     // Get the status of features and cache them in mFeatures.
281     void queryFeatures();
282     // Return whether a feature is enabled.  Features that don't exist in the backend have Unknown
283     // status, and are considered disabled for the purposes of this function.
284     bool isFeatureEnabled(angle::Feature feature) override;
285 
286   private:
287     EGLWindow(EGLenum clientType,
288               EGLint glesMajorVersion,
289               EGLint glesMinorVersion,
290               EGLint profileMask);
291     ~EGLWindow() override;
292 
293     EGLConfig mConfig;
294     EGLDisplay mDisplay;
295     EGLSurface mSurface;
296     EGLContext mContext;
297 
298     EGLint mEGLMajorVersion;
299     EGLint mEGLMinorVersion;
300 
301     ANGLEFeatureArray mFeatures;
302 };
303 
304 #endif  // UTIL_EGLWINDOW_H_
305