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 }; 61 62 class ANGLE_UTIL_EXPORT GLWindowBase : angle::NonCopyable 63 { 64 public: 65 static void Delete(GLWindowBase **window); 66 67 // It should also be possible to set multisample and floating point framebuffers. getClientMajorVersion()68 EGLint getClientMajorVersion() const { return mClientMajorVersion; } getClientMinorVersion()69 EGLint getClientMinorVersion() const { return mClientMinorVersion; } 70 71 virtual bool initializeGL(OSWindow *osWindow, 72 angle::Library *glWindowingLibrary, 73 angle::GLESDriverType driverType, 74 const EGLPlatformParameters &platformParams, 75 const ConfigParameters &configParams) = 0; 76 virtual bool isGLInitialized() const = 0; 77 virtual void swap() = 0; 78 virtual void destroyGL() = 0; 79 virtual bool makeCurrent() = 0; 80 virtual bool hasError() const = 0; 81 virtual bool setSwapInterval(EGLint swapInterval) = 0; 82 virtual angle::GenericProc getProcAddress(const char *name) = 0; 83 isMultisample()84 bool isMultisample() const { return mConfigParams.multisample; } isDebugEnabled()85 bool isDebugEnabled() const { return mConfigParams.debug; } 86 getPlatformMethods()87 const angle::PlatformMethods *getPlatformMethods() const { return mPlatform.platformMethods; } 88 getPlatform()89 const EGLPlatformParameters &getPlatform() const { return mPlatform; } getConfigParams()90 const ConfigParameters &getConfigParams() const { return mConfigParams; } 91 92 protected: 93 GLWindowBase(EGLint glesMajorVersion, EGLint glesMinorVersion); 94 virtual ~GLWindowBase(); 95 96 EGLint mClientMajorVersion; 97 EGLint mClientMinorVersion; 98 EGLPlatformParameters mPlatform; 99 ConfigParameters mConfigParams; 100 }; 101 102 class ANGLE_UTIL_EXPORT EGLWindow : public GLWindowBase 103 { 104 public: 105 static EGLWindow *New(EGLint glesMajorVersion, EGLint glesMinorVersion); 106 static void Delete(EGLWindow **window); 107 108 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config); 109 110 EGLConfig getConfig() const; 111 EGLDisplay getDisplay() const; 112 EGLSurface getSurface() const; 113 EGLContext getContext() const; 114 115 bool isContextVersion(EGLint glesMajorVersion, EGLint glesMinorVersion) const; 116 117 // Internally initializes the Display, Surface and Context. 118 bool initializeGL(OSWindow *osWindow, 119 angle::Library *glWindowingLibrary, 120 angle::GLESDriverType driverType, 121 const EGLPlatformParameters &platformParams, 122 const ConfigParameters &configParams) override; 123 124 bool isGLInitialized() const override; 125 void swap() override; 126 void destroyGL() override; 127 bool makeCurrent() override; 128 bool hasError() const override; 129 bool setSwapInterval(EGLint swapInterval) override; 130 angle::GenericProc getProcAddress(const char *name) override; 131 132 // Only initializes the Display. 133 bool initializeDisplay(OSWindow *osWindow, 134 angle::Library *glWindowingLibrary, 135 angle::GLESDriverType driverType, 136 const EGLPlatformParameters ¶ms); 137 138 // Only initializes the Surface. 139 bool initializeSurface(OSWindow *osWindow, 140 angle::Library *glWindowingLibrary, 141 const ConfigParameters ¶ms); 142 143 // Create an EGL context with this window's configuration 144 EGLContext createContext(EGLContext share) const; 145 146 // Only initializes the Context. 147 bool initializeContext(); 148 149 void destroySurface(); 150 void destroyContext(); 151 isDisplayInitialized()152 bool isDisplayInitialized() const { return mDisplay != EGL_NO_DISPLAY; } 153 154 private: 155 EGLWindow(EGLint glesMajorVersion, EGLint glesMinorVersion); 156 157 ~EGLWindow() override; 158 159 EGLConfig mConfig; 160 EGLDisplay mDisplay; 161 EGLSurface mSurface; 162 EGLContext mContext; 163 164 EGLint mEGLMajorVersion; 165 EGLint mEGLMinorVersion; 166 }; 167 168 #endif // UTIL_EGLWINDOW_H_ 169