blob: 99ce887d9e26ba57bbd673e80a4a0e72984084d5 [file] [log] [blame]
[email protected]c9e2cbbb2012-05-12 21:17:271// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7196e012011-06-16 20:54:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]c9e2cbbb2012-05-12 21:17:275#ifndef UI_GL_GL_SHARE_GROUP_H_
6#define UI_GL_GL_SHARE_GROUP_H_
[email protected]7196e012011-06-16 20:54:537
8#include <set>
thomasanderson62ba78ff2016-10-01 02:03:429#include <unordered_map>
[email protected]7196e012011-06-16 20:54:5310
avi739878c2015-12-24 18:06:1711#include "base/macros.h"
[email protected]7196e012011-06-16 20:54:5312#include "base/memory/ref_counted.h"
avi739878c2015-12-24 18:06:1713#include "build/build_config.h"
[email protected]c9e2cbbb2012-05-12 21:17:2714#include "ui/gl/gl_export.h"
[email protected]7196e012011-06-16 20:54:5315
kylechar7a463842016-05-26 14:46:1216namespace gl {
[email protected]7196e012011-06-16 20:54:5317
18class GLContext;
thomasanderson62ba78ff2016-10-01 02:03:4219class GLSurface;
[email protected]7196e012011-06-16 20:54:5320
21// A group of GL contexts that share an ID namespace.
[email protected]fe377e12011-08-18 17:37:3622class GL_EXPORT GLShareGroup : public base::RefCounted<GLShareGroup> {
[email protected]7196e012011-06-16 20:54:5323 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]276f89062011-10-13 22:55:5035 // 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
thomasanderson62ba78ff2016-10-01 02:03:4239 // 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]ee1e6aa2012-11-29 09:24:1042
[email protected]cd195afe2013-03-06 09:31:3743#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]7196e012011-06-16 20:54:5350 private:
51 friend class base::RefCounted<GLShareGroup>;
[email protected]c9e2cbbb2012-05-12 21:17:2752
[email protected]7196e012011-06-16 20:54:5353 ~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]c9e2cbbb2012-05-12 21:17:2759
thomasanderson62ba78ff2016-10-01 02:03:4260 std::unordered_map<unsigned long, GLContext*> shared_contexts_;
[email protected]ee1e6aa2012-11-29 09:24:1061
[email protected]cd195afe2013-03-06 09:31:3762#if defined(OS_MACOSX)
63 int renderer_id_;
64#endif
65
[email protected]7196e012011-06-16 20:54:5366 DISALLOW_COPY_AND_ASSIGN(GLShareGroup);
67};
68
kylechar7a463842016-05-26 14:46:1269} // namespace gl
[email protected]7196e012011-06-16 20:54:5370
[email protected]c9e2cbbb2012-05-12 21:17:2771#endif // UI_GL_GL_SHARE_GROUP_H_