[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [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] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 5 | #ifndef UI_GL_GL_SHARE_GROUP_H_ |
6 | #define UI_GL_GL_SHARE_GROUP_H_ | ||||
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 7 | |
8 | #include <set> | ||||
thomasanderson | 62ba78ff | 2016-10-01 02:03:42 | [diff] [blame] | 9 | #include <unordered_map> |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 10 | |
avi | 739878c | 2015-12-24 18:06:17 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
avi | 739878c | 2015-12-24 18:06:17 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 14 | #include "ui/gl/gl_export.h" |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 15 | |
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 16 | namespace gl { |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 17 | |
18 | class GLContext; | ||||
thomasanderson | 62ba78ff | 2016-10-01 02:03:42 | [diff] [blame] | 19 | class GLSurface; |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 20 | |
21 | // A group of GL contexts that share an ID namespace. | ||||
[email protected] | fe377e1 | 2011-08-18 17:37:36 | [diff] [blame] | 22 | class GL_EXPORT GLShareGroup : public base::RefCounted<GLShareGroup> { |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 23 | public: |
24 | GLShareGroup(); | ||||
25 | |||||
26 | // These two should only be called from the constructor and destructor of | ||||
27 | // GLContext. | ||||
28 | void AddContext(GLContext* context); | ||||
29 | void RemoveContext(GLContext* context); | ||||
30 | |||||
31 | // Returns a handle to any initialized context in the share group or NULL if | ||||
32 | // there are no initialized contexts in the share group. | ||||
33 | void* GetHandle(); | ||||
34 | |||||
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 35 | // Returns a pointer to any initialized context in the share group |
36 | // or NULL if there are no initialized contexts in the share group. | ||||
37 | GLContext* GetContext(); | ||||
38 | |||||
thomasanderson | 62ba78ff | 2016-10-01 02:03:42 | [diff] [blame] | 39 | // Sets and returns the shared GL context. Used for context virtualization. |
40 | void SetSharedContext(GLSurface* compatible, GLContext* context); | ||||
41 | GLContext* GetSharedContext(GLSurface* compatible); | ||||
[email protected] | ee1e6aa | 2012-11-29 09:24:10 | [diff] [blame] | 42 | |
[email protected] | cd195afe | 2013-03-06 09:31:37 | [diff] [blame] | 43 | #if defined(OS_MACOSX) |
44 | // Sets and returns the ID of the renderer that all contexts in this share | ||||
45 | // group should be on. | ||||
46 | void SetRendererID(int renderer_id); | ||||
47 | int GetRendererID(); | ||||
48 | #endif | ||||
49 | |||||
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 50 | private: |
51 | friend class base::RefCounted<GLShareGroup>; | ||||
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 52 | |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 53 | ~GLShareGroup(); |
54 | |||||
55 | // References to GLContext are by raw pointer to avoid a reference count | ||||
56 | // cycle. | ||||
57 | typedef std::set<GLContext*> ContextSet; | ||||
58 | ContextSet contexts_; | ||||
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 59 | |
thomasanderson | 62ba78ff | 2016-10-01 02:03:42 | [diff] [blame] | 60 | std::unordered_map<unsigned long, GLContext*> shared_contexts_; |
[email protected] | ee1e6aa | 2012-11-29 09:24:10 | [diff] [blame] | 61 | |
[email protected] | cd195afe | 2013-03-06 09:31:37 | [diff] [blame] | 62 | #if defined(OS_MACOSX) |
63 | int renderer_id_; | ||||
64 | #endif | ||||
65 | |||||
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 66 | DISALLOW_COPY_AND_ASSIGN(GLShareGroup); |
67 | }; | ||||
68 | |||||
kylechar | 7a46384 | 2016-05-26 14:46:12 | [diff] [blame] | 69 | } // namespace gl |
[email protected] | 7196e01 | 2011-06-16 20:54:53 | [diff] [blame] | 70 | |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 71 | #endif // UI_GL_GL_SHARE_GROUP_H_ |