summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-16 04:52:53 +0000
committerenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-16 04:52:53 +0000
commit344e58d0497d68437f9653fcfc3788d85f3f8450 (patch)
tree321e166fe1f3429ad8d8e5343fde1697aad88de0 /cc
parent95c9d11429b11171b41e28527dc8a915949016fc (diff)
downloadchromium_src-344e58d0497d68437f9653fcfc3788d85f3f8450.zip
chromium_src-344e58d0497d68437f9653fcfc3788d85f3f8450.tar.gz
chromium_src-344e58d0497d68437f9653fcfc3788d85f3f8450.tar.bz2
cc: Refactor content scale/bounds into draw properties
This change allows layer impls to manipulate their content scale. This will allow PictureLayerImpl to pick some contents scale based on the scales of their tilings, rather than being stuck at the contents scale of its PictureLayer. This also de-virtualizes all of the content scale/bounds functions and instead allows a layer to manipulate its draw properties in response to a bounds or contents scale change. BUG=155209 Review URL: https://chromiumcodereview.appspot.com/11503005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173365 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/contents_scaling_layer.cc32
-rw-r--r--cc/contents_scaling_layer.h13
-rw-r--r--cc/contents_scaling_layer_unittest.cc30
-rw-r--r--cc/draw_properties.h10
-rw-r--r--cc/image_layer.cc18
-rw-r--r--cc/image_layer.h10
-rw-r--r--cc/layer.cc27
-rw-r--r--cc/layer.h14
-rw-r--r--cc/layer_impl.cc12
-rw-r--r--cc/layer_impl.h11
-rw-r--r--cc/layer_tree_host_common.cc27
-rw-r--r--cc/layer_tree_host_common_unittest.cc31
-rw-r--r--cc/layer_tree_host_unittest.cc15
-rw-r--r--cc/scrollbar_layer.cc18
-rw-r--r--cc/scrollbar_layer.h6
-rw-r--r--cc/scrollbar_layer_unittest.cc5
-rw-r--r--cc/test/tiled_layer_test_common.cc31
-rw-r--r--cc/test/tiled_layer_test_common.h15
-rw-r--r--cc/tiled_layer_unittest.cc8
19 files changed, 197 insertions, 136 deletions
diff --git a/cc/contents_scaling_layer.cc b/cc/contents_scaling_layer.cc
index 454b6e7..579af34 100644
--- a/cc/contents_scaling_layer.cc
+++ b/cc/contents_scaling_layer.cc
@@ -11,30 +11,28 @@ gfx::Size ContentsScalingLayer::computeContentBoundsForScale(float scaleX, float
return gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scaleX, scaleY));
}
-ContentsScalingLayer::ContentsScalingLayer()
- : m_contentsScale(1.0) {
+ContentsScalingLayer::ContentsScalingLayer() {
}
ContentsScalingLayer::~ContentsScalingLayer() {
}
-gfx::Size ContentsScalingLayer::contentBounds() const {
- return computeContentBoundsForScale(contentsScaleX(), contentsScaleY());
+void ContentsScalingLayer::calculateContentsScale(
+ float ideal_contents_scale,
+ float* contents_scale_x,
+ float* contents_scale_y,
+ gfx::Size* content_bounds) {
+ *contents_scale_x = ideal_contents_scale;
+ *contents_scale_y = ideal_contents_scale;
+ *content_bounds = computeContentBoundsForScale(
+ ideal_contents_scale,
+ ideal_contents_scale);
}
-float ContentsScalingLayer::contentsScaleX() const {
- return m_contentsScale;
-}
-
-float ContentsScalingLayer::contentsScaleY() const {
- return m_contentsScale;
-}
-
-void ContentsScalingLayer::setContentsScale(float contentsScale) {
- if (m_contentsScale == contentsScale)
- return;
- m_contentsScale = contentsScale;
- setNeedsDisplay();
+void ContentsScalingLayer::didUpdateBounds() {
+ drawProperties().content_bounds = computeContentBoundsForScale(
+ contentsScaleX(),
+ contentsScaleY());
}
} // namespace cc
diff --git a/cc/contents_scaling_layer.h b/cc/contents_scaling_layer.h
index 4f0fcdb..81b51ff 100644
--- a/cc/contents_scaling_layer.h
+++ b/cc/contents_scaling_layer.h
@@ -14,19 +14,18 @@ namespace cc {
// The content bounds are determined by bounds and scale of the contents.
class CC_EXPORT ContentsScalingLayer : public Layer {
public:
- virtual gfx::Size contentBounds() const OVERRIDE;
- virtual float contentsScaleX() const OVERRIDE;
- virtual float contentsScaleY() const OVERRIDE;
- virtual void setContentsScale(float contentsScale) OVERRIDE;
+ virtual void calculateContentsScale(
+ float ideal_contents_scale,
+ float* contents_scale_x,
+ float* contents_scale_y,
+ gfx::Size* content_bounds) OVERRIDE;
+ virtual void didUpdateBounds() OVERRIDE;
protected:
ContentsScalingLayer();
virtual ~ContentsScalingLayer();
gfx::Size computeContentBoundsForScale(float scaleX, float scaleY) const;
-
- private:
- float m_contentsScale;
};
} // namespace cc
diff --git a/cc/contents_scaling_layer_unittest.cc b/cc/contents_scaling_layer_unittest.cc
index 1825641..5d17e9c 100644
--- a/cc/contents_scaling_layer_unittest.cc
+++ b/cc/contents_scaling_layer_unittest.cc
@@ -26,7 +26,16 @@ class MockContentsScalingLayer : public ContentsScalingLayer {
}
const gfx::RectF& lastNeedsDisplayRect() const {
- return m_lastNeedsDisplayRect;
+ return m_lastNeedsDisplayRect;
+ }
+
+ void updateContentsScale(float contentsScale) {
+ // Simulate calcDrawProperties.
+ calculateContentsScale(
+ contentsScale,
+ &drawProperties().contents_scale_x,
+ &drawProperties().contents_scale_y,
+ &drawProperties().content_bounds);
}
private:
@@ -46,7 +55,7 @@ TEST(ContentsScalingLayerTest, checkContentsBounds) {
EXPECT_EQ(320, testLayer->contentBounds().width());
EXPECT_EQ(240, testLayer->contentBounds().height());
- testLayer->setContentsScale(2.0f);
+ testLayer->updateContentsScale(2.0f);
EXPECT_EQ(640, testLayer->contentBounds().width());
EXPECT_EQ(480, testLayer->contentBounds().height());
@@ -54,25 +63,10 @@ TEST(ContentsScalingLayerTest, checkContentsBounds) {
EXPECT_EQ(20, testLayer->contentBounds().width());
EXPECT_EQ(40, testLayer->contentBounds().height());
- testLayer->setContentsScale(1.33f);
+ testLayer->updateContentsScale(1.33f);
EXPECT_EQ(14, testLayer->contentBounds().width());
EXPECT_EQ(27, testLayer->contentBounds().height());
}
-TEST(ContentsScalingLayerTest, checkContentsScaleChangeTriggersNeedsDisplay) {
- scoped_refptr<MockContentsScalingLayer> testLayer =
- make_scoped_refptr(new MockContentsScalingLayer());
-
- testLayer->setBounds(gfx::Size(320, 240));
-
- testLayer->resetNeedsDisplay();
- EXPECT_FALSE(testLayer->needsDisplay());
-
- testLayer->setContentsScale(testLayer->contentsScaleX() + 1.f);
- EXPECT_TRUE(testLayer->needsDisplay());
- EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 320, 240),
- testLayer->lastNeedsDisplayRect());
-}
-
} // namespace
} // namespace cc
diff --git a/cc/draw_properties.h b/cc/draw_properties.h
index 3895ef0..e5bf813 100644
--- a/cc/draw_properties.h
+++ b/cc/draw_properties.h
@@ -24,6 +24,8 @@ struct CC_EXPORT DrawProperties {
, can_use_lcd_text(false)
, is_clipped(false)
, render_target(0)
+ , contents_scale_x(1)
+ , contents_scale_y(1)
, num_descendants_that_draw_content(0)
{
}
@@ -75,6 +77,14 @@ struct CC_EXPORT DrawProperties {
// state.
gfx::Rect clip_rect;
+ // The scale used to move between layer space and content space, and bounds
+ // of the space. One is always a function of the other, but which one
+ // depends on the layer type. For picture layers, this is an ideal scale,
+ // and not always the one used.
+ float contents_scale_x;
+ float contents_scale_y;
+ gfx::Size content_bounds;
+
// Does not include this layer itself, only its children and descendants.
int num_descendants_that_draw_content;
};
diff --git a/cc/image_layer.cc b/cc/image_layer.cc
index f3819fa..82ce952 100644
--- a/cc/image_layer.cc
+++ b/cc/image_layer.cc
@@ -74,9 +74,15 @@ LayerUpdater* ImageLayer::updater() const
return m_updater.get();
}
-gfx::Size ImageLayer::contentBounds() const
+void ImageLayer::calculateContentsScale(
+ float ideal_contents_scale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds)
{
- return gfx::Size(m_bitmap.width(), m_bitmap.height());
+ *contentsScaleX = imageContentsScaleX();
+ *contentsScaleY = imageContentsScaleY();
+ *contentBounds = gfx::Size(m_bitmap.width(), m_bitmap.height());
}
bool ImageLayer::drawsContent() const
@@ -84,16 +90,16 @@ bool ImageLayer::drawsContent() const
return !m_bitmap.isNull() && TiledLayer::drawsContent();
}
-float ImageLayer::contentsScaleX() const
+float ImageLayer::imageContentsScaleX() const
{
- if (bounds().IsEmpty() || contentBounds().IsEmpty())
+ if (bounds().IsEmpty() || m_bitmap.width() == 0)
return 1;
return static_cast<float>(m_bitmap.width()) / bounds().width();
}
-float ImageLayer::contentsScaleY() const
+float ImageLayer::imageContentsScaleY() const
{
- if (bounds().IsEmpty() || contentBounds().IsEmpty())
+ if (bounds().IsEmpty() || m_bitmap.height() == 0)
return 1;
return static_cast<float>(m_bitmap.height()) / bounds().height();
}
diff --git a/cc/image_layer.h b/cc/image_layer.h
index f4f6cd7..86d0dac 100644
--- a/cc/image_layer.h
+++ b/cc/image_layer.h
@@ -21,8 +21,11 @@ public:
virtual bool drawsContent() const OVERRIDE;
virtual void setTexturePriorities(const PriorityCalculator&) OVERRIDE;
virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats&) OVERRIDE;
- virtual float contentsScaleX() const OVERRIDE;
- virtual float contentsScaleY() const OVERRIDE;
+ virtual void calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds) OVERRIDE;
void setBitmap(const SkBitmap& image);
@@ -34,7 +37,8 @@ private:
virtual LayerUpdater* updater() const OVERRIDE;
virtual void createUpdaterIfNeeded() OVERRIDE;
- virtual gfx::Size contentBounds() const OVERRIDE;
+ float imageContentsScaleX() const;
+ float imageContentsScaleY() const;
SkBitmap m_bitmap;
diff --git a/cc/layer.cc b/cc/layer.cc
index ddc02b4..3519f14 100644
--- a/cc/layer.cc
+++ b/cc/layer.cc
@@ -216,12 +216,19 @@ void Layer::setBounds(const gfx::Size& size)
m_bounds = size;
+ didUpdateBounds();
+
if (firstResize)
setNeedsDisplay();
else
setNeedsCommit();
}
+void Layer::didUpdateBounds()
+{
+ m_drawProperties.content_bounds = bounds();
+}
+
Layer* Layer::rootLayer()
{
Layer* layer = this;
@@ -274,9 +281,15 @@ void Layer::setBackgroundColor(SkColor backgroundColor)
setNeedsCommit();
}
-gfx::Size Layer::contentBounds() const
+void Layer::calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds)
{
- return bounds();
+ *contentsScaleX = 1;
+ *contentsScaleY = 1;
+ *contentBounds = bounds();
}
void Layer::setMasksToBounds(bool masksToBounds)
@@ -633,16 +646,6 @@ void Layer::setDebugName(const std::string& debugName)
setNeedsCommit();
}
-float Layer::contentsScaleX() const
-{
- return 1.0;
-}
-
-float Layer::contentsScaleY() const
-{
- return 1.0;
-}
-
void Layer::setRasterScale(float scale)
{
if (m_rasterScale == scale)
diff --git a/cc/layer.h b/cc/layer.h
index 2be73c2..ede6120 100644
--- a/cc/layer.h
+++ b/cc/layer.h
@@ -84,8 +84,9 @@ public:
// A layer's bounds are in logical, non-page-scaled pixels (however, the
// root layer's bounds are in physical pixels).
void setBounds(const gfx::Size&);
+ // TODO(enne): remove this function: http://crbug.com/166023
+ virtual void didUpdateBounds();
const gfx::Size& bounds() const { return m_bounds; }
- virtual gfx::Size contentBounds() const;
void setMasksToBounds(bool);
bool masksToBounds() const { return m_masksToBounds; }
@@ -226,9 +227,14 @@ public:
// The contentsScale converts from logical, non-page-scaled pixels to target pixels.
// The contentsScale is 1 for the root layer as it is already in physical pixels.
// By default contentsScale is forced to be 1 except for subclasses of ContentsScalingLayer.
- virtual float contentsScaleX() const;
- virtual float contentsScaleY() const;
- virtual void setContentsScale(float contentsScale) { }
+ float contentsScaleX() const { return m_drawProperties.contents_scale_x; }
+ float contentsScaleY() const { return m_drawProperties.contents_scale_y; }
+ gfx::Size contentBounds() const { return m_drawProperties.content_bounds; }
+ virtual void calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds);
// The scale at which contents should be rastered, to match the scale at
// which they will drawn to the screen. This scale is a component of the
diff --git a/cc/layer_impl.cc b/cc/layer_impl.cc
index 0c22ccf..e1cf9d4 100644
--- a/cc/layer_impl.cc
+++ b/cc/layer_impl.cc
@@ -29,8 +29,6 @@ LayerImpl::LayerImpl(LayerTreeImpl* treeImpl, int id)
, m_layerTreeImpl(treeImpl)
, m_anchorPoint(0.5, 0.5)
, m_anchorPointZ(0)
- , m_contentsScaleX(1.0)
- , m_contentsScaleY(1.0)
, m_scrollable(false)
, m_shouldScrollOnMainThread(false)
, m_haveWheelEventHandlers(false)
@@ -677,20 +675,20 @@ bool LayerImpl::transformIsAnimating() const
void LayerImpl::setContentBounds(const gfx::Size& contentBounds)
{
- if (m_contentBounds == contentBounds)
+ if (this->contentBounds() == contentBounds)
return;
- m_contentBounds = contentBounds;
+ m_drawProperties.content_bounds = contentBounds;
noteLayerPropertyChanged();
}
void LayerImpl::setContentsScale(float contentsScaleX, float contentsScaleY)
{
- if (m_contentsScaleX == contentsScaleX && m_contentsScaleY == contentsScaleY)
+ if (this->contentsScaleX() == contentsScaleX && this->contentsScaleY() == contentsScaleY)
return;
- m_contentsScaleX = contentsScaleX;
- m_contentsScaleY = contentsScaleY;
+ m_drawProperties.contents_scale_x = contentsScaleX;
+ m_drawProperties.contents_scale_y = contentsScaleY;
noteLayerPropertyChanged();
}
diff --git a/cc/layer_impl.h b/cc/layer_impl.h
index 4d6e0cd..3d7ab85 100644
--- a/cc/layer_impl.h
+++ b/cc/layer_impl.h
@@ -190,13 +190,11 @@ public:
void setBounds(const gfx::Size&);
const gfx::Size& bounds() const { return m_bounds; }
- // ContentBounds may be [0, 1) pixels larger than bounds * contentsScale.
- // Don't calculate scale from it. Use contentsScale instead for accuracy.
void setContentBounds(const gfx::Size&);
- gfx::Size contentBounds() const { return m_contentBounds; }
+ gfx::Size contentBounds() const { return m_drawProperties.content_bounds; }
- float contentsScaleX() const { return m_contentsScaleX; }
- float contentsScaleY() const { return m_contentsScaleY; }
+ float contentsScaleX() const { return m_drawProperties.contents_scale_x; }
+ float contentsScaleY() const { return m_drawProperties.contents_scale_y; }
void setContentsScale(float contentsScaleX, float contentsScaleY);
gfx::Vector2d scrollOffset() const { return m_scrollOffset; }
@@ -326,9 +324,6 @@ private:
gfx::PointF m_anchorPoint;
float m_anchorPointZ;
gfx::Size m_bounds;
- gfx::Size m_contentBounds;
- float m_contentsScaleX;
- float m_contentsScaleY;
gfx::Vector2d m_scrollOffset;
bool m_scrollable;
bool m_shouldScrollOnMainThread;
diff --git a/cc/layer_tree_host_common.cc b/cc/layer_tree_host_common.cc
index 158b751..b9fc380 100644
--- a/cc/layer_tree_host_common.cc
+++ b/cc/layer_tree_host_common.cc
@@ -379,8 +379,9 @@ gfx::Transform computeScrollCompensationMatrixForChildren(LayerImpl* layer, cons
return nextScrollCompensationMatrix;
}
-// There is no contentsScale on impl thread.
-static inline void updateLayerContentsScale(LayerImpl*, const gfx::Transform&, float, float, bool) { }
+static inline void updateLayerContentsScale(LayerImpl* layer, const gfx::Transform& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool animatingTransformToScreen)
+{
+}
static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool animatingTransformToScreen)
{
@@ -405,15 +406,31 @@ static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform&
float contentsScale = rasterScale * deviceScaleFactor;
if (!layer->boundsContainPageScale())
contentsScale *= pageScaleFactor;
- layer->setContentsScale(contentsScale);
+ layer->calculateContentsScale(
+ contentsScale,
+ &layer->drawProperties().contents_scale_x,
+ &layer->drawProperties().contents_scale_y,
+ &layer->drawProperties().content_bounds);
Layer* maskLayer = layer->maskLayer();
if (maskLayer)
- maskLayer->setContentsScale(contentsScale);
+ {
+ maskLayer->calculateContentsScale(
+ contentsScale,
+ &maskLayer->drawProperties().contents_scale_x,
+ &maskLayer->drawProperties().contents_scale_y,
+ &maskLayer->drawProperties().content_bounds);
+ }
Layer* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->maskLayer() : 0;
if (replicaMaskLayer)
- replicaMaskLayer->setContentsScale(contentsScale);
+ {
+ replicaMaskLayer->calculateContentsScale(
+ contentsScale,
+ &replicaMaskLayer->drawProperties().contents_scale_x,
+ &replicaMaskLayer->drawProperties().contents_scale_y,
+ &replicaMaskLayer->drawProperties().content_bounds);
+ }
}
template<typename LayerType, typename LayerList>
diff --git a/cc/layer_tree_host_common_unittest.cc b/cc/layer_tree_host_common_unittest.cc
index 1577646..91a6e62 100644
--- a/cc/layer_tree_host_common_unittest.cc
+++ b/cc/layer_tree_host_common_unittest.cc
@@ -2408,12 +2408,6 @@ TEST(LayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsInHighDPI)
setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
const double deviceScaleFactor = 2;
- root->setContentsScale(deviceScaleFactor);
- renderSurface1->setContentsScale(deviceScaleFactor);
- renderSurface2->setContentsScale(deviceScaleFactor);
- child1->setContentsScale(deviceScaleFactor);
- child2->setContentsScale(deviceScaleFactor);
- child3->setContentsScale(deviceScaleFactor);
root->setMasksToBounds(true);
renderSurface1->setForceRenderSurface(true);
@@ -3978,9 +3972,18 @@ class NoScaleContentLayer : public ContentLayer
public:
static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); }
- virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); }
- virtual float contentsScaleX() const OVERRIDE { return 1.0; }
- virtual float contentsScaleY() const OVERRIDE { return 1.0; }
+ virtual void calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds) OVERRIDE
+ {
+ Layer::calculateContentsScale(
+ idealContentsScale,
+ contentsScaleX,
+ contentsScaleY,
+ contentBounds);
+ }
protected:
explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(client) { }
@@ -4534,11 +4537,6 @@ TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
int dummyMaxTextureSize = 512;
const double deviceScaleFactor = 1.5;
- parent->setContentsScale(deviceScaleFactor);
- child->setContentsScale(deviceScaleFactor);
- duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
- replica->setContentsScale(deviceScaleFactor);
-
LayerTreeHostCommon::calculateDrawProperties(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, false, renderSurfaceLayerList);
// We should have two render surfaces. The root's render surface and child's
@@ -4617,11 +4615,6 @@ TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPIAccurateScal
int dummyMaxTextureSize = 512;
const float deviceScaleFactor = 1.7f;
- parent->setContentsScale(deviceScaleFactor);
- child->setContentsScale(deviceScaleFactor);
- duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
- replica->setContentsScale(deviceScaleFactor);
-
LayerTreeHostCommon::calculateDrawProperties(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, false, renderSurfaceLayerList);
// We should have two render surfaces. The root's render surface and child's
diff --git a/cc/layer_tree_host_unittest.cc b/cc/layer_tree_host_unittest.cc
index 7add7ca..4174491 100644
--- a/cc/layer_tree_host_unittest.cc
+++ b/cc/layer_tree_host_unittest.cc
@@ -1221,9 +1221,18 @@ class NoScaleContentLayer : public ContentLayer {
public:
static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); }
- virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); }
- virtual float contentsScaleX() const OVERRIDE { return 1.0; }
- virtual float contentsScaleY() const OVERRIDE { return 1.0; }
+ virtual void calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds) OVERRIDE
+ {
+ Layer::calculateContentsScale(
+ idealContentsScale,
+ contentsScaleX,
+ contentsScaleY,
+ contentBounds);
+ }
private:
explicit NoScaleContentLayer(ContentLayerClient* client)
diff --git a/cc/scrollbar_layer.cc b/cc/scrollbar_layer.cc
index 8ebfc89..9fb96ff 100644
--- a/cc/scrollbar_layer.cc
+++ b/cc/scrollbar_layer.cc
@@ -68,11 +68,19 @@ float ScrollbarLayer::clampScaleToMaxTextureSize(float scale) {
return scale;
}
-void ScrollbarLayer::setContentsScale(float contentsScale) {
- contentsScale = clampScaleToMaxTextureSize(contentsScale);
- ContentsScalingLayer::setContentsScale(contentsScale);
- DCHECK_LE(contentBounds().width(), maxTextureSize());
- DCHECK_LE(contentBounds().height(), maxTextureSize());
+void ScrollbarLayer::calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds)
+{
+ ContentsScalingLayer::calculateContentsScale(
+ clampScaleToMaxTextureSize(idealContentsScale),
+ contentsScaleX,
+ contentsScaleY,
+ contentBounds);
+ DCHECK_LE(contentBounds->width(), maxTextureSize());
+ DCHECK_LE(contentBounds->height(), maxTextureSize());
}
void ScrollbarLayer::pushPropertiesTo(LayerImpl* layer)
diff --git a/cc/scrollbar_layer.h b/cc/scrollbar_layer.h
index 13341a3..47de62e 100644
--- a/cc/scrollbar_layer.h
+++ b/cc/scrollbar_layer.h
@@ -33,7 +33,11 @@ public:
virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats&) OVERRIDE;
virtual void setLayerTreeHost(LayerTreeHost*) OVERRIDE;
virtual void pushPropertiesTo(LayerImpl*) OVERRIDE;
- virtual void setContentsScale(float contentsScale) OVERRIDE;
+ virtual void calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds) OVERRIDE;
virtual ScrollbarLayer* toScrollbarLayer() OVERRIDE;
diff --git a/cc/scrollbar_layer_unittest.cc b/cc/scrollbar_layer_unittest.cc
index 5b5ab8b..572b30b 100644
--- a/cc/scrollbar_layer_unittest.cc
+++ b/cc/scrollbar_layer_unittest.cc
@@ -138,8 +138,11 @@ public:
virtual void beginTest() OVERRIDE
{
+ m_layerTreeHost->initializeRendererIfNeeded();
+
scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
m_scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), m_painter, WebKit::FakeWebScrollbarThemeGeometry::create(), 1);
+ m_scrollbarLayer->setLayerTreeHost(m_layerTreeHost.get());
m_scrollbarLayer->setBounds(m_bounds);
m_layerTreeHost->rootLayer()->addChild(m_scrollbarLayer);
@@ -152,8 +155,6 @@ public:
virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE
{
- m_layerTreeHost->initializeRendererIfNeeded();
-
const int kMaxTextureSize = m_layerTreeHost->rendererCapabilities().maxTextureSize;
// Check first that we're actually testing something.
diff --git a/cc/test/tiled_layer_test_common.cc b/cc/test/tiled_layer_test_common.cc
index 8010638..f891d36 100644
--- a/cc/test/tiled_layer_test_common.cc
+++ b/cc/test/tiled_layer_test_common.cc
@@ -134,29 +134,40 @@ cc::PrioritizedResourceManager* FakeTiledLayer::resourceManager() const
return m_resourceManager;
}
-cc::LayerUpdater* FakeTiledLayer::updater() const
+void FakeTiledLayer::updateContentsScale(float idealContentsScale)
{
- return m_fakeUpdater.get();
+ calculateContentsScale(
+ idealContentsScale,
+ &drawProperties().contents_scale_x,
+ &drawProperties().contents_scale_y,
+ &drawProperties().content_bounds);
}
-gfx::Size FakeTiledLayerWithScaledBounds::contentBounds() const
+cc::LayerUpdater* FakeTiledLayer::updater() const
{
- return m_forcedContentBounds;
+ return m_fakeUpdater.get();
}
-float FakeTiledLayerWithScaledBounds::contentsScaleX() const
+void FakeTiledLayerWithScaledBounds::setContentBounds(const gfx::Size& contentBounds)
{
- return static_cast<float>(m_forcedContentBounds.width()) / bounds().width();
+ m_forcedContentBounds = contentBounds;
+ drawProperties().content_bounds = m_forcedContentBounds;
}
-float FakeTiledLayerWithScaledBounds::contentsScaleY() const
+void FakeTiledLayerWithScaledBounds::calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds)
{
- return static_cast<float>(m_forcedContentBounds.height()) / bounds().height();
+ *contentsScaleX = static_cast<float>(m_forcedContentBounds.width()) / bounds().width();
+ *contentsScaleY = static_cast<float>(m_forcedContentBounds.height()) / bounds().height();
+ *contentBounds = m_forcedContentBounds;
}
-void FakeTiledLayerWithScaledBounds::setContentsScale(float)
+void FakeTiledLayerWithScaledBounds::didUpdateBounds()
{
- NOTREACHED();
+ drawProperties().content_bounds = m_forcedContentBounds;
}
} // namespace
diff --git a/cc/test/tiled_layer_test_common.h b/cc/test/tiled_layer_test_common.h
index 1992824..169179a 100644
--- a/cc/test/tiled_layer_test_common.h
+++ b/cc/test/tiled_layer_test_common.h
@@ -99,6 +99,9 @@ public:
FakeLayerUpdater* fakeLayerUpdater() { return m_fakeUpdater.get(); }
gfx::RectF updateRect() { return m_updateRect; }
+ // Simulate calcDrawProperties.
+ void updateContentsScale(float idealContentsScale);
+
protected:
virtual cc::LayerUpdater* updater() const OVERRIDE;
virtual void createUpdaterIfNeeded() OVERRIDE { }
@@ -114,11 +117,13 @@ class FakeTiledLayerWithScaledBounds : public FakeTiledLayer {
public:
explicit FakeTiledLayerWithScaledBounds(cc::PrioritizedResourceManager*);
- void setContentBounds(const gfx::Size& contentBounds) { m_forcedContentBounds = contentBounds; }
- virtual gfx::Size contentBounds() const OVERRIDE;
- virtual float contentsScaleX() const OVERRIDE;
- virtual float contentsScaleY() const OVERRIDE;
- virtual void setContentsScale(float) OVERRIDE;
+ void setContentBounds(const gfx::Size& contentBounds);
+ virtual void calculateContentsScale(
+ float idealContentsScale,
+ float* contentsScaleX,
+ float* contentsScaleY,
+ gfx::Size* contentBounds) OVERRIDE;
+ virtual void didUpdateBounds() OVERRIDE;
protected:
virtual ~FakeTiledLayerWithScaledBounds();
diff --git a/cc/tiled_layer_unittest.cc b/cc/tiled_layer_unittest.cc
index b6f4fdd..c148f78e 100644
--- a/cc/tiled_layer_unittest.cc
+++ b/cc/tiled_layer_unittest.cc
@@ -763,7 +763,7 @@ TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges)
// Change the contents scale and verify that the content rectangle requiring painting
// is not scaled.
- layer->setContentsScale(2);
+ layer->updateContentsScale(2);
layer->drawProperties().visible_content_rect = gfx::Rect(0, 0, 200, 200);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100), layer->lastNeedsDisplayRect());
@@ -1176,7 +1176,7 @@ TEST_F(TiledLayerTest, tilesPaintedWithOcclusionAndScaling)
// This makes sure the painting works when the content space is scaled to
// a different layer space. In this case tiles are scaled to be 200x200
// pixels, which means none should be occluded.
- layer->setContentsScale(0.5);
+ layer->updateContentsScale(0.5);
EXPECT_FLOAT_EQ(layer->contentsScaleX(), layer->contentsScaleY());
layer->setBounds(gfx::Size(600, 600));
gfx::Transform drawTransform;
@@ -1577,7 +1577,7 @@ TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringPaint)
gfx::Rect layerRect(0, 0, 30, 31);
layer->setPosition(layerRect.origin());
layer->setBounds(layerRect.size());
- layer->setContentsScale(1.5);
+ layer->updateContentsScale(1.5);
gfx::Rect contentRect(0, 0, 45, 47);
EXPECT_EQ(contentRect.size(), layer->contentBounds());
@@ -1608,7 +1608,7 @@ TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringInvalidation)
gfx::Rect layerRect(0, 0, 30, 31);
layer->setPosition(layerRect.origin());
layer->setBounds(layerRect.size());
- layer->setContentsScale(1.3f);
+ layer->updateContentsScale(1.3f);
gfx::Rect contentRect(gfx::Point(), layer->contentBounds());
layer->drawProperties().visible_content_rect = contentRect;