diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-08 00:00:19 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-08 00:00:19 +0000 |
commit | e0eb7c401b51dc1761e5926c0e8e9c7872c6abdd (patch) | |
tree | 9e0d4323e0df867411df7ee85903bb71f46d0a9a | |
parent | 96036b5cda2f5802f11823de205287c7f0a43834 (diff) | |
download | chromium_src-e0eb7c401b51dc1761e5926c0e8e9c7872c6abdd.zip chromium_src-e0eb7c401b51dc1761e5926c0e8e9c7872c6abdd.tar.gz chromium_src-e0eb7c401b51dc1761e5926c0e8e9c7872c6abdd.tar.bz2 |
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
-rw-r--r-- | cc/layer_impl.cc | 13 | ||||
-rw-r--r-- | cc/layer_impl.h | 6 | ||||
-rw-r--r-- | cc/layer_tree_host_common.cc | 58 | ||||
-rw-r--r-- | cc/picture_layer_impl.cc | 57 | ||||
-rw-r--r-- | cc/picture_layer_impl.h | 6 | ||||
-rw-r--r-- | cc/picture_layer_tiling_set.h | 1 |
6 files changed, 105 insertions, 36 deletions
diff --git a/cc/layer_impl.cc b/cc/layer_impl.cc index 4ab9989..c588fe2 100644 --- a/cc/layer_impl.cc +++ b/cc/layer_impl.cc @@ -713,6 +713,19 @@ void LayerImpl::setContentsScale(float contentsScaleX, float contentsScaleY) 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) { if (m_scrollOffset == scrollOffset) diff --git a/cc/layer_impl.h b/cc/layer_impl.h index 4320446..2219cf7 100644 --- a/cc/layer_impl.h +++ b/cc/layer_impl.h @@ -199,6 +199,12 @@ public: float contentsScaleY() const { return m_drawProperties.contents_scale_y; } 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; } void setScrollOffset(gfx::Vector2d); diff --git a/cc/layer_tree_host_common.cc b/cc/layer_tree_host_common.cc index feba747..5af7a69 100644 --- a/cc/layer_tree_host_common.cc +++ b/cc/layer_tree_host_common.cc @@ -406,8 +406,41 @@ gfx::Transform computeScrollCompensationMatrixForChildren(LayerImpl* layer, cons 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) { + 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) @@ -433,31 +466,8 @@ static inline void updateLayerContentsScale(Layer* layer, const gfx::Transform& float contentsScale = rasterScale * deviceScaleFactor; if (!layer->boundsContainPageScale()) 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; - if (replicaMaskLayer) - { - replicaMaskLayer->calculateContentsScale( - contentsScale, - &replicaMaskLayer->drawProperties().contents_scale_x, - &replicaMaskLayer->drawProperties().contents_scale_y, - &replicaMaskLayer->drawProperties().content_bounds); - } + calculateContentsScale(layer, contentsScale); } template<typename LayerType, typename LayerList> diff --git a/cc/picture_layer_impl.cc b/cc/picture_layer_impl.cc index d5a44c7..161fd83 100644 --- a/cc/picture_layer_impl.cc +++ b/cc/picture_layer_impl.cc @@ -15,6 +15,7 @@ #include "cc/solid_color_draw_quad.h" #include "cc/tile_draw_quad.h" #include "ui/gfx/quad_f.h" +#include "ui/gfx/size_conversions.h" namespace cc { @@ -129,18 +130,6 @@ void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { } 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 = screenSpaceTransform(); double current_time = @@ -170,6 +159,36 @@ void PictureLayerImpl::didUpdateTransforms() { 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, gfx::Rect rect) { TileManager* tile_manager = layerTreeImpl()->tile_manager(); @@ -260,4 +279,18 @@ gfx::Size PictureLayerImpl::TileSize() const { 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 diff --git a/cc/picture_layer_impl.h b/cc/picture_layer_impl.h index c7fbf6e..60e2c8d 100644 --- a/cc/picture_layer_impl.h +++ b/cc/picture_layer_impl.h @@ -30,6 +30,11 @@ public: virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE; virtual void dumpLayerProperties(std::string*, int indent) const 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. virtual scoped_refptr<Tile> CreateTile(PictureLayerTiling*, @@ -48,6 +53,7 @@ protected: void AddTiling(float contents_scale, gfx::Size tile_size); void SyncFromActiveLayer(const PictureLayerImpl* other); gfx::Size TileSize() const; + void ManageTilings(float ideal_contents_scale); PictureLayerTilingSet tilings_; scoped_refptr<PicturePileImpl> pile_; diff --git a/cc/picture_layer_tiling_set.h b/cc/picture_layer_tiling_set.h index 11e2796..383884e 100644 --- a/cc/picture_layer_tiling_set.h +++ b/cc/picture_layer_tiling_set.h @@ -30,6 +30,7 @@ class CC_EXPORT PictureLayerTilingSet { float contents_scale, gfx::Size tile_size); size_t num_tilings() const { return tilings_.size(); } + PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; } void Reset(); |