blob: 55de6eba091516319d57d1e184994a6987dc886a [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 Madill0448ec82016-12-23 13:41:47 -050015#include "common/Optional.h"
Jamie Madill35cd7332018-12-02 12:03:33 -050016#include "common/angleutils.h"
Jamie Madillba319ba2018-12-29 10:29:33 -050017#include "util/EGLPlatformParameters.h"
18#include "util/util_export.h"
19#include "util/util_gl.h"
Jamie Madill1cfaaf82014-08-21 10:04:04 -040020
21class OSWindow;
22
Jamie Madill98de8262017-05-29 13:01:02 -040023namespace angle
24{
Jamie Madillba319ba2018-12-29 10:29:33 -050025class Library;
Jamie Madill98de8262017-05-29 13:01:02 -040026struct PlatformMethods;
Jamie Madillba319ba2018-12-29 10:29:33 -050027} // namespace angle
Jamie Madill98de8262017-05-29 13:01:02 -040028
Jamie Madillad398ee2019-01-03 13:01:08 -050029class ANGLE_UTIL_EXPORT GLWindowBase : angle::NonCopyable
Jamie Madill1cfaaf82014-08-21 10:04:04 -040030{
31 public:
Jamie Madillad398ee2019-01-03 13:01:08 -050032 static void Delete(GLWindowBase **window);
Jamie Madill1cfaaf82014-08-21 10:04:04 -040033
Jamie Madillad398ee2019-01-03 13:01:08 -050034 // It should also be possible to set multisample and floating point framebuffers.
Jamie Madill3757a5a2014-08-26 13:16:36 -040035 void setConfigRedBits(int bits) { mRedBits = bits; }
36 void setConfigGreenBits(int bits) { mGreenBits = bits; }
37 void setConfigBlueBits(int bits) { mBlueBits = bits; }
38 void setConfigAlphaBits(int bits) { mAlphaBits = bits; }
39 void setConfigDepthBits(int bits) { mDepthBits = bits; }
40 void setConfigStencilBits(int bits) { mStencilBits = bits; }
Jamie Madillad398ee2019-01-03 13:01:08 -050041 void setSwapInterval(int swapInterval) { mSwapInterval = swapInterval; }
42
43 int getConfigRedBits() const { return mRedBits; }
44 int getConfigGreenBits() const { return mGreenBits; }
45 int getConfigBlueBits() const { return mBlueBits; }
46 int getConfigAlphaBits() const { return mAlphaBits; }
47 int getConfigDepthBits() const { return mDepthBits; }
48 int getConfigStencilBits() const { return mStencilBits; }
49 int getSwapInterval() const { return mSwapInterval; }
50 void setPlatformMethods(angle::PlatformMethods *platformMethods)
51 {
52 mPlatformMethods = platformMethods;
53 }
54 void setWebGLCompatibilityEnabled(bool webglCompatibility)
55 {
56 mWebGLCompatibility = webglCompatibility;
57 }
58 void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; }
59
60 EGLint getClientMajorVersion() const { return mClientMajorVersion; }
61 EGLint getClientMinorVersion() const { return mClientMinorVersion; }
62
Jamie Madill1f56ed22019-01-03 15:24:22 -050063 virtual bool initializeGL(OSWindow *osWindow, angle::Library *glWindowingLibrary) = 0;
64 virtual bool isGLInitialized() const = 0;
65 virtual void swap() = 0;
66 virtual void destroyGL() = 0;
67 virtual void makeCurrent() = 0;
68 virtual bool hasError() const = 0;
Jamie Madillad398ee2019-01-03 13:01:08 -050069
70 protected:
71 GLWindowBase(EGLint glesMajorVersion, EGLint glesMinorVersion);
72 virtual ~GLWindowBase();
73
74 EGLint mClientMajorVersion;
75 EGLint mClientMinorVersion;
76 int mRedBits;
77 int mGreenBits;
78 int mBlueBits;
79 int mAlphaBits;
80 int mDepthBits;
81 int mStencilBits;
82 int mSwapInterval;
83
84 angle::PlatformMethods *mPlatformMethods;
85 Optional<bool> mWebGLCompatibility;
86 Optional<bool> mRobustResourceInit;
87};
88
89class ANGLE_UTIL_EXPORT EGLWindow : public GLWindowBase
90{
91 public:
92 static EGLWindow *New(EGLint glesMajorVersion,
93 EGLint glesMinorVersion,
94 const EGLPlatformParameters &platform);
95 static void Delete(EGLWindow **window);
96
Geoff Langc5a2a172017-01-13 15:55:07 -050097 void setConfigComponentType(EGLenum componentType) { mComponentType = componentType; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040098 void setMultisample(bool multisample) { mMultisample = multisample; }
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -070099 void setSamples(EGLint samples) { mSamples = samples; }
Geoff Lang70d0f492015-12-10 17:45:46 -0500100 void setDebugEnabled(bool debug) { mDebug = debug; }
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500101 void setNoErrorEnabled(bool noError) { mNoError = noError; }
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400102 void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; }
Geoff Langf41a7152016-09-19 15:11:17 -0400103 void setBindGeneratesResource(bool bindGeneratesResource)
104 {
105 mBindGeneratesResource = bindGeneratesResource;
106 }
Jamie Madill222c5172017-07-19 16:15:42 -0400107 void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; }
Geoff Langfeb8c682017-02-13 16:07:35 -0500108 void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; }
Jiajia Qin8a7b3a02017-08-25 16:05:48 +0800109 void setRobustAccess(bool enabled) { mRobustAccess = enabled; }
Jamie Madill293e1142017-07-11 13:51:05 -0400110 void setContextProgramCacheEnabled(bool enabled) { mContextProgramCacheEnabled = enabled; }
Geoff Lang24ddc7a2018-06-11 14:56:34 -0400111 void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -0400112
Cooper Partin1bd7dd42015-06-11 08:58:53 -0700113 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
114
Jamie Madillad398ee2019-01-03 13:01:08 -0500115 void swap() override;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400116
Geoff Lang0d3683c2014-10-23 11:08:16 -0400117 const EGLPlatformParameters &getPlatform() const { return mPlatform; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400118 EGLConfig getConfig() const;
119 EGLDisplay getDisplay() const;
120 EGLSurface getSurface() const;
121 EGLContext getContext() const;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400122 bool isMultisample() const { return mMultisample; }
Geoff Lang70d0f492015-12-10 17:45:46 -0500123 bool isDebugEnabled() const { return mDebug; }
Jamie Madill98de8262017-05-29 13:01:02 -0400124 const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400125
Jamie Madille08a1d32017-03-07 17:24:06 -0500126 // Internally initializes the Display, Surface and Context.
Jamie Madillad398ee2019-01-03 13:01:08 -0500127 bool initializeGL(OSWindow *osWindow, angle::Library *glWindowingLibrary) override;
Jamie Madille08a1d32017-03-07 17:24:06 -0500128
129 // Only initializes the Display and Surface.
Jamie Madillad398ee2019-01-03 13:01:08 -0500130 bool initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *glWindowingLibrary);
Jamie Madille08a1d32017-03-07 17:24:06 -0500131
Geoff Lang3b9b0272018-04-30 16:27:24 -0400132 // Create an EGL context with this window's configuration
133 EGLContext createContext(EGLContext share) const;
134
Jamie Madille08a1d32017-03-07 17:24:06 -0500135 // Only initializes the Context.
136 bool initializeContext();
137
Jamie Madillad398ee2019-01-03 13:01:08 -0500138 void destroyGL() override;
139 bool isGLInitialized() const override;
140 void makeCurrent() override;
Jamie Madill1f56ed22019-01-03 15:24:22 -0500141 bool hasError() const override;
Jamie Madillfe548342017-06-19 11:13:24 -0400142
Jamie Madill948bbe52017-06-01 13:10:42 -0400143 static bool ClientExtensionEnabled(const std::string &extName);
144
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400145 private:
Jamie Madillad398ee2019-01-03 13:01:08 -0500146 EGLWindow(EGLint glesMajorVersion,
147 EGLint glesMinorVersion,
148 const EGLPlatformParameters &platform);
149
150 ~EGLWindow() override;
151
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400152 EGLConfig mConfig;
153 EGLDisplay mDisplay;
154 EGLSurface mSurface;
155 EGLContext mContext;
156
Jamie Madille08a1d32017-03-07 17:24:06 -0500157 EGLint mEGLMajorVersion;
158 EGLint mEGLMinorVersion;
Geoff Lang0d3683c2014-10-23 11:08:16 -0400159 EGLPlatformParameters mPlatform;
Geoff Langc5a2a172017-01-13 15:55:07 -0500160 EGLenum mComponentType;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400161 bool mMultisample;
Geoff Lang70d0f492015-12-10 17:45:46 -0500162 bool mDebug;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500163 bool mNoError;
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400164 Optional<bool> mExtensionsEnabled;
Geoff Langf41a7152016-09-19 15:11:17 -0400165 bool mBindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500166 bool mClientArraysEnabled;
Jiajia Qin8a7b3a02017-08-25 16:05:48 +0800167 bool mRobustAccess;
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -0700168 EGLint mSamples;
Jamie Madill222c5172017-07-19 16:15:42 -0400169 Optional<bool> mDebugLayersEnabled;
Jamie Madill293e1142017-07-11 13:51:05 -0400170 Optional<bool> mContextProgramCacheEnabled;
Geoff Lang24ddc7a2018-06-11 14:56:34 -0400171 Optional<bool> mContextVirtualization;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400172};
173
Jamie Madillba319ba2018-12-29 10:29:33 -0500174ANGLE_UTIL_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName);
Jamie Madill948bbe52017-06-01 13:10:42 -0400175
Jamie Madill35cd7332018-12-02 12:03:33 -0500176#endif // UTIL_EGLWINDOW_H_