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 11 namespace gpu { 12 namespace gles2 { 13 class GLES2Decoder; 14 } 15 } 16 namespace gfx { 17 18 class GLContext; 19 class GLSurface; 20 struct GLVersionInfo; 21 22 void InitializeStaticGLBindingsGL(); 23 void InitializeDynamicGLBindingsGL(GLContext* context); 24 void InitializeDebugGLBindingsGL(); 25 void InitializeNullDrawGLBindingsGL(); 26 // TODO(danakj): Remove this when all test suites are using null-draw. 27 bool HasInitializedNullDrawGLBindingsGL(); 28 bool SetNullDrawGLBindingsEnabledGL(bool enabled); 29 void ClearGLBindingsGL(); 30 void SetGLToRealGLApi(); 31 void SetGLApi(GLApi* api); 32 void SetGLApiToNoContext(); 33 const GLVersionInfo* GetGLVersionInfo(); 34 35 class GLApiBase : public GLApi { 36 public: 37 // Include the auto-generated part of this class. We split this because 38 // it means we can easily edit the non-auto generated parts right here in 39 // this file instead of having to edit some template or the code generator. 40 #include "gl_bindings_api_autogen_gl.h" 41 42 protected: 43 GLApiBase(); 44 virtual ~GLApiBase(); 45 void InitializeBase(DriverGL* driver); 46 void SignalFlush(); 47 48 DriverGL* driver_; 49 }; 50 51 // Implemenents the GL API by calling directly into the driver. 52 class RealGLApi : public GLApiBase { 53 public: 54 RealGLApi(); 55 virtual ~RealGLApi(); 56 void Initialize(DriverGL* driver); 57 58 private: 59 virtual void glFinishFn() OVERRIDE; 60 virtual void glFlushFn() OVERRIDE; 61 }; 62 63 // Inserts a TRACE for every GL call. 64 class TraceGLApi : public GLApi { 65 public: TraceGLApi(GLApi * gl_api)66 TraceGLApi(GLApi* gl_api) : gl_api_(gl_api) { } 67 virtual ~TraceGLApi(); 68 69 // Include the auto-generated part of this class. We split this because 70 // it means we can easily edit the non-auto generated parts right here in 71 // this file instead of having to edit some template or the code generator. 72 #include "gl_bindings_api_autogen_gl.h" 73 74 private: 75 GLApi* gl_api_; 76 }; 77 78 // Catches incorrect usage when GL calls are made without a current context. 79 class NoContextGLApi : public GLApi { 80 public: 81 NoContextGLApi(); 82 virtual ~NoContextGLApi(); 83 84 // Include the auto-generated part of this class. We split this because 85 // it means we can easily edit the non-auto generated parts right here in 86 // this file instead of having to edit some template or the code generator. 87 #include "gl_bindings_api_autogen_gl.h" 88 }; 89 90 // Implementents the GL API using co-operative state restoring. 91 // Assumes there is only one real GL context and that multiple virtual contexts 92 // are implemented above it. Restores the needed state from the current context. 93 class VirtualGLApi : public GLApiBase { 94 public: 95 VirtualGLApi(); 96 virtual ~VirtualGLApi(); 97 void Initialize(DriverGL* driver, GLContext* real_context); 98 99 // Sets the current virutal context. 100 bool MakeCurrent(GLContext* virtual_context, GLSurface* surface); 101 102 void OnReleaseVirtuallyCurrent(GLContext* virtual_context); 103 104 private: 105 // Overridden functions from GLApiBase 106 virtual const GLubyte* glGetStringFn(GLenum name) OVERRIDE; 107 virtual void glFinishFn() OVERRIDE; 108 virtual void glFlushFn() OVERRIDE; 109 110 // The real context we're running on. 111 GLContext* real_context_; 112 113 // The current virtual context. 114 GLContext* current_context_; 115 116 // The supported extensions being advertised for this virtual context. 117 std::string extensions_; 118 }; 119 120 } // namespace gfx 121 122 #endif // UI_GL_GL_GL_API_IMPLEMENTATION_H_ 123