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

Issue 25023003: Implement color filter as GrGLEffect (Closed)

Created:
7 years, 2 months ago by Kimmo Kinnunen
Modified:
7 years, 2 months ago
CC:
skia-review_googlegroups.com
Visibility:
Public.

Description

Implement SkColorFilter as a GrGLEffect Adds GrEffect::willUseInputColor() which indicates whether or not the input color affects the output of the effect. This is needed for certain Xfermodes, such as kSrc_Mode. For these modes the color filter will not use the input color. An effect with GrEffect::willUseInputColor() true will cause all color or coverage effects before it to be discarded, as their computations cannot affect the output. In these cases program is marked as having white input color. This fixes an assert when Skia is compiled in a mode that prefers using uniforms instead of attributes for constants. (Flags GR_GL_USE_NV_PATH_RENDERING or GR_GL_NO_CONSTANT_ATTRIBUTES). Using attributes hides the problem where the fragment shader does not need input color for color filters that ignore DST part of the filter. The assert would be hit when uniform manager tries to bind an uniform which has been optimized away by the shader compiler. Adds specific GrGLSLExpr4 and GrGLSLExpr1 classes. This way the GLSL expressions like "(v - src.a)" can remain somewhat readable in form of "(v - src.a())". The GrGLSLExpr<typename> template implements the generic functionality, GrGLSLExprX is the specialization that exposes the type-safe interface to this functionality. Also adds operators so that GLSL binary operators of the form "(float * vecX)" can be expressed in C++. Before only the equivalent "(vecX * float)" was possible. This reverts the common blending calculations to more conventional order, such as "(1-a) * c" instead of "c * (1-a)". Changes GrGLSLExpr1::OnesStr from 1 to 1.0 in order to preserve the color filter blending formula string the same (with the exception of variable name change). Shaders change in case of input color being needed: - vec4 filteredColor; - filteredColor = (((1.0 - uFilterColor.a) * output_Stage0) + uFilterColor); - fsColorOut = filteredColor; + vec4 output_Stage1; + { // Stage 1: ModeColorFilterEffect + output_Stage1 = (((1.0 - uFilterColor_Stage1.a) * output_Stage0) + uFilterColor_Stage1); + } + fsColorOut = output_Stage1; Shaders change in case of input color being not needed: -uniform vec4 uFilterColor; -in vec4 vColor; +uniform vec4 uFilterColor_Stage0; out vec4 fsColorOut; void main() { - vec4 filteredColor; - filteredColor = uFilterColor; - fsColorOut = filteredColor; + vec4 output_Stage0; + { // Stage 0: ModeColorFilterEffect + output_Stage0 = uFilterColor_Stage0; + } + fsColorOut = output_Stage0; } Committed: http://code.google.com/p/skia/source/detail?r=11912

Patch Set 1 #

Total comments: 1

Patch Set 2 : ready for review #

Patch Set 3 : Fix a small thinko #

Total comments: 1

Patch Set 4 : add a test and fix bugs revealed by the test #

Patch Set 5 : rebase #

Total comments: 6

Patch Set 6 : Addressing review comments #

Patch Set 7 : rebase #

Total comments: 2

Patch Set 8 : simplified #

Patch Set 9 : simplified #

Patch Set 10 : marked all effects that do not use input color #

Patch Set 11 : maybe more readable #

Patch Set 12 : address review comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+795 lines, -471 lines) Patch
M gyp/tests.gyp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +1 line, -0 lines 0 comments Download
M include/gpu/GrEffect.h View 1 2 3 4 5 6 7 8 9 10 11 4 chunks +12 lines, -0 lines 0 comments Download
M include/gpu/GrPaint.h View 1 2 3 4 5 5 chunks +6 lines, -28 lines 0 comments Download
M src/effects/SkBitmapAlphaThresholdShader.cpp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +1 line, -1 line 0 comments Download
M src/effects/SkColorFilters.cpp View 1 2 3 4 5 6 7 8 9 10 11 2 chunks +290 lines, -0 lines 0 comments Download
M src/effects/SkDisplacementMapEffect.cpp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +1 line, -0 lines 0 comments Download
M src/effects/SkMatrixConvolutionImageFilter.cpp View 1 2 3 4 5 6 7 8 9 10 11 2 chunks +2 lines, -0 lines 0 comments Download
M src/effects/SkPerlinNoiseShader.cpp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +1 line, -0 lines 0 comments Download
M src/effects/gradients/SkGradientShader.cpp View 1 2 3 4 5 6 7 8 9 10 11 2 chunks +2 lines, -2 lines 0 comments Download
M src/gpu/GrAAConvexPathRenderer.cpp View 1 2 3 4 5 6 7 8 9 10 1 chunk +1 line, -1 line 0 comments Download
M src/gpu/GrAARectRenderer.cpp View 1 2 3 4 5 6 7 8 9 10 2 chunks +2 lines, -2 lines 0 comments Download
M src/gpu/GrDrawState.h View 1 2 3 4 5 6 7 8 9 10 11 4 chunks +0 lines, -18 lines 0 comments Download
M src/gpu/GrDrawState.cpp View 6 7 2 chunks +0 lines, -8 lines 0 comments Download
M src/gpu/GrOvalRenderer.cpp View 1 2 3 4 5 6 7 8 9 10 3 chunks +3 lines, -3 lines 0 comments Download
M src/gpu/GrPaint.cpp View 1 chunk +0 lines, -6 lines 0 comments Download
M src/gpu/SkGpuDevice.cpp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +0 lines, -7 lines 0 comments Download
M src/gpu/effects/GrBezierEffect.cpp View 1 2 3 4 5 6 7 8 9 10 3 chunks +3 lines, -3 lines 0 comments Download
M src/gpu/effects/GrBicubicEffect.cpp View 1 2 3 4 5 6 7 8 9 10 11 3 chunks +4 lines, -0 lines 0 comments Download
M src/gpu/gl/GrGLProgram.h View 1 2 3 4 5 6 2 chunks +0 lines, -2 lines 0 comments Download
M src/gpu/gl/GrGLProgram.cpp View 1 2 3 4 5 6 7 8 9 10 11 7 chunks +10 lines, -154 lines 0 comments Download
M src/gpu/gl/GrGLProgramDesc.h View 1 2 3 4 5 6 1 chunk +0 lines, -1 line 0 comments Download
M src/gpu/gl/GrGLProgramDesc.cpp View 1 2 3 4 5 6 7 8 8 chunks +32 lines, -16 lines 0 comments Download
M src/gpu/gl/GrGLSL.h View 1 2 3 4 5 6 7 8 9 10 5 chunks +142 lines, -100 lines 0 comments Download
M src/gpu/gl/GrGLSL.cpp View 1 2 3 4 5 6 7 8 9 10 1 chunk +1 line, -1 line 0 comments Download
M src/gpu/gl/GrGLSL_impl.h View 1 2 3 4 5 6 7 8 9 10 1 chunk +128 lines, -93 lines 0 comments Download
M src/gpu/gl/GrGLShaderBuilder.h View 1 2 3 4 5 6 7 8 9 10 11 7 chunks +10 lines, -10 lines 0 comments Download
M src/gpu/gl/GrGLShaderBuilder.cpp View 1 2 3 4 5 6 7 8 9 10 11 5 chunks +12 lines, -12 lines 0 comments Download
M tests/GLProgramsTest.cpp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +0 lines, -3 lines 0 comments Download
A tests/GpuColorFilterTest.cpp View 1 2 3 1 chunk +131 lines, -0 lines 0 comments Download

