[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 5 | #ifndef UI_GFX_GL_GL_CONTEXT_H_ |
6 | #define UI_GFX_GL_GL_CONTEXT_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 8 | |
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 9 | #include <string> |
10 | |||||
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 11 | #include "build/build_config.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 12 | #include "ui/gfx/native_widget_types.h" |
13 | #include "ui/gfx/size.h" | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 14 | |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 15 | namespace gfx { |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 16 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 17 | // Encapsulates an OpenGL context, hiding platform specific management. |
18 | class GLContext { | ||||
19 | public: | ||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 20 | GLContext() {} |
21 | virtual ~GLContext() {} | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 22 | |
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] | 7d9ce4f | 2010-04-14 18:39:40 | [diff] [blame] | 29 | // Returns true if this context is current. |
30 | virtual bool IsCurrent() = 0; | ||||
31 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 32 | // 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] | 5259ead8 | 2010-09-10 18:02:02 | [diff] [blame] | 37 | virtual bool SwapBuffers() = 0; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 38 | |
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] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 43 | virtual void* GetHandle() = 0; |
44 | |||||
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 45 | // Set swap interval. This context must be current. |
46 | virtual void SetSwapInterval(int interval) = 0; | ||||
47 | |||||
[email protected] | eff9a22 | 2010-12-21 21:48:56 | [diff] [blame] | 48 | // 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] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 52 | // Returns space separated list of extensions. The context must be current. |
53 | virtual std::string GetExtensions(); | ||||
54 | |||||
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 55 | // Returns whether the current context supports the named extension. The |
56 | // context must be current. | ||||
[email protected] | 1c0585d | 2010-10-07 23:19:16 | [diff] [blame] | 57 | bool HasExtension(const char* name); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 58 | |
[email protected] | 30aa5c1a | 2010-07-14 20:47:04 | [diff] [blame] | 59 | static bool InitializeOneOff(); |
60 | |||||
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 61 | #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] | dc57aa98 | 2010-06-15 21:54:02 | [diff] [blame] | 69 | // |share_context|, if non-NULL, is a context which the internally created |
70 | // OpenGL context shares textures and other resources. | ||||
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 71 | static GLContext* CreateOffscreenGLContext(GLContext* shared_context); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 72 | |
[email protected] | 0fc3574 | 2011-04-13 17:57:54 | [diff] [blame^] | 73 | static bool LosesAllContextsOnContextLost(); |
74 | |||||
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 75 | protected: |
76 | bool InitializeCommon(); | ||||
77 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 78 | private: |
79 | DISALLOW_COPY_AND_ASSIGN(GLContext); | ||||
80 | }; | ||||
81 | |||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 82 | } // namespace gfx |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 83 | |
[email protected] | 5ae0b28 | 2011-03-28 19:24:49 | [diff] [blame] | 84 | #endif // UI_GFX_GL_GL_CONTEXT_H_ |