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

Side by Side Diff: cc/layers/painted_scrollbar_layer_impl_unittest.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/layers/painted_scrollbar_layer_impl.h" 5 #include "cc/layers/painted_scrollbar_layer_impl.h"
6 6
7 #include "cc/quads/draw_quad.h"
7 #include "cc/test/layer_test_common.h" 8 #include "cc/test/layer_test_common.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace cc { 11 namespace cc {
11 namespace { 12 namespace {
12 13
13 TEST(PaintedScrollbarLayerImplTest, Occlusion) { 14 TEST(PaintedScrollbarLayerImplTest, Occlusion) {
14 gfx::Size layer_size(10, 1000); 15 gfx::Size layer_size(10, 1000);
16 float scale = 2.f;
17 gfx::Size scaled_layer_size(20, 2000);
15 gfx::Size viewport_size(1000, 1000); 18 gfx::Size viewport_size(1000, 1000);
16 19
17 LayerTestCommon::LayerImplTest impl; 20 LayerTestCommon::LayerImplTest impl;
18 21
19 SkBitmap thumb_sk_bitmap; 22 SkBitmap thumb_sk_bitmap;
20 thumb_sk_bitmap.allocN32Pixels(10, 10); 23 thumb_sk_bitmap.allocN32Pixels(10, 10);
21 thumb_sk_bitmap.setImmutable(); 24 thumb_sk_bitmap.setImmutable();
22 UIResourceId thumb_uid = 5; 25 UIResourceId thumb_uid = 5;
23 UIResourceBitmap thumb_bitmap(thumb_sk_bitmap); 26 UIResourceBitmap thumb_bitmap(thumb_sk_bitmap);
24 impl.host_impl()->CreateUIResource(thumb_uid, thumb_bitmap); 27 impl.host_impl()->CreateUIResource(thumb_uid, thumb_bitmap);
25 28
26 SkBitmap track_sk_bitmap; 29 SkBitmap track_sk_bitmap;
27 track_sk_bitmap.allocN32Pixels(10, 10); 30 track_sk_bitmap.allocN32Pixels(10, 10);
28 track_sk_bitmap.setImmutable(); 31 track_sk_bitmap.setImmutable();
29 UIResourceId track_uid = 6; 32 UIResourceId track_uid = 6;
30 UIResourceBitmap track_bitmap(track_sk_bitmap); 33 UIResourceBitmap track_bitmap(track_sk_bitmap);
31 impl.host_impl()->CreateUIResource(track_uid, track_bitmap); 34 impl.host_impl()->CreateUIResource(track_uid, track_bitmap);
32 35
33 ScrollbarOrientation orientation = VERTICAL; 36 ScrollbarOrientation orientation = VERTICAL;
34 37
35 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 38 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
36 impl.AddChildToRoot<PaintedScrollbarLayerImpl>(orientation); 39 impl.AddChildToRoot<PaintedScrollbarLayerImpl>(orientation);
37 scrollbar_layer_impl->SetBounds(layer_size); 40 scrollbar_layer_impl->SetBounds(layer_size);
38 scrollbar_layer_impl->SetContentBounds(layer_size); 41 scrollbar_layer_impl->SetContentBounds(layer_size);
42 scrollbar_layer_impl->SetContentsOpaque(true);
43 scrollbar_layer_impl->set_internal_contents_scale_and_bounds(
44 scale, scaled_layer_size);
39 scrollbar_layer_impl->SetDrawsContent(true); 45 scrollbar_layer_impl->SetDrawsContent(true);
40 scrollbar_layer_impl->SetThumbThickness(layer_size.width()); 46 scrollbar_layer_impl->SetThumbThickness(layer_size.width());
41 scrollbar_layer_impl->SetThumbLength(500); 47 scrollbar_layer_impl->SetThumbLength(500);
42 scrollbar_layer_impl->SetTrackLength(layer_size.height()); 48 scrollbar_layer_impl->SetTrackLength(layer_size.height());
43 scrollbar_layer_impl->SetCurrentPos(100.f / 4); 49 scrollbar_layer_impl->SetCurrentPos(100.f / 4);
44 scrollbar_layer_impl->SetMaximum(100); 50 scrollbar_layer_impl->SetMaximum(100);
45 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(1.f / 2); 51 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(1.f / 2);
46 scrollbar_layer_impl->set_track_ui_resource_id(track_uid); 52 scrollbar_layer_impl->set_track_ui_resource_id(track_uid);
47 scrollbar_layer_impl->set_thumb_ui_resource_id(thumb_uid); 53 scrollbar_layer_impl->set_thumb_ui_resource_id(thumb_uid);
48 54
49 impl.CalcDrawProps(viewport_size); 55 impl.CalcDrawProps(viewport_size);
50 56
51 gfx::Rect thumb_rect = scrollbar_layer_impl->ComputeThumbQuadRect(); 57 gfx::Rect thumb_rect = scrollbar_layer_impl->ComputeThumbQuadRect();
52 EXPECT_EQ(gfx::Rect(0, 500 / 4, 10, layer_size.height() / 2).ToString(), 58 EXPECT_EQ(gfx::Rect(0, 500 / 4, 10, layer_size.height() / 2).ToString(),
53 thumb_rect.ToString()); 59 thumb_rect.ToString());
54 60
55 { 61 {
56 SCOPED_TRACE("No occlusion"); 62 SCOPED_TRACE("No occlusion");
57 gfx::Rect occluded; 63 gfx::Rect occluded;
58 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); 64 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
59 65
60 size_t partially_occluded_count = 0; 66 size_t partially_occluded_count = 0;
61 LayerTestCommon::VerifyQuadsAreOccluded( 67 LayerTestCommon::VerifyQuadsAreOccluded(
62 impl.quad_list(), occluded, &partially_occluded_count); 68 impl.quad_list(), occluded, &partially_occluded_count);
63 EXPECT_EQ(2u, impl.quad_list().size()); 69 EXPECT_EQ(2u, impl.quad_list().size());
64 EXPECT_EQ(0u, partially_occluded_count); 70 EXPECT_EQ(0u, partially_occluded_count);
71
72 // Note: this is also testing that the thumb and track are both
73 // scaled by the internal contents scale. It's not occlusion-related
74 // but is easy to verify here.
75 const DrawQuad* thumb_quad = impl.quad_list().ElementAt(0);
76 const DrawQuad* track_quad = impl.quad_list().ElementAt(1);
77
78 gfx::Rect scaled_thumb_rect = gfx::ScaleToEnclosingRect(thumb_rect, scale);
79 EXPECT_EQ(track_quad->rect.ToString(),
80 gfx::Rect(scaled_layer_size).ToString());
81 EXPECT_EQ(track_quad->opaque_rect.ToString(),
82 gfx::Rect(scaled_layer_size).ToString());
83 EXPECT_EQ(track_quad->visible_rect.ToString(),
84 gfx::Rect(scaled_layer_size).ToString());
85 EXPECT_EQ(thumb_quad->rect.ToString(), scaled_thumb_rect.ToString());
86 EXPECT_EQ(thumb_quad->visible_rect.ToString(),
87 scaled_thumb_rect.ToString());
65 } 88 }
66 89
67 { 90 {
68 SCOPED_TRACE("Full occlusion"); 91 SCOPED_TRACE("Full occlusion");
69 gfx::Rect occluded(scrollbar_layer_impl->visible_content_rect()); 92 gfx::Rect occluded(scrollbar_layer_impl->visible_content_rect());
70 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); 93 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
71 94
72 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); 95 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
73 EXPECT_EQ(impl.quad_list().size(), 0u); 96 EXPECT_EQ(impl.quad_list().size(), 0u);
74 } 97 }
75 98
76 { 99 {
77 SCOPED_TRACE("Partial occlusion"); 100 SCOPED_TRACE("Partial occlusion");
78 gfx::Rect occluded(0, 0, 5, 1000); 101 gfx::Rect occluded(0, 0, 5, 1000);
79 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); 102 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
80 103
81 size_t partially_occluded_count = 0; 104 size_t partially_occluded_count = 0;
82 LayerTestCommon::VerifyQuadsAreOccluded( 105 LayerTestCommon::VerifyQuadsAreOccluded(
83 impl.quad_list(), occluded, &partially_occluded_count); 106 impl.quad_list(), occluded, &partially_occluded_count);
84 // The layer outputs two quads, which is partially occluded. 107 // The layer outputs two quads, which is partially occluded.
85 EXPECT_EQ(2u, impl.quad_list().size()); 108 EXPECT_EQ(2u, impl.quad_list().size());
86 EXPECT_EQ(2u, partially_occluded_count); 109 EXPECT_EQ(2u, partially_occluded_count);
87 } 110 }
88 } 111 }
89 112
90 } // namespace 113 } // namespace
91 } // namespace cc 114 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/painted_scrollbar_layer_impl.cc ('k') | cc/layers/picture_image_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698