diff options
author | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-26 09:24:43 +0000 |
---|---|---|
committer | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-26 09:24:43 +0000 |
commit | dd65f91f9abdea4c58648911a149215e67d6a0f4 (patch) | |
tree | 8d337e3a0e41631c666870299bb229483a055aa1 | |
parent | 465acd519d086204d3c3df2c10bab72ce034940f (diff) | |
download | chromium_src-dd65f91f9abdea4c58648911a149215e67d6a0f4.zip chromium_src-dd65f91f9abdea4c58648911a149215e67d6a0f4.tar.gz chromium_src-dd65f91f9abdea4c58648911a149215e67d6a0f4.tar.bz2 |
Let AreVisibleResourcesReady return correct value for PictureImageLayerImpl
AreVisibleResourcesReady didn't return correct value because
PictureLayerImpl::raster_source_scale_ didn't reflect the actual value for
PictureImageLayerImpl. In this CL raster_contents_scale_ and
low_res_raster_contents_scale_ are stored in PictureLayerImpl.
BTW extracted the code to determine if raster scale needs to be adjusted
into ShouldAdjustRasterScale().
BUG=223201
TEST=PictureImageLayerImplTest.*
Review URL: https://chromiumcodereview.appspot.com/12954006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190621 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | cc/cc_tests.gyp | 2 | ||||
-rw-r--r-- | cc/layers/picture_image_layer_impl.cc | 7 | ||||
-rw-r--r-- | cc/layers/picture_image_layer_impl.h | 4 | ||||
-rw-r--r-- | cc/layers/picture_image_layer_impl_unittest.cc | 81 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.cc | 130 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.h | 9 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl_unittest.cc | 8 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_tiling_client.h | 1 | ||||
-rw-r--r-- | cc/test/impl_side_painting_settings.h | 21 |
9 files changed, 184 insertions, 79 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index b625cce..35b7095 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -40,6 +40,7 @@ 'layers/nine_patch_layer_impl_unittest.cc', 'layers/nine_patch_layer_unittest.cc', 'trees/occlusion_tracker_unittest.cc', + 'layers/picture_image_layer_impl_unittest.cc', 'layers/picture_layer_impl_unittest.cc', 'resources/picture_layer_tiling_set_unittest.cc', 'resources/picture_layer_tiling_unittest.cc', @@ -115,6 +116,7 @@ 'test/fake_web_scrollbar_theme_geometry.h', 'test/geometry_test_utils.cc', 'test/geometry_test_utils.h', + 'test/impl_side_painting_settings.h', 'test/layer_test_common.cc', 'test/layer_test_common.h', 'test/layer_tree_pixel_test.cc', diff --git a/cc/layers/picture_image_layer_impl.cc b/cc/layers/picture_image_layer_impl.cc index 9fa401f..5c18d01 100644 --- a/cc/layers/picture_image_layer_impl.cc +++ b/cc/layers/picture_image_layer_impl.cc @@ -31,10 +31,15 @@ void PictureImageLayerImpl::GetDebugBorderProperties( *width = DebugColors::ImageLayerBorderWidth(layer_tree_impl()); } +bool PictureImageLayerImpl::ShouldAdjustRasterScale( + bool animating_transform_to_screen) const { + return false; +} + void PictureImageLayerImpl::CalculateRasterContentsScale( bool animating_transform_to_screen, float* raster_contents_scale, - float* low_res_raster_contents_scale) { + float* low_res_raster_contents_scale) const { // Don't scale images during rastering to ensure image quality, save memory // and avoid frequent re-rastering on change of scale. *raster_contents_scale = std::max(1.f, MinimumContentsScale()); diff --git a/cc/layers/picture_image_layer_impl.h b/cc/layers/picture_image_layer_impl.h index 4bbafa7f22..943981e 100644 --- a/cc/layers/picture_image_layer_impl.h +++ b/cc/layers/picture_image_layer_impl.h @@ -24,10 +24,12 @@ class CC_EXPORT PictureImageLayerImpl : public PictureLayerImpl { protected: PictureImageLayerImpl(LayerTreeImpl* tree_impl, int id); + virtual bool ShouldAdjustRasterScale( + bool animating_transform_to_screen) const OVERRIDE; virtual void CalculateRasterContentsScale( bool animating_transform_to_screen, float* raster_contents_scale, - float* low_res_raster_contents_scale) OVERRIDE; + float* low_res_raster_contents_scale) const OVERRIDE; virtual void GetDebugBorderProperties( SkColor* color, float* width) const OVERRIDE; diff --git a/cc/layers/picture_image_layer_impl_unittest.cc b/cc/layers/picture_image_layer_impl_unittest.cc new file mode 100644 index 0000000..5e8b1d8 --- /dev/null +++ b/cc/layers/picture_image_layer_impl_unittest.cc @@ -0,0 +1,81 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/layers/picture_image_layer_impl.h" + +#include "cc/test/fake_impl_proxy.h" +#include "cc/test/fake_layer_tree_host_impl.h" +#include "cc/test/fake_output_surface.h" +#include "cc/test/fake_picture_layer_tiling_client.h" +#include "cc/test/impl_side_painting_settings.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace cc { +namespace { + +class TestablePictureImageLayerImpl : public PictureImageLayerImpl { + public: + TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) + : PictureImageLayerImpl(tree_impl, id) { + } + friend class PictureImageLayerImplTest; +}; + +class PictureImageLayerImplTest : public testing::Test { + public: + PictureImageLayerImplTest() + : host_impl_(ImplSidePaintingSettings(), &proxy_) { + tiling_client_.SetTileSize(ImplSidePaintingSettings().default_tile_size); + host_impl_.CreatePendingTree(); + host_impl_.InitializeRenderer(CreateFakeOutputSurface()); + } + + scoped_ptr<TestablePictureImageLayerImpl> CreateLayer(int id) { + TestablePictureImageLayerImpl* layer = + new TestablePictureImageLayerImpl(host_impl_.pending_tree(), id); + layer->SetBounds(gfx::Size(100, 200)); + layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_)); + layer->tilings_->SetLayerBounds(layer->bounds()); + layer->pile_ = tiling_client_.pile(); + return make_scoped_ptr(layer); + } + + private: + FakeImplProxy proxy_; + FakeLayerTreeHostImpl host_impl_; + FakePictureLayerTilingClient tiling_client_; +}; + +TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { + scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1)); + layer->SetDrawsContent(true); + + float contents_scale_x; + float contents_scale_y; + gfx::Size content_bounds; + layer->CalculateContentsScale(2.f, false, + &contents_scale_x, &contents_scale_y, + &content_bounds); + EXPECT_FLOAT_EQ(1.f, contents_scale_x); + EXPECT_FLOAT_EQ(1.f, contents_scale_y); + EXPECT_EQ(layer->bounds(), content_bounds); +} + +TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { + scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1)); + layer->SetBounds(gfx::Size(100, 200)); + layer->SetDrawsContent(true); + + float contents_scale_x; + float contents_scale_y; + gfx::Size content_bounds; + layer->CalculateContentsScale(2.f, false, + &contents_scale_x, &contents_scale_y, + &content_bounds); + + EXPECT_TRUE(layer->AreVisibleResourcesReady()); +} + +} // namespace +} // namespace cc diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index 25bff69..8e0d06f 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -29,14 +29,16 @@ PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) : LayerImpl(tree_impl, id), pile_(PicturePileImpl::Create(true)), last_content_scale_(0), - ideal_contents_scale_(0), is_mask_(false), ideal_page_scale_(0.f), ideal_device_scale_(0.f), ideal_source_scale_(0.f), + ideal_contents_scale_(0.f), raster_page_scale_(0.f), raster_device_scale_(0.f), raster_source_scale_(0.f), + raster_contents_scale_(0.f), + low_res_raster_contents_scale_(0.f), raster_source_scale_was_animating_(false), is_using_lcd_text_(true) { } @@ -80,6 +82,8 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { layer_impl->raster_page_scale_ = raster_page_scale_; layer_impl->raster_device_scale_ = raster_device_scale_; layer_impl->raster_source_scale_ = raster_source_scale_; + layer_impl->raster_contents_scale_ = raster_contents_scale_; + layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; layer_impl->is_using_lcd_text_ = is_using_lcd_text_; } @@ -397,6 +401,8 @@ void PictureLayerImpl::SyncFromActiveLayer() { raster_page_scale_ = 0; raster_device_scale_ = 0; raster_source_scale_ = 0; + raster_contents_scale_ = 0; + low_res_raster_contents_scale_ = 0; return; } @@ -411,6 +417,8 @@ void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { raster_page_scale_ = other->raster_page_scale_; raster_device_scale_ = other->raster_device_scale_; raster_source_scale_ = other->raster_source_scale_; + raster_contents_scale_ = other->raster_contents_scale_; + low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; is_using_lcd_text_ = other->is_using_lcd_text_; // Add synthetic invalidations for any recordings that were dropped. As @@ -494,13 +502,8 @@ bool PictureLayerImpl::AreVisibleResourcesReady() const { const gfx::Rect& rect = visible_content_rect(); - float raster_contents_scale = - raster_page_scale_ * - raster_device_scale_ * - raster_source_scale_; - float min_acceptable_scale = - std::min(raster_contents_scale, ideal_contents_scale_); + std::min(raster_contents_scale_, ideal_contents_scale_); TreePriority tree_priority = layer_tree_impl()->tile_manager()->GlobalState().tree_priority; @@ -510,14 +513,9 @@ bool PictureLayerImpl::AreVisibleResourcesReady() const { active_animation_controllers().empty(); if (PictureLayerImpl* twin = ActiveTwin()) { - float twin_raster_contents_scale = - twin->raster_page_scale_ * - twin->raster_device_scale_ * - twin->raster_source_scale_; - min_acceptable_scale = std::min( min_acceptable_scale, - std::min(twin->ideal_contents_scale_, twin_raster_contents_scale)); + std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_)); } Region missing_region = rect; @@ -604,43 +602,15 @@ void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { if (pile_->recorded_region().IsEmpty()) return; - bool is_active_layer = layer_tree_impl()->IsActiveTree(); - bool is_pinching = layer_tree_impl()->PinchGestureActive(); + bool change_target_tiling = + !raster_page_scale_ || !raster_device_scale_ || !raster_source_scale_ || + ShouldAdjustRasterScale(animating_transform_to_screen); - bool change_target_tiling = false; - - if (!raster_page_scale_ || !raster_device_scale_ || !raster_source_scale_) - change_target_tiling = true; - - // TODO(danakj): Adjust raster_source_scale_ closer to ideal_source_scale_ at - // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending - // tree. This will allow CSS scale changes to get re-rastered at an - // appropriate rate. - - if (is_active_layer) { - if (raster_source_scale_was_animating_ && !animating_transform_to_screen) - change_target_tiling = true; + if (layer_tree_impl()->IsActiveTree()) { + // Store the value for the next time ShouldAdjustRasterScale is called. raster_source_scale_was_animating_ = animating_transform_to_screen; } - if (is_active_layer && is_pinching && raster_page_scale_) { - // If the page scale diverges too far during pinch, change raster target to - // the current page scale. - float ratio = PositiveRatio(ideal_page_scale_, raster_page_scale_); - if (ratio >= kMaxScaleRatioDuringPinch) - change_target_tiling = true; - } - - if (!is_pinching) { - // When not pinching, match the ideal page scale factor. - if (raster_page_scale_ != ideal_page_scale_) - change_target_tiling = true; - } - - // Always match the ideal device scale factor. - if (raster_device_scale_ != ideal_device_scale_) - change_target_tiling = true; - if (!change_target_tiling) return; @@ -648,20 +618,18 @@ void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { raster_device_scale_ = ideal_device_scale_; raster_source_scale_ = ideal_source_scale_; - float raster_contents_scale; - float low_res_raster_contents_scale; CalculateRasterContentsScale(animating_transform_to_screen, - &raster_contents_scale, - &low_res_raster_contents_scale); + &raster_contents_scale_, + &low_res_raster_contents_scale_); PictureLayerTiling* high_res = NULL; PictureLayerTiling* low_res = NULL; for (size_t i = 0; i < tilings_->num_tilings(); ++i) { PictureLayerTiling* tiling = tilings_->tiling_at(i); - if (tiling->contents_scale() == raster_contents_scale) + if (tiling->contents_scale() == raster_contents_scale_) high_res = tiling; - if (tiling->contents_scale() == low_res_raster_contents_scale) + if (tiling->contents_scale() == low_res_raster_contents_scale_) low_res = tiling; // Reset all tilings to non-ideal until the end of this function. @@ -669,12 +637,12 @@ void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { } if (!high_res) { - high_res = AddTiling(raster_contents_scale); - if (raster_contents_scale == low_res_raster_contents_scale) + high_res = AddTiling(raster_contents_scale_); + if (raster_contents_scale_ == low_res_raster_contents_scale_) low_res = high_res; } if (!low_res && low_res != high_res) - low_res = AddTiling(low_res_raster_contents_scale); + low_res = AddTiling(low_res_raster_contents_scale_); if (high_res) high_res->set_resolution(HIGH_RESOLUTION); @@ -682,10 +650,44 @@ void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { low_res->set_resolution(LOW_RESOLUTION); } +bool PictureLayerImpl::ShouldAdjustRasterScale( + bool animating_transform_to_screen) const { + // TODO(danakj): Adjust raster source scale closer to ideal source scale at + // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending + // tree. This will allow CSS scale changes to get re-rastered at an + // appropriate rate. + + bool is_active_layer = layer_tree_impl()->IsActiveTree(); + if (is_active_layer && raster_source_scale_was_animating_ && + !animating_transform_to_screen) + return true; + + bool is_pinching = layer_tree_impl()->PinchGestureActive(); + if (is_active_layer && is_pinching && raster_page_scale_) { + // If the page scale diverges too far during pinch, change raster target to + // the current page scale. + float ratio = PositiveRatio(ideal_page_scale_, raster_page_scale_); + if (ratio >= kMaxScaleRatioDuringPinch) + return true; + } + + if (!is_pinching) { + // When not pinching, match the ideal page scale factor. + if (raster_page_scale_ != ideal_page_scale_) + return true; + } + + // Always match the ideal device scale factor. + if (raster_device_scale_ != ideal_device_scale_) + return true; + + return false; +} + void PictureLayerImpl::CalculateRasterContentsScale( bool animating_transform_to_screen, float* raster_contents_scale, - float* low_res_raster_contents_scale) { + float* low_res_raster_contents_scale) const { *raster_contents_scale = ideal_contents_scale_; // Don't allow animating CSS scales to drop below 1. @@ -705,27 +707,19 @@ void PictureLayerImpl::CleanUpTilingsOnActiveLayer( std::vector<PictureLayerTiling*> used_tilings) { DCHECK(layer_tree_impl()->IsActiveTree()); - float raster_contents_scale = - raster_page_scale_ * raster_device_scale_ * raster_source_scale_; - float min_acceptable_high_res_scale = std::min( - raster_contents_scale, ideal_contents_scale_); + raster_contents_scale_, ideal_contents_scale_); float max_acceptable_high_res_scale = std::max( - raster_contents_scale, ideal_contents_scale_); + raster_contents_scale_, ideal_contents_scale_); PictureLayerImpl* twin = PendingTwin(); if (twin) { - float twin_raster_contents_scale = - twin->raster_page_scale_ * - twin->raster_device_scale_ * - twin->raster_source_scale_; - min_acceptable_high_res_scale = std::min( min_acceptable_high_res_scale, - std::min(twin_raster_contents_scale, twin->ideal_contents_scale_)); + std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); max_acceptable_high_res_scale = std::max( max_acceptable_high_res_scale, - std::max(twin_raster_contents_scale, twin->ideal_contents_scale_)); + std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); } float low_res_factor = diff --git a/cc/layers/picture_layer_impl.h b/cc/layers/picture_layer_impl.h index 9e54f43..4a85691 100644 --- a/cc/layers/picture_layer_impl.h +++ b/cc/layers/picture_layer_impl.h @@ -75,10 +75,12 @@ class CC_EXPORT PictureLayerImpl : public LayerImpl, void RemoveTiling(float contents_scale); void SyncFromActiveLayer(const PictureLayerImpl* other); void ManageTilings(bool animating_transform_to_screen); + virtual bool ShouldAdjustRasterScale( + bool animating_transform_to_screen) const; virtual void CalculateRasterContentsScale( bool animating_transform_to_screen, float* raster_contents_scale, - float* low_res_raster_contents_scale); + float* low_res_raster_contents_scale) const; void CleanUpTilingsOnActiveLayer( std::vector<PictureLayerTiling*> used_tilings); PictureLayerImpl* PendingTwin() const; @@ -96,16 +98,19 @@ class CC_EXPORT PictureLayerImpl : public LayerImpl, gfx::Transform last_screen_space_transform_; gfx::Size last_bounds_; float last_content_scale_; - float ideal_contents_scale_; bool is_mask_; float ideal_page_scale_; float ideal_device_scale_; float ideal_source_scale_; + float ideal_contents_scale_; float raster_page_scale_; float raster_device_scale_; float raster_source_scale_; + float raster_contents_scale_; + float low_res_raster_contents_scale_; + bool raster_source_scale_was_animating_; bool is_using_lcd_text_; diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc index 9ea3878..1d50b25 100644 --- a/cc/layers/picture_layer_impl_unittest.cc +++ b/cc/layers/picture_layer_impl_unittest.cc @@ -9,6 +9,7 @@ #include "cc/test/fake_impl_proxy.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" +#include "cc/test/impl_side_painting_settings.h" #include "cc/trees/layer_tree_impl.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkDevice.h" @@ -52,13 +53,6 @@ class TestablePictureLayerImpl : public PictureLayerImpl { } }; -class ImplSidePaintingSettings : public LayerTreeSettings { - public: - ImplSidePaintingSettings() { - impl_side_painting = true; - } -}; - class TestablePicturePileImpl : public PicturePileImpl { public: static scoped_refptr<TestablePicturePileImpl> CreateFilledPile( diff --git a/cc/test/fake_picture_layer_tiling_client.h b/cc/test/fake_picture_layer_tiling_client.h index 0dd9717..4cde8cd 100644 --- a/cc/test/fake_picture_layer_tiling_client.h +++ b/cc/test/fake_picture_layer_tiling_client.h @@ -30,6 +30,7 @@ class FakePictureLayerTilingClient : public PictureLayerTilingClient { void SetTileSize(gfx::Size tile_size); gfx::Size TileSize() const { return tile_size_; } + scoped_refptr<PicturePileImpl> pile() { return pile_; } protected: FakeTileManagerClient tile_manager_client_; diff --git a/cc/test/impl_side_painting_settings.h b/cc/test/impl_side_painting_settings.h new file mode 100644 index 0000000..6929a48 --- /dev/null +++ b/cc/test/impl_side_painting_settings.h @@ -0,0 +1,21 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_TEST_IMPL_SIDE_PAINTING_SETTINGS_H_ +#define CC_TEST_IMPL_SIDE_PAINTING_SETTINGS_H_ + +#include "cc/trees/layer_tree_settings.h" + +namespace cc { + +class ImplSidePaintingSettings : public LayerTreeSettings { + public: + ImplSidePaintingSettings() { + impl_side_painting = true; + } +}; + +} // namespace cc + +#endif // CC_TEST_IMPL_SIDE_PAINTING_SETTINGS_H_ |