Introduce SkStrikeCacheInterface

Introduce SkStrikeCacheInterface in order to move from a
template a based interface on SkGlyphRunListPainter to
a class based interface.

Change-Id: Ib15e437420c00f4e11242ac1a4d8a87ee2af9ee1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/197101
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2019-03-04 11:20:28 -05:00 committed by Skia Commit-Bot
parent b6c15babd5
commit 0f27b5ee2b
9 changed files with 121 additions and 76 deletions

View File

@ -133,8 +133,6 @@ skia_core_sources = [
"$_src/core/SkGlobalInitialization_core.cpp",
"$_src/core/SkGlyph.h",
"$_src/core/SkGlyph.cpp",
"$_src/core/SkStrike.cpp",
"$_src/core/SkStrike.h",
"$_src/core/SkGlyphRun.cpp",
"$_src/core/SkGlyphRun.h",
"$_src/core/SkGlyphRunPainter.cpp",
@ -264,8 +262,11 @@ skia_core_sources = [
"$_src/core/SkSpriteBlitter.h",
"$_src/core/SkStream.cpp",
"$_src/core/SkStreamPriv.h",
"$_src/core/SkStrike.cpp",
"$_src/core/SkStrike.h",
"$_src/core/SkStrikeCache.cpp",
"$_src/core/SkStrikeCache.h",
"$_src/core/SkStrikeInterface.h",
"$_src/core/SkString.cpp",
"$_src/core/SkStringUtils.cpp",
"$_src/core/SkStroke.h",

View File

@ -29,6 +29,7 @@
#include "SkPathEffect.h"
#include "SkRasterClip.h"
#include "SkRemoteGlyphCacheImpl.h"
#include "SkStrikeInterface.h"
#include "SkStrike.h"
#include "SkStrikeCache.h"
#include "SkTDArray.h"
@ -1074,7 +1075,7 @@ void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForMask(
auto creator = [this]
(const SkDescriptor& desc, SkScalerContextEffects effects, const SkTypeface& typeface) {
return SkScopedStrike{fStrikeServer->getOrCreateCache(desc, typeface, effects)};
return fStrikeServer->findOrCreateScopedStrike(desc, effects, typeface);
};
auto processMasks = [] (
@ -1099,7 +1100,7 @@ void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
auto creator = [this]
(const SkDescriptor& desc, SkScalerContextEffects effects, const SkTypeface& typeface) {
return SkScopedStrike{fStrikeServer->getOrCreateCache(desc, typeface, effects)};
return fStrikeServer->findOrCreateScopedStrike(desc, effects, typeface);
};
// This processor is empty because all changes to the cache are tracked through
@ -1160,7 +1161,7 @@ bool SkTextBlobCacheDiffCanvas::TrackLayerDevice::maybeProcessGlyphRunForDFT(
auto creator = [this]
(const SkDescriptor& desc, SkScalerContextEffects effects, const SkTypeface& typeface) {
return SkScopedStrike{fStrikeServer->getOrCreateCache(desc, typeface, effects)};
return fStrikeServer->findOrCreateScopedStrike(desc, effects, typeface);
};
fPainter.drawGlyphRunAsSDFWithARGBFallback(

View File

@ -20,45 +20,6 @@ class GrColorSpaceInfo;
class GrRenderTargetContext;
#endif
class SkStrikeSpec {
public:
SkStrikeSpec(const SkDescriptor& desc,
const SkTypeface& typeface,
const SkScalerContextEffects& effects)
: fDesc{desc}
, fTypeface{typeface}
, fEffects{effects} {}
const SkDescriptor& desc() const { return fDesc; }
const SkTypeface& typeface() const { return fTypeface; }
SkScalerContextEffects effects() const {return fEffects; }
private:
const SkDescriptor& fDesc;
const SkTypeface& fTypeface;
const SkScalerContextEffects fEffects;
};
class SkStrikeInterface {
public:
virtual ~SkStrikeInterface() = default;
virtual SkVector rounding() const = 0;
virtual const SkDescriptor& getDescriptor() const = 0;
virtual SkStrikeSpec strikeSpec() const = 0;
virtual const SkGlyph& getGlyphMetrics(SkGlyphID glyphID, SkPoint position) = 0;
virtual bool decideCouldDrawFromPath(const SkGlyph& glyph) = 0;
virtual void onAboutToExitScope() = 0;
struct Deleter {
void operator()(SkStrikeInterface* ptr) const {
ptr->onAboutToExitScope();
}
};
};
using SkScopedStrike = std::unique_ptr<SkStrikeInterface, SkStrikeInterface::Deleter>;
class SkStrikeCommon {
public:
static SkVector PixelRounding(bool isSubpixel, SkAxisAlignment axisAlignment);

View File

@ -315,6 +315,24 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache(
}
SkScopedStrike SkStrikeServer::findOrCreateScopedStrike(const SkDescriptor& desc,
const SkScalerContextEffects& effects,
const SkTypeface& typeface) {
return SkScopedStrike{this->getOrCreateCache(desc, typeface, effects)};
}
void SkStrikeServer::checkForDeletedEntries() {
auto it = fRemoteGlyphStateMap.begin();
while (fRemoteGlyphStateMap.size() > fMaxEntriesInDescriptorMap &&
it != fRemoteGlyphStateMap.end()) {
if (fDiscardableHandleManager->isHandleDeleted(it->second->discardableHandleId())) {
it = fRemoteGlyphStateMap.erase(it);
} else {
++it;
}
}
}
SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache(
const SkDescriptor& desc, const SkTypeface& typeface, SkScalerContextEffects effects) {
@ -381,18 +399,6 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache(
return cacheStatePtr;
}
void SkStrikeServer::checkForDeletedEntries() {
auto it = fRemoteGlyphStateMap.begin();
while (fRemoteGlyphStateMap.size() > fMaxEntriesInDescriptorMap &&
it != fRemoteGlyphStateMap.end()) {
if (fDiscardableHandleManager->isHandleDeleted(it->second->discardableHandleId())) {
it = fRemoteGlyphStateMap.erase(it);
} else {
++it;
}
}
}
// -- SkGlyphCacheState ----------------------------------------------------------------------------
SkStrikeServer::SkGlyphCacheState::SkGlyphCacheState(
const SkDescriptor& descriptor,

View File

@ -22,6 +22,7 @@
#include "SkNoDrawCanvas.h"
#include "SkRefCnt.h"
#include "SkSerialProcs.h"
#include "SkStrikeInterface.h"
#include "SkTypeface.h"
class Serializer;
@ -86,7 +87,7 @@ private:
using SkDiscardableHandleId = uint32_t;
// This class is not thread-safe.
class SK_API SkStrikeServer {
class SK_API SkStrikeServer final : public SkStrikeCacheInterface {
public:
// An interface used by the server to create handles for pinning SkStrike
// entries on the remote client.
@ -113,7 +114,7 @@ public:
};
explicit SkStrikeServer(DiscardableHandleManager* discardableHandleManager);
~SkStrikeServer();
~SkStrikeServer() override;
// Serializes the typeface to be remoted using this server.
sk_sp<SkData> serializeTypeface(SkTypeface*);
@ -133,9 +134,9 @@ public:
SkScalerContextFlags flags,
SkScalerContextEffects* effects);
SkGlyphCacheState* getOrCreateCache(const SkDescriptor& desc,
const SkTypeface& typeface,
SkScalerContextEffects effects);
SkScopedStrike findOrCreateScopedStrike(const SkDescriptor& desc,
const SkScalerContextEffects& effects,
const SkTypeface& typeface) override;
void setMaxEntriesInDescriptorMapForTesting(size_t count) {
fMaxEntriesInDescriptorMap = count;
@ -147,6 +148,10 @@ private:
void checkForDeletedEntries();
SkGlyphCacheState* getOrCreateCache(const SkDescriptor& desc,
const SkTypeface& typeface,
SkScalerContextEffects effects);
SkDescriptorMap<std::unique_ptr<SkGlyphCacheState>> fRemoteGlyphStateMap;
DiscardableHandleManager* const fDiscardableHandleManager;
SkTHashSet<SkFontID> fCachedTypefaces;

View File

@ -19,6 +19,7 @@
#include "SkMaskGamma.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkStrikeInterface.h"
#include "SkSurfacePriv.h"
#include "SkTypeface.h"
#include "SkWriteBuffer.h"
@ -37,18 +38,6 @@ enum SkScalerContextFlags : uint32_t {
kFakeGammaAndBoostContrast = kFakeGamma | kBoostContrast,
};
struct SkScalerContextEffects {
SkScalerContextEffects() : fPathEffect(nullptr), fMaskFilter(nullptr) {}
SkScalerContextEffects(SkPathEffect* pe, SkMaskFilter* mf)
: fPathEffect(pe), fMaskFilter(mf) {}
explicit SkScalerContextEffects(const SkPaint& paint)
: fPathEffect(paint.getPathEffect())
, fMaskFilter(paint.getMaskFilter()) {}
SkPathEffect* fPathEffect;
SkMaskFilter* fMaskFilter;
};
enum SkAxisAlignment : uint32_t {
kNone_SkAxisAlignment,
kX_SkAxisAlignment,

View File

@ -16,6 +16,7 @@
#include "SkPaint.h"
#include "SkTHash.h"
#include "SkScalerContext.h"
#include "SkStrikeInterface.h"
#include "SkTemplates.h"
#include <memory>

View File

@ -39,12 +39,12 @@ public:
virtual bool canDelete() = 0;
};
class SkStrikeCache {
class SkStrikeCache final : public SkStrikeCacheInterface {
class Node;
public:
SkStrikeCache() = default;
~SkStrikeCache();
~SkStrikeCache() override;
class ExclusiveStrikePtr {
public:
@ -116,7 +116,7 @@ public:
SkScopedStrike findOrCreateScopedStrike(const SkDescriptor& desc,
const SkScalerContextEffects& effects,
const SkTypeface& typeface);
const SkTypeface& typeface) override;
static ExclusiveStrikePtr FindOrCreateStrikeExclusive(
const SkFont& font,

View File

@ -0,0 +1,81 @@
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkStrikeInterface_DEFINED
#define SkStrikeInterface_DEFINED
#include <memory>
#include "SkPoint.h"
#include "SkTypes.h"
class SkDescriptor;
class SkGlyph;
class SkMaskFilter;
class SkPathEffect;
class SkTypeface;
// TODO: rename SkScalerContextEffects -> SkStrikeEffects
struct SkScalerContextEffects {
SkScalerContextEffects() : fPathEffect(nullptr), fMaskFilter(nullptr) {}
SkScalerContextEffects(SkPathEffect* pe, SkMaskFilter* mf)
: fPathEffect(pe), fMaskFilter(mf) {}
explicit SkScalerContextEffects(const SkPaint& paint)
: fPathEffect(paint.getPathEffect())
, fMaskFilter(paint.getMaskFilter()) {}
SkPathEffect* fPathEffect;
SkMaskFilter* fMaskFilter;
};
class SkStrikeSpec {
public:
SkStrikeSpec(const SkDescriptor& desc,
const SkTypeface& typeface,
const SkScalerContextEffects& effects)
: fDesc{desc}
, fTypeface{typeface}
, fEffects{effects} {}
const SkDescriptor& desc() const { return fDesc; }
const SkTypeface& typeface() const { return fTypeface; }
SkScalerContextEffects effects() const {return fEffects; }
private:
const SkDescriptor& fDesc;
const SkTypeface& fTypeface;
const SkScalerContextEffects fEffects;
};
class SkStrikeInterface {
public:
virtual ~SkStrikeInterface() = default;
virtual SkVector rounding() const = 0;
virtual const SkDescriptor& getDescriptor() const = 0;
virtual SkStrikeSpec strikeSpec() const = 0;
virtual const SkGlyph& getGlyphMetrics(SkGlyphID glyphID, SkPoint position) = 0;
virtual bool decideCouldDrawFromPath(const SkGlyph& glyph) = 0;
virtual void onAboutToExitScope() = 0;
struct Deleter {
void operator()(SkStrikeInterface* ptr) const {
ptr->onAboutToExitScope();
}
};
};
using SkScopedStrike = std::unique_ptr<SkStrikeInterface, SkStrikeInterface::Deleter>;
class SkStrikeCacheInterface {
public:
virtual ~SkStrikeCacheInterface() = default;
virtual SkScopedStrike findOrCreateScopedStrike(const SkDescriptor& desc,
const SkScalerContextEffects& effects,
const SkTypeface& typeface) = 0;
};
#endif //SkStrikeInterface_DEFINED