blob: 7c0b669c0b3dcf1f80dd8269dfc9ad9d82e5484f [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]c9e2cbbb2012-05-12 21:17:2712#include "ui/gl/gl_share_group.h"
13#include "ui/gl/gpu_preference.h"
[email protected]d37231fa2010-04-09 21:16:0214
[email protected]5a6db6c2010-04-22 18:32:0615namespace gfx {
[email protected]d37231fa2010-04-09 21:16:0216
[email protected]a4127722011-04-27 23:13:5217class GLSurface;
18
[email protected]d37231fa2010-04-09 21:16:0219// Encapsulates an OpenGL context, hiding platform specific management.
[email protected]fe377e12011-08-18 17:37:3620class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
[email protected]d37231fa2010-04-09 21:16:0221 public:
[email protected]7196e012011-06-16 20:54:5322 explicit GLContext(GLShareGroup* share_group);
[email protected]d37231fa2010-04-09 21:16:0223
[email protected]f62a5ab2011-05-23 20:34:1524 // 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]276f89062011-10-13 22:55:5028 virtual bool Initialize(
29 GLSurface* compatible_surface, GpuPreference gpu_preference) = 0;
[email protected]f62a5ab2011-05-23 20:34:1530
[email protected]d37231fa2010-04-09 21:16:0231 // Destroys the GL context.
32 virtual void Destroy() = 0;
33
[email protected]f62a5ab2011-05-23 20:34:1534 // Makes the GL context and a surface current on the current thread.
35 virtual bool MakeCurrent(GLSurface* surface) = 0;
[email protected]d37231fa2010-04-09 21:16:0236
[email protected]f62a5ab2011-05-23 20:34:1537 // Releases this GL context and surface as current on the current thread.
38 virtual void ReleaseCurrent(GLSurface* surface) = 0;
[email protected]a4127722011-04-27 23:13:5239
[email protected]f62a5ab2011-05-23 20:34:1540 // 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]a4127722011-04-27 23:13:5243
[email protected]d37231fa2010-04-09 21:16:0244 // Get the underlying platform specific GL context "handle".
[email protected]4bedba72010-04-20 22:08:5445 virtual void* GetHandle() = 0;
46
[email protected]1c0585d2010-10-07 23:19:1647 // 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]631e6c9b2012-09-21 00:24:0253 // 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]876f6fee2010-08-02 23:10:3258 // Returns whether the current context supports the named extension. The
59 // context must be current.
[email protected]1c0585d2010-10-07 23:19:1660 bool HasExtension(const char* name);
[email protected]876f6fee2010-08-02 23:10:3261
[email protected]7196e012011-06-16 20:54:5362 GLShareGroup* share_group();
63
[email protected]ffae4022011-05-12 22:54:2964 // Create a GL context that is compatible with the given surface.
[email protected]7196e012011-06-16 20:54:5365 // |share_group|, if non-NULL, is a group of contexts which the
[email protected]ffae4022011-05-12 22:54:2966 // internally created OpenGL context shares textures and other resources.
[email protected]fbe20372011-06-01 01:46:3867 static scoped_refptr<GLContext> CreateGLContext(
[email protected]7196e012011-06-16 20:54:5368 GLShareGroup* share_group,
[email protected]276f89062011-10-13 22:55:5069 GLSurface* compatible_surface,
70 GpuPreference gpu_preference);
[email protected]d37231fa2010-04-09 21:16:0271
[email protected]0fc35742011-04-13 17:57:5472 static bool LosesAllContextsOnContextLost();
73
[email protected]276f89062011-10-13 22:55:5074 static bool SupportsDualGpus();
75
[email protected]c777de52011-09-09 23:08:5676 static GLContext* GetCurrent();
77
[email protected]706b69f2012-07-27 04:59:3078 virtual bool WasAllocatedUsingRobustnessExtension();
[email protected]38d139d2011-07-14 00:38:4379
[email protected]fbe20372011-06-01 01:46:3880 protected:
81 virtual ~GLContext();
[email protected]c777de52011-09-09 23:08:5682 static void SetCurrent(GLContext* context, GLSurface* surface);
[email protected]fbe20372011-06-01 01:46:3883
[email protected]6494823b2011-10-27 18:30:4484 // 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]d37231fa2010-04-09 21:16:0289 private:
[email protected]fbe20372011-06-01 01:46:3890 friend class base::RefCounted<GLContext>;
[email protected]c9e2cbbb2012-05-12 21:17:2791
92 scoped_refptr<GLShareGroup> share_group_;
93
[email protected]d37231fa2010-04-09 21:16:0294 DISALLOW_COPY_AND_ASSIGN(GLContext);
95};
96
[email protected]5a6db6c2010-04-22 18:32:0697} // namespace gfx
[email protected]d37231fa2010-04-09 21:16:0298
[email protected]c9e2cbbb2012-05-12 21:17:2799#endif // UI_GL_GL_CONTEXT_H_