Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 499503002: Respect window transparency when applying window shape. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-add AeroGlass checks for Windows Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/compositor/layer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 18 matching lines...) Expand all
29 #include "ui/compositor/layer_animator.h" 29 #include "ui/compositor/layer_animator.h"
30 #include "ui/compositor/test/context_factories_for_test.h" 30 #include "ui/compositor/test/context_factories_for_test.h"
31 #include "ui/compositor/test/draw_waiter_for_test.h" 31 #include "ui/compositor/test/draw_waiter_for_test.h"
32 #include "ui/compositor/test/test_compositor_host.h" 32 #include "ui/compositor/test/test_compositor_host.h"
33 #include "ui/compositor/test/test_layers.h" 33 #include "ui/compositor/test/test_layers.h"
34 #include "ui/gfx/canvas.h" 34 #include "ui/gfx/canvas.h"
35 #include "ui/gfx/codec/png_codec.h" 35 #include "ui/gfx/codec/png_codec.h"
36 #include "ui/gfx/gfx_paths.h" 36 #include "ui/gfx/gfx_paths.h"
37 #include "ui/gfx/skia_util.h" 37 #include "ui/gfx/skia_util.h"
38 38
39 #if defined(OS_WIN)
40 #include "ui/base/win/shell.h"
41 #endif
42
39 using cc::MatchesPNGFile; 43 using cc::MatchesPNGFile;
40 44
41 namespace ui { 45 namespace ui {
42 46
43 namespace { 47 namespace {
44 48
45 // There are three test classes in here that configure the Compositor and 49 // There are three test classes in here that configure the Compositor and
46 // Layer's slightly differently: 50 // Layer's slightly differently:
47 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This 51 // - LayerWithNullDelegateTest uses NullLayerDelegate as the LayerDelegate. This
48 // is typically the base class you want to use. 52 // is typically the base class you want to use.
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 << SkColorGetA(actual_color) << "); " 882 << SkColorGetA(actual_color) << "); "
879 << "expected RGBA=(" 883 << "expected RGBA=("
880 << SkColorGetR(expected_color) << "," 884 << SkColorGetR(expected_color) << ","
881 << SkColorGetG(expected_color) << "," 885 << SkColorGetG(expected_color) << ","
882 << SkColorGetB(expected_color) << "," 886 << SkColorGetB(expected_color) << ","
883 << SkColorGetA(expected_color) << ")"; 887 << SkColorGetA(expected_color) << ")";
884 } 888 }
885 } 889 }
886 } 890 }
887 891
892 // Checks that using the AlphaShape filter applied to a layer with
893 // transparency, alpha-blends properly with the layer below.
894 TEST_F(LayerWithRealCompositorTest, DrawAlphaThresholdFilterPixels) {
895 gfx::Size viewport_size = GetCompositor()->size();
896
897 int test_size = 200;
898 EXPECT_GE(viewport_size.width(), test_size);
899 EXPECT_GE(viewport_size.height(), test_size);
900
901 int blue_height = 10;
902 // Blue with a wee bit of transparency.
903 SkColor bluish = SkColorSetARGBInline(40, 0, 0, 255);
Wez 2014/08/26 01:53:39 nit: translucent_blue?
904
905 bool alpha_blend = false;
Wez 2014/08/26 01:53:39 expect_alpha_blend?
garykac 2014/09/02 19:27:06 Done.
906 #if defined(USE_AURA) && !defined(OS_CHROMEOS)
907 alpha_blend = true;
908 #if defined(OS_WIN)
909 if (!ui::win::IsAeroGlassEnabled()) {
Wez 2014/08/26 01:53:39 Do we need a similar test for Linux Aura, since we
910 alpha_blend = false;
911 }
912 #endif // OS_WIN
913 #endif // USE_AURA && !OS_CHROMEOS
914
915 SkColor blue_over_red;
916 if (alpha_blend) {
917 // Transparent blue blended with red.
918 blue_over_red = SkColorSetARGBInline(255, 143, 143, 183);
919 } else {
920 // Transparent blue overwriting lower layer.
Wez 2014/08/26 01:53:38 This is confusingly worded.
921 blue_over_red = SkColorSetARGBInline(255, 0, 0, 40);
922 }
923
924 scoped_ptr<Layer> layer(
Wez 2014/08/26 01:53:39 layer1, or background_layer
garykac 2014/09/02 19:27:07 Done.
925 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size)));
926 scoped_ptr<Layer> layer2(
Wez 2014/08/26 01:53:38 or blue_layer or foreground_layer
garykac 2014/09/02 19:27:06 Done.
927 CreateColorLayer(bluish, gfx::Rect(viewport_size)));
928
929 SkRegion shape;
930 shape.setRect(0, 0, viewport_size.width(), blue_height);
931 layer2->SetAlphaShape(make_scoped_ptr(new SkRegion(shape)));
932
933 layer->Add(layer2.get());
934
935 DrawTree(layer.get());
936
937 SkBitmap bitmap;
938 ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size)));
939 ASSERT_FALSE(bitmap.empty());
940
941 SkAutoLockPixels lock(bitmap);
942 // Ignore the edge pixels since the blending can vary on some platforms.
Wez 2014/08/26 01:53:39 This only seems to ignore the top-most and left-mo
garykac 2014/09/02 19:27:06 The test size is much smaller than the window, so
943 for (int x = 1; x < test_size; x++) {
944 for (int y = 1; y < test_size; y++) {
945 SkColor actual_color = bitmap.getColor(x, y);
946 SkColor expected_color = y < blue_height ? blue_over_red : SK_ColorRED;
947 EXPECT_EQ(expected_color, actual_color)
948 << "Pixel error at x=" << x << " y=" << y << "; "
949 << "actual RGBA=("
950 << SkColorGetR(actual_color) << ","
951 << SkColorGetG(actual_color) << ","
952 << SkColorGetB(actual_color) << ","
953 << SkColorGetA(actual_color) << "); "
954 << "expected RGBA=("
955 << SkColorGetR(expected_color) << ","
956 << SkColorGetG(expected_color) << ","
957 << SkColorGetB(expected_color) << ","
958 << SkColorGetA(expected_color) << ")";
959 }
960 }
961 }
962
888 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. 963 // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor.
889 TEST_F(LayerWithRealCompositorTest, SetRootLayer) { 964 TEST_F(LayerWithRealCompositorTest, SetRootLayer) {
890 Compositor* compositor = GetCompositor(); 965 Compositor* compositor = GetCompositor();
891 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 966 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
892 gfx::Rect(20, 20, 400, 400))); 967 gfx::Rect(20, 20, 400, 400)));
893 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, 968 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
894 gfx::Rect(10, 10, 350, 350))); 969 gfx::Rect(10, 10, 350, 350)));
895 970
896 EXPECT_EQ(NULL, l1->GetCompositor()); 971 EXPECT_EQ(NULL, l1->GetCompositor());
897 EXPECT_EQ(NULL, l2->GetCompositor()); 972 EXPECT_EQ(NULL, l2->GetCompositor());
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 1660
1586 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); 1661 c11->SetBounds(gfx::Rect(2, 2, 10, 10));
1587 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); 1662 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get());
1588 // c11 is now off the pixel. 1663 // c11 is now off the pixel.
1589 // 0.5 / 1.5 = 0.333... 1664 // 0.5 / 1.5 = 0.333...
1590 EXPECT_EQ("0.33 0.33", 1665 EXPECT_EQ("0.33 0.33",
1591 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); 1666 Vector2dFTo100thPercisionString(c11->subpixel_position_offset()));
1592 } 1667 }
1593 1668
1594 } // namespace ui 1669 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698