| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/layer.h" | 7 #include "cc/layer.h" |
| 8 | 8 |
| 9 #include "cc/active_animation.h" | 9 #include "cc/active_animation.h" |
| 10 #include "cc/animation_events.h" | 10 #include "cc/animation_events.h" |
| 11 #include "cc/layer_animation_controller.h" | 11 #include "cc/layer_animation_controller.h" |
| 12 #include "cc/layer_impl.h" | 12 #include "cc/layer_impl.h" |
| 13 #include "cc/layer_tree_host.h" | 13 #include "cc/layer_tree_host.h" |
| 14 #include "cc/settings.h" | 14 #include "cc/settings.h" |
| 15 #include "third_party/skia/include/core/SkImageFilter.h" | 15 #include "third_party/skia/include/core/SkImageFilter.h" |
| 16 #include "ui/gfx/rect_conversions.h" |
| 16 #include <public/WebAnimationDelegate.h> | 17 #include <public/WebAnimationDelegate.h> |
| 17 #include <public/WebLayerScrollClient.h> | 18 #include <public/WebLayerScrollClient.h> |
| 18 #include <public/WebSize.h> | 19 #include <public/WebSize.h> |
| 19 | 20 |
| 20 using namespace std; | 21 using namespace std; |
| 21 using WebKit::WebTransformationMatrix; | 22 using WebKit::WebTransformationMatrix; |
| 22 | 23 |
| 23 namespace cc { | 24 namespace cc { |
| 24 | 25 |
| 25 static int s_nextLayerId = 1; | 26 static int s_nextLayerId = 1; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if (host && m_layerAnimationController->hasActiveAnimation()) | 113 if (host && m_layerAnimationController->hasActiveAnimation()) |
| 113 host->didAddAnimation(); | 114 host->didAddAnimation(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void Layer::setNeedsCommit() | 117 void Layer::setNeedsCommit() |
| 117 { | 118 { |
| 118 if (m_layerTreeHost) | 119 if (m_layerTreeHost) |
| 119 m_layerTreeHost->setNeedsCommit(); | 120 m_layerTreeHost->setNeedsCommit(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 IntRect Layer::layerRectToContentRect(const FloatRect& layerRect) const | 123 gfx::Rect Layer::layerRectToContentRect(const gfx::RectF& layerRect) const |
| 123 { | 124 { |
| 124 FloatRect contentRect(layerRect); | 125 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), content
sScaleY()); |
| 125 contentRect.scale(contentsScaleX(), contentsScaleY()); | |
| 126 IntRect intContentRect = enclosingIntRect(contentRect); | |
| 127 // Intersect with content rect to avoid the extra pixel because for some | 126 // Intersect with content rect to avoid the extra pixel because for some |
| 128 // values x and y, ceil((x / y) * y) may be x + 1. | 127 // values x and y, ceil((x / y) * y) may be x + 1. |
| 129 intContentRect.intersect(IntRect(IntPoint(), contentBounds())); | 128 contentRect.Intersect(gfx::Rect(gfx::Point(), contentBounds())); |
| 130 return intContentRect; | 129 return gfx::ToEnclosingRect(contentRect); |
| 131 } | 130 } |
| 132 | 131 |
| 133 void Layer::setParent(Layer* layer) | 132 void Layer::setParent(Layer* layer) |
| 134 { | 133 { |
| 135 DCHECK(!layer || !layer->hasAncestor(this)); | 134 DCHECK(!layer || !layer->hasAncestor(this)); |
| 136 m_parent = layer; | 135 m_parent = layer; |
| 137 setLayerTreeHost(m_parent ? m_parent->layerTreeHost() : 0); | 136 setLayerTreeHost(m_parent ? m_parent->layerTreeHost() : 0); |
| 138 | 137 |
| 139 forceAutomaticRasterScaleToBeRecomputed(); | 138 forceAutomaticRasterScaleToBeRecomputed(); |
| 140 } | 139 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 208 |
| 210 int Layer::indexOfChild(const Layer* reference) | 209 int Layer::indexOfChild(const Layer* reference) |
| 211 { | 210 { |
| 212 for (size_t i = 0; i < m_children.size(); i++) { | 211 for (size_t i = 0; i < m_children.size(); i++) { |
| 213 if (m_children[i] == reference) | 212 if (m_children[i] == reference) |
| 214 return i; | 213 return i; |
| 215 } | 214 } |
| 216 return -1; | 215 return -1; |
| 217 } | 216 } |
| 218 | 217 |
| 219 void Layer::setBounds(const IntSize& size) | 218 void Layer::setBounds(const gfx::Size& size) |
| 220 { | 219 { |
| 221 if (bounds() == size) | 220 if (bounds() == size) |
| 222 return; | 221 return; |
| 223 | 222 |
| 224 bool firstResize = bounds().isEmpty() && !size.isEmpty(); | 223 bool firstResize = bounds().IsEmpty() && !size.IsEmpty(); |
| 225 | 224 |
| 226 m_bounds = size; | 225 m_bounds = size; |
| 227 | 226 |
| 228 if (firstResize) | 227 if (firstResize) |
| 229 setNeedsDisplay(); | 228 setNeedsDisplay(); |
| 230 else | 229 else |
| 231 setNeedsCommit(); | 230 setNeedsCommit(); |
| 232 } | 231 } |
| 233 | 232 |
| 234 Layer* Layer::rootLayer() | 233 Layer* Layer::rootLayer() |
| (...skipping 17 matching lines...) Expand all Loading... |
| 252 { | 251 { |
| 253 if (children == m_children) | 252 if (children == m_children) |
| 254 return; | 253 return; |
| 255 | 254 |
| 256 removeAllChildren(); | 255 removeAllChildren(); |
| 257 size_t listSize = children.size(); | 256 size_t listSize = children.size(); |
| 258 for (size_t i = 0; i < listSize; i++) | 257 for (size_t i = 0; i < listSize; i++) |
| 259 addChild(children[i]); | 258 addChild(children[i]); |
| 260 } | 259 } |
| 261 | 260 |
| 262 void Layer::setAnchorPoint(const FloatPoint& anchorPoint) | 261 void Layer::setAnchorPoint(const gfx::PointF& anchorPoint) |
| 263 { | 262 { |
| 264 if (m_anchorPoint == anchorPoint) | 263 if (m_anchorPoint == anchorPoint) |
| 265 return; | 264 return; |
| 266 m_anchorPoint = anchorPoint; | 265 m_anchorPoint = anchorPoint; |
| 267 setNeedsCommit(); | 266 setNeedsCommit(); |
| 268 } | 267 } |
| 269 | 268 |
| 270 void Layer::setAnchorPointZ(float anchorPointZ) | 269 void Layer::setAnchorPointZ(float anchorPointZ) |
| 271 { | 270 { |
| 272 if (m_anchorPointZ == anchorPointZ) | 271 if (m_anchorPointZ == anchorPointZ) |
| 273 return; | 272 return; |
| 274 m_anchorPointZ = anchorPointZ; | 273 m_anchorPointZ = anchorPointZ; |
| 275 setNeedsCommit(); | 274 setNeedsCommit(); |
| 276 } | 275 } |
| 277 | 276 |
| 278 void Layer::setBackgroundColor(SkColor backgroundColor) | 277 void Layer::setBackgroundColor(SkColor backgroundColor) |
| 279 { | 278 { |
| 280 if (m_backgroundColor == backgroundColor) | 279 if (m_backgroundColor == backgroundColor) |
| 281 return; | 280 return; |
| 282 m_backgroundColor = backgroundColor; | 281 m_backgroundColor = backgroundColor; |
| 283 setNeedsCommit(); | 282 setNeedsCommit(); |
| 284 } | 283 } |
| 285 | 284 |
| 286 IntSize Layer::contentBounds() const | 285 gfx::Size Layer::contentBounds() const |
| 287 { | 286 { |
| 288 return bounds(); | 287 return bounds(); |
| 289 } | 288 } |
| 290 | 289 |
| 291 void Layer::setMasksToBounds(bool masksToBounds) | 290 void Layer::setMasksToBounds(bool masksToBounds) |
| 292 { | 291 { |
| 293 if (m_masksToBounds == masksToBounds) | 292 if (m_masksToBounds == masksToBounds) |
| 294 return; | 293 return; |
| 295 m_masksToBounds = masksToBounds; | 294 m_masksToBounds = masksToBounds; |
| 296 setNeedsCommit(); | 295 setNeedsCommit(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 372 } |
| 374 | 373 |
| 375 void Layer::setContentsOpaque(bool opaque) | 374 void Layer::setContentsOpaque(bool opaque) |
| 376 { | 375 { |
| 377 if (m_contentsOpaque == opaque) | 376 if (m_contentsOpaque == opaque) |
| 378 return; | 377 return; |
| 379 m_contentsOpaque = opaque; | 378 m_contentsOpaque = opaque; |
| 380 setNeedsDisplay(); | 379 setNeedsDisplay(); |
| 381 } | 380 } |
| 382 | 381 |
| 383 void Layer::setPosition(const FloatPoint& position) | 382 void Layer::setPosition(const gfx::PointF& position) |
| 384 { | 383 { |
| 385 if (m_position == position) | 384 if (m_position == position) |
| 386 return; | 385 return; |
| 387 m_position = position; | 386 m_position = position; |
| 388 setNeedsCommit(); | 387 setNeedsCommit(); |
| 389 } | 388 } |
| 390 | 389 |
| 391 void Layer::setSublayerTransform(const WebTransformationMatrix& sublayerTransfor
m) | 390 void Layer::setSublayerTransform(const WebTransformationMatrix& sublayerTransfor
m) |
| 392 { | 391 { |
| 393 if (m_sublayerTransform == sublayerTransform) | 392 if (m_sublayerTransform == sublayerTransform) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 498 |
| 500 m_isDrawable = isDrawable; | 499 m_isDrawable = isDrawable; |
| 501 setNeedsCommit(); | 500 setNeedsCommit(); |
| 502 } | 501 } |
| 503 | 502 |
| 504 Layer* Layer::parent() const | 503 Layer* Layer::parent() const |
| 505 { | 504 { |
| 506 return m_parent; | 505 return m_parent; |
| 507 } | 506 } |
| 508 | 507 |
| 509 void Layer::setNeedsDisplayRect(const FloatRect& dirtyRect) | 508 void Layer::setNeedsDisplayRect(const gfx::RectF& dirtyRect) |
| 510 { | 509 { |
| 511 m_updateRect.unite(dirtyRect); | 510 m_updateRect.Union(dirtyRect); |
| 512 | 511 |
| 513 // Simply mark the contents as dirty. For non-root layers, the call to | 512 // Simply mark the contents as dirty. For non-root layers, the call to |
| 514 // setNeedsCommit will schedule a fresh compositing pass. | 513 // setNeedsCommit will schedule a fresh compositing pass. |
| 515 // For the root layer, setNeedsCommit has no effect. | 514 // For the root layer, setNeedsCommit has no effect. |
| 516 if (!dirtyRect.isEmpty()) | 515 if (!dirtyRect.IsEmpty()) |
| 517 m_needsDisplay = true; | 516 m_needsDisplay = true; |
| 518 | 517 |
| 519 if (drawsContent()) | 518 if (drawsContent()) |
| 520 setNeedsCommit(); | 519 setNeedsCommit(); |
| 521 } | 520 } |
| 522 | 521 |
| 523 bool Layer::descendantIsFixedToContainerLayer() const | 522 bool Layer::descendantIsFixedToContainerLayer() const |
| 524 { | 523 { |
| 525 for (size_t i = 0; i < m_children.size(); ++i) { | 524 for (size_t i = 0; i < m_children.size(); ++i) { |
| 526 if (m_children[i]->fixedToContainerLayer() || m_children[i]->descendantI
sFixedToContainerLayer()) | 525 if (m_children[i]->fixedToContainerLayer() || m_children[i]->descendantI
sFixedToContainerLayer()) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility); | 589 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility); |
| 591 layer->setScrollPosition(m_scrollPosition); | 590 layer->setScrollPosition(m_scrollPosition); |
| 592 layer->setMaxScrollPosition(m_maxScrollPosition); | 591 layer->setMaxScrollPosition(m_maxScrollPosition); |
| 593 layer->setSublayerTransform(m_sublayerTransform); | 592 layer->setSublayerTransform(m_sublayerTransform); |
| 594 if (!transformIsAnimating()) | 593 if (!transformIsAnimating()) |
| 595 layer->setTransform(m_transform); | 594 layer->setTransform(m_transform); |
| 596 | 595 |
| 597 // If the main thread commits multiple times before the impl thread actually
draws, then damage tracking | 596 // If the main thread commits multiple times before the impl thread actually
draws, then damage tracking |
| 598 // will become incorrect if we simply clobber the updateRect here. The Layer
Impl's updateRect needs to | 597 // will become incorrect if we simply clobber the updateRect here. The Layer
Impl's updateRect needs to |
| 599 // accumulate (i.e. union) any update changes that have occurred on the main
thread. | 598 // accumulate (i.e. union) any update changes that have occurred on the main
thread. |
| 600 m_updateRect.uniteIfNonZero(layer->updateRect()); | 599 m_updateRect.Union(layer->updateRect()); |
| 601 layer->setUpdateRect(m_updateRect); | 600 layer->setUpdateRect(m_updateRect); |
| 602 | 601 |
| 603 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta()); | 602 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta()); |
| 604 layer->setSentScrollDelta(IntSize()); | 603 layer->setSentScrollDelta(IntSize()); |
| 605 | 604 |
| 606 layer->setStackingOrderChanged(m_stackingOrderChanged); | 605 layer->setStackingOrderChanged(m_stackingOrderChanged); |
| 607 | 606 |
| 608 if (maskLayer()) | 607 if (maskLayer()) |
| 609 maskLayer()->pushPropertiesTo(layer->maskLayer()); | 608 maskLayer()->pushPropertiesTo(layer->maskLayer()); |
| 610 if (replicaLayer()) | 609 if (replicaLayer()) |
| 611 replicaLayer()->pushPropertiesTo(layer->replicaLayer()); | 610 replicaLayer()->pushPropertiesTo(layer->replicaLayer()); |
| 612 | 611 |
| 613 m_layerAnimationController->pushAnimationUpdatesTo(layer->layerAnimationCont
roller()); | 612 m_layerAnimationController->pushAnimationUpdatesTo(layer->layerAnimationCont
roller()); |
| 614 | 613 |
| 615 // Reset any state that should be cleared for the next update. | 614 // Reset any state that should be cleared for the next update. |
| 616 m_stackingOrderChanged = false; | 615 m_stackingOrderChanged = false; |
| 617 m_updateRect = FloatRect(); | 616 m_updateRect = gfx::RectF(); |
| 618 } | 617 } |
| 619 | 618 |
| 620 scoped_ptr<LayerImpl> Layer::createLayerImpl() | 619 scoped_ptr<LayerImpl> Layer::createLayerImpl() |
| 621 { | 620 { |
| 622 return LayerImpl::create(m_layerId); | 621 return LayerImpl::create(m_layerId); |
| 623 } | 622 } |
| 624 | 623 |
| 625 bool Layer::drawsContent() const | 624 bool Layer::drawsContent() const |
| 626 { | 625 { |
| 627 return m_isDrawable; | 626 return m_isDrawable; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 | 823 |
| 825 void Layer::notifyAnimationFinished(double wallClockTime) | 824 void Layer::notifyAnimationFinished(double wallClockTime) |
| 826 { | 825 { |
| 827 if (m_layerAnimationDelegate) | 826 if (m_layerAnimationDelegate) |
| 828 m_layerAnimationDelegate->notifyAnimationFinished(wallClockTime); | 827 m_layerAnimationDelegate->notifyAnimationFinished(wallClockTime); |
| 829 } | 828 } |
| 830 | 829 |
| 831 Region Layer::visibleContentOpaqueRegion() const | 830 Region Layer::visibleContentOpaqueRegion() const |
| 832 { | 831 { |
| 833 if (contentsOpaque()) | 832 if (contentsOpaque()) |
| 834 return visibleContentRect(); | 833 return cc::IntRect(visibleContentRect()); |
| 835 return Region(); | 834 return Region(); |
| 836 } | 835 } |
| 837 | 836 |
| 838 ScrollbarLayer* Layer::toScrollbarLayer() | 837 ScrollbarLayer* Layer::toScrollbarLayer() |
| 839 { | 838 { |
| 840 return 0; | 839 return 0; |
| 841 } | 840 } |
| 842 | 841 |
| 843 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) | 842 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) |
| 844 { | 843 { |
| 845 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. | 844 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. |
| 846 } | 845 } |
| 847 | 846 |
| 848 } | 847 } |
| OLD | NEW |