| 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 |
| 25 // Destroys the GL context. | 23 // Destroys the GL context. |
| 26 virtual void Destroy() = 0; | 24 virtual void Destroy() = 0; |
| 27 | 25 |
| 28 // Makes the GL context current on the current thread. | 26 // Makes the GL context and a surface current on the current thread. |
| 29 virtual bool MakeCurrent() = 0; | 27 virtual bool MakeCurrent(GLSurface* surface) = 0; |
| 30 | 28 |
| 31 // Releases this GL context as current on the current thread. TODO(apatrick): | 29 // Releases this GL context and surface as current on the current thread. |
| 32 // implement this in the other GLContexts. | 30 virtual void ReleaseCurrent(GLSurface* surface) = 0; |
| 33 virtual void ReleaseCurrent(); | |
| 34 | 31 |
| 35 // Returns true if this context is current. | 32 // Returns true if this context and surface is current. Pass a null surface |
| 36 virtual bool IsCurrent() = 0; | 33 // if the current surface is not important. |
| 37 | 34 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 | 35 |
| 52 // Get the underlying platform specific GL context "handle". | 36 // Get the underlying platform specific GL context "handle". |
| 53 virtual void* GetHandle() = 0; | 37 virtual void* GetHandle() = 0; |
| 54 | 38 |
| 55 // Set swap interval. This context must be current. | 39 // Set swap interval. This context must be current. |
| 56 virtual void SetSwapInterval(int interval) = 0; | 40 virtual void SetSwapInterval(int interval) = 0; |
| 57 | 41 |
| 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. | 42 // Returns space separated list of extensions. The context must be current. |
| 63 virtual std::string GetExtensions(); | 43 virtual std::string GetExtensions(); |
| 64 | 44 |
| 65 // Returns whether the current context supports the named extension. The | 45 // Returns whether the current context supports the named extension. The |
| 66 // context must be current. | 46 // context must be current. |
| 67 bool HasExtension(const char* name); | 47 bool HasExtension(const char* name); |
| 68 | 48 |
| 69 // Create a GL context that is compatible with the given surface. | 49 // Create a GL context that is compatible with the given surface. |
| 70 // |share_context|, if non-NULL, is a context which the | 50 // |share_context|, if non-NULL, is a context which the |
| 71 // internally created OpenGL context shares textures and other resources. | 51 // internally created OpenGL context shares textures and other resources. |
| 72 // TODO(apatrick): For the time being, the context will take ownership of the | 52 static GLContext* CreateGLContext(GLContext* shared_context); |
| 73 // surface and the surface will be made the current read and draw surface | |
| 74 // when the context is made current. | |
| 75 static GLContext* CreateGLContext(GLSurface* compatible_surface, | |
| 76 GLContext* shared_context); | |
| 77 | 53 |
| 78 static bool LosesAllContextsOnContextLost(); | 54 static bool LosesAllContextsOnContextLost(); |
| 79 | 55 |
| 80 protected: | |
| 81 bool InitializeCommon(); | |
| 82 | |
| 83 private: | 56 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(GLContext); | 57 DISALLOW_COPY_AND_ASSIGN(GLContext); |
| 85 }; | 58 }; |
| 86 | 59 |
| 87 } // namespace gfx | 60 } // namespace gfx |
| 88 | 61 |
| 89 #endif // UI_GFX_GL_GL_CONTEXT_H_ | 62 #endif // UI_GFX_GL_GL_CONTEXT_H_ |
| OLD | NEW |