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