Index: ui/compositor/layer_unittest.cc |
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc |
index e44f0e4908db73e92cd666d8c0908fcd1e7f2878..ab867b8e587f11089ee35fa86a859a83e31f681e 100644 |
--- a/ui/compositor/layer_unittest.cc |
+++ b/ui/compositor/layer_unittest.cc |
@@ -36,6 +36,10 @@ |
#include "ui/gfx/gfx_paths.h" |
#include "ui/gfx/skia_util.h" |
+#if defined(OS_WIN) |
+#include "ui/base/win/shell.h" |
+#endif |
+ |
using cc::MatchesPNGFile; |
namespace ui { |
@@ -885,6 +889,78 @@ TEST_F(LayerWithRealCompositorTest, DrawPixels) { |
} |
} |
+// Checks that pixels are actually drawn to the screen with a read back. |
danakj
2014/08/25 17:17:37
This test is checking something about filters, not
garykac
2014/08/26 01:44:38
Done.
|
+TEST_F(LayerWithRealCompositorTest, DrawAlphaThresholdFilterPixels) { |
+ gfx::Size viewport_size = GetCompositor()->size(); |
+ |
+ // The window should be some non-trivial size but may not be exactly |
danakj
2014/08/25 17:17:37
drop this copy pasta
garykac
2014/08/26 01:44:38
Done.
|
+ // 500x500 on all platforms/bots. |
+ int test_size = 200; |
+ EXPECT_GE(viewport_size.width(), test_size); |
+ EXPECT_GE(viewport_size.height(), test_size); |
+ |
+ int blue_height = 10; |
+ // Blue with a wee bit of transparency. |
+ SkColor bluish = SkColorSetARGBInline(40, 0, 0, 255); |
+ |
+ bool alpha_blend = false; |
+#if defined(USE_AURA) && !defined(OS_CHROMEOS) |
danakj
2014/08/25 17:17:37
use_aura is always true in this test file, no?
danakj
2014/08/25 17:17:37
why is alpha_blend false on chromeos?
garykac
2014/08/26 01:44:38
I would have loved for that to have been true, but
garykac
2014/08/26 01:44:38
Because the CrOS bots apparently don't alpha blend
|
+ alpha_blend = true; |
+#if defined(OS_WIN) |
+ if (!ui::win::IsAeroGlassEnabled()) { |
danakj
2014/08/25 17:17:37
what does aero glass have to do with the composito
garykac
2014/08/26 01:44:38
https://code.google.com/p/chromium/codesearch#chro
|
+ alpha_blend = false; |
+ } |
+#endif // OS_WIN |
+#endif // USE_AURA && SK_SUPPORT_GPU |
danakj
2014/08/25 17:17:37
this comment does not match your #if
garykac
2014/08/26 01:44:38
Done.
|
+ |
+ SkColor blue_over_red; |
+ if (alpha_blend) { |
+ // Transparent blue blended with red. |
+ blue_over_red = SkColorSetARGBInline(255, 143, 143, 183); |
+ } else { |
+ // Transparent blue overwriting lower layer. |
+ blue_over_red = SkColorSetARGBInline(255, 0, 0, 40); |
+ } |
+ |
+ scoped_ptr<Layer> layer( |
+ CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); |
+ scoped_ptr<Layer> layer2( |
+ CreateColorLayer(bluish, gfx::Rect(viewport_size))); |
+ |
+ SkRegion shape; |
+ shape.setRect(0, 0, viewport_size.width(), blue_height); |
+ layer2->SetAlphaShape(make_scoped_ptr(new SkRegion(shape))); |
+ |
+ layer->Add(layer2.get()); |
+ |
+ DrawTree(layer.get()); |
+ |
+ SkBitmap bitmap; |
+ ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size))); |
+ ASSERT_FALSE(bitmap.empty()); |
+ |
+ SkAutoLockPixels lock(bitmap); |
+ // Ignore the edge pixels since the blending can vary on some platforms. |
+ for (int x = 1; x < test_size; x++) { |
+ for (int y = 1; y < test_size; y++) { |
+ SkColor actual_color = bitmap.getColor(x, y); |
+ SkColor expected_color = y < blue_height ? blue_over_red : SK_ColorRED; |
+ EXPECT_EQ(expected_color, actual_color) |
+ << "Pixel error at x=" << x << " y=" << y << "; " |
+ << "actual RGBA=(" |
+ << SkColorGetR(actual_color) << "," |
+ << SkColorGetG(actual_color) << "," |
+ << SkColorGetB(actual_color) << "," |
+ << SkColorGetA(actual_color) << "); " |
+ << "expected RGBA=(" |
+ << SkColorGetR(expected_color) << "," |
+ << SkColorGetG(expected_color) << "," |
+ << SkColorGetB(expected_color) << "," |
+ << SkColorGetA(expected_color) << ")"; |
+ } |
+ } |
+} |
+ |
// Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. |
TEST_F(LayerWithRealCompositorTest, SetRootLayer) { |
Compositor* compositor = GetCompositor(); |