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/angleutils.h" 17 #include "util/EGLPlatformParameters.h" 18 #include "util/util_export.h" 19 #include "util/util_gl.h" 20 21 class OSWindow; 22 23 namespace angle 24 { 25 class Library; 26 struct PlatformMethods; 27 using GenericProc = void (*)(); 28 } // namespace angle 29 30 struct ANGLE_UTIL_EXPORT ConfigParameters 31 { 32 ConfigParameters(); 33 ~ConfigParameters(); 34 35 void reset(); 36 37 // Surface and Context parameters. 38 int redBits; 39 int greenBits; 40 int blueBits; 41 int alphaBits; 42 int depthBits; 43 int stencilBits; 44 45 Optional<bool> webGLCompatibility; 46 Optional<bool> robustResourceInit; 47 48 // EGLWindow-specific. 49 EGLenum componentType; 50 bool multisample; 51 bool debug; 52 bool noError; 53 Optional<bool> extensionsEnabled; 54 bool bindGeneratesResource; 55 bool clientArraysEnabled; 56 bool robustAccess; 57 EGLint samples; 58 Optional<bool> contextProgramCacheEnabled; 59 EGLenum resetStrategy; 60 EGLenum colorSpace; 61 EGLint swapInterval; 62 }; 63 64 using GLWindowContext = struct GLWindowHandleContext_T *; 65 66 enum class GLWindowResult 67 { 68 NoError, 69 NoColorspaceSupport, 70 Error, 71 }; 72 73 class ANGLE_UTIL_EXPORT GLWindowBase : angle::NonCopyable 74 { 75 public: 76 static void Delete(GLWindowBase **window); 77 78 // It should also be possible to set multisample and floating point framebuffers. getClientMajorVersion()79 EGLint getClientMajorVersion() const { return mClientMajorVersion; } getClientMinorVersion()80 EGLint getClientMinorVersion() const { return mClientMinorVersion; } 81 82 virtual bool initializeGL(OSWindow *osWindow, 83 angle::Library *glWindowingLibrary, 84 angle::GLESDriverType driverType, 85 const EGLPlatformParameters &platformParams, 86 const ConfigParameters &configParams) = 0; 87 88 virtual GLWindowResult initializeGLWithResult(OSWindow *osWindow, 89 angle::Library *glWindowingLibrary, 90 angle::GLESDriverType driverType, 91 const EGLPlatformParameters &platformParams, 92 const ConfigParameters &configParams) = 0; 93 94 virtual bool isGLInitialized() const = 0; 95 virtual void swap() = 0; 96 virtual void destroyGL() = 0; 97 virtual bool makeCurrent() = 0; 98 virtual bool hasError() const = 0; 99 virtual bool setSwapInterval(EGLint swapInterval) = 0; 100 virtual angle::GenericProc getProcAddress(const char *name) = 0; 101 // EGLContext and HGLRC (WGL) are both "handles", which are implemented as pointers. 102 // Use void* here and let the underlying implementation handle interpreting the type correctly. 103 virtual GLWindowContext getCurrentContextGeneric() = 0; 104 virtual GLWindowContext createContextGeneric(GLWindowContext share) = 0; 105 virtual bool makeCurrentGeneric(GLWindowContext context) = 0; 106 isMultisample()107 bool isMultisample() const { return mConfigParams.multisample; } isDebugEnabled()108 bool isDebugEnabled() const { return mConfigParams.debug; } 109 getPlatformMethods()110 const angle::PlatformMethods *getPlatformMethods() const { return mPlatform.platformMethods; } 111 getPlatform()112 const EGLPlatformParameters &getPlatform() const { return mPlatform; } getConfigParams()113 const ConfigParameters &getConfigParams() const { return mConfigParams; } 114 115 protected: 116 GLWindowBase(EGLint glesMajorVersion, EGLint glesMinorVersion); 117 virtual ~GLWindowBase(); 118 119 EGLint mClientMajorVersion; 120 EGLint mClientMinorVersion; 121 EGLPlatformParameters mPlatform; 122 ConfigParameters mConfigParams; 123 }; 124 125 class ANGLE_UTIL_EXPORT EGLWindow : public GLWindowBase 126 { 127 public: 128 static EGLWindow *New(EGLint glesMajorVersion, EGLint glesMinorVersion); 129 static void Delete(EGLWindow **window); 130 131 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config); 132 133 EGLConfig getConfig() const; 134 EGLDisplay getDisplay() const; 135 EGLSurface getSurface() const; 136 EGLContext getContext() const; 137 138 bool isContextVersion(EGLint glesMajorVersion, EGLint glesMinorVersion) const; 139 140 // Internally initializes the Display, Surface and Context. 141 bool initializeGL(OSWindow *osWindow, 142 angle::Library *glWindowingLibrary, 143 angle::GLESDriverType driverType, 144 const EGLPlatformParameters &platformParams, 145 const ConfigParameters &configParams) override; 146 147 GLWindowResult initializeGLWithResult(OSWindow *osWindow, 148 angle::Library *glWindowingLibrary, 149 angle::GLESDriverType driverType, 150 const EGLPlatformParameters &platformParams, 151 const ConfigParameters &configParams) override; 152 153 bool isGLInitialized() const override; 154 void swap() override; 155 void destroyGL() override; 156 bool makeCurrent() override; 157 bool hasError() const override; 158 bool setSwapInterval(EGLint swapInterval) override; 159 angle::GenericProc getProcAddress(const char *name) override; 160 // Initializes EGL resources. 161 GLWindowContext getCurrentContextGeneric() override; 162 GLWindowContext createContextGeneric(GLWindowContext share) override; 163 bool makeCurrentGeneric(GLWindowContext context) override; 164 165 // Only initializes the Display. 166 bool initializeDisplay(OSWindow *osWindow, 167 angle::Library *glWindowingLibrary, 168 angle::GLESDriverType driverType, 169 const EGLPlatformParameters ¶ms); 170 171 // Only initializes the Surface. 172 GLWindowResult initializeSurface(OSWindow *osWindow, 173 angle::Library *glWindowingLibrary, 174 const ConfigParameters ¶ms); 175 176 // Create an EGL context with this window's configuration 177 EGLContext createContext(EGLContext share, EGLint *extraAttributes); 178 // Make the EGL context current 179 bool makeCurrent(EGLContext context); 180 181 // Only initializes the Context. 182 bool initializeContext(); 183 184 void destroySurface(); 185 void destroyContext(); 186 isDisplayInitialized()187 bool isDisplayInitialized() const { return mDisplay != EGL_NO_DISPLAY; } 188 189 private: 190 EGLWindow(EGLint glesMajorVersion, EGLint glesMinorVersion); 191 ~EGLWindow() override; 192 193 EGLConfig mConfig; 194 EGLDisplay mDisplay; 195 EGLSurface mSurface; 196 EGLContext mContext; 197 198 EGLint mEGLMajorVersion; 199 EGLint mEGLMinorVersion; 200 }; 201 202 #endif // UTIL_EGLWINDOW_H_ 203