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 #include "ui/gl/gl_version_info.h" | 17 #include "ui/gl/gl_version_info.h" |
18 | 18 |
19 namespace gfx { | 19 namespace gfx { |
20 | 20 |
21 namespace { | 21 namespace { |
22 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky | 22 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky |
23 current_context_ = LAZY_INSTANCE_INITIALIZER; | 23 current_context_ = LAZY_INSTANCE_INITIALIZER; |
24 | 24 |
25 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky | 25 base::LazyInstance<base::ThreadLocalPointer<GLContext> >::Leaky |
26 current_real_context_ = LAZY_INSTANCE_INITIALIZER; | 26 current_real_context_ = LAZY_INSTANCE_INITIALIZER; |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 GLContext::FlushEvent::FlushEvent() { | |
30 } | |
31 | |
32 GLContext::FlushEvent::~FlushEvent() { | |
33 } | |
34 | |
35 void GLContext::FlushEvent::Signal() { | |
36 flag_.Set(); | |
37 } | |
38 | |
39 bool GLContext::FlushEvent::IsSignaled() { | |
40 return flag_.IsSet(); | |
41 } | |
42 | |
43 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { | 29 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { |
44 if (!share_group_.get()) | 30 if (!share_group_.get()) |
45 share_group_ = new GLShareGroup; | 31 share_group_ = new GLShareGroup; |
46 | 32 |
47 share_group_->AddContext(this); | 33 share_group_->AddContext(this); |
48 } | 34 } |
49 | 35 |
50 GLContext::~GLContext() { | 36 GLContext::~GLContext() { |
51 share_group_->RemoveContext(this); | 37 share_group_->RemoveContext(this); |
52 if (GetCurrent() == this) { | 38 if (GetCurrent() == this) { |
53 SetCurrent(NULL); | 39 SetCurrent(NULL); |
54 } | 40 } |
55 } | 41 } |
56 | 42 |
57 scoped_refptr<GLContext::FlushEvent> GLContext::SignalFlush() { | |
58 DCHECK(IsCurrent(NULL)); | |
59 scoped_refptr<FlushEvent> flush_event = new FlushEvent(); | |
60 flush_events_.push_back(flush_event); | |
61 return flush_event; | |
62 } | |
63 | |
64 bool GLContext::GetTotalGpuMemory(size_t* bytes) { | 43 bool GLContext::GetTotalGpuMemory(size_t* bytes) { |
65 DCHECK(bytes); | 44 DCHECK(bytes); |
66 *bytes = 0; | 45 *bytes = 0; |
67 return false; | 46 return false; |
68 } | 47 } |
69 | 48 |
70 void GLContext::SetSafeToForceGpuSwitch() { | 49 void GLContext::SetSafeToForceGpuSwitch() { |
71 } | 50 } |
72 | 51 |
73 void GLContext::SetUnbindFboOnMakeCurrent() { | 52 void GLContext::SetUnbindFboOnMakeCurrent() { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 165 |
187 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { | 166 void GLContext::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { |
188 if (virtual_gl_api_) | 167 if (virtual_gl_api_) |
189 virtual_gl_api_->OnReleaseVirtuallyCurrent(virtual_context); | 168 virtual_gl_api_->OnReleaseVirtuallyCurrent(virtual_context); |
190 } | 169 } |
191 | 170 |
192 void GLContext::SetRealGLApi() { | 171 void GLContext::SetRealGLApi() { |
193 SetGLToRealGLApi(); | 172 SetGLToRealGLApi(); |
194 } | 173 } |
195 | 174 |
196 void GLContext::OnFlush() { | |
197 for (size_t n = 0; n < flush_events_.size(); n++) | |
198 flush_events_[n]->Signal(); | |
199 flush_events_.clear(); | |
200 } | |
201 | |
202 GLContextReal::GLContextReal(GLShareGroup* share_group) | 175 GLContextReal::GLContextReal(GLShareGroup* share_group) |
203 : GLContext(share_group) {} | 176 : GLContext(share_group) {} |
204 | 177 |
205 GLContextReal::~GLContextReal() {} | 178 GLContextReal::~GLContextReal() {} |
206 | 179 |
207 void GLContextReal::SetCurrent(GLSurface* surface) { | 180 void GLContextReal::SetCurrent(GLSurface* surface) { |
208 GLContext::SetCurrent(surface); | 181 GLContext::SetCurrent(surface); |
209 current_real_context_.Pointer()->Set(surface ? this : NULL); | 182 current_real_context_.Pointer()->Set(surface ? this : NULL); |
210 } | 183 } |
211 | 184 |
212 } // namespace gfx | 185 } // namespace gfx |
OLD | NEW |