[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 5 | #ifndef UI_GFX_GL_GL_CONTEXT_H_ |
6 | #define UI_GFX_GL_GL_CONTEXT_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 8 | |
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 9 | #include <string> |
10 | |||||
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 13 | #include "ui/gfx/gl/gl_share_group.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 14 | |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 15 | namespace gfx { |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 16 | |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 17 | class GLSurface; |
18 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 19 | // Encapsulates an OpenGL context, hiding platform specific management. |
[email protected] | fe377e1 | 2011-08-18 17:37:36 | [diff] [blame^] | 20 | class GL_EXPORT GLContext : public base::RefCounted<GLContext> { |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 21 | public: |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 22 | explicit GLContext(GLShareGroup* share_group); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 23 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 24 | // 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 | ||||
26 | // surface is only needed for certain platforms like WGL, OSMesa and GLX. It | ||||
27 | // should be specific for all platforms though. | ||||
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 28 | virtual bool Initialize(GLSurface* compatible_surface) = 0; |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 29 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 30 | // Destroys the GL context. |
31 | virtual void Destroy() = 0; | ||||
32 | |||||
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 33 | // Makes the GL context and a surface current on the current thread. |
34 | virtual bool MakeCurrent(GLSurface* surface) = 0; | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 35 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 36 | // Releases this GL context and surface as current on the current thread. |
37 | virtual void ReleaseCurrent(GLSurface* surface) = 0; | ||||
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 38 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 39 | // Returns true if this context and surface is current. Pass a null surface |
40 | // if the current surface is not important. | ||||
41 | virtual bool IsCurrent(GLSurface* surface) = 0; | ||||
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 42 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 43 | // Get the underlying platform specific GL context "handle". |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 44 | virtual void* GetHandle() = 0; |
45 | |||||
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 46 | // Set swap interval. This context must be current. |
47 | virtual void SetSwapInterval(int interval) = 0; | ||||
48 | |||||
49 | // Returns space separated list of extensions. The context must be current. | ||||
50 | virtual std::string GetExtensions(); | ||||
51 | |||||
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 52 | // Returns whether the current context supports the named extension. The |
53 | // context must be current. | ||||
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 54 | bool HasExtension(const char* name); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 55 | |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 56 | GLShareGroup* share_group(); |
57 | |||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 58 | // Create a GL context that is compatible with the given surface. |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 59 | // |share_group|, if non-NULL, is a group of contexts which the |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 60 | // internally created OpenGL context shares textures and other resources. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 61 | static scoped_refptr<GLContext> CreateGLContext( |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 62 | GLShareGroup* share_group, |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 63 | GLSurface* compatible_surface); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 64 | |
[email protected] | 0fc3574 | 2011-04-13 17:57:54 | [diff] [blame] | 65 | static bool LosesAllContextsOnContextLost(); |
66 | |||||
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 67 | virtual bool WasAllocatedUsingARBRobustness(); |
68 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 69 | protected: |
70 | virtual ~GLContext(); | ||||
71 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 72 | private: |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 73 | scoped_refptr<GLShareGroup> share_group_; |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 74 | friend class base::RefCounted<GLContext>; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(GLContext); |
76 | }; | ||||
77 | |||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 78 | } // namespace gfx |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 79 | |
[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 80 | #endif // UI_GFX_GL_GL_CONTEXT_H_ |