Commit 668b9493 authored by Weiliang Chen's avatar Weiliang Chen Committed by Commit Bot

SkiaRenderer: Apply Render Pass Opacity Last

RenderPass's opacity need to be applied as last step. This is for
refection filter case where we expect the opacity to be applied to the
combination of original and reflected content. This is done by applying
the opacity as a color filter.

Bug: 908951
Test: layout tests compositing/reflections/reflection-opacity.html
Change-Id: I84226726b6cae0e294d6409d3e8e93f38648c867
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1534140Reviewed-by: default avatarJonathan Ross <jonross@chromium.org>
Commit-Queue: weiliangc <weiliangc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644476}
parent 2d20abc2
......@@ -45,6 +45,7 @@
#include "third_party/skia/include/core/SkPixelRef.h"
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
#include "third_party/skia/include/effects/SkOverdrawColorFilter.h"
#include "third_party/skia/include/effects/SkShaderMaskFilter.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
......@@ -1128,7 +1129,7 @@ void SkiaRenderer::DrawStreamVideoQuad(const StreamVideoDrawQuad* quad,
uv_rect, gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect));
SkRect sk_uv_rect = gfx::RectFToSkRect(visible_uv_rect);
SkRect quad_rect = gfx::RectToSkRect(quad->visible_rect);
// TODO: figure out how to set correct filter quality.
// TODO(vikassoni): figure out how to set correct filter quality.
paint->setFilterQuality(kLow_SkFilterQuality);
current_canvas_->drawImageRect(image, sk_uv_rect, quad_rect, paint);
}
......@@ -1228,6 +1229,17 @@ bool SkiaRenderer::CalculateRPDQParams(sk_sp<SkImage> content,
}
}
// If we need to apply filter, apply opacity as the last step of image filter
// so it is uniform across.
if (filter && quad->shared_quad_state->opacity != 1.f) {
SkColor alpha_as_color =
SkColor4f({1.f, 1.f, 1.f, quad->shared_quad_state->opacity})
.toSkColor();
sk_sp<SkColorFilter> cf =
SkColorFilter::MakeModeFilter(alpha_as_color, SkBlendMode::kDstIn);
filter = SkColorFilterImageFilter::Make(cf, filter);
}
// If after applying the filter we would be clipped out, skip the draw.
if (filter) {
gfx::Rect clip_rect = quad->shared_quad_state->clip_rect;
......@@ -1329,6 +1341,12 @@ void SkiaRenderer::DrawRenderPassQuadInternal(const RenderPassDrawQuad* quad,
if (params.image_filter)
paint->setImageFilter(params.image_filter);
// If this render pass has filter, reset paint to opaque. Render Pass should
// apply their opacity as last step, this is done by using a color filter.
// This is required for reflector filter.
if (params.image_filter)
paint->setAlpha(255);
SkRect content_rect = RectFToSkRect(quad->tex_coord_rect);
SkRect dest_visible_rect = gfx::RectToSkRect(quad->visible_rect);
......
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