Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 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 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 10 | #include <stdint.h> |
Corentin Wallez | 178e597 | 2015-09-14 11:52:44 -0700 | [diff] [blame] | 11 | #include <list> |
| 12 | #include <memory> |
Corentin Wallez | 178e597 | 2015-09-14 11:52:44 -0700 | [diff] [blame] | 13 | #include <string> |
| 14 | |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 15 | #include "common/Optional.h" |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 16 | #include "common/angleutils.h" |
Jamie Madill | ba319ba | 2018-12-29 10:29:33 -0500 | [diff] [blame^] | 17 | #include "util/EGLPlatformParameters.h" |
| 18 | #include "util/util_export.h" |
| 19 | #include "util/util_gl.h" |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 20 | |
| 21 | class OSWindow; |
| 22 | |
Jamie Madill | 98de826 | 2017-05-29 13:01:02 -0400 | [diff] [blame] | 23 | namespace angle |
| 24 | { |
Jamie Madill | ba319ba | 2018-12-29 10:29:33 -0500 | [diff] [blame^] | 25 | class Library; |
Jamie Madill | 98de826 | 2017-05-29 13:01:02 -0400 | [diff] [blame] | 26 | struct PlatformMethods; |
Jamie Madill | ba319ba | 2018-12-29 10:29:33 -0500 | [diff] [blame^] | 27 | } // namespace angle |
Jamie Madill | 98de826 | 2017-05-29 13:01:02 -0400 | [diff] [blame] | 28 | |
Jamie Madill | ba319ba | 2018-12-29 10:29:33 -0500 | [diff] [blame^] | 29 | class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 30 | { |
| 31 | public: |
Geoff Lang | 5ade845 | 2015-09-02 11:00:30 -0400 | [diff] [blame] | 32 | EGLWindow(EGLint glesMajorVersion, |
| 33 | EGLint glesMinorVersion, |
| 34 | const EGLPlatformParameters &platform); |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 35 | |
| 36 | ~EGLWindow(); |
| 37 | |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 38 | void setConfigRedBits(int bits) { mRedBits = bits; } |
| 39 | void setConfigGreenBits(int bits) { mGreenBits = bits; } |
| 40 | void setConfigBlueBits(int bits) { mBlueBits = bits; } |
| 41 | void setConfigAlphaBits(int bits) { mAlphaBits = bits; } |
| 42 | void setConfigDepthBits(int bits) { mDepthBits = bits; } |
| 43 | void setConfigStencilBits(int bits) { mStencilBits = bits; } |
Geoff Lang | c5a2a17 | 2017-01-13 15:55:07 -0500 | [diff] [blame] | 44 | void setConfigComponentType(EGLenum componentType) { mComponentType = componentType; } |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 45 | void setMultisample(bool multisample) { mMultisample = multisample; } |
Bryan Bernhart (Intel Americas Inc) | 151d5de | 2017-04-13 09:52:23 -0700 | [diff] [blame] | 46 | void setSamples(EGLint samples) { mSamples = samples; } |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 47 | void setDebugEnabled(bool debug) { mDebug = debug; } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 48 | void setNoErrorEnabled(bool noError) { mNoError = noError; } |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 49 | void setWebGLCompatibilityEnabled(bool webglCompatibility) |
| 50 | { |
| 51 | mWebGLCompatibility = webglCompatibility; |
| 52 | } |
Geoff Lang | 0ab41fa | 2018-03-14 11:03:30 -0400 | [diff] [blame] | 53 | void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; } |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 54 | void setBindGeneratesResource(bool bindGeneratesResource) |
| 55 | { |
| 56 | mBindGeneratesResource = bindGeneratesResource; |
| 57 | } |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 58 | void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 59 | void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; } |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 60 | void setRobustAccess(bool enabled) { mRobustAccess = enabled; } |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 61 | void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; } |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 62 | void setSwapInterval(EGLint swapInterval) { mSwapInterval = swapInterval; } |
Jamie Madill | 98de826 | 2017-05-29 13:01:02 -0400 | [diff] [blame] | 63 | void setPlatformMethods(angle::PlatformMethods *platformMethods) |
| 64 | { |
| 65 | mPlatformMethods = platformMethods; |
| 66 | } |
Jamie Madill | 293e114 | 2017-07-11 13:51:05 -0400 | [diff] [blame] | 67 | void setContextProgramCacheEnabled(bool enabled) { mContextProgramCacheEnabled = enabled; } |
Geoff Lang | 24ddc7a | 2018-06-11 14:56:34 -0400 | [diff] [blame] | 68 | void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; } |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 69 | |
Cooper Partin | 1bd7dd4 | 2015-06-11 08:58:53 -0700 | [diff] [blame] | 70 | static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config); |
| 71 | |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 72 | void swap(); |
| 73 | |
Geoff Lang | 5ade845 | 2015-09-02 11:00:30 -0400 | [diff] [blame] | 74 | EGLint getClientMajorVersion() const { return mClientMajorVersion; } |
| 75 | EGLint getClientMinorVersion() const { return mClientMinorVersion; } |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 76 | const EGLPlatformParameters &getPlatform() const { return mPlatform; } |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 77 | EGLConfig getConfig() const; |
| 78 | EGLDisplay getDisplay() const; |
| 79 | EGLSurface getSurface() const; |
| 80 | EGLContext getContext() const; |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 81 | int getConfigRedBits() const { return mRedBits; } |
| 82 | int getConfigGreenBits() const { return mGreenBits; } |
| 83 | int getConfigBlueBits() const { return mBlueBits; } |
| 84 | int getConfigAlphaBits() const { return mAlphaBits; } |
| 85 | int getConfigDepthBits() const { return mDepthBits; } |
| 86 | int getConfigStencilBits() const { return mStencilBits; } |
| 87 | bool isMultisample() const { return mMultisample; } |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 88 | bool isDebugEnabled() const { return mDebug; } |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 89 | EGLint getSwapInterval() const { return mSwapInterval; } |
Jamie Madill | 98de826 | 2017-05-29 13:01:02 -0400 | [diff] [blame] | 90 | const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; } |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 91 | |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 92 | // Internally initializes the Display, Surface and Context. |
Jamie Madill | ba319ba | 2018-12-29 10:29:33 -0500 | [diff] [blame^] | 93 | bool initializeGL(OSWindow *osWindow, angle::Library *eglLibrary); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 94 | |
| 95 | // Only initializes the Display and Surface. |
Jamie Madill | ba319ba | 2018-12-29 10:29:33 -0500 | [diff] [blame^] | 96 | bool initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *eglLibrary); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 97 | |
Geoff Lang | 3b9b027 | 2018-04-30 16:27:24 -0400 | [diff] [blame] | 98 | // Create an EGL context with this window's configuration |
| 99 | EGLContext createContext(EGLContext share) const; |
| 100 | |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 101 | // Only initializes the Context. |
| 102 | bool initializeContext(); |
| 103 | |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 104 | void destroyGL(); |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 105 | bool isGLInitialized() const; |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 106 | |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 107 | void makeCurrent(); |
| 108 | |
Jamie Madill | 948bbe5 | 2017-06-01 13:10:42 -0400 | [diff] [blame] | 109 | static bool ClientExtensionEnabled(const std::string &extName); |
| 110 | |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 111 | private: |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 112 | EGLConfig mConfig; |
| 113 | EGLDisplay mDisplay; |
| 114 | EGLSurface mSurface; |
| 115 | EGLContext mContext; |
| 116 | |
Geoff Lang | 5ade845 | 2015-09-02 11:00:30 -0400 | [diff] [blame] | 117 | EGLint mClientMajorVersion; |
| 118 | EGLint mClientMinorVersion; |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 119 | EGLint mEGLMajorVersion; |
| 120 | EGLint mEGLMinorVersion; |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 121 | EGLPlatformParameters mPlatform; |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 122 | int mRedBits; |
| 123 | int mGreenBits; |
| 124 | int mBlueBits; |
| 125 | int mAlphaBits; |
| 126 | int mDepthBits; |
| 127 | int mStencilBits; |
Geoff Lang | c5a2a17 | 2017-01-13 15:55:07 -0500 | [diff] [blame] | 128 | EGLenum mComponentType; |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 129 | bool mMultisample; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 130 | bool mDebug; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 131 | bool mNoError; |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 132 | bool mWebGLCompatibility; |
Geoff Lang | 0ab41fa | 2018-03-14 11:03:30 -0400 | [diff] [blame] | 133 | Optional<bool> mExtensionsEnabled; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 134 | bool mBindGeneratesResource; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 135 | bool mClientArraysEnabled; |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 136 | bool mRobustAccess; |
Jamie Madill | 948bbe5 | 2017-06-01 13:10:42 -0400 | [diff] [blame] | 137 | Optional<bool> mRobustResourceInit; |
Jamie Madill | 3757a5a | 2014-08-26 13:16:36 -0400 | [diff] [blame] | 138 | EGLint mSwapInterval; |
Bryan Bernhart (Intel Americas Inc) | 151d5de | 2017-04-13 09:52:23 -0700 | [diff] [blame] | 139 | EGLint mSamples; |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 140 | Optional<bool> mDebugLayersEnabled; |
Jamie Madill | 293e114 | 2017-07-11 13:51:05 -0400 | [diff] [blame] | 141 | Optional<bool> mContextProgramCacheEnabled; |
Geoff Lang | 24ddc7a | 2018-06-11 14:56:34 -0400 | [diff] [blame] | 142 | Optional<bool> mContextVirtualization; |
Jamie Madill | 98de826 | 2017-05-29 13:01:02 -0400 | [diff] [blame] | 143 | angle::PlatformMethods *mPlatformMethods; |
Jamie Madill | 1cfaaf8 | 2014-08-21 10:04:04 -0400 | [diff] [blame] | 144 | }; |
| 145 | |
Jamie Madill | ba319ba | 2018-12-29 10:29:33 -0500 | [diff] [blame^] | 146 | ANGLE_UTIL_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName); |
Jamie Madill | 948bbe5 | 2017-06-01 13:10:42 -0400 | [diff] [blame] | 147 | |
Jamie Madill | 35cd733 | 2018-12-02 12:03:33 -0500 | [diff] [blame] | 148 | #endif // UTIL_EGLWINDOW_H_ |