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