[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 764c182 | 2014-01-11 02:12:21 | [diff] [blame] | 5 | #ifndef UI_GL_GL_GL_API_IMPLEMENTATION_H_ |
6 | #define UI_GL_GL_GL_API_IMPLEMENTATION_H_ | ||||
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 7 | |
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 8 | #include <vector> |
9 | |||||
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
11 | #include "ui/gl/gl_bindings.h" | ||||
ccameron | 18bbc2a | 2014-08-28 22:36:16 | [diff] [blame] | 12 | #include "ui/gl/gl_export.h" |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 13 | |
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 14 | namespace base { |
15 | class CommandLine; | ||||
16 | } | ||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 17 | namespace gpu { |
18 | namespace gles2 { | ||||
19 | class GLES2Decoder; | ||||
20 | } | ||||
21 | } | ||||
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 22 | namespace gfx { |
23 | |||||
24 | class GLContext; | ||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 25 | class GLSurface; |
[email protected] | 50f5ff6 | 2014-06-20 23:33:04 | [diff] [blame] | 26 | struct GLVersionInfo; |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 27 | |
[email protected] | a37d7ff | 2014-01-17 21:31:00 | [diff] [blame] | 28 | void InitializeStaticGLBindingsGL(); |
29 | void InitializeDynamicGLBindingsGL(GLContext* context); | ||||
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 30 | void InitializeDebugGLBindingsGL(); |
[email protected] | 70c908c | 2014-01-12 02:09:45 | [diff] [blame] | 31 | void InitializeNullDrawGLBindingsGL(); |
[email protected] | ae967b0 | 2014-02-21 21:18:58 | [diff] [blame] | 32 | // TODO(danakj): Remove this when all test suites are using null-draw. |
33 | bool HasInitializedNullDrawGLBindingsGL(); | ||||
[email protected] | 2fc82a9 | 2014-02-20 22:52:08 | [diff] [blame] | 34 | bool SetNullDrawGLBindingsEnabledGL(bool enabled); |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 35 | void ClearGLBindingsGL(); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 36 | void SetGLToRealGLApi(); |
37 | void SetGLApi(GLApi* api); | ||||
[email protected] | 9552137 | 2014-04-02 18:37:12 | [diff] [blame] | 38 | void SetGLApiToNoContext(); |
[email protected] | 50f5ff6 | 2014-06-20 23:33:04 | [diff] [blame] | 39 | const GLVersionInfo* GetGLVersionInfo(); |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 40 | |
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 41 | class GL_EXPORT GLApiBase : public GLApi { |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 42 | public: |
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 43 | // Include the auto-generated part of this class. We split this because |
44 | // it means we can easily edit the non-auto generated parts right here in | ||||
45 | // this file instead of having to edit some template or the code generator. | ||||
46 | #include "gl_bindings_api_autogen_gl.h" | ||||
47 | |||||
[email protected] | 95c9d11 | 2012-12-16 04:52:36 | [diff] [blame] | 48 | protected: |
49 | GLApiBase(); | ||||
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 50 | ~GLApiBase() override; |
[email protected] | 95c9d11 | 2012-12-16 04:52:36 | [diff] [blame] | 51 | void InitializeBase(DriverGL* driver); |
52 | |||||
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 53 | DriverGL* driver_; |
54 | }; | ||||
55 | |||||
[email protected] | 95c9d11 | 2012-12-16 04:52:36 | [diff] [blame] | 56 | // Implemenents the GL API by calling directly into the driver. |
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 57 | class GL_EXPORT RealGLApi : public GLApiBase { |
[email protected] | 95c9d11 | 2012-12-16 04:52:36 | [diff] [blame] | 58 | public: |
59 | RealGLApi(); | ||||
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 60 | ~RealGLApi() override; |
[email protected] | 95c9d11 | 2012-12-16 04:52:36 | [diff] [blame] | 61 | void Initialize(DriverGL* driver); |
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 62 | void InitializeWithCommandLine(DriverGL* driver, |
63 | base::CommandLine* command_line); | ||||
64 | |||||
dyen | 4db835b2 | 2015-05-18 23:03:38 | [diff] [blame] | 65 | void InitializeWithContext(); |
66 | |||||
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 67 | void glGetIntegervFn(GLenum pname, GLint* params) override; |
68 | const GLubyte* glGetStringFn(GLenum name) override; | ||||
69 | const GLubyte* glGetStringiFn(GLenum name, GLuint index) override; | ||||
[email protected] | f6c292f | 2014-04-03 14:44:55 | [diff] [blame] | 70 | |
71 | private: | ||||
dyen | 4db835b2 | 2015-05-18 23:03:38 | [diff] [blame] | 72 | void InitializeFilteredExtensions(); |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 73 | void glFinishFn() override; |
74 | void glFlushFn() override; | ||||
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 75 | |
76 | // Filtered GL_EXTENSIONS we return to glGetString(i) calls. | ||||
dyen | 4db835b2 | 2015-05-18 23:03:38 | [diff] [blame] | 77 | std::vector<std::string> disabled_exts_; |
dyen | 5a6bcfe5 | 2015-05-14 00:09:33 | [diff] [blame] | 78 | std::vector<std::string> filtered_exts_; |
79 | std::string filtered_exts_str_; | ||||
[email protected] | 95c9d11 | 2012-12-16 04:52:36 | [diff] [blame] | 80 | }; |
81 | |||||
[email protected] | b8f1d48c | 2013-02-07 05:21:12 | [diff] [blame] | 82 | // Inserts a TRACE for every GL call. |
[email protected] | 9552137 | 2014-04-02 18:37:12 | [diff] [blame] | 83 | class TraceGLApi : public GLApi { |
[email protected] | b8f1d48c | 2013-02-07 05:21:12 | [diff] [blame] | 84 | public: |
85 | TraceGLApi(GLApi* gl_api) : gl_api_(gl_api) { } | ||||
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 86 | ~TraceGLApi() override; |
[email protected] | b8f1d48c | 2013-02-07 05:21:12 | [diff] [blame] | 87 | |
88 | // Include the auto-generated part of this class. We split this because | ||||
89 | // it means we can easily edit the non-auto generated parts right here in | ||||
90 | // this file instead of having to edit some template or the code generator. | ||||
91 | #include "gl_bindings_api_autogen_gl.h" | ||||
92 | |||||
93 | private: | ||||
94 | GLApi* gl_api_; | ||||
95 | }; | ||||
96 | |||||
[email protected] | 9552137 | 2014-04-02 18:37:12 | [diff] [blame] | 97 | // Catches incorrect usage when GL calls are made without a current context. |
98 | class NoContextGLApi : public GLApi { | ||||
99 | public: | ||||
100 | NoContextGLApi(); | ||||
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 101 | ~NoContextGLApi() override; |
[email protected] | 9552137 | 2014-04-02 18:37:12 | [diff] [blame] | 102 | |
103 | // Include the auto-generated part of this class. We split this because | ||||
104 | // it means we can easily edit the non-auto generated parts right here in | ||||
105 | // this file instead of having to edit some template or the code generator. | ||||
106 | #include "gl_bindings_api_autogen_gl.h" | ||||
107 | }; | ||||
108 | |||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 109 | // Implementents the GL API using co-operative state restoring. |
110 | // Assumes there is only one real GL context and that multiple virtual contexts | ||||
111 | // are implemented above it. Restores the needed state from the current context. | ||||
[email protected] | 9552137 | 2014-04-02 18:37:12 | [diff] [blame] | 112 | class VirtualGLApi : public GLApiBase { |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 113 | public: |
114 | VirtualGLApi(); | ||||
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 115 | ~VirtualGLApi() override; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 116 | void Initialize(DriverGL* driver, GLContext* real_context); |
117 | |||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 118 | // Sets the current virutal context. |
119 | bool MakeCurrent(GLContext* virtual_context, GLSurface* surface); | ||||
120 | |||||
[email protected] | 063121b8 | 2013-05-31 03:48:14 | [diff] [blame] | 121 | void OnReleaseVirtuallyCurrent(GLContext* virtual_context); |
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 122 | |
[email protected] | f6c292f | 2014-04-03 14:44:55 | [diff] [blame] | 123 | private: |
[email protected] | 95c9d11 | 2012-12-16 04:52:36 | [diff] [blame] | 124 | // Overridden functions from GLApiBase |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 125 | const GLubyte* glGetStringFn(GLenum name) override; |
126 | void glFinishFn() override; | ||||
127 | void glFlushFn() override; | ||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 128 | |
129 | // The real context we're running on. | ||||
130 | GLContext* real_context_; | ||||
131 | |||||
132 | // The current virtual context. | ||||
133 | GLContext* current_context_; | ||||
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 134 | |
135 | // The supported extensions being advertised for this virtual context. | ||||
136 | std::string extensions_; | ||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 137 | }; |
138 | |||||
ccameron | 18bbc2a | 2014-08-28 22:36:16 | [diff] [blame] | 139 | class GL_EXPORT ScopedSetGLToRealGLApi { |
140 | public: | ||||
141 | ScopedSetGLToRealGLApi(); | ||||
142 | ~ScopedSetGLToRealGLApi(); | ||||
143 | |||||
144 | private: | ||||
145 | GLApi* old_gl_api_; | ||||
146 | }; | ||||
147 | |||||
[email protected] | b97c908 | 2012-10-25 17:21:38 | [diff] [blame] | 148 | } // namespace gfx |
149 | |||||
[email protected] | 764c182 | 2014-01-11 02:12:21 | [diff] [blame] | 150 | #endif // UI_GL_GL_GL_API_IMPLEMENTATION_H_ |