Consolidate glyph attributes in SkGlyphDigest

SkGlyphDigest encompasses glyph attributes used early in the
text drawing stack. This is a newer class, so move functions and
constants  to  SkGlyphDigest that were historically misplaced.

Change-Id: Iec20c9a96fd7f4adf560f0c385dfd90abf13f009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/557579
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-07-11 13:50:40 -04:00 committed by SkCQ
parent 4e085a7ab0
commit 6aa1170c10
12 changed files with 35 additions and 54 deletions

View File

@ -379,7 +379,6 @@ skia_core_sources = [
"$_src/core/SkStreamPriv.h",
"$_src/core/SkStrikeCache.cpp",
"$_src/core/SkStrikeCache.h",
"$_src/core/SkStrikeForGPU.cpp",
"$_src/core/SkStrikeForGPU.h",
"$_src/core/SkStrikeSpec.cpp",
"$_src/core/SkStrikeSpec.h",

View File

@ -664,7 +664,6 @@ BASE_SRCS_ALL = [
"src/core/SkStreamPriv.h",
"src/core/SkStrikeCache.cpp",
"src/core/SkStrikeCache.h",
"src/core/SkStrikeForGPU.cpp",
"src/core/SkStrikeForGPU.h",
"src/core/SkStrikeSpec.cpp",
"src/core/SkStrikeSpec.h",

View File

@ -325,7 +325,6 @@ CORE_FILES = [
"SkStreamPriv.h",
"SkStrikeCache.cpp",
"SkStrikeCache.h",
"SkStrikeForGPU.cpp",
"SkStrikeForGPU.h",
"SkStrikeSpec.cpp",
"SkStrikeSpec.h",

View File

@ -329,7 +329,7 @@ void RemoteStrike::writePendingGlyphs(Serializer* serializer) {
write_glyph(glyph, serializer);
auto imageSize = glyph.imageSize();
if (imageSize > 0 && FitsInAtlas(glyph)) {
if (imageSize > 0 && SkGlyphDigest::FitsInAtlas(glyph)) {
glyph.setImage(serializer->allocate(imageSize, glyph.formatAlignment()));
fContext->getImage(glyph);
}
@ -1052,7 +1052,7 @@ bool SkStrikeClientImpl::readStrikeData(const volatile void* memory, size_t memo
SkTLazy<SkGlyph> glyph;
if (!ReadGlyph(glyph, &deserializer)) READ_FAILURE
if (!glyph->isEmpty() && StrikeForGPU::FitsInAtlas(*glyph)) {
if (!glyph->isEmpty() && SkGlyphDigest::FitsInAtlas(*glyph)) {
const volatile void* image =
deserializer.read(glyph->imageSize(), glyph->formatAlignment());
if (!image) READ_FAILURE

View File

@ -402,13 +402,30 @@ SkGlyphDigest::SkGlyphDigest(size_t index, const SkGlyph& glyph)
: fIndex{SkTo<uint32_t>(index)}
, fIsEmpty(glyph.isEmpty())
, fIsColor(glyph.isColor())
, fCanDrawAsMask{sktext::gpu::StrikeForGPU::CanDrawAsMask(glyph)}
, fCanDrawAsSDFT{sktext::gpu::StrikeForGPU::CanDrawAsSDFT(glyph)}
, fCanDrawAsMask{CanDrawAsMask(glyph)}
, fCanDrawAsSDFT{CanDrawAsSDFT(glyph)}
, fLeft{SkTo<int16_t>(glyph.left())}
, fTop{SkTo<int16_t>(glyph.top())}
, fWidth{SkTo<uint16_t>(glyph.width())}
, fHeight{SkTo<uint16_t>(glyph.height())} {}
bool SkGlyphDigest::CanDrawAsMask(const SkGlyph& glyph) {
return FitsInAtlas(glyph);
}
bool SkGlyphDigest::CanDrawAsSDFT(const SkGlyph& glyph) {
return FitsInAtlas(glyph) && glyph.maskFormat() == SkMask::kSDF_Format;
}
bool SkGlyphDigest::CanDrawAsPath(const SkGlyph& glyph) {
SkASSERT(glyph.setPathHasBeenCalled());
return glyph.path() != nullptr;
}
bool SkGlyphDigest::FitsInAtlas(const SkGlyph& glyph) {
return glyph.maxDimension() <= kSkSideTooBigForAtlas;
}
// -- SkGlyphPositionRoundingSpec ------------------------------------------------------------------
SkVector SkGlyphPositionRoundingSpec::HalfAxisSampleFreq(
bool isSubpixel, SkAxisAlignment axisAlignment) {

View File

@ -285,6 +285,10 @@ class SkGlyph;
// SkGlyphDigest is the only information that needs to be stored in the cache.
class SkGlyphDigest {
public:
// An atlas consists of plots, and plots hold glyphs. The minimum a plot can be is 256x256.
// This means that the maximum size a glyph can be is 256x256.
static constexpr uint16_t kSkSideTooBigForAtlas = 256;
// Default ctor is only needed for the hash table.
SkGlyphDigest() = default;
SkGlyphDigest(size_t index, const SkGlyph& glyph);
@ -297,6 +301,12 @@ public:
return std::max(fWidth, fHeight);
}
// Common categories for glyph types used by GPU.
static bool CanDrawAsMask(const SkGlyph& glyph);
static bool CanDrawAsSDFT(const SkGlyph& glyph);
static bool CanDrawAsPath(const SkGlyph& glyph);
static bool FitsInAtlas(const SkGlyph& glyph);
private:
static_assert(SkPackedGlyphID::kEndData == 20);
struct {

View File

@ -17,13 +17,6 @@ namespace sktext {
class GlyphRunList;
}
class SkStrikeCommon {
public:
// An atlas consists of plots, and plots hold glyphs. The minimum a plot can be is 256x256.
// This means that the maximum size a glyph can be is 256x256.
inline static constexpr uint16_t kSkSideTooBigForAtlas = 256;
};
// -- SkGlyphRunListPainterCPU ---------------------------------------------------------------------
class SkGlyphRunListPainterCPU {
public:

View File

@ -1,29 +0,0 @@
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/core/SkStrikeForGPU.h"
#include "src/core/SkGlyphRunPainter.h"
namespace sktext::gpu {
bool StrikeForGPU::CanDrawAsMask(const SkGlyph& glyph) {
return FitsInAtlas(glyph);
}
bool StrikeForGPU::CanDrawAsSDFT(const SkGlyph& glyph) {
return FitsInAtlas(glyph) && glyph.maskFormat() == SkMask::kSDF_Format;
}
bool StrikeForGPU::CanDrawAsPath(const SkGlyph& glyph) {
SkASSERT(glyph.setPathHasBeenCalled());
return glyph.path() != nullptr;
}
bool StrikeForGPU::FitsInAtlas(const SkGlyph& glyph) {
return glyph.maxDimension() <= SkStrikeCommon::kSkSideTooBigForAtlas;
}
} // namespace sktext::gpu

View File

@ -56,13 +56,6 @@ public:
// Return the maximum dimension of a span of glyphs.
virtual SkScalar findMaximumGlyphDimension(SkSpan<const SkGlyphID> glyphs) = 0;
// Common categories for glyph types used by GPU.
static bool CanDrawAsMask(const SkGlyph& glyph);
static bool CanDrawAsSDFT(const SkGlyph& glyph);
static bool CanDrawAsPath(const SkGlyph& glyph);
static bool FitsInAtlas(const SkGlyph& glyph);
struct Deleter {
void operator()(StrikeForGPU* ptr) const {
ptr->onAboutToExitScope();

View File

@ -49,7 +49,7 @@ SDFTControl::SDFTControl(
bool SDFTControl::isDirect(SkScalar approximateDeviceTextSize, const SkPaint& paint) const {
return !fForcePaths &&
!isSDFT(approximateDeviceTextSize, paint) &&
approximateDeviceTextSize < SkStrikeCommon::kSkSideTooBigForAtlas;
approximateDeviceTextSize < SkGlyphDigest::kSkSideTooBigForAtlas;
}
bool SDFTControl::isSDFT(SkScalar approximateDeviceTextSize, const SkPaint& paint) const {

View File

@ -1261,7 +1261,7 @@ SubRunOwner DirectMaskSubRun::Make(const SkZip<SkGlyphVariant, SkPoint>& accepte
// atlas. This boundary is checked below to ensure that the call to SkGlyphRect below will
// not overflow.
constexpr SkScalar kMaxPos =
std::numeric_limits<int16_t>::max() - SkStrikeCommon::kSkSideTooBigForAtlas;
std::numeric_limits<int16_t>::max() - SkGlyphDigest::kSkSideTooBigForAtlas;
SkGlyphRect runBounds = skglyph::empty_rect();
size_t goodPosCount = 0;
for (auto [variant, pos] : accepted) {
@ -2673,7 +2673,7 @@ std::tuple<bool, SubRunContainerOwner> SubRunContainer::MakeInAlloc(
// Remember, this will be an integer. Reduce to make a one pixel border for the
// bilerp padding.
static const constexpr SkScalar kMaxBilerpAtlasDimension =
SkStrikeCommon::kSkSideTooBigForAtlas - 2;
SkGlyphDigest::kSkSideTooBigForAtlas - 2;
// Get the raw glyph IDs to simulate device drawing to figure the maximum device
// dimension.

View File

@ -644,7 +644,7 @@ sk_sp<SkTextBlob> make_blob_causing_fallback(
SkRect glyphBounds;
font.getWidths(runBuffer.glyphs, 1, nullptr, &glyphBounds);
REPORTER_ASSERT(reporter, glyphBounds.width() > SkStrikeCommon::kSkSideTooBigForAtlas);
REPORTER_ASSERT(reporter, glyphBounds.width() > SkGlyphDigest::kSkSideTooBigForAtlas);
for (int i = 0; i < runSize; i++) {
runBuffer.pos[i] = i * 10;