Remake SkStrikeCache::commonSetup as constructor.
Also explicitly default all special methods of SkStrikeCache to get
nicer warnings.
Change-Id: I8856a905c6075ca52d4ad900ccd0dacc581cd485
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/350637
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index e1911d9..2f82f57 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -156,9 +156,7 @@
if (useSDFT) {
// Process SDFT - This should be the .009% case.
- SkScalar minScale, maxScale;
- SkStrikeSpec strikeSpec;
- std::tie(strikeSpec, minScale, maxScale) =
+ const auto& [strikeSpec, minScale, maxScale] =
SkStrikeSpec::MakeSDFT(runFont, runPaint, fDeviceProps, drawMatrix, options);
if (!strikeSpec.isEmpty()) {
diff --git a/src/core/SkStrikeSpec.cpp b/src/core/SkStrikeSpec.cpp
index 1277d95..597d084 100644
--- a/src/core/SkStrikeSpec.cpp
+++ b/src/core/SkStrikeSpec.cpp
@@ -23,17 +23,13 @@
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& deviceMatrix) {
- SkStrikeSpec storage;
- storage.commonSetup(font, paint, surfaceProps, scalerContextFlags, deviceMatrix);
-
- return storage;
+ return SkStrikeSpec(font, paint, surfaceProps, scalerContextFlags, deviceMatrix, 1);
}
SkStrikeSpec SkStrikeSpec::MakePath(const SkFont& font, const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags) {
- SkStrikeSpec storage;
// setup our std runPaint, in hopes of getting hits in the cache
SkPaint pathPaint{paint};
@@ -41,14 +37,13 @@
// The factor to get from the size stored in the strike to the size needed for
// the source.
- storage.fStrikeToSourceRatio = pathFont.setupForAsPaths(&pathPaint);
+ SkScalar strikeToSourceRatio = pathFont.setupForAsPaths(&pathPaint);
// The sub-pixel position will always happen when transforming to the screen.
pathFont.setSubpixel(false);
- storage.commonSetup(pathFont, pathPaint, surfaceProps, scalerContextFlags, SkMatrix::I());
-
- return storage;
+ return SkStrikeSpec(pathFont, pathPaint, surfaceProps, scalerContextFlags,
+ SkMatrix::I(), strikeToSourceRatio);
}
SkStrikeSpec SkStrikeSpec::MakeSourceFallback(
@@ -57,7 +52,6 @@
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
SkScalar maxSourceGlyphDimension) {
- SkStrikeSpec storage;
// Subtract 2 to account for the bilerp pad around the glyph
SkScalar maxAtlasDimension = SkStrikeCommon::kSkSideTooBigForAtlas - 2;
@@ -77,16 +71,13 @@
fallbackFont.setSubpixel(false);
// The scale factor to go from strike size to the source size for glyphs.
- storage.fStrikeToSourceRatio = runFontTextSize / fallbackTextSize;
+ SkScalar strikeToSourceRatio = runFontTextSize / fallbackTextSize;
- storage.commonSetup(fallbackFont, paint, surfaceProps, scalerContextFlags, SkMatrix::I());
-
- return storage;
+ return SkStrikeSpec(fallbackFont, paint, surfaceProps, scalerContextFlags,
+ SkMatrix::I(), strikeToSourceRatio);
}
SkStrikeSpec SkStrikeSpec::MakeCanonicalized(const SkFont& font, const SkPaint* paint) {
- SkStrikeSpec storage;
-
SkPaint canonicalizedPaint;
if (paint != nullptr) {
canonicalizedPaint = *paint;
@@ -94,36 +85,26 @@
const SkFont* canonicalizedFont = &font;
SkTLazy<SkFont> pathFont;
+ SkScalar strikeToSourceRatio = 1;
if (ShouldDrawAsPath(canonicalizedPaint, font, SkMatrix::I())) {
canonicalizedFont = pathFont.set(font);
- storage.fStrikeToSourceRatio = pathFont->setupForAsPaths(nullptr);
+ strikeToSourceRatio = pathFont->setupForAsPaths(nullptr);
canonicalizedPaint.reset();
}
- storage.commonSetup(*canonicalizedFont,
- canonicalizedPaint,
- SkSurfaceProps(),
- kFakeGammaAndBoostContrast,
- SkMatrix::I());
- return storage;
+ return SkStrikeSpec(*canonicalizedFont, canonicalizedPaint,
+ SkSurfaceProps(), kFakeGammaAndBoostContrast,
+ SkMatrix::I(), strikeToSourceRatio);
}
SkStrikeSpec SkStrikeSpec::MakeWithNoDevice(const SkFont& font, const SkPaint* paint) {
- SkStrikeSpec storage;
-
SkPaint setupPaint;
if (paint != nullptr) {
setupPaint = *paint;
}
- storage.commonSetup(font,
- setupPaint,
- SkSurfaceProps(),
- kFakeGammaAndBoostContrast,
- SkMatrix::I());
-
- return storage;
-
+ return SkStrikeSpec(font, setupPaint, SkSurfaceProps(), kFakeGammaAndBoostContrast,
+ SkMatrix::I(), 1);
}
SkStrikeSpec SkStrikeSpec::MakeDefault() {
@@ -173,14 +154,9 @@
}
font.setSize((SkScalar)unitsPerEm);
- SkStrikeSpec storage;
- storage.commonSetup(font,
- SkPaint(),
- SkSurfaceProps(0, kUnknown_SkPixelGeometry),
- kFakeGammaAndBoostContrast,
- SkMatrix::I());
-
- return storage;
+ return SkStrikeSpec(font, SkPaint(),
+ SkSurfaceProps(0, kUnknown_SkPixelGeometry), kFakeGammaAndBoostContrast,
+ SkMatrix::I(), 1);
}
#if SK_SUPPORT_GPU
@@ -188,11 +164,10 @@
SkStrikeSpec::MakeSDFT(const SkFont& font, const SkPaint& paint,
const SkSurfaceProps& surfaceProps, const SkMatrix& deviceMatrix,
const GrSDFTOptions& options) {
- SkStrikeSpec storage;
-
SkPaint dfPaint{paint};
dfPaint.setMaskFilter(GrSDFMaskFilter::Make());
- SkFont dfFont = options.getSDFFont(font, deviceMatrix, &storage.fStrikeToSourceRatio);
+ SkScalar strikeToSourceRatio;
+ SkFont dfFont = options.getSDFFont(font, deviceMatrix, &strikeToSourceRatio);
// Fake-gamma and subpixel antialiasing are applied in the shader, so we ignore the
// passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
@@ -201,9 +176,10 @@
SkScalar minScale, maxScale;
std::tie(minScale, maxScale) = options.computeSDFMinMaxScale(font.getSize(), deviceMatrix);
- storage.commonSetup(dfFont, dfPaint, surfaceProps, flags, SkMatrix::I());
+ SkStrikeSpec strikeSpec(dfFont, dfPaint, surfaceProps, flags,
+ SkMatrix::I(), strikeToSourceRatio);
- return std::tie(storage, minScale, maxScale);
+ return std::make_tuple(std::move(strikeSpec), minScale, maxScale);
}
sk_sp<GrTextStrike> SkStrikeSpec::findOrCreateGrStrike(GrStrikeCache* cache) const {
@@ -211,10 +187,13 @@
}
#endif
-void SkStrikeSpec::commonSetup(const SkFont& font, const SkPaint& paint,
- const SkSurfaceProps& surfaceProps,
- SkScalerContextFlags scalerContextFlags,
- const SkMatrix& deviceMatrix) {
+SkStrikeSpec::SkStrikeSpec(const SkFont& font, const SkPaint& paint,
+ const SkSurfaceProps& surfaceProps,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& deviceMatrix,
+ SkScalar strikeToSourceRatio)
+ : fStrikeToSourceRatio(strikeToSourceRatio)
+{
SkScalerContextEffects effects;
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
diff --git a/src/core/SkStrikeSpec.h b/src/core/SkStrikeSpec.h
index 5b85411..82133d9 100644
--- a/src/core/SkStrikeSpec.h
+++ b/src/core/SkStrikeSpec.h
@@ -25,6 +25,14 @@
class SkStrikeSpec {
public:
+ SkStrikeSpec(const SkStrikeSpec&) = default;
+ SkStrikeSpec& operator=(const SkStrikeSpec&) = delete;
+
+ SkStrikeSpec(SkStrikeSpec&&) = default;
+ SkStrikeSpec& operator=(SkStrikeSpec&&) = delete;
+
+ ~SkStrikeSpec() = default;
+
// Create a strike spec for mask style cache entries.
static SkStrikeSpec MakeMask(
const SkFont& font,
@@ -83,18 +91,19 @@
static bool ShouldDrawAsPath(const SkPaint& paint, const SkFont& font, const SkMatrix& matrix);
private:
- void commonSetup(
+ SkStrikeSpec(
const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
- const SkMatrix& deviceMatrix);
+ const SkMatrix& deviceMatrix,
+ SkScalar strikeToSourceRatio);
SkAutoDescriptor fAutoDescriptor;
sk_sp<SkMaskFilter> fMaskFilter;
sk_sp<SkPathEffect> fPathEffect;
sk_sp<SkTypeface> fTypeface;
- SkScalar fStrikeToSourceRatio{1.0f};
+ const SkScalar fStrikeToSourceRatio;
};
class SkBulkGlyphMetrics {