blob: 02980f5ce0859a28c4f796b7ce412f157ac35ce1 [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 Madill19a43db2015-03-20 16:14:04 -040027// A hidden define used in some renderers (currently D3D-only)
28// to init a no-op renderer. Useful for performance testing.
29#ifndef EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE
30#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE 0x6AC0
31#endif
32
Jamie Madill98de8262017-05-29 13:01:02 -040033namespace angle
34{
35struct PlatformMethods;
36}
37
Yuly Novikove3352f92016-08-12 20:40:14 -040038struct ANGLE_EXPORT EGLPlatformParameters
Geoff Lang0d3683c2014-10-23 11:08:16 -040039{
40 EGLint renderer;
41 EGLint majorVersion;
42 EGLint minorVersion;
Geoff Lang7825f612014-11-26 16:19:41 -050043 EGLint deviceType;
Austin Kinross2a63b3f2016-02-08 12:29:08 -080044 EGLint presentPath;
Geoff Lang0d3683c2014-10-23 11:08:16 -040045
46 EGLPlatformParameters();
47 explicit EGLPlatformParameters(EGLint renderer);
Geoff Lang7825f612014-11-26 16:19:41 -050048 EGLPlatformParameters(EGLint renderer, EGLint majorVersion, EGLint minorVersion, EGLint deviceType);
Austin Kinross2a63b3f2016-02-08 12:29:08 -080049 EGLPlatformParameters(EGLint renderer,
50 EGLint majorVersion,
51 EGLint minorVersion,
52 EGLint deviceType,
53 EGLint presentPath);
Geoff Lang0d3683c2014-10-23 11:08:16 -040054};
55
Yuly Novikove3352f92016-08-12 20:40:14 -040056ANGLE_EXPORT bool operator<(const EGLPlatformParameters &a, const EGLPlatformParameters &b);
57ANGLE_EXPORT bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b);
Geoff Langdd323e92015-06-09 15:16:31 -040058
Yuly Novikove3352f92016-08-12 20:40:14 -040059class ANGLE_EXPORT EGLWindow : angle::NonCopyable
Jamie Madill1cfaaf82014-08-21 10:04:04 -040060{
61 public:
Geoff Lang5ade8452015-09-02 11:00:30 -040062 EGLWindow(EGLint glesMajorVersion,
63 EGLint glesMinorVersion,
64 const EGLPlatformParameters &platform);
Jamie Madill1cfaaf82014-08-21 10:04:04 -040065
66 ~EGLWindow();
67
Jamie Madill3757a5a2014-08-26 13:16:36 -040068 void setConfigRedBits(int bits) { mRedBits = bits; }
69 void setConfigGreenBits(int bits) { mGreenBits = bits; }
70 void setConfigBlueBits(int bits) { mBlueBits = bits; }
71 void setConfigAlphaBits(int bits) { mAlphaBits = bits; }
72 void setConfigDepthBits(int bits) { mDepthBits = bits; }
73 void setConfigStencilBits(int bits) { mStencilBits = bits; }
Geoff Langc5a2a172017-01-13 15:55:07 -050074 void setConfigComponentType(EGLenum componentType) { mComponentType = componentType; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040075 void setMultisample(bool multisample) { mMultisample = multisample; }
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -070076 void setSamples(EGLint samples) { mSamples = samples; }
Geoff Lang70d0f492015-12-10 17:45:46 -050077 void setDebugEnabled(bool debug) { mDebug = debug; }
Jamie Madill60ec6ea2016-01-22 15:27:19 -050078 void setNoErrorEnabled(bool noError) { mNoError = noError; }
Geoff Langc287ea62016-09-16 14:46:51 -040079 void setWebGLCompatibilityEnabled(bool webglCompatibility)
80 {
81 mWebGLCompatibility = webglCompatibility;
82 }
Geoff Langf41a7152016-09-19 15:11:17 -040083 void setBindGeneratesResource(bool bindGeneratesResource)
84 {
85 mBindGeneratesResource = bindGeneratesResource;
86 }
Jamie Madill0448ec82016-12-23 13:41:47 -050087 void setVulkanLayersEnabled(bool enabled) { mVulkanLayersEnabled = enabled; }
Geoff Langfeb8c682017-02-13 16:07:35 -050088 void setClientArraysEnabled(bool enabled) { mClientArraysEnabled = enabled; }
Jamie Madille08a1d32017-03-07 17:24:06 -050089 void setRobustResourceInit(bool enabled) { mRobustResourceInit = enabled; }
Jamie Madill3757a5a2014-08-26 13:16:36 -040090 void setSwapInterval(EGLint swapInterval) { mSwapInterval = swapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -040091 void setPlatformMethods(angle::PlatformMethods *platformMethods)
92 {
93 mPlatformMethods = platformMethods;
94 }
Jamie Madill3757a5a2014-08-26 13:16:36 -040095
Cooper Partin1bd7dd42015-06-11 08:58:53 -070096 static EGLBoolean FindEGLConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *config);
97
Jamie Madill1cfaaf82014-08-21 10:04:04 -040098 void swap();
99
Geoff Lang5ade8452015-09-02 11:00:30 -0400100 EGLint getClientMajorVersion() const { return mClientMajorVersion; }
101 EGLint getClientMinorVersion() const { return mClientMinorVersion; }
Geoff Lang0d3683c2014-10-23 11:08:16 -0400102 const EGLPlatformParameters &getPlatform() const { return mPlatform; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400103 EGLConfig getConfig() const;
104 EGLDisplay getDisplay() const;
105 EGLSurface getSurface() const;
106 EGLContext getContext() const;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400107 int getConfigRedBits() const { return mRedBits; }
108 int getConfigGreenBits() const { return mGreenBits; }
109 int getConfigBlueBits() const { return mBlueBits; }
110 int getConfigAlphaBits() const { return mAlphaBits; }
111 int getConfigDepthBits() const { return mDepthBits; }
112 int getConfigStencilBits() const { return mStencilBits; }
113 bool isMultisample() const { return mMultisample; }
Geoff Lang70d0f492015-12-10 17:45:46 -0500114 bool isDebugEnabled() const { return mDebug; }
Jamie Madill3757a5a2014-08-26 13:16:36 -0400115 EGLint getSwapInterval() const { return mSwapInterval; }
Jamie Madill98de8262017-05-29 13:01:02 -0400116 const angle::PlatformMethods *getPlatformMethods() const { return mPlatformMethods; }
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400117
Jamie Madille08a1d32017-03-07 17:24:06 -0500118 // Internally initializes the Display, Surface and Context.
Austin Kinross18b931d2014-09-29 12:58:31 -0700119 bool initializeGL(OSWindow *osWindow);
Jamie Madille08a1d32017-03-07 17:24:06 -0500120
121 // Only initializes the Display and Surface.
122 bool initializeDisplayAndSurface(OSWindow *osWindow);
123
124 // Only initializes the Context.
125 bool initializeContext();
126
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400127 void destroyGL();
Jamie Madill77a72f62015-04-14 11:18:32 -0400128 bool isGLInitialized() const;
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400129
Jamie Madillfe548342017-06-19 11:13:24 -0400130 void makeCurrent();
131
Jamie Madill948bbe52017-06-01 13:10:42 -0400132 static bool ClientExtensionEnabled(const std::string &extName);
133
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400134 private:
Jamie Madill1cfaaf82014-08-21 10:04:04 -0400135 EGLConfig mConfig;
136 EGLDisplay mDisplay;
137 EGLSurface mSurface;
138 EGLContext mContext;
139
Geoff Lang5ade8452015-09-02 11:00:30 -0400140 EGLint mClientMajorVersion;
141 EGLint mClientMinorVersion;
Jamie Madille08a1d32017-03-07 17:24:06 -0500142 EGLint mEGLMajorVersion;
143 EGLint mEGLMinorVersion;
Geoff Lang0d3683c2014-10-23 11:08:16 -0400144 EGLPlatformParameters mPlatform;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400145 int mRedBits;
146 int mGreenBits;
147 int mBlueBits;
148 int mAlphaBits;
149 int mDepthBits;
150 int mStencilBits;
Geoff Langc5a2a172017-01-13 15:55:07 -0500151 EGLenum mComponentType;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400152 bool mMultisample;
Geoff Lang70d0f492015-12-10 17:45:46 -0500153 bool mDebug;
Jamie Madill60ec6ea2016-01-22 15:27:19 -0500154 bool mNoError;
Geoff Langc287ea62016-09-16 14:46:51 -0400155 bool mWebGLCompatibility;
Geoff Langf41a7152016-09-19 15:11:17 -0400156 bool mBindGeneratesResource;
Geoff Langfeb8c682017-02-13 16:07:35 -0500157 bool mClientArraysEnabled;
Jamie Madill948bbe52017-06-01 13:10:42 -0400158 Optional<bool> mRobustResourceInit;
Jamie Madill3757a5a2014-08-26 13:16:36 -0400159 EGLint mSwapInterval;
Bryan Bernhart (Intel Americas Inc)151d5de2017-04-13 09:52:23 -0700160 EGLint mSamples;
Jamie Madill0448ec82016-12-23 13:41:47 -0500161 Optional<bool> mVulkanLayersEnabled;
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_