OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "cc/animation_registrar.h" | 13 #include "cc/animation_registrar.h" |
14 #include "cc/heads_up_display_layer.h" | 14 #include "cc/heads_up_display_layer.h" |
15 #include "cc/heads_up_display_layer_impl.h" | 15 #include "cc/heads_up_display_layer_impl.h" |
16 #include "cc/layer.h" | 16 #include "cc/layer.h" |
17 #include "cc/layer_animation_controller.h" | 17 #include "cc/layer_animation_controller.h" |
18 #include "cc/layer_iterator.h" | 18 #include "cc/layer_iterator.h" |
19 #include "cc/layer_tree_host_client.h" | 19 #include "cc/layer_tree_host_client.h" |
20 #include "cc/layer_tree_host_common.h" | 20 #include "cc/layer_tree_host_common.h" |
21 #include "cc/layer_tree_host_impl.h" | 21 #include "cc/layer_tree_host_impl.h" |
22 #include "cc/layer_tree_impl.h" | 22 #include "cc/layer_tree_impl.h" |
23 #include "cc/math_util.h" | 23 #include "cc/math_util.h" |
24 #include "cc/occlusion_tracker.h" | 24 #include "cc/occlusion_tracker.h" |
25 #include "cc/overdraw_metrics.h" | 25 #include "cc/overdraw_metrics.h" |
26 #include "cc/pinch_zoom_scrollbar.h" | |
27 #include "cc/pinch_zoom_scrollbar_geometry.h" | |
28 #include "cc/pinch_zoom_scrollbar_painter.h" | |
26 #include "cc/prioritized_resource_manager.h" | 29 #include "cc/prioritized_resource_manager.h" |
30 #include "cc/scrollbar_layer.h" | |
27 #include "cc/single_thread_proxy.h" | 31 #include "cc/single_thread_proxy.h" |
28 #include "cc/switches.h" | 32 #include "cc/switches.h" |
29 #include "cc/thread.h" | 33 #include "cc/thread.h" |
30 #include "cc/thread_proxy.h" | 34 #include "cc/thread_proxy.h" |
31 #include "cc/top_controls_manager.h" | 35 #include "cc/top_controls_manager.h" |
32 #include "cc/tree_synchronizer.h" | 36 #include "cc/tree_synchronizer.h" |
33 | 37 |
34 namespace { | 38 namespace { |
35 static int numLayerTreeInstances; | 39 static int numLayerTreeInstances; |
36 } | 40 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 324 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
321 hostImpl->setDebugState(m_debugState); | 325 hostImpl->setDebugState(m_debugState); |
322 | 326 |
323 DCHECK(!syncTree->ViewportSizeInvalid()); | 327 DCHECK(!syncTree->ViewportSizeInvalid()); |
324 | 328 |
325 if (newImplTreeHasNoEvictedResources) { | 329 if (newImplTreeHasNoEvictedResources) { |
326 if (syncTree->ContentsTexturesPurged()) | 330 if (syncTree->ContentsTexturesPurged()) |
327 syncTree->ResetContentsTexturesPurged(); | 331 syncTree->ResetContentsTexturesPurged(); |
328 } | 332 } |
329 | 333 |
334 syncTree->SetPinchZoomHorizontalLayerId( | |
335 m_pinchZoomScrollbarHorizontal ? m_pinchZoomScrollbarHorizontal->id() : -1); | |
336 syncTree->SetPinchZoomVerticalLayerId( | |
337 m_pinchZoomScrollbarVertical ? m_pinchZoomScrollbarVertical->id() : -1); | |
338 | |
330 if (!m_settings.implSidePainting) { | 339 if (!m_settings.implSidePainting) { |
331 // If we're not in impl-side painting, the tree is immediately | 340 // If we're not in impl-side painting, the tree is immediately |
332 // considered active. | 341 // considered active. |
333 syncTree->DidBecomeActive(); | 342 syncTree->DidBecomeActive(); |
334 } | 343 } |
335 | 344 |
336 if (m_debugState.continuousPainting) | 345 if (m_debugState.continuousPainting) |
337 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber()) ; | 346 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber()) ; |
338 | 347 |
339 m_commitNumber++; | 348 m_commitNumber++; |
340 } | 349 } |
341 | 350 |
351 void LayerTreeHost::setPinchZoomScrollbarsBoundsAndPosition() | |
352 { | |
353 if (!m_pinchZoomScrollbarHorizontal || !m_pinchZoomScrollbarVertical) | |
354 return; | |
355 | |
356 gfx::Size size = layoutViewportSize(); | |
357 int trackWidth = PinchZoomScrollbarGeometry::kTrackWidth; | |
358 | |
359 m_pinchZoomScrollbarHorizontal->setBounds(gfx::Size(size.width() - trackWidt h, trackWidth)); | |
360 m_pinchZoomScrollbarHorizontal->setPosition(gfx::PointF(0, size.height() - t rackWidth)); | |
361 m_pinchZoomScrollbarHorizontal->setNeedsDisplay(); | |
362 | |
363 m_pinchZoomScrollbarVertical->setBounds(gfx::Size(trackWidth, size.height() - trackWidth)); | |
364 m_pinchZoomScrollbarVertical->setPosition(gfx::PointF(size.width() - trackWi dth, 0)); | |
365 m_pinchZoomScrollbarVertical->setNeedsDisplay(); | |
366 } | |
367 | |
368 static scoped_refptr<ScrollbarLayer> CreatePinchZoomScrollbar( | |
369 WebKit::WebScrollbar::Orientation orientation, LayerTreeHost* owner) | |
370 { | |
371 scoped_refptr<ScrollbarLayer> scrollbarLayer = ScrollbarLayer::create( | |
372 make_scoped_ptr( | |
373 new PinchZoomScrollbar(orientation, owner)).PassAs<WebKit::WebScroll bar>(), | |
jamesr
2013/03/02 03:19:14
doing make_scoped_ptr(...).PassAs<T> is just extra
wjmaclean
2013/03/04 15:53:10
Done.
| |
374 make_scoped_ptr(new PinchZoomScrollbarPainter).PassAs<ScrollbarThemePain ter>(), | |
375 make_scoped_ptr(new PinchZoomScrollbarGeometry).PassAs<WebKit::WebScroll barThemeGeometry>(), | |
376 -1); | |
377 scrollbarLayer->setIsDrawable(true); | |
378 scrollbarLayer->setOpacity(0.01); //PinchZoomScrollbar::kDefaultOpacity) ; | |
jamesr
2013/03/02 03:19:14
This doesn't make sense. If it's drawable, why is
wjmaclean
2013/03/04 15:53:10
If I make it not drawable, then later when we use
| |
379 return scrollbarLayer; | |
380 } | |
381 | |
382 void LayerTreeHost::createAndAddPinchZoomScrollbars() | |
383 { | |
384 bool needsPropertiesUpdated = false; | |
385 | |
386 if (!m_pinchZoomScrollbarHorizontal) { | |
387 m_pinchZoomScrollbarHorizontal = CreatePinchZoomScrollbar(WebKit::WebScr ollbar::Horizontal, this); | |
388 needsPropertiesUpdated = true; | |
389 } | |
390 | |
391 if (!m_pinchZoomScrollbarVertical) { | |
392 m_pinchZoomScrollbarVertical = CreatePinchZoomScrollbar( WebKit::WebScro llbar::Vertical, this); | |
393 needsPropertiesUpdated = true; | |
394 } | |
395 | |
396 DCHECK(m_pinchZoomScrollbarHorizontal && m_pinchZoomScrollbarVertical); | |
397 | |
398 if (!m_pinchZoomScrollbarHorizontal->parent()) | |
399 m_rootLayer->addChild(m_pinchZoomScrollbarHorizontal); | |
400 | |
401 if (!m_pinchZoomScrollbarVertical->parent()) | |
402 m_rootLayer->addChild(m_pinchZoomScrollbarVertical); | |
403 | |
404 if (needsPropertiesUpdated) | |
405 setPinchZoomScrollbarsBoundsAndPosition(); | |
406 } | |
407 | |
342 void LayerTreeHost::willCommit() | 408 void LayerTreeHost::willCommit() |
343 { | 409 { |
344 m_client->willCommit(); | 410 m_client->willCommit(); |
345 | 411 |
346 if (m_debugState.showHudInfo()) { | 412 if (m_debugState.showHudInfo()) { |
347 if (!m_hudLayer) | 413 if (!m_hudLayer) |
348 m_hudLayer = HeadsUpDisplayLayer::create(); | 414 m_hudLayer = HeadsUpDisplayLayer::create(); |
349 | 415 |
350 if (m_rootLayer && !m_hudLayer->parent()) | 416 if (m_rootLayer && !m_hudLayer->parent()) |
351 m_rootLayer->addChild(m_hudLayer); | 417 m_rootLayer->addChild(m_hudLayer); |
352 } else if (m_hudLayer) { | 418 } else if (m_hudLayer) { |
353 m_hudLayer->removeFromParent(); | 419 m_hudLayer->removeFromParent(); |
354 m_hudLayer = 0; | 420 m_hudLayer = 0; |
355 } | 421 } |
422 | |
423 // Setup pinch-zoom scrollbars if required. | |
424 if (m_settings.usePinchZoomScrollbars) | |
425 createAndAddPinchZoomScrollbars(); | |
356 } | 426 } |
357 | 427 |
358 void LayerTreeHost::commitComplete() | 428 void LayerTreeHost::commitComplete() |
359 { | 429 { |
360 m_client->didCommit(); | 430 m_client->didCommit(); |
361 } | 431 } |
362 | 432 |
363 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface() | 433 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface() |
364 { | 434 { |
365 return m_client->createOutputSurface(); | 435 return m_client->createOutputSurface(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 } | 562 } |
493 | 563 |
494 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) | 564 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) |
495 { | 565 { |
496 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) | 566 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) |
497 return; | 567 return; |
498 | 568 |
499 m_layoutViewportSize = layoutViewportSize; | 569 m_layoutViewportSize = layoutViewportSize; |
500 m_deviceViewportSize = deviceViewportSize; | 570 m_deviceViewportSize = deviceViewportSize; |
501 | 571 |
572 setPinchZoomScrollbarsBoundsAndPosition(); | |
502 setNeedsCommit(); | 573 setNeedsCommit(); |
503 } | 574 } |
504 | 575 |
505 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min PageScaleFactor, float maxPageScaleFactor) | 576 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min PageScaleFactor, float maxPageScaleFactor) |
506 { | 577 { |
507 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) | 578 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) |
508 return; | 579 return; |
509 | 580 |
510 m_pageScaleFactor = pageScaleFactor; | 581 m_pageScaleFactor = pageScaleFactor; |
511 m_minPageScaleFactor = minPageScaleFactor; | 582 m_minPageScaleFactor = minPageScaleFactor; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 | 656 |
586 for (size_t i = 0; i < layer->children().size(); ++i) { | 657 for (size_t i = 0; i < layer->children().size(); ++i) { |
587 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); | 658 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); |
588 if (found) | 659 if (found) |
589 return found; | 660 return found; |
590 } | 661 } |
591 | 662 |
592 return 0; | 663 return 0; |
593 } | 664 } |
594 | 665 |
666 Layer* LayerTreeHost::rootScrollLayer() const | |
667 { | |
668 return findFirstScrollableLayer(m_rootLayer.get()); | |
669 } | |
670 | |
595 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) | 671 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) |
596 { | 672 { |
597 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); | 673 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); |
598 | 674 |
599 LayerList updateList; | 675 LayerList updateList; |
600 | 676 |
601 { | 677 { |
602 Layer* rootScroll = findFirstScrollableLayer(rootLayer); | 678 Layer* rootScroll = findFirstScrollableLayer(rootLayer); |
603 if (rootScroll) | 679 if (rootScroll) |
604 rootScroll->setImplTransform(m_implTransform); | 680 rootScroll->setImplTransform(m_implTransform); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 } | 952 } |
877 } | 953 } |
878 | 954 |
879 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime) | 955 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime) |
880 { | 956 { |
881 if (!layer) | 957 if (!layer) |
882 return; | 958 return; |
883 | 959 |
884 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { | 960 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { |
885 if (layer->id() == events[eventIndex].layerId) { | 961 if (layer->id() == events[eventIndex].layerId) { |
886 if (events[eventIndex].type == AnimationEvent::Started) | 962 switch (events[eventIndex].type) { |
963 case AnimationEvent::Started : | |
887 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT()); | 964 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT()); |
888 else | 965 break; |
966 case AnimationEvent::Finished : | |
889 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); | 967 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); |
968 break; | |
969 | |
970 case AnimationEvent::PropertyUpdate : | |
971 layer->notifyAnimationPropertyUpdate(events[eventIndex]); | |
972 break; | |
973 | |
974 default: | |
975 NOTREACHED(); | |
976 } | |
890 } | 977 } |
891 } | 978 } |
892 | 979 |
893 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) | 980 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) |
894 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); | 981 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); |
895 } | 982 } |
896 | 983 |
897 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() | 984 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() |
898 { | 985 { |
899 return m_proxy->capturePicture(); | 986 return m_proxy->capturePicture(); |
900 } | 987 } |
901 | 988 |
902 } // namespace cc | 989 } // namespace cc |
OLD | NEW |