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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 void RenderWidgetCompositor::didCompleteSwapBuffers() { | 436 void RenderWidgetCompositor::didCompleteSwapBuffers() { |
434 widget_->didCompleteSwapBuffers(); | 437 widget_->didCompleteSwapBuffers(); |
435 } | 438 } |
436 | 439 |
437 // TODO(jamesr): This goes through WebViewImpl just to do suppression, refactor | 440 // TODO(jamesr): This goes through WebViewImpl just to do suppression, refactor |
438 // that piece out. | 441 // that piece out. |
439 void RenderWidgetCompositor::scheduleComposite() { | 442 void RenderWidgetCompositor::scheduleComposite() { |
440 client_->scheduleComposite(); | 443 client_->scheduleComposite(); |
441 } | 444 } |
442 | 445 |
446 class RenderWidgetCompositor::MainThreadContextProvider | |
447 : public cc::ContextProvider { | |
448 public: | |
449 virtual bool InitializeOnMainThread() OVERRIDE { return true; } | |
450 virtual bool BindToCurrentThread() OVERRIDE { return true; } | |
451 | |
452 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
453 return WebKit::WebSharedGraphicsContext3D::mainThreadContext(); | |
jamesr
2013/02/22 19:11:40
We also have WebKit::WebView::sharedGraphicsContex
danakj
2013/02/22 19:17:53
Ohh, okay. Thanks for the heads up.
| |
454 } | |
455 virtual class GrContext* GrContext() OVERRIDE { | |
456 return WebKit::WebSharedGraphicsContext3D::mainThreadGrContext(); | |
457 } | |
458 | |
459 virtual void VerifyContexts() OVERRIDE {} | |
460 | |
461 protected: | |
462 virtual ~MainThreadContextProvider() {} | |
463 }; | |
464 | |
465 scoped_refptr<cc::ContextProvider> | |
466 RenderWidgetCompositor::OffscreenContextProviderForMainThread() { | |
467 if (!contexts_main_thread_) | |
468 contexts_main_thread_ = new MainThreadContextProvider; | |
469 return contexts_main_thread_; | |
470 } | |
471 | |
472 class RenderWidgetCompositor::CompositorThreadContextProvider | |
473 : public cc::ContextProvider { | |
474 public: | |
475 CompositorThreadContextProvider() : destroyed_(false) {} | |
476 | |
477 virtual bool InitializeOnMainThread() OVERRIDE { | |
478 return WebKit::WebSharedGraphicsContext3D::createCompositorThreadContext(); | |
479 } | |
480 virtual bool BindToCurrentThread() OVERRIDE { | |
481 return Context3d()->makeContextCurrent(); | |
482 } | |
483 | |
484 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
485 return WebKit::WebSharedGraphicsContext3D::compositorThreadContext(); | |
486 } | |
487 virtual class GrContext* GrContext() OVERRIDE { | |
488 return WebKit::WebSharedGraphicsContext3D::compositorThreadGrContext(); | |
489 } | |
490 | |
491 virtual void VerifyContexts() OVERRIDE { | |
492 if (Context3d() && !Context3d()->isContextLost()) | |
493 return; | |
494 base::AutoLock lock(destroyed_lock_); | |
495 destroyed_ = true; | |
496 } | |
497 bool DestroyedOnMainThread() { | |
498 base::AutoLock lock(destroyed_lock_); | |
499 return destroyed_; | |
500 } | |
501 | |
502 protected: | |
503 virtual ~CompositorThreadContextProvider() {} | |
504 | |
505 private: | |
506 base::Lock destroyed_lock_; | |
507 bool destroyed_; | |
508 }; | |
509 | |
510 scoped_refptr<cc::ContextProvider> | |
511 RenderWidgetCompositor::OffscreenContextProviderForCompositorThread() { | |
512 if (!contexts_compositor_thread_ || | |
513 contexts_compositor_thread_->DestroyedOnMainThread()) | |
514 contexts_compositor_thread_ = new CompositorThreadContextProvider; | |
515 return contexts_compositor_thread_; | |
516 } | |
517 | |
443 } // namespace content | 518 } // namespace content |
OLD | NEW |