From 569f29da862372ab8faeaf851966c2d620bb696c Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Wed, 30 Jun 2021 18:15:43 -0400 Subject: [PATCH] Only trigger serializing blender if it isn't a mode Change-Id: I9f9cf7f92232c365538f3dd29df226933827771c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423582 Reviewed-by: Brian Osman Commit-Queue: Mike Reed --- src/core/SkPaint.cpp | 20 +++++++++++++++----- tests/PaintTest.cpp | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index edb687b1c8..d428070c2b 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -248,6 +248,8 @@ template uint32_t shift_bits(T value, unsigned shift, unsigned bits return v << shift; } +constexpr uint8_t CUSTOM_BLEND_MODE_SENTINEL = 0xFF; + /* Packing the paint flags : 8 // 2... blend : 8 // 30+ @@ -260,9 +262,13 @@ template uint32_t shift_bits(T value, unsigned shift, unsigned bits */ static uint32_t pack_v68(const SkPaint& paint, unsigned flatFlags) { uint32_t packed = 0; + const auto bm = paint.asBlendMode(); + const unsigned mode = bm ? static_cast(bm.value()) + : CUSTOM_BLEND_MODE_SENTINEL; + packed |= shift_bits(((unsigned)paint.isDither() << 1) | (unsigned)paint.isAntiAlias(), 0, 8); - packed |= shift_bits(paint.getBlendMode(), 8, 8); + packed |= shift_bits(mode, 8, 8); packed |= shift_bits(paint.getStrokeCap(), 16, 2); packed |= shift_bits(paint.getStrokeJoin(), 18, 2); packed |= shift_bits(paint.getStyle(), 20, 2); @@ -277,7 +283,13 @@ static uint32_t unpack_v68(SkPaint* paint, uint32_t packed, SkSafeRange& safe) { paint->setAntiAlias((packed & 1) != 0); paint->setDither((packed & 2) != 0); packed >>= 8; - paint->setBlendMode(safe.checkLE(packed & 0xFF, SkBlendMode::kLastMode)); + { + unsigned mode = packed & 0xFF; + if (mode != CUSTOM_BLEND_MODE_SENTINEL) { // sentinel for custom blender + paint->setBlendMode(safe.checkLE(mode, SkBlendMode::kLastMode)); + } + // else we will unflatten the custom blender + } packed >>= 8; paint->setStrokeCap(safe.checkLE(packed & 0x3, SkPaint::kLast_Cap)); packed >>= 2; @@ -303,7 +315,7 @@ void SkPaintPriv::Flatten(const SkPaint& paint, SkWriteBuffer& buffer) { paint.getMaskFilter() || paint.getColorFilter() || paint.getImageFilter() || - paint.getBlender()) { + !paint.asBlendMode()) { flatFlags |= kHasEffects_FlatFlag; } @@ -343,7 +355,6 @@ SkReadPaintResult SkPaintPriv::Unflatten(SkPaint* paint, SkReadBuffer& buffer, S paint->setMaskFilter(nullptr); paint->setColorFilter(nullptr); paint->setImageFilter(nullptr); - paint->experimental_setBlender(nullptr); } else if (buffer.isVersionLT(SkPicturePriv::kSkBlenderInSkPaint)) { // This paint predates the introduction of user blend functions (via SkBlender). paint->setPathEffect(buffer.readPathEffect()); @@ -352,7 +363,6 @@ SkReadPaintResult SkPaintPriv::Unflatten(SkPaint* paint, SkReadBuffer& buffer, S paint->setColorFilter(buffer.readColorFilter()); (void)buffer.read32(); // was drawLooper (now deprecated) paint->setImageFilter(buffer.readImageFilter()); - paint->experimental_setBlender(nullptr); } else { paint->setPathEffect(buffer.readPathEffect()); paint->setShader(buffer.readShader()); diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index 560f020a59..2db0ed6b80 100644 --- a/tests/PaintTest.cpp +++ b/tests/PaintTest.cpp @@ -158,8 +158,8 @@ DEF_TEST(Paint_MoreFlattening, r) { ASSERT(reader.offset() == writer.bytesWritten()); // No matter the encoding, these must always hold. - ASSERT(other.getColor() == paint.getColor()); - ASSERT(other.getBlendMode() == paint.getBlendMode()); + ASSERT(other.getColor() == paint.getColor()); + ASSERT(other.asBlendMode() == paint.asBlendMode()); } #include "include/effects/SkColorMatrixFilter.h"