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" |
| 8 #include "base/cancelable_callback.h" |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
11 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_context.h" | 14 #include "ui/gl/gl_context.h" |
13 #include "ui/gl/gl_gl_api_implementation.h" | 15 #include "ui/gl/gl_gl_api_implementation.h" |
14 #include "ui/gl/gl_implementation.h" | 16 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_surface.h" | 17 #include "ui/gl/gl_surface.h" |
16 #include "ui/gl/gl_switches.h" | 18 #include "ui/gl/gl_switches.h" |
(...skipping 17 matching lines...) Expand all Loading... |
34 GetCurrent()->ReleaseCurrent(NULL); | 36 GetCurrent()->ReleaseCurrent(NULL); |
35 } | 37 } |
36 } | 38 } |
37 | 39 |
38 void GLContext::ScopedReleaseCurrent::Cancel() { | 40 void GLContext::ScopedReleaseCurrent::Cancel() { |
39 canceled_ = true; | 41 canceled_ = true; |
40 } | 42 } |
41 | 43 |
42 GLContext::GLContext(GLShareGroup* share_group) : | 44 GLContext::GLContext(GLShareGroup* share_group) : |
43 share_group_(share_group), | 45 share_group_(share_group), |
| 46 state_dirtied_externally_(false), |
44 swap_interval_(1), | 47 swap_interval_(1), |
45 force_swap_interval_zero_(false) { | 48 force_swap_interval_zero_(false), |
| 49 state_dirtied_callback_( |
| 50 base::Bind(&GLContext::SetStateWasDirtiedExternally, |
| 51 // Note that if this is not unretained, it will create a cycle (and |
| 52 // will never be freed. |
| 53 base::Unretained(this), |
| 54 true)) { |
46 if (!share_group_.get()) | 55 if (!share_group_.get()) |
47 share_group_ = new GLShareGroup; | 56 share_group_ = new GLShareGroup; |
48 | 57 |
49 share_group_->AddContext(this); | 58 share_group_->AddContext(this); |
50 } | 59 } |
51 | 60 |
52 GLContext::~GLContext() { | 61 GLContext::~GLContext() { |
53 share_group_->RemoveContext(this); | 62 share_group_->RemoveContext(this); |
54 if (GetCurrent() == this) { | 63 if (GetCurrent() == this) { |
55 SetCurrent(NULL); | 64 SetCurrent(NULL); |
(...skipping 30 matching lines...) Expand all Loading... |
86 return std::string(version ? version : ""); | 95 return std::string(version ? version : ""); |
87 } | 96 } |
88 | 97 |
89 std::string GLContext::GetGLRenderer() { | 98 std::string GLContext::GetGLRenderer() { |
90 DCHECK(IsCurrent(NULL)); | 99 DCHECK(IsCurrent(NULL)); |
91 const char *renderer = | 100 const char *renderer = |
92 reinterpret_cast<const char*>(glGetString(GL_RENDERER)); | 101 reinterpret_cast<const char*>(glGetString(GL_RENDERER)); |
93 return std::string(renderer ? renderer : ""); | 102 return std::string(renderer ? renderer : ""); |
94 } | 103 } |
95 | 104 |
| 105 base::Closure GLContext::GetStateWasDirtiedExternallyCallback() { |
| 106 return state_dirtied_callback_.callback(); |
| 107 } |
| 108 |
| 109 void GLContext::RestoreStateIfDirtiedExternally() { |
| 110 NOTREACHED(); |
| 111 } |
| 112 |
| 113 bool GLContext::GetStateWasDirtiedExternally() const { |
| 114 DCHECK(virtual_gl_api_); |
| 115 return state_dirtied_externally_; |
| 116 } |
| 117 |
| 118 void GLContext::SetStateWasDirtiedExternally(bool dirtied_externally) { |
| 119 DCHECK(virtual_gl_api_); |
| 120 state_dirtied_externally_ = dirtied_externally; |
| 121 } |
| 122 |
96 bool GLContext::HasExtension(const char* name) { | 123 bool GLContext::HasExtension(const char* name) { |
97 std::string extensions = GetExtensions(); | 124 std::string extensions = GetExtensions(); |
98 extensions += " "; | 125 extensions += " "; |
99 | 126 |
100 std::string delimited_name(name); | 127 std::string delimited_name(name); |
101 delimited_name += " "; | 128 delimited_name += " "; |
102 | 129 |
103 return extensions.find(delimited_name) != std::string::npos; | 130 return extensions.find(delimited_name) != std::string::npos; |
104 } | 131 } |
105 | 132 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 248 } |
222 | 249 |
223 GLContextReal::~GLContextReal() {} | 250 GLContextReal::~GLContextReal() {} |
224 | 251 |
225 void GLContextReal::SetCurrent(GLSurface* surface) { | 252 void GLContextReal::SetCurrent(GLSurface* surface) { |
226 GLContext::SetCurrent(surface); | 253 GLContext::SetCurrent(surface); |
227 current_real_context_.Pointer()->Set(surface ? this : NULL); | 254 current_real_context_.Pointer()->Set(surface ? this : NULL); |
228 } | 255 } |
229 | 256 |
230 } // namespace gfx | 257 } // namespace gfx |
OLD | NEW |