blob: c4c251f92f6735f04f84370bd2a3a5ee14990bcf [file] [log] [blame]
Jamie Madill1cfaaf82014-08-21 10:04:04 -04001//
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
Corentin Wallez178e5972015-09-14 11:52:44 -070010#include <list>
11#include <memory>
12#include <stdint.h>
13#include <string>
14
Yuly Novikove3352f92016-08-12 20:40:14 -040015#include <export.h>
Jamie Madill1cfaaf82014-08-21 10:04:04 -040016#include <GLES2/gl2.h>
17#include <GLES2/gl2ext.h>
Corentin Wallez178e5972015-09-14 11:52:44 -070018#include <GLES3/gl3.h>
Jamie Madill1cfaaf82014-08-21 10:04:04 -040019#include <EGL/egl.h>
20#include <EGL/eglext.h>
21
Jamie Madill2d1eea02015-03-27 09:46:41 -040022#include "common/angleutils.h"
Jamie Madill0448ec82016-12-23 13:41:47 -050023#include "common/Optional.h"
Jamie Madill1cfaaf82014-08-21 10:04:04 -040024
25class OSWindow;
26
Jamie Madill98de8262017-05-29 13:01:02 -040027namespace angle
28{
29struct PlatformMethods;
30}
31
Yuly Novikove3352f92016-08-12 20:40:14 -040032struct ANGLE_EXPORT EGLPlatformParameters
Geoff Lang0d3683c2014-10-23 11:08:16 -040033{
34 EGLint renderer;
35 EGLint majorVersion;
36 EGLint minorVersion;
Geoff Lang7825f612014-11-26 16:19:41 -050037 EGLint deviceType;
Austin Kinross2a63b3f2016-02-08 12:29:08 -080038 EGLint presentPath;
Geoff Lang0d3683c2014-10-23 11:08:16 -040039
40 EGLPlatformParameters();
41 explicit EGLPlatformParameters(EGLint renderer);
Geoff Lang7825f612014-11-26 16:19:41 -050042 EGLPlatformParameters(EGLint renderer, EGLint majorVersion, EGLint minorVersion, EGLint deviceType);
Austin Kinross2a63b3f2016-02-08 12:29:08 -080043 EGLPlatformParameters(EGLint renderer,
44 EGLint majorVersion,
45 EGLint minorVersion,
46 EGLint deviceType,
47 EGLint presentPath);
Geoff Lang0d3683c2014-10-23 11:08:16 -040048};
49
Yuly Novikove3352f92016-08-12 20:40:14 -040050ANGLE_EXPORT bool operator<(const EGLPlatformParameters &a, const EGLPlatformParameters &b);
51ANGLE_EXPORT bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b);
Geoff Langdd323e92015-06-09 15:16:31 -040052
Yuly Novikove3352f92016-08-12 20:40:14 -040053class ANGLE_EXPORT EGLWindow : angle::NonCopyable
Jamie Madill1cfaaf82014-08-21 10:04:04 -040054{
55 public:
Geoff Lang5ade8452015-09-02 11:00:30 -040056 EGLWindow(EGLint glesMajorVersion,
57 EGLint glesMinorVersion,
58 const EGLPlatformParameters &platform);
Jamie Madill1cfaaf82014-08-21 10:04:04 -040059
60 ~EGLWindow();
61
Jamie Madill3757a5a2014-08-26 13:16:36 -040062 void setConfigRedBits(int bits) { mRedBits = bits; }
63 void setConfigGreenBits(int bits) { mGreenBits = bits; }
64 void setConfigBlueBits(int bits) { mBlueBits = bits; }
65 void setConfigAlphaBits(int bits) { mAlphaBits = bits; }
66 void setConfigDepthBits(int bits) { mDepthBits = bits; }
67 void setConfigStencilBits(int bits) { mStencilBits = bits; }
Geoff Langc5a2a172017-01-13 15:55:07 -050068 void setConfigComponentType(EGLenum componentType) { mComponentType = componentType; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040069 void setMultisample(bool multisample) { mMultisample = multisample; }
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -070070 void setSamples(EGLint samples) { mSamples = samples; }
Geoff Lang70d0f492015-12-10 17:45:46 -050071 void setDebugEnabled(bool debug) { mDebug = debug; }
Jamie Madill60ec6ea2016-01-22 15:27:19 -050072 void setNoErrorEnabled(bool noError) { mNoError = noError; }
Geoff Langc287ea62016-09-16 14:46:51 -040073 void setWebGLCompatibilityEnabled(bool webglCompatibility)
74 {
75 mWebGLCompatibility = webglCompatibility;
76 }
Geoff Lang0ab41fa2018-03-14 11:03:30 -040077 void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; }
Geoff Langf41a7152016-09-19 15:11:17 -040078 void setBindGeneratesResource(bool bindGeneratesResource)
79 {
80 mBindGeneratesResource = bindGeneratesResource;
81 }
Jamie Madill222c5172017-07-19 16:15:42 -040082 void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; }
Geoff Langfeb8c682017-02-13 16:07:35 -050083 void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; }
Jiajia Qin8a7b3a02017-08-25 16:05:48 +080084 void setRobustAccess(bool enabled) { mRobustAccess = enabled; }
Jamie Madille08a1d32017-03-07 17:24:06 -050085 void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040086 void setSwapInterval(EGLint swapInterval) { mSwapInterval = swapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -040087 void setPlatformMethods(angle::PlatformMethods *platformMethods)
88 {
89 mPlatformMethods = platformMethods;
90 }
Jamie Madill293e1142017-07-11 13:51:05 -040091 void setContextProgramCacheEnabled(bool enabled) { mContextProgramCacheEnabled = enabled; }
Geoff Lang24ddc7a2018-06-11 14:56:34 -040092 void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040093
Cooper Partin1bd7dd42015-06-11 08:58:53 -070094 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
95
Jamie Madill1cfaaf82014-08-21 10:04:04 -040096 void swap();
97
Geoff Lang5ade8452015-09-02 11:00:30 -040098 EGLint getClientMajorVersion() const { return mClientMajorVersion; }
99 EGLint getClientMinorVersion() const { return mClientMinorVersion; }
Geoff Lang0d3683c2014-10-23 11:08:16 -0400100 const EGLPlatformParameters &getPlatform() const { return mPlatform; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400101 EGLConfig getConfig() const;
102 EGLDisplay getDisplay() const;
103 EGLSurface getSurface() const;
104 EGLContext getContext() const;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400105 int getConfigRedBits() const { return mRedBits; }
106 int getConfigGreenBits() const { return mGreenBits; }
107 int getConfigBlueBits() const { return mBlueBits; }
108 int getConfigAlphaBits() const { return mAlphaBits; }
109 int getConfigDepthBits() const { return mDepthBits; }
110 int getConfigStencilBits() const { return mStencilBits; }
111 bool isMultisample() const { return mMultisample; }
Geoff Lang70d0f492015-12-10 17:45:46 -0500112 bool isDebugEnabled() const { return mDebug; }
Jamie Madill3757a5a2014-08-26 13:16:36 -0400113 EGLint getSwapInterval() const { return mSwapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -0400114 const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400115
Jamie Madille08a1d32017-03-07 17:24:06 -0500116 // Internally initializes the Display, Surface and Context.
Austin Kinross18b931d2014-09-29 12:58:31 -0700117 bool initializeGL(OSWindow *osWindow);
Jamie Madille08a1d32017-03-07 17:24:06 -0500118
119 // Only initializes the Display and Surface.
120 bool initializeDisplayAndSurface(OSWindow *osWindow);
121
Geoff Lang3b9b0272018-04-30 16:27:24 -0400122 // Create an EGL context with this window's configuration
123 EGLContext createContext(EGLContext share) const;
124
Jamie Madille08a1d32017-03-07 17:24:06 -0500125 // Only initializes the Context.
126 bool initializeContext();
127
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400128 void destroyGL();
Jamie Madill77a72f62015-04-14 11:18:32 -0400129 bool isGLInitialized() const;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400130
Jamie Madillfe548342017-06-19 11:13:24 -0400131 void makeCurrent();
132
Jamie Madill948bbe52017-06-01 13:10:42 -0400133 static bool ClientExtensionEnabled(const std::string &extName);
134
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400135 private:
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400136 EGLConfig mConfig;
137 EGLDisplay mDisplay;
138 EGLSurface mSurface;
139 EGLContext mContext;
140
Geoff Lang5ade8452015-09-02 11:00:30 -0400141 EGLint mClientMajorVersion;
142 EGLint mClientMinorVersion;
Jamie Madille08a1d32017-03-07 17:24:06 -0500143 EGLint mEGLMajorVersion;
144 EGLint mEGLMinorVersion;
Geoff Lang0d3683c2014-10-23 11:08:16 -0400145 EGLPlatformParameters mPlatform;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400146 int mRedBits;
147 int mGreenBits;
148 int mBlueBits;
149 int mAlphaBits;
150 int mDepthBits;
151 int mStencilBits;
Geoff Langc5a2a172017-01-13 15:55:07 -0500152 EGLenum mComponentType;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400153 bool mMultisample;
Geoff Lang70d0f492015-12-10 17:45:46 -0500154 bool mDebug;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500155 bool mNoError;
Geoff Langc287ea62016-09-16 14:46:51 -0400156 bool mWebGLCompatibility;
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400157 Optional<bool> mExtensionsEnabled;
Geoff Langf41a7152016-09-19 15:11:17 -0400158 bool mBindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500159 bool mClientArraysEnabled;
Jiajia Qin8a7b3a02017-08-25 16:05:48 +0800160 bool mRobustAccess;
Jamie Madill948bbe52017-06-01 13:10:42 -0400161 Optional<bool> mRobustResourceInit;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400162 EGLint mSwapInterval;
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -0700163 EGLint mSamples;
Jamie Madill222c5172017-07-19 16:15:42 -0400164 Optional<bool> mDebugLayersEnabled;
Jamie Madill293e1142017-07-11 13:51:05 -0400165 Optional<bool> mContextProgramCacheEnabled;
Geoff Lang24ddc7a2018-06-11 14:56:34 -0400166 Optional<bool> mContextVirtualization;
Jamie Madill98de8262017-05-29 13:01:02 -0400167 angle::PlatformMethods *mPlatformMethods;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400168};
169
Jamie Madill948bbe52017-06-01 13:10:42 -0400170ANGLE_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName);
171
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400172#endif // UTIL_EGLWINDOW_H_