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

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: really remove quad argument this time... 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..54c328525098404fbe90274046b0ffaff836e43e 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -700,6 +700,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,
@@ -973,7 +990,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);
@@ -992,9 +1010,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) {
@@ -1048,8 +1065,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_,
@@ -1117,6 +1133,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 +1382,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 {
« 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