Skip to content

Commit 3f79f07

Browse files
herbderbySkia Commit-Bot
authored andcommitted
Use SkStrikeSpecStorage to lookup strike for GPU text drawing
Change-Id: If0d93ea722dc87ebb83e90159474a4ff702717a7 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212961 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Herb Derby <herb@google.com>
1 parent c8a84d2 commit 3f79f07

1 file changed

Lines changed: 30 additions & 75 deletions

File tree

src/core/SkGlyphRunPainter.cpp

Lines changed: 30 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "src/core/SkStrike.h"
3434
#include "src/core/SkStrikeCache.h"
3535
#include "src/core/SkStrikeInterface.h"
36+
#include "src/core/SkStrikeSpec.h"
3637
#include "src/core/SkTraceEvent.h"
3738

3839
#include <limits.h>
@@ -316,14 +317,11 @@ void SkGlyphRunListPainter::processARGBFallback(SkScalar maxSourceGlyphDimension
316317
point.fY = SkScalarFloorToScalar(point.fY);
317318
}
318319

319-
SkAutoDescriptor ad;
320-
SkScalerContextEffects effects;
321-
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
322-
runFont, runPaint, fDeviceProps, fScalerContextFlags, viewMatrix, &ad, &effects);
320+
SkStrikeSpecStorage strikeSpec =
321+
SkStrikeSpecStorage::MakeMask(runFont, runPaint,
322+
fDeviceProps, fScalerContextFlags, viewMatrix);
323323

324-
SkScopedStrike strike =
325-
fStrikeCache->findOrCreateScopedStrike(
326-
*ad.getDesc(), effects, *runFont.getTypefaceOrDefault());
324+
SkScopedStrike strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
327325

328326
SkSpan<const SkGlyphPos> glyphPosSpan = strike->prepareForDrawing(
329327
fARGBGlyphsIDs.data(),
@@ -359,19 +357,13 @@ void SkGlyphRunListPainter::processARGBFallback(SkScalar maxSourceGlyphDimension
359357
// The scale factor to go from strike size to the source size for glyphs.
360358
SkScalar fallbackTextScale = runFontTextSize / fallbackTextSize;
361359

362-
SkAutoDescriptor ad;
363-
SkScalerContextEffects effects;
364-
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(fallbackFont,
365-
runPaint,
366-
fDeviceProps,
367-
fScalerContextFlags,
368-
SkMatrix::I(),
369-
&ad,
370-
&effects);
360+
SkStrikeSpecStorage strikeSpec = SkStrikeSpecStorage::MakeMask(fallbackFont,
361+
runPaint,
362+
fDeviceProps,
363+
fScalerContextFlags,
364+
SkMatrix::I());
371365

372-
SkScopedStrike strike =
373-
fStrikeCache->findOrCreateScopedStrike(
374-
*ad.getDesc(), effects, *fallbackFont.getTypefaceOrDefault());
366+
SkScopedStrike strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
375367

376368
auto glyphPosSpan = strike->prepareForDrawing(fARGBGlyphsIDs.data(),
377369
fARGBPositions.data(),
@@ -426,27 +418,13 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
426418
SkMatrix::MakeTrans(origin.x(), origin.y())
427419
.mapPoints(fPositions, glyphRun.positions().data(), glyphRun.runSize());
428420

429-
// Setup distance field runPaint and text ratio
430-
SkPaint dfPaint = GrTextContext::InitDistanceFieldPaint(runPaint);
431-
SkScalar cacheToSourceScale;
432-
SkFont dfFont = GrTextContext::InitDistanceFieldFont(
433-
runFont, viewMatrix, options, &cacheToSourceScale);
434-
435-
// Fake-gamma and subpixel antialiasing are applied in the shader, so we ignore the
436-
// passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
437-
SkScalerContextFlags flags = SkScalerContextFlags::kNone;
438-
439421
SkScalar minScale, maxScale;
440-
std::tie(minScale, maxScale) = GrTextContext::InitDistanceFieldMinMaxScale(
441-
runFont.getSize(), viewMatrix, options);
422+
SkStrikeSpecStorage strikeSpec;
423+
std::tie(strikeSpec, minScale, maxScale) =
424+
SkStrikeSpecStorage::MakeSDFT(
425+
runFont, runPaint,fDeviceProps, viewMatrix, options);
442426

443-
SkAutoDescriptor ad;
444-
SkScalerContextEffects effects;
445-
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
446-
dfFont, dfPaint, fDeviceProps, flags, SkMatrix::I(), &ad, &effects);
447-
SkScopedStrike strike =
448-
fStrikeCache->findOrCreateScopedStrike(
449-
*ad.getDesc(), effects, *dfFont.getTypefaceOrDefault());
427+
SkScopedStrike strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
450428

451429
SkSpan<const SkGlyphPos> glyphPosSpan = strike->prepareForDrawing(
452430
glyphRun.glyphsIDs().data(),
@@ -485,20 +463,22 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
485463
SkSpan<const SkGlyphPos>{fGlyphPos, glyphsWithMaskCount},
486464
strike.get(),
487465
runFont,
488-
cacheToSourceScale,
466+
strikeSpec.strikeToSourceRatio(),
489467
minScale,
490468
maxScale,
491469
hasWCoord);
492470

493471
if (!fPaths.empty()) {
494472
process->processSourcePaths(
495-
SkSpan<const SkGlyphPos>{fPaths}, strike.get(), cacheToSourceScale);
473+
SkSpan<const SkGlyphPos>{fPaths},
474+
strike.get(),
475+
strikeSpec.strikeToSourceRatio());
496476
}
497477
}
498478

