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
5#ifndef UI_GL_GL_GL_API_IMPLEMENTATION_H_
6#define UI_GL_GL_GL_API_IMPLEMENTATION_H_
7
8#include "base/compiler_specific.h"
9#include "ui/gl/gl_bindings.h"
10#include "ui/gl/gl_export.h"
11
12namespace gpu {
13namespace gles2 {
14class GLES2Decoder;
15}
16}
17namespace gfx {
18
19class GLContext;
20class GLSurface;
21struct GLVersionInfo;
22
23void InitializeStaticGLBindingsGL();
24void InitializeDynamicGLBindingsGL(GLContext* context);
25void InitializeDebugGLBindingsGL();
26void InitializeNullDrawGLBindingsGL();
27// TODO(danakj): Remove this when all test suites are using null-draw.
28bool HasInitializedNullDrawGLBindingsGL();
29bool SetNullDrawGLBindingsEnabledGL(bool enabled);
30void ClearGLBindingsGL();
31void SetGLToRealGLApi();
32void SetGLApi(GLApi* api);
33void SetGLApiToNoContext();
34const GLVersionInfo* GetGLVersionInfo();
35
36class GLApiBase : public GLApi {
37 public:
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"
42
43 protected:
44  GLApiBase();
45  virtual ~GLApiBase();
46  void InitializeBase(DriverGL* driver);
47  void SignalFlush();
48
49  DriverGL* driver_;
50};
51
52// Implemenents the GL API by calling directly into the driver.
53class RealGLApi : public GLApiBase {
54 public:
55  RealGLApi();
56  virtual ~RealGLApi();
57  void Initialize(DriverGL* driver);
58
59 private:
60  virtual void glFinishFn() OVERRIDE;
61  virtual void glFlushFn() OVERRIDE;
62};
63
64// Inserts a TRACE for every GL call.
65class TraceGLApi : public GLApi {
66 public:
67  TraceGLApi(GLApi* gl_api) : gl_api_(gl_api) { }
68  virtual ~TraceGLApi();
69
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"
74
75 private:
76  GLApi* gl_api_;
77};
78
79// Catches incorrect usage when GL calls are made without a current context.
80class NoContextGLApi : public GLApi {
81 public:
82  NoContextGLApi();
83  virtual ~NoContextGLApi();
84
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"
89};
90
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.
94class VirtualGLApi : public GLApiBase {
95 public:
96  VirtualGLApi();
97  virtual ~VirtualGLApi();
98  void Initialize(DriverGL* driver, GLContext* real_context);
99
100  // Sets the current virutal context.
101  bool MakeCurrent(GLContext* virtual_context, GLSurface* surface);
102
103  void OnReleaseVirtuallyCurrent(GLContext* virtual_context);
104
105private:
106  // Overridden functions from GLApiBase
107  virtual const GLubyte* glGetStringFn(GLenum name) OVERRIDE;
108  virtual void glFinishFn() OVERRIDE;
109  virtual void glFlushFn() OVERRIDE;
110
111  // The real context we're running on.
112  GLContext* real_context_;
113
114  // The current virtual context.
115  GLContext* current_context_;
116
117  // The supported extensions being advertised for this virtual context.
118  std::string extensions_;
119};
120
121class GL_EXPORT ScopedSetGLToRealGLApi {
122 public:
123  ScopedSetGLToRealGLApi();
124  ~ScopedSetGLToRealGLApi();
125
126 private:
127  GLApi* old_gl_api_;
128};
129
130}  // namespace gfx
131
132#endif  // UI_GL_GL_GL_API_IMPLEMENTATION_H_
133