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_impl.h" | 5 #include "cc/layer_impl.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "cc/animation_registrar.h" | 10 #include "cc/animation_registrar.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 , m_maskLayerId(-1) | 29 , m_maskLayerId(-1) |
30 , m_replicaLayerId(-1) | 30 , m_replicaLayerId(-1) |
31 , m_layerId(id) | 31 , m_layerId(id) |
32 , m_layerTreeImpl(treeImpl) | 32 , m_layerTreeImpl(treeImpl) |
33 , m_anchorPoint(0.5, 0.5) | 33 , m_anchorPoint(0.5, 0.5) |
34 , m_anchorPointZ(0) | 34 , m_anchorPointZ(0) |
35 , m_scrollable(false) | 35 , m_scrollable(false) |
36 , m_shouldScrollOnMainThread(false) | 36 , m_shouldScrollOnMainThread(false) |
37 , m_haveWheelEventHandlers(false) | 37 , m_haveWheelEventHandlers(false) |
38 , m_backgroundColor(0) | 38 , m_backgroundColor(0) |
| 39 , m_stackingOrderChanged(false) |
39 , m_doubleSided(true) | 40 , m_doubleSided(true) |
40 , m_layerPropertyChanged(false) | 41 , m_layerPropertyChanged(false) |
41 , m_layerSurfacePropertyChanged(false) | 42 , m_layerSurfacePropertyChanged(false) |
42 , m_masksToBounds(false) | 43 , m_masksToBounds(false) |
43 , m_contentsOpaque(false) | 44 , m_contentsOpaque(false) |
44 , m_opacity(1.0) | 45 , m_opacity(1.0) |
45 , m_preserves3D(false) | 46 , m_preserves3D(false) |
46 , m_useParentBackfaceVisibility(false) | 47 , m_useParentBackfaceVisibility(false) |
47 , m_drawCheckerboardForMissingTiles(false) | 48 , m_drawCheckerboardForMissingTiles(false) |
48 , m_drawsContent(false) | 49 , m_drawsContent(false) |
(...skipping 25 matching lines...) Expand all Loading... |
74 } | 75 } |
75 | 76 |
76 void LayerImpl::addChild(scoped_ptr<LayerImpl> child) | 77 void LayerImpl::addChild(scoped_ptr<LayerImpl> child) |
77 { | 78 { |
78 child->setParent(this); | 79 child->setParent(this); |
79 DCHECK_EQ(layerTreeImpl(), child->layerTreeImpl()); | 80 DCHECK_EQ(layerTreeImpl(), child->layerTreeImpl()); |
80 m_children.push_back(child.Pass()); | 81 m_children.push_back(child.Pass()); |
81 layerTreeImpl()->SetNeedsUpdateDrawProperties(); | 82 layerTreeImpl()->SetNeedsUpdateDrawProperties(); |
82 } | 83 } |
83 | 84 |
| 85 LayerImpl* LayerImpl::childAt(size_t index) const |
| 86 { |
| 87 DCHECK_LT(index, m_children.size()); |
| 88 return m_children[index]; |
| 89 } |
| 90 |
84 scoped_ptr<LayerImpl> LayerImpl::removeChild(LayerImpl* child) | 91 scoped_ptr<LayerImpl> LayerImpl::removeChild(LayerImpl* child) |
85 { | 92 { |
86 for (ScopedPtrVector<LayerImpl>::iterator it = m_children.begin(); it != m_c
hildren.end(); ++it) { | 93 for (ScopedPtrVector<LayerImpl>::iterator it = m_children.begin(); it != m_c
hildren.end(); ++it) { |
87 if (*it == child) { | 94 if (*it == child) { |
88 scoped_ptr<LayerImpl> ret = m_children.take(it); | 95 scoped_ptr<LayerImpl> ret = m_children.take(it); |
89 m_children.erase(it); | 96 m_children.erase(it); |
90 layerTreeImpl()->SetNeedsUpdateDrawProperties(); | 97 layerTreeImpl()->SetNeedsUpdateDrawProperties(); |
91 return ret.Pass(); | 98 return ret.Pass(); |
92 } | 99 } |
93 } | 100 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 bool LayerImpl::canClipSelf() const | 305 bool LayerImpl::canClipSelf() const |
299 { | 306 { |
300 return false; | 307 return false; |
301 } | 308 } |
302 | 309 |
303 bool LayerImpl::areVisibleResourcesReady() const | 310 bool LayerImpl::areVisibleResourcesReady() const |
304 { | 311 { |
305 return true; | 312 return true; |
306 } | 313 } |
307 | 314 |
| 315 scoped_ptr<LayerImpl> LayerImpl::createLayerImpl(LayerTreeImpl* treeImpl) |
| 316 { |
| 317 return LayerImpl::create(treeImpl, m_layerId); |
| 318 } |
| 319 |
| 320 void LayerImpl::pushPropertiesTo(LayerImpl* layer) |
| 321 { |
| 322 layer->setAnchorPoint(m_anchorPoint); |
| 323 layer->setAnchorPointZ(m_anchorPointZ); |
| 324 layer->setBackgroundColor(m_backgroundColor); |
| 325 layer->setBounds(m_bounds); |
| 326 layer->setContentBounds(contentBounds()); |
| 327 layer->setContentsScale(contentsScaleX(), contentsScaleY()); |
| 328 layer->setDebugName(m_debugName); |
| 329 layer->setDoubleSided(m_doubleSided); |
| 330 layer->setDrawCheckerboardForMissingTiles(m_drawCheckerboardForMissingTiles)
; |
| 331 layer->setForceRenderSurface(m_forceRenderSurface); |
| 332 layer->setDrawsContent(drawsContent()); |
| 333 layer->setFilters(filters()); |
| 334 layer->setFilter(filter()); |
| 335 layer->setBackgroundFilters(backgroundFilters()); |
| 336 layer->setMasksToBounds(m_masksToBounds); |
| 337 layer->setShouldScrollOnMainThread(m_shouldScrollOnMainThread); |
| 338 layer->setHaveWheelEventHandlers(m_haveWheelEventHandlers); |
| 339 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion); |
| 340 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion); |
| 341 layer->setContentsOpaque(m_contentsOpaque); |
| 342 if (!opacityIsAnimating()) |
| 343 layer->setOpacity(m_opacity); |
| 344 layer->setPosition(m_position); |
| 345 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay
ers); |
| 346 layer->setFixedToContainerLayer(m_fixedToContainerLayer); |
| 347 layer->setPreserves3D(preserves3D()); |
| 348 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility); |
| 349 layer->setSublayerTransform(m_sublayerTransform); |
| 350 if (!transformIsAnimating()) |
| 351 layer->setTransform(m_transform); |
| 352 |
| 353 layer->setScrollable(m_scrollable); |
| 354 layer->setScrollOffset(m_scrollOffset); |
| 355 layer->setMaxScrollOffset(m_maxScrollOffset); |
| 356 |
| 357 // If the main thread commits multiple times before the impl thread actually
draws, then damage tracking |
| 358 // will become incorrect if we simply clobber the updateRect here. The Layer
Impl's updateRect needs to |
| 359 // accumulate (i.e. union) any update changes that have occurred on the main
thread. |
| 360 m_updateRect.Union(layer->updateRect()); |
| 361 layer->setUpdateRect(m_updateRect); |
| 362 |
| 363 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta()); |
| 364 layer->setSentScrollDelta(gfx::Vector2d()); |
| 365 |
| 366 layer->setStackingOrderChanged(m_stackingOrderChanged); |
| 367 |
| 368 m_layerAnimationController->pushAnimationUpdatesTo(layer->layerAnimationCont
roller()); |
| 369 |
| 370 // Reset any state that should be cleared for the next update. |
| 371 m_stackingOrderChanged = false; |
| 372 m_updateRect = gfx::RectF(); |
| 373 } |
| 374 |
308 std::string LayerImpl::indentString(int indent) | 375 std::string LayerImpl::indentString(int indent) |
309 { | 376 { |
310 std::string str; | 377 std::string str; |
311 for (int i = 0; i != indent; ++i) | 378 for (int i = 0; i != indent; ++i) |
312 str.append(" "); | 379 str.append(" "); |
313 return str; | 380 return str; |
314 } | 381 } |
315 | 382 |
316 void LayerImpl::dumpLayerProperties(std::string* str, int indent) const | 383 void LayerImpl::dumpLayerProperties(std::string* str, int indent) const |
317 { | 384 { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 list = new base::ListValue; | 468 list = new base::ListValue; |
402 for (size_t i = 0; i < m_children.size(); ++i) | 469 for (size_t i = 0; i < m_children.size(); ++i) |
403 list->Append(m_children[i]->layerTreeAsJson()); | 470 list->Append(m_children[i]->layerTreeAsJson()); |
404 result->Set("Children", list); | 471 result->Set("Children", list); |
405 | 472 |
406 return result; | 473 return result; |
407 } | 474 } |
408 | 475 |
409 void LayerImpl::setStackingOrderChanged(bool stackingOrderChanged) | 476 void LayerImpl::setStackingOrderChanged(bool stackingOrderChanged) |
410 { | 477 { |
411 // We don't need to store this flag; we only need to track that the change o
ccurred. | 478 if (stackingOrderChanged) { |
412 if (stackingOrderChanged) | 479 m_stackingOrderChanged = true; |
413 noteLayerPropertyChangedForSubtree(); | 480 noteLayerPropertyChangedForSubtree(); |
| 481 } |
414 } | 482 } |
415 | 483 |
416 bool LayerImpl::layerSurfacePropertyChanged() const | 484 bool LayerImpl::layerSurfacePropertyChanged() const |
417 { | 485 { |
418 if (m_layerSurfacePropertyChanged) | 486 if (m_layerSurfacePropertyChanged) |
419 return true; | 487 return true; |
420 | 488 |
421 // If this layer's surface property hasn't changed, we want to see if | 489 // If this layer's surface property hasn't changed, we want to see if |
422 // some layer above us has changed this property. This is done for the | 490 // some layer above us has changed this property. This is done for the |
423 // case when such parent layer does not draw content, and therefore will | 491 // case when such parent layer does not draw content, and therefore will |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 m_replicaLayerId = newLayerId; | 624 m_replicaLayerId = newLayerId; |
557 noteLayerPropertyChangedForSubtree(); | 625 noteLayerPropertyChangedForSubtree(); |
558 } | 626 } |
559 | 627 |
560 scoped_ptr<LayerImpl> LayerImpl::takeReplicaLayer() | 628 scoped_ptr<LayerImpl> LayerImpl::takeReplicaLayer() |
561 { | 629 { |
562 m_replicaLayerId = -1; | 630 m_replicaLayerId = -1; |
563 return m_replicaLayer.Pass(); | 631 return m_replicaLayer.Pass(); |
564 } | 632 } |
565 | 633 |
| 634 ScrollbarLayerImpl* LayerImpl::toScrollbarLayer() |
| 635 { |
| 636 return 0; |
| 637 } |
| 638 |
566 void LayerImpl::setDrawsContent(bool drawsContent) | 639 void LayerImpl::setDrawsContent(bool drawsContent) |
567 { | 640 { |
568 if (m_drawsContent == drawsContent) | 641 if (m_drawsContent == drawsContent) |
569 return; | 642 return; |
570 | 643 |
571 m_drawsContent = drawsContent; | 644 m_drawsContent = drawsContent; |
572 noteLayerPropertyChanged(); | 645 noteLayerPropertyChanged(); |
573 } | 646 } |
574 | 647 |
575 void LayerImpl::setAnchorPoint(const gfx::PointF& anchorPoint) | 648 void LayerImpl::setAnchorPoint(const gfx::PointF& anchorPoint) |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 if (!m_scrollbarAnimationController) | 944 if (!m_scrollbarAnimationController) |
872 m_scrollbarAnimationController = createScrollbarAnimationControllerW
ithFade(this); | 945 m_scrollbarAnimationController = createScrollbarAnimationControllerW
ithFade(this); |
873 } else { | 946 } else { |
874 m_scrollbarAnimationController.reset(); | 947 m_scrollbarAnimationController.reset(); |
875 } | 948 } |
876 | 949 |
877 } | 950 } |
878 void LayerImpl::setHorizontalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) | 951 void LayerImpl::setHorizontalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) |
879 { | 952 { |
880 m_horizontalScrollbarLayer = scrollbarLayer; | 953 m_horizontalScrollbarLayer = scrollbarLayer; |
| 954 if (m_horizontalScrollbarLayer) |
| 955 m_horizontalScrollbarLayer->setScrollLayerId(id()); |
881 } | 956 } |
882 | 957 |
883 void LayerImpl::setVerticalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) | 958 void LayerImpl::setVerticalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) |
884 { | 959 { |
885 m_verticalScrollbarLayer = scrollbarLayer; | 960 m_verticalScrollbarLayer = scrollbarLayer; |
| 961 if (m_verticalScrollbarLayer) |
| 962 m_verticalScrollbarLayer->setScrollLayerId(id()); |
886 } | 963 } |
887 | 964 |
888 } // namespace cc | 965 } // namespace cc |
OLD | NEW |