OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_share_group.h" | 5 #include "ui/gl/gl_share_group.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "ui/gl/gl_context.h" | 9 #include "ui/gl/gl_context.h" |
| 10 #include "ui/gl/gl_implementation.h" |
| 11 #include "ui/gl/gl_surface.h" |
10 | 12 |
11 namespace gl { | 13 namespace gl { |
12 | 14 |
13 GLShareGroup::GLShareGroup() | 15 GLShareGroup::GLShareGroup() |
14 : shared_context_(NULL) | |
15 #if defined(OS_MACOSX) | 16 #if defined(OS_MACOSX) |
16 , renderer_id_(-1) | 17 : renderer_id_(-1) |
17 #endif | 18 #endif |
18 { | 19 { |
19 } | 20 } |
20 | 21 |
21 void GLShareGroup::AddContext(GLContext* context) { | 22 void GLShareGroup::AddContext(GLContext* context) { |
22 contexts_.insert(context); | 23 contexts_.insert(context); |
23 } | 24 } |
24 | 25 |
25 void GLShareGroup::RemoveContext(GLContext* context) { | 26 void GLShareGroup::RemoveContext(GLContext* context) { |
26 contexts_.erase(context); | 27 contexts_.erase(context); |
27 if (shared_context_ == context) | 28 for (const auto& pair : shared_contexts_) { |
28 shared_context_ = NULL; | 29 if (pair.second == context) { |
| 30 shared_contexts_.erase(pair.first); |
| 31 return; |
| 32 } |
| 33 } |
29 } | 34 } |
30 | 35 |
31 void* GLShareGroup::GetHandle() { | 36 void* GLShareGroup::GetHandle() { |
32 GLContext* context = GetContext(); | 37 GLContext* context = GetContext(); |
33 if (context) | 38 if (context) |
34 return context->GetHandle(); | 39 return context->GetHandle(); |
35 | 40 |
36 return NULL; | 41 return NULL; |
37 } | 42 } |
38 | 43 |
39 GLContext* GLShareGroup::GetContext() { | 44 GLContext* GLShareGroup::GetContext() { |
40 for (ContextSet::iterator it = contexts_.begin(); | 45 for (ContextSet::iterator it = contexts_.begin(); |
41 it != contexts_.end(); | 46 it != contexts_.end(); |
42 ++it) { | 47 ++it) { |
43 if ((*it)->GetHandle()) | 48 if ((*it)->GetHandle()) |
44 return *it; | 49 return *it; |
45 } | 50 } |
46 | 51 |
47 return NULL; | 52 return NULL; |
48 } | 53 } |
49 | 54 |
50 void GLShareGroup::SetSharedContext(GLContext* context) { | 55 void GLShareGroup::SetSharedContext(GLSurface* compatible, GLContext* context) { |
51 DCHECK(contexts_.find(context) != contexts_.end()); | 56 DCHECK(contexts_.find(context) != contexts_.end()); |
52 shared_context_ = context; | 57 shared_contexts_[compatible->GetCompatibilityKey()] = context; |
53 } | 58 } |
54 | 59 |
55 GLContext* GLShareGroup::GetSharedContext() { | 60 GLContext* GLShareGroup::GetSharedContext(GLSurface* compatible) { |
56 return shared_context_; | 61 unsigned long compatibility_key = compatible->GetCompatibilityKey(); |
| 62 auto it = shared_contexts_.find(compatibility_key); |
| 63 if (it == shared_contexts_.end()) |
| 64 return nullptr; |
| 65 return it->second; |
57 } | 66 } |
58 | 67 |
59 #if defined(OS_MACOSX) | 68 #if defined(OS_MACOSX) |
60 void GLShareGroup::SetRendererID(int renderer_id) { | 69 void GLShareGroup::SetRendererID(int renderer_id) { |
61 renderer_id_ = renderer_id; | 70 renderer_id_ = renderer_id; |
62 } | 71 } |
63 | 72 |
64 int GLShareGroup::GetRendererID() { | 73 int GLShareGroup::GetRendererID() { |
65 return renderer_id_; | 74 return renderer_id_; |
66 } | 75 } |
67 #endif | 76 #endif |
68 | 77 |
69 GLShareGroup::~GLShareGroup() { | 78 GLShareGroup::~GLShareGroup() { |
70 } | 79 } |
71 | 80 |
72 } // namespace gl | 81 } // namespace gl |
OLD | NEW |