This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
- RunPixelTestType
- TEST_F
- TEST_F
#include "build/build_config.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/test/layer_tree_pixel_test.h"
#include "cc/test/pixel_comparator.h"
#include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
#include "third_party/skia/include/effects/SkColorMatrixFilter.h"
#if !defined(OS_ANDROID)
namespace cc {
namespace {
class LayerTreeHostFiltersPixelTest : public LayerTreePixelTest {};
TEST_F(LayerTreeHostFiltersPixelTest, BackgroundFilterBlur) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
gfx::Rect(50, 50, 100, 100), kCSSGreen);
scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer(
gfx::Rect(30, 30, 140, 140), SK_ColorTRANSPARENT);
background->AddChild(green);
background->AddChild(blur);
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(2.f));
blur->SetBackgroundFilters(filters);
#if defined(OS_WIN)
float percentage_pixels_large_error = 1.09f;
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 1;
int small_error_allowed = 0;
pixel_comparator_.reset(new FuzzyPixelComparator(
true,
percentage_pixels_large_error,
percentage_pixels_small_error,
average_error_allowed_in_bad_pixels,
large_error_allowed,
small_error_allowed));
#endif
RunPixelTest(GL_WITH_BITMAP,
background,
base::FilePath(FILE_PATH_LITERAL("background_filter_blur.png")));
}
TEST_F(LayerTreeHostFiltersPixelTest, BackgroundFilterBlurOutsets) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
scoped_refptr<SolidColorLayer> green_border = CreateSolidColorLayerWithBorder(
gfx::Rect(1, 1, 198, 198), SK_ColorWHITE, 10, kCSSGreen);
scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer(
gfx::Rect(12, 12, 176, 176), SK_ColorTRANSPARENT);
background->AddChild(green_border);
background->AddChild(blur);
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(5.f));
blur->SetBackgroundFilters(filters);
#if defined(OS_WIN)
float percentage_pixels_large_error = 6.5f;
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 2;
int small_error_allowed = 0;
pixel_comparator_.reset(new FuzzyPixelComparator(
true,
percentage_pixels_large_error,
percentage_pixels_small_error,
average_error_allowed_in_bad_pixels,
large_error_allowed,
small_error_allowed));
#endif
RunPixelTest(GL_WITH_BITMAP,
background,
base::FilePath(FILE_PATH_LITERAL(
"background_filter_blur_outsets.png")));
}
TEST_F(LayerTreeHostFiltersPixelTest, BackgroundFilterBlurOffAxis) {
scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
gfx::Rect(200, 200), SK_ColorWHITE);
scoped_refptr<SolidColorLayer> green = CreateSolidColorLayer(
gfx::Rect(50, 50, 100, 100), kCSSGreen);
scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayerWithBorder(
gfx::Rect(30, 30, 120, 120), SK_ColorTRANSPARENT, 1, SK_ColorBLACK);
background->AddChild(green);
background->AddChild(blur);
background->SetShouldFlattenTransform(false);
background->SetIs3dSorted(true);
green->SetShouldFlattenTransform(false);
green->SetIs3dSorted(true);
gfx::Transform background_transform;
background_transform.ApplyPerspectiveDepth(200.0);
background->SetTransform(background_transform);
blur->SetShouldFlattenTransform(false);
blur->SetIs3dSorted(true);
for (size_t i = 0; i < blur->children().size(); ++i)
blur->children()[i]->SetIs3dSorted(true);
gfx::Transform blur_transform;
blur_transform.Translate(55.0, 65.0);
blur_transform.RotateAboutXAxis(85.0);
blur_transform.RotateAboutYAxis(180.0);
blur_transform.RotateAboutZAxis(20.0);
blur_transform.Translate(-60.0, -60.0);
blur->SetTransform(blur_transform);
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(2.f));
blur->SetBackgroundFilters(filters);
#if defined(OS_WIN)
float percentage_pixels_large_error = 0.3825f;
float percentage_pixels_small_error = 0.0f;
float average_error_allowed_in_bad_pixels = 1.f;
int large_error_allowed = 2;
int small_error_allowed = 0;
pixel_comparator_.reset(new FuzzyPixelComparator(
true,
percentage_pixels_large_error,
percentage_pixels_small_error,
average_error_allowed_in_bad_pixels,
large_error_allowed,
small_error_allowed));
#endif
RunPixelTest(GL_WITH_BITMAP,
background,
base::FilePath(FILE_PATH_LITERAL(
"background_filter_blur_off_axis.png")));
}
class ImageFilterClippedPixelTest : public LayerTreeHostFiltersPixelTest {
protected:
void RunPixelTestType(PixelTestType test_type) {
scoped_refptr<SolidColorLayer> root =
CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorBLACK);
scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorYELLOW);
root->AddChild(background);
scoped_refptr<SolidColorLayer> foreground =
CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorRED);
background->AddChild(foreground);
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(matrix[0]));
matrix[2] = matrix[6] = matrix[10] = matrix[18] = SK_Scalar1;
skia::RefPtr<SkColorFilter> colorFilter(
skia::AdoptRef(new SkColorMatrixFilter(matrix)));
SkImageFilter::CropRect crop_rect(SkRect::MakeXYWH(0, 100, 200, 100));
skia::RefPtr<SkImageFilter> filter = skia::AdoptRef(
SkColorFilterImageFilter::Create(colorFilter.get(), NULL, &crop_rect));
FilterOperations filters;
filters.Append(FilterOperation::CreateReferenceFilter(filter));
background->SetMasksToBounds(true);
foreground->SetFilters(filters);
gfx::Transform transform;
transform.Translate(0.0, -100.0);
foreground->SetTransform(transform);
RunPixelTest(test_type,
background,
base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")));
}
};
TEST_F(ImageFilterClippedPixelTest, ImageFilterClipped_GL) {
RunPixelTestType(GL_WITH_BITMAP);
}
TEST_F(ImageFilterClippedPixelTest, ImageFilterClipped_Software) {
RunPixelTestType(SOFTWARE_WITH_BITMAP);
}
}
}
#endif