blob: 5340ada49951bff78671bc8b5c739dd38a5ca2e0 [file] [log] [blame]
[email protected]5ae0b282011-03-28 19:24:491// Copyright (c) 2011 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]5ae0b282011-03-28 19:24:495#ifndef UI_GFX_GL_GL_CONTEXT_H_
6#define UI_GFX_GL_GL_CONTEXT_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]d37231fa2010-04-09 21:16:028
[email protected]1c0585d2010-10-07 23:19:169#include <string>
10
[email protected]f62a5ab2011-05-23 20:34:1511#include "base/basictypes.h"
[email protected]fbe20372011-06-01 01:46:3812#include "base/memory/ref_counted.h"
[email protected]7196e012011-06-16 20:54:5313#include "ui/gfx/gl/gl_share_group.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]7196e012011-06-16 20:54:5328 virtual bool Initialize(GLSurface* compatible_surface) = 0;
[email protected]f62a5ab2011-05-23 20:34:1529
[email protected]d37231fa2010-04-09 21:16:0230 // Destroys the GL context.
31 virtual void Destroy() = 0;
32
[email protected]f62a5ab2011-05-23 20:34:1533 // Makes the GL context and a surface current on the current thread.
34 virtual bool MakeCurrent(GLSurface* surface) = 0;
[email protected]d37231fa2010-04-09 21:16:0235
[email protected]f62a5ab2011-05-23 20:34:1536 // Releases this GL context and surface as current on the current thread.
37 virtual void ReleaseCurrent(GLSurface* surface) = 0;
[email protected]a4127722011-04-27 23:13:5238
[email protected]f62a5ab2011-05-23 20:34:1539 // 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]a4127722011-04-27 23:13:5242
[email protected]d37231fa2010-04-09 21:16:0243 // Get the underlying platform specific GL context "handle".
[email protected]4bedba72010-04-20 22:08:5444 virtual void* GetHandle() = 0;
45
[email protected]1c0585d2010-10-07 23:19:1646 // 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]876f6fee2010-08-02 23:10:3252 // Returns whether the current context supports the named extension. The
53 // context must be current.
[email protected]1c0585d2010-10-07 23:19:1654 bool HasExtension(const char* name);
[email protected]876f6fee2010-08-02 23:10:3255
[email protected]7196e012011-06-16 20:54:5356 GLShareGroup* share_group();
57
[email protected]ffae4022011-05-12 22:54:2958 // Create a GL context that is compatible with the given surface.
[email protected]7196e012011-06-16 20:54:5359 // |share_group|, if non-NULL, is a group of contexts which the
[email protected]ffae4022011-05-12 22:54:2960 // internally created OpenGL context shares textures and other resources.
[email protected]fbe20372011-06-01 01:46:3861 static scoped_refptr<GLContext> CreateGLContext(
[email protected]7196e012011-06-16 20:54:5362 GLShareGroup* share_group,
[email protected]fbe20372011-06-01 01:46:3863 GLSurface* compatible_surface);
[email protected]d37231fa2010-04-09 21:16:0264
[email protected]0fc35742011-04-13 17:57:5465 static bool LosesAllContextsOnContextLost();
66
[email protected]38d139d2011-07-14 00:38:4367 virtual bool WasAllocatedUsingARBRobustness();
68
[email protected]fbe20372011-06-01 01:46:3869 protected:
70 virtual ~GLContext();
71
[email protected]d37231fa2010-04-09 21:16:0272 private:
[email protected]7196e012011-06-16 20:54:5373 scoped_refptr<GLShareGroup> share_group_;
[email protected]fbe20372011-06-01 01:46:3874 friend class base::RefCounted<GLContext>;
[email protected]d37231fa2010-04-09 21:16:0275 DISALLOW_COPY_AND_ASSIGN(GLContext);
76};
77
[email protected]5a6db6c2010-04-22 18:32:0678} // namespace gfx
[email protected]d37231fa2010-04-09 21:16:0279
[email protected]5ae0b282011-03-28 19:24:4980#endif // UI_GFX_GL_GL_CONTEXT_H_