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