Commit 6860e109 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Limit minimum scale of PaintedScrollbarLayer to 1

This is to avoid too low scale when animating scale above the
scrollbar layer.

This is not ideal. In the future we should move rasterization of
scrollbar layers to impl-side to better handle scales
(crbug.com/1009291).

Bug: 1133997
Change-Id: I3364754f530914816fe8526c627e6cf12e7942ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2453436Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814681}
parent ab089045
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include "cc/layers/painted_scrollbar_layer.h" #include "cc/layers/painted_scrollbar_layer.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "cc/layers/painted_scrollbar_layer_impl.h" #include "cc/layers/painted_scrollbar_layer_impl.h"
#include "cc/paint/skia_paint_canvas.h" #include "cc/paint/skia_paint_canvas.h"
...@@ -140,6 +144,10 @@ bool PaintedScrollbarLayer::UpdateInternalContentScale() { ...@@ -140,6 +144,10 @@ bool PaintedScrollbarLayer::UpdateInternalContentScale() {
gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents(
transform, layer_tree_host()->device_scale_factor()); transform, layer_tree_host()->device_scale_factor());
float scale = std::max(transform_scales.x(), transform_scales.y()); float scale = std::max(transform_scales.x(), transform_scales.y());
// Clamp minimum scale to 1 to avoid too low scale during scale animation.
// TODO(crbug.com/1009291): Move rasterization of scrollbars to the impl side
// to better handle scale changes.
scale = std::max(1.0f, scale);
bool updated = false; bool updated = false;
updated |= UpdateProperty(scale, &internal_contents_scale_); updated |= UpdateProperty(scale, &internal_contents_scale_);
......
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
#include "cc/layers/painted_scrollbar_layer.h" #include "cc/layers/painted_scrollbar_layer.h"
#include <memory>
#include "cc/animation/animation_host.h" #include "cc/animation/animation_host.h"
#include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host.h"
#include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_painted_scrollbar_layer.h"
#include "cc/test/fake_scrollbar.h" #include "cc/test/fake_scrollbar.h"
#include "cc/test/layer_test_common.h" #include "cc/test/layer_test_common.h"
#include "cc/test/test_task_graph_runner.h" #include "cc/test/test_task_graph_runner.h"
...@@ -19,6 +22,20 @@ namespace cc { ...@@ -19,6 +22,20 @@ namespace cc {
namespace { namespace {
class PaintedScrollbarLayerTest : public testing::Test {
protected:
void SetUp() override {
animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
layer_tree_host_ = FakeLayerTreeHost::Create(
&fake_client_, &task_graph_runner_, animation_host_.get());
}
FakeLayerTreeHostClient fake_client_;
TestTaskGraphRunner task_graph_runner_;
std::unique_ptr<AnimationHost> animation_host_;
std::unique_ptr<FakeLayerTreeHost> layer_tree_host_;
};
class MockScrollbar : public FakeScrollbar { class MockScrollbar : public FakeScrollbar {
public: public:
MockScrollbar() { MockScrollbar() {
...@@ -35,14 +52,7 @@ class MockScrollbar : public FakeScrollbar { ...@@ -35,14 +52,7 @@ class MockScrollbar : public FakeScrollbar {
~MockScrollbar() override = default; ~MockScrollbar() override = default;
}; };
TEST(PaintedScrollbarLayerTest, NeedsPaint) { TEST_F(PaintedScrollbarLayerTest, NeedsPaint) {
FakeLayerTreeHostClient fake_client_;
TestTaskGraphRunner task_graph_runner_;
auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
auto layer_tree_host = FakeLayerTreeHost::Create(
&fake_client_, &task_graph_runner_, animation_host.get());
auto scrollbar = base::MakeRefCounted<MockScrollbar>(); auto scrollbar = base::MakeRefCounted<MockScrollbar>();
scoped_refptr<PaintedScrollbarLayer> scrollbar_layer = scoped_refptr<PaintedScrollbarLayer> scrollbar_layer =
PaintedScrollbarLayer::Create(scrollbar); PaintedScrollbarLayer::Create(scrollbar);
...@@ -50,10 +60,10 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) { ...@@ -50,10 +60,10 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) {
scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetIsDrawable(true);
scrollbar_layer->SetBounds(gfx::Size(100, 100)); scrollbar_layer->SetBounds(gfx::Size(100, 100));
layer_tree_host->SetRootLayer(scrollbar_layer); layer_tree_host_->SetRootLayer(scrollbar_layer);
UpdateDrawProperties(layer_tree_host.get()); UpdateDrawProperties(layer_tree_host_.get());
EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host.get()); EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
// Request no paint, but expect them to be painted because they have not // Request no paint, but expect them to be painted because they have not
// yet been initialized. // yet been initialized.
...@@ -95,5 +105,32 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) { ...@@ -95,5 +105,32 @@ TEST(PaintedScrollbarLayerTest, NeedsPaint) {
Mock::VerifyAndClearExpectations(scrollbar.get()); Mock::VerifyAndClearExpectations(scrollbar.get());
} }
TEST_F(PaintedScrollbarLayerTest, InternalContentBounds) {
auto scrollbar = base::MakeRefCounted<FakeScrollbar>();
auto scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar);
scrollbar_layer->SetIsDrawable(true);
scrollbar_layer->SetBounds(gfx::Size(10, 100));
layer_tree_host_->SetRootLayer(scrollbar_layer);
UpdateDrawProperties(layer_tree_host_.get());
EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
scrollbar_layer->Update();
EXPECT_EQ(gfx::Size(10, 100), scrollbar_layer->internal_content_bounds());
layer_tree_host_->SetViewportRectAndScale(
layer_tree_host_->device_viewport_rect(), 2.0f,
layer_tree_host_->local_surface_id_from_parent());
UpdateDrawProperties(layer_tree_host_.get());
scrollbar_layer->Update();
EXPECT_EQ(gfx::Size(20, 200), scrollbar_layer->internal_content_bounds());
layer_tree_host_->SetViewportRectAndScale(
layer_tree_host_->device_viewport_rect(), 0.1f,
layer_tree_host_->local_surface_id_from_parent());
UpdateDrawProperties(layer_tree_host_.get());
scrollbar_layer->Update();
EXPECT_EQ(gfx::Size(10, 100), scrollbar_layer->internal_content_bounds());
}
} // namespace } // namespace
} // namespace cc } // namespace cc
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