blob: 77f167fb86913f2c0478f902f9d712c6f2f30649 [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]d37231fa2010-04-09 21:16:0213
[email protected]5a6db6c2010-04-22 18:32:0614namespace gfx {
[email protected]d37231fa2010-04-09 21:16:0215
[email protected]a4127722011-04-27 23:13:5216class GLSurface;
17
[email protected]d37231fa2010-04-09 21:16:0218// Encapsulates an OpenGL context, hiding platform specific management.
[email protected]fbe20372011-06-01 01:46:3819class GLContext : public base::RefCounted<GLContext> {
[email protected]d37231fa2010-04-09 21:16:0220 public:
[email protected]fbe20372011-06-01 01:46:3821 GLContext();
[email protected]d37231fa2010-04-09 21:16:0222
[email protected]f62a5ab2011-05-23 20:34:1523 // 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]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]ffae4022011-05-12 22:54:2956 // 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]fbe20372011-06-01 01:46:3859 static scoped_refptr<GLContext> CreateGLContext(
60 GLContext* shared_context,
61 GLSurface* compatible_surface);
[email protected]d37231fa2010-04-09 21:16:0262
[email protected]0fc35742011-04-13 17:57:5463 static bool LosesAllContextsOnContextLost();
64
[email protected]fbe20372011-06-01 01:46:3865 protected:
66 virtual ~GLContext();
67
[email protected]d37231fa2010-04-09 21:16:0268 private:
[email protected]fbe20372011-06-01 01:46:3869 friend class base::RefCounted<GLContext>;
[email protected]d37231fa2010-04-09 21:16:0270 DISALLOW_COPY_AND_ASSIGN(GLContext);
71};
72
[email protected]5a6db6c2010-04-22 18:32:0673} // namespace gfx
[email protected]d37231fa2010-04-09 21:16:0274
[email protected]5ae0b282011-03-28 19:24:4975#endif // UI_GFX_GL_GL_CONTEXT_H_