Move remove ptr args to MakeRecAndEffects

Move this conversion out through the transitive closure of calls. As you
move up the stack, everything becomes refs instread of pointers.

Reorder args of MakeRecAndEffects and setupCache to match the majority of other
calls.

Change-Id: I72baf457cd9140f76ee5f7122493284c4be5bcd0
Reviewed-on: https://skia-review.googlesource.com/c/169765
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2018-11-08 16:40:26 -05:00 committed by Skia Commit-Bot
parent b07ed8fb07
commit b07aba4214
19 changed files with 116 additions and 106 deletions

View File

@ -46,7 +46,7 @@ private:
void onDelayedSetup() override {
SkPaint defaultPaint;
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(defaultPaint);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(defaultPaint);
for (int i = 0; i < kNumGlyphs; ++i) {
SkPackedGlyphID id(cache->unicharToGlyph(kGlyphs[i]));
sk_ignore_unused_variable(cache->getScalerContext()->getPath(id, &fGlyphs[i]));

View File

@ -21,7 +21,8 @@ static void do_font_stuff(SkPaint* paint) {
for (SkScalar i = 8; i < 64; i++) {
paint->setTextSize(i);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
*paint, nullptr, SkScalerContextFlags::kNone, nullptr);
*paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
SkScalerContextFlags::kNone, SkMatrix::I());
uint16_t glyphs['z'];
for (int c = ' '; c < 'z'; c++) {
glyphs[c] = cache->unicharToGlyph(c);

View File

@ -33,7 +33,7 @@ public:
void onOnceBeforeDraw() final {
SkPaint defaultPaint;
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(defaultPaint);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(defaultPaint);
SkPath glyphPaths[52];
for (int i = 0; i < 52; ++i) {
// I and l are rects on OS X ...

View File

@ -368,7 +368,7 @@ void SkGlyphRunBuilder::simplifyDrawText(
if (!glyphIDs.empty()) {
fScratchAdvances.resize(runSize);
{
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(runPaint);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(runPaint);
cache->getAdvances(glyphIDs, fScratchAdvances.data());
}

View File

@ -180,7 +180,7 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
SkScalar textScale = pathPaint.setupForAsPaths();
auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
pathPaint, &props, fScalerContextFlags, nullptr);
pathPaint, props, fScalerContextFlags, SkMatrix::I());
SkTDArray<PathAndPos> pathsAndPositions;
pathsAndPositions.setReserve(runSize);
@ -204,7 +204,7 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
paint);
} else {
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
paint, &props, fScalerContextFlags, &deviceMatrix);
paint, props, fScalerContextFlags, deviceMatrix);
// Add rounding and origin.
SkMatrix matrix = deviceMatrix;
@ -599,8 +599,8 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
fBlob->setHasBitmap();
fBlob->setSubRunHasW(fRunIndex, glyphCacheMatrix.hasPerspective());
SkExclusiveStrikePtr fallbackCache =
fBlob->setupCache(fRunIndex, fProps, fScalerContextFlags,
fallbackPaint, &glyphCacheMatrix);
fBlob->setupCache(fRunIndex,
fallbackPaint, fProps, fScalerContextFlags, glyphCacheMatrix);
sk_sp<GrTextStrike> strike = fGlyphCache->getStrike(fallbackCache.get());
const SkPoint* glyphPos = positions.data();
for (auto glyphID : glyphIDs) {
@ -649,7 +649,7 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
{
auto cache = this->setupCache(
runIndex, props, flags, distanceFieldPaint, &SkMatrix::I());
runIndex, distanceFieldPaint, props, flags, SkMatrix::I());
sk_sp<GrTextStrike> currStrike = glyphCache->getStrike(cache.get());
@ -698,7 +698,7 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
SkScalar textScale = pathPaint.setupForAsPaths();
auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
pathPaint, &props, scalerContextFlags, &SkMatrix::I());
pathPaint, props, scalerContextFlags, SkMatrix::I());
// Given a glyph that is not ARGB, draw it.
auto perPath = [textScale, runIndex, this, &pathCache]
@ -723,7 +723,7 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
this->setHasBitmap();
auto cache = this->setupCache(
runIndex, props, scalerContextFlags, runPaint, &viewMatrix);
runIndex, runPaint, props, scalerContextFlags, viewMatrix);
sk_sp<GrTextStrike> currStrike = glyphCache->getStrike(cache.get());

