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

Unified Diff: cc/output/gl_renderer.cc

Issue 608523003: Implement mix-blend-mode=screen using glBlendFunc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/gl_renderer.cc
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index 6bb6f439ed849eb831c38c3287eaa776d4160f6d..fa4bef494fea9e7f104a8db3681c688af7c5c4c6 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -700,6 +700,41 @@ static skia::RefPtr<SkImage> ApplyImageFilter(
return image;
}
+bool GLRenderer::ShouldApplyBackgroundFilters(DrawingFrame* frame,
enne (OOO) 2014/09/26 18:20:36 How is this related to this change?
Erik Dahlström (inactive) 2014/09/29 08:33:41 You're right, it's not really related, I'll drop t
+ const RenderPassDrawQuad* quad) {
+ if (quad->background_filters.IsEmpty())
+ return false;
+
+ // TODO(danakj): We only allow background filters on an opaque render surface
+ // because other surfaces may contain translucent pixels, and the contents
+ // behind those translucent pixels wouldn't have the filter applied.
+ if (frame->current_render_pass->has_transparent_background)
+ return false;
+
+ // TODO(ajuma): Add support for reference filters once
+ // FilterOperations::GetOutsets supports reference filters.
+ if (quad->background_filters.HasReferenceFilter())
+ return false;
+ return true;
+}
+
+bool GLRenderer::ShouldApplyBlendModeUsingBlendFunc(const DrawQuad* quad) {
+ SkXfermode::Mode blend_mode = quad->shared_quad_state->blend_mode;
+ return blend_mode == SkXfermode::kScreen_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(const DrawQuad* quad) {
+ DCHECK(ShouldApplyBlendModeUsingBlendFunc(quad));
+ 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,
@@ -973,7 +1008,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,8 +1029,9 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
return;
bool need_background_texture =
- quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode ||
- !quad->background_filters.IsEmpty();
+ (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode &&
+ !ShouldApplyBlendModeUsingBlendFunc(quad)) ||
enne (OOO) 2014/09/26 18:20:36 Could you combine ShouldApplyBlendModeUsingBlendFu
Erik Dahlström (inactive) 2014/09/29 08:33:41 Done.
+ ShouldApplyBackgroundFilters(frame, quad);
bool background_changed = false;
scoped_ptr<ScopedResource> background_texture;
if (need_background_texture) {
@@ -1049,7 +1086,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
}
if (quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode &&
- background_texture) {
+ background_texture && !ShouldApplyBlendModeUsingBlendFunc(quad)) {
filter_bitmap =
ApplyBlendModeWithBackdrop(ScopedUseGrContext::Create(this, frame),
resource_provider_,
@@ -1117,6 +1154,9 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
contents_resource_lock->target());
}
+ if (ShouldApplyBlendModeUsingBlendFunc(quad))
+ ApplyBlendModeUsingBlendFunc(quad);
+
TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
gl_,
&highp_threshold_cache_,
@@ -1363,6 +1403,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(quad);
}
struct SolidColorProgramUniforms {
« no previous file with comments | « cc/output/gl_renderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698