| 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 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 disable_schedule_composite_(false) { | 142 disable_schedule_composite_(false) { |
| 143 WebKit::WebLayerTreeView::Settings settings; | 143 WebKit::WebLayerTreeView::Settings settings; |
| 144 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 144 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 145 settings.showFPSCounter = | 145 settings.showFPSCounter = |
| 146 command_line->HasSwitch(switches::kUIShowFPSCounter); | 146 command_line->HasSwitch(switches::kUIShowFPSCounter); |
| 147 settings.showPlatformLayerTree = | 147 settings.showPlatformLayerTree = |
| 148 command_line->HasSwitch(switches::kUIShowLayerTree); | 148 command_line->HasSwitch(switches::kUIShowLayerTree); |
| 149 settings.refreshRate = | 149 settings.refreshRate = |
| 150 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; | 150 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; |
| 151 | 151 |
| 152 #if !defined(WEBCOMPOSITOR_OWNS_SETTINGS) | |
| 153 settings.partialSwapEnabled = | |
| 154 command_line->HasSwitch(switches::kUIEnablePartialSwap); | |
| 155 settings.perTilePainting = | |
| 156 command_line->HasSwitch(switches::kUIEnablePerTilePainting); | |
| 157 #endif | |
| 158 | |
| 159 host_.initialize(this, root_web_layer_, settings); | 152 host_.initialize(this, root_web_layer_, settings); |
| 160 host_.setSurfaceReady(); | 153 host_.setSurfaceReady(); |
| 161 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | 154 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 162 } | 155 } |
| 163 | 156 |
| 164 Compositor::~Compositor() { | 157 Compositor::~Compositor() { |
| 165 // Don't call |CompositorDelegate::ScheduleDraw| from this point. | 158 // Don't call |CompositorDelegate::ScheduleDraw| from this point. |
| 166 delegate_ = NULL; | 159 delegate_ = NULL; |
| 167 // There's a cycle between |root_web_layer_| and |host_|, which results in | 160 // There's a cycle between |root_web_layer_| and |host_|, which results in |
| 168 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle | 161 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle |
| 169 // is broken. | 162 // is broken. |
| 170 host_.setRootLayer(NULL); | 163 host_.setRootLayer(NULL); |
| 171 if (root_layer_) | 164 if (root_layer_) |
| 172 root_layer_->SetCompositor(NULL); | 165 root_layer_->SetCompositor(NULL); |
| 173 | 166 |
| 174 // Stop all outstanding draws before telling the ContextFactory to tear | 167 // Stop all outstanding draws before telling the ContextFactory to tear |
| 175 // down any contexts that the |host_| may rely upon. | 168 // down any contexts that the |host_| may rely upon. |
| 176 host_.reset(); | 169 host_.reset(); |
| 177 | 170 |
| 178 if (!test_compositor_enabled) | 171 if (!test_compositor_enabled) |
| 179 ContextFactory::GetInstance()->RemoveCompositor(this); | 172 ContextFactory::GetInstance()->RemoveCompositor(this); |
| 180 } | 173 } |
| 181 | 174 |
| 182 void Compositor::Initialize(bool use_thread) { | 175 void Compositor::Initialize(bool use_thread) { |
| 183 #if defined(WEBCOMPOSITOR_OWNS_SETTINGS) | |
| 184 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 176 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 185 // These settings must be applied before we initialize the compositor. | 177 // These settings must be applied before we initialize the compositor. |
| 186 WebKit::WebCompositor::setPartialSwapEnabled( | 178 WebKit::WebCompositor::setPartialSwapEnabled( |
| 187 command_line->HasSwitch(switches::kUIEnablePartialSwap)); | 179 command_line->HasSwitch(switches::kUIEnablePartialSwap)); |
| 188 WebKit::WebCompositor::setPerTilePaintingEnabled( | 180 WebKit::WebCompositor::setPerTilePaintingEnabled( |
| 189 command_line->HasSwitch(switches::kUIEnablePerTilePainting)); | 181 command_line->HasSwitch(switches::kUIEnablePerTilePainting)); |
| 190 #endif | |
| 191 if (use_thread) | 182 if (use_thread) |
| 192 g_compositor_thread = new webkit_glue::WebThreadImpl("Browser Compositor"); | 183 g_compositor_thread = new webkit_glue::WebThreadImpl("Browser Compositor"); |
| 193 WebKit::WebCompositor::initialize(g_compositor_thread); | 184 WebKit::WebCompositor::initialize(g_compositor_thread); |
| 194 } | 185 } |
| 195 | 186 |
| 196 void Compositor::Terminate() { | 187 void Compositor::Terminate() { |
| 197 WebKit::WebCompositor::shutdown(); | 188 WebKit::WebCompositor::shutdown(); |
| 198 if (g_compositor_thread) { | 189 if (g_compositor_thread) { |
| 199 delete g_compositor_thread; | 190 delete g_compositor_thread; |
| 200 g_compositor_thread = NULL; | 191 g_compositor_thread = NULL; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 416 |
| 426 COMPOSITOR_EXPORT void DisableTestCompositor() { | 417 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 427 test_compositor_enabled = false; | 418 test_compositor_enabled = false; |
| 428 } | 419 } |
| 429 | 420 |
| 430 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 421 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 431 return test_compositor_enabled; | 422 return test_compositor_enabled; |
| 432 } | 423 } |
| 433 | 424 |
| 434 } // namespace ui | 425 } // namespace ui |
| OLD | NEW |