Commit e0eb7c40 authored by enne@chromium.org's avatar enne@chromium.org

cc: Use maximum tiling contents scales for picture layer scale

Due to the way the math works out for calculating which tiles to use for a
given content rect, the content scale for a picture layer has to be the maximum
of all the tilings on a layer.

Currently, each layer only has one tiling, but this change also creates the
infrastructure for adding different tilings over time and clamping contents
scales to a minimum.

NOTRY=true
R=danakj@chromium.org
BUG=155209


Review URL: https://chromiumcodereview.appspot.com/11777008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175420 0039d316-1c4b-4281-b951-d872f2087c98
parent 96036b5c
...@@ -713,6 +713,19 @@ void LayerImpl::setContentsScale(float contentsScaleX, float contentsScaleY) ...@@ -713,6 +713,19 @@ void LayerImpl::setContentsScale(float contentsScaleX, float contentsScaleY)
noteLayerPropertyChanged(); noteLayerPropertyChanged();
} }
void LayerImpl::calculateContentsScale(
float idealContentsScale,
float* contentsScaleX,
float* contentsScaleY,
gfx::Size* contentBounds)
{
// Base LayerImpl has all of its content scales and content bounds pushed
// from its Layer during commit and just reuses those values as-is.
*contentsScaleX = this->contentsScaleX();
*contentsScaleY = this->contentsScaleY();
*contentBounds = this->contentBounds();
}
void LayerImpl::setScrollOffset(gfx::Vector2d scrollOffset) void LayerImpl::setScrollOffset(gfx::Vector2d scrollOffset)
{ {
if (m_scrollOffset == scrollOffset) if (m_scrollOffset == scrollOffset)
......
...@@ -199,6 +199,12 @@ public: ...@@ -199,6 +199,12 @@ public:
float contentsScaleY() const { return m_drawProperties.contents_scale_y; } float contentsScaleY() const { return m_drawProperties.contents_scale_y; }
void setContentsScale(float contentsScaleX, float contentsScaleY); void setContentsScale(float contentsScaleX, float contentsScaleY);
virtual void calculateContentsScale(
float idealContentsScale,
float* contentsScaleX,
float* contentsScaleY,
gfx::Size* contentBounds);
gfx::Vector2d scrollOffset() const { return m_scrollOffset; } gfx::Vector2d scrollOffset() const { return m_scrollOffset; }
void setScrollOffset(gfx::Vector2d); void setScrollOffset(gfx::Vector2d);
......
...@@ -406,8 +406,41 @@ gfx::Transform computeScrollCompensationMatrixForChildren(LayerImpl* layer, cons ...@@ -406,8 +406,41 @@ gfx::Transform computeScrollCompensationMatrixForChildren(LayerImpl* layer, cons
return nextScrollCompensationMatrix; return nextScrollCompensationMatrix;
} }
template<typename LayerType>
static inline void calculateContentsScale(LayerType* layer, float contentsScale)
{
layer->calculateContentsScale(
contentsScale,
&layer->drawProperties().contents_scale_x,
&layer->drawProperties().contents_scale_y,
&layer->drawProperties().content_bounds);
LayerType* maskLayer = layer->maskLayer();
if (maskLayer)
{
maskLayer->calculateContentsScale(
contentsScale,
&maskLayer->drawProperties().contents_scale_x,
&maskLayer->drawProperties().contents_scale_y,
&maskLayer->drawProperties().content_bounds);
}
LayerType* replicaMaskLayer = layer->replicaLayer() ? layer->replicaLayer()->maskLayer() : 0;
if (replicaMaskLayer)
{
replicaMaskLayer->calculateContentsScale(
contentsScale,
&replicaMaskLayer->drawProperties().contents_scale_x,
&replicaMaskLayer->drawProperties().contents_scale_y,
&replicaMaskLayer->drawProperties().content_bounds);
}
}
static inline void updateLayerContentsScale(LayerImpl* layer, const gfx::Transform& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool animatingTransformToScreen) static inline void updateLayerContentsScale(LayerImpl* layer, const gfx::Transform& combinedTransform, float deviceScaleFactor, float pageScaleFactor, bool animatingTransformToScreen)
{ {
gfx::Vector2dF transformScale = MathUtil::computeTransform2dScaleComponents(combinedTransform, deviceScaleFactor * pageScaleFactor);
float contentsScale = std::max(transformScale.x(), transformScale.y());
calculateContentsScale(layer, contentsScale);
} }
static inline void updateLayerContentsScale(Layer* 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)
...@@ -433,31 +466,8 @@ static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform& ...@@ -433,31 +466,8 @@ static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform&
float contentsScale = rasterScale * deviceScaleFactor; float contentsScale = rasterScale * deviceScaleFactor;
if (!layer->boundsContainPageScale()) if (!layer->boundsContainPageScale())
contentsScale *= pageScaleFactor; contentsScale *= pageScaleFactor;
layer->calculateContentsScale(
contentsScale,
&layer->drawProperties().contents_scale_x,
&layer->drawProperties().contents_scale_y,
&layer->drawProperties().content_bounds);
Layer* maskLayer = layer->maskLayer();
if (maskLayer)
{
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; calculateContentsScale(layer, contentsScale);
if (replicaMaskLayer)
{
replicaMaskLayer->calculateContentsScale(
contentsScale,
&replicaMaskLayer->drawProperties().contents_scale_x,
&replicaMaskLayer->drawProperties().contents_scale_y,
&replicaMaskLayer->drawProperties().content_bounds);
}
} }
template<typename LayerType, typename LayerList> template<typename LayerType, typename LayerList>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "cc/solid_color_draw_quad.h" #include "cc/solid_color_draw_quad.h"
#include "cc/tile_draw_quad.h" #include "cc/tile_draw_quad.h"
#include "ui/gfx/quad_f.h" #include "ui/gfx/quad_f.h"
#include "ui/gfx/size_conversions.h"
namespace cc { namespace cc {
...@@ -129,18 +130,6 @@ void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { ...@@ -129,18 +130,6 @@ void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const {
} }
void PictureLayerImpl::didUpdateTransforms() { void PictureLayerImpl::didUpdateTransforms() {
if (drawsContent()) {
// TODO(enne): Add tilings during pinch zoom
// TODO(enne): Consider culling old tilings after pinch finishes.
if (!tilings_.num_tilings()) {
AddTiling(contentsScaleX(), TileSize());
// TODO(enne): Add a low-res tiling as well.
}
} else {
// TODO(enne): This should be unnecessary once there are two trees.
tilings_.Reset();
}
gfx::Transform current_screen_space_transform = gfx::Transform current_screen_space_transform =
screenSpaceTransform(); screenSpaceTransform();
double current_time = double current_time =
...@@ -170,6 +159,36 @@ void PictureLayerImpl::didUpdateTransforms() { ...@@ -170,6 +159,36 @@ void PictureLayerImpl::didUpdateTransforms() {
last_content_scale_y_ = contentsScaleY(); last_content_scale_y_ = contentsScaleY();
} }
void PictureLayerImpl::calculateContentsScale(
float ideal_contents_scale,
float* contents_scale_x,
float* contents_scale_y,
gfx::Size* content_bounds) {
if (!drawsContent()) {
DCHECK(!tilings_.num_tilings());
return;
}
ManageTilings(ideal_contents_scale);
// The content scale and bounds for a PictureLayerImpl is somewhat fictitious.
// There are (usually) several tilings at different scales. However, the
// content bounds is the (integer!) space in which quads are generated.
// In order to guarantee that we can fill this integer space with any set of
// tilings (and then map back to floating point texture coordinates), the
// contents scale must be at least as large as the largest of the tilings.
float max_contents_scale = 1.f;
for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
const PictureLayerTiling* tiling = tilings_.tiling_at(i);
max_contents_scale = std::max(max_contents_scale, tiling->contents_scale());
}
*contents_scale_x = max_contents_scale;
*contents_scale_y = max_contents_scale;
*content_bounds = gfx::ToCeiledSize(
gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale));
}
scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling,
gfx::Rect rect) { gfx::Rect rect) {
TileManager* tile_manager = layerTreeImpl()->tile_manager(); TileManager* tile_manager = layerTreeImpl()->tile_manager();
...@@ -260,4 +279,18 @@ gfx::Size PictureLayerImpl::TileSize() const { ...@@ -260,4 +279,18 @@ gfx::Size PictureLayerImpl::TileSize() const {
return layerTreeImpl()->settings().defaultTileSize; return layerTreeImpl()->settings().defaultTileSize;
} }
void PictureLayerImpl::ManageTilings(float ideal_contents_scale) {
if (drawsContent()) {
// TODO(enne): Add tilings during pinch zoom
// TODO(enne): Consider culling old tilings after pinch finishes.
if (!tilings_.num_tilings()) {
AddTiling(ideal_contents_scale, TileSize());
// TODO(enne): Add a low-res tiling as well.
}
} else {
// TODO(enne): This should be unnecessary once there are two trees.
tilings_.Reset();
}
}
} // namespace cc } // namespace cc
...@@ -30,6 +30,11 @@ public: ...@@ -30,6 +30,11 @@ public:
virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE; virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE;
virtual void dumpLayerProperties(std::string*, int indent) const OVERRIDE; virtual void dumpLayerProperties(std::string*, int indent) const OVERRIDE;
virtual void didUpdateTransforms() OVERRIDE; virtual void didUpdateTransforms() OVERRIDE;
virtual void calculateContentsScale(
float ideal_contents_scale,
float* contents_scale_x,
float* contents_scale_y,
gfx::Size* content_bounds) OVERRIDE;
// PictureLayerTilingClient overrides. // PictureLayerTilingClient overrides.
virtual scoped_refptr<Tile> CreateTile(PictureLayerTiling*, virtual scoped_refptr<Tile> CreateTile(PictureLayerTiling*,
...@@ -48,6 +53,7 @@ protected: ...@@ -48,6 +53,7 @@ protected:
void AddTiling(float contents_scale, gfx::Size tile_size); void AddTiling(float contents_scale, gfx::Size tile_size);
void SyncFromActiveLayer(const PictureLayerImpl* other); void SyncFromActiveLayer(const PictureLayerImpl* other);
gfx::Size TileSize() const; gfx::Size TileSize() const;
void ManageTilings(float ideal_contents_scale);
PictureLayerTilingSet tilings_; PictureLayerTilingSet tilings_;
scoped_refptr<PicturePileImpl> pile_; scoped_refptr<PicturePileImpl> pile_;
......
...@@ -30,6 +30,7 @@ class CC_EXPORT PictureLayerTilingSet { ...@@ -30,6 +30,7 @@ class CC_EXPORT PictureLayerTilingSet {
float contents_scale, float contents_scale,
gfx::Size tile_size); gfx::Size tile_size);
size_t num_tilings() const { return tilings_.size(); } size_t num_tilings() const { return tilings_.size(); }
PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; }
void Reset(); void Reset();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment