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