| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "cc/context_provider.h" | 14 #include "cc/context_provider.h" |
| 15 #include "cc/layer.h" | 15 #include "cc/layer.h" |
| 16 #include "cc/layer_tree_debug_state.h" | 16 #include "cc/layer_tree_debug_state.h" |
| 17 #include "cc/layer_tree_host.h" | 17 #include "cc/layer_tree_host.h" |
| 18 #include "cc/switches.h" | 18 #include "cc/switches.h" |
| 19 #include "cc/thread_impl.h" | 19 #include "cc/thread_impl.h" |
| 20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 21 #include "content/renderer/gpu/compositor_thread.h" | 21 #include "content/renderer/gpu/compositor_thread.h" |
| 22 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" | 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" |
| 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsCo
ntext3D.h" | |
| 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 26 #include "ui/gl/gl_switches.h" | 25 #include "ui/gl/gl_switches.h" |
| 27 #include "webkit/compositor_bindings/web_layer_impl.h" | 26 #include "webkit/compositor_bindings/web_layer_impl.h" |
| 28 #include "webkit/compositor_bindings/web_to_ccinput_handler_adapter.h" | 27 #include "webkit/compositor_bindings/web_to_ccinput_handler_adapter.h" |
| 29 | 28 |
| 30 namespace cc { | 29 namespace cc { |
| 31 class Layer; | 30 class Layer; |
| 32 } | 31 } |
| 33 | 32 |
| 34 using WebKit::WebFloatPoint; | 33 using WebKit::WebFloatPoint; |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 479 |
| 481 void RenderWidgetCompositor::didCompleteSwapBuffers() { | 480 void RenderWidgetCompositor::didCompleteSwapBuffers() { |
| 482 widget_->didCompleteSwapBuffers(); | 481 widget_->didCompleteSwapBuffers(); |
| 483 } | 482 } |
| 484 | 483 |
| 485 void RenderWidgetCompositor::scheduleComposite() { | 484 void RenderWidgetCompositor::scheduleComposite() { |
| 486 if (!suppress_schedule_composite_) | 485 if (!suppress_schedule_composite_) |
| 487 widget_->scheduleComposite(); | 486 widget_->scheduleComposite(); |
| 488 } | 487 } |
| 489 | 488 |
| 490 class RenderWidgetCompositor::MainThreadContextProvider | |
| 491 : public cc::ContextProvider { | |
| 492 public: | |
| 493 virtual bool InitializeOnMainThread() OVERRIDE { return true; } | |
| 494 virtual bool BindToCurrentThread() OVERRIDE { return true; } | |
| 495 | |
| 496 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
| 497 return WebKit::WebSharedGraphicsContext3D::mainThreadContext(); | |
| 498 } | |
| 499 virtual class GrContext* GrContext() OVERRIDE { | |
| 500 return WebKit::WebSharedGraphicsContext3D::mainThreadGrContext(); | |
| 501 } | |
| 502 | |
| 503 virtual void VerifyContexts() OVERRIDE {} | |
| 504 | |
| 505 protected: | |
| 506 virtual ~MainThreadContextProvider() {} | |
| 507 }; | |
| 508 | |
| 509 scoped_refptr<cc::ContextProvider> | 489 scoped_refptr<cc::ContextProvider> |
| 510 RenderWidgetCompositor::OffscreenContextProviderForMainThread() { | 490 RenderWidgetCompositor::OffscreenContextProviderForMainThread() { |
| 511 if (!contexts_main_thread_) | 491 return RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); |
| 512 contexts_main_thread_ = new MainThreadContextProvider; | |
| 513 return contexts_main_thread_; | |
| 514 } | 492 } |
| 515 | 493 |
| 516 class RenderWidgetCompositor::CompositorThreadContextProvider | |
| 517 : public cc::ContextProvider { | |
| 518 public: | |
| 519 CompositorThreadContextProvider() : initialized_(false), destroyed_(false) {} | |
| 520 | |
| 521 virtual bool InitializeOnMainThread() OVERRIDE { | |
| 522 if (!initialized_) { | |
| 523 initialized_ = | |
| 524 WebKit::WebSharedGraphicsContext3D::createCompositorThreadContext(); | |
| 525 } | |
| 526 return initialized_; | |
| 527 } | |
| 528 virtual bool BindToCurrentThread() OVERRIDE { | |
| 529 return Context3d()->makeContextCurrent(); | |
| 530 } | |
| 531 | |
| 532 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
| 533 return WebKit::WebSharedGraphicsContext3D::compositorThreadContext(); | |
| 534 } | |
| 535 virtual class GrContext* GrContext() OVERRIDE { | |
| 536 return WebKit::WebSharedGraphicsContext3D::compositorThreadGrContext(); | |
| 537 } | |
| 538 | |
| 539 virtual void VerifyContexts() OVERRIDE { | |
| 540 if (Context3d() && !Context3d()->isContextLost()) | |
| 541 return; | |
| 542 base::AutoLock lock(destroyed_lock_); | |
| 543 destroyed_ = true; | |
| 544 } | |
| 545 bool DestroyedOnMainThread() { | |
| 546 base::AutoLock lock(destroyed_lock_); | |
| 547 return destroyed_; | |
| 548 } | |
| 549 | |
| 550 protected: | |
| 551 virtual ~CompositorThreadContextProvider() {} | |
| 552 | |
| 553 private: | |
| 554 bool initialized_; | |
| 555 | |
| 556 base::Lock destroyed_lock_; | |
| 557 bool destroyed_; | |
| 558 }; | |
| 559 | |
| 560 scoped_refptr<cc::ContextProvider> | 494 scoped_refptr<cc::ContextProvider> |
| 561 RenderWidgetCompositor::OffscreenContextProviderForCompositorThread() { | 495 RenderWidgetCompositor::OffscreenContextProviderForCompositorThread() { |
| 562 if (!contexts_compositor_thread_ || | 496 return RenderThreadImpl::current()-> |
| 563 contexts_compositor_thread_->DestroyedOnMainThread()) | 497 OffscreenContextProviderForCompositorThread(); |
| 564 contexts_compositor_thread_ = new CompositorThreadContextProvider; | |
| 565 return contexts_compositor_thread_; | |
| 566 } | 498 } |
| 567 | 499 |
| 568 } // namespace content | 500 } // namespace content |
| OLD | NEW |