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.
5 #ifndef UI_GL_GL_GL_API_IMPLEMENTATION_H_
6 #define UI_GL_GL_GL_API_IMPLEMENTATION_H_
10 #include "base/compiler_specific.h"
11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_export.h"
28 void InitializeStaticGLBindingsGL();
29 void InitializeDynamicGLBindingsGL(GLContext
* context
);
30 void InitializeDebugGLBindingsGL();
31 void InitializeNullDrawGLBindingsGL();
32 // TODO(danakj): Remove this when all test suites are using null-draw.
33 bool HasInitializedNullDrawGLBindingsGL();
34 bool SetNullDrawGLBindingsEnabledGL(bool enabled
);
35 void ClearGLBindingsGL();
36 void SetGLToRealGLApi();
37 void SetGLApi(GLApi
* api
);
38 void SetGLApiToNoContext();
39 const GLVersionInfo
* GetGLVersionInfo();
41 class GL_EXPORT GLApiBase
: public GLApi
{
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"
50 ~GLApiBase() override
;
51 void InitializeBase(DriverGL
* driver
);
56 // Implemenents the GL API by calling directly into the driver.
57 class GL_EXPORT RealGLApi
: public GLApiBase
{
60 ~RealGLApi() override
;
61 void Initialize(DriverGL
* driver
);
62 void InitializeWithCommandLine(DriverGL
* driver
,
63 base::CommandLine
* command_line
);
65 void InitializeWithContext();
67 void glGetIntegervFn(GLenum pname
, GLint
* params
) override
;
68 const GLubyte
* glGetStringFn(GLenum name
) override
;
69 const GLubyte
* glGetStringiFn(GLenum name
, GLuint index
) override
;
72 void InitializeFilteredExtensions();
73 void glFinishFn() override
;
74 void glFlushFn() override
;
76 // Filtered GL_EXTENSIONS we return to glGetString(i) calls.
77 std::vector
<std::string
> disabled_exts_
;
78 std::vector
<std::string
> filtered_exts_
;
79 std::string filtered_exts_str_
;
82 // Inserts a TRACE for every GL call.
83 class TraceGLApi
: public GLApi
{
85 TraceGLApi(GLApi
* gl_api
) : gl_api_(gl_api
) { }
86 ~TraceGLApi() override
;
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"
97 // Catches incorrect usage when GL calls are made without a current context.
98 class NoContextGLApi
: public GLApi
{
101 ~NoContextGLApi() override
;
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"
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.
112 class VirtualGLApi
: public GLApiBase
{
115 ~VirtualGLApi() override
;
116 void Initialize(DriverGL
* driver
, GLContext
* real_context
);
118 // Sets the current virutal context.
119 bool MakeCurrent(GLContext
* virtual_context
, GLSurface
* surface
);
121 void OnReleaseVirtuallyCurrent(GLContext
* virtual_context
);
124 // Overridden functions from GLApiBase
125 const GLubyte
* glGetStringFn(GLenum name
) override
;
126 void glFinishFn() override
;
127 void glFlushFn() override
;
129 // The real context we're running on.
130 GLContext
* real_context_
;
132 // The current virtual context.
133 GLContext
* current_context_
;
135 // The supported extensions being advertised for this virtual context.
136 std::string extensions_
;
139 class GL_EXPORT ScopedSetGLToRealGLApi
{
141 ScopedSetGLToRealGLApi();
142 ~ScopedSetGLToRealGLApi();
150 #endif // UI_GL_GL_GL_API_IMPLEMENTATION_H_