| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/cancelable_callback.h" | 8 #include "base/cancelable_callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 GLContext::ScopedReleaseCurrent::~ScopedReleaseCurrent() { | 35 GLContext::ScopedReleaseCurrent::~ScopedReleaseCurrent() { |
| 36 if (!canceled_ && GetCurrent()) { | 36 if (!canceled_ && GetCurrent()) { |
| 37 GetCurrent()->ReleaseCurrent(nullptr); | 37 GetCurrent()->ReleaseCurrent(nullptr); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 void GLContext::ScopedReleaseCurrent::Cancel() { | 41 void GLContext::ScopedReleaseCurrent::Cancel() { |
| 42 canceled_ = true; | 42 canceled_ = true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 GLContext::GLContext(GLShareGroup* share_group) : | 45 GLContext::GLContext(GLShareGroup* share_group) |
| 46 share_group_(share_group), | 46 : share_group_(share_group), |
| 47 state_dirtied_externally_(false), | 47 state_dirtied_externally_(false), |
| 48 swap_interval_(1), | 48 swap_interval_(1), |
| 49 force_swap_interval_zero_(false), | 49 force_swap_interval_zero_(false) { |
| 50 state_dirtied_callback_( | |
| 51 base::Bind(&GLContext::SetStateWasDirtiedExternally, | |
| 52 // Note that if this is not unretained, it will create a cycle (and | |
| 53 // will never be freed. | |
| 54 base::Unretained(this), | |
| 55 true)) { | |
| 56 if (!share_group_.get()) | 50 if (!share_group_.get()) |
| 57 share_group_ = new GLShareGroup; | 51 share_group_ = new GLShareGroup; |
| 58 | 52 |
| 59 share_group_->AddContext(this); | 53 share_group_->AddContext(this); |
| 60 } | 54 } |
| 61 | 55 |
| 62 GLContext::~GLContext() { | 56 GLContext::~GLContext() { |
| 63 share_group_->RemoveContext(this); | 57 share_group_->RemoveContext(this); |
| 64 if (GetCurrent() == this) { | 58 if (GetCurrent() == this) { |
| 65 SetCurrent(nullptr); | 59 SetCurrent(nullptr); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 89 return std::string(version ? version : ""); | 83 return std::string(version ? version : ""); |
| 90 } | 84 } |
| 91 | 85 |
| 92 std::string GLContext::GetGLRenderer() { | 86 std::string GLContext::GetGLRenderer() { |
| 93 DCHECK(IsCurrent(nullptr)); | 87 DCHECK(IsCurrent(nullptr)); |
| 94 const char *renderer = | 88 const char *renderer = |
| 95 reinterpret_cast<const char*>(glGetString(GL_RENDERER)); | 89 reinterpret_cast<const char*>(glGetString(GL_RENDERER)); |
| 96 return std::string(renderer ? renderer : ""); | 90 return std::string(renderer ? renderer : ""); |
| 97 } | 91 } |
| 98 | 92 |
| 99 base::Closure GLContext::GetStateWasDirtiedExternallyCallback() { | |
| 100 return state_dirtied_callback_.callback(); | |
| 101 } | |
| 102 | |
| 103 void GLContext::RestoreStateIfDirtiedExternally() { | |
| 104 NOTREACHED(); | |
| 105 } | |
| 106 | |
| 107 bool GLContext::GetStateWasDirtiedExternally() const { | |
| 108 DCHECK(virtual_gl_api_); | |
| 109 return state_dirtied_externally_; | |
| 110 } | |
| 111 | |
| 112 void GLContext::SetStateWasDirtiedExternally(bool dirtied_externally) { | |
| 113 DCHECK(virtual_gl_api_); | |
| 114 state_dirtied_externally_ = dirtied_externally; | |
| 115 } | |
| 116 | |
| 117 bool GLContext::HasExtension(const char* name) { | 93 bool GLContext::HasExtension(const char* name) { |
| 118 std::string extensions = GetExtensions(); | 94 std::string extensions = GetExtensions(); |
| 119 extensions += " "; | 95 extensions += " "; |
| 120 | 96 |
| 121 std::string delimited_name(name); | 97 std::string delimited_name(name); |
| 122 delimited_name += " "; | 98 delimited_name += " "; |
| 123 | 99 |
| 124 return extensions.find(delimited_name) != std::string::npos; | 100 return extensions.find(delimited_name) != std::string::npos; |
| 125 } | 101 } |
| 126 | 102 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 217 } |
| 242 | 218 |
| 243 GLContextReal::~GLContextReal() {} | 219 GLContextReal::~GLContextReal() {} |
| 244 | 220 |
| 245 void GLContextReal::SetCurrent(GLSurface* surface) { | 221 void GLContextReal::SetCurrent(GLSurface* surface) { |
| 246 GLContext::SetCurrent(surface); | 222 GLContext::SetCurrent(surface); |
| 247 current_real_context_.Pointer()->Set(surface ? this : nullptr); | 223 current_real_context_.Pointer()->Set(surface ? this : nullptr); |
| 248 } | 224 } |
| 249 | 225 |
| 250 } // namespace gfx | 226 } // namespace gfx |
| OLD | NEW |