| 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" | 7 #include "cc/quads/draw_quad.h" |
| 8 #include "cc/quads/texture_draw_quad.h" |
| 8 #include "cc/test/layer_test_common.h" | 9 #include "cc/test/layer_test_common.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace cc { | 12 namespace cc { |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 TEST(PaintedScrollbarLayerImplTest, Occlusion) { | 15 TEST(PaintedScrollbarLayerImplTest, Occlusion) { |
| 15 gfx::Size layer_size(10, 1000); | 16 gfx::Size layer_size(10, 1000); |
| 16 float scale = 2.f; | 17 float scale = 2.f; |
| 17 gfx::Size scaled_layer_size(20, 2000); | 18 gfx::Size scaled_layer_size(20, 2000); |
| 18 gfx::Size viewport_size(1000, 1000); | 19 gfx::Size viewport_size(1000, 1000); |
| 20 float thumb_opacity = 0.2f; |
| 21 float track_opacity = 0.8f; |
| 19 | 22 |
| 20 LayerTestCommon::LayerImplTest impl; | 23 LayerTestCommon::LayerImplTest impl; |
| 21 | 24 |
| 22 SkBitmap thumb_sk_bitmap; | 25 SkBitmap thumb_sk_bitmap; |
| 23 thumb_sk_bitmap.allocN32Pixels(10, 10); | 26 thumb_sk_bitmap.allocN32Pixels(10, 10); |
| 24 thumb_sk_bitmap.setImmutable(); | 27 thumb_sk_bitmap.setImmutable(); |
| 25 UIResourceId thumb_uid = 5; | 28 UIResourceId thumb_uid = 5; |
| 26 UIResourceBitmap thumb_bitmap(thumb_sk_bitmap); | 29 UIResourceBitmap thumb_bitmap(thumb_sk_bitmap); |
| 27 impl.host_impl()->CreateUIResource(thumb_uid, thumb_bitmap); | 30 impl.host_impl()->CreateUIResource(thumb_uid, thumb_bitmap); |
| 28 | 31 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 scale, scaled_layer_size); | 46 scale, scaled_layer_size); |
| 44 scrollbar_layer_impl->SetDrawsContent(true); | 47 scrollbar_layer_impl->SetDrawsContent(true); |
| 45 scrollbar_layer_impl->SetThumbThickness(layer_size.width()); | 48 scrollbar_layer_impl->SetThumbThickness(layer_size.width()); |
| 46 scrollbar_layer_impl->SetThumbLength(500); | 49 scrollbar_layer_impl->SetThumbLength(500); |
| 47 scrollbar_layer_impl->SetTrackLength(layer_size.height()); | 50 scrollbar_layer_impl->SetTrackLength(layer_size.height()); |
| 48 scrollbar_layer_impl->SetCurrentPos(100.f / 4); | 51 scrollbar_layer_impl->SetCurrentPos(100.f / 4); |
| 49 scrollbar_layer_impl->SetClipLayerLength(100.f); | 52 scrollbar_layer_impl->SetClipLayerLength(100.f); |
| 50 scrollbar_layer_impl->SetScrollLayerLength(200.f); | 53 scrollbar_layer_impl->SetScrollLayerLength(200.f); |
| 51 scrollbar_layer_impl->set_track_ui_resource_id(track_uid); | 54 scrollbar_layer_impl->set_track_ui_resource_id(track_uid); |
| 52 scrollbar_layer_impl->set_thumb_ui_resource_id(thumb_uid); | 55 scrollbar_layer_impl->set_thumb_ui_resource_id(thumb_uid); |
| 56 scrollbar_layer_impl->set_track_opacity(track_opacity); |
| 57 scrollbar_layer_impl->set_thumb_opacity(thumb_opacity); |
| 53 | 58 |
| 54 impl.CalcDrawProps(viewport_size); | 59 impl.CalcDrawProps(viewport_size); |
| 55 | 60 |
| 56 gfx::Rect thumb_rect = scrollbar_layer_impl->ComputeThumbQuadRect(); | 61 gfx::Rect thumb_rect = scrollbar_layer_impl->ComputeThumbQuadRect(); |
| 57 EXPECT_EQ(gfx::Rect(0, 500 / 4, 10, layer_size.height() / 2).ToString(), | 62 EXPECT_EQ(gfx::Rect(0, 500 / 4, 10, layer_size.height() / 2).ToString(), |
| 58 thumb_rect.ToString()); | 63 thumb_rect.ToString()); |
| 59 | 64 |
| 60 { | 65 { |
| 61 SCOPED_TRACE("No occlusion"); | 66 SCOPED_TRACE("No occlusion"); |
| 62 gfx::Rect occluded; | 67 gfx::Rect occluded; |
| 63 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); | 68 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); |
| 64 | 69 |
| 65 size_t partially_occluded_count = 0; | 70 size_t partially_occluded_count = 0; |
| 66 LayerTestCommon::VerifyQuadsAreOccluded( | 71 LayerTestCommon::VerifyQuadsAreOccluded( |
| 67 impl.quad_list(), occluded, &partially_occluded_count); | 72 impl.quad_list(), occluded, &partially_occluded_count); |
| 68 EXPECT_EQ(2u, impl.quad_list().size()); | 73 EXPECT_EQ(2u, impl.quad_list().size()); |
| 69 EXPECT_EQ(0u, partially_occluded_count); | 74 EXPECT_EQ(0u, partially_occluded_count); |
| 70 | 75 |
| 71 // Note: this is also testing that the thumb and track are both | 76 // Note: this is also testing that the thumb and track are both |
| 72 // scaled by the internal contents scale. It's not occlusion-related | 77 // scaled by the internal contents scale. It's not occlusion-related |
| 73 // but is easy to verify here. | 78 // but is easy to verify here. |
| 74 const DrawQuad* thumb_quad = impl.quad_list().ElementAt(0); | 79 const DrawQuad* thumb_draw_quad = impl.quad_list().ElementAt(0); |
| 75 const DrawQuad* track_quad = impl.quad_list().ElementAt(1); | 80 const DrawQuad* track_draw_quad = impl.quad_list().ElementAt(1); |
| 81 |
| 82 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, thumb_draw_quad->material); |
| 83 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, track_draw_quad->material); |
| 84 |
| 85 const TextureDrawQuad* thumb_quad = |
| 86 TextureDrawQuad::MaterialCast(thumb_draw_quad); |
| 87 const TextureDrawQuad* track_quad = |
| 88 TextureDrawQuad::MaterialCast(track_draw_quad); |
| 76 | 89 |
| 77 gfx::Rect scaled_thumb_rect = gfx::ScaleToEnclosingRect(thumb_rect, scale); | 90 gfx::Rect scaled_thumb_rect = gfx::ScaleToEnclosingRect(thumb_rect, scale); |
| 78 EXPECT_EQ(track_quad->rect.ToString(), | 91 EXPECT_EQ(track_quad->rect.ToString(), |
| 79 gfx::Rect(scaled_layer_size).ToString()); | 92 gfx::Rect(scaled_layer_size).ToString()); |
| 80 EXPECT_EQ(track_quad->opaque_rect.ToString(), | 93 EXPECT_EQ(track_quad->opaque_rect.ToString(), |
| 81 gfx::Rect(scaled_layer_size).ToString()); | 94 gfx::Rect(scaled_layer_size).ToString()); |
| 82 EXPECT_EQ(track_quad->visible_rect.ToString(), | 95 EXPECT_EQ(track_quad->visible_rect.ToString(), |
| 83 gfx::Rect(scaled_layer_size).ToString()); | 96 gfx::Rect(scaled_layer_size).ToString()); |
| 84 EXPECT_EQ(thumb_quad->rect.ToString(), scaled_thumb_rect.ToString()); | 97 EXPECT_EQ(thumb_quad->rect.ToString(), scaled_thumb_rect.ToString()); |
| 85 EXPECT_EQ(thumb_quad->visible_rect.ToString(), | 98 EXPECT_EQ(thumb_quad->visible_rect.ToString(), |
| 86 scaled_thumb_rect.ToString()); | 99 scaled_thumb_rect.ToString()); |
| 100 EXPECT_EQ(thumb_quad->visible_rect.ToString(), |
| 101 scaled_thumb_rect.ToString()); |
| 102 for (size_t i = 0; i < 4; ++i) { |
| 103 EXPECT_EQ(thumb_opacity, thumb_quad->vertex_opacity[i]); |
| 104 EXPECT_EQ(track_opacity, track_quad->vertex_opacity[i]); |
| 105 } |
| 87 } | 106 } |
| 88 | 107 |
| 89 { | 108 { |
| 90 SCOPED_TRACE("Full occlusion"); | 109 SCOPED_TRACE("Full occlusion"); |
| 91 gfx::Rect occluded(scrollbar_layer_impl->visible_layer_rect()); | 110 gfx::Rect occluded(scrollbar_layer_impl->visible_layer_rect()); |
| 92 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); | 111 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); |
| 93 | 112 |
| 94 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); | 113 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); |
| 95 EXPECT_EQ(impl.quad_list().size(), 0u); | 114 EXPECT_EQ(impl.quad_list().size(), 0u); |
| 96 } | 115 } |
| 97 | 116 |
| 98 { | 117 { |
| 99 SCOPED_TRACE("Partial occlusion"); | 118 SCOPED_TRACE("Partial occlusion"); |
| 100 gfx::Rect occluded(0, 0, 5, 1000); | 119 gfx::Rect occluded(0, 0, 5, 1000); |
| 101 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); | 120 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded); |
| 102 | 121 |
| 103 size_t partially_occluded_count = 0; | 122 size_t partially_occluded_count = 0; |
| 104 LayerTestCommon::VerifyQuadsAreOccluded( | 123 LayerTestCommon::VerifyQuadsAreOccluded( |
| 105 impl.quad_list(), occluded, &partially_occluded_count); | 124 impl.quad_list(), occluded, &partially_occluded_count); |
| 106 // The layer outputs two quads, which is partially occluded. | 125 // The layer outputs two quads, which is partially occluded. |
| 107 EXPECT_EQ(2u, impl.quad_list().size()); | 126 EXPECT_EQ(2u, impl.quad_list().size()); |
| 108 EXPECT_EQ(2u, partially_occluded_count); | 127 EXPECT_EQ(2u, partially_occluded_count); |
| 109 } | 128 } |
| 110 } | 129 } |
| 111 | 130 |
| 112 } // namespace | 131 } // namespace |
| 113 } // namespace cc | 132 } // namespace cc |
| OLD | NEW |