| 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::ScopedReleaseCurrent::ScopedReleaseCurrent() : canceled_(false) {} |
| 30 |
| 31 GLContext::ScopedReleaseCurrent::~ScopedReleaseCurrent() { |
| 32 if (!canceled_ && GetCurrent()) { |
| 33 GetCurrent()->ReleaseCurrent(NULL); |
| 34 } |
| 35 } |
| 36 |
| 37 void GLContext::ScopedReleaseCurrent::Cancel() { |
| 38 canceled_ = true; |
| 39 } |
| 40 |
| 29 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { | 41 GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { |
| 30 if (!share_group_.get()) | 42 if (!share_group_.get()) |
| 31 share_group_ = new GLShareGroup; | 43 share_group_ = new GLShareGroup; |
| 32 | 44 |
| 33 share_group_->AddContext(this); | 45 share_group_->AddContext(this); |
| 34 } | 46 } |
| 35 | 47 |
| 36 GLContext::~GLContext() { | 48 GLContext::~GLContext() { |
| 37 share_group_->RemoveContext(this); | 49 share_group_->RemoveContext(this); |
| 38 if (GetCurrent() == this) { | 50 if (GetCurrent() == this) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return current_context_.Pointer()->Get(); | 130 return current_context_.Pointer()->Get(); |
| 119 } | 131 } |
| 120 | 132 |
| 121 GLContext* GLContext::GetRealCurrent() { | 133 GLContext* GLContext::GetRealCurrent() { |
| 122 return current_real_context_.Pointer()->Get(); | 134 return current_real_context_.Pointer()->Get(); |
| 123 } | 135 } |
| 124 | 136 |
| 125 void GLContext::SetCurrent(GLSurface* surface) { | 137 void GLContext::SetCurrent(GLSurface* surface) { |
| 126 current_context_.Pointer()->Set(surface ? this : NULL); | 138 current_context_.Pointer()->Set(surface ? this : NULL); |
| 127 GLSurface::SetCurrent(surface); | 139 GLSurface::SetCurrent(surface); |
| 140 if (!surface) |
| 141 SetGLApiToNoContext(); |
| 128 } | 142 } |
| 129 | 143 |
| 130 GLStateRestorer* GLContext::GetGLStateRestorer() { | 144 GLStateRestorer* GLContext::GetGLStateRestorer() { |
| 131 return state_restorer_.get(); | 145 return state_restorer_.get(); |
| 132 } | 146 } |
| 133 | 147 |
| 134 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { | 148 void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) { |
| 135 state_restorer_ = make_scoped_ptr(state_restorer); | 149 state_restorer_ = make_scoped_ptr(state_restorer); |
| 136 } | 150 } |
| 137 | 151 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 : GLContext(share_group) {} | 190 : GLContext(share_group) {} |
| 177 | 191 |
| 178 GLContextReal::~GLContextReal() {} | 192 GLContextReal::~GLContextReal() {} |
| 179 | 193 |
| 180 void GLContextReal::SetCurrent(GLSurface* surface) { | 194 void GLContextReal::SetCurrent(GLSurface* surface) { |
| 181 GLContext::SetCurrent(surface); | 195 GLContext::SetCurrent(surface); |
| 182 current_real_context_.Pointer()->Set(surface ? this : NULL); | 196 current_real_context_.Pointer()->Set(surface ? this : NULL); |
| 183 } | 197 } |
| 184 | 198 |
| 185 } // namespace gfx | 199 } // namespace gfx |
| OLD | NEW |