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/time.h" | 11 #include "base/time.h" |
| 12 #include "cc/context_provider.h" |
11 #include "cc/layer.h" | 13 #include "cc/layer.h" |
12 #include "cc/layer_tree_debug_state.h" | 14 #include "cc/layer_tree_debug_state.h" |
13 #include "cc/layer_tree_host.h" | 15 #include "cc/layer_tree_host.h" |
14 #include "cc/switches.h" | 16 #include "cc/switches.h" |
15 #include "cc/thread_impl.h" | 17 #include "cc/thread_impl.h" |
16 #include "content/renderer/gpu/compositor_thread.h" | 18 #include "content/renderer/gpu/compositor_thread.h" |
17 #include "content/renderer/render_thread_impl.h" | 19 #include "content/renderer/render_thread_impl.h" |
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" |
| 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsCo
ntext3D.h" |
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
20 #include "webkit/compositor_bindings/web_layer_impl.h" | 23 #include "webkit/compositor_bindings/web_layer_impl.h" |
21 #include "webkit/compositor_bindings/web_to_ccinput_handler_adapter.h" | 24 #include "webkit/compositor_bindings/web_to_ccinput_handler_adapter.h" |
22 | 25 |
23 namespace cc { | 26 namespace cc { |
24 class Layer; | 27 class Layer; |
25 } | 28 } |
26 | 29 |
27 using WebKit::WebFloatPoint; | 30 using WebKit::WebFloatPoint; |
28 using WebKit::WebSize; | 31 using WebKit::WebSize; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 void RenderWidgetCompositor::didCompleteSwapBuffers() { | 418 void RenderWidgetCompositor::didCompleteSwapBuffers() { |
416 widget_->didCompleteSwapBuffers(); | 419 widget_->didCompleteSwapBuffers(); |
417 } | 420 } |
418 | 421 |
419 // TODO(jamesr): This goes through WebViewImpl just to do suppression, refactor | 422 // TODO(jamesr): This goes through WebViewImpl just to do suppression, refactor |
420 // that piece out. | 423 // that piece out. |
421 void RenderWidgetCompositor::scheduleComposite() { | 424 void RenderWidgetCompositor::scheduleComposite() { |
422 client_->scheduleComposite(); | 425 client_->scheduleComposite(); |
423 } | 426 } |
424 | 427 |
| 428 class RenderWidgetCompositor::MainThreadContextProvider |
| 429 : public cc::ContextProvider { |
| 430 public: |
| 431 virtual bool InitializeOnMainThread() OVERRIDE { return true; } |
| 432 virtual bool BindToCurrentThread() OVERRIDE { return true; } |
| 433 |
| 434 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
| 435 return WebKit::WebSharedGraphicsContext3D::mainThreadContext(); |
| 436 } |
| 437 virtual class GrContext* GrContext() OVERRIDE { |
| 438 return WebKit::WebSharedGraphicsContext3D::mainThreadGrContext(); |
| 439 } |
| 440 |
| 441 virtual void VerifyContexts() OVERRIDE {} |
| 442 |
| 443 protected: |
| 444 virtual ~MainThreadContextProvider() {} |
| 445 }; |
| 446 |
| 447 scoped_refptr<cc::ContextProvider> |
| 448 RenderWidgetCompositor::OffscreenContextProviderForMainThread() { |
| 449 if (!contexts_main_thread_) |
| 450 contexts_main_thread_ = new MainThreadContextProvider; |
| 451 return contexts_main_thread_; |
| 452 } |
| 453 |
| 454 class RenderWidgetCompositor::CompositorThreadContextProvider |
| 455 : public cc::ContextProvider { |
| 456 public: |
| 457 CompositorThreadContextProvider() : destroyed_(false) {} |
| 458 |
| 459 virtual bool InitializeOnMainThread() OVERRIDE { |
| 460 return WebKit::WebSharedGraphicsContext3D::createCompositorThreadContext(); |
| 461 } |
| 462 virtual bool BindToCurrentThread() OVERRIDE { |
| 463 return Context3d()->makeContextCurrent(); |
| 464 } |
| 465 |
| 466 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
| 467 return WebKit::WebSharedGraphicsContext3D::compositorThreadContext(); |
| 468 } |
| 469 virtual class GrContext* GrContext() OVERRIDE { |
| 470 return WebKit::WebSharedGraphicsContext3D::compositorThreadGrContext(); |
| 471 } |
| 472 |
| 473 virtual void VerifyContexts() OVERRIDE { |
| 474 if (Context3d() && !Context3d()->isContextLost()) |
| 475 return; |
| 476 base::AutoLock lock(destroyed_lock_); |
| 477 destroyed_ = true; |
| 478 } |
| 479 bool DestroyedOnMainThread() { |
| 480 base::AutoLock lock(destroyed_lock_); |
| 481 return destroyed_; |
| 482 } |
| 483 |
| 484 protected: |
| 485 virtual ~CompositorThreadContextProvider() {} |
| 486 |
| 487 private: |
| 488 base::Lock destroyed_lock_; |
| 489 bool destroyed_; |
| 490 }; |
| 491 |
| 492 scoped_refptr<cc::ContextProvider> |
| 493 RenderWidgetCompositor::OffscreenContextProviderForCompositorThread() { |
| 494 if (!contexts_compositor_thread_ || |
| 495 contexts_compositor_thread_->DestroyedOnMainThread()) |
| 496 contexts_compositor_thread_ = new CompositorThreadContextProvider; |
| 497 return contexts_compositor_thread_; |
| 498 } |
| 499 |
425 } // namespace content | 500 } // namespace content |
OLD | NEW |