blob: 1977ffc644d16c8d754162bfeeee11271b7bc8ed [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
Jamie Madill35cd7332018-12-02 12:03:33 -050010#include <stdint.h>
Corentin Wallez178e5972015-09-14 11:52:44 -070011#include <list>
12#include <memory>
Corentin Wallez178e5972015-09-14 11:52:44 -070013#include <string>
14
Jamie Madill35cd7332018-12-02 12:03:33 -050015#include <EGL/egl.h>
16#include <EGL/eglext.h>
Jamie Madill1cfaaf82014-08-21 10:04:04 -040017#include <GLES2/gl2.h>
18#include <GLES2/gl2ext.h>
Corentin Wallez178e5972015-09-14 11:52:44 -070019#include <GLES3/gl3.h>
Jamie Madill35cd7332018-12-02 12:03:33 -050020#include <export.h>
Jamie Madill1cfaaf82014-08-21 10:04:04 -040021
Jamie Madill0448ec82016-12-23 13:41:47 -050022#include "common/Optional.h"
Jamie Madill35cd7332018-12-02 12:03:33 -050023#include "common/angleutils.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);
Jamie Madill35cd7332018-12-02 12:03:33 -050042 EGLPlatformParameters(EGLint renderer,
43 EGLint majorVersion,
44 EGLint minorVersion,
45 EGLint deviceType);
Austin Kinross2a63b3f2016-02-08 12:29:08 -080046 EGLPlatformParameters(EGLint renderer,
47 EGLint majorVersion,
48 EGLint minorVersion,
49 EGLint deviceType,
50 EGLint presentPath);
Geoff Lang0d3683c2014-10-23 11:08:16 -040051};
52
Yuly Novikove3352f92016-08-12 20:40:14 -040053ANGLE_EXPORT bool operator<(const EGLPlatformParameters &a, const EGLPlatformParameters &b);
54ANGLE_EXPORT bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b);
Geoff Langdd323e92015-06-09 15:16:31 -040055
Yuly Novikove3352f92016-08-12 20:40:14 -040056class ANGLE_EXPORT EGLWindow : angle::NonCopyable
Jamie Madill1cfaaf82014-08-21 10:04:04 -040057{
58 public:
Geoff Lang5ade8452015-09-02 11:00:30 -040059 EGLWindow(EGLint glesMajorVersion,
60 EGLint glesMinorVersion,
61 const EGLPlatformParameters &platform);
Jamie Madill1cfaaf82014-08-21 10:04:04 -040062
63 ~EGLWindow();
64
Jamie Madill3757a5a2014-08-26 13:16:36 -040065 void setConfigRedBits(int bits) { mRedBits = bits; }
66 void setConfigGreenBits(int bits) { mGreenBits = bits; }
67 void setConfigBlueBits(int bits) { mBlueBits = bits; }
68 void setConfigAlphaBits(int bits) { mAlphaBits = bits; }
69 void setConfigDepthBits(int bits) { mDepthBits = bits; }
70 void setConfigStencilBits(int bits) { mStencilBits = bits; }
Geoff Langc5a2a172017-01-13 15:55:07 -050071 void setConfigComponentType(EGLenum componentType) { mComponentType = componentType; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040072 void setMultisample(bool multisample) { mMultisample = multisample; }
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -070073 void setSamples(EGLint samples) { mSamples = samples; }
Geoff Lang70d0f492015-12-10 17:45:46 -050074 void setDebugEnabled(bool debug) { mDebug = debug; }
Jamie Madill60ec6ea2016-01-22 15:27:19 -050075 void setNoErrorEnabled(bool noError) { mNoError = noError; }
Geoff Langc287ea62016-09-16 14:46:51 -040076 void setWebGLCompatibilityEnabled(bool webglCompatibility)
77 {
78 mWebGLCompatibility = webglCompatibility;
79 }
Geoff Lang0ab41fa2018-03-14 11:03:30 -040080 void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; }
Geoff Langf41a7152016-09-19 15:11:17 -040081 void setBindGeneratesResource(bool bindGeneratesResource)
82 {
83 mBindGeneratesResource = bindGeneratesResource;
84 }
Jamie Madill222c5172017-07-19 16:15:42 -040085 void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; }
Geoff Langfeb8c682017-02-13 16:07:35 -050086 void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; }
Jiajia Qin8a7b3a02017-08-25 16:05:48 +080087 void setRobustAccess(bool enabled) { mRobustAccess = enabled; }
Jamie Madille08a1d32017-03-07 17:24:06 -050088 void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040089 void setSwapInterval(EGLint swapInterval) { mSwapInterval = swapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -040090 void setPlatformMethods(angle::PlatformMethods *platformMethods)
91 {
92 mPlatformMethods = platformMethods;
93 }
Jamie Madill293e1142017-07-11 13:51:05 -040094 void setContextProgramCacheEnabled(bool enabled) { mContextProgramCacheEnabled = enabled; }
Geoff Lang24ddc7a2018-06-11 14:56:34 -040095 void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040096
Cooper Partin1bd7dd42015-06-11 08:58:53 -070097 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
98
Jamie Madill1cfaaf82014-08-21 10:04:04 -040099 void swap();
100
Geoff Lang5ade8452015-09-02 11:00:30 -0400101 EGLint getClientMajorVersion() const { return mClientMajorVersion; }
102 EGLint getClientMinorVersion() const { return mClientMinorVersion; }
Geoff Lang0d3683c2014-10-23 11:08:16 -0400103 const EGLPlatformParameters &getPlatform() const { return mPlatform; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400104 EGLConfig getConfig() const;
105 EGLDisplay getDisplay() const;
106 EGLSurface getSurface() const;
107 EGLContext getContext() const;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400108 int getConfigRedBits() const { return mRedBits; }
109 int getConfigGreenBits() const { return mGreenBits; }
110 int getConfigBlueBits() const { return mBlueBits; }
111 int getConfigAlphaBits() const { return mAlphaBits; }
112 int getConfigDepthBits() const { return mDepthBits; }
113 int getConfigStencilBits() const { return mStencilBits; }
114 bool isMultisample() const { return mMultisample; }
Geoff Lang70d0f492015-12-10 17:45:46 -0500115 bool isDebugEnabled() const { return mDebug; }
Jamie Madill3757a5a2014-08-26 13:16:36 -0400116 EGLint getSwapInterval() const { return mSwapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -0400117 const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400118
Jamie Madille08a1d32017-03-07 17:24:06 -0500119 // Internally initializes the Display, Surface and Context.
Austin Kinross18b931d2014-09-29 12:58:31 -0700120 bool initializeGL(OSWindow *osWindow);
Jamie Madille08a1d32017-03-07 17:24:06 -0500121
122 // Only initializes the Display and Surface.
123 bool initializeDisplayAndSurface(OSWindow *osWindow);
124
Geoff Lang3b9b0272018-04-30 16:27:24 -0400125 // Create an EGL context with this window's configuration
126 EGLContext createContext(EGLContext share) const;
127
Jamie Madille08a1d32017-03-07 17:24:06 -0500128 // Only initializes the Context.
129 bool initializeContext();
130
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400131 void destroyGL();
Jamie Madill77a72f62015-04-14 11:18:32 -0400132 bool isGLInitialized() const;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400133
Jamie Madillfe548342017-06-19 11:13:24 -0400134 void makeCurrent();
135
Jamie Madill948bbe52017-06-01 13:10:42 -0400136 static bool ClientExtensionEnabled(const std::string &extName);
137
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400138 private:
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400139 EGLConfig mConfig;
140 EGLDisplay mDisplay;
141 EGLSurface mSurface;
142 EGLContext mContext;
143
Geoff Lang5ade8452015-09-02 11:00:30 -0400144 EGLint mClientMajorVersion;
145 EGLint mClientMinorVersion;
Jamie Madille08a1d32017-03-07 17:24:06 -0500146 EGLint mEGLMajorVersion;
147 EGLint mEGLMinorVersion;
Geoff Lang0d3683c2014-10-23 11:08:16 -0400148 EGLPlatformParameters mPlatform;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400149 int mRedBits;
150 int mGreenBits;
151 int mBlueBits;
152 int mAlphaBits;
153 int mDepthBits;
154 int mStencilBits;
Geoff Langc5a2a172017-01-13 15:55:07 -0500155 EGLenum mComponentType;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400156 bool mMultisample;
Geoff Lang70d0f492015-12-10 17:45:46 -0500157 bool mDebug;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500158 bool mNoError;
Geoff Langc287ea62016-09-16 14:46:51 -0400159 bool mWebGLCompatibility;
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400160 Optional<bool> mExtensionsEnabled;
Geoff Langf41a7152016-09-19 15:11:17 -0400161 bool mBindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500162 bool mClientArraysEnabled;
Jiajia Qin8a7b3a02017-08-25 16:05:48 +0800163 bool mRobustAccess;
Jamie Madill948bbe52017-06-01 13:10:42 -0400164 Optional<bool> mRobustResourceInit;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400165 EGLint mSwapInterval;
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -0700166 EGLint mSamples;
Jamie Madill222c5172017-07-19 16:15:42 -0400167 Optional<bool> mDebugLayersEnabled;
Jamie Madill293e1142017-07-11 13:51:05 -0400168 Optional<bool> mContextProgramCacheEnabled;
Geoff Lang24ddc7a2018-06-11 14:56:34 -0400169 Optional<bool> mContextVirtualization;
Jamie Madill98de8262017-05-29 13:01:02 -0400170 angle::PlatformMethods *mPlatformMethods;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400171};
172
Jamie Madill948bbe52017-06-01 13:10:42 -0400173ANGLE_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName);
174
Jamie Madill35cd7332018-12-02 12:03:33 -0500175#endif // UTIL_EGLWINDOW_H_