Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: cc/scrollbar_layer_unittest.cc

Issue 12297009: cc: SolidColorQuad-based scrollbars for Android [M25] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix DCHECK failure in test by creating render surface Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scrollbar_layer_impl.cc ('k') | content/renderer/gpu/render_widget_compositor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scrollbar_layer.h" 5 #include "cc/scrollbar_layer.h"
6 6
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"
7 #include "cc/scrollbar_animation_controller.h" 11 #include "cc/scrollbar_animation_controller.h"
8 #include "cc/scrollbar_layer_impl.h" 12 #include "cc/scrollbar_layer_impl.h"
9 #include "cc/single_thread_proxy.h" 13 #include "cc/single_thread_proxy.h"
14 #include "cc/solid_color_draw_quad.h"
10 #include "cc/test/fake_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_client.h"
11 #include "cc/test/fake_layer_tree_host_impl.h" 17 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_scrollbar_theme_painter.h" 18 #include "cc/test/fake_scrollbar_theme_painter.h"
13 #include "cc/test/fake_web_scrollbar.h" 19 #include "cc/test/fake_web_scrollbar.h"
14 #include "cc/test/fake_web_scrollbar_theme_geometry.h" 20 #include "cc/test/fake_web_scrollbar_theme_geometry.h"
21 #include "cc/test/geometry_test_utils.h"
15 #include "cc/test/layer_tree_test_common.h" 22 #include "cc/test/layer_tree_test_common.h"
23 #include "cc/test/mock_quad_culler.h"
16 #include "cc/test/test_web_graphics_context_3d.h" 24 #include "cc/test/test_web_graphics_context_3d.h"
17 #include "cc/tree_synchronizer.h" 25 #include "cc/tree_synchronizer.h"
26 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h"
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGe ometry.h" 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGe ometry.h"
21 30
22 namespace cc { 31 namespace cc {
23 namespace { 32 namespace {
24 33
25 scoped_ptr<LayerImpl> layerImplForScrollAreaAndScrollbar( 34 scoped_ptr<LayerImpl> layerImplForScrollAreaAndScrollbar(
26 FakeLayerTreeHostImpl* host_impl, 35 FakeLayerTreeHostImpl* host_impl,
27 scoped_ptr<WebKit::WebScrollbar> scrollbar, 36 scoped_ptr<WebKit::WebScrollbar> scrollbar,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); 140 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
132 EXPECT_EQ(300, ccScrollbarLayer->maximum()); 141 EXPECT_EQ(300, ccScrollbarLayer->maximum());
133 142
134 layerImplTreeRoot->scrollBy(gfx::Vector2d(12, 34)); 143 layerImplTreeRoot->scrollBy(gfx::Vector2d(12, 34));
135 144
136 EXPECT_EQ(112, ccScrollbarLayer->currentPos()); 145 EXPECT_EQ(112, ccScrollbarLayer->currentPos());
137 EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); 146 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
138 EXPECT_EQ(300, ccScrollbarLayer->maximum()); 147 EXPECT_EQ(300, ccScrollbarLayer->maximum());
139 } 148 }
140 149
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
158 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
159 static_cast<FakeWebScrollbar*>(scrollbar.get())->setOverlay(true);
160 scoped_ptr<LayerImpl> layerImplTreeRoot = layerImplForScrollAreaAndScrollbar (&hostImpl, scrollbar.Pass(), false);
161 ScrollbarLayerImpl* scrollbarLayerImpl = static_cast<ScrollbarLayerImpl*>(la yerImplTreeRoot->children()[1]);
162 scrollbarLayerImpl->setThumbSize(gfx::Size(4, 4));
163
164 // Thickness should be overridden to 3.
165 {
166 MockQuadCuller quadCuller;
167 AppendQuadsData data;
168 scrollbarLayerImpl->appendQuads(quadCuller, data);
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.
177 scrollbarLayerImpl->drawProperties().contents_scale_x = 2;
178 scrollbarLayerImpl->drawProperties().contents_scale_y = 2;
179 {
180 MockQuadCuller quadCuller;
181 AppendQuadsData data;
182 scrollbarLayerImpl->appendQuads(quadCuller, data);
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
141 class ScrollbarLayerTestMaxTextureSize : public ThreadedTest { 192 class ScrollbarLayerTestMaxTextureSize : public ThreadedTest {
142 public: 193 public:
143 ScrollbarLayerTestMaxTextureSize() {} 194 ScrollbarLayerTestMaxTextureSize() {}
144 195
145 void setScrollbarBounds(gfx::Size bounds) { 196 void setScrollbarBounds(gfx::Size bounds) {
146 m_bounds = bounds; 197 m_bounds = bounds;
147 } 198 }
148 199
149 virtual void beginTest() OVERRIDE 200 virtual void beginTest() OVERRIDE
150 { 201 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 }; 238 };
188 239
189 TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { 240 TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) {
190 scoped_ptr<TestWebGraphicsContext3D> context = TestWebGraphicsContext3D::Cre ate(); 241 scoped_ptr<TestWebGraphicsContext3D> context = TestWebGraphicsContext3D::Cre ate();
191 int max_size = 0; 242 int max_size = 0;
192 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 243 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
193 setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 244 setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
194 runTest(true); 245 runTest(true);
195 } 246 }
196 247
248 class MockLayerTreeHost : public LayerTreeHost {
249 public:
250 MockLayerTreeHost(const LayerTreeSettings& settings)
251 : LayerTreeHost(&m_fakeClient, settings)
252 {
253 initialize(scoped_ptr<Thread>(NULL));
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
271 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
272 scoped_refptr<Layer> layerTreeRoot = Layer::create();
273 scoped_refptr<Layer> contentLayer = Layer::create();
274 scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.P ass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(true), layerTreeRoot->id());
275 layerTreeRoot->addChild(contentLayer);
276 layerTreeRoot->addChild(scrollbarLayer);
277
278 m_layerTreeHost->initializeRendererIfNeeded();
279 m_layerTreeHost->contentsTextureManager()->setMaxMemoryLimitBytes(1024 * 1024);
280 m_layerTreeHost->setRootLayer(layerTreeRoot);
281
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->drawProperties().content_bounds = gfx::Size(100, 200);
289 scrollbarLayer->drawProperties().visible_content_rect = gfx::Rect(0, 0, 100, 200);
290 scrollbarLayer->createRenderSurface();
291 scrollbarLayer->drawProperties().render_target = scrollbarLayer;
292
293 testing::Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
294 EXPECT_EQ(scrollbarLayer->layerTreeHost(), m_layerTreeHost.get());
295
296 PriorityCalculator calculator;
297 ResourceUpdateQueue queue;
298 OcclusionTracker occlusionTracker(gfx::Rect(), false);
299
300 scrollbarLayer->setTexturePriorities(calculator);
301 m_layerTreeHost->contentsTextureManager()->prioritizeTextures();
302 scrollbarLayer->update(queue, &occlusionTracker, NULL);
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
197 } // namespace 326 } // namespace
198 } // namespace cc 327 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scrollbar_layer_impl.cc ('k') | content/renderer/gpu/render_widget_compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698