[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 5 | #include "cc/scrollbar_layer.h" |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 6 | |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 7 | #include "cc/append_quads_data.h" |
| 8 | #include "cc/prioritized_resource_manager.h" |
| 9 | #include "cc/priority_calculator.h" |
| 10 | #include "cc/resource_update_queue.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 11 | #include "cc/scrollbar_animation_controller.h" |
| 12 | #include "cc/scrollbar_layer_impl.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 13 | #include "cc/single_thread_proxy.h" |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 14 | #include "cc/solid_color_draw_quad.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 15 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 16 | #include "cc/test/fake_layer_tree_host_client.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 17 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 18 | #include "cc/test/fake_scrollbar_theme_painter.h" |
| 19 | #include "cc/test/fake_web_scrollbar.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 20 | #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 21 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 22 | #include "cc/test/layer_tree_test_common.h" |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 23 | #include "cc/test/mock_quad_culler.h" |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 24 | #include "cc/test/test_web_graphics_context_3d.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 25 | #include "cc/tree_synchronizer.h" |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 26 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 27 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 920caa5 | 2012-12-18 22:39:50 | [diff] [blame] | 28 | #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 29 | #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGeometry.h" |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 30 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 31 | namespace cc { |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 32 | namespace { |
| 33 | |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 34 | scoped_ptr<LayerImpl> layerImplForScrollAreaAndScrollbar( |
| 35 | FakeLayerTreeHostImpl* host_impl, |
| 36 | scoped_ptr<WebKit::WebScrollbar> scrollbar, |
| 37 | bool reverse_order) |
| 38 | { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 39 | scoped_refptr<Layer> layerTreeRoot = Layer::Create(); |
| 40 | scoped_refptr<Layer> child1 = Layer::Create(); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 41 | scoped_refptr<Layer> child2 = ScrollbarLayer::Create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(true), child1->id()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 42 | layerTreeRoot->AddChild(child1); |
| 43 | layerTreeRoot->InsertChild(child2, reverse_order ? 0 : 1); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 44 | scoped_ptr<LayerImpl> layerImpl = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), host_impl->active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 45 | TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImpl.get()); |
| 46 | return layerImpl.Pass(); |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 49 | TEST(ScrollbarLayerTest, resolveScrollLayerPointer) |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 50 | { |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 51 | FakeImplProxy proxy; |
| 52 | FakeLayerTreeHostImpl hostImpl(&proxy); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 53 | |
| 54 | { |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 55 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 56 | scoped_ptr<LayerImpl> layerImplTreeRoot = layerImplForScrollAreaAndScrollbar(&hostImpl, scrollbar.Pass(), false); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 57 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 58 | LayerImpl* ccChild1 = layerImplTreeRoot->children()[0]; |
| 59 | ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 60 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 61 | EXPECT_EQ(ccChild1->horizontal_scrollbar_layer(), ccChild2); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | { // another traverse order |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 65 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 66 | scoped_ptr<LayerImpl> layerImplTreeRoot = layerImplForScrollAreaAndScrollbar(&hostImpl, scrollbar.Pass(), true); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 67 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 68 | ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[0]); |
| 69 | LayerImpl* ccChild2 = layerImplTreeRoot->children()[1]; |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 70 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 71 | EXPECT_EQ(ccChild2->horizontal_scrollbar_layer(), ccChild1); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 75 | TEST(ScrollbarLayerTest, shouldScrollNonOverlayOnMainThread) |
| 76 | { |
| 77 | FakeImplProxy proxy; |
| 78 | FakeLayerTreeHostImpl hostImpl(&proxy); |
| 79 | |
| 80 | // Create and attach a non-overlay scrollbar. |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 81 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 82 | static_cast<FakeWebScrollbar*>(scrollbar.get())->setOverlay(false); |
| 83 | scoped_ptr<LayerImpl> layerImplTreeRoot = layerImplForScrollAreaAndScrollbar(&hostImpl, scrollbar.Pass(), false); |
| 84 | ScrollbarLayerImpl* scrollbarLayerImpl = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
| 85 | |
| 86 | // When the scrollbar is not an overlay scrollbar, the scroll should be |
| 87 | // responded to on the main thread as the compositor does not yet implement |
| 88 | // scrollbar scrolling. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 89 | EXPECT_EQ(InputHandlerClient::ScrollOnMainThread, scrollbarLayerImpl->TryScroll(gfx::Point(0, 0), InputHandlerClient::Gesture)); |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 90 | |
| 91 | // Create and attach an overlay scrollbar. |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 92 | scrollbar = FakeWebScrollbar::Create(); |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 93 | static_cast<FakeWebScrollbar*>(scrollbar.get())->setOverlay(true); |
| 94 | |
| 95 | layerImplTreeRoot = layerImplForScrollAreaAndScrollbar(&hostImpl, scrollbar.Pass(), false); |
| 96 | scrollbarLayerImpl = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
| 97 | |
| 98 | // The user shouldn't be able to drag an overlay scrollbar and the scroll |
| 99 | // may be handled in the compositor. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 100 | EXPECT_EQ(InputHandlerClient::ScrollIgnored, scrollbarLayerImpl->TryScroll(gfx::Point(0, 0), InputHandlerClient::Gesture)); |
[email protected] | 7776666 | 2012-12-20 21:01:50 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 103 | TEST(ScrollbarLayerTest, scrollOffsetSynchronization) |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 104 | { |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 105 | FakeImplProxy proxy; |
| 106 | FakeLayerTreeHostImpl hostImpl(&proxy); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 107 | |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 108 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 109 | scoped_refptr<Layer> layerTreeRoot = Layer::Create(); |
| 110 | scoped_refptr<Layer> contentLayer = Layer::Create(); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 111 | scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::Create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(true), layerTreeRoot->id()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 112 | layerTreeRoot->AddChild(contentLayer); |
| 113 | layerTreeRoot->AddChild(scrollbarLayer); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 114 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 115 | layerTreeRoot->SetScrollOffset(gfx::Vector2d(10, 20)); |
| 116 | layerTreeRoot->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
| 117 | layerTreeRoot->SetBounds(gfx::Size(100, 200)); |
| 118 | contentLayer->SetBounds(gfx::Size(100, 200)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 119 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 120 | scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 121 | TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 122 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 123 | ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 124 | |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 125 | EXPECT_EQ(10, ccScrollbarLayer->CurrentPos()); |
| 126 | EXPECT_EQ(100, ccScrollbarLayer->TotalSize()); |
| 127 | EXPECT_EQ(30, ccScrollbarLayer->Maximum()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 128 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 129 | layerTreeRoot->SetScrollOffset(gfx::Vector2d(100, 200)); |
| 130 | layerTreeRoot->SetMaxScrollOffset(gfx::Vector2d(300, 500)); |
| 131 | layerTreeRoot->SetBounds(gfx::Size(1000, 2000)); |
| 132 | contentLayer->SetBounds(gfx::Size(1000, 2000)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 133 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 134 | ScrollbarAnimationController* scrollbarController = layerImplTreeRoot->scrollbar_animation_controller(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 135 | layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.active_tree()); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 136 | TreeSynchronizer::pushProperties(layerTreeRoot.get(), layerImplTreeRoot.get()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 137 | EXPECT_EQ(scrollbarController, layerImplTreeRoot->scrollbar_animation_controller()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 138 | |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 139 | EXPECT_EQ(100, ccScrollbarLayer->CurrentPos()); |
| 140 | EXPECT_EQ(1000, ccScrollbarLayer->TotalSize()); |
| 141 | EXPECT_EQ(300, ccScrollbarLayer->Maximum()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 142 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 143 | layerImplTreeRoot->ScrollBy(gfx::Vector2d(12, 34)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 144 | |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 145 | EXPECT_EQ(112, ccScrollbarLayer->CurrentPos()); |
| 146 | EXPECT_EQ(1000, ccScrollbarLayer->TotalSize()); |
| 147 | EXPECT_EQ(300, ccScrollbarLayer->Maximum()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 150 | TEST(ScrollbarLayerTest, solidColorThicknessOverride) |
| 151 | { |
| 152 | LayerTreeSettings layerTreeSettings; |
| 153 | layerTreeSettings.solidColorScrollbars = true; |
| 154 | layerTreeSettings.solidColorScrollbarThicknessDIP = 3; |
| 155 | FakeImplProxy proxy; |
| 156 | FakeLayerTreeHostImpl hostImpl(layerTreeSettings, &proxy); |
| 157 | |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 158 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 159 | static_cast<FakeWebScrollbar*>(scrollbar.get())->setOverlay(true); |
| 160 | scoped_ptr<LayerImpl> layerImplTreeRoot = layerImplForScrollAreaAndScrollbar(&hostImpl, scrollbar.Pass(), false); |
| 161 | ScrollbarLayerImpl* scrollbarLayerImpl = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 162 | scrollbarLayerImpl->SetThumbSize(gfx::Size(4, 4)); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 163 | |
| 164 | // Thickness should be overridden to 3. |
| 165 | { |
| 166 | MockQuadCuller quadCuller; |
| 167 | AppendQuadsData data; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 168 | scrollbarLayerImpl->AppendQuads(&quadCuller, &data); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 169 | |
| 170 | const QuadList& quads = quadCuller.quadList(); |
| 171 | ASSERT_EQ(1, quads.size()); |
| 172 | EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 173 | EXPECT_RECT_EQ(gfx::Rect(1, 0, 4, 3), quads[0]->rect); |
| 174 | } |
| 175 | |
| 176 | // Contents scale should scale the draw quad. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 177 | scrollbarLayerImpl->draw_properties().contents_scale_x = 2; |
| 178 | scrollbarLayerImpl->draw_properties().contents_scale_y = 2; |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 179 | { |
| 180 | MockQuadCuller quadCuller; |
| 181 | AppendQuadsData data; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 182 | scrollbarLayerImpl->AppendQuads(&quadCuller, &data); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 183 | |
| 184 | const QuadList& quads = quadCuller.quadList(); |
| 185 | ASSERT_EQ(1, quads.size()); |
| 186 | EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 187 | EXPECT_RECT_EQ(gfx::Rect(2, 0, 8, 6), quads[0]->rect); |
| 188 | } |
| 189 | |
| 190 | } |
| 191 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 192 | class ScrollbarLayerTestMaxTextureSize : public ThreadedTest { |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 193 | public: |
| 194 | ScrollbarLayerTestMaxTextureSize() {} |
| 195 | |
| 196 | void setScrollbarBounds(gfx::Size bounds) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 197 | bounds_ = bounds; |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | virtual void beginTest() OVERRIDE |
| 201 | { |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 202 | m_layerTreeHost->InitializeRendererIfNeeded(); |
[email protected] | 344e58d0 | 2012-12-16 04:52:53 | [diff] [blame] | 203 | |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 204 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); |
| 205 | m_scrollbarLayer = ScrollbarLayer::Create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(true), 1); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 206 | m_scrollbarLayer->SetLayerTreeHost(m_layerTreeHost.get()); |
| 207 | m_scrollbarLayer->SetBounds(bounds_); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 208 | m_layerTreeHost->root_layer()->AddChild(m_scrollbarLayer); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 209 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 210 | m_scrollLayer = Layer::Create(); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 211 | m_scrollbarLayer->SetScrollLayerId(m_scrollLayer->id()); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 212 | m_layerTreeHost->root_layer()->AddChild(m_scrollLayer); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 213 | |
| 214 | postSetNeedsCommitToMainThread(); |
| 215 | } |
| 216 | |
| 217 | virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE |
| 218 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 219 | const int kMaxTextureSize = impl->GetRendererCapabilities().max_texture_size; |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 220 | |
| 221 | // Check first that we're actually testing something. |
| 222 | EXPECT_GT(m_scrollbarLayer->bounds().width(), kMaxTextureSize); |
| 223 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 224 | EXPECT_EQ(m_scrollbarLayer->content_bounds().width(), kMaxTextureSize - 1); |
| 225 | EXPECT_EQ(m_scrollbarLayer->content_bounds().height(), kMaxTextureSize - 1); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 226 | |
| 227 | endTest(); |
| 228 | } |
| 229 | |
| 230 | virtual void afterTest() OVERRIDE |
| 231 | { |
| 232 | } |
| 233 | |
| 234 | private: |
| 235 | scoped_refptr<ScrollbarLayer> m_scrollbarLayer; |
| 236 | scoped_refptr<Layer> m_scrollLayer; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 237 | gfx::Size bounds_; |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 241 | scoped_ptr<TestWebGraphicsContext3D> context = TestWebGraphicsContext3D::Create(); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 242 | int max_size = 0; |
[email protected] | 501a770 | 2012-12-19 05:25:05 | [diff] [blame] | 243 | context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 244 | setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); |
| 245 | runTest(true); |
| 246 | } |
| 247 | |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 248 | class MockLayerTreeHost : public LayerTreeHost { |
| 249 | public: |
| 250 | MockLayerTreeHost(const LayerTreeSettings& settings) |
| 251 | : LayerTreeHost(&m_fakeClient, settings) |
| 252 | { |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 253 | Initialize(scoped_ptr<Thread>(NULL)); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | private: |
| 257 | FakeLayerImplTreeHostClient m_fakeClient; |
| 258 | }; |
| 259 | |
| 260 | |
| 261 | class ScrollbarLayerTestResourceCreation : public testing::Test { |
| 262 | public: |
| 263 | ScrollbarLayerTestResourceCreation() |
| 264 | { |
| 265 | } |
| 266 | |
| 267 | void testResourceUpload(int expectedResources) |
| 268 | { |
| 269 | m_layerTreeHost.reset(new MockLayerTreeHost(m_layerTreeSettings)); |
| 270 | |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 271 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 272 | scoped_refptr<Layer> layerTreeRoot = Layer::Create(); |
| 273 | scoped_refptr<Layer> contentLayer = Layer::Create(); |
[email protected] | 3138b26 | 2013-03-08 18:39:08 | [diff] [blame] | 274 | scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::Create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(true), layerTreeRoot->id()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 275 | layerTreeRoot->AddChild(contentLayer); |
| 276 | layerTreeRoot->AddChild(scrollbarLayer); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 277 | |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 278 | m_layerTreeHost->InitializeRendererIfNeeded(); |
| 279 | m_layerTreeHost->contents_texture_manager()->setMaxMemoryLimitBytes(1024 * 1024); |
| 280 | m_layerTreeHost->SetRootLayer(layerTreeRoot); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 281 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 282 | scrollbarLayer->SetIsDrawable(true); |
| 283 | scrollbarLayer->SetBounds(gfx::Size(100, 100)); |
| 284 | layerTreeRoot->SetScrollOffset(gfx::Vector2d(10, 20)); |
| 285 | layerTreeRoot->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
| 286 | layerTreeRoot->SetBounds(gfx::Size(100, 200)); |
| 287 | contentLayer->SetBounds(gfx::Size(100, 200)); |
| 288 | scrollbarLayer->draw_properties().content_bounds = gfx::Size(100, 200); |
| 289 | scrollbarLayer->draw_properties().visible_content_rect = gfx::Rect(0, 0, 100, 200); |
| 290 | scrollbarLayer->CreateRenderSurface(); |
| 291 | scrollbarLayer->draw_properties().render_target = scrollbarLayer; |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 292 | |
| 293 | testing::Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 294 | EXPECT_EQ(scrollbarLayer->layer_tree_host(), m_layerTreeHost.get()); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 295 | |
| 296 | PriorityCalculator calculator; |
| 297 | ResourceUpdateQueue queue; |
| 298 | OcclusionTracker occlusionTracker(gfx::Rect(), false); |
| 299 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 300 | scrollbarLayer->SetTexturePriorities(calculator); |
[email protected] | 804c898 | 2013-03-13 16:32:21 | [diff] [blame] | 301 | m_layerTreeHost->contents_texture_manager()->prioritizeTextures(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 302 | scrollbarLayer->Update(&queue, &occlusionTracker, NULL); |
[email protected] | 72d0fce | 2013-02-20 08:11:58 | [diff] [blame] | 303 | EXPECT_EQ(0, queue.fullUploadSize()); |
| 304 | EXPECT_EQ(expectedResources, queue.partialUploadSize()); |
| 305 | |
| 306 | testing::Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 307 | } |
| 308 | |
| 309 | protected: |
| 310 | scoped_ptr<MockLayerTreeHost> m_layerTreeHost; |
| 311 | LayerTreeSettings m_layerTreeSettings; |
| 312 | }; |
| 313 | |
| 314 | TEST_F(ScrollbarLayerTestResourceCreation, resourceUpload) |
| 315 | { |
| 316 | m_layerTreeSettings.solidColorScrollbars = false; |
| 317 | testResourceUpload(2); |
| 318 | } |
| 319 | |
| 320 | TEST_F(ScrollbarLayerTestResourceCreation, solidColorNoResourceUpload) |
| 321 | { |
| 322 | m_layerTreeSettings.solidColorScrollbars = true; |
| 323 | testResourceUpload(0); |
| 324 | } |
| 325 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 326 | } // namespace |
| 327 | } // namespace cc |