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 "gpu/command_buffer/service/context_group.h" | 5 #include "gpu/command_buffer/service/context_group.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 decoders_.push_back(base::AsWeakPtr<GLES2Decoder>(decoder)); | 235 decoders_.push_back(base::AsWeakPtr<GLES2Decoder>(decoder)); |
236 return true; | 236 return true; |
237 } | 237 } |
238 | 238 |
239 namespace { | 239 namespace { |
240 | 240 |
241 bool IsNull(const base::WeakPtr<gles2::GLES2Decoder>& decoder) { | 241 bool IsNull(const base::WeakPtr<gles2::GLES2Decoder>& decoder) { |
242 return !decoder.get(); | 242 return !decoder.get(); |
243 } | 243 } |
244 | 244 |
| 245 template <typename T> |
| 246 class WeakPtrEquals { |
| 247 public: |
| 248 explicit WeakPtrEquals(T* t) : t_(t) {} |
| 249 |
| 250 bool operator()(const base::WeakPtr<T>& t) { |
| 251 return t.get() == t_; |
| 252 } |
| 253 |
| 254 private: |
| 255 T* const t_; |
| 256 }; |
| 257 |
245 } // namespace anonymous | 258 } // namespace anonymous |
246 | 259 |
247 bool ContextGroup::HaveContexts() { | 260 bool ContextGroup::HaveContexts() { |
248 decoders_.erase(std::remove_if(decoders_.begin(), decoders_.end(), IsNull), | 261 decoders_.erase(std::remove_if(decoders_.begin(), decoders_.end(), IsNull), |
249 decoders_.end()); | 262 decoders_.end()); |
250 return !decoders_.empty(); | 263 return !decoders_.empty(); |
251 } | 264 } |
252 | 265 |
253 void ContextGroup::Destroy(GLES2Decoder* decoder, bool have_context) { | 266 void ContextGroup::Destroy(GLES2Decoder* decoder, bool have_context) { |
254 decoders_.erase(std::remove(decoders_.begin(), decoders_.end(), | 267 decoders_.erase(std::remove_if(decoders_.begin(), decoders_.end(), |
255 decoder->AsWeakPtr()), | 268 WeakPtrEquals<gles2::GLES2Decoder>(decoder)), |
256 decoders_.end()); | 269 decoders_.end()); |
257 // If we still have contexts do nothing. | 270 // If we still have contexts do nothing. |
258 if (HaveContexts()) { | 271 if (HaveContexts()) { |
259 return; | 272 return; |
260 } | 273 } |
261 | 274 |
262 if (buffer_manager_ != NULL) { | 275 if (buffer_manager_ != NULL) { |
263 buffer_manager_->Destroy(have_context); | 276 buffer_manager_->Destroy(have_context); |
264 buffer_manager_.reset(); | 277 buffer_manager_.reset(); |
265 } | 278 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 GLenum pname, GLint min_required, uint32* v) { | 367 GLenum pname, GLint min_required, uint32* v) { |
355 uint32 value = 0; | 368 uint32 value = 0; |
356 GetIntegerv(pname, &value); | 369 GetIntegerv(pname, &value); |
357 bool result = CheckGLFeatureU(min_required, &value); | 370 bool result = CheckGLFeatureU(min_required, &value); |
358 *v = value; | 371 *v = value; |
359 return result; | 372 return result; |
360 } | 373 } |
361 | 374 |
362 } // namespace gles2 | 375 } // namespace gles2 |
363 } // namespace gpu | 376 } // namespace gpu |
OLD | NEW |