Messages

Total messages: 23 (0 generated)
Kimmo Kinnunen
depends on https://codereview.chromium.org/25048002
7 years, 2 months ago (2013-09-27 13:39:10 UTC) #1
Kimmo Kinnunen
Brian, ran into this while implementing NVPR. This is a work in progress.. Do you ...
7 years, 2 months ago (2013-09-27 13:41:12 UTC) #2
bsalomon
Kimmo, Thanks for this! I think we may want to change GrEffect::getConstantColorComponents() into something that ...
7 years, 2 months ago (2013-09-27 13:59:38 UTC) #3
Kimmo Kinnunen
On 2013/09/27 13:59:38, bsalomon wrote: > Kimmo, Thanks for this! > > I think we ...
7 years, 2 months ago (2013-10-01 12:44:36 UTC) #4
Kimmo Kinnunen
https://codereview.chromium.org/25023003/diff/11001/src/effects/SkColorFilters.cpp File src/effects/SkColorFilters.cpp (right): https://codereview.chromium.org/25023003/diff/11001/src/effects/SkColorFilters.cpp#newcode366 src/effects/SkColorFilters.cpp:366: void ModeColorFilterEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { Btw: It'd ...
7 years, 2 months ago (2013-10-01 12:55:46 UTC) #5
Kimmo Kinnunen
Found the solution to the test question..
7 years, 2 months ago (2013-10-02 12:35:25 UTC) #6
bsalomon
On 2013/10/01 12:44:36, kkinnunen wrote: > On 2013/09/27 13:59:38, bsalomon wrote: > > Kimmo, Thanks ...
7 years, 2 months ago (2013-10-02 15:32:53 UTC) #7
bsalomon
https://codereview.chromium.org/25023003/diff/21001/src/effects/SkColorFilters.cpp File src/effects/SkColorFilters.cpp (right): https://codereview.chromium.org/25023003/diff/21001/src/effects/SkColorFilters.cpp#newcode304 src/effects/SkColorFilters.cpp:304: * flags through the blending equation. "It has members ...
7 years, 2 months ago (2013-10-02 16:37:58 UTC) #8
Kimmo Kinnunen
https://chromiumcodereview.appspot.com/25023003/diff/21001/src/effects/SkColorFilters.cpp File src/effects/SkColorFilters.cpp (right): https://chromiumcodereview.appspot.com/25023003/diff/21001/src/effects/SkColorFilters.cpp#newcode304 src/effects/SkColorFilters.cpp:304: * flags through the blending equation. On 2013/10/02 16:37:59, ...
7 years, 2 months ago (2013-10-04 06:21:18 UTC) #9
bsalomon
Kimmo, I just noticed that you have a number of issues with uploaded patches but ...
7 years, 2 months ago (2013-10-07 14:04:59 UTC) #10
Kimmo Kinnunen
Thanks. How about the new version? https://codereview.chromium.org/25023003/diff/52001/src/gpu/GrDrawState.h File src/gpu/GrDrawState.h (right): https://codereview.chromium.org/25023003/diff/52001/src/gpu/GrDrawState.h#newcode1063 src/gpu/GrDrawState.h:1063: class EffectStageArray { ...
7 years, 2 months ago (2013-10-10 08:12:28 UTC) #11
Kimmo Kinnunen
Hmm. I think the client code using GrGLSLExpr becomes unclear. Maybe I can still refine ...
7 years, 2 months ago (2013-10-11 12:58:10 UTC) #12
Kimmo Kinnunen
This is maybe a bit simpler. Example of how it would expand: https://codereview.chromium.org/26190003/
7 years, 2 months ago (2013-10-14 14:17:15 UTC) #13
bsalomon
Kimmo, sorry letting this fall off my radar! One small request: can willUseInputColor be made ...
7 years, 2 months ago (2013-10-18 14:10:16 UTC) #14
Kimmo Kinnunen
On 2013/10/18 14:10:16, bsalomon wrote: > Kimmo, sorry letting this fall off my radar! One ...
7 years, 2 months ago (2013-10-21 13:28:24 UTC) #15
bsalomon
On 2013/10/21 13:28:24, kkinnunen wrote: > On 2013/10/18 14:10:16, bsalomon wrote: > > Kimmo, sorry ...
7 years, 2 months ago (2013-10-21 13:39:21 UTC) #16
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://skia-tree-status.appspot.com/cq/kkinnunen@nvidia.com/25023003/98001
7 years, 2 months ago (2013-10-22 20:52:35 UTC) #17
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://skia-tree-status.appspot.com/cq/kkinnunen@nvidia.com/25023003/98001
7 years, 2 months ago (2013-10-23 05:41:36 UTC) #18
commit-bot: I haz the power
Change committed as 11912
7 years, 2 months ago (2013-10-23 05:42:12 UTC) #19
Stephen White
Annoying post-commit drive-by: "An effect with GrEffect::willUseInputColor() true will cause all color or coverage effects ...
7 years, 2 months ago (2013-10-23 14:11:30 UTC) #20
mtklein
On 2013/10/23 14:11:30, Stephen White wrote: > Annoying post-commit drive-by: > > "An effect with ...
7 years, 2 months ago (2013-10-23 15:41:41 UTC) #21
bsalomon
On 2013/10/23 15:41:41, mtklein wrote: > On 2013/10/23 14:11:30, Stephen White wrote: > > Annoying ...
7 years, 2 months ago (2013-10-23 15:45:00 UTC) #22
Kimmo Kinnunen
7 years, 2 months ago (2013-10-24 05:47:21 UTC) #23
Message was sent while issue was closed.
On 2013/10/23 15:41:41, mtklein wrote:
> On 2013/10/23 14:11:30, Stephen White wrote:
> > Annoying post-commit drive-by:
> > 
> > "An effect with GrEffect::willUseInputColor() true will cause all color
> > or coverage effects before it to be discarded, as their computations
> > cannot affect the output."
> > 
> > Did you mean "false"?

Yeah, correct.
 
> 
> After this CL, I'm seeing the GLPrograms test assert:
> 
> $ out/Debug/tests --match GLPrograms
> Non-default runtime configuration options:
> Skia UnitTests: --match GLPrograms SK_DEBUG SK_SCALAR_IS_FLOAT
> skia_arch_width=64
> [  1/  1] (1) GLPrograms
> ../../src/effects/SkColorFilters.cpp:227: failed assertion
> "SkXfermode::kDst_Mode != mode"

The assertion is fixed in:
https://codereview.chromium.org/39403002/

Sorry about the mess.

Powered by Google App Engine
This is Rietveld 408576698