OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GFX_GL_GL_CONTEXT_H_ | 5 #ifndef UI_GFX_GL_GL_CONTEXT_H_ |
6 #define UI_GFX_GL_GL_CONTEXT_H_ | 6 #define UI_GFX_GL_GL_CONTEXT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "build/build_config.h" | 11 #include "base/basictypes.h" |
12 #include "ui/gfx/native_widget_types.h" | |
13 #include "ui/gfx/size.h" | |
14 | 12 |
15 namespace gfx { | 13 namespace gfx { |
16 | 14 |
17 class GLSurface; | 15 class GLSurface; |
18 | 16 |
19 // Encapsulates an OpenGL context, hiding platform specific management. | 17 // Encapsulates an OpenGL context, hiding platform specific management. |
20 class GLContext { | 18 class GLContext { |
21 public: | 19 public: |
22 GLContext() {} | 20 GLContext() {} |
23 virtual ~GLContext() {} | 21 virtual ~GLContext() {} |
24 | 22 |
23 // Initializes the GL context to be compatible with the given surface. The GL | |
24 // context can be made with other surface's of the same type. | |
25 virtual bool Initialize(GLContext* shared_context, | |
26 GLSurface* compatible_surface) = 0; | |
Alexey Marinichev
2011/05/23 18:19:12
compatible_surface is used only by linux and osmes
| |
27 | |
25 // Destroys the GL context. | 28 // Destroys the GL context. |
26 virtual void Destroy() = 0; | 29 virtual void Destroy() = 0; |
27 | 30 |
28 // Makes the GL context current on the current thread. | 31 // Makes the GL context and a surface current on the current thread. |
29 virtual bool MakeCurrent() = 0; | 32 virtual bool MakeCurrent(GLSurface* surface) = 0; |
30 | 33 |
31 // Releases this GL context as current on the current thread. TODO(apatrick): | 34 // Releases this GL context and surface as current on the current thread. |
32 // implement this in the other GLContexts. | 35 virtual void ReleaseCurrent(GLSurface* surface) = 0; |
33 virtual void ReleaseCurrent(); | |
34 | 36 |
35 // Returns true if this context is current. | 37 // Returns true if this context and surface is current. Pass a null surface |
36 virtual bool IsCurrent() = 0; | 38 // if the current surface is not important. |
37 | 39 virtual bool IsCurrent(GLSurface* surface) = 0; |
38 // Returns true if this context is offscreen. | |
39 virtual bool IsOffscreen() = 0; | |
40 | |
41 // Swaps front and back buffers. This has no effect for off-screen | |
42 // contexts. | |
43 virtual bool SwapBuffers() = 0; | |
44 | |
45 // Get the size of the back buffer. | |
46 virtual gfx::Size GetSize() = 0; | |
47 | |
48 // Get the surface. TODO(apatrick): remove this when contexts are split from | |
49 // surfaces. | |
50 virtual GLSurface* GetSurface(); | |
51 | 40 |
52 // Get the underlying platform specific GL context "handle". | 41 // Get the underlying platform specific GL context "handle". |
53 virtual void* GetHandle() = 0; | 42 virtual void* GetHandle() = 0; |
54 | 43 |
55 // Set swap interval. This context must be current. | 44 // Set swap interval. This context must be current. |
56 virtual void SetSwapInterval(int interval) = 0; | 45 virtual void SetSwapInterval(int interval) = 0; |
57 | 46 |
58 // Returns the internal frame buffer object name if the context is backed by | |
59 // FBO. Otherwise returns 0. | |
60 virtual unsigned int GetBackingFrameBufferObject(); | |
61 | |
62 // Returns space separated list of extensions. The context must be current. | 47 // Returns space separated list of extensions. The context must be current. |
63 virtual std::string GetExtensions(); | 48 virtual std::string GetExtensions(); |
64 | 49 |
65 // Returns whether the current context supports the named extension. The | 50 // Returns whether the current context supports the named extension. The |
66 // context must be current. | 51 // context must be current. |
67 bool HasExtension(const char* name); | 52 bool HasExtension(const char* name); |
68 | 53 |
69 // Create a GL context that is compatible with the given surface. | 54 // Create a GL context that is compatible with the given surface. |
70 // |share_context|, if non-NULL, is a context which the | 55 // |share_context|, if non-NULL, is a context which the |
71 // internally created OpenGL context shares textures and other resources. | 56 // internally created OpenGL context shares textures and other resources. |
72 // TODO(apatrick): For the time being, the context will take ownership of the | 57 static GLContext* CreateGLContext(GLContext* shared_context, |
73 // surface and the surface will be made the current read and draw surface | 58 GLSurface* compatible_surface); |
74 // when the context is made current. | |
75 static GLContext* CreateGLContext(GLSurface* compatible_surface, | |
76 GLContext* shared_context); | |
77 | 59 |
78 static bool LosesAllContextsOnContextLost(); | 60 static bool LosesAllContextsOnContextLost(); |
79 | 61 |
80 protected: | |
81 bool InitializeCommon(); | |
82 | |
83 private: | 62 private: |
84 DISALLOW_COPY_AND_ASSIGN(GLContext); | 63 DISALLOW_COPY_AND_ASSIGN(GLContext); |
85 }; | 64 }; |
86 | 65 |
87 } // namespace gfx | 66 } // namespace gfx |
88 | 67 |
89 #endif // UI_GFX_GL_GL_CONTEXT_H_ | 68 #endif // UI_GFX_GL_GL_CONTEXT_H_ |
OLD | NEW |