Revert "fonts: Add support for distance field text to font remoting."

This reverts commit 35e0a1a690.

Reason for revert: looks like we're leaking paths?
https://chromium-swarm.appspot.com/task?id=3da25e2f0cadb210&refresh=10

Original change's description:
> fonts: Add support for distance field text to font remoting.
> 
> R=​jvanverth@google.com, herb@google.com
> 
> Bug: skia:7913
> Change-Id: Id3f5b3e75005be9a7234df774268359b406c99a8
> Reviewed-on: https://skia-review.googlesource.com/128970
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Jim Van Verth <jvanverth@google.com>
> Commit-Queue: Khusal Sagar <khushalsagar@chromium.org>

TBR=jvanverth@google.com,bsalomon@google.com,bungeman@google.com,herb@google.com,khushalsagar@chromium.org

Change-Id: I37c54c8748db9b20e1f48016d8298808a1999fdb
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7913
Reviewed-on: https://skia-review.googlesource.com/129681
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2018-05-23 00:15:37 +00:00 committed by Skia Commit-Bot
parent fc6cf92e4b
commit 7257e22e43
8 changed files with 63 additions and 210 deletions

View File

@ -282,8 +282,6 @@ public:
// Chrome is using this!
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
bool supportsDistanceFieldText() const;
protected:
GrContext(GrBackend, int32_t id = SK_InvalidGenID);

View File

