Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 "cc/layers/solid_color_layer.h" | |
| 6 #include "cc/layers/texture_layer.h" | |
| 7 #include "cc/test/layer_tree_pixel_test.h" | |
| 8 | |
| 9 #if !defined(OS_ANDROID) | |
| 10 | |
| 11 namespace cc { | |
| 12 namespace { | |
| 13 | |
| 14 class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {}; | |
| 15 | |
| 16 SkXfermode::Mode const blend_modes[] = { | |
|
danakj
2013/11/13 21:02:03
style: compile-time constants should be kBlendMode
rosca
2013/11/14 21:56:34
Done.
| |
| 17 SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode, | |
| 18 SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode, | |
| 19 SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode, | |
| 20 SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode, | |
| 21 SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode, | |
| 22 SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode, | |
| 23 SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode, | |
| 24 SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode}; | |
| 25 | |
| 26 const int kBlendModesCount = arraysize(blend_modes); | |
| 27 | |
| 28 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot) { | |
| 29 const int lane_width = 15; | |
|
danakj
2013/11/13 21:02:03
style: compile-time constants should be kLaneWidth
rosca
2013/11/14 21:56:34
Done.
| |
| 30 const int lane_height = kBlendModesCount * lane_width; | |
| 31 const int root_size = (kBlendModesCount + 2) * lane_width; | |
| 32 | |
| 33 scoped_refptr<SolidColorLayer> background = | |
| 34 CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange); | |
| 35 | |
| 36 // Orange child layers will blend with the green background | |
| 37 for (int i = 0; i < kBlendModesCount; ++i) { | |
| 38 gfx::Rect child_rect( | |
| 39 (i + 1) * lane_width, lane_width, lane_width, lane_height); | |
| 40 scoped_refptr<SolidColorLayer> orange = | |
| 41 CreateSolidColorLayer(child_rect, kCSSGreen); | |
| 42 background->AddChild(orange); | |
| 43 orange->SetBlendMode(blend_modes[i]); | |
| 44 } | |
| 45 | |
| 46 RunPixelTest(GL_WITH_BITMAP, | |
| 47 background, | |
| 48 base::FilePath(FILE_PATH_LITERAL("blending_with_root.png"))); | |
| 49 } | |
| 50 | |
| 51 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) { | |
| 52 const int lane_width = 15; | |
| 53 const int lane_height = kBlendModesCount * lane_width; | |
| 54 const int root_size = (kBlendModesCount + 2) * lane_width; | |
| 55 | |
| 56 scoped_refptr<SolidColorLayer> background = | |
| 57 CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange); | |
| 58 | |
| 59 // Orange child layers have a background filter set and they will blend with | |
| 60 // the green background | |
| 61 for (int i = 0; i < kBlendModesCount; ++i) { | |
| 62 gfx::Rect child_rect( | |
| 63 (i + 1) * lane_width, lane_width, lane_width, lane_height); | |
| 64 scoped_refptr<SolidColorLayer> orange = | |
| 65 CreateSolidColorLayer(child_rect, kCSSGreen); | |
| 66 background->AddChild(orange); | |
| 67 | |
| 68 FilterOperations filters; | |
| 69 filters.Append(FilterOperation::CreateGrayscaleFilter(.75)); | |
| 70 orange->SetBackgroundFilters(filters); | |
| 71 orange->SetBlendMode(blend_modes[i]); | |
| 72 } | |
| 73 | |
| 74 RunPixelTest(GL_WITH_BITMAP, | |
| 75 background, | |
| 76 base::FilePath(FILE_PATH_LITERAL("blending_and_filter.png"))); | |
| 77 } | |
| 78 | |
| 79 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent) { | |
| 80 const int lane_width = 15; | |
| 81 const int lane_height = kBlendModesCount * lane_width; | |
| 82 const int root_size = (kBlendModesCount + 2) * lane_width; | |
| 83 | |
| 84 scoped_refptr<SolidColorLayer> root = | |
| 85 CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSBrown); | |
| 86 | |
| 87 SkBitmap bitmap; | |
| 88 bitmap.setConfig(SkBitmap::kARGB_8888_Config, root_size, root_size); | |
| 89 bitmap.allocPixels(); | |
| 90 SkCanvas canvas(bitmap); | |
| 91 | |
| 92 SkPaint paint; | |
| 93 paint.setColor(SK_ColorRED); | |
| 94 canvas.clear(SK_ColorTRANSPARENT); | |
| 95 gfx::Rect red_lane_quad(0, lane_width * 2, root_size, lane_width); | |
| 96 canvas.drawRect(SkRect::MakeXYWH(0, lane_width * 2, root_size, lane_width), | |
| 97 paint); | |
| 98 | |
| 99 scoped_refptr<TextureLayer> background = | |
| 100 CreateTextureLayer(gfx::Rect(root_size, root_size), bitmap); | |
| 101 root->AddChild(background); | |
| 102 background->SetIsRootForIsolatedGroup(true); | |
| 103 | |
| 104 // Orange child layers will blend with the green background | |
| 105 for (int i = 0; i < kBlendModesCount; ++i) { | |
| 106 gfx::Rect child_rect( | |
| 107 (i + 1) * lane_width, lane_width, lane_width, lane_height); | |
| 108 scoped_refptr<SolidColorLayer> orange = | |
| 109 CreateSolidColorLayer(child_rect, kCSSGreen); | |
| 110 background->AddChild(orange); | |
| 111 orange->SetBlendMode(blend_modes[i]); | |
| 112 } | |
| 113 | |
| 114 RunPixelTest(GL_WITH_BITMAP, | |
| 115 root, | |
| 116 base::FilePath(FILE_PATH_LITERAL("blending_transparent.png"))); | |
| 117 } | |
| 118 | |
| 119 } // namespace | |
| 120 } // namespace cc | |
| 121 | |
| 122 #endif // OS_ANDROID | |
| OLD | NEW |