[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
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] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 5 | #ifndef APP_GFX_GL_GL_CONTEXT_H_ |
6 | #define APP_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] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 9 | #include "base/logging.h" |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 11 | #include "gfx/native_widget_types.h" |
12 | #include "gfx/size.h" | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 13 | |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 14 | namespace gfx { |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 15 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 16 | // Encapsulates an OpenGL context, hiding platform specific management. |
17 | class GLContext { | ||||
18 | public: | ||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 19 | GLContext() {} |
20 | virtual ~GLContext() {} | ||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 21 | |
22 | // Destroys the GL context. | ||||
23 | virtual void Destroy() = 0; | ||||
24 | |||||
25 | // Makes the GL context current on the current thread. | ||||
26 | virtual bool MakeCurrent() = 0; | ||||
27 | |||||
[email protected] | 7d9ce4f | 2010-04-14 18:39:40 | [diff] [blame] | 28 | // Returns true if this context is current. |
29 | virtual bool IsCurrent() = 0; | ||||
30 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 31 | // Returns true if this context is offscreen. |
32 | virtual bool IsOffscreen() = 0; | ||||
33 | |||||
34 | // Swaps front and back buffers. This has no effect for off-screen | ||||
35 | // contexts. | ||||
36 | virtual void SwapBuffers() = 0; | ||||
37 | |||||
38 | // Get the size of the back buffer. | ||||
39 | virtual gfx::Size GetSize() = 0; | ||||
40 | |||||
41 | // Get the underlying platform specific GL context "handle". | ||||
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 42 | virtual void* GetHandle() = 0; |
43 | |||||
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame^] | 44 | // Returns whether the current context supports the named extension. The |
45 | // context must be current. | ||||
46 | virtual bool HasExtension(const char* name); | ||||
47 | |||||
[email protected] | 30aa5c1a | 2010-07-14 20:47:04 | [diff] [blame] | 48 | static bool InitializeOneOff(); |
49 | |||||
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 50 | #if !defined(OS_MACOSX) |
51 | // Create a GL context that renders directly to a view. | ||||
52 | static GLContext* CreateViewGLContext(gfx::PluginWindowHandle window, | ||||
53 | bool multisampled); | ||||
54 | #endif | ||||
55 | |||||
56 | // Create a GL context used for offscreen rendering. It is initially backed by | ||||
57 | // a 1x1 pbuffer. Use it to create an FBO to do useful rendering. | ||||
[email protected] | dc57aa98 | 2010-06-15 21:54:02 | [diff] [blame] | 58 | // |share_context|, if non-NULL, is a context which the internally created |
59 | // OpenGL context shares textures and other resources. | ||||
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 60 | static GLContext* CreateOffscreenGLContext(GLContext* shared_context); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 61 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 62 | protected: |
63 | bool InitializeCommon(); | ||||
64 | |||||
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 65 | private: |
66 | DISALLOW_COPY_AND_ASSIGN(GLContext); | ||||
67 | }; | ||||
68 | |||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 69 | } // namespace gfx |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 70 | |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 71 | #endif // APP_GFX_GL_GL_CONTEXT_H_ |