View File

@ -73,7 +73,7 @@ void SkOverdrawCanvas::drawPosTextCommon(const void* text, size_t byteLength, co
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
this->getProps(&props);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
paint, &props, SkScalerContextFlags::kNone, &this->getTotalMatrix());
paint, props, SkScalerContextFlags::kNone, this->getTotalMatrix());
SkFindAndPlaceGlyph::ProcessPosText(paint.getTextEncoding(), (const char*) text, byteLength,
SkPoint::Make(0, 0), SkMatrix(), (const SkScalar*) pos, 2,
cache.get(), processBounds);

View File

@ -102,7 +102,7 @@ int SkPaint::textToGlyphs(const void* textData, size_t byteLength, uint16_t glyp
return SkToInt(byteLength >> 1);
}
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(*this);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(*this);
const void* stop = (const char*)textData + byteLength;
uint16_t* gptr = glyphs;
@ -137,7 +137,7 @@ bool SkPaint::containsText(const void* textData, size_t byteLength) const {
return true;
}
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(*this);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(*this);
const void* stop = (const char*)textData + byteLength;
const SkTypeface::Encoding encoding = to_encoding(this->getTextEncoding());
while (textData < stop) {
@ -158,7 +158,7 @@ void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar tex
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
*this, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
*this, props, SkScalerContextFlags::kFakeGammaAndBoostContrast, SkMatrix::I());
for (int index = 0; index < count; index++) {
textData[index] = cache->glyphToUnichar(glyphs[index]);
@ -390,7 +390,7 @@ SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound
const SkPaint& paint = canon.getPaint();
SkScalar scale = canon.getScale();
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
SkScalar width = 0;
@ -443,7 +443,7 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
maxWidth /= scale;
}
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
false);
@ -486,7 +486,8 @@ SkScalar SkPaint::getFontMetrics(SkFontMetrics* metrics) const {
SkScalerContextEffects effects;
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
paint, nullptr, SkScalerContextFlags::kNone, nullptr, &ad, &effects);
paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
SkScalerContextFlags::kNone, SkMatrix::I(), &ad, &effects);
{
auto typeface = SkPaintPriv::GetTypefaceOrDefault(paint);
@ -525,7 +526,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength,
const SkPaint& paint = canon.getPaint();
SkScalar scale = canon.getScale();
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(paint);
auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
nullptr != bounds);
@ -787,9 +788,7 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
}
// SRGBTODO: Is this correct?
fCache = SkStrikeCache::FindOrCreateStrikeExclusive(
fPaint, nullptr,
SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
fCache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(fPaint);
SkPaint::Style style = SkPaint::kFill_Style;
sk_sp<SkPathEffect> pe;

View File

@ -64,7 +64,7 @@ static const SkDescriptor* create_descriptor(
SkScalerContextRec deviceRec;
bool enableTypefaceFiltering = (type == kDevice);
SkScalerContext::MakeRecAndEffects(
font, paint, &props, &m, flags, &deviceRec, effects, enableTypefaceFiltering);
font, paint, props, flags, m, &deviceRec, effects, enableTypefaceFiltering);
return SkScalerContext::AutoDescriptorGivenRecAndEffects(deviceRec, *effects, ad);
}

View File

