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