OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/renderer/gpu/render_widget_compositor.h" | 5 #include "content/renderer/gpu/render_widget_compositor.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 scoped_refptr<cc::ContextProvider> | 463 scoped_refptr<cc::ContextProvider> |
464 RenderWidgetCompositor::OffscreenContextProviderForMainThread() { | 464 RenderWidgetCompositor::OffscreenContextProviderForMainThread() { |
465 if (!contexts_main_thread_) | 465 if (!contexts_main_thread_) |
466 contexts_main_thread_ = new MainThreadContextProvider; | 466 contexts_main_thread_ = new MainThreadContextProvider; |
467 return contexts_main_thread_; | 467 return contexts_main_thread_; |
468 } | 468 } |
469 | 469 |
470 class RenderWidgetCompositor::CompositorThreadContextProvider | 470 class RenderWidgetCompositor::CompositorThreadContextProvider |
471 : public cc::ContextProvider { | 471 : public cc::ContextProvider { |
472 public: | 472 public: |
473 CompositorThreadContextProvider() : destroyed_(false) {} | 473 CompositorThreadContextProvider() : initialized_(false), destroyed_(false) {} |
474 | 474 |
475 virtual bool InitializeOnMainThread() OVERRIDE { | 475 virtual bool InitializeOnMainThread() OVERRIDE { |
476 return WebKit::WebSharedGraphicsContext3D::createCompositorThreadContext(); | 476 if (!initialized_) { |
| 477 initialized_ = |
| 478 WebKit::WebSharedGraphicsContext3D::createCompositorThreadContext(); |
| 479 } |
| 480 return initialized_; |
477 } | 481 } |
478 virtual bool BindToCurrentThread() OVERRIDE { | 482 virtual bool BindToCurrentThread() OVERRIDE { |
479 return Context3d()->makeContextCurrent(); | 483 return Context3d()->makeContextCurrent(); |
480 } | 484 } |
481 | 485 |
482 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | 486 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
483 return WebKit::WebSharedGraphicsContext3D::compositorThreadContext(); | 487 return WebKit::WebSharedGraphicsContext3D::compositorThreadContext(); |
484 } | 488 } |
485 virtual class GrContext* GrContext() OVERRIDE { | 489 virtual class GrContext* GrContext() OVERRIDE { |
486 return WebKit::WebSharedGraphicsContext3D::compositorThreadGrContext(); | 490 return WebKit::WebSharedGraphicsContext3D::compositorThreadGrContext(); |
487 } | 491 } |
488 | 492 |
489 virtual void VerifyContexts() OVERRIDE { | 493 virtual void VerifyContexts() OVERRIDE { |
490 if (Context3d() && !Context3d()->isContextLost()) | 494 if (Context3d() && !Context3d()->isContextLost()) |
491 return; | 495 return; |
492 base::AutoLock lock(destroyed_lock_); | 496 base::AutoLock lock(destroyed_lock_); |
493 destroyed_ = true; | 497 destroyed_ = true; |
494 } | 498 } |
495 bool DestroyedOnMainThread() { | 499 bool DestroyedOnMainThread() { |
496 base::AutoLock lock(destroyed_lock_); | 500 base::AutoLock lock(destroyed_lock_); |
497 return destroyed_; | 501 return destroyed_; |
498 } | 502 } |
499 | 503 |
500 protected: | 504 protected: |
501 virtual ~CompositorThreadContextProvider() {} | 505 virtual ~CompositorThreadContextProvider() {} |
502 | 506 |
503 private: | 507 private: |
| 508 bool initialized_; |
| 509 |
504 base::Lock destroyed_lock_; | 510 base::Lock destroyed_lock_; |
505 bool destroyed_; | 511 bool destroyed_; |
506 }; | 512 }; |
507 | 513 |
508 scoped_refptr<cc::ContextProvider> | 514 scoped_refptr<cc::ContextProvider> |
509 RenderWidgetCompositor::OffscreenContextProviderForCompositorThread() { | 515 RenderWidgetCompositor::OffscreenContextProviderForCompositorThread() { |
510 if (!contexts_compositor_thread_ || | 516 if (!contexts_compositor_thread_ || |
511 contexts_compositor_thread_->DestroyedOnMainThread()) | 517 contexts_compositor_thread_->DestroyedOnMainThread()) |
512 contexts_compositor_thread_ = new CompositorThreadContextProvider; | 518 contexts_compositor_thread_ = new CompositorThreadContextProvider; |
513 return contexts_compositor_thread_; | 519 return contexts_compositor_thread_; |
514 } | 520 } |
515 | 521 |
516 } // namespace content | 522 } // namespace content |
OLD | NEW |