| 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/debug_border_draw_quad.h" | 10 #include "cc/debug_border_draw_quad.h" |
| 11 #include "cc/debug_colors.h" | 11 #include "cc/debug_colors.h" |
| 12 #include "cc/layer_tree_host_impl.h" | 12 #include "cc/layer_tree_host_impl.h" |
| 13 #include "cc/layer_tree_impl.h" |
| 13 #include "cc/math_util.h" | 14 #include "cc/math_util.h" |
| 14 #include "cc/proxy.h" | 15 #include "cc/proxy.h" |
| 15 #include "cc/quad_sink.h" | 16 #include "cc/quad_sink.h" |
| 16 #include "cc/scrollbar_animation_controller.h" | 17 #include "cc/scrollbar_animation_controller.h" |
| 17 #include "ui/gfx/point_conversions.h" | 18 #include "ui/gfx/point_conversions.h" |
| 18 #include "ui/gfx/rect_conversions.h" | 19 #include "ui/gfx/rect_conversions.h" |
| 19 | 20 |
| 20 namespace cc { | 21 namespace cc { |
| 21 | 22 |
| 22 LayerImpl::LayerImpl(LayerTreeHostImpl* hostImpl, int id) | 23 LayerImpl::LayerImpl(LayerTreeImpl* treeImpl, int id) |
| 23 : m_parent(0) | 24 : m_parent(0) |
| 24 , m_maskLayerId(-1) | 25 , m_maskLayerId(-1) |
| 25 , m_replicaLayerId(-1) | 26 , m_replicaLayerId(-1) |
| 26 , m_layerId(id) | 27 , m_layerId(id) |
| 27 , m_layerTreeHostImpl(hostImpl) | 28 , m_layerTreeImpl(treeImpl) |
| 28 , m_anchorPoint(0.5, 0.5) | 29 , m_anchorPoint(0.5, 0.5) |
| 29 , m_anchorPointZ(0) | 30 , m_anchorPointZ(0) |
| 30 , m_contentsScaleX(1.0) | 31 , m_contentsScaleX(1.0) |
| 31 , m_contentsScaleY(1.0) | 32 , m_contentsScaleY(1.0) |
| 32 , m_scrollable(false) | 33 , m_scrollable(false) |
| 33 , m_shouldScrollOnMainThread(false) | 34 , m_shouldScrollOnMainThread(false) |
| 34 , m_haveWheelEventHandlers(false) | 35 , m_haveWheelEventHandlers(false) |
| 35 , m_backgroundColor(0) | 36 , m_backgroundColor(0) |
| 36 , m_doubleSided(true) | 37 , m_doubleSided(true) |
| 37 , m_layerPropertyChanged(false) | 38 , m_layerPropertyChanged(false) |
| 38 , m_layerSurfacePropertyChanged(false) | 39 , m_layerSurfacePropertyChanged(false) |
| 39 , m_masksToBounds(false) | 40 , m_masksToBounds(false) |
| 40 , m_contentsOpaque(false) | 41 , m_contentsOpaque(false) |
| 41 , m_opacity(1.0) | 42 , m_opacity(1.0) |
| 42 , m_preserves3D(false) | 43 , m_preserves3D(false) |
| 43 , m_useParentBackfaceVisibility(false) | 44 , m_useParentBackfaceVisibility(false) |
| 44 , m_drawCheckerboardForMissingTiles(false) | 45 , m_drawCheckerboardForMissingTiles(false) |
| 45 , m_useLCDText(false) | 46 , m_useLCDText(false) |
| 46 , m_drawsContent(false) | 47 , m_drawsContent(false) |
| 47 , m_forceRenderSurface(false) | 48 , m_forceRenderSurface(false) |
| 48 , m_isContainerForFixedPositionLayers(false) | 49 , m_isContainerForFixedPositionLayers(false) |
| 49 , m_fixedToContainerLayer(false) | 50 , m_fixedToContainerLayer(false) |
| 50 , m_drawDepth(0) | 51 , m_drawDepth(0) |
| 51 #ifndef NDEBUG | 52 #ifndef NDEBUG |
| 52 , m_betweenWillDrawAndDidDraw(false) | 53 , m_betweenWillDrawAndDidDraw(false) |
| 53 #endif | 54 #endif |
| 54 , m_layerAnimationController(LayerAnimationController::create(this)) | 55 , m_layerAnimationController(LayerAnimationController::create(this)) |
| 55 { | 56 { |
| 56 DCHECK(m_layerId > 0); | 57 DCHECK(m_layerId > 0); |
| 57 DCHECK(m_layerTreeHostImpl); | 58 DCHECK(m_layerTreeImpl); |
| 58 } | 59 } |
| 59 | 60 |
| 60 LayerImpl::~LayerImpl() | 61 LayerImpl::~LayerImpl() |
| 61 { | 62 { |
| 62 #ifndef NDEBUG | 63 #ifndef NDEBUG |
| 63 DCHECK(!m_betweenWillDrawAndDidDraw); | 64 DCHECK(!m_betweenWillDrawAndDidDraw); |
| 64 #endif | 65 #endif |
| 65 } | 66 } |
| 66 | 67 |
| 67 void LayerImpl::addChild(scoped_ptr<LayerImpl> child) | 68 void LayerImpl::addChild(scoped_ptr<LayerImpl> child) |
| 68 { | 69 { |
| 69 child->setParent(this); | 70 child->setParent(this); |
| 70 DCHECK_EQ(layerTreeHostImpl(), child->layerTreeHostImpl()); | 71 DCHECK_EQ(layerTreeHostImpl(), child->layerTreeHostImpl()); |
| 71 m_children.append(child.Pass()); | 72 m_children.append(child.Pass()); |
| 72 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 73 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 scoped_ptr<LayerImpl> LayerImpl::removeChild(LayerImpl* child) | 76 scoped_ptr<LayerImpl> LayerImpl::removeChild(LayerImpl* child) |
| 76 { | 77 { |
| 77 for (size_t i = 0; i < m_children.size(); ++i) { | 78 for (size_t i = 0; i < m_children.size(); ++i) { |
| 78 if (m_children[i] == child) { | 79 if (m_children[i] == child) { |
| 79 scoped_ptr<LayerImpl> ret = m_children.take(i); | 80 scoped_ptr<LayerImpl> ret = m_children.take(i); |
| 80 m_children.remove(i); | 81 m_children.remove(i); |
| 81 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 82 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 82 return ret.Pass(); | 83 return ret.Pass(); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 return scoped_ptr<LayerImpl>(); | 86 return scoped_ptr<LayerImpl>(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void LayerImpl::removeAllChildren() | 89 void LayerImpl::removeAllChildren() |
| 89 { | 90 { |
| 90 m_children.clear(); | 91 m_children.clear(); |
| 91 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 92 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void LayerImpl::clearChildList() | 95 void LayerImpl::clearChildList() |
| 95 { | 96 { |
| 96 if (m_children.isEmpty()) | 97 if (m_children.isEmpty()) |
| 97 return; | 98 return; |
| 98 | 99 |
| 99 m_children.clear(); | 100 m_children.clear(); |
| 100 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 101 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void LayerImpl::createRenderSurface() | 104 void LayerImpl::createRenderSurface() |
| 104 { | 105 { |
| 105 DCHECK(!m_drawProperties.render_surface); | 106 DCHECK(!m_drawProperties.render_surface); |
| 106 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurfaceImpl(this
)); | 107 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurfaceImpl(this
)); |
| 107 m_drawProperties.render_target = this; | 108 m_drawProperties.render_target = this; |
| 108 } | 109 } |
| 109 | 110 |
| 110 int LayerImpl::descendantsDrawContent() | 111 int LayerImpl::descendantsDrawContent() |
| 111 { | 112 { |
| 112 int result = 0; | 113 int result = 0; |
| 113 for (size_t i = 0; i < m_children.size(); ++i) { | 114 for (size_t i = 0; i < m_children.size(); ++i) { |
| 114 if (m_children[i]->drawsContent()) | 115 if (m_children[i]->drawsContent()) |
| 115 ++result; | 116 ++result; |
| 116 result += m_children[i]->descendantsDrawContent(); | 117 result += m_children[i]->descendantsDrawContent(); |
| 117 if (result > 1) | 118 if (result > 1) |
| 118 return result; | 119 return result; |
| 119 } | 120 } |
| 120 return result; | 121 return result; |
| 121 } | 122 } |
| 122 | 123 |
| 124 LayerTreeHostImpl* LayerImpl::layerTreeHostImpl() const { |
| 125 return m_layerTreeImpl->layer_tree_host_impl(); |
| 126 } |
| 127 |
| 123 scoped_ptr<SharedQuadState> LayerImpl::createSharedQuadState() const | 128 scoped_ptr<SharedQuadState> LayerImpl::createSharedQuadState() const |
| 124 { | 129 { |
| 125 scoped_ptr<SharedQuadState> state = SharedQuadState::Create(); | 130 scoped_ptr<SharedQuadState> state = SharedQuadState::Create(); |
| 126 state->SetAll(m_drawProperties.target_space_transform, | 131 state->SetAll(m_drawProperties.target_space_transform, |
| 127 m_drawProperties.visible_content_rect, | 132 m_drawProperties.visible_content_rect, |
| 128 m_drawProperties.drawable_content_rect, | 133 m_drawProperties.drawable_content_rect, |
| 129 m_drawProperties.clip_rect, | 134 m_drawProperties.clip_rect, |
| 130 m_drawProperties.is_clipped, | 135 m_drawProperties.is_clipped, |
| 131 m_drawProperties.opacity); | 136 m_drawProperties.opacity); |
| 132 return state.Pass(); | 137 return state.Pass(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 144 void LayerImpl::didDraw(ResourceProvider*) | 149 void LayerImpl::didDraw(ResourceProvider*) |
| 145 { | 150 { |
| 146 #ifndef NDEBUG | 151 #ifndef NDEBUG |
| 147 DCHECK(m_betweenWillDrawAndDidDraw); | 152 DCHECK(m_betweenWillDrawAndDidDraw); |
| 148 m_betweenWillDrawAndDidDraw = false; | 153 m_betweenWillDrawAndDidDraw = false; |
| 149 #endif | 154 #endif |
| 150 } | 155 } |
| 151 | 156 |
| 152 bool LayerImpl::showDebugBorders() const | 157 bool LayerImpl::showDebugBorders() const |
| 153 { | 158 { |
| 154 return m_layerTreeHostImpl->debugState().showDebugBorders; | 159 return layerTreeHostImpl()->debugState().showDebugBorders; |
| 155 } | 160 } |
| 156 | 161 |
| 157 void LayerImpl::getDebugBorderProperties(SkColor* color, float* width) const | 162 void LayerImpl::getDebugBorderProperties(SkColor* color, float* width) const |
| 158 { | 163 { |
| 159 if (m_drawsContent) { | 164 if (m_drawsContent) { |
| 160 *color = DebugColors::ContentLayerBorderColor(); | 165 *color = DebugColors::ContentLayerBorderColor(); |
| 161 *width = DebugColors::ContentLayerBorderWidth(m_layerTreeHostImpl); | 166 *width = DebugColors::ContentLayerBorderWidth(layerTreeHostImpl()); |
| 162 return; | 167 return; |
| 163 } | 168 } |
| 164 | 169 |
| 165 if (m_masksToBounds) { | 170 if (m_masksToBounds) { |
| 166 *color = DebugColors::MaskingLayerBorderColor(); | 171 *color = DebugColors::MaskingLayerBorderColor(); |
| 167 *width = DebugColors::MaskingLayerBorderWidth(m_layerTreeHostImpl); | 172 *width = DebugColors::MaskingLayerBorderWidth(layerTreeHostImpl()); |
| 168 return; | 173 return; |
| 169 } | 174 } |
| 170 | 175 |
| 171 *color = DebugColors::ContainerLayerBorderColor(); | 176 *color = DebugColors::ContainerLayerBorderColor(); |
| 172 *width = DebugColors::ContainerLayerBorderWidth(m_layerTreeHostImpl); | 177 *width = DebugColors::ContainerLayerBorderWidth(layerTreeHostImpl()); |
| 173 } | 178 } |
| 174 | 179 |
| 175 void LayerImpl::appendDebugBorderQuad(QuadSink& quadList, const SharedQuadState*
sharedQuadState, AppendQuadsData& appendQuadsData) const | 180 void LayerImpl::appendDebugBorderQuad(QuadSink& quadList, const SharedQuadState*
sharedQuadState, AppendQuadsData& appendQuadsData) const |
| 176 { | 181 { |
| 177 if (!showDebugBorders()) | 182 if (!showDebugBorders()) |
| 178 return; | 183 return; |
| 179 | 184 |
| 180 SkColor color; | 185 SkColor color; |
| 181 float width; | 186 float width; |
| 182 getDebugBorderProperties(&color, &width); | 187 getDebugBorderProperties(&color, &width); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (!scrollable()) { | 264 if (!scrollable()) { |
| 260 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); | 265 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); |
| 261 return InputHandlerClient::ScrollIgnored; | 266 return InputHandlerClient::ScrollIgnored; |
| 262 } | 267 } |
| 263 | 268 |
| 264 return InputHandlerClient::ScrollStarted; | 269 return InputHandlerClient::ScrollStarted; |
| 265 } | 270 } |
| 266 | 271 |
| 267 bool LayerImpl::drawCheckerboardForMissingTiles() const | 272 bool LayerImpl::drawCheckerboardForMissingTiles() const |
| 268 { | 273 { |
| 269 return m_drawCheckerboardForMissingTiles && !m_layerTreeHostImpl->settings()
.backgroundColorInsteadOfCheckerboard; | 274 return m_drawCheckerboardForMissingTiles && !layerTreeHostImpl()->settings()
.backgroundColorInsteadOfCheckerboard; |
| 270 } | 275 } |
| 271 | 276 |
| 272 gfx::Rect LayerImpl::layerRectToContentRect(const gfx::RectF& layerRect) const | 277 gfx::Rect LayerImpl::layerRectToContentRect(const gfx::RectF& layerRect) const |
| 273 { | 278 { |
| 274 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), content
sScaleY()); | 279 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), content
sScaleY()); |
| 275 // Intersect with content rect to avoid the extra pixel because for some | 280 // Intersect with content rect to avoid the extra pixel because for some |
| 276 // values x and y, ceil((x / y) * y) may be x + 1. | 281 // values x and y, ceil((x / y) * y) may be x + 1. |
| 277 contentRect.Intersect(gfx::Rect(gfx::Point(), contentBounds())); | 282 contentRect.Intersect(gfx::Rect(gfx::Point(), contentBounds())); |
| 278 return gfx::ToEnclosingRect(contentRect); | 283 return gfx::ToEnclosingRect(contentRect); |
| 279 } | 284 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 return true; | 407 return true; |
| 403 current = current->m_parent; | 408 current = current->m_parent; |
| 404 } | 409 } |
| 405 | 410 |
| 406 return false; | 411 return false; |
| 407 } | 412 } |
| 408 | 413 |
| 409 void LayerImpl::noteLayerSurfacePropertyChanged() | 414 void LayerImpl::noteLayerSurfacePropertyChanged() |
| 410 { | 415 { |
| 411 m_layerSurfacePropertyChanged = true; | 416 m_layerSurfacePropertyChanged = true; |
| 412 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 417 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 413 } | 418 } |
| 414 | 419 |
| 415 void LayerImpl::noteLayerPropertyChanged() | 420 void LayerImpl::noteLayerPropertyChanged() |
| 416 { | 421 { |
| 417 m_layerPropertyChanged = true; | 422 m_layerPropertyChanged = true; |
| 418 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 423 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 419 } | 424 } |
| 420 | 425 |
| 421 void LayerImpl::noteLayerPropertyChangedForSubtree() | 426 void LayerImpl::noteLayerPropertyChangedForSubtree() |
| 422 { | 427 { |
| 423 noteLayerPropertyChanged(); | 428 noteLayerPropertyChanged(); |
| 424 noteLayerPropertyChangedForDescendants(); | 429 noteLayerPropertyChangedForDescendants(); |
| 425 } | 430 } |
| 426 | 431 |
| 427 void LayerImpl::noteLayerPropertyChangedForDescendants() | 432 void LayerImpl::noteLayerPropertyChangedForDescendants() |
| 428 { | 433 { |
| 429 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 434 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 430 for (size_t i = 0; i < m_children.size(); ++i) | 435 for (size_t i = 0; i < m_children.size(); ++i) |
| 431 m_children[i]->noteLayerPropertyChangedForSubtree(); | 436 m_children[i]->noteLayerPropertyChangedForSubtree(); |
| 432 } | 437 } |
| 433 | 438 |
| 434 const char* LayerImpl::layerTypeAsString() const | 439 const char* LayerImpl::layerTypeAsString() const |
| 435 { | 440 { |
| 436 return "Layer"; | 441 return "Layer"; |
| 437 } | 442 } |
| 438 | 443 |
| 439 void LayerImpl::resetAllChangeTrackingForSubtree() | 444 void LayerImpl::resetAllChangeTrackingForSubtree() |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 void LayerImpl::didLoseOutputSurface() | 736 void LayerImpl::didLoseOutputSurface() |
| 732 { | 737 { |
| 733 } | 738 } |
| 734 | 739 |
| 735 void LayerImpl::setMaxScrollOffset(gfx::Vector2d maxScrollOffset) | 740 void LayerImpl::setMaxScrollOffset(gfx::Vector2d maxScrollOffset) |
| 736 { | 741 { |
| 737 if (m_maxScrollOffset == maxScrollOffset) | 742 if (m_maxScrollOffset == maxScrollOffset) |
| 738 return; | 743 return; |
| 739 m_maxScrollOffset = maxScrollOffset; | 744 m_maxScrollOffset = maxScrollOffset; |
| 740 | 745 |
| 741 m_layerTreeHostImpl->setNeedsUpdateDrawProperties(); | 746 layerTreeHostImpl()->setNeedsUpdateDrawProperties(); |
| 742 | 747 |
| 743 if (!m_scrollbarAnimationController) | 748 if (!m_scrollbarAnimationController) |
| 744 return; | 749 return; |
| 745 m_scrollbarAnimationController->updateScrollOffset(this); | 750 m_scrollbarAnimationController->updateScrollOffset(this); |
| 746 } | 751 } |
| 747 | 752 |
| 748 ScrollbarLayerImpl* LayerImpl::horizontalScrollbarLayer() | 753 ScrollbarLayerImpl* LayerImpl::horizontalScrollbarLayer() |
| 749 { | 754 { |
| 750 return m_scrollbarAnimationController ? m_scrollbarAnimationController->hori
zontalScrollbarLayer() : 0; | 755 return m_scrollbarAnimationController ? m_scrollbarAnimationController->hori
zontalScrollbarLayer() : 0; |
| 751 } | 756 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 775 | 780 |
| 776 void LayerImpl::setVerticalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) | 781 void LayerImpl::setVerticalScrollbarLayer(ScrollbarLayerImpl* scrollbarLayer) |
| 777 { | 782 { |
| 778 if (!m_scrollbarAnimationController) | 783 if (!m_scrollbarAnimationController) |
| 779 m_scrollbarAnimationController = ScrollbarAnimationController::create(th
is); | 784 m_scrollbarAnimationController = ScrollbarAnimationController::create(th
is); |
| 780 m_scrollbarAnimationController->setVerticalScrollbarLayer(scrollbarLayer); | 785 m_scrollbarAnimationController->setVerticalScrollbarLayer(scrollbarLayer); |
| 781 m_scrollbarAnimationController->updateScrollOffset(this); | 786 m_scrollbarAnimationController->updateScrollOffset(this); |
| 782 } | 787 } |
| 783 | 788 |
| 784 } // namespace cc | 789 } // namespace cc |
| OLD | NEW |