blob: 169eeb0647412b0358eac23d88396d76a517b49b [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; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040092
Cooper Partin1bd7dd42015-06-11 08:58:53 -070093 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
94
Jamie Madill1cfaaf82014-08-21 10:04:04 -040095 void swap();
96
Geoff Lang5ade8452015-09-02 11:00:30 -040097 EGLint getClientMajorVersion() const { return mClientMajorVersion; }
98 EGLint getClientMinorVersion() const { return mClientMinorVersion; }
Geoff Lang0d3683c2014-10-23 11:08:16 -040099 const EGLPlatformParameters &getPlatform() const { return mPlatform; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400100 EGLConfig getConfig() const;
101 EGLDisplay getDisplay() const;
102 EGLSurface getSurface() const;
103 EGLContext getContext() const;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400104 int getConfigRedBits() const { return mRedBits; }
105 int getConfigGreenBits() const { return mGreenBits; }
106 int getConfigBlueBits() const { return mBlueBits; }
107 int getConfigAlphaBits() const { return mAlphaBits; }
108 int getConfigDepthBits() const { return mDepthBits; }
109 int getConfigStencilBits() const { return mStencilBits; }
110 bool isMultisample() const { return mMultisample; }
Geoff Lang70d0f492015-12-10 17:45:46 -0500111 bool isDebugEnabled() const { return mDebug; }
Jamie Madill3757a5a2014-08-26 13:16:36 -0400112 EGLint getSwapInterval() const { return mSwapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -0400113 const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400114
Jamie Madille08a1d32017-03-07 17:24:06 -0500115 // Internally initializes the Display, Surface and Context.
Austin Kinross18b931d2014-09-29 12:58:31 -0700116 bool initializeGL(OSWindow *osWindow);
Jamie Madille08a1d32017-03-07 17:24:06 -0500117
118 // Only initializes the Display and Surface.
119 bool initializeDisplayAndSurface(OSWindow *osWindow);
120
121 // Only initializes the Context.
122 bool initializeContext();
123
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400124 void destroyGL();
Jamie Madill77a72f62015-04-14 11:18:32 -0400125 bool isGLInitialized() const;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400126
Jamie Madillfe548342017-06-19 11:13:24 -0400127 void makeCurrent();
128
Jamie Madill948bbe52017-06-01 13:10:42 -0400129 static bool ClientExtensionEnabled(const std::string &extName);
130
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400131 private:
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400132 EGLConfig mConfig;
133 EGLDisplay mDisplay;
134 EGLSurface mSurface;
135 EGLContext mContext;
136
Geoff Lang5ade8452015-09-02 11:00:30 -0400137 EGLint mClientMajorVersion;
138 EGLint mClientMinorVersion;
Jamie Madille08a1d32017-03-07 17:24:06 -0500139 EGLint mEGLMajorVersion;
140 EGLint mEGLMinorVersion;
Geoff Lang0d3683c2014-10-23 11:08:16 -0400141 EGLPlatformParameters mPlatform;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400142 int mRedBits;
143 int mGreenBits;
144 int mBlueBits;
145 int mAlphaBits;
146 int mDepthBits;
147 int mStencilBits;
Geoff Langc5a2a172017-01-13 15:55:07 -0500148 EGLenum mComponentType;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400149 bool mMultisample;
Geoff Lang70d0f492015-12-10 17:45:46 -0500150 bool mDebug;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500151 bool mNoError;
Geoff Langc287ea62016-09-16 14:46:51 -0400152 bool mWebGLCompatibility;
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400153 Optional<bool> mExtensionsEnabled;
Geoff Langf41a7152016-09-19 15:11:17 -0400154 bool mBindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500155 bool mClientArraysEnabled;
Jiajia Qin8a7b3a02017-08-25 16:05:48 +0800156 bool mRobustAccess;
Jamie Madill948bbe52017-06-01 13:10:42 -0400157 Optional<bool> mRobustResourceInit;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400158 EGLint mSwapInterval;
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -0700159 EGLint mSamples;
Jamie Madill222c5172017-07-19 16:15:42 -0400160 Optional<bool> mDebugLayersEnabled;
Jamie Madill293e1142017-07-11 13:51:05 -0400161 Optional<bool> mContextProgramCacheEnabled;
Jamie Madill98de8262017-05-29 13:01:02 -0400162 angle::PlatformMethods *mPlatformMethods;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400163};
164
Jamie Madill948bbe52017-06-01 13:10:42 -0400165ANGLE_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName);
166
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400167#endif // UTIL_EGLWINDOW_H_