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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
13 #include "ui/gl/gl_gl_api_implementation.h" | 13 #include "ui/gl/gl_gl_api_implementation.h" |
14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
16 #include "ui/gl/gl_switches.h" | 16 #include "ui/gl/gl_switches.h" |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 | 19 |
20 namespace { | 20 namespace { |
21 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky | 21 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky |
22 current_context_ = LAZY_INSTANCE_INITIALIZER; | 22 current_context_ = LAZY_INSTANCE_INITIALIZER; |
23 | |
24 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky | |
25 current_real_context_ = LAZY_INSTANCE_INITIALIZER; | |
23 } // namespace | 26 } // namespace |
24 | 27 |
25 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { | 28 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { |
26 if (!share_group_.get()) | 29 if (!share_group_.get()) |
27 share_group_ = new GLShareGroup; | 30 share_group_ = new GLShareGroup; |
28 | 31 |
29 share_group_->AddContext(this); | 32 share_group_->AddContext(this); |
30 } | 33 } |
31 | 34 |
32 GLContext::~GLContext() { | 35 GLContext::~GLContext() { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 default: | 86 default: |
84 NOTREACHED(); | 87 NOTREACHED(); |
85 return true; | 88 return true; |
86 } | 89 } |
87 } | 90 } |
88 | 91 |
89 GLContext* GLContext::GetCurrent() { | 92 GLContext* GLContext::GetCurrent() { |
90 return current_context_.Pointer()->Get(); | 93 return current_context_.Pointer()->Get(); |
91 } | 94 } |
92 | 95 |
96 GLContext* GLContext::GetRealCurrent() { | |
97 return current_real_context_.Pointer()->Get(); | |
98 } | |
99 | |
93 void GLContext::SetCurrent(GLContext* context, GLSurface* surface) { | 100 void GLContext::SetCurrent(GLContext* context, GLSurface* surface) { |
101 if (!context || !context->IsVirtualContext()) { | |
no sievers
2013/05/24 17:04:02
Do we allow SetCurrent(NULL, !NULL)?
Or should we
jonathan.backer
2013/05/24 20:36:40
Yeah. I just looked at the OSX code (which might h
jonathan.backer
2013/05/27 16:37:36
Done.
| |
102 current_real_context_.Pointer()->Set(context); | |
103 GLSurface::SetRealCurrent(surface); | |
104 } | |
94 current_context_.Pointer()->Set(context); | 105 current_context_.Pointer()->Set(context); |
95 GLSurface::SetCurrent(surface); | 106 GLSurface::SetCurrent(surface); |
96 } | 107 } |
97 | 108 |
98 GLStateRestorer* GLContext::GetGLStateRestorer() { | 109 GLStateRestorer* GLContext::GetGLStateRestorer() { |
99 return state_restorer_.get(); | 110 return state_restorer_.get(); |
100 } | 111 } |
101 | 112 |
102 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { | 113 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { |
103 state_restorer_ = make_scoped_ptr(state_restorer); | 114 state_restorer_ = make_scoped_ptr(state_restorer); |
(...skipping 17 matching lines...) Expand all Loading... | |
121 void GLContext::SetupForVirtualization() { | 132 void GLContext::SetupForVirtualization() { |
122 if (!virtual_gl_api_) { | 133 if (!virtual_gl_api_) { |
123 virtual_gl_api_.reset(new VirtualGLApi()); | 134 virtual_gl_api_.reset(new VirtualGLApi()); |
124 virtual_gl_api_->Initialize(&g_driver_gl, this); | 135 virtual_gl_api_->Initialize(&g_driver_gl, this); |
125 } | 136 } |
126 } | 137 } |
127 | 138 |
128 bool GLContext::MakeVirtuallyCurrent( | 139 bool GLContext::MakeVirtuallyCurrent( |
129 GLContext* virtual_context, GLSurface* surface) { | 140 GLContext* virtual_context, GLSurface* surface) { |
130 DCHECK(virtual_gl_api_); | 141 DCHECK(virtual_gl_api_); |
131 return virtual_gl_api_->MakeCurrent(virtual_context, surface); | 142 bool result = virtual_gl_api_->MakeCurrent(virtual_context, surface); |
143 if (result) | |
144 SetCurrent(virtual_context, surface); | |
jonathan.backer
2013/05/23 21:00:53
Maybe SetCurrent(NULL, NULL) otherwise?
| |
145 return result; | |
132 } | 146 } |
133 | 147 |
134 void GLContext::OnDestroyVirtualContext(GLContext* virtual_context) { | 148 void GLContext::OnDestroyVirtualContext(GLContext* virtual_context) { |
135 if (virtual_gl_api_) | 149 if (virtual_gl_api_) |
136 virtual_gl_api_->OnDestroyVirtualContext(virtual_context); | 150 virtual_gl_api_->OnDestroyVirtualContext(virtual_context); |
137 } | 151 } |
138 | 152 |
139 void GLContext::SetRealGLApi() { | 153 void GLContext::SetRealGLApi() { |
140 SetGLToRealGLApi(); | 154 SetGLToRealGLApi(); |
141 } | 155 } |
142 | 156 |
157 bool GLContext::IsVirtualContext() { | |
158 return false; | |
159 } | |
160 | |
143 } // namespace gfx | 161 } // namespace gfx |
OLD | NEW |