@ -23,7 +23,6 @@
#if SK_SUPPORT_GPU
#include "GrDrawOpAtlas.h"
#include "text/GrAtlasTextContext.h"
#endif
static SkDescriptor* auto_descriptor_from_desc(const SkDescriptor* source_desc,
@ -189,18 +188,14 @@ public:
};
// -- SkTextBlobCacheDiffCanvas -------------------------------------------------------------------
SkTextBlobCacheDiffCanvas::Settings::Settings() = default;
SkTextBlobCacheDiffCanvas::Settings::~Settings() = default;
SkTextBlobCacheDiffCanvas::SkTextBlobCacheDiffCanvas(int width, int height,
const SkMatrix& deviceMatrix,
const SkSurfaceProps& props,
SkStrikeServer* strikeSever, Settings settings)
SkStrikeServer* strikeSever)
: SkNoDrawCanvas{sk_make_sp<TrackLayerDevice>(SkIRect::MakeWH(width, height), props)}
, fDeviceMatrix{deviceMatrix}
, fSurfaceProps{props}
, fStrikeServer{strikeSever}
, fSettings{settings} {
, fStrikeServer{strikeSever} {
SkASSERT(fStrikeServer);
}
@ -279,23 +274,6 @@ void SkTextBlobCacheDiffCanvas::processGlyphRun(
runMatrix.preTranslate(position.x(), position.y());
runMatrix.preTranslate(it.offset().x(), it.offset().y());
#if SK_SUPPORT_GPU
GrAtlasTextContext::Options options;
options.fMinDistanceFieldFontSize = fSettings.fMinDistanceFieldFontSize;
options.fMaxDistanceFieldFontSize = fSettings.fMaxDistanceFieldFontSize;
GrAtlasTextContext::SanitizeOptions(&options);
if (GrAtlasTextContext::CanDrawAsDistanceFields(runPaint, runMatrix, fSurfaceProps,
fSettings.fContextSupportsDistanceFieldText,
options)) {
SkScalar textRatio;
SkPaint dfPaint(runPaint);
SkScalerContextFlags flags;
GrAtlasTextContext::InitDistanceFieldPaint(nullptr, &dfPaint, runMatrix, options,
&textRatio, &flags);
this->processGlyphRunForDFT(it, dfPaint, flags);
}
#endif
// If the matrix has perspective, we fall back to using distance field text or paths.
// TODO: Add distance field text support, and FallbackTextHelper logic from GrAtlasTextContext.
if (SkDraw::ShouldDrawTextAsPaths(runPaint, runMatrix)) {
@ -356,11 +334,9 @@ void SkTextBlobCacheDiffCanvas::processGlyphRun(
SkScalerContextRec deviceSpecificRec;
SkScalerContextEffects effects;
auto* glyphCacheState =
static_cast<SkStrikeServer*>(fStrikeServer)
->getOrCreateCache(runPaint, &fSurfaceProps, &runMatrix,
SkScalerContextFlags::kFakeGammaAndBoostContrast,
&deviceSpecificRec, &effects);
auto* glyphCacheState = static_cast<SkStrikeServer*>(fStrikeServer)
->getOrCreateCache(runPaint, &fSurfaceProps, &runMatrix,
&deviceSpecificRec, &effects);
SkASSERT(glyphCacheState);
const bool asPath = false;
@ -393,35 +369,13 @@ void SkTextBlobCacheDiffCanvas::processGlyphRunForPaths(const SkTextBlobRunItera
pathPaint.setStyle(SkPaint::kFill_Style);
pathPaint.setPathEffect(nullptr);
SkScalerContextRec deviceSpecificRec;
SkScalerContextEffects effects;
auto* glyphCacheState =
static_cast<SkStrikeServer*>(fStrikeServer)
->getOrCreateCache(pathPaint, &fSurfaceProps, nullptr,
SkScalerContextFlags::kFakeGammaAndBoostContrast,
&deviceSpecificRec, &effects);
const bool asPath = true;
const SkIPoint subPixelPos{0, 0};
const uint16_t* glyphs = it.glyphs();
for (uint32_t index = 0; index < it.glyphCount(); index++) {
glyphCacheState->addGlyph(runPaint.getTypeface(),
effects,
SkPackedGlyphID(glyphs[index], subPixelPos.x(), subPixelPos.y()),
asPath);
}
}
void SkTextBlobCacheDiffCanvas::processGlyphRunForDFT(const SkTextBlobRunIterator& it,
const SkPaint& runPaint,
SkScalerContextFlags flags) {
SkScalerContextRec deviceSpecificRec;
SkScalerContextEffects effects;
auto* glyphCacheState = static_cast<SkStrikeServer*>(fStrikeServer)
->getOrCreateCache(runPaint, &fSurfaceProps, nullptr, flags,
->getOrCreateCache(pathPaint, &fSurfaceProps, nullptr,
&deviceSpecificRec, &effects);
const bool asPath = false;
const bool asPath = true;
const SkIPoint subPixelPos{0, 0};
const uint16_t* glyphs = it.glyphs();
for (uint32_t index = 0; index < it.glyphCount(); index++) {
@ -497,12 +451,15 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache(
const SkPaint& paint,
const SkSurfaceProps* props,
const SkMatrix* matrix,
SkScalerContextFlags flags,
SkScalerContextRec* deviceRec,
SkScalerContextEffects* effects) {
SkScalerContextRec keyRec;
SkScalerContext::MakeRecAndEffects(paint, props, matrix, flags, deviceRec, effects, true);
SkScalerContext::MakeRecAndEffects(paint, props, matrix, flags, &keyRec, effects, false);
SkScalerContext::MakeRecAndEffects(paint, props, matrix,
SkScalerContextFlags::kFakeGammaAndBoostContrast, deviceRec,
effects, true);
SkScalerContext::MakeRecAndEffects(paint, props, matrix,
SkScalerContextFlags::kFakeGammaAndBoostContrast, &keyRec,
effects, false);
TRACE_EVENT1("skia", "RecForDesc", "rec", TRACE_STR_COPY(keyRec.dump().c_str()));
// TODO: possible perf improvement - don't recompute the device desc on cache hit.

View File

@ -28,7 +28,6 @@ class Serializer;
class SkDescriptor;
class SkGlyphCache;
struct SkPackedGlyphID;
enum SkScalerContextFlags : uint32_t;
class SkScalerContextRecDescriptor;
class SkTextBlobRunIterator;
class SkTypefaceProxy;
@ -52,17 +51,8 @@ using SkDescriptorSet =
// which will be serialized and renderered using the SkStrikeClient.
class SK_API SkTextBlobCacheDiffCanvas : public SkNoDrawCanvas {
public:
struct SK_API Settings {
Settings();
~Settings();
bool fContextSupportsDistanceFieldText = true;
SkScalar fMinDistanceFieldFontSize = -1.f;
SkScalar fMaxDistanceFieldFontSize = -1.f;
};
SkTextBlobCacheDiffCanvas(int width, int height, const SkMatrix& deviceMatrix,
const SkSurfaceProps& props, SkStrikeServer* strikeserver,
Settings settings = Settings());
const SkSurfaceProps& props, SkStrikeServer* strikeserver);
~SkTextBlobCacheDiffCanvas() override;
protected:
@ -80,13 +70,10 @@ private:
const SkTextBlobRunIterator& it,
const SkPaint& runPaint);
void processGlyphRunForPaths(const SkTextBlobRunIterator& it, const SkPaint& runPaint);
void processGlyphRunForDFT(const SkTextBlobRunIterator& it, const SkPaint& runPaint,
SkScalerContextFlags flags);
const SkMatrix fDeviceMatrix;
const SkSurfaceProps fSurfaceProps;
SkStrikeServer* const fStrikeServer;
const Settings fSettings;
};
using SkDiscardableHandleId = uint32_t;
@ -174,7 +161,7 @@ public:
};
SkGlyphCacheState* getOrCreateCache(const SkPaint&, const SkSurfaceProps*, const SkMatrix*,
SkScalerContextFlags flags, SkScalerContextRec* deviceRec,
SkScalerContextRec* deviceRec,
SkScalerContextEffects* effects);
private:

View File

@ -1514,10 +1514,6 @@ bool GrContext::validPMUPMConversionExists() {
return fPMUPMConversionsRoundTrip;
}
bool GrContext::supportsDistanceFieldText() const {
return fCaps->shaderCaps()->supportsDistanceFieldText();
}
//////////////////////////////////////////////////////////////////////////////
// DDL TODO: remove 'maxResources'

View File

@ -37,8 +37,6 @@ public:
void dumpJSON(SkJSONWriter*) const;
bool supportsDistanceFieldText() const { return fShaderDerivativeSupport; }
bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; }
bool geometryShaderSupport() const { return fGeometryShaderSupport; }
bool gsInvocationsSupport() const { return fGSInvocationsSupport; }

View File

@ -41,8 +41,14 @@ static const int kDefaultMaxDistanceFieldFontSize = 2 * kLargeDFFontSize;
#endif
GrAtlasTextContext::GrAtlasTextContext(const Options& options)
: fDistanceAdjustTable(new GrDistanceFieldAdjustTable), fOptions(options) {
SanitizeOptions(&fOptions);
: fDistanceAdjustTable(new GrDistanceFieldAdjustTable) {
fMaxDistanceFieldFontSize = options.fMaxDistanceFieldFontSize < 0.f
? kDefaultMaxDistanceFieldFontSize
: options.fMaxDistanceFieldFontSize;
fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize < 0.f
? kDefaultMinDistanceFieldFontSize
: options.fMinDistanceFieldFontSize;
fDistanceFieldVerticesAlwaysHaveW = options.fDistanceFieldVerticesAlwaysHaveW;
}
std::unique_ptr<GrAtlasTextContext> GrAtlasTextContext::Make(const Options& options) {
@ -205,8 +211,7 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
}
cacheBlob->setRunPaintFlags(run, runPaint.skPaint().getFlags());
if (CanDrawAsDistanceFields(runPaint, viewMatrix, props,
shaderCaps.supportsDistanceFieldText(), fOptions)) {
if (this->canDrawAsDistanceFields(runPaint, viewMatrix, props, shaderCaps)) {
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: {
this->drawDFText(cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags,
@ -269,8 +274,7 @@ GrAtlasTextContext::makeDrawTextBlob(GrTextBlobCache* blobCache,
blob->initThrowawayBlob(viewMatrix, x, y);
blob->setRunPaintFlags(0, paint.skPaint().getFlags());
if (CanDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(),
fOptions)) {
if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) {
this->drawDFText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix,
text, byteLength, x, y);
} else {
@ -300,8 +304,7 @@ GrAtlasTextContext::makeDrawPosTextBlob(GrTextBlobCache* blobCache,
blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y());
blob->setRunPaintFlags(0, paint.skPaint().getFlags());
if (CanDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(),
fOptions)) {
if (this->canDrawAsDistanceFields(paint, viewMatrix, props, shaderCaps)) {
this->drawDFPosText(blob.get(), 0, glyphCache, props, paint, scalerContextFlags, viewMatrix,
text, byteLength, pos, scalarsPerPosition, offset);
} else {
@ -562,26 +565,16 @@ void GrAtlasTextContext::BmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
textRatio, true);
}
void GrAtlasTextContext::SanitizeOptions(Options* options) {
if (options->fMaxDistanceFieldFontSize < 0.f) {
options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;
}
if (options->fMinDistanceFieldFontSize < 0.f) {
options->fMinDistanceFieldFontSize = kDefaultMinDistanceFieldFontSize;
}
}
bool GrAtlasTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
const Options& options) {
const GrShaderCaps& caps) const {
if (!viewMatrix.hasPerspective()) {
SkScalar maxScale = viewMatrix.getMaxScale();
SkScalar scaledTextSize = maxScale * skPaint.getTextSize();
// Hinted text looks far better at small resolutions
// Scaling up beyond 2x yields undesireable artifacts
if (scaledTextSize < options.fMinDistanceFieldFontSize ||
scaledTextSize > options.fMaxDistanceFieldFontSize) {
if (scaledTextSize < fMinDistanceFieldFontSize ||
scaledTextSize > fMaxDistanceFieldFontSize) {
return false;
}
@ -596,7 +589,7 @@ bool GrAtlasTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const S
}
// mask filters modify alpha, which doesn't translate well to distance
if (skPaint.getMaskFilter() || !contextSupportsDistanceFieldText) {
if (skPaint.getMaskFilter() || !caps.shaderDerivativeSupport()) {
return false;
}
@ -608,12 +601,10 @@ bool GrAtlasTextContext::CanDrawAsDistanceFields(const SkPaint& skPaint, const S
return true;
}
void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
SkPaint* skPaint,
const SkMatrix& viewMatrix,
const Options& options,
SkScalar* textRatio,
SkScalerContextFlags* flags) {
const SkMatrix& viewMatrix) const {
SkScalar textSize = skPaint->getTextSize();
SkScalar scaledTextSize = textSize;
@ -636,7 +627,7 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
SkScalar dfMaskScaleFloor;
SkScalar dfMaskScaleCeil;
if (scaledTextSize <= kSmallDFFontLimit) {
dfMaskScaleFloor = options.fMinDistanceFieldFontSize;
dfMaskScaleFloor = fMinDistanceFieldFontSize;
dfMaskScaleCeil = kSmallDFFontLimit;
*textRatio = textSize / kSmallDFFontSize;
skPaint->setTextSize(SkIntToScalar(kSmallDFFontSize));
@ -647,7 +638,7 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
skPaint->setTextSize(SkIntToScalar(kMediumDFFontSize));
} else {
dfMaskScaleFloor = kMediumDFFontLimit;
dfMaskScaleCeil = options.fMaxDistanceFieldFontSize;
dfMaskScaleCeil = fMaxDistanceFieldFontSize;
*textRatio = textSize / kLargeDFFontSize;
skPaint->setTextSize(SkIntToScalar(kLargeDFFontSize));
}
@ -660,10 +651,7 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
// against these values to decide if we can reuse or not(ie, will a given scale change our mip
// level)
SkASSERT(dfMaskScaleFloor <= scaledTextSize && scaledTextSize <= dfMaskScaleCeil);
if (blob) {
blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize,
dfMaskScaleCeil / scaledTextSize);
}
blob->setMinAndMaxScale(dfMaskScaleFloor / scaledTextSize, dfMaskScaleCeil / scaledTextSize);
skPaint->setAntiAlias(true);
skPaint->setLCDRenderText(false);
@ -672,10 +660,6 @@ void GrAtlasTextContext::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
skPaint->setSubpixelText(true);
skPaint->setMaskFilter(GrSDFMaskFilter::Make());
// We apply the fake-gamma by altering the distance in the shader, so we ignore the
// passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
*flags = SkScalerContextFlags::kNone;
}
void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex,
@ -761,13 +745,12 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
return;
}
bool hasWCoord = viewMatrix.hasPerspective() || fOptions.fDistanceFieldVerticesAlwaysHaveW;
bool hasWCoord = viewMatrix.hasPerspective() || fDistanceFieldVerticesAlwaysHaveW;
// Setup distance field paint and text ratio
SkScalar textRatio;
SkPaint dfPaint(paint);
SkScalerContextFlags flags;
InitDistanceFieldPaint(blob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags);
this->initDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix);
blob->setHasDistanceField();
blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(),
paint.skPaint().isAntiAlias(), hasWCoord);
@ -777,7 +760,10 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
sk_sp<GrTextStrike> currStrike;
{
auto cache = blob->setupCache(runIndex, props, flags, dfPaint, nullptr);
// We apply the fake-gamma by altering the distance in the shader, so we ignore the
// passed-in scaler context flags. (It's only used when we fall-back to bitmap text).
auto cache = blob->setupCache(runIndex, props, SkScalerContextFlags::kNone, dfPaint,
nullptr);
SkPaint::GlyphCacheProc glyphCacheProc =
SkPaint::GetGlyphCacheProc(dfPaint.getTextEncoding(), true);

View File

@ -60,18 +60,6 @@ public:
const SkMatrix& viewMatrix, const char* text,
int x, int y);
static void SanitizeOptions(Options* options);
static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
const Options& options);
static void InitDistanceFieldPaint(GrAtlasTextBlob* blob,
SkPaint* skPaint,
const SkMatrix& viewMatrix,
const Options& options,
SkScalar* textRatio,
SkScalerContextFlags* flags);
private:
GrAtlasTextContext(const Options& options);
@ -170,6 +158,9 @@ private:
const SkPoint& offset);
// functions for appending distance field text
bool canDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkSurfaceProps& props, const GrShaderCaps& caps) const;
void drawDFText(GrAtlasTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&,
const GrTextUtils::Paint& paint, SkScalerContextFlags scalerContextFlags,
const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x,
@ -182,6 +173,11 @@ private:
size_t byteLength, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) const;
void initDistanceFieldPaint(GrAtlasTextBlob* blob,
SkPaint* skPaint,
SkScalar* textRatio,
const SkMatrix& viewMatrix) const;
static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy,
GrColor color, SkGlyphCache*, SkScalar textRatio);
@ -194,7 +190,9 @@ private:
sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
Options fOptions;
SkScalar fMinDistanceFieldFontSize;
SkScalar fMaxDistanceFieldFontSize;
bool fDistanceFieldVerticesAlwaysHaveW;
#if GR_TEST_UTILS
static const SkScalerContextFlags kTextBlobOpScalerContextFlags =

View File

@ -15,10 +15,6 @@
#include "SkTypeface_remote.h"
#include "Test.h"
#if SK_SUPPORT_GPU
#include "text/GrAtlasTextContext.h"
#endif
class DiscardableManager : public SkStrikeServer::DiscardableHandleManager,
public SkStrikeClient::DiscardableHandleManager {
public:
@ -83,26 +79,14 @@ sk_sp<SkTextBlob> buildTextBlob(sk_sp<SkTypeface> tf, int glyphCount) {
} \
}
#if SK_SUPPORT_GPU
SkTextBlobCacheDiffCanvas::Settings MakeSettings(GrContext* context) {
SkTextBlobCacheDiffCanvas::Settings settings;
settings.fContextSupportsDistanceFieldText = context->supportsDistanceFieldText();
return settings;
}
SkBitmap RasterBlob(sk_sp<SkTextBlob> blob, int width, int height, const SkPaint& paint,
GrContext* context, const SkMatrix* matrix = nullptr) {
const SkImageInfo info =
SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
auto surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
if (matrix) surface->getCanvas()->concat(*matrix);
SkBitmap RasterBlob(sk_sp<SkTextBlob> blob, int width, int height, const SkPaint& paint) {
auto surface = SkSurface::MakeRasterN32Premul(width, height);
surface->getCanvas()->drawTextBlob(blob.get(), 0u, 0u, paint);
SkBitmap bitmap;
bitmap.allocN32Pixels(width, height);
surface->readPixels(bitmap, 0, 0);
return bitmap;
}
#endif
DEF_TEST(SkRemoteGlyphCache_TypefaceSerialization, reporter) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
@ -118,8 +102,7 @@ DEF_TEST(SkRemoteGlyphCache_TypefaceSerialization, reporter) {
server_tf->uniqueID());
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_StrikeSerialization, reporter, ctxInfo) {
DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
SkStrikeServer server(discardableManager.get());
SkStrikeClient client(discardableManager);
@ -132,8 +115,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_StrikeSerialization, repor
int glyphCount = 10;
auto serverBlob = buildTextBlob(serverTf, glyphCount);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
MakeSettings(ctxInfo.grContext()));
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server);
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
std::vector<uint8_t> serverStrikeData;
@ -145,11 +127,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_StrikeSerialization, repor
client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
auto clientBlob = buildTextBlob(clientTf, glyphCount);
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext());
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext());
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint);
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint);
COMPARE_BLOBS(expected, actual, reporter);
}
#endif
DEF_TEST(SkRemoteGlyphCache_StrikeLockingServer, reporter) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
@ -269,8 +250,7 @@ DEF_TEST(SkRemoteGlyphCache_ClientMemoryAccounting, reporter) {
SkStrikeCache::Validate();
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsPath, reporter, ctxInfo) {
DEF_TEST(SkRemoteGlyphCache_DrawTextAsPath, reporter) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
SkStrikeServer server(discardableManager.get());
SkStrikeClient client(discardableManager);
@ -286,8 +266,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsPath, reporter,
int glyphCount = 10;
auto serverBlob = buildTextBlob(serverTf, glyphCount);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
MakeSettings(ctxInfo.grContext()));
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server);
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
std::vector<uint8_t> serverStrikeData;
@ -299,54 +278,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsPath, reporter,
client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
auto clientBlob = buildTextBlob(clientTf, glyphCount);
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext());
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext());
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint);
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint);
COMPARE_BLOBS(expected, actual, reporter);
SkStrikeCache::Validate();
}
#endif
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, ctxInfo) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
SkStrikeServer server(discardableManager.get());
SkStrikeClient client(discardableManager);
SkPaint paint;
// A perspective transform forces fallback to dft.
SkMatrix matrix = SkMatrix::I();
matrix[SkMatrix::kMPersp0] = 0.5f;
REPORTER_ASSERT(reporter, matrix.hasPerspective());
SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
GrAtlasTextContext::Options options;
GrAtlasTextContext::SanitizeOptions(&options);
REPORTER_ASSERT(reporter, GrAtlasTextContext::CanDrawAsDistanceFields(
paint, matrix, surfaceProps, true, options));
// Server.
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
auto serverTfData = server.serializeTypeface(serverTf.get());
int glyphCount = 10;
auto serverBlob = buildTextBlob(serverTf, glyphCount);
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
MakeSettings(ctxInfo.grContext()));
cache_diff_canvas.concat(matrix);
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
std::vector<uint8_t> serverStrikeData;
server.writeStrikeData(&serverStrikeData);
// Client.
auto clientTf = client.deserializeTypeface(serverTfData->data(), serverTfData->size());
REPORTER_ASSERT(reporter,
client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
auto clientBlob = buildTextBlob(clientTf, glyphCount);
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext(), &matrix);
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext(), &matrix);
COMPARE_BLOBS(expected, actual, reporter);
SkStrikeCache::Validate();
}
#endif