[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 5 | #ifndef UI_GL_GL_CONTEXT_H_ |
6 | #define UI_GL_GL_CONTEXT_H_ | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7 | |
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 8 | #include <string> |
9 | |||||
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 12 | #include "ui/gl/gl_share_group.h" |
13 | #include "ui/gl/gpu_preference.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] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 28 | virtual bool Initialize( |
29 | GLSurface* compatible_surface, GpuPreference gpu_preference) = 0; | ||||
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 30 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 31 | // Destroys the GL context. |
32 | virtual void Destroy() = 0; | ||||
33 | |||||
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 34 | // Makes the GL context and a surface current on the current thread. |
35 | virtual bool MakeCurrent(GLSurface* surface) = 0; | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 36 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 37 | // Releases this GL context and surface as current on the current thread. |
38 | virtual void ReleaseCurrent(GLSurface* surface) = 0; | ||||
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 39 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 40 | // Returns true if this context and surface is current. Pass a null surface |
41 | // if the current surface is not important. | ||||
42 | virtual bool IsCurrent(GLSurface* surface) = 0; | ||||
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 43 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 44 | // Get the underlying platform specific GL context "handle". |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 45 | virtual void* GetHandle() = 0; |
46 | |||||
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 47 | // Set swap interval. This context must be current. |
48 | virtual void SetSwapInterval(int interval) = 0; | ||||
49 | |||||
50 | // Returns space separated list of extensions. The context must be current. | ||||
51 | virtual std::string GetExtensions(); | ||||
52 | |||||
[email protected] | 631e6c9b | 2012-09-21 00:24:02 | [diff] [blame^] | 53 | // 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 | ||||
55 | // to get the exact amount of GPU memory. | ||||
56 | virtual bool GetTotalGpuMemory(size_t* bytes); | ||||
57 | |||||
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 58 | // Returns whether the current context supports the named extension. The |
59 | // context must be current. | ||||
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 60 | bool HasExtension(const char* name); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 61 | |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 62 | GLShareGroup* share_group(); |
63 | |||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 64 | // Create a GL context that is compatible with the given surface. |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 65 | // |share_group|, if non-NULL, is a group of contexts which the |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 66 | // internally created OpenGL context shares textures and other resources. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 67 | static scoped_refptr<GLContext> CreateGLContext( |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 68 | GLShareGroup* share_group, |
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 69 | GLSurface* compatible_surface, |
70 | GpuPreference gpu_preference); | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 71 | |
[email protected] | 0fc3574 | 2011-04-13 17:57:54 | [diff] [blame] | 72 | static bool LosesAllContextsOnContextLost(); |
73 | |||||
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 74 | static bool SupportsDualGpus(); |
75 | |||||
[email protected] | c777de5 | 2011-09-09 23:08:56 | [diff] [blame] | 76 | static GLContext* GetCurrent(); |
77 | |||||
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 78 | virtual bool WasAllocatedUsingRobustnessExtension(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 79 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 80 | protected: |
81 | virtual ~GLContext(); | ||||
[email protected] | c777de5 | 2011-09-09 23:08:56 | [diff] [blame] | 82 | static void SetCurrent(GLContext* context, GLSurface* surface); |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 83 | |
[email protected] | 6494823b | 2011-10-27 18:30:44 | [diff] [blame] | 84 | // Initialize function pointers to extension functions in the GL |
85 | // implementation. Should be called immediately after this context is made | ||||
86 | // current. | ||||
87 | bool InitializeExtensionBindings(); | ||||
88 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 89 | private: |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 90 | friend class base::RefCounted<GLContext>; |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 91 | |
92 | scoped_refptr<GLShareGroup> share_group_; | ||||
93 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 94 | DISALLOW_COPY_AND_ASSIGN(GLContext); |
95 | }; | ||||
96 | |||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 97 | } // namespace gfx |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 98 | |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 99 | #endif // UI_GL_GL_CONTEXT_H_ |