[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] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 13 | |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 14 | namespace gfx { |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 15 | |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 16 | class GLSurface; |
17 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 18 | // Encapsulates an OpenGL context, hiding platform specific management. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 19 | class GLContext : public base::RefCounted<GLContext> { |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 20 | public: |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 21 | GLContext(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 22 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 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. The compatible | ||||
25 | // surface is only needed for certain platforms like WGL, OSMesa and GLX. It | ||||
26 | // should be specific for all platforms though. | ||||
27 | virtual bool Initialize(GLContext* shared_context, | ||||
28 | GLSurface* compatible_surface) = 0; | ||||
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] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 56 | // Create a GL context that is compatible with the given surface. |
57 | // |share_context|, if non-NULL, is a context which the | ||||
58 | // internally created OpenGL context shares textures and other resources. | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 59 | static scoped_refptr<GLContext> CreateGLContext( |
60 | GLContext* shared_context, | ||||
61 | GLSurface* compatible_surface); | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 62 | |
[email protected] | 0fc3574 | 2011-04-13 17:57:54 | [diff] [blame] | 63 | static bool LosesAllContextsOnContextLost(); |
64 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 65 | protected: |
66 | virtual ~GLContext(); | ||||
67 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 68 | private: |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 69 | friend class base::RefCounted<GLContext>; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(GLContext); |
71 | }; | ||||
72 | |||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 73 | } // namespace gfx |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 74 | |
[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 75 | #endif // UI_GFX_GL_GL_CONTEXT_H_ |