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

Unified Diff: cc/trees/layer_tree_host_pixeltest_blending.cc

Issue 23455060: mix-blend-mode implementation for accelerated layers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_pixeltest_blending.cc
diff --git a/cc/trees/layer_tree_host_pixeltest_blending.cc b/cc/trees/layer_tree_host_pixeltest_blending.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4af5c19127add30ce9057e5d83173db85cb570ba
--- /dev/null
+++ b/cc/trees/layer_tree_host_pixeltest_blending.cc
@@ -0,0 +1,122 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/layers/solid_color_layer.h"
+#include "cc/layers/texture_layer.h"
+#include "cc/test/layer_tree_pixel_test.h"
+
+#if !defined(OS_ANDROID)
+
+namespace cc {
+namespace {
+
+class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {};
+
+SkXfermode::Mode const blend_modes[] = {
+ SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode,
+ SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode,
+ SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode,
+ SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode,
+ SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode,
+ SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode,
+ SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode,
+ SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode};
+
+const int kBlendModesCount = arraysize(blend_modes);
+
+TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot) {
+ const int lane_width = 15;
+ const int lane_height = kBlendModesCount * lane_width;
+ const int root_size = (kBlendModesCount + 2) * lane_width;
+
+ scoped_refptr<SolidColorLayer> background =
+ CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange);
+
+ // Orange child layers will blend with the green background
+ for (int i = 0; i < kBlendModesCount; ++i) {
+ gfx::Rect child_rect(
+ (i + 1) * lane_width, lane_width, lane_width, lane_height);
+ scoped_refptr<SolidColorLayer> orange =
+ CreateSolidColorLayer(child_rect, kCSSGreen);
+ background->AddChild(orange);
+ orange->SetBlendMode(blend_modes[i]);
+ }
+
+ RunPixelTest(GL_WITH_BITMAP,
enne (OOO) 2013/11/04 22:38:16 I'm assuming that you will add cc::SoftwareRendere
enne (OOO) 2013/11/04 23:24:36 I filed http://crbug.com/314865 and http://crbug.c
rosca 2013/11/05 19:14:09 Thanks for filing these bugs. We plan to add funct
+ background,
+ base::FilePath(FILE_PATH_LITERAL("blending_with_root.png")));
+}
+
+TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) {
+ const int lane_width = 15;
+ const int lane_height = kBlendModesCount * lane_width;
+ const int root_size = (kBlendModesCount + 2) * lane_width;
+
+ scoped_refptr<SolidColorLayer> background =
+ CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange);
+
+ // Orange child layers have a background filter set and they will blend with
+ // the green background
+ for (int i = 0; i < kBlendModesCount; ++i) {
+ gfx::Rect child_rect(
+ (i + 1) * lane_width, lane_width, lane_width, lane_height);
+ scoped_refptr<SolidColorLayer> orange =
+ CreateSolidColorLayer(child_rect, kCSSGreen);
+ background->AddChild(orange);
+
+ FilterOperations filters;
+ filters.Append(FilterOperation::CreateGrayscaleFilter(.75));
+ orange->SetBackgroundFilters(filters);
+ orange->SetBlendMode(blend_modes[i]);
+ }
+
+ RunPixelTest(GL_WITH_BITMAP,
+ background,
+ base::FilePath(FILE_PATH_LITERAL("blending_and_filter.png")));
+}
+
+TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent) {
+ const int lane_width = 15;
+ const int lane_height = kBlendModesCount * lane_width;
+ const int root_size = (kBlendModesCount + 2) * lane_width;
+
+ scoped_refptr<SolidColorLayer> root =
+ CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSBrown);
+
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, root_size, root_size);
+ bitmap.allocPixels();
+ SkCanvas canvas(bitmap);
+
+ SkPaint paint;
+ paint.setColor(SK_ColorRED);
+ canvas.clear(SK_ColorTRANSPARENT);
+ gfx::Rect red_lane_quad(0, lane_width * 2, root_size, lane_width);
+ canvas.drawRect(SkRect::MakeXYWH(0, lane_width * 2, root_size, lane_width),
+ paint);
+
+ scoped_refptr<TextureLayer> background =
+ CreateTextureLayer(gfx::Rect(root_size, root_size), bitmap);
+ root->AddChild(background);
+ background->SetIsRootForIsolatedGroup(true);
+
+ // Orange child layers will blend with the green background
+ for (int i = 0; i < kBlendModesCount; ++i) {
+ gfx::Rect child_rect(
+ (i + 1) * lane_width, lane_width, lane_width, lane_height);
+ scoped_refptr<SolidColorLayer> orange =
+ CreateSolidColorLayer(child_rect, kCSSGreen);
+ background->AddChild(orange);
+ orange->SetBlendMode(blend_modes[i]);
+ }
+
+ RunPixelTest(GL_WITH_BITMAP,
+ root,
+ base::FilePath(FILE_PATH_LITERAL("blending_transparent.png")));
+}
+
+} // namespace
+} // namespace cc
+
+#endif // OS_ANDROID

Powered by Google App Engine
This is Rietveld 408576698