Commit 50f0dca8 authored by rosca's avatar rosca Committed by Commit bot

Adding support for blending in cc::SoftwareRenderer

GLRenderer already can handle blend modes, so it should be handled for
SoftwareRenderer too.
Blending layers get their own rendering surface for the time being,
so blending should be applied only on render pass quads.

BUG=314865

Review URL: https://codereview.chromium.org/532003003

Cr-Commit-Position: refs/heads/master@{#293972}
parent 86f0ea2e
......@@ -161,13 +161,6 @@ typedef ::testing::Types<GLRenderer,
SoftwareRendererWithExpandedViewport> RendererTypes;
TYPED_TEST_CASE(RendererPixelTest, RendererTypes);
// All pixels can be off by one, but any more than that is an error.
class FuzzyPixelOffByOneComparator : public FuzzyPixelComparator {
public:
explicit FuzzyPixelOffByOneComparator(bool discard_alpha)
: FuzzyPixelComparator(discard_alpha, 100.f, 0.f, 1.f, 1, 0) {}
};
template <typename RendererType>
class FuzzyForSoftwareOnlyPixelComparator : public PixelComparator {
public:
......
......@@ -254,9 +254,10 @@ void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) {
current_paint_.setFilterLevel(SkPaint::kLow_FilterLevel);
}
if (quad->ShouldDrawWithBlending()) {
if (quad->ShouldDrawWithBlending() ||
quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode) {
current_paint_.setAlpha(quad->opacity() * 255);
current_paint_.setXfermodeMode(SkXfermode::kSrcOver_Mode);
current_paint_.setXfermodeMode(quad->shared_quad_state->blend_mode);
} else {
current_paint_.setXfermodeMode(SkXfermode::kSrc_Mode);
}
......@@ -545,7 +546,7 @@ void SoftwareRenderer::DrawRenderPassQuad(const DrawingFrame* frame,
current_paint_.setRasterizer(mask_rasterizer.get());
current_canvas_->drawRect(dest_visible_rect, current_paint_);
} else {
// TODO(skaslev): Apply background filters and blend with content
// TODO(skaslev): Apply background filters
current_canvas_->drawRect(dest_visible_rect, current_paint_);
}
}
......
......@@ -69,6 +69,13 @@ class FuzzyPixelComparator : public PixelComparator {
int small_error_threshold_;
};
// All pixels can be off by one, but any more than that is an error.
class FuzzyPixelOffByOneComparator : public FuzzyPixelComparator {
public:
explicit FuzzyPixelOffByOneComparator(bool discard_alpha)
: FuzzyPixelComparator(discard_alpha, 100.f, 0.f, 1.f, 1, 0) {}
};
} // namespace cc
#endif // CC_TEST_PIXEL_COMPARATOR_H_
......@@ -5,6 +5,7 @@
#include "cc/layers/solid_color_layer.h"
#include "cc/layers/texture_layer.h"
#include "cc/test/layer_tree_pixel_test.h"
#include "cc/test/pixel_comparator.h"
#if !defined(OS_ANDROID)
......@@ -24,6 +25,11 @@ SkXfermode::Mode const kBlendModes[] = {
const int kBlendModesCount = arraysize(kBlendModes);
class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {
public:
LayerTreeHostBlendingPixelTest() {
pixel_comparator_.reset(new FuzzyPixelOffByOneComparator(true));
}
protected:
void RunBlendingWithRootPixelTestType(PixelTestType type) {
const int kLaneWidth = 15;
......@@ -82,6 +88,10 @@ TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_GL) {
RunBlendingWithRootPixelTestType(GL_WITH_BITMAP);
}
TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_Software) {
RunBlendingWithRootPixelTestType(SOFTWARE_WITH_BITMAP);
}
TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) {
const int kLaneWidth = 15;
const int kLaneHeight = kBlendModesCount * kLaneWidth;
......@@ -114,6 +124,10 @@ TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_GL) {
RunBlendingWithTransparentPixelTestType(GL_WITH_BITMAP);
}
TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_Software) {
RunBlendingWithTransparentPixelTestType(SOFTWARE_WITH_BITMAP);
}
} // namespace
} // namespace cc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment