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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 disable_schedule_composite_(false) { | 143 disable_schedule_composite_(false) { |
144 WebKit::WebLayerTreeView::Settings settings; | 144 WebKit::WebLayerTreeView::Settings settings; |
145 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 145 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
146 settings.showFPSCounter = | 146 settings.showFPSCounter = |
147 command_line->HasSwitch(switches::kUIShowFPSCounter); | 147 command_line->HasSwitch(switches::kUIShowFPSCounter); |
148 settings.showPlatformLayerTree = | 148 settings.showPlatformLayerTree = |
149 command_line->HasSwitch(switches::kUIShowLayerTree); | 149 command_line->HasSwitch(switches::kUIShowLayerTree); |
150 settings.refreshRate = | 150 settings.refreshRate = |
151 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; | 151 test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; |
152 | 152 |
| 153 #if defined(WEBLAYER_IS_PURE_VIRTUAL) |
| 154 host_.initialize(this, *root_web_layer_, settings); |
| 155 root_web_layer_->setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 156 #else |
153 host_.initialize(this, root_web_layer_, settings); | 157 host_.initialize(this, root_web_layer_, settings); |
| 158 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
| 159 #endif |
154 host_.setSurfaceReady(); | 160 host_.setSurfaceReady(); |
155 root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); | |
156 } | 161 } |
157 | 162 |
158 Compositor::~Compositor() { | 163 Compositor::~Compositor() { |
159 // Don't call |CompositorDelegate::ScheduleDraw| from this point. | 164 // Don't call |CompositorDelegate::ScheduleDraw| from this point. |
160 delegate_ = NULL; | 165 delegate_ = NULL; |
| 166 #if !defined(WEBLAYER_IS_PURE_VIRTUAL) |
161 // There's a cycle between |root_web_layer_| and |host_|, which results in | 167 // There's a cycle between |root_web_layer_| and |host_|, which results in |
162 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle | 168 // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle |
163 // is broken. | 169 // is broken. |
164 host_.setRootLayer(NULL); | 170 host_.setRootLayer(NULL); |
| 171 #endif |
165 if (root_layer_) | 172 if (root_layer_) |
166 root_layer_->SetCompositor(NULL); | 173 root_layer_->SetCompositor(NULL); |
167 | 174 |
168 // Stop all outstanding draws before telling the ContextFactory to tear | 175 // Stop all outstanding draws before telling the ContextFactory to tear |
169 // down any contexts that the |host_| may rely upon. | 176 // down any contexts that the |host_| may rely upon. |
170 host_.reset(); | 177 host_.reset(); |
171 | 178 |
172 if (!test_compositor_enabled) | 179 if (!test_compositor_enabled) |
173 ContextFactory::GetInstance()->RemoveCompositor(this); | 180 ContextFactory::GetInstance()->RemoveCompositor(this); |
174 } | 181 } |
(...skipping 30 matching lines...) Expand all Loading... |
205 } | 212 } |
206 | 213 |
207 void Compositor::SetRootLayer(Layer* root_layer) { | 214 void Compositor::SetRootLayer(Layer* root_layer) { |
208 if (root_layer_ == root_layer) | 215 if (root_layer_ == root_layer) |
209 return; | 216 return; |
210 if (root_layer_) | 217 if (root_layer_) |
211 root_layer_->SetCompositor(NULL); | 218 root_layer_->SetCompositor(NULL); |
212 root_layer_ = root_layer; | 219 root_layer_ = root_layer; |
213 if (root_layer_ && !root_layer_->GetCompositor()) | 220 if (root_layer_ && !root_layer_->GetCompositor()) |
214 root_layer_->SetCompositor(this); | 221 root_layer_->SetCompositor(this); |
| 222 #if defined(WEBLAYER_IS_PURE_VIRTUAL) |
| 223 root_web_layer_->removeAllChildren(); |
| 224 if (root_layer_) |
| 225 root_web_layer_->addChild(root_layer_->web_layer()); |
| 226 #else |
215 root_web_layer_.removeAllChildren(); | 227 root_web_layer_.removeAllChildren(); |
216 if (root_layer_) | 228 if (root_layer_) |
217 root_web_layer_.addChild(root_layer_->web_layer()); | 229 root_web_layer_.addChild(root_layer_->web_layer()); |
| 230 #endif |
218 } | 231 } |
219 | 232 |
220 void Compositor::Draw(bool force_clear) { | 233 void Compositor::Draw(bool force_clear) { |
221 if (!root_layer_) | 234 if (!root_layer_) |
222 return; | 235 return; |
223 | 236 |
224 last_started_frame_++; | 237 last_started_frame_++; |
225 if (!g_compositor_thread) | 238 if (!g_compositor_thread) |
226 FOR_EACH_OBSERVER(CompositorObserver, | 239 FOR_EACH_OBSERVER(CompositorObserver, |
227 observer_list_, | 240 observer_list_, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 274 } |
262 return false; | 275 return false; |
263 } | 276 } |
264 | 277 |
265 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { | 278 void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { |
266 DCHECK_GT(scale, 0); | 279 DCHECK_GT(scale, 0); |
267 if (size_in_pixel.IsEmpty() || scale <= 0) | 280 if (size_in_pixel.IsEmpty() || scale <= 0) |
268 return; | 281 return; |
269 size_ = size_in_pixel; | 282 size_ = size_in_pixel; |
270 host_.setViewportSize(size_in_pixel); | 283 host_.setViewportSize(size_in_pixel); |
| 284 #if defined(WEBLAYER_IS_PURE_VIRTUAL) |
| 285 root_web_layer_->setBounds(size_in_pixel); |
| 286 #else |
271 root_web_layer_.setBounds(size_in_pixel); | 287 root_web_layer_.setBounds(size_in_pixel); |
| 288 #endif |
272 | 289 |
273 if (device_scale_factor_ != scale) { | 290 if (device_scale_factor_ != scale) { |
274 device_scale_factor_ = scale; | 291 device_scale_factor_ = scale; |
275 if (root_layer_) | 292 if (root_layer_) |
276 root_layer_->OnDeviceScaleFactorChanged(scale); | 293 root_layer_->OnDeviceScaleFactorChanged(scale); |
277 } | 294 } |
278 } | 295 } |
279 | 296 |
280 void Compositor::AddObserver(CompositorObserver* observer) { | 297 void Compositor::AddObserver(CompositorObserver* observer) { |
281 observer_list_.AddObserver(observer); | 298 observer_list_.AddObserver(observer); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 477 |
461 COMPOSITOR_EXPORT void DisableTestCompositor() { | 478 COMPOSITOR_EXPORT void DisableTestCompositor() { |
462 test_compositor_enabled = false; | 479 test_compositor_enabled = false; |
463 } | 480 } |
464 | 481 |
465 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 482 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
466 return test_compositor_enabled; | 483 return test_compositor_enabled; |
467 } | 484 } |
468 | 485 |
469 } // namespace ui | 486 } // namespace ui |
OLD | NEW |