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_
8 #include "base/compiler_specific.h"
9 #include "ui/gl/gl_bindings.h"
10 #include "ui/gl/gl_export.h"
23 void InitializeStaticGLBindingsGL();
24 void InitializeDynamicGLBindingsGL(GLContext
* context
);
25 void InitializeDebugGLBindingsGL();
26 void InitializeNullDrawGLBindingsGL();
27 // TODO(danakj): Remove this when all test suites are using null-draw.
28 bool HasInitializedNullDrawGLBindingsGL();
29 bool SetNullDrawGLBindingsEnabledGL(bool enabled
);
30 void ClearGLBindingsGL();
31 void SetGLToRealGLApi();
32 void SetGLApi(GLApi
* api
);
33 void SetGLApiToNoContext();
34 const GLVersionInfo
* GetGLVersionInfo();
36 class GLApiBase
: public GLApi
{
38 // Include the auto-generated part of this class. We split this because
39 // it means we can easily edit the non-auto generated parts right here in
40 // this file instead of having to edit some template or the code generator.
41 #include "gl_bindings_api_autogen_gl.h"
45 ~GLApiBase() override
;
46 void InitializeBase(DriverGL
* driver
);
52 // Implemenents the GL API by calling directly into the driver.
53 class RealGLApi
: public GLApiBase
{
56 ~RealGLApi() override
;
57 void Initialize(DriverGL
* driver
);
60 void glFinishFn() override
;
61 void glFlushFn() override
;
64 // Inserts a TRACE for every GL call.
65 class TraceGLApi
: public GLApi
{
67 TraceGLApi(GLApi
* gl_api
) : gl_api_(gl_api
) { }
68 ~TraceGLApi() override
;
70 // Include the auto-generated part of this class. We split this because
71 // it means we can easily edit the non-auto generated parts right here in
72 // this file instead of having to edit some template or the code generator.
73 #include "gl_bindings_api_autogen_gl.h"
79 // Catches incorrect usage when GL calls are made without a current context.
80 class NoContextGLApi
: public GLApi
{
83 ~NoContextGLApi() override
;
85 // Include the auto-generated part of this class. We split this because
86 // it means we can easily edit the non-auto generated parts right here in
87 // this file instead of having to edit some template or the code generator.
88 #include "gl_bindings_api_autogen_gl.h"
91 // Implementents the GL API using co-operative state restoring.
92 // Assumes there is only one real GL context and that multiple virtual contexts
93 // are implemented above it. Restores the needed state from the current context.
94 class VirtualGLApi
: public GLApiBase
{
97 ~VirtualGLApi() override
;
98 void Initialize(DriverGL
* driver
, GLContext
* real_context
);
100 // Sets the current virutal context.
101 bool MakeCurrent(GLContext
* virtual_context
, GLSurface
* surface
);
103 void OnReleaseVirtuallyCurrent(GLContext
* virtual_context
);
106 // Overridden functions from GLApiBase
107 const GLubyte
* glGetStringFn(GLenum name
) override
;
108 void glFinishFn() override
;
109 void glFlushFn() override
;
111 // The real context we're running on.
112 GLContext
* real_context_
;
114 // The current virtual context.
115 GLContext
* current_context_
;
117 // The supported extensions being advertised for this virtual context.
118 std::string extensions_
;
121 class GL_EXPORT ScopedSetGLToRealGLApi
{
123 ScopedSetGLToRealGLApi();
124 ~ScopedSetGLToRealGLApi();
132 #endif // UI_GL_GL_GL_API_IMPLEMENTATION_H_