Commit 43889311 authored by ed's avatar ed Committed by Commit bot

Implement mix-blend-mode=screen using glBlendFunc.

This avoids creating a temporary texture for the blending step, and
if there's no background filter also avoids creating the backdrop texture.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#297385}
parent 053089cc
......@@ -701,6 +701,23 @@ static skia::RefPtr<SkImage> ApplyImageFilter(
return image;
}
bool GLRenderer::ShouldApplyBlendModeUsingBlendFunc(const DrawQuad* quad) {
SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode;
return blend_mode == SkXfermode::kScreen_Mode ||
blend_mode == SkXfermode::kSrcOver_Mode;
}
void GLRenderer::ApplyBlendModeUsingBlendFunc(const DrawQuad* quad) {
DCHECK(ShouldApplyBlendModeUsingBlendFunc(quad));
if (quad->shared_quad_state->blend_mode == SkXfermode::kScreen_Mode) {
GLC(gl_, gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE));
}
}
void GLRenderer::RestoreBlendFuncToDefault() {
GLC(gl_, gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
}
static skia::RefPtr<SkImage> ApplyBlendModeWithBackdrop(
scoped_ptr<GLRenderer::ScopedUseGrContext> use_gr_context,
ResourceProvider* resource_provider,
......@@ -974,7 +991,8 @@ scoped_ptr<ScopedResource> GLRenderer::GetBackgroundWithFilters(
void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
const RenderPassDrawQuad* quad) {
SetBlendEnabled(quad->ShouldDrawWithBlending());
SetBlendEnabled(quad->ShouldDrawWithBlending() ||
ShouldApplyBlendModeUsingBlendFunc(quad));
ScopedResource* contents_texture =
render_pass_textures_.get(quad->render_pass_id);
......@@ -993,9 +1011,8 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
if (!contents_device_transform.GetInverse(&contents_device_transform_inverse))
return;
bool need_background_texture =
quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode ||
!quad->background_filters.IsEmpty();
bool need_background_texture = !ShouldApplyBlendModeUsingBlendFunc(quad) ||
!quad->background_filters.IsEmpty();
bool background_changed = false;
scoped_ptr<ScopedResource> background_texture;
if (need_background_texture) {
......@@ -1049,8 +1066,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
}
}
if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode &&
background_texture) {
if (background_texture && !ShouldApplyBlendModeUsingBlendFunc(quad)) {
filter_bitmap =
ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame),
resource_provider_,
......@@ -1118,6 +1134,9 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
contents_resource_lock->target());
}
if (ShouldApplyBlendModeUsingBlendFunc(quad))
ApplyBlendModeUsingBlendFunc(quad);
TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
gl_,
&highp_threshold_cache_,
......@@ -1364,6 +1383,9 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
// scope, so the draw gets processed before the filter texture gets deleted.
if (filter_bitmap)
GLC(gl_, gl_->Flush());
if (ShouldApplyBlendModeUsingBlendFunc(quad))
RestoreBlendFuncToDefault();
}
struct SolidColorProgramUniforms {
......
......@@ -143,6 +143,9 @@ class CC_EXPORT GLRenderer : public DirectRenderer {
const CheckerboardDrawQuad* quad);
void DrawDebugBorderQuad(const DrawingFrame* frame,
const DebugBorderDrawQuad* quad);
static bool ShouldApplyBlendModeUsingBlendFunc(const DrawQuad* quad);
void ApplyBlendModeUsingBlendFunc(const DrawQuad* quad);
void RestoreBlendFuncToDefault();
scoped_ptr<ScopedResource> GetBackgroundWithFilters(
DrawingFrame* frame,
const RenderPassDrawQuad* quad,
......
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