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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
12 #include "ui/gl/gl_share_group.h" | 13 #include "ui/gl/gl_share_group.h" |
13 #include "ui/gl/gpu_preference.h" | 14 #include "ui/gl/gpu_preference.h" |
14 | 15 |
15 namespace gfx { | 16 namespace gfx { |
16 | 17 |
17 class GLSurface; | 18 class GLSurface; |
| 19 class VirtualGLApi; |
| 20 class GLStateRestorer; |
18 | 21 |
19 // Encapsulates an OpenGL context, hiding platform specific management. | 22 // Encapsulates an OpenGL context, hiding platform specific management. |
20 class GL_EXPORT GLContext : public base::RefCounted<GLContext> { | 23 class GL_EXPORT GLContext : public base::RefCounted<GLContext> { |
21 public: | 24 public: |
22 explicit GLContext(GLShareGroup* share_group); | 25 explicit GLContext(GLShareGroup* share_group); |
23 | 26 |
24 // Initializes the GL context to be compatible with the given surface. The GL | 27 // Initializes the GL context to be compatible with the given surface. The GL |
25 // context can be made with other surface's of the same type. The compatible | 28 // context can be made with other surface's of the same type. The compatible |
26 // surface is only needed for certain platforms like WGL, OSMesa and GLX. It | 29 // surface is only needed for certain platforms like WGL, OSMesa and GLX. It |
27 // should be specific for all platforms though. | 30 // should be specific for all platforms though. |
28 virtual bool Initialize( | 31 virtual bool Initialize( |
29 GLSurface* compatible_surface, GpuPreference gpu_preference) = 0; | 32 GLSurface* compatible_surface, GpuPreference gpu_preference) = 0; |
30 | 33 |
31 // Destroys the GL context. | 34 // Destroys the GL context. |
32 virtual void Destroy() = 0; | 35 virtual void Destroy() = 0; |
33 | 36 |
34 // Makes the GL context and a surface current on the current thread. | 37 // Makes the GL context and a surface current on the current thread. |
35 virtual bool MakeCurrent(GLSurface* surface) = 0; | 38 virtual bool MakeCurrent(GLSurface* surface) = 0; |
36 | 39 |
37 // Releases this GL context and surface as current on the current thread. | 40 // Releases this GL context and surface as current on the current thread. |
38 virtual void ReleaseCurrent(GLSurface* surface) = 0; | 41 virtual void ReleaseCurrent(GLSurface* surface) = 0; |
39 | 42 |
40 // Returns true if this context and surface is current. Pass a null surface | 43 // Returns true if this context and surface is current. Pass a null surface |
41 // if the current surface is not important. | 44 // if the current surface is not important. |
42 virtual bool IsCurrent(GLSurface* surface) = 0; | 45 virtual bool IsCurrent(GLSurface* surface) = 0; |
43 | 46 |
44 // Get the underlying platform specific GL context "handle". | 47 // Get the underlying platform specific GL context "handle". |
45 virtual void* GetHandle() = 0; | 48 virtual void* GetHandle() = 0; |
46 | 49 |
| 50 // Gets the GLStateRestore for the context. |
| 51 virtual GLStateRestorer* GetGLStateRestorer(); |
| 52 |
47 // Set swap interval. This context must be current. | 53 // Set swap interval. This context must be current. |
48 virtual void SetSwapInterval(int interval) = 0; | 54 virtual void SetSwapInterval(int interval) = 0; |
49 | 55 |
50 // Returns space separated list of extensions. The context must be current. | 56 // Returns space separated list of extensions. The context must be current. |
51 virtual std::string GetExtensions(); | 57 virtual std::string GetExtensions(); |
52 | 58 |
53 // Returns in bytes the total amount of GPU memory for the GPU which this | 59 // Returns in bytes the total amount of GPU memory for the GPU which this |
54 // context is currently rendering on. Returns false if no extension exists | 60 // context is currently rendering on. Returns false if no extension exists |
55 // to get the exact amount of GPU memory. | 61 // to get the exact amount of GPU memory. |
56 virtual bool GetTotalGpuMemory(size_t* bytes); | 62 virtual bool GetTotalGpuMemory(size_t* bytes); |
(...skipping 11 matching lines...) Expand all Loading... |
68 GLShareGroup* share_group, | 74 GLShareGroup* share_group, |
69 GLSurface* compatible_surface, | 75 GLSurface* compatible_surface, |
70 GpuPreference gpu_preference); | 76 GpuPreference gpu_preference); |
71 | 77 |
72 static bool LosesAllContextsOnContextLost(); | 78 static bool LosesAllContextsOnContextLost(); |
73 | 79 |
74 static GLContext* GetCurrent(); | 80 static GLContext* GetCurrent(); |
75 | 81 |
76 virtual bool WasAllocatedUsingRobustnessExtension(); | 82 virtual bool WasAllocatedUsingRobustnessExtension(); |
77 | 83 |
| 84 // Use this context for virtualization. |
| 85 void SetupForVirtualization(); |
| 86 |
| 87 // Make this context current when used for context virtualization. |
| 88 bool MakeVirtuallyCurrent(GLContext* virutal_context, GLSurface* surface); |
| 89 |
78 protected: | 90 protected: |
79 virtual ~GLContext(); | 91 virtual ~GLContext(); |
| 92 |
| 93 // Sets the GL api to the real hardware API (vs the VirtualAPI) |
| 94 static void SetRealGLApi(); |
80 static void SetCurrent(GLContext* context, GLSurface* surface); | 95 static void SetCurrent(GLContext* context, GLSurface* surface); |
81 | 96 |
82 // Initialize function pointers to extension functions in the GL | 97 // Initialize function pointers to extension functions in the GL |
83 // implementation. Should be called immediately after this context is made | 98 // implementation. Should be called immediately after this context is made |
84 // current. | 99 // current. |
85 bool InitializeExtensionBindings(); | 100 bool InitializeExtensionBindings(); |
86 | 101 |
87 private: | 102 private: |
88 friend class base::RefCounted<GLContext>; | 103 friend class base::RefCounted<GLContext>; |
89 | 104 |
90 scoped_refptr<GLShareGroup> share_group_; | 105 scoped_refptr<GLShareGroup> share_group_; |
| 106 scoped_ptr<VirtualGLApi> virtual_gl_api_; |
91 | 107 |
92 DISALLOW_COPY_AND_ASSIGN(GLContext); | 108 DISALLOW_COPY_AND_ASSIGN(GLContext); |
93 }; | 109 }; |
94 | 110 |
95 } // namespace gfx | 111 } // namespace gfx |
96 | 112 |
97 #endif // UI_GL_GL_CONTEXT_H_ | 113 #endif // UI_GL_GL_CONTEXT_H_ |
OLD | NEW |