1 // Copyright 2013 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 5 #include "build/build_config.h" 6 #include "cc/layers/solid_color_layer.h" 7 #include "cc/test/layer_tree_pixel_test.h" 8 #include "cc/test/pixel_comparator.h" 9 10 #if !defined(OS_ANDROID) 11 12 namespace cc { 13 namespace { 14 15 class LayerTreeHostFiltersPixelTest : public LayerTreePixelTest {}; 16 17 TEST_F(LayerTreeHostFiltersPixelTest, BackgroundFilterBlur) { 18 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( 19 gfx::Rect(200, 200), SK_ColorWHITE); 20 21 // The green box is entirely behind a layer with background blur, so it 22 // should appear blurred on its edges. 23 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( 24 gfx::Rect(50, 50, 100, 100), kCSSGreen); 25 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( 26 gfx::Rect(30, 30, 140, 140), SK_ColorTRANSPARENT); 27 background->AddChild(green); 28 background->AddChild(blur); 29 30 FilterOperations filters; 31 filters.Append(FilterOperation::CreateBlurFilter(2.f)); 32 blur->SetBackgroundFilters(filters); 33 34 #if defined(OS_WIN) 35 // Windows has 436 pixels off by 1: crbug.com/259915 36 float percentage_pixels_large_error = 1.09f; // 436px / (200*200) 37 float percentage_pixels_small_error = 0.0f; 38 float average_error_allowed_in_bad_pixels = 1.f; 39 int large_error_allowed = 1; 40 int small_error_allowed = 0; 41 pixel_comparator_.reset(new FuzzyPixelComparator( 42 true, // discard_alpha 43 percentage_pixels_large_error, 44 percentage_pixels_small_error, 45 average_error_allowed_in_bad_pixels, 46 large_error_allowed, 47 small_error_allowed)); 48 #endif 49 50 RunPixelTest(GL_WITH_BITMAP, 51 background, 52 base::FilePath(FILE_PATH_LITERAL("background_filter_blur.png"))); 53 } 54 55 TEST_F(LayerTreeHostFiltersPixelTest, DISABLED_BackgroundFilterBlurOutsets) { 56 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( 57 gfx::Rect(200, 200), SK_ColorWHITE); 58 59 // The green border is outside the layer with background blur, but the 60 // background blur should use pixels from outside its layer borders, up to the 61 // radius of the blur effect. So the border should be blurred underneath the 62 // top layer causing the green to bleed under the transparent layer, but not 63 // in the 1px region between the transparent layer and the green border. 64 scoped_refptr<SolidColorLayer> green_border = CreateSolidColorLayerWithBorder( 65 gfx::Rect(1, 1, 198, 198), SK_ColorWHITE, 10, kCSSGreen); 66 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( 67 gfx::Rect(12, 12, 176, 176), SK_ColorTRANSPARENT); 68 background->AddChild(green_border); 69 background->AddChild(blur); 70 71 FilterOperations filters; 72 filters.Append(FilterOperation::CreateBlurFilter(5.f)); 73 blur->SetBackgroundFilters(filters); 74 75 #if defined(OS_WIN) 76 // Windows has 2250 pixels off by at most 2: crbug.com/259922 77 float percentage_pixels_large_error = 5.625f; // 2250px / (200*200) 78 float percentage_pixels_small_error = 0.0f; 79 float average_error_allowed_in_bad_pixels = 1.f; 80 int large_error_allowed = 2; 81 int small_error_allowed = 0; 82 pixel_comparator_.reset(new FuzzyPixelComparator( 83 true, // discard_alpha 84 percentage_pixels_large_error, 85 percentage_pixels_small_error, 86 average_error_allowed_in_bad_pixels, 87 large_error_allowed, 88 small_error_allowed)); 89 #endif 90 91 RunPixelTest(GL_WITH_BITMAP, 92 background, 93 base::FilePath(FILE_PATH_LITERAL( 94 "background_filter_blur_outsets.png"))); 95 } 96 97 TEST_F(LayerTreeHostFiltersPixelTest, BackgroundFilterBlurOffAxis) { 98 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( 99 gfx::Rect(200, 200), SK_ColorWHITE); 100 101 // This verifies that the perspective of the clear layer (with black border) 102 // does not influence the blending of the green box behind it. Also verifies 103 // that the blur is correctly clipped inside the transformed clear layer. 104 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer( 105 gfx::Rect(50, 50, 100, 100), kCSSGreen); 106 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayerWithBorder( 107 gfx::Rect(30, 30, 120, 120), SK_ColorTRANSPARENT, 1, SK_ColorBLACK); 108 background->AddChild(green); 109 background->AddChild(blur); 110 111 background->SetPreserves3d(true); 112 gfx::Transform background_transform; 113 background_transform.ApplyPerspectiveDepth(200.0); 114 background->SetTransform(background_transform); 115 116 blur->SetPreserves3d(true); 117 gfx::Transform blur_transform; 118 blur_transform.Translate(55.0, 65.0); 119 blur_transform.RotateAboutXAxis(85.0); 120 blur_transform.RotateAboutYAxis(180.0); 121 blur_transform.RotateAboutZAxis(20.0); 122 blur_transform.Translate(-60.0, -60.0); 123 blur->SetTransform(blur_transform); 124 125 FilterOperations filters; 126 filters.Append(FilterOperation::CreateBlurFilter(2.f)); 127 blur->SetBackgroundFilters(filters); 128 129 #if defined(OS_WIN) 130 // Windows has 151 pixels off by at most 2: crbug.com/225027 131 float percentage_pixels_large_error = 0.3775f; // 151px / (200*200) 132 float percentage_pixels_small_error = 0.0f; 133 float average_error_allowed_in_bad_pixels = 1.f; 134 int large_error_allowed = 2; 135 int small_error_allowed = 0; 136 pixel_comparator_.reset(new FuzzyPixelComparator( 137 true, // discard_alpha 138 percentage_pixels_large_error, 139 percentage_pixels_small_error, 140 average_error_allowed_in_bad_pixels, 141 large_error_allowed, 142 small_error_allowed)); 143 #endif 144 145 RunPixelTest(GL_WITH_BITMAP, 146 background, 147 base::FilePath(FILE_PATH_LITERAL( 148 "background_filter_blur_off_axis.png"))); 149 } 150 151 } // namespace 152 } // namespace cc 153 154 #endif // OS_ANDROID 155