blob: f39a77ac740ead20fd1ebfbd5c9ff205985df477 [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]4bedba72010-04-20 22:08:5411#include "build/build_config.h"
[email protected]08397d52011-02-05 01:53:3812#include "ui/gfx/native_widget_types.h"
13#include "ui/gfx/size.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]d37231fa2010-04-09 21:16:0217// Encapsulates an OpenGL context, hiding platform specific management.
18class GLContext {
19 public:
[email protected]5a6db6c2010-04-22 18:32:0620 GLContext() {}
21 virtual ~GLContext() {}
[email protected]d37231fa2010-04-09 21:16:0222
23 // Destroys the GL context.
24 virtual void Destroy() = 0;
25
26 // Makes the GL context current on the current thread.
27 virtual bool MakeCurrent() = 0;
28
[email protected]7d9ce4f2010-04-14 18:39:4029 // Returns true if this context is current.
30 virtual bool IsCurrent() = 0;
31
[email protected]d37231fa2010-04-09 21:16:0232 // Returns true if this context is offscreen.
33 virtual bool IsOffscreen() = 0;
34
35 // Swaps front and back buffers. This has no effect for off-screen
36 // contexts.
[email protected]5259ead82010-09-10 18:02:0237 virtual bool SwapBuffers() = 0;
[email protected]d37231fa2010-04-09 21:16:0238
39 // Get the size of the back buffer.
40 virtual gfx::Size GetSize() = 0;
41
42 // Get the underlying platform specific GL context "handle".
[email protected]4bedba72010-04-20 22:08:5443 virtual void* GetHandle() = 0;
44
[email protected]1c0585d2010-10-07 23:19:1645 // Set swap interval. This context must be current.
46 virtual void SetSwapInterval(int interval) = 0;
47
[email protected]eff9a222010-12-21 21:48:5648 // Returns the internal frame buffer object name if the context is backed by
49 // FBO. Otherwise returns 0.
50 virtual unsigned int GetBackingFrameBufferObject();
51
[email protected]1c0585d2010-10-07 23:19:1652 // Returns space separated list of extensions. The context must be current.
53 virtual std::string GetExtensions();
54
[email protected]876f6fee2010-08-02 23:10:3255 // Returns whether the current context supports the named extension. The
56 // context must be current.
[email protected]1c0585d2010-10-07 23:19:1657 bool HasExtension(const char* name);
[email protected]876f6fee2010-08-02 23:10:3258
[email protected]30aa5c1a2010-07-14 20:47:0459 static bool InitializeOneOff();
60
[email protected]4bedba72010-04-20 22:08:5461#if !defined(OS_MACOSX)
62 // Create a GL context that renders directly to a view.
63 static GLContext* CreateViewGLContext(gfx::PluginWindowHandle window,
64 bool multisampled);
65#endif
66
67 // Create a GL context used for offscreen rendering. It is initially backed by
68 // a 1x1 pbuffer. Use it to create an FBO to do useful rendering.
[email protected]dc57aa982010-06-15 21:54:0269 // |share_context|, if non-NULL, is a context which the internally created
70 // OpenGL context shares textures and other resources.
[email protected]b9363b22010-06-09 22:06:1571 static GLContext* CreateOffscreenGLContext(GLContext* shared_context);
[email protected]d37231fa2010-04-09 21:16:0272
[email protected]0fc35742011-04-13 17:57:5473 static bool LosesAllContextsOnContextLost();
74
[email protected]2f2d7042010-04-14 21:45:5875 protected:
76 bool InitializeCommon();
77
[email protected]d37231fa2010-04-09 21:16:0278 private:
79 DISALLOW_COPY_AND_ASSIGN(GLContext);
80};
81
[email protected]5a6db6c2010-04-22 18:32:0682} // namespace gfx
[email protected]d37231fa2010-04-09 21:16:0283
[email protected]5ae0b282011-03-28 19:24:4984#endif // UI_GFX_GL_GL_CONTEXT_H_