Merge "Fix Canvas#drawVertices color blending when no shader is provided" into tm-qpr-dev am: 716c5618df

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19558695

Change-Id: I759f579b9e468673c85d9388f5165826e85562f2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Nolan Scobie
2022-08-09 21:07:17 +00:00
committed by Automerger Merge Worker

View File

@@ -407,14 +407,28 @@ static void drawVertices(JNIEnv* env, jobject, jlong canvasHandle,
indices = (const uint16_t*)(indexA.ptr() + indexIndex); indices = (const uint16_t*)(indexA.ptr() + indexIndex);
} }
SkVertices::VertexMode mode = static_cast<SkVertices::VertexMode>(modeHandle); SkVertices::VertexMode vertexMode = static_cast<SkVertices::VertexMode>(modeHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
get_canvas(canvasHandle)->drawVertices(SkVertices::MakeCopy(mode, vertexCount,
reinterpret_cast<const SkPoint*>(verts), // Preserve legacy Skia behavior: ignore the shader if there are no texs set.
reinterpret_cast<const SkPoint*>(texs), Paint noShaderPaint;
reinterpret_cast<const SkColor*>(colors), if (jtexs == NULL) {
indexCount, indices).get(), noShaderPaint = Paint(*paint);
SkBlendMode::kModulate, *paint); noShaderPaint.setShader(nullptr);
paint = &noShaderPaint;
}
// Since https://skia-review.googlesource.com/c/skia/+/473676, Skia will blend paint and vertex
// colors when no shader is provided. This ternary uses kDst to mimic the old behavior of
// ignoring the paint and using the vertex colors directly when no shader is provided.
SkBlendMode blendMode = paint->getShader() ? SkBlendMode::kModulate : SkBlendMode::kDst;
get_canvas(canvasHandle)
->drawVertices(SkVertices::MakeCopy(
vertexMode, vertexCount, reinterpret_cast<const SkPoint*>(verts),
reinterpret_cast<const SkPoint*>(texs),
reinterpret_cast<const SkColor*>(colors), indexCount, indices)
.get(),
blendMode, *paint);
} }
static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle,