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