blob: 35d040c411da216587545ae9feb323f180ee376d [file] [log] [blame]
[email protected]b97c9082012-10-25 17:21:381// 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]764c1822014-01-11 02:12:215#ifndef UI_GL_GL_GL_API_IMPLEMENTATION_H_
6#define UI_GL_GL_GL_API_IMPLEMENTATION_H_
[email protected]b97c9082012-10-25 17:21:387
dyen5a6bcfe52015-05-14 00:09:338#include <vector>
9
[email protected]b97c9082012-10-25 17:21:3810#include "base/compiler_specific.h"
11#include "ui/gl/gl_bindings.h"
ccameron18bbc2a2014-08-28 22:36:1612#include "ui/gl/gl_export.h"
[email protected]b97c9082012-10-25 17:21:3813
dyen5a6bcfe52015-05-14 00:09:3314namespace base {
15class CommandLine;
16}
[email protected]1868a342012-11-07 15:56:0217namespace gpu {
18namespace gles2 {
19class GLES2Decoder;
20}
21}
[email protected]b97c9082012-10-25 17:21:3822namespace gfx {
23
24class GLContext;
[email protected]1868a342012-11-07 15:56:0225class GLSurface;
[email protected]50f5ff62014-06-20 23:33:0426struct GLVersionInfo;
[email protected]b97c9082012-10-25 17:21:3827
[email protected]a37d7ff2014-01-17 21:31:0028void InitializeStaticGLBindingsGL();
29void InitializeDynamicGLBindingsGL(GLContext* context);
[email protected]b97c9082012-10-25 17:21:3830void InitializeDebugGLBindingsGL();
[email protected]70c908c2014-01-12 02:09:4531void InitializeNullDrawGLBindingsGL();
[email protected]ae967b02014-02-21 21:18:5832// TODO(danakj): Remove this when all test suites are using null-draw.
33bool HasInitializedNullDrawGLBindingsGL();
[email protected]2fc82a92014-02-20 22:52:0834bool SetNullDrawGLBindingsEnabledGL(bool enabled);
[email protected]b97c9082012-10-25 17:21:3835void ClearGLBindingsGL();
[email protected]1868a342012-11-07 15:56:0236void SetGLToRealGLApi();
37void SetGLApi(GLApi* api);
[email protected]95521372014-04-02 18:37:1238void SetGLApiToNoContext();
[email protected]50f5ff62014-06-20 23:33:0439const GLVersionInfo* GetGLVersionInfo();
[email protected]b97c9082012-10-25 17:21:3840
dyen5a6bcfe52015-05-14 00:09:3341class GL_EXPORT GLApiBase : public GLApi {
[email protected]b97c9082012-10-25 17:21:3842 public:
[email protected]b97c9082012-10-25 17:21:3843 // 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]95c9d112012-12-16 04:52:3648 protected:
49 GLApiBase();
dcheng08038792014-10-21 10:53:2650 ~GLApiBase() override;
[email protected]95c9d112012-12-16 04:52:3651 void InitializeBase(DriverGL* driver);
52
[email protected]b97c9082012-10-25 17:21:3853 DriverGL* driver_;
54};
55
[email protected]95c9d112012-12-16 04:52:3656// Implemenents the GL API by calling directly into the driver.
dyen5a6bcfe52015-05-14 00:09:3357class GL_EXPORT RealGLApi : public GLApiBase {
[email protected]95c9d112012-12-16 04:52:3658 public:
59 RealGLApi();
dcheng08038792014-10-21 10:53:2660 ~RealGLApi() override;
[email protected]95c9d112012-12-16 04:52:3661 void Initialize(DriverGL* driver);
dyen5a6bcfe52015-05-14 00:09:3362 void InitializeWithCommandLine(DriverGL* driver,
63 base::CommandLine* command_line);
64
dyen4db835b22015-05-18 23:03:3865 void InitializeWithContext();
66
dyen5a6bcfe52015-05-14 00:09:3367 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]f6c292f2014-04-03 14:44:5570
71 private:
dyen4db835b22015-05-18 23:03:3872 void InitializeFilteredExtensions();
dcheng08038792014-10-21 10:53:2673 void glFinishFn() override;
74 void glFlushFn() override;
dyen5a6bcfe52015-05-14 00:09:3375
76 // Filtered GL_EXTENSIONS we return to glGetString(i) calls.
dyen4db835b22015-05-18 23:03:3877 std::vector<std::string> disabled_exts_;
dyen5a6bcfe52015-05-14 00:09:3378 std::vector<std::string> filtered_exts_;
79 std::string filtered_exts_str_;
[email protected]95c9d112012-12-16 04:52:3680};
81
[email protected]b8f1d48c2013-02-07 05:21:1282// Inserts a TRACE for every GL call.
[email protected]95521372014-04-02 18:37:1283class TraceGLApi : public GLApi {
[email protected]b8f1d48c2013-02-07 05:21:1284 public:
85 TraceGLApi(GLApi* gl_api) : gl_api_(gl_api) { }
dcheng08038792014-10-21 10:53:2686 ~TraceGLApi() override;
[email protected]b8f1d48c2013-02-07 05:21:1287
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]95521372014-04-02 18:37:1297// Catches incorrect usage when GL calls are made without a current context.
98class NoContextGLApi : public GLApi {
99 public:
100 NoContextGLApi();
dcheng08038792014-10-21 10:53:26101 ~NoContextGLApi() override;
[email protected]95521372014-04-02 18:37:12102
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]1868a342012-11-07 15:56:02109// 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]95521372014-04-02 18:37:12112class VirtualGLApi : public GLApiBase {
[email protected]1868a342012-11-07 15:56:02113 public:
114 VirtualGLApi();
dcheng08038792014-10-21 10:53:26115 ~VirtualGLApi() override;
[email protected]1868a342012-11-07 15:56:02116 void Initialize(DriverGL* driver, GLContext* real_context);
117
[email protected]1868a342012-11-07 15:56:02118 // Sets the current virutal context.
119 bool MakeCurrent(GLContext* virtual_context, GLSurface* surface);
120
[email protected]063121b82013-05-31 03:48:14121 void OnReleaseVirtuallyCurrent(GLContext* virtual_context);
[email protected]b3cbad12012-12-05 19:56:36122
[email protected]f6c292f2014-04-03 14:44:55123private:
[email protected]95c9d112012-12-16 04:52:36124 // Overridden functions from GLApiBase
dcheng08038792014-10-21 10:53:26125 const GLubyte* glGetStringFn(GLenum name) override;
126 void glFinishFn() override;
127 void glFlushFn() override;
[email protected]1868a342012-11-07 15:56:02128
129 // The real context we're running on.
130 GLContext* real_context_;
131
132 // The current virtual context.
133 GLContext* current_context_;
[email protected]b3cbad12012-12-05 19:56:36134
135 // The supported extensions being advertised for this virtual context.
136 std::string extensions_;
[email protected]1868a342012-11-07 15:56:02137};
138
ccameron18bbc2a2014-08-28 22:36:16139class GL_EXPORT ScopedSetGLToRealGLApi {
140 public:
141 ScopedSetGLToRealGLApi();
142 ~ScopedSetGLToRealGLApi();
143
144 private:
145 GLApi* old_gl_api_;
146};
147
[email protected]b97c9082012-10-25 17:21:38148} // namespace gfx
149
[email protected]764c1822014-01-11 02:12:21150#endif // UI_GL_GL_GL_API_IMPLEMENTATION_H_