From 15e42b30e50377be6c075d392ecb5cb006edad91 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Wed, 28 Jul 2021 16:35:39 -0400 Subject: [PATCH] draw vertices: implement blending the tri-color shader If there are colors, and the incoming paint has a shader, then they need to be blended. Bug=Skia:11822 Change-Id: Id5a1d7dffcaedb678214c694c9c87d0c71cdc991 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/434161 Reviewed-by: Mike Reed Reviewed-by: Brian Osman Commit-Queue: Herb Derby --- src/core/SkDraw_vertices.cpp | 75 +++++++++++++++++------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/src/core/SkDraw_vertices.cpp b/src/core/SkDraw_vertices.cpp index 5c43c88f3c..d53ad09f99 100644 --- a/src/core/SkDraw_vertices.cpp +++ b/src/core/SkDraw_vertices.cpp @@ -352,50 +352,45 @@ void SkDraw::drawFixedVertices(const SkVertices* vertices, SkBlendMode blendMode // No colors are changing and no texture coordinates are changing, so no updates between // triangles are needed. Use SkVM to blit the triangles. if (gUseSkVMBlitter) { - if (!colors) { - if (!texCoords || texCoords == positions) { - if (auto blitter = SkVMBlitter::Make( - fDst, paint, *fMatrixProvider, outerAlloc, this->fRC->clipShader())) { - while (vertProc(&state)) { - fill_triangle(state, blitter, *fRC, dev2, dev3); - } - return; - } - } else { - auto texCoordShader = as_SB(shader)->updatableShader(outerAlloc); - SkPaint shaderPaint{paint}; - shaderPaint.setShader(sk_ref_sp(texCoordShader)); - if (auto blitter = SkVMBlitter::Make( - fDst, shaderPaint, *fMatrixProvider, outerAlloc, this->fRC->clipShader())) { + SkUpdatableShader* texCoordShader = nullptr; + if (texCoords && texCoords != positions) { + texCoordShader = as_SB(shader)->updatableShader(outerAlloc); + shader = texCoordShader; + } - SkMatrix localM; - while (vertProc(&state)) { - if (texture_to_matrix(state, positions, texCoords, &localM) && - texCoordShader->update(SkMatrix::Concat(ctm, localM))) { - fill_triangle(state, blitter, *fRC, dev2, dev3); - } - } - return; - } + SkTriColorShader* colorShader = nullptr; + SkPMColor4f* dstColors = nullptr; + if (colors) { + colorShader = outerAlloc->make( + compute_is_opaque(colors, vertexCount), usePerspective); + dstColors = convert_colors(colors, vertexCount, fDst.colorSpace(), outerAlloc); + if (shader) { + shader = outerAlloc->make( + blendMode, sk_ref_sp(colorShader), sk_ref_sp(shader)); + } else { + shader = colorShader; } - } else if(!texCoords) { - auto triangleShader = - outerAlloc->make( - compute_is_opaque(colors,vertexCount), usePerspective); - SkPaint shaderPaint{paint}; - shaderPaint.setShader(sk_ref_sp(triangleShader)); - if (auto blitter = SkVMBlitter::Make( - fDst, shaderPaint, *fMatrixProvider, outerAlloc, this->fRC->clipShader())) { - SkPMColor4f* dstColors = - convert_colors(colors, vertexCount, fDst.colorSpace(), outerAlloc); - while (vertProc(&state)) { - if (triangleShader->update(ctmInverse, positions, dstColors, - state.f0, state.f1, state.f2)) { - fill_triangle(state, blitter, *fRC, dev2, dev3); - } + } + + SkPaint shaderPaint{paint}; + shaderPaint.setShader(sk_ref_sp(shader)); + if (auto blitter = SkVMBlitter::Make( + fDst, shaderPaint, *fMatrixProvider, outerAlloc, this->fRC->clipShader())) { + while (vertProc(&state)) { + SkMatrix localM; + if (texCoordShader && !(texture_to_matrix(state, positions, texCoords, &localM) + && texCoordShader->update(SkMatrix::Concat(ctm, localM)))) { + continue; } - return; + + if (colorShader && !colorShader->update(ctmInverse, positions, dstColors,state.f0, + state.f1, state.f2)) { + continue; + } + + fill_triangle(state, blitter, *fRC, dev2, dev3); } + return; } }