@ -900,15 +900,14 @@ static SkFontHinting computeHinting(const SkFont& font) {
// The only reason this is not file static is because it needs the context of SkScalerContext to
// access SkPaint::computeLuminanceColor.
void SkScalerContext::MakeRecAndEffects(const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps* surfaceProps,
const SkMatrix* deviceMatrix,
void SkScalerContext::MakeRecAndEffects(const SkFont& font, const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& deviceMatrix,
SkScalerContextRec* rec,
SkScalerContextEffects* effects,
bool enableTypefaceFiltering) {
SkASSERT(deviceMatrix == nullptr || !deviceMatrix->hasPerspective());
SkASSERT(!deviceMatrix.hasPerspective());
sk_bzero(rec, sizeof(SkScalerContextRec));
@ -921,24 +920,19 @@ void SkScalerContext::MakeRecAndEffects(const SkFont& font,
bool checkPost2x2 = false;
if (deviceMatrix) {
const SkMatrix::TypeMask mask = deviceMatrix->getType();
if (mask & SkMatrix::kScale_Mask) {
rec->fPost2x2[0][0] = sk_relax(deviceMatrix->getScaleX());
rec->fPost2x2[1][1] = sk_relax(deviceMatrix->getScaleY());
checkPost2x2 = true;
} else {
rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
}
if (mask & SkMatrix::kAffine_Mask) {
rec->fPost2x2[0][1] = sk_relax(deviceMatrix->getSkewX());
rec->fPost2x2[1][0] = sk_relax(deviceMatrix->getSkewY());
checkPost2x2 = true;
} else {
rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0;
}
const SkMatrix::TypeMask mask = deviceMatrix.getType();
if (mask & SkMatrix::kScale_Mask) {
rec->fPost2x2[0][0] = sk_relax(deviceMatrix.getScaleX());
rec->fPost2x2[1][1] = sk_relax(deviceMatrix.getScaleY());
checkPost2x2 = true;
} else {
rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
}
if (mask & SkMatrix::kAffine_Mask) {
rec->fPost2x2[0][1] = sk_relax(deviceMatrix.getSkewX());
rec->fPost2x2[1][0] = sk_relax(deviceMatrix.getSkewY());
checkPost2x2 = true;
} else {
rec->fPost2x2[0][1] = rec->fPost2x2[1][0] = 0;
}
@ -989,9 +983,8 @@ void SkScalerContext::MakeRecAndEffects(const SkFont& font,
rec->fMaskFormat = SkMask::kA8_Format;
flags |= SkScalerContext::kGenA8FromLCD_Flag;
} else {
SkPixelGeometry geometry = surfaceProps
? surfaceProps->pixelGeometry()
: SkSurfacePropsDefaultPixelGeometry();
SkPixelGeometry geometry = surfaceProps.pixelGeometry();
switch (geometry) {
case kUnknown_SkPixelGeometry:
// eeek, can't support LCD
@ -1113,14 +1106,14 @@ SkDescriptor* SkScalerContext::MakeDescriptorForPaths(SkFontID typefaceID,
}
SkDescriptor* SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
const SkPaint& paint, const SkSurfaceProps* surfaceProps,
const SkPaint& paint, const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix* deviceMatrix, SkAutoDescriptor* ad,
const SkMatrix& deviceMatrix, SkAutoDescriptor* ad,
SkScalerContextEffects* effects) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
SkScalerContextRec rec;
MakeRecAndEffects(font, paint, surfaceProps, deviceMatrix, scalerContextFlags, &rec, effects);
MakeRecAndEffects(font, paint, surfaceProps, scalerContextFlags, deviceMatrix, &rec, effects);
return AutoDescriptorGivenRecAndEffects(rec, *effects, ad);
}

View File

@ -19,6 +19,7 @@
#include "SkMaskGamma.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkSurfacePriv.h"
#include "SkTypeface.h"
#include "SkWriteBuffer.h"
@ -311,25 +312,23 @@ public:
static bool GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma,
uint8_t* data);
static void MakeRecAndEffects(const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps* surfaceProps,
const SkMatrix* deviceMatrix,
static void MakeRecAndEffects(const SkFont& font, const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& deviceMatrix,
SkScalerContextRec* rec,
SkScalerContextEffects* effects,
bool enableTypefaceFiltering = true);
static void MakeRecAndEffectsUsingDefaultPaint(const SkFont& font,
const SkSurfaceProps* surfaceProps,
const SkMatrix* deviceMatrix,
SkScalerContextFlags scalerContextFlags,
SkScalerContextRec* rec,
SkScalerContextEffects* effects,
bool enableTypefaceFiltering = true) {
// If we are creating rec and effects from a font only, then there is no device around either.
static void MakeRecAndEffectsFromFont(const SkFont& font,
SkScalerContextRec* rec,
SkScalerContextEffects* effects,
bool enableTypefaceFiltering = true) {
SkPaint paint;
return MakeRecAndEffects(font, paint, surfaceProps, deviceMatrix, scalerContextFlags,
rec, effects, enableTypefaceFiltering);
return MakeRecAndEffects(
font, paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
SkScalerContextFlags::kNone, SkMatrix::I(), rec, effects, enableTypefaceFiltering);
}
static SkDescriptor* MakeDescriptorForPaths(SkFontID fontID,
@ -364,9 +363,9 @@ public:
SkAxisAlignment computeAxisAlignmentForHText() const;
static SkDescriptor* CreateDescriptorAndEffectsUsingPaint(
const SkPaint& paint, const SkSurfaceProps* surfaceProps,
const SkPaint& paint, const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix* deviceMatrix, SkAutoDescriptor* ad,
const SkMatrix& deviceMatrix, SkAutoDescriptor* ad,
SkScalerContextEffects* effects);
protected:

View File

@ -148,9 +148,9 @@ SkExclusiveStrikePtr SkStrikeCache::findOrCreateStrikeExclusive(
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(
const SkPaint& paint,
const SkSurfaceProps* surfaceProps,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix* deviceMatrix)
const SkMatrix& deviceMatrix)
{
SkAutoDescriptor ad;
SkScalerContextEffects effects;
@ -163,9 +163,10 @@ SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(
return FindOrCreateStrikeExclusive(*desc, effects, *tf);
}
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(const SkPaint& paint) {
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkPaint& paint) {
return FindOrCreateStrikeExclusive(
paint, nullptr, kFakeGammaAndBoostContrast, nullptr);
paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
kFakeGammaAndBoostContrast, SkMatrix::I());
}
void SkStrikeCache::PurgeAll() {

View File

@ -104,11 +104,11 @@ public:
static ExclusiveStrikePtr FindOrCreateStrikeExclusive(
const SkPaint& paint,
const SkSurfaceProps* surfaceProps,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix* deviceMatrix);
const SkMatrix& deviceMatrix);
static ExclusiveStrikePtr FindOrCreateStrikeExclusive(const SkPaint& paint);
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkPaint& paint);
static std::unique_ptr<SkScalerContext> CreateScalerContext(
const SkDescriptor&, const SkScalerContextEffects&, const SkTypeface&);

View File

@ -20,10 +20,6 @@ static inline SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps* p
}
}
static inline SkPixelGeometry SkSurfacePropsDefaultPixelGeometry() {
return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType).pixelGeometry();
}
constexpr size_t kIgnoreRowBytesValue = static_cast<size_t>(~0);
bool SkSurfaceValidateRasterInfo(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue);

View File

@ -14,6 +14,7 @@
#include "SkOTTable_OS_2.h"
#include "SkOnce.h"
#include "SkStream.h"
#include "SkSurfacePriv.h"
#include "SkTypeface.h"
#include "SkTypefaceCache.h"
@ -401,10 +402,7 @@ bool SkTypeface::onComputeBounds(SkRect* bounds) const {
SkScalerContextRec rec;
SkScalerContextEffects effects;
const SkSurfaceProps* defaultProps = nullptr;
const SkMatrix* noDeviceMatrix = nullptr;
SkScalerContext::MakeRecAndEffectsUsingDefaultPaint(
font, defaultProps, noDeviceMatrix, SkScalerContextFlags::kNone, &rec, &effects);
SkScalerContext::MakeRecAndEffectsFromFont(font, &rec, &effects);
SkAutoDescriptor ad;
SkScalerContextEffects noeffects;

View File

@ -59,10 +59,10 @@ sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount, int runCount) {
}
SkExclusiveStrikePtr GrTextBlob::setupCache(int runIndex,
const SkSurfaceProps& props,
SkScalerContextFlags scalerContextFlags,
const SkPaint& skPaint,
const SkMatrix* viewMatrix) {
const SkPaint& skPaint,
const SkSurfaceProps& props,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& viewMatrix) {
GrTextBlob::Run* run = &fRuns[runIndex];
// if we have an override descriptor for the run, then we should use that
@ -70,7 +70,7 @@ SkExclusiveStrikePtr GrTextBlob::setupCache(int runIndex,
&run->fDescriptor;
SkScalerContextEffects effects;
SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
skPaint, &props, scalerContextFlags, viewMatrix, desc, &effects);
skPaint, props, scalerContextFlags, viewMatrix, desc, &effects);
run->fTypeface = SkPaintPriv::RefTypefaceOrDefault(skPaint);
run->fPathEffect = sk_ref_sp(effects.fPathEffect);
run->fMaskFilter = sk_ref_sp(effects.fMaskFilter);

View File

@ -180,10 +180,10 @@ public:
}
SkExclusiveStrikePtr setupCache(int runIndex,
const SkPaint& skPaint,
const SkSurfaceProps& props,
SkScalerContextFlags scalerContextFlags,
const SkPaint& skPaint,
const SkMatrix* viewMatrix);
const SkMatrix& viewMatrix);
// Appends a glyph to the blob. If the glyph is too large, the glyph will be appended
// as a path.

View File

@ -46,7 +46,7 @@ SkExclusiveStrikePtr SkPDFFont::MakeVectorCache(SkTypeface* face, int* size) {
tmpPaint.setTextSize((SkScalar)unitsPerEm);
const SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
return SkStrikeCache::FindOrCreateStrikeExclusive(
tmpPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
tmpPaint, props, SkScalerContextFlags::kFakeGammaAndBoostContrast, SkMatrix::I());
}
namespace {

View File

@ -1873,8 +1873,8 @@ HRESULT SkXPSDevice::CreateTypefaceUse(const SkPaint& paint,
newTypefaceUse.xpsFont = xpsFontResource.release();
auto glyphCache =
SkStrikeCache::FindOrCreateStrikeExclusive(
paint, &this->surfaceProps(),
SkScalerContextFlags::kNone, nullptr);
paint, this->surfaceProps(),
SkScalerContextFlags::kNone, SkMatrix::I());
unsigned int glyphCount = glyphCache->getGlyphCount();
newTypefaceUse.glyphsUsed = new SkBitSet(glyphCount);
@ -2057,8 +2057,8 @@ void SkXPSDevice::drawPosText(const void* text, size_t byteLen,
auto cache =
SkStrikeCache::FindOrCreateStrikeExclusive(
paint, &this->surfaceProps(),
SkScalerContextFlags::kNone, nullptr);
paint, this->surfaceProps(),
SkScalerContextFlags::kNone, SkMatrix::I());
// Advance width and offsets for glyphs measured in hundredths of the font em size
// (XPS Spec 5.1.3).

View File

@ -14,6 +14,7 @@
#include "SkRemoteGlyphCacheImpl.h"
#include "SkStrikeCache.h"
#include "SkSurface.h"
#include "SkSurfacePriv.h"
#include "SkTestEmptyTypeface.h"
#include "SkTextBlob.h"
#include "SkTypeface_remote.h"
@ -118,12 +119,21 @@ SkTextBlobCacheDiffCanvas::Settings MakeSettings(GrContext* context) {
return settings;
}
sk_sp<SkSurface> MakeSurface(int width, int height, GrContext* context) {
const SkImageInfo info =
SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
}
const SkSurfaceProps FindSurfaceProps(GrContext* context) {
auto surface = MakeSurface(1, 1, context);
return surface->props();
}
SkBitmap RasterBlob(sk_sp<SkTextBlob> blob, int width, int height, const SkPaint& paint,
GrContext* context, const SkMatrix* matrix = nullptr,
SkScalar x = 0) {
const SkImageInfo info =
SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
auto surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
auto surface = MakeSurface(width, height, context);
if (matrix) surface->getCanvas()->concat(*matrix);
surface->getCanvas()->drawTextBlob(blob.get(), x, 0, paint);
SkBitmap bitmap;
@ -161,7 +171,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_StrikeSerialization, repor
int glyphCount = 10;
auto serverBlob = buildTextBlob(serverTf, glyphCount);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
auto props = FindSurfaceProps(ctxInfo.grContext());
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
MakeSettings(ctxInfo.grContext()));
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
@ -402,7 +412,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsPath, reporter,
int glyphCount = 10;
auto serverBlob = buildTextBlob(serverTf, glyphCount);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
auto props = FindSurfaceProps(ctxInfo.grContext());
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
MakeSettings(ctxInfo.grContext()));
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
@ -479,7 +489,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsMaskWithPathFall
auto serverBlob = make_blob_causing_fallback(serverTf, serverTf.get(), reporter);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
auto props = FindSurfaceProps(ctxInfo.grContext());
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
MakeSettings(ctxInfo.grContext()));
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
@ -519,7 +529,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextXY, reporter, ctxI
int glyphCount = 10;
auto serverBlob = buildTextBlob(serverTf, glyphCount);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
auto props = FindSurfaceProps(ctxInfo.grContext());
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
MakeSettings(ctxInfo.grContext()));
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0.5, 0, paint);
@ -648,7 +658,9 @@ DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
SkScalerContextRec rec;
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(
font, paint, SkSurfacePropsCopyOrDefault(nullptr), flags,
SkMatrix::I(), &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
@ -666,7 +678,9 @@ DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
SkScalerContextRec rec;
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(
font, paint, SkSurfacePropsCopyOrDefault(nullptr), flags,
SkMatrix::I(), &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto testCache = strikeCache.findStrikeExclusive(*desc);
REPORTER_ASSERT(reporter, !(testCache == nullptr));
@ -678,7 +692,10 @@ DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
SkScalerContextRec rec;
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kNone;
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(
font, paint, SkSurfacePropsCopyOrDefault(nullptr), flags,
SkMatrix::I(),
&rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
testCache = strikeCache.findStrikeExclusive(*desc);
REPORTER_ASSERT(reporter, testCache == nullptr);
@ -754,7 +771,9 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
paint.setTypeface(serverTf);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(
font, paint, SkSurfacePropsCopyOrDefault(nullptr), flags,
SkMatrix::I(), &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto context = serverTf->createScalerContext(effects, desc, false);
@ -772,7 +791,9 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
paint.setTypeface(clientTf);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(
font, paint, SkSurfacePropsCopyOrDefault(nullptr), flags,
SkMatrix::I(), &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
@ -791,7 +812,7 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
paint.setTypeface(serverTf);
auto* cacheState = server.getOrCreateCache(
paint, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
paint, SkSurfacePropsCopyOrDefault(nullptr),
SkMatrix::I(), flags, &effects);
cacheState->addGlyph(lostGlyphID, false);
@ -809,7 +830,9 @@ DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
SkScalerContextEffects effects;
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
paint.setTypeface(clientTf);
SkScalerContext::MakeRecAndEffects(font, paint, nullptr, nullptr, flags, &rec, &effects, false);
SkScalerContext::MakeRecAndEffects(
font, paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry), flags,
SkMatrix::I(), &rec, &effects, false);
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
auto fallbackCache = strikeCache.findStrikeExclusive(*desc);