499479
// fGlyphPos will be reused here.
500480
if (!fARGBGlyphsIDs.empty()) {
501-
this->processARGBFallback(maxFallbackDimension * cacheToSourceScale,
481+
this->processARGBFallback(maxFallbackDimension * strikeSpec.strikeToSourceRatio(),
502482
runPaint, runFont, viewMatrix, process);
503483
}
504484
} else if (SkGlyphRunListPainter::ShouldDrawAsPath(runPaint, runFont, viewMatrix)) {
@@ -507,30 +487,10 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
507487
SkMatrix::MakeTrans(origin.x(), origin.y()).mapPoints(
508488
fPositions, glyphRun.positions().data(), glyphRun.runSize());
509489

510-
// setup our std runPaint, in hopes of getting hits in the cache
511-
SkPaint pathPaint{runPaint};
512-
SkFont pathFont{runFont};
513-
514-
// The factor to get from the size stored in the strike to the size needed for
515-
// the source.
516-
SkScalar strikeToSourceRatio = pathFont.setupForAsPaths(&pathPaint);
490+
SkStrikeSpecStorage strikeSpec = SkStrikeSpecStorage::MakePath(
491+
runFont, runPaint, fDeviceProps, fScalerContextFlags);
517492

518-
// The sub-pixel position will always happen when transforming to the screen.
519-
pathFont.setSubpixel(false);
520-
521-
SkAutoDescriptor ad;
522-
SkScalerContextEffects effects;
523-
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(pathFont,
524-
pathPaint,
525-
fDeviceProps,
526-
fScalerContextFlags,
527-
SkMatrix::I(),
528-
&ad,
529-
&effects);
530-
531-
SkScopedStrike strike =
532-
fStrikeCache->findOrCreateScopedStrike(
533-
*ad.getDesc(), effects,*pathFont.getTypefaceOrDefault());
493+
SkScopedStrike strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
534494

535495
SkSpan<const SkGlyphPos> glyphPosSpan = strike->prepareForDrawing(
536496
glyphRun.glyphsIDs().data(),
@@ -561,26 +521,21 @@ void SkGlyphRunListPainter::processGlyphRunList(const SkGlyphRunList& glyphRunLi
561521
process->processSourcePaths(
562522
SkSpan<const SkGlyphPos>{fGlyphPos, glyphsWithPathCount},
563523
strike.get(),
564-
strikeToSourceRatio);
524+
strikeSpec.strikeToSourceRatio());
565525
}
566526

567527
// fGlyphPos will be reused here.
568528
if (!fARGBGlyphsIDs.empty()) {
569-
this->processARGBFallback(maxFallbackDimension * strikeToSourceRatio,
529+
this->processARGBFallback(maxFallbackDimension * strikeSpec.strikeToSourceRatio(),
570530
runPaint, runFont, viewMatrix, process);
571531
}
572532
} else {
573533

574-
SkAutoDescriptor ad;
575-
SkScalerContextEffects effects;
576-
577-
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
578-
runFont, runPaint, fDeviceProps, fScalerContextFlags, viewMatrix, &ad,
579-
&effects);
534+
SkStrikeSpecStorage strikeSpec =
535+
SkStrikeSpecStorage::MakeMask(runFont, runPaint,
536+
fDeviceProps, fScalerContextFlags, viewMatrix);
580537

581-
SkTypeface* typeface = runFont.getTypefaceOrDefault();
582-
SkScopedStrike strike =
583-
fStrikeCache->findOrCreateScopedStrike(*ad.getDesc(), effects, *typeface);
538+
SkScopedStrike strike = strikeSpec.findOrCreateScopedStrike(fStrikeCache);
584539

585540
SkMatrix mapping = viewMatrix;
586541
mapping.preTranslate(origin.x(), origin.y());

0 commit comments

Comments
 (0)