| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/compositor/compositor.h" | 5 #include "ui/compositor/compositor.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "cc/font_atlas.h" | 16 #include "cc/font_atlas.h" |
| 17 #include "cc/input_handler.h" | 17 #include "cc/input_handler.h" |
| 18 #include "cc/layer.h" | 18 #include "cc/layer.h" |
| 19 #include "cc/layer_tree_host.h" | 19 #include "cc/layer_tree_host.h" |
| 20 #include "cc/output_surface.h" | 20 #include "cc/output_surface_impl.h" |
| 21 #include "cc/thread_impl.h" | 21 #include "cc/thread_impl.h" |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
| 23 #include "ui/compositor/compositor_observer.h" | 23 #include "ui/compositor/compositor_observer.h" |
| 24 #include "ui/compositor/compositor_switches.h" | 24 #include "ui/compositor/compositor_switches.h" |
| 25 #include "ui/compositor/dip_util.h" | 25 #include "ui/compositor/dip_util.h" |
| 26 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
| 27 #include "ui/compositor/test_web_graphics_context_3d.h" | 27 #include "ui/compositor/test_web_graphics_context_3d.h" |
| 28 #include "ui/gl/gl_context.h" | 28 #include "ui/gl/gl_context.h" |
| 29 #include "ui/gl/gl_implementation.h" | 29 #include "ui/gl/gl_implementation.h" |
| 30 #include "ui/gl/gl_surface.h" | 30 #include "ui/gl/gl_surface.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 base::Thread* g_compositor_thread = NULL; | 48 base::Thread* g_compositor_thread = NULL; |
| 49 | 49 |
| 50 bool test_compositor_enabled = false; | 50 bool test_compositor_enabled = false; |
| 51 | 51 |
| 52 ui::ContextFactory* g_context_factory = NULL; | 52 ui::ContextFactory* g_context_factory = NULL; |
| 53 | 53 |
| 54 const int kCompositorLockTimeoutMs = 67; | 54 const int kCompositorLockTimeoutMs = 67; |
| 55 | 55 |
| 56 // Adapts a pure WebGraphicsContext3D into a cc::OutputSurface. | |
| 57 class WebGraphicsContextToOutputSurfaceAdapter | |
| 58 : public cc::OutputSurface { | |
| 59 public: | |
| 60 explicit WebGraphicsContextToOutputSurfaceAdapter( | |
| 61 WebKit::WebGraphicsContext3D* context) | |
| 62 : context3D_(context), | |
| 63 client_(NULL) { | |
| 64 } | |
| 65 | |
| 66 virtual bool BindToClient( | |
| 67 cc::OutputSurfaceClient* client) OVERRIDE { | |
| 68 DCHECK(client); | |
| 69 if (!context3D_->makeContextCurrent()) | |
| 70 return false; | |
| 71 client_ = client; | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 virtual const struct Capabilities& Capabilities() const OVERRIDE { | |
| 76 return capabilities_; | |
| 77 } | |
| 78 | |
| 79 virtual WebKit::WebGraphicsContext3D* Context3D() const OVERRIDE { | |
| 80 return context3D_.get(); | |
| 81 } | |
| 82 | |
| 83 virtual cc::SoftwareOutputDevice* SoftwareDevice() const OVERRIDE { | |
| 84 return NULL; | |
| 85 } | |
| 86 | |
| 87 virtual void SendFrameToParentCompositor(cc::CompositorFrame*) OVERRIDE { | |
| 88 } | |
| 89 | |
| 90 private: | |
| 91 scoped_ptr<WebKit::WebGraphicsContext3D> context3D_; | |
| 92 struct Capabilities capabilities_; | |
| 93 cc::OutputSurfaceClient* client_; | |
| 94 }; | |
| 95 | |
| 96 class PendingSwap { | 56 class PendingSwap { |
| 97 public: | 57 public: |
| 98 PendingSwap(SwapType type, ui::PostedSwapQueue* posted_swaps); | 58 PendingSwap(SwapType type, ui::PostedSwapQueue* posted_swaps); |
| 99 ~PendingSwap(); | 59 ~PendingSwap(); |
| 100 | 60 |
| 101 SwapType type() const { return type_; } | 61 SwapType type() const { return type_; } |
| 102 bool posted() const { return posted_; } | 62 bool posted() const { return posted_; } |
| 103 | 63 |
| 104 private: | 64 private: |
| 105 friend class ui::PostedSwapQueue; | 65 friend class ui::PostedSwapQueue; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (!gfx::GLSurface::InitializeOneOff() || | 108 if (!gfx::GLSurface::InitializeOneOff() || |
| 149 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | 109 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
| 150 LOG(ERROR) << "Could not load the GL bindings"; | 110 LOG(ERROR) << "Could not load the GL bindings"; |
| 151 return false; | 111 return false; |
| 152 } | 112 } |
| 153 return true; | 113 return true; |
| 154 } | 114 } |
| 155 | 115 |
| 156 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( | 116 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( |
| 157 Compositor* compositor) { | 117 Compositor* compositor) { |
| 158 return new WebGraphicsContextToOutputSurfaceAdapter( | 118 return new cc::OutputSurfaceImpl( |
| 159 CreateContextCommon(compositor, false)); | 119 make_scoped_ptr(CreateContextCommon(compositor, false))); |
| 160 } | 120 } |
| 161 | 121 |
| 162 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 122 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
| 163 return CreateContextCommon(NULL, true); | 123 return CreateContextCommon(NULL, true); |
| 164 } | 124 } |
| 165 | 125 |
| 166 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 126 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
| 167 } | 127 } |
| 168 | 128 |
| 169 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 129 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 cc::LayerTreeSettings settings; | 271 cc::LayerTreeSettings settings; |
| 312 settings.initialDebugState.showFPSCounter = | 272 settings.initialDebugState.showFPSCounter = |
| 313 command_line->HasSwitch(switches::kUIShowFPSCounter); | 273 command_line->HasSwitch(switches::kUIShowFPSCounter); |
| 314 settings.initialDebugState.showPlatformLayerTree = | 274 settings.initialDebugState.showPlatformLayerTree = |
| 315 command_line->HasSwitch(switches::kUIShowLayerTree); | 275 command_line->HasSwitch(switches::kUIShowLayerTree); |
| 316 settings.refreshRate = | 276 settings.refreshRate = |
| 317 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; | 277 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; |
| 318 settings.initialDebugState.showDebugBorders = | 278 settings.initialDebugState.showDebugBorders = |
| 319 command_line->HasSwitch(switches::kUIShowLayerBorders); | 279 command_line->HasSwitch(switches::kUIShowLayerBorders); |
| 320 settings.partialSwapEnabled = | 280 settings.partialSwapEnabled = |
| 321 command_line->HasSwitch(switches::kUIEnablePartialSwap); | 281 command_line->HasSwitch(switches::kUIEnablePartialSwap) || |
| 282 command_line->HasSwitch(switches::kUIEnableSoftwareCompositing); |
| 322 settings.perTilePaintingEnabled = | 283 settings.perTilePaintingEnabled = |
| 323 command_line->HasSwitch(switches::kUIEnablePerTilePainting); | 284 command_line->HasSwitch(switches::kUIEnablePerTilePainting); |
| 324 | 285 |
| 325 scoped_ptr<cc::Thread> thread; | 286 scoped_ptr<cc::Thread> thread; |
| 326 if (g_compositor_thread) { | 287 if (g_compositor_thread) { |
| 327 thread = cc::ThreadImpl::createForDifferentThread( | 288 thread = cc::ThreadImpl::createForDifferentThread( |
| 328 g_compositor_thread->message_loop_proxy()); | 289 g_compositor_thread->message_loop_proxy()); |
| 329 } | 290 } |
| 330 | 291 |
| 331 host_ = cc::LayerTreeHost::create(this, settings, thread.Pass()); | 292 host_ = cc::LayerTreeHost::create(this, settings, thread.Pass()); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 root_layer_->SendDamagedRects(); | 461 root_layer_->SendDamagedRects(); |
| 501 disable_schedule_composite_ = false; | 462 disable_schedule_composite_ = false; |
| 502 } | 463 } |
| 503 | 464 |
| 504 void Compositor::applyScrollAndScale(gfx::Vector2d scrollDelta, | 465 void Compositor::applyScrollAndScale(gfx::Vector2d scrollDelta, |
| 505 float pageScale) { | 466 float pageScale) { |
| 506 } | 467 } |
| 507 | 468 |
| 508 scoped_ptr<cc::OutputSurface> Compositor::createOutputSurface() { | 469 scoped_ptr<cc::OutputSurface> Compositor::createOutputSurface() { |
| 509 if (test_compositor_enabled) { | 470 if (test_compositor_enabled) { |
| 510 ui::TestWebGraphicsContext3D* test_context = | 471 scoped_ptr<ui::TestWebGraphicsContext3D> context3d( |
| 511 new ui::TestWebGraphicsContext3D(); | 472 new ui::TestWebGraphicsContext3D); |
| 512 test_context->Initialize(); | 473 context3d->Initialize(); |
| 513 return scoped_ptr<cc::OutputSurface>( | 474 return scoped_ptr<cc::OutputSurface>( |
| 514 new WebGraphicsContextToOutputSurfaceAdapter(test_context)); | 475 new cc::OutputSurfaceImpl( |
| 476 context3d.PassAs<WebKit::WebGraphicsContext3D>())); |
| 515 } else { | 477 } else { |
| 516 return scoped_ptr<cc::OutputSurface>( | 478 return scoped_ptr<cc::OutputSurface>( |
| 517 ContextFactory::GetInstance()->CreateOutputSurface(this)); | 479 ContextFactory::GetInstance()->CreateOutputSurface(this)); |
| 518 } | 480 } |
| 519 } | 481 } |
| 520 | 482 |
| 521 void Compositor::didRecreateOutputSurface(bool success) { | 483 void Compositor::didRecreateOutputSurface(bool success) { |
| 522 } | 484 } |
| 523 | 485 |
| 524 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { | 486 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 566 |
| 605 COMPOSITOR_EXPORT void DisableTestCompositor() { | 567 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 606 test_compositor_enabled = false; | 568 test_compositor_enabled = false; |
| 607 } | 569 } |
| 608 | 570 |
| 609 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 571 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 610 return test_compositor_enabled; | 572 return test_compositor_enabled; |
| 611 } | 573 } |
| 612 | 574 |
| 613 } // namespace ui | 575 } // namespace ui |
| OLD | NEW |