| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GL_GL_CONTEXT_H_ | 5 #ifndef UI_GL_GL_CONTEXT_H_ |
| 6 #define UI_GL_GL_CONTEXT_H_ | 6 #define UI_GL_GL_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 9 | 10 |
| 11 #include "base/atomicops.h" |
| 10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "ui/gl/gl_share_group.h" | 15 #include "ui/gl/gl_share_group.h" |
| 14 #include "ui/gl/gl_state_restorer.h" | 16 #include "ui/gl/gl_state_restorer.h" |
| 15 #include "ui/gl/gpu_preference.h" | 17 #include "ui/gl/gpu_preference.h" |
| 16 | 18 |
| 17 namespace gfx { | 19 namespace gfx { |
| 18 | 20 |
| 19 class GLSurface; | 21 class GLSurface; |
| 20 class VirtualGLApi; | 22 class VirtualGLApi; |
| 21 struct GLVersionInfo; | 23 struct GLVersionInfo; |
| 22 | 24 |
| 23 // Encapsulates an OpenGL context, hiding platform specific management. | 25 // Encapsulates an OpenGL context, hiding platform specific management. |
| 24 class GL_EXPORT GLContext : public base::RefCounted<GLContext> { | 26 class GL_EXPORT GLContext : public base::RefCounted<GLContext> { |
| 25 public: | 27 public: |
| 26 explicit GLContext(GLShareGroup* share_group); | 28 explicit GLContext(GLShareGroup* share_group); |
| 27 | 29 |
| 28 // Initializes the GL context to be compatible with the given surface. The GL | 30 // Initializes the GL context to be compatible with the given surface. The GL |
| 29 // context can be made with other surface's of the same type. The compatible | 31 // context can be made with other surface's of the same type. The compatible |
| 30 // surface is only needed for certain platforms like WGL, OSMesa and GLX. It | 32 // surface is only needed for certain platforms like WGL, OSMesa and GLX. It |
| 31 // should be specific for all platforms though. | 33 // should be specific for all platforms though. |
| 32 virtual bool Initialize( | 34 virtual bool Initialize( |
| 33 GLSurface* compatible_surface, GpuPreference gpu_preference) = 0; | 35 GLSurface* compatible_surface, GpuPreference gpu_preference) = 0; |
| 34 | 36 |
| 37 class FlushEvent : public base::RefCountedThreadSafe<FlushEvent> { |
| 38 public: |
| 39 bool IsSignaled(); |
| 40 |
| 41 private: |
| 42 friend class base::RefCountedThreadSafe<FlushEvent>; |
| 43 friend class GLContext; |
| 44 FlushEvent(); |
| 45 virtual ~FlushEvent(); |
| 46 void Signal(); |
| 47 |
| 48 base::subtle::Atomic32 state_; |
| 49 }; |
| 50 |
| 51 scoped_refptr<FlushEvent> SignalFlush(); |
| 52 |
| 35 // Destroys the GL context. | 53 // Destroys the GL context. |
| 36 virtual void Destroy() = 0; | 54 virtual void Destroy() = 0; |
| 37 | 55 |
| 38 // Makes the GL context and a surface current on the current thread. | 56 // Makes the GL context and a surface current on the current thread. |
| 39 virtual bool MakeCurrent(GLSurface* surface) = 0; | 57 virtual bool MakeCurrent(GLSurface* surface) = 0; |
| 40 | 58 |
| 41 // Releases this GL context and surface as current on the current thread. | 59 // Releases this GL context and surface as current on the current thread. |
| 42 virtual void ReleaseCurrent(GLSurface* surface) = 0; | 60 virtual void ReleaseCurrent(GLSurface* surface) = 0; |
| 43 | 61 |
| 44 // Returns true if this context and surface is current. Pass a null surface | 62 // Returns true if this context and surface is current. Pass a null surface |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // Notify this context that |virtual_context|, that was using us, is | 125 // Notify this context that |virtual_context|, that was using us, is |
| 108 // being released or destroyed. | 126 // being released or destroyed. |
| 109 void OnReleaseVirtuallyCurrent(GLContext* virtual_context); | 127 void OnReleaseVirtuallyCurrent(GLContext* virtual_context); |
| 110 | 128 |
| 111 // Returns the GL version string. The context must be current. | 129 // Returns the GL version string. The context must be current. |
| 112 virtual std::string GetGLVersion(); | 130 virtual std::string GetGLVersion(); |
| 113 | 131 |
| 114 // Returns the GL renderer string. The context must be current. | 132 // Returns the GL renderer string. The context must be current. |
| 115 virtual std::string GetGLRenderer(); | 133 virtual std::string GetGLRenderer(); |
| 116 | 134 |
| 135 // Called when glFlush()/glFinish() is called with this context current. |
| 136 void OnFlush(); |
| 137 |
| 117 protected: | 138 protected: |
| 118 virtual ~GLContext(); | 139 virtual ~GLContext(); |
| 119 | 140 |
| 120 // Sets the GL api to the real hardware API (vs the VirtualAPI) | 141 // Sets the GL api to the real hardware API (vs the VirtualAPI) |
| 121 static void SetRealGLApi(); | 142 static void SetRealGLApi(); |
| 122 virtual void SetCurrent(GLSurface* surface); | 143 virtual void SetCurrent(GLSurface* surface); |
| 123 | 144 |
| 124 // Initialize function pointers to functions where the bound version depends | 145 // Initialize function pointers to functions where the bound version depends |
| 125 // on GL version or supported extensions. Should be called immediately after | 146 // on GL version or supported extensions. Should be called immediately after |
| 126 // this context is made current. | 147 // this context is made current. |
| 127 bool InitializeDynamicBindings(); | 148 bool InitializeDynamicBindings(); |
| 128 | 149 |
| 129 // Returns the last real (non-virtual) GLContext made current. | 150 // Returns the last real (non-virtual) GLContext made current. |
| 130 static GLContext* GetRealCurrent(); | 151 static GLContext* GetRealCurrent(); |
| 131 | 152 |
| 132 private: | 153 private: |
| 133 friend class base::RefCounted<GLContext>; | 154 friend class base::RefCounted<GLContext>; |
| 134 | 155 |
| 135 // For GetRealCurrent. | 156 // For GetRealCurrent. |
| 136 friend class VirtualGLApi; | 157 friend class VirtualGLApi; |
| 137 | 158 |
| 138 scoped_refptr<GLShareGroup> share_group_; | 159 scoped_refptr<GLShareGroup> share_group_; |
| 139 scoped_ptr<VirtualGLApi> virtual_gl_api_; | 160 scoped_ptr<VirtualGLApi> virtual_gl_api_; |
| 140 scoped_ptr<GLStateRestorer> state_restorer_; | 161 scoped_ptr<GLStateRestorer> state_restorer_; |
| 141 scoped_ptr<GLVersionInfo> version_info_; | 162 scoped_ptr<GLVersionInfo> version_info_; |
| 142 | 163 |
| 164 std::vector<scoped_refptr<FlushEvent> > flush_events_; |
| 165 |
| 143 DISALLOW_COPY_AND_ASSIGN(GLContext); | 166 DISALLOW_COPY_AND_ASSIGN(GLContext); |
| 144 }; | 167 }; |
| 145 | 168 |
| 146 class GL_EXPORT GLContextReal : public GLContext { | 169 class GL_EXPORT GLContextReal : public GLContext { |
| 147 public: | 170 public: |
| 148 explicit GLContextReal(GLShareGroup* share_group); | 171 explicit GLContextReal(GLShareGroup* share_group); |
| 149 | 172 |
| 150 protected: | 173 protected: |
| 151 virtual ~GLContextReal(); | 174 virtual ~GLContextReal(); |
| 152 | 175 |
| 153 virtual void SetCurrent(GLSurface* surface) OVERRIDE; | 176 virtual void SetCurrent(GLSurface* surface) OVERRIDE; |
| 154 | 177 |
| 155 private: | 178 private: |
| 156 DISALLOW_COPY_AND_ASSIGN(GLContextReal); | 179 DISALLOW_COPY_AND_ASSIGN(GLContextReal); |
| 157 }; | 180 }; |
| 158 | 181 |
| 159 } // namespace gfx | 182 } // namespace gfx |
| 160 | 183 |
| 161 #endif // UI_GL_GL_CONTEXT_H_ | 184 #endif // UI_GL_GL_CONTEXT_H_ |
| OLD | NEW |