summaryrefslogtreecommitdiff
path: root/chromium/cc/layers/scrollbar_layer_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/layers/scrollbar_layer_unittest.cc')
-rw-r--r--chromium/cc/layers/scrollbar_layer_unittest.cc389
1 files changed, 276 insertions, 113 deletions
diff --git a/chromium/cc/layers/scrollbar_layer_unittest.cc b/chromium/cc/layers/scrollbar_layer_unittest.cc
index b7981041f09..2e1b4b6f483 100644
--- a/chromium/cc/layers/scrollbar_layer_unittest.cc
+++ b/chromium/cc/layers/scrollbar_layer_unittest.cc
@@ -2,24 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/layers/scrollbar_layer.h"
-
+#include "base/containers/hash_tables.h"
#include "cc/animation/scrollbar_animation_controller.h"
+#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/layers/append_quads_data.h"
-#include "cc/layers/scrollbar_layer_impl.h"
+#include "cc/layers/painted_scrollbar_layer.h"
+#include "cc/layers/painted_scrollbar_layer_impl.h"
+#include "cc/layers/scrollbar_layer_interface.h"
+#include "cc/layers/solid_color_scrollbar_layer.h"
+#include "cc/layers/solid_color_scrollbar_layer_impl.h"
#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/resources/prioritized_resource_manager.h"
-#include "cc/resources/priority_calculator.h"
#include "cc/resources/resource_update_queue.h"
#include "cc/test/fake_impl_proxy.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_impl.h"
+#include "cc/test/fake_painted_scrollbar_layer.h"
#include "cc/test/fake_scrollbar.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/layer_tree_test.h"
#include "cc/test/mock_quad_culler.h"
-#include "cc/test/test_web_graphics_context_3d.h"
+#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/tree_synchronizer.h"
@@ -32,12 +35,20 @@ namespace {
LayerImpl* LayerImplForScrollAreaAndScrollbar(
FakeLayerTreeHost* host,
scoped_ptr<Scrollbar> scrollbar,
- bool reverse_order) {
+ bool reverse_order,
+ bool use_solid_color_scrollbar,
+ int thumb_thickness) {
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> child1 = Layer::Create();
- scoped_refptr<Layer> child2 =
- ScrollbarLayer::Create(scrollbar.Pass(),
- child1->id());
+ scoped_refptr<Layer> child2;
+ if (use_solid_color_scrollbar) {
+ const bool kIsLeftSideVerticalScrollbar = false;
+ child2 = SolidColorScrollbarLayer::Create(
+ scrollbar->Orientation(), thumb_thickness,
+ kIsLeftSideVerticalScrollbar, child1->id());
+ } else {
+ child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id());
+ }
layer_tree_root->AddChild(child1);
layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
host->SetRootLayer(layer_tree_root);
@@ -47,12 +58,13 @@ LayerImpl* LayerImplForScrollAreaAndScrollbar(
TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
- LayerImpl* layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false);
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ host.get(), scrollbar.Pass(), false, false, 0);
LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
- ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>(
- layer_impl_tree_root->children()[1]);
+ PaintedScrollbarLayerImpl* cc_child2 =
+ static_cast<PaintedScrollbarLayerImpl*>(
+ layer_impl_tree_root->children()[1]);
EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2);
}
@@ -60,11 +72,12 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
- LayerImpl* layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), true);
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ host.get(), scrollbar.Pass(), true, false, 0);
- ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>(
- layer_impl_tree_root->children()[0]);
+ PaintedScrollbarLayerImpl* cc_child1 =
+ static_cast<PaintedScrollbarLayerImpl*>(
+ layer_impl_tree_root->children()[0]);
LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1);
@@ -75,10 +88,11 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
// Create and attach a non-overlay scrollbar.
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
- LayerImpl* layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false);
- ScrollbarLayerImpl* scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ host.get(), scrollbar.Pass(), false, false, 0);
+ PaintedScrollbarLayerImpl* scrollbar_layer_impl =
+ static_cast<PaintedScrollbarLayerImpl*>(
+ layer_impl_tree_root->children()[1]);
// When the scrollbar is not an overlay scrollbar, the scroll should be
// responded to on the main thread as the compositor does not yet implement
@@ -90,10 +104,10 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
// Create and attach an overlay scrollbar.
scrollbar.reset(new FakeScrollbar(false, false, true));
- layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false);
- scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
+ layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ host.get(), scrollbar.Pass(), false, false, 0);
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
+ layer_impl_tree_root->children()[1]);
// The user shouldn't be able to drag an overlay scrollbar and the scroll
// may be handled in the compositor.
@@ -102,15 +116,14 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
InputHandler::Gesture));
}
-TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
+TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) {
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create();
scoped_refptr<Layer> scrollbar_layer =
- ScrollbarLayer::Create(scrollbar.Pass(),
- layer_tree_root->id());
+ PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
layer_tree_root->SetScrollable(true);
layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20));
@@ -127,11 +140,12 @@ TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
- ScrollbarLayerImpl* cc_scrollbar_layer =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
+ ScrollbarLayerImplBase* cc_scrollbar_layer =
+ static_cast<PaintedScrollbarLayerImpl*>(
+ layer_impl_tree_root->children()[1]);
- EXPECT_EQ(10.f, cc_scrollbar_layer->CurrentPos());
- EXPECT_EQ(30, cc_scrollbar_layer->Maximum());
+ EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
+ EXPECT_EQ(30, cc_scrollbar_layer->maximum());
layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200));
layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500));
@@ -146,31 +160,124 @@ TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
EXPECT_EQ(scrollbar_controller,
layer_impl_tree_root->scrollbar_animation_controller());
- EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos());
- EXPECT_EQ(300, cc_scrollbar_layer->Maximum());
+ EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
+ EXPECT_EQ(300, cc_scrollbar_layer->maximum());
layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34));
- EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos());
- EXPECT_EQ(300, cc_scrollbar_layer->Maximum());
+ EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
+ EXPECT_EQ(300, cc_scrollbar_layer->maximum());
+}
+
+TEST(ScrollbarLayerTest, ThumbRect) {
+ scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
+ scoped_refptr<Layer> root_layer = Layer::Create();
+ scoped_refptr<Layer> content_layer = Layer::Create();
+ scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
+ FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
+
+ root_layer->SetScrollable(true);
+ root_layer->SetMaxScrollOffset(gfx::Vector2d(80, 0));
+ root_layer->SetBounds(gfx::Size(100, 50));
+ content_layer->SetBounds(gfx::Size(100, 50));
+
+ host->SetRootLayer(root_layer);
+ root_layer->AddChild(content_layer);
+ root_layer->AddChild(scrollbar_layer);
+
+ root_layer->SetScrollOffset(gfx::Vector2d(0, 0));
+ scrollbar_layer->SetBounds(gfx::Size(70, 10));
+ scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
+ scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
+ scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
+ scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
+ scrollbar_layer->UpdateThumbAndTrackGeometry();
+ LayerImpl* root_layer_impl = NULL;
+ PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL;
+
+ // Thumb is at the edge of the scrollbar (should be inset to
+ // the start of the track within the scrollbar layer's
+ // position).
+ scrollbar_layer->UpdateThumbAndTrackGeometry();
+ root_layer_impl = host->CommitAndCreateLayerImplTree();
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
+ root_layer_impl->children()[1]);
+ EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
+ scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
+
+ // Under-scroll (thumb position should clamp and be unchanged).
+ root_layer->SetScrollOffset(gfx::Vector2d(-5, 0));
+
+ scrollbar_layer->UpdateThumbAndTrackGeometry();
+ root_layer_impl = host->CommitAndCreateLayerImplTree();
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
+ root_layer_impl->children()[1]);
+ EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
+ scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
+
+ // Over-scroll (thumb position should clamp on the far side).
+ root_layer->SetScrollOffset(gfx::Vector2d(85, 0));
+
+ scrollbar_layer->UpdateThumbAndTrackGeometry();
+ root_layer_impl = host->CommitAndCreateLayerImplTree();
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
+ root_layer_impl->children()[1]);
+ EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(),
+ scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
+
+ // Change thumb thickness and length.
+ scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4);
+ scrollbar_layer->fake_scrollbar()->set_thumb_length(6);
+
+ scrollbar_layer->UpdateThumbAndTrackGeometry();
+ root_layer_impl = host->CommitAndCreateLayerImplTree();
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
+ root_layer_impl->children()[1]);
+ EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(),
+ scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
+
+ // Shrink the scrollbar layer to cover only the track.
+ scrollbar_layer->SetBounds(gfx::Size(50, 10));
+ scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10));
+ scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
+
+ scrollbar_layer->UpdateThumbAndTrackGeometry();
+ root_layer_impl = host->CommitAndCreateLayerImplTree();
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
+ root_layer_impl->children()[1]);
+ EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
+ scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
+
+ // Shrink the track in the non-scrolling dimension so that it only covers the
+ // middle third of the scrollbar layer (this does not affect the thumb
+ // position).
+ scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6));
+
+ scrollbar_layer->UpdateThumbAndTrackGeometry();
+ root_layer_impl = host->CommitAndCreateLayerImplTree();
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
+ root_layer_impl->children()[1]);
+ EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
+ scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
}
TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
+ const int kThumbThickness = 3;
+ const int kTrackLength = 100;
+
LayerTreeSettings layer_tree_settings;
- layer_tree_settings.solid_color_scrollbars = true;
- layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
scoped_ptr<FakeLayerTreeHost> host =
FakeLayerTreeHost::Create(layer_tree_settings);
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
- LayerImpl* layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false);
- ScrollbarLayerImpl* scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
- scrollbar_layer_impl->SetThumbThickness(3);
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ host.get(), scrollbar.Pass(), false, true, kThumbThickness);
+ ScrollbarLayerImplBase* scrollbar_layer_impl =
+ static_cast<SolidColorScrollbarLayerImpl*>(
+ layer_impl_tree_root->children()[1]);
+ scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
scrollbar_layer_impl->SetCurrentPos(10.f);
scrollbar_layer_impl->SetMaximum(100);
- scrollbar_layer_impl->SetTrackLength(100);
scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f);
// Thickness should be overridden to 3.
@@ -217,20 +324,21 @@ TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
}
TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
+ const int kThumbThickness = 3;
+ const int kTrackLength = 10;
+
LayerTreeSettings layer_tree_settings;
- layer_tree_settings.solid_color_scrollbars = true;
- layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
scoped_ptr<FakeLayerTreeHost> host =
FakeLayerTreeHost::Create(layer_tree_settings);
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
- LayerImpl* layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false);
- ScrollbarLayerImpl* scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ host.get(), scrollbar.Pass(), false, true, kThumbThickness);
+ ScrollbarLayerImplBase* scrollbar_layer_impl =
+ static_cast<PaintedScrollbarLayerImpl*>(
+ layer_impl_tree_root->children()[1]);
- scrollbar_layer_impl->SetThumbThickness(3);
- scrollbar_layer_impl->SetTrackLength(10);
+ scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
scrollbar_layer_impl->SetCurrentPos(4.f);
scrollbar_layer_impl->SetMaximum(8);
@@ -259,40 +367,43 @@ class ScrollbarLayerSolidColorThumbTest : public testing::Test {
layer_tree_settings.solid_color_scrollbars = true;
host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_));
- horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create(
- host_impl_->active_tree(), 1, HORIZONTAL);
- vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create(
- host_impl_->active_tree(), 2, VERTICAL);
+ const int kThumbThickness = 3;
+ const bool kIsLeftSideVerticalScrollbar = false;
+
+ horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create(
+ host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness,
+ kIsLeftSideVerticalScrollbar);
+ vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create(
+ host_impl_->active_tree(), 2, VERTICAL, kThumbThickness,
+ kIsLeftSideVerticalScrollbar);
}
protected:
FakeImplProxy proxy_;
scoped_ptr<FakeLayerTreeHostImpl> host_impl_;
- scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_;
- scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_;
+ scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_;
+ scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_;
};
TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
horizontal_scrollbar_layer_->SetCurrentPos(0);
horizontal_scrollbar_layer_->SetMaximum(10);
- horizontal_scrollbar_layer_->SetThumbThickness(3);
// Simple case - one third of the scrollable area is visible, so the thumb
// should be one third as long as the track.
horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f);
- horizontal_scrollbar_layer_->SetTrackLength(100);
+ horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3));
EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
// The thumb's length should never be less than its thickness.
horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f);
- horizontal_scrollbar_layer_->SetTrackLength(100);
+ horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3));
EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
}
TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
- horizontal_scrollbar_layer_->SetTrackLength(100);
+ horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3));
horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f);
- horizontal_scrollbar_layer_->SetThumbThickness(3);
horizontal_scrollbar_layer_->SetCurrentPos(0);
horizontal_scrollbar_layer_->SetMaximum(100);
@@ -311,15 +422,15 @@ TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
}
TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
- ScrollbarLayerImpl* layers[2] =
+ SolidColorScrollbarLayerImpl* layers[2] =
{ horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() };
for (size_t i = 0; i < 2; ++i) {
- layers[i]->SetTrackLength(100);
layers[i]->SetVisibleToTotalLengthRatio(0.2f);
- layers[i]->SetThumbThickness(3);
layers[i]->SetCurrentPos(25);
layers[i]->SetMaximum(100);
}
+ layers[0]->SetBounds(gfx::Size(100, 3));
+ layers[1]->SetBounds(gfx::Size(3, 100));
EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f),
horizontal_scrollbar_layer_->ComputeThumbQuadRect());
@@ -347,7 +458,7 @@ class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
virtual void BeginTest() OVERRIDE {
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
- scrollbar_layer_ = ScrollbarLayer::Create(scrollbar.Pass(), 1);
+ scrollbar_layer_ = PaintedScrollbarLayer::Create(scrollbar.Pass(), 1);
scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
scrollbar_layer_->SetBounds(bounds_);
layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
@@ -377,7 +488,7 @@ class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
virtual void AfterTest() OVERRIDE {}
private:
- scoped_refptr<ScrollbarLayer> scrollbar_layer_;
+ scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_;
scoped_refptr<Layer> scroll_layer_;
gfx::Size bounds_;
};
@@ -404,9 +515,49 @@ class MockLayerTreeHost : public LayerTreeHost {
public:
MockLayerTreeHost(LayerTreeHostClient* client,
const LayerTreeSettings& settings)
- : LayerTreeHost(client, settings) {
+ : LayerTreeHost(client, settings),
+ next_id_(1),
+ total_ui_resource_created_(0),
+ total_ui_resource_deleted_(0) {
Initialize(NULL);
}
+
+ virtual UIResourceId CreateUIResource(UIResourceClient* content) OVERRIDE {
+ total_ui_resource_created_++;
+ UIResourceId nid = next_id_++;
+ ui_resource_bitmap_map_.insert(
+ std::make_pair(nid, content->GetBitmap(nid, false)));
+ return nid;
+ }
+
+ // Deletes a UI resource. May safely be called more than once.
+ virtual void DeleteUIResource(UIResourceId id) OVERRIDE {
+ UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
+ if (iter != ui_resource_bitmap_map_.end()) {
+ ui_resource_bitmap_map_.erase(iter);
+ total_ui_resource_deleted_++;
+ }
+ }
+
+ size_t UIResourceCount() { return ui_resource_bitmap_map_.size(); }
+ int TotalUIResourceDeleted() { return total_ui_resource_deleted_; }
+ int TotalUIResourceCreated() { return total_ui_resource_created_; }
+
+ gfx::Size ui_resource_size(UIResourceId id) {
+ UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
+ if (iter != ui_resource_bitmap_map_.end())
+ return iter->second.GetSize();
+ return gfx::Size();
+ }
+
+ private:
+ typedef base::hash_map<UIResourceId, UIResourceBitmap>
+ UIResourceBitmapMap;
+ UIResourceBitmapMap ui_resource_bitmap_map_;
+
+ int next_id_;
+ int total_ui_resource_created_;
+ int total_ui_resource_deleted_;
};
@@ -415,21 +566,34 @@ class ScrollbarLayerTestResourceCreation : public testing::Test {
ScrollbarLayerTestResourceCreation()
: fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
- void TestResourceUpload(size_t expected_resources) {
+ void TestResourceUpload(int num_updates,
+ size_t expected_resources,
+ int expected_created,
+ int expected_deleted,
+ bool use_solid_color_scrollbar) {
layer_tree_host_.reset(
new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create();
- scoped_refptr<Layer> scrollbar_layer =
- ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
+ scoped_refptr<Layer> scrollbar_layer;
+ if (use_solid_color_scrollbar) {
+ const int kThumbThickness = 3;
+ const bool kIsLeftSideVerticalScrollbar = false;
+ scrollbar_layer =
+ SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
+ kThumbThickness,
+ kIsLeftSideVerticalScrollbar,
+ layer_tree_root->id());
+ } else {
+ scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(),
+ layer_tree_root->id());
+ }
layer_tree_root->AddChild(content_layer);
layer_tree_root->AddChild(scrollbar_layer);
layer_tree_host_->InitializeOutputSurfaceIfNeeded();
- layer_tree_host_->contents_texture_manager()->
- SetMaxMemoryLimitBytes(1024 * 1024);
layer_tree_host_->SetRootLayer(layer_tree_root);
scrollbar_layer->SetIsDrawable(true);
@@ -447,16 +611,17 @@ class ScrollbarLayerTestResourceCreation : public testing::Test {
testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
- PriorityCalculator calculator;
ResourceUpdateQueue queue;
OcclusionTracker occlusion_tracker(gfx::Rect(), false);
scrollbar_layer->SavePaintProperties();
- scrollbar_layer->SetTexturePriorities(calculator);
- layer_tree_host_->contents_texture_manager()->PrioritizeTextures();
- scrollbar_layer->Update(&queue, &occlusion_tracker);
- EXPECT_EQ(0u, queue.FullUploadSize());
- EXPECT_EQ(expected_resources, queue.PartialUploadSize());
+ for (int update_counter = 0; update_counter < num_updates; update_counter++)
+ scrollbar_layer->Update(&queue, &occlusion_tracker);
+
+ // A non-solid-color scrollbar should have requested two textures.
+ EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount());
+ EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
+ EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
@@ -470,13 +635,22 @@ class ScrollbarLayerTestResourceCreation : public testing::Test {
};
TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
- layer_tree_settings_.solid_color_scrollbars = false;
- TestResourceUpload(2);
+ bool use_solid_color_scrollbars = false;
+ TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
+ int num_updates[3] = {1, 5, 10};
+ for (int j = 0; j < 3; j++) {
+ TestResourceUpload(num_updates[j],
+ 2,
+ num_updates[j] * 2,
+ (num_updates[j] - 1) * 2,
+ use_solid_color_scrollbars);
+ }
}
TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
- layer_tree_settings_.solid_color_scrollbars = true;
- TestResourceUpload(0);
+ bool use_solid_color_scrollbars = true;
+ TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
+ TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
}
class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
@@ -484,25 +658,20 @@ class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
ScaledScrollbarLayerTestResourceCreation()
: fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
- void TestResourceUpload(size_t expected_resources, const float test_scale) {
+ void TestResourceUpload(const float test_scale) {
layer_tree_host_.reset(
new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
gfx::Point scrollbar_location(0, 185);
- scoped_ptr<FakeScrollbar> scrollbar(new FakeScrollbar(false, true, false));
- scrollbar->set_location(scrollbar_location);
-
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create();
- scoped_refptr<Layer> scrollbar_layer =
- ScrollbarLayer::Create(scrollbar.PassAs<cc::Scrollbar>(),
- layer_tree_root->id());
+ scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
+ FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
+
layer_tree_root->AddChild(content_layer);
layer_tree_root->AddChild(scrollbar_layer);
layer_tree_host_->InitializeOutputSurfaceIfNeeded();
- layer_tree_host_->contents_texture_manager()->
- SetMaxMemoryLimitBytes(1024 * 1024);
layer_tree_host_->SetRootLayer(layer_tree_root);
scrollbar_layer->SetIsDrawable(true);
@@ -529,30 +698,23 @@ class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
- PriorityCalculator calculator;
ResourceUpdateQueue queue;
OcclusionTracker occlusion_tracker(gfx::Rect(), false);
-
scrollbar_layer->SavePaintProperties();
- scrollbar_layer->SetTexturePriorities(calculator);
- layer_tree_host_->contents_texture_manager()->PrioritizeTextures();
scrollbar_layer->Update(&queue, &occlusion_tracker);
- EXPECT_EQ(expected_resources, queue.PartialUploadSize());
// Verify that we have not generated any content uploads that are larger
// than their destination textures.
- while (queue.HasMoreUpdates()) {
- ResourceUpdate update = queue.TakeFirstPartialUpload();
- EXPECT_LE(update.texture->size().width(),
- scrollbar_layer->content_bounds().width());
- EXPECT_LE(update.texture->size().height(),
- scrollbar_layer->content_bounds().height());
-
- EXPECT_LE(update.dest_offset.x() + update.content_rect.width(),
- update.texture->size().width());
- EXPECT_LE(update.dest_offset.y() + update.content_rect.height(),
- update.texture->size().height());
- }
+
+ gfx::Size track_size = layer_tree_host_->ui_resource_size(
+ scrollbar_layer->track_resource_id());
+ gfx::Size thumb_size = layer_tree_host_->ui_resource_size(
+ scrollbar_layer->thumb_resource_id());
+
+ EXPECT_LE(track_size.width(), scrollbar_layer->content_bounds().width());
+ EXPECT_LE(track_size.height(), scrollbar_layer->content_bounds().height());
+ EXPECT_LE(thumb_size.width(), scrollbar_layer->content_bounds().width());
+ EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height());
testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
@@ -566,10 +728,11 @@ class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
};
TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
- layer_tree_settings_.solid_color_scrollbars = false;
// Pick a test scale that moves the scrollbar's (non-zero) position to
// a non-pixel-aligned location.
- TestResourceUpload(2, 1.41f);
+ TestResourceUpload(.041f);
+ TestResourceUpload(1.41f);
+ TestResourceUpload(4.1f);
}
} // namespace