blob: 555c8c8e5e4c8766d58ba5ff041c38b2d24066a4 [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 Madillba319ba2018-12-29 10:29:33 -050029class ANGLE_UTIL_EXPORT EGLWindow : angle::NonCopyable
Jamie Madill1cfaaf82014-08-21 10:04:04 -040030{
31 public:
Geoff Lang5ade8452015-09-02 11:00:30 -040032 EGLWindow(EGLint glesMajorVersion,
33 EGLint glesMinorVersion,
34 const EGLPlatformParameters &platform);
Jamie Madill1cfaaf82014-08-21 10:04:04 -040035
36 ~EGLWindow();
37
Jamie Madill3757a5a2014-08-26 13:16:36 -040038 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 Langc5a2a172017-01-13 15:55:07 -050044 void setConfigComponentType(EGLenum componentType) { mComponentType = componentType; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040045 void setMultisample(bool multisample) { mMultisample = multisample; }
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -070046 void setSamples(EGLint samples) { mSamples = samples; }
Geoff Lang70d0f492015-12-10 17:45:46 -050047 void setDebugEnabled(bool debug) { mDebug = debug; }
Jamie Madill60ec6ea2016-01-22 15:27:19 -050048 void setNoErrorEnabled(bool noError) { mNoError = noError; }
Geoff Langc287ea62016-09-16 14:46:51 -040049 void setWebGLCompatibilityEnabled(bool webglCompatibility)
50 {
51 mWebGLCompatibility = webglCompatibility;
52 }
Geoff Lang0ab41fa2018-03-14 11:03:30 -040053 void setExtensionsEnabled(bool extensionsEnabled) { mExtensionsEnabled = extensionsEnabled; }
Geoff Langf41a7152016-09-19 15:11:17 -040054 void setBindGeneratesResource(bool bindGeneratesResource)
55 {
56 mBindGeneratesResource = bindGeneratesResource;
57 }
Jamie Madill222c5172017-07-19 16:15:42 -040058 void setDebugLayersEnabled(bool enabled) { mDebugLayersEnabled = enabled; }
Geoff Langfeb8c682017-02-13 16:07:35 -050059 void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; }
Jiajia Qin8a7b3a02017-08-25 16:05:48 +080060 void setRobustAccess(bool enabled) { mRobustAccess = enabled; }
Jamie Madille08a1d32017-03-07 17:24:06 -050061 void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040062 void setSwapInterval(EGLint swapInterval) { mSwapInterval = swapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -040063 void setPlatformMethods(angle::PlatformMethods *platformMethods)
64 {
65 mPlatformMethods = platformMethods;
66 }
Jamie Madill293e1142017-07-11 13:51:05 -040067 void setContextProgramCacheEnabled(bool enabled) { mContextProgramCacheEnabled = enabled; }
Geoff Lang24ddc7a2018-06-11 14:56:34 -040068 void setContextVirtualization(bool enabled) { mContextVirtualization = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040069
Cooper Partin1bd7dd42015-06-11 08:58:53 -070070 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
71
Jamie Madill1cfaaf82014-08-21 10:04:04 -040072 void swap();
73
Geoff Lang5ade8452015-09-02 11:00:30 -040074 EGLint getClientMajorVersion() const { return mClientMajorVersion; }
75 EGLint getClientMinorVersion() const { return mClientMinorVersion; }
Geoff Lang0d3683c2014-10-23 11:08:16 -040076 const EGLPlatformParameters &getPlatform() const { return mPlatform; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -040077 EGLConfig getConfig() const;
78 EGLDisplay getDisplay() const;
79 EGLSurface getSurface() const;
80 EGLContext getContext() const;
Jamie Madill3757a5a2014-08-26 13:16:36 -040081 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 Lang70d0f492015-12-10 17:45:46 -050088 bool isDebugEnabled() const { return mDebug; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040089 EGLint getSwapInterval() const { return mSwapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -040090 const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -040091
Jamie Madille08a1d32017-03-07 17:24:06 -050092 // Internally initializes the Display, Surface and Context.
Jamie Madillba319ba2018-12-29 10:29:33 -050093 bool initializeGL(OSWindow *osWindow, angle::Library *eglLibrary);
Jamie Madille08a1d32017-03-07 17:24:06 -050094
95 // Only initializes the Display and Surface.
Jamie Madillba319ba2018-12-29 10:29:33 -050096 bool initializeDisplayAndSurface(OSWindow *osWindow, angle::Library *eglLibrary);
Jamie Madille08a1d32017-03-07 17:24:06 -050097
Geoff Lang3b9b0272018-04-30 16:27:24 -040098 // Create an EGL context with this window's configuration
99 EGLContext createContext(EGLContext share) const;
100
Jamie Madille08a1d32017-03-07 17:24:06 -0500101 // Only initializes the Context.
102 bool initializeContext();
103
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400104 void destroyGL();
Jamie Madill77a72f62015-04-14 11:18:32 -0400105 bool isGLInitialized() const;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400106
Jamie Madillfe548342017-06-19 11:13:24 -0400107 void makeCurrent();
108
Jamie Madill948bbe52017-06-01 13:10:42 -0400109 static bool ClientExtensionEnabled(const std::string &extName);
110
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400111 private:
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400112 EGLConfig mConfig;
113 EGLDisplay mDisplay;
114 EGLSurface mSurface;
115 EGLContext mContext;
116
Geoff Lang5ade8452015-09-02 11:00:30 -0400117 EGLint mClientMajorVersion;
118 EGLint mClientMinorVersion;
Jamie Madille08a1d32017-03-07 17:24:06 -0500119 EGLint mEGLMajorVersion;
120 EGLint mEGLMinorVersion;
Geoff Lang0d3683c2014-10-23 11:08:16 -0400121 EGLPlatformParameters mPlatform;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400122 int mRedBits;
123 int mGreenBits;
124 int mBlueBits;
125 int mAlphaBits;
126 int mDepthBits;
127 int mStencilBits;
Geoff Langc5a2a172017-01-13 15:55:07 -0500128 EGLenum mComponentType;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400129 bool mMultisample;
Geoff Lang70d0f492015-12-10 17:45:46 -0500130 bool mDebug;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500131 bool mNoError;
Geoff Langc287ea62016-09-16 14:46:51 -0400132 bool mWebGLCompatibility;
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400133 Optional<bool> mExtensionsEnabled;
Geoff Langf41a7152016-09-19 15:11:17 -0400134 bool mBindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500135 bool mClientArraysEnabled;
Jiajia Qin8a7b3a02017-08-25 16:05:48 +0800136 bool mRobustAccess;
Jamie Madill948bbe52017-06-01 13:10:42 -0400137 Optional<bool> mRobustResourceInit;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400138 EGLint mSwapInterval;
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -0700139 EGLint mSamples;
Jamie Madill222c5172017-07-19 16:15:42 -0400140 Optional<bool> mDebugLayersEnabled;
Jamie Madill293e1142017-07-11 13:51:05 -0400141 Optional<bool> mContextProgramCacheEnabled;
Geoff Lang24ddc7a2018-06-11 14:56:34 -0400142 Optional<bool> mContextVirtualization;
Jamie Madill98de8262017-05-29 13:01:02 -0400143 angle::PlatformMethods *mPlatformMethods;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400144};
145
Jamie Madillba319ba2018-12-29 10:29:33 -0500146ANGLE_UTIL_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName);
Jamie Madill948bbe52017-06-01 13:10:42 -0400147
Jamie Madill35cd7332018-12-02 12:03:33 -0500148#endif // UTIL_EGLWINDOW_H_