blob: 8f9aa231f7e86c973de5041cf25ed931f8f523af [file] [log] [blame]
[email protected]c9e2cbbb2012-05-12 21:17:271// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d37231fa2010-04-09 21:16:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]c9e2cbbb2012-05-12 21:17:275#ifndef UI_GL_GL_CONTEXT_H_
6#define UI_GL_GL_CONTEXT_H_
[email protected]d37231fa2010-04-09 21:16:027
[email protected]1c0585d2010-10-07 23:19:168#include <string>
9
[email protected]f62a5ab2011-05-23 20:34:1510#include "base/basictypes.h"
[email protected]fbe20372011-06-01 01:46:3811#include "base/memory/ref_counted.h"
[email protected]1868a342012-11-07 15:56:0212#include "base/memory/scoped_ptr.h"
[email protected]c9e2cbbb2012-05-12 21:17:2713#include "ui/gl/gl_share_group.h"
14#include "ui/gl/gpu_preference.h"
[email protected]d37231fa2010-04-09 21:16:0215
[email protected]5a6db6c2010-04-22 18:32:0616namespace gfx {
[email protected]d37231fa2010-04-09 21:16:0217
[email protected]a4127722011-04-27 23:13:5218class GLSurface;
[email protected]1868a342012-11-07 15:56:0219class VirtualGLApi;
20class GLStateRestorer;
[email protected]a4127722011-04-27 23:13:5221
[email protected]d37231fa2010-04-09 21:16:0222// Encapsulates an OpenGL context, hiding platform specific management.
[email protected]fe377e12011-08-18 17:37:3623class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
[email protected]d37231fa2010-04-09 21:16:0224 public:
[email protected]7196e012011-06-16 20:54:5325 explicit GLContext(GLShareGroup* share_group);
[email protected]d37231fa2010-04-09 21:16:0226
[email protected]f62a5ab2011-05-23 20:34:1527 // Initializes the GL context to be compatible with the given surface. The GL
28 // context can be made with other surface's of the same type. The compatible
29 // surface is only needed for certain platforms like WGL, OSMesa and GLX. It
30 // should be specific for all platforms though.
[email protected]276f89062011-10-13 22:55:5031 virtual bool Initialize(
32 GLSurface* compatible_surface, GpuPreference gpu_preference) = 0;
[email protected]f62a5ab2011-05-23 20:34:1533
[email protected]d37231fa2010-04-09 21:16:0234 // Destroys the GL context.
35 virtual void Destroy() = 0;
36
[email protected]f62a5ab2011-05-23 20:34:1537 // Makes the GL context and a surface current on the current thread.
38 virtual bool MakeCurrent(GLSurface* surface) = 0;
[email protected]d37231fa2010-04-09 21:16:0239
[email protected]f62a5ab2011-05-23 20:34:1540 // Releases this GL context and surface as current on the current thread.
41 virtual void ReleaseCurrent(GLSurface* surface) = 0;
[email protected]a4127722011-04-27 23:13:5242
[email protected]f62a5ab2011-05-23 20:34:1543 // Returns true if this context and surface is current. Pass a null surface
44 // if the current surface is not important.
45 virtual bool IsCurrent(GLSurface* surface) = 0;
[email protected]a4127722011-04-27 23:13:5246
[email protected]d37231fa2010-04-09 21:16:0247 // Get the underlying platform specific GL context "handle".
[email protected]4bedba72010-04-20 22:08:5448 virtual void* GetHandle() = 0;
49
[email protected]1868a342012-11-07 15:56:0250 // Gets the GLStateRestore for the context.
51 virtual GLStateRestorer* GetGLStateRestorer();
52
[email protected]1c0585d2010-10-07 23:19:1653 // Set swap interval. This context must be current.
54 virtual void SetSwapInterval(int interval) = 0;
55
56 // Returns space separated list of extensions. The context must be current.
57 virtual std::string GetExtensions();
58
[email protected]631e6c9b2012-09-21 00:24:0259 // Returns in bytes the total amount of GPU memory for the GPU which this
60 // context is currently rendering on. Returns false if no extension exists
61 // to get the exact amount of GPU memory.
62 virtual bool GetTotalGpuMemory(size_t* bytes);
63
[email protected]97419c02013-04-10 02:52:3864 // Indicate that it is safe to force this context to switch GPUs, since
65 // transitioning can cause corruption and hangs (OS X only).
66 virtual void SetSafeToForceGpuSwitch();
67
[email protected]9b753992013-04-27 02:04:4168 // Indicate that the real context switches should unbind the FBO first
[email protected]85cb4682013-04-20 00:54:2469 // (For an Android work-around only).
[email protected]9b753992013-04-27 02:04:4170 virtual void SetUnbindFboOnMakeCurrent();
[email protected]85cb4682013-04-20 00:54:2471
[email protected]876f6fee2010-08-02 23:10:3272 // Returns whether the current context supports the named extension. The
73 // context must be current.
[email protected]1c0585d2010-10-07 23:19:1674 bool HasExtension(const char* name);
[email protected]876f6fee2010-08-02 23:10:3275
[email protected]7196e012011-06-16 20:54:5376 GLShareGroup* share_group();
77
[email protected]ffae4022011-05-12 22:54:2978 // Create a GL context that is compatible with the given surface.
[email protected]7196e012011-06-16 20:54:5379 // |share_group|, if non-NULL, is a group of contexts which the
[email protected]ffae4022011-05-12 22:54:2980 // internally created OpenGL context shares textures and other resources.
[email protected]fbe20372011-06-01 01:46:3881 static scoped_refptr<GLContext> CreateGLContext(
[email protected]7196e012011-06-16 20:54:5382 GLShareGroup* share_group,
[email protected]276f89062011-10-13 22:55:5083 GLSurface* compatible_surface,
84 GpuPreference gpu_preference);
[email protected]d37231fa2010-04-09 21:16:0285
[email protected]0fc35742011-04-13 17:57:5486 static bool LosesAllContextsOnContextLost();
87
[email protected]c777de52011-09-09 23:08:5688 static GLContext* GetCurrent();
89
[email protected]706b69f2012-07-27 04:59:3090 virtual bool WasAllocatedUsingRobustnessExtension();
[email protected]38d139d2011-07-14 00:38:4391
[email protected]1868a342012-11-07 15:56:0292 // Use this context for virtualization.
93 void SetupForVirtualization();
94
95 // Make this context current when used for context virtualization.
[email protected]b3cbad12012-12-05 19:56:3696 bool MakeVirtuallyCurrent(GLContext* virtual_context, GLSurface* surface);
97
98 // Notify this context that |virtual_context|, that was using us, is
99 // being destroyed.
100 void OnDestroyVirtualContext(GLContext* virtual_context);
[email protected]1868a342012-11-07 15:56:02101
[email protected]fbe20372011-06-01 01:46:38102 protected:
103 virtual ~GLContext();
[email protected]1868a342012-11-07 15:56:02104
105 // Sets the GL api to the real hardware API (vs the VirtualAPI)
106 static void SetRealGLApi();
[email protected]c777de52011-09-09 23:08:56107 static void SetCurrent(GLContext* context, GLSurface* surface);
[email protected]fbe20372011-06-01 01:46:38108
[email protected]6494823b2011-10-27 18:30:44109 // Initialize function pointers to extension functions in the GL
110 // implementation. Should be called immediately after this context is made
111 // current.
112 bool InitializeExtensionBindings();
113
[email protected]d37231fa2010-04-09 21:16:02114 private:
[email protected]fbe20372011-06-01 01:46:38115 friend class base::RefCounted<GLContext>;
[email protected]c9e2cbbb2012-05-12 21:17:27116
117 scoped_refptr<GLShareGroup> share_group_;
[email protected]1868a342012-11-07 15:56:02118 scoped_ptr<VirtualGLApi> virtual_gl_api_;
[email protected]c9e2cbbb2012-05-12 21:17:27119
[email protected]d37231fa2010-04-09 21:16:02120 DISALLOW_COPY_AND_ASSIGN(GLContext);
121};
122
[email protected]5a6db6c2010-04-22 18:32:06123} // namespace gfx
[email protected]d37231fa2010-04-09 21:16:02124
[email protected]c9e2cbbb2012-05-12 21:17:27125#endif // UI_GL_GL_CONTEXT_H_