Reenable NullOpenerRedirectForksProcess, as the offending patch has been reverted
[chromium-blink-merge.git] / cc / render_surface_filters_unittest.cc
blob17d3ab7d9c3dfdb5ab6c81b9fce5a0f3149544fb
1 // Copyright 2012 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.
5 #include "cc/render_surface_filters.h"
7 #include "cc/test/compositor_fake_web_graphics_context_3d.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include <public/WebFilterOperation.h>
10 #include <public/WebFilterOperations.h>
12 using namespace WebKit;
14 namespace cc {
15 namespace {
17 // Checks whether op can be combined with a following color matrix.
18 bool isCombined(const WebFilterOperation& op)
20 WebFilterOperations filters;
21 filters.append(op);
22 filters.append(WebFilterOperation::createBrightnessFilter(0)); // brightness(0) is identity.
23 WebFilterOperations optimized = RenderSurfaceFilters::optimize(filters);
24 return optimized.size() == 1;
27 TEST(RenderSurfaceFiltersTest, testColorMatrixFiltersCombined)
29 // Several filters should always combine for any amount between 0 and 1:
30 // grayscale, saturate, invert, contrast, opacity.
31 EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0)));
32 // Note that we use 0.3f to avoid "argument is truncated from 'double' to
33 // 'float'" warnings on Windows. 0.5 is exactly representable as a float, so
34 // there is no warning.
35 EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0.3f)));
36 EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(0.5)));
37 EXPECT_TRUE(isCombined(WebFilterOperation::createGrayscaleFilter(1)));
39 EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(0)));
40 EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(0.3f)));
41 EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(0.5)));
42 EXPECT_TRUE(isCombined(WebFilterOperation::createSaturateFilter(1)));
44 EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(0)));
45 EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(0.3f)));
46 EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(0.5)));
47 EXPECT_TRUE(isCombined(WebFilterOperation::createInvertFilter(1)));
49 EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(0)));
50 EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(0.3f)));
51 EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(0.5)));
52 EXPECT_TRUE(isCombined(WebFilterOperation::createContrastFilter(1)));
54 EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(0)));
55 EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(0.3f)));
56 EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(0.5)));
57 EXPECT_TRUE(isCombined(WebFilterOperation::createOpacityFilter(1)));
59 // Several filters should never combine: brightness(amount > 0), blur, drop-shadow.
60 EXPECT_FALSE(isCombined(WebFilterOperation::createBrightnessFilter(0.5)));
61 EXPECT_FALSE(isCombined(WebFilterOperation::createBrightnessFilter(1)));
62 EXPECT_FALSE(isCombined(WebFilterOperation::createBlurFilter(3)));
63 EXPECT_FALSE(isCombined(WebFilterOperation::createDropShadowFilter(WebPoint(2, 2), 3, 0xffffffff)));
65 // sepia and hue may or may not combine depending on the value.
66 EXPECT_TRUE(isCombined(WebFilterOperation::createSepiaFilter(0)));
67 EXPECT_FALSE(isCombined(WebFilterOperation::createSepiaFilter(1)));
68 EXPECT_TRUE(isCombined(WebFilterOperation::createHueRotateFilter(0)));
69 EXPECT_FALSE(isCombined(WebFilterOperation::createHueRotateFilter(180)));
71 float matrix1[20] = {
72 1, 0, 0, 0, 0,
73 0, 1, 0, 0, 0,
74 0, 0, 1, 0, 0,
75 0, 0, 0, 1, 0,
77 EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix1)));
79 float matrix2[20] = {
80 1, 1, 0, 0, 0,
81 0, 1, 0, 0, 0,
82 0, 0, 1, 0, 0,
83 0, 0, 0, 1, 0,
85 EXPECT_FALSE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix2)));
87 float matrix3[20] = {
88 0.25, 0, 0, 0, 255*0.75,
89 0, 1, 0, 0, 0,
90 0, 0, 1, 0, 0,
91 0, 0, 0, 1, 0,
93 EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix3)));
95 float matrix4[20] = {
96 -0.25, 0.75, 0, 0, 255*0.25,
97 0, 1, 0, 0, 0,
98 0, 0, 1, 0, 0,
99 0, 0, 0, 1, 0,
101 EXPECT_TRUE(isCombined(WebFilterOperation::createColorMatrixFilter(matrix4)));
104 TEST(RenderSurfaceFiltersTest, testOptimize)
106 WebFilterOperation combines(WebFilterOperation::createBrightnessFilter(0));
107 WebFilterOperation doesntCombine(WebFilterOperation::createBrightnessFilter(1));
109 WebFilterOperations filters;
110 WebFilterOperations optimized = RenderSurfaceFilters::optimize(filters);
111 EXPECT_EQ(0u, optimized.size());
113 filters.append(combines);
114 optimized = RenderSurfaceFilters::optimize(filters);
115 EXPECT_EQ(1u, optimized.size());
117 filters.append(combines);
118 optimized = RenderSurfaceFilters::optimize(filters);
119 EXPECT_EQ(1u, optimized.size());
121 filters.append(doesntCombine);
122 optimized = RenderSurfaceFilters::optimize(filters);
123 EXPECT_EQ(1u, optimized.size());
125 filters.append(combines);
126 optimized = RenderSurfaceFilters::optimize(filters);
127 EXPECT_EQ(2u, optimized.size());
129 filters.append(doesntCombine);
130 optimized = RenderSurfaceFilters::optimize(filters);
131 EXPECT_EQ(2u, optimized.size());
133 filters.append(doesntCombine);
134 optimized = RenderSurfaceFilters::optimize(filters);
135 EXPECT_EQ(3u, optimized.size());
138 } // namespace
139 } // namespace cc