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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 2936343002: Add support to GLRenderer for different blending for solid color quads (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | cc/output/renderer_pixeltest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 blend_mode == SkBlendMode::kDstIn || 704 blend_mode == SkBlendMode::kDstIn ||
705 blend_mode == SkBlendMode::kScreen; 705 blend_mode == SkBlendMode::kScreen;
706 } 706 }
707 707
708 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) { 708 void GLRenderer::ApplyBlendModeUsingBlendFunc(SkBlendMode blend_mode) {
709 // Any modes set here must be reset in RestoreBlendFuncToDefault 709 // Any modes set here must be reset in RestoreBlendFuncToDefault
710 if (blend_mode == SkBlendMode::kSrcOver) { 710 if (blend_mode == SkBlendMode::kSrcOver) {
711 // Left no-op intentionally. 711 // Left no-op intentionally.
712 } else if (blend_mode == SkBlendMode::kDstIn) { 712 } else if (blend_mode == SkBlendMode::kDstIn) {
713 gl_->BlendFunc(GL_ZERO, GL_SRC_ALPHA); 713 gl_->BlendFunc(GL_ZERO, GL_SRC_ALPHA);
714 } else if (blend_mode == SkBlendMode::kDstOut) {
715 gl_->BlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
714 } else if (blend_mode == SkBlendMode::kScreen) { 716 } else if (blend_mode == SkBlendMode::kScreen) {
715 gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); 717 gl_->BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
716 } else { 718 } else {
717 DCHECK(use_blend_equation_advanced_); 719 DCHECK(use_blend_equation_advanced_);
718 GLenum equation = GL_FUNC_ADD; 720 GLenum equation = GL_FUNC_ADD;
719 switch (blend_mode) { 721 switch (blend_mode) {
720 case SkBlendMode::kScreen: 722 case SkBlendMode::kScreen:
721 equation = GL_SCREEN_KHR; 723 equation = GL_SCREEN_KHR;
722 break; 724 break;
723 case SkBlendMode::kOverlay: 725 case SkBlendMode::kOverlay:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 771 }
770 gl_->BlendEquation(equation); 772 gl_->BlendEquation(equation);
771 } 773 }
772 } 774 }
773 775
774 void GLRenderer::RestoreBlendFuncToDefault(SkBlendMode blend_mode) { 776 void GLRenderer::RestoreBlendFuncToDefault(SkBlendMode blend_mode) {
775 switch (blend_mode) { 777 switch (blend_mode) {
776 case SkBlendMode::kSrcOver: 778 case SkBlendMode::kSrcOver:
777 break; 779 break;
778 case SkBlendMode::kDstIn: 780 case SkBlendMode::kDstIn:
781 case SkBlendMode::kDstOut:
779 case SkBlendMode::kScreen: 782 case SkBlendMode::kScreen:
780 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 783 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
781 break; 784 break;
782 default: 785 default:
783 DCHECK(use_blend_equation_advanced_); 786 DCHECK(use_blend_equation_advanced_);
784 gl_->BlendEquation(GL_FUNC_ADD); 787 gl_->BlendEquation(GL_FUNC_ADD);
785 } 788 }
786 } 789 }
787 790
788 bool GLRenderer::ShouldApplyBackgroundFilters( 791 bool GLRenderer::ShouldApplyBackgroundFilters(
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 void GLRenderer::DrawSolidColorQuad(const SolidColorDrawQuad* quad, 1730 void GLRenderer::DrawSolidColorQuad(const SolidColorDrawQuad* quad,
1728 const gfx::QuadF* clip_region) { 1731 const gfx::QuadF* clip_region) {
1729 gfx::Rect tile_rect = quad->visible_rect; 1732 gfx::Rect tile_rect = quad->visible_rect;
1730 1733
1731 SkColor color = quad->color; 1734 SkColor color = quad->color;
1732 float opacity = quad->shared_quad_state->opacity; 1735 float opacity = quad->shared_quad_state->opacity;
1733 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity; 1736 float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity;
1734 1737
1735 // Early out if alpha is small enough that quad doesn't contribute to output. 1738 // Early out if alpha is small enough that quad doesn't contribute to output.
1736 if (alpha < std::numeric_limits<float>::epsilon() && 1739 if (alpha < std::numeric_limits<float>::epsilon() &&
1737 quad->ShouldDrawWithBlending()) 1740 quad->ShouldDrawWithBlending() &&
1741 quad->shared_quad_state->blend_mode == SkBlendMode::kSrcOver)
1738 return; 1742 return;
1739 1743
1740 gfx::Transform device_transform = 1744 gfx::Transform device_transform =
1741 current_frame()->window_matrix * current_frame()->projection_matrix * 1745 current_frame()->window_matrix * current_frame()->projection_matrix *
1742 quad->shared_quad_state->quad_to_target_transform; 1746 quad->shared_quad_state->quad_to_target_transform;
1743 device_transform.FlattenTo2d(); 1747 device_transform.FlattenTo2d();
1744 if (!device_transform.IsInvertible()) 1748 if (!device_transform.IsInvertible())
1745 return; 1749 return;
1746 1750
1747 auto local_quad = gfx::QuadF(gfx::RectF(tile_rect)); 1751 auto local_quad = gfx::QuadF(gfx::RectF(tile_rect));
(...skipping 26 matching lines...) Expand all
1774 quad_color_space); 1778 quad_color_space);
1775 SetShaderColor(color, opacity); 1779 SetShaderColor(color, opacity);
1776 1780
1777 if (use_aa) { 1781 if (use_aa) {
1778 gl_->Uniform3fv(current_program_->edge_location(), 8, edge); 1782 gl_->Uniform3fv(current_program_->edge_location(), 8, edge);
1779 } 1783 }
1780 1784
1781 // Enable blending when the quad properties require it or if we decided 1785 // Enable blending when the quad properties require it or if we decided
1782 // to use antialiasing. 1786 // to use antialiasing.
1783 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa); 1787 SetBlendEnabled(quad->ShouldDrawWithBlending() || use_aa);
1788 ApplyBlendModeUsingBlendFunc(quad->shared_quad_state->blend_mode);
1784 1789
1785 // Antialising requires a normalized quad, but this could lead to floating 1790 // Antialising requires a normalized quad, but this could lead to floating
1786 // point precision errors, so only normalize when antialising is on. 1791 // point precision errors, so only normalize when antialising is on.
1787 if (use_aa) { 1792 if (use_aa) {
1788 // Normalize to tile_rect. 1793 // Normalize to tile_rect.
1789 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); 1794 local_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height());
1790 1795
1791 SetShaderQuadF(local_quad); 1796 SetShaderQuadF(local_quad);
1792 1797
1793 // The transform and vertex data are used to figure out the extents that the 1798 // The transform and vertex data are used to figure out the extents that the
1794 // un-antialiased quad should have and which vertex this is and the float 1799 // un-antialiased quad should have and which vertex this is and the float
1795 // quad passed in via uniform is the actual geometry that gets used to draw 1800 // quad passed in via uniform is the actual geometry that gets used to draw
1796 // it. This is why this centered rect is used and not the original 1801 // it. This is why this centered rect is used and not the original
1797 // quad_rect. 1802 // quad_rect.
1798 gfx::RectF centered_rect( 1803 gfx::RectF centered_rect(
1799 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()), 1804 gfx::PointF(-0.5f * tile_rect.width(), -0.5f * tile_rect.height()),
1800 gfx::SizeF(tile_rect.size())); 1805 gfx::SizeF(tile_rect.size()));
1801 DrawQuadGeometry(current_frame()->projection_matrix, 1806 DrawQuadGeometry(current_frame()->projection_matrix,
1802 quad->shared_quad_state->quad_to_target_transform, 1807 quad->shared_quad_state->quad_to_target_transform,
1803 centered_rect); 1808 centered_rect);
1804 } else { 1809 } else {
1805 PrepareGeometry(SHARED_BINDING); 1810 PrepareGeometry(SHARED_BINDING);
1806 SetShaderQuadF(local_quad); 1811 SetShaderQuadF(local_quad);
1807 SetShaderMatrix(current_frame()->projection_matrix * 1812 SetShaderMatrix(current_frame()->projection_matrix *
1808 quad->shared_quad_state->quad_to_target_transform); 1813 quad->shared_quad_state->quad_to_target_transform);
1809 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); 1814 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
1810 } 1815 }
1816 RestoreBlendFuncToDefault(quad->shared_quad_state->blend_mode);
1811 } 1817 }
1812 1818
1813 void GLRenderer::DrawTileQuad(const TileDrawQuad* quad, 1819 void GLRenderer::DrawTileQuad(const TileDrawQuad* quad,
1814 const gfx::QuadF* clip_region) { 1820 const gfx::QuadF* clip_region) {
1815 DrawContentQuad(quad, quad->resource_id(), clip_region); 1821 DrawContentQuad(quad, quad->resource_id(), clip_region);
1816 } 1822 }
1817 1823
1818 void GLRenderer::DrawContentQuad(const ContentDrawQuadBase* quad, 1824 void GLRenderer::DrawContentQuad(const ContentDrawQuadBase* quad,
1819 ResourceId resource_id, 1825 ResourceId resource_id,
1820 const gfx::QuadF* clip_region) { 1826 const gfx::QuadF* clip_region) {
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 return; 3617 return;
3612 3618
3613 // Report GPU overdraw as a percentage of |max_result|. 3619 // Report GPU overdraw as a percentage of |max_result|.
3614 TRACE_COUNTER1( 3620 TRACE_COUNTER1(
3615 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", 3621 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw",
3616 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / 3622 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) /
3617 max_result); 3623 max_result);
3618 } 3624 }
3619 3625
3620 } // namespace cc 3626 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/output/renderer_pixeltest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698