class SkPathEffect;
struct SkPoint;
class SkRasterizer;
+struct SkScalerContextEffects;
class SkShader;
class SkSurfaceProps;
class SkTypeface;
* Allocs an SkDescriptor on the heap and return it to the caller as a refcnted
* SkData. Caller is responsible for managing the lifetime of this object.
*/
- void getScalerContextDescriptor(SkAutoDescriptor*, const SkSurfaceProps& surfaceProps,
+ void getScalerContextDescriptor(SkScalerContextEffects*, SkAutoDescriptor*,
+ const SkSurfaceProps& surfaceProps,
uint32_t scalerContextFlags, const SkMatrix*) const;
SkGlyphCache* detachCache(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
void descriptorProc(const SkSurfaceProps* surfaceProps, uint32_t scalerContextFlags,
const SkMatrix* deviceMatrix,
- void (*proc)(SkTypeface*, const SkDescriptor*, void*),
+ void (*proc)(SkTypeface*, const SkScalerContextEffects&,
+ const SkDescriptor*, void*),
void* context) const;
/*
-
/*
* Copyright 2006 The Android Open Source Project
*
* found in the LICENSE file.
*/
-
#ifndef SkTypeface_DEFINED
#define SkTypeface_DEFINED
#include "SkRect.h"
#include "SkString.h"
+#define SK_SUPPORT_NEW_ONCREATESCALERCONTEXT
+
class SkDescriptor;
class SkFontData;
class SkFontDescriptor;
class SkScalerContext;
struct SkScalerContextRec;
+struct SkScalerContextEffects;
class SkStream;
class SkStreamAsset;
class SkAdvancedTypefaceMetrics;
* if allowFailure is true, this returns NULL, else it returns a
* dummy scalercontext that will not crash, but will draw nothing.
*/
- SkScalerContext* createScalerContext(const SkDescriptor*,
+ SkScalerContext* createScalerContext(const SkScalerContextEffects&, const SkDescriptor*,
bool allowFailure = false) const;
/**
friend class SkScalerContext;
static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal);
- virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0;
+ virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const = 0;
virtual void onFilterRec(SkScalerContextRec*) const = 0;
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo,
- call a fontscaler (which might call into the cache)
*/
SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface,
- const SkDescriptor* desc,
- bool (*proc)(const SkGlyphCache*, void*),
- void* context) {
+ const SkScalerContextEffects& effects,
+ const SkDescriptor* desc,
+ bool (*proc)(const SkGlyphCache*, void*),
+ void* context) {
if (!typeface) {
typeface = SkTypeface::GetDefaultTypeface();
}
{
// pass true the first time, to notice if the scalercontext failed,
// so we can try the purge.
- SkScalerContext* ctx = typeface->createScalerContext(desc, true);
+ SkScalerContext* ctx = typeface->createScalerContext(effects, desc, true);
if (!ctx) {
get_globals().purgeAll();
- ctx = typeface->createScalerContext(desc, false);
+ ctx = typeface->createScalerContext(effects, desc, false);
SkASSERT(ctx);
}
cache = new SkGlyphCache(typeface, desc, ctx);
If the proc() returns true, detach the cache and return it, otherwise leave it and return
nullptr.
*/
- static SkGlyphCache* VisitCache(SkTypeface*, const SkDescriptor* desc,
+ static SkGlyphCache* VisitCache(SkTypeface*, const SkScalerContextEffects&, const SkDescriptor*,
bool (*proc)(const SkGlyphCache*, void*),
void* context);
more than 1 strike for the same descriptor, but that will eventually get purged, and the
win is that different thread will never block each other while a strike is being used.
*/
- static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkDescriptor* desc) {
- return VisitCache(typeface, desc, DetachProc, nullptr);
+ static SkGlyphCache* DetachCache(SkTypeface* typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) {
+ return VisitCache(typeface, effects, desc, DetachProc, nullptr);
}
static void Dump();
SkGlyphCache* getCache() const { return this->get(); }
SkAutoGlyphCache(SkGlyphCache* cache) : INHERITED(cache) {}
- SkAutoGlyphCache(SkTypeface* typeface, const SkDescriptor* desc)
- : INHERITED(SkGlyphCache::DetachCache(typeface, desc))
+ SkAutoGlyphCache(SkTypeface* typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc)
+ : INHERITED(SkGlyphCache::DetachCache(typeface, effects, desc))
{}
/** deprecated: always enables fake gamma */
SkAutoGlyphCache(const SkPaint& paint,
#include "SkGlyphCache.h"
#include "SkUtils.h"
-static void DetachDescProc(SkTypeface* typeface, const SkDescriptor* desc,
- void* context) {
- *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc);
+static void DetachDescProc(SkTypeface* typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc, void* context) {
+ *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, effects, desc);
}
-int SkPaint::textToGlyphs(const void* textData, size_t byteLength,
- uint16_t glyphs[]) const {
+int SkPaint::textToGlyphs(const void* textData, size_t byteLength, uint16_t glyphs[]) const {
if (byteLength == 0) {
return 0;
}
return false; // don't detach the cache
}
-static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc,
- void* context) {
- SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context);
+static void FontMetricsDescProc(SkTypeface* typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc, void* context) {
+ SkGlyphCache::VisitCache(typeface, effects, desc, FontMetricsCacheProc, context);
}
SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const {
#endif
/* see the note on ignoreGamma on descriptorProc */
-void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad,
+void SkPaint::getScalerContextDescriptor(SkScalerContextEffects* effects,
+ SkAutoDescriptor* ad,
const SkSurfaceProps& surfaceProps,
uint32_t scalerContextFlags,
const SkMatrix* deviceMatrix) const {
#ifdef TEST_DESC
test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
#endif
+
+ effects->fPathEffect = pe;
+ effects->fMaskFilter = mf;
+ effects->fRasterizer = ra;
}
/*
void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps,
uint32_t scalerContextFlags,
const SkMatrix* deviceMatrix,
- void (*proc)(SkTypeface*, const SkDescriptor*, void*),
+ void (*proc)(SkTypeface*, const SkScalerContextEffects&,
+ const SkDescriptor*, void*),
void* context) const {
SkScalerContext::Rec rec;
test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
#endif
- proc(fTypeface.get(), desc, context);
+ proc(fTypeface.get(), { pe, mf, ra }, desc, context);
}
SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps,
#define DUMP_RECx
#endif
-static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
- SkFlattenable::Type ft) {
- SkFlattenable* obj = nullptr;
- uint32_t len;
- const void* data = desc->findEntry(tag, &len);
-
- if (data) {
- SkReadBuffer buffer(data, len);
- obj = buffer.readFlattenable(ft);
- SkASSERT(buffer.offset() == buffer.size());
- }
- return obj;
-}
-
-SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
+SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc)
: fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, nullptr)))
- , fTypeface(SkRef(typeface))
- , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag,
- SkFlattenable::kSkPathEffect_Type)))
- , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag,
- SkFlattenable::kSkMaskFilter_Type)))
- , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag,
- SkFlattenable::kSkRasterizer_Type)))
+ , fTypeface(sk_ref_sp(typeface))
+ , fPathEffect(sk_ref_sp(effects.fPathEffect))
+ , fMaskFilter(sk_ref_sp(effects.fMaskFilter))
+ , fRasterizer(sk_ref_sp(effects.fRasterizer))
// Initialize based on our settings. Subclasses can also force this.
, fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != nullptr || fRasterizer != nullptr)
#endif
}
-SkScalerContext::~SkScalerContext() {
- SkSafeUnref(fPathEffect);
- SkSafeUnref(fMaskFilter);
- SkSafeUnref(fRasterizer);
-}
+SkScalerContext::~SkScalerContext() {}
void SkScalerContext::getAdvance(SkGlyph* glyph) {
// mark us as just having a valid advance
SkMask mask;
if (fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr,
- fMaskFilter, &mask,
+ fMaskFilter.get(), &mask,
SkMask::kJustComputeBounds_CreateMode)) {
glyph->fLeft = mask.fBounds.fLeft;
glyph->fTop = mask.fBounds.fTop;
tmpGlyph.initGlyphIdFrom(origGlyph);
// need the original bounds, sans our maskfilter
- SkMaskFilter* mf = fMaskFilter;
- fMaskFilter = nullptr; // temp disable
+ SkMaskFilter* mf = fMaskFilter.release(); // temp disable
this->getMetrics(&tmpGlyph);
- fMaskFilter = mf; // restore
+ fMaskFilter = sk_sp<SkMaskFilter>(mf); // restore
// we need the prefilter bounds to be <= filter bounds
SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth);
sk_bzero(glyph->fImage, mask.computeImageSize());
if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr,
- fMaskFilter, &mask,
+ fMaskFilter.get(), &mask,
SkMask::kJustRenderImage_CreateMode)) {
return;
}
class SkScalerContext_Empty : public SkScalerContext {
public:
- SkScalerContext_Empty(SkTypeface* face, const SkDescriptor* desc)
- : SkScalerContext(face, desc) {}
+ SkScalerContext_Empty(SkTypeface* typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc)
+ : SkScalerContext(typeface, effects, desc) {}
protected:
unsigned generateGlyphCount() override {
extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc);
-SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc,
+SkScalerContext* SkTypeface::createScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc,
bool allowFailure) const {
- SkScalerContext* c = this->onCreateScalerContext(desc);
+ SkScalerContext* c = this->onCreateScalerContext(effects, desc);
if (!c && !allowFailure) {
- c = new SkScalerContext_Empty(const_cast<SkTypeface*>(this), desc);
+ c = new SkScalerContext_Empty(const_cast<SkTypeface*>(this), effects, desc);
}
return c;
}
class SkPathEffect;
class SkRasterizer;
+struct SkScalerContextEffects {
+ SkScalerContextEffects() : fPathEffect(nullptr), fMaskFilter(nullptr), fRasterizer(nullptr) {}
+ SkScalerContextEffects(SkPathEffect* pe, SkMaskFilter* mf, SkRasterizer* ra)
+ : fPathEffect(pe), fMaskFilter(mf), fRasterizer(ra) {}
+
+ SkPathEffect* fPathEffect;
+ SkMaskFilter* fMaskFilter;
+ SkRasterizer* fRasterizer;
+};
+
enum SkAxisAlignment {
kNone_SkAxisAlignment,
kX_SkAxisAlignment,
kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag,
};
-
- SkScalerContext(SkTypeface*, const SkDescriptor*);
+ SkScalerContext(SkTypeface*, const SkScalerContextEffects&, const SkDescriptor*);
virtual ~SkScalerContext();
SkTypeface* getTypeface() const { return fTypeface.get(); }
const Rec& getRec() const { return fRec; }
+ SkScalerContextEffects getEffects() const {
+ return { fPathEffect.get(), fMaskFilter.get(), fRasterizer.get() };
+ }
+
/**
* Return the axis (if any) that the baseline for horizontal text should land on.
* As an example, the identity matrix will return kX_SkAxisAlignment
*/
SkAxisAlignment computeAxisAlignmentForHText();
-
protected:
Rec fRec;
friend class SkRandomScalerContext; // For debug purposes
// never null
- SkAutoTUnref<SkTypeface> fTypeface;
+ sk_sp<SkTypeface> fTypeface;
- // optional object, which may be null
- SkPathEffect* fPathEffect;
- SkMaskFilter* fMaskFilter;
- SkRasterizer* fRasterizer;
+ // optional objects, which may be null
+ sk_sp<SkPathEffect> fPathEffect;
+ sk_sp<SkMaskFilter> fMaskFilter;
+ sk_sp<SkRasterizer> fRasterizer;
// if this is set, we draw the image from a path, rather than
// calling generateImage.
SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { }
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
- SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override {
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override {
return nullptr;
}
void onFilterRec(SkScalerContextRec*) const override { }
desc->init();
desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
- SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(desc, true));
+ SkScalerContextEffects noeffects;
+ SkAutoTDelete<SkScalerContext> ctx(this->createScalerContext(noeffects, desc, true));
if (ctx.get()) {
SkPaint::FontMetrics fm;
ctx->getFontMetrics(&fm);
* found in the LICENSE file.
*/
+#include "SkDescriptor.h"
#include "SkGScalerContext.h"
#include "SkGlyph.h"
#include "SkPath.h"
#include "SkCanvas.h"
+#define STD_SIZE 1
+
class SkGScalerContext : public SkScalerContext {
public:
- SkGScalerContext(SkGTypeface*, const SkDescriptor*);
- virtual ~SkGScalerContext();
+ SkGScalerContext(SkGTypeface* face, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc)
+ : SkScalerContext(face, effects, desc)
+ , fFace(face)
+ {
+
+ size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec);
+ SkAutoDescriptor ad(descSize);
+ SkDescriptor* newDesc = ad.getDesc();
+
+ newDesc->init();
+ void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
+ sizeof(SkScalerContext::Rec), &fRec);
+ {
+ SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
+ rec->fTextSize = STD_SIZE;
+ rec->fPreScaleX = SK_Scalar1;
+ rec->fPreSkewX = 0;
+ rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
+ rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
+ }
+ SkASSERT(descSize == newDesc->getLength());
+ newDesc->computeChecksum();
+
+ fProxy = face->proxy()->createScalerContext(effects, newDesc);
+
+ fRec.getSingleMatrix(&fMatrix);
+ fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
+ }
+ virtual ~SkGScalerContext() { delete fProxy; }
protected:
unsigned generateGlyphCount() override;
SkMatrix fMatrix;
};
-#define STD_SIZE 1
-
-#include "SkDescriptor.h"
-
-SkGScalerContext::SkGScalerContext(SkGTypeface* face, const SkDescriptor* desc)
- : SkScalerContext(face, desc)
- , fFace(face)
-{
-
- size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec);
- SkAutoDescriptor ad(descSize);
- SkDescriptor* newDesc = ad.getDesc();
-
- newDesc->init();
- void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
- sizeof(SkScalerContext::Rec), &fRec);
- {
- SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
- rec->fTextSize = STD_SIZE;
- rec->fPreScaleX = SK_Scalar1;
- rec->fPreSkewX = 0;
- rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
- rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
- }
- SkASSERT(descSize == newDesc->getLength());
- newDesc->computeChecksum();
-
- fProxy = face->proxy()->createScalerContext(newDesc);
-
- fRec.getSingleMatrix(&fMatrix);
- fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
-}
-
-SkGScalerContext::~SkGScalerContext() { delete fProxy; }
-
unsigned SkGScalerContext::generateGlyphCount() {
return fProxy->getGlyphCount();
}
fProxy->unref();
}
-SkScalerContext* SkGTypeface::onCreateScalerContext(
- const SkDescriptor* desc) const {
- return new SkGScalerContext(const_cast<SkGTypeface*>(this), desc);
+SkScalerContext* SkGTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const {
+ return new SkGScalerContext(const_cast<SkGTypeface*>(this), effects, desc);
}
void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const {
const SkPaint& paint() const { return fPaint; }
protected:
- SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo,
class SkRandomScalerContext : public SkScalerContext {
public:
- SkRandomScalerContext(SkRandomTypeface*, const SkDescriptor*, bool fFakeIt);
+ SkRandomScalerContext(SkRandomTypeface*, const SkScalerContextEffects&,
+ const SkDescriptor*, bool fFakeIt);
virtual ~SkRandomScalerContext();
protected:
#include "SkDescriptor.h"
-SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDescriptor* desc,
+SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face,
+ const SkScalerContextEffects& effects,
+ const SkDescriptor* desc,
bool fakeIt)
- : SkScalerContext(face, desc)
+ : SkScalerContext(face, effects, desc)
, fFace(face)
, fFakeIt(fakeIt) {
- fProxy = face->proxy()->createScalerContext(desc);
+ fProxy = face->proxy()->createScalerContext(effects, desc);
}
SkRandomScalerContext::~SkRandomScalerContext() { delete fProxy; }
fProxy->unref();
}
-SkScalerContext* SkRandomTypeface::onCreateScalerContext(
- const SkDescriptor* desc) const {
- return new SkRandomScalerContext(const_cast<SkRandomTypeface*>(this), desc, fFakeIt);
+SkScalerContext* SkRandomTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const {
+ return new SkRandomScalerContext(const_cast<SkRandomTypeface*>(this), effects, desc, fFakeIt);
}
void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {
const SkPaint& paint() const { return fPaint; }
protected:
- SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo,
class SkTestScalerContext : public SkScalerContext {
public:
- SkTestScalerContext(SkTestTypeface* face, const SkDescriptor* desc)
- : SkScalerContext(face, desc)
+ SkTestScalerContext(SkTestTypeface* face, const SkScalerContextEffects& effects,
+ const SkDescriptor* desc)
+ : SkScalerContext(face, effects, desc)
, fFace(face)
{
fRec.getSingleMatrix(&fMatrix);
SkMatrix fMatrix;
};
-SkScalerContext* SkTestTypeface::onCreateScalerContext(const SkDescriptor* desc) const {
- return new SkTestScalerContext(const_cast<SkTestTypeface*>(this), desc);
+SkScalerContext* SkTestTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const {
+ return new SkTestScalerContext(const_cast<SkTestTypeface*>(this), effects, desc);
}
void getMetrics(SkGlyph* glyph);
void getPath(const SkGlyph& glyph, SkPath* path);
protected:
- SkScalerContext* onCreateScalerContext(const SkDescriptor* desc) const override;
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo,
class GlyphGenerator : public GrPathRange::PathGenerator {
public:
- GlyphGenerator(const SkTypeface& typeface, const SkDescriptor& desc)
- : fScalerContext(typeface.createScalerContext(&desc))
+ GlyphGenerator(const SkTypeface& typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor& desc)
+ : fScalerContext(typeface.createScalerContext(effects, &desc))
#ifdef SK_DEBUG
, fDesc(desc.copy())
#endif
};
GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface,
+ const SkScalerContextEffects& effects,
const SkDescriptor* desc,
const GrStrokeInfo& stroke) {
if (nullptr == typeface) {
}
if (desc) {
- SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *desc));
+ SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, effects, *desc));
return this->createPathRange(generator, stroke);
}
genericDesc->init();
genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
genericDesc->computeChecksum();
+
+ // No effects, so we make a dummy struct
+ SkScalerContextEffects noEffects;
- SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, *genericDesc));
+ SkAutoTUnref<GlyphGenerator> generator(new GlyphGenerator(*typeface, noEffects, *genericDesc));
return this->createPathRange(generator, stroke);
}
*
* @return a new path range populated with glyphs.
*/
- GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const GrStrokeInfo&);
+ GrPathRange* createGlyphs(const SkTypeface*, const SkScalerContextEffects&,
+ const SkDescriptor*, const GrStrokeInfo&);
/** None of these params are optional, pointers used just to avoid making copies. */
struct StencilPathArgs {
return this->gpu()->pathRendering()->createPathRange(gen, stroke);
}
-GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf, const SkDescriptor* desc,
+GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf,
+ const SkScalerContextEffects& effects,
+ const SkDescriptor* desc,
const GrStrokeInfo& stroke) {
SkASSERT(this->gpu()->pathRendering());
- return this->gpu()->pathRendering()->createGlyphs(tf, desc, stroke);
+ return this->gpu()->pathRendering()->createGlyphs(tf, effects, desc, stroke);
}
GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedType,
*/
GrPath* createPath(const SkPath&, const GrStrokeInfo&);
GrPathRange* createPathRange(GrPathRange::PathGenerator*, const GrStrokeInfo&);
- GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const GrStrokeInfo&);
+ GrPathRange* createGlyphs(const SkTypeface*, const SkScalerContextEffects&,
+ const SkDescriptor*, const GrStrokeInfo&);
using GrTextureProvider::assignUniqueKeyToResource;
using GrTextureProvider::findAndRefResourceByUniqueKey;
// if we have an override descriptor for the run, then we should use that
SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDescriptor.get() :
&run->fDescriptor;
- skPaint.getScalerContextDescriptor(desc, props, scalerContextFlags, viewMatrix);
+ skPaint.getScalerContextDescriptor(&run->fEffects, desc, props, scalerContextFlags, viewMatrix);
run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
- return SkGlyphCache::DetachCache(run->fTypeface, desc->getDesc());
+ return SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, desc->getDesc());
}
void GrAtlasTextBlob::appendGlyph(int runIndex,
SkAutoTUnref<SkTypeface> fTypeface;
SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo;
SkAutoDescriptor fDescriptor;
+ SkScalerContextEffects fEffects;
// Distance field text cannot draw coloremoji, and so has to fall back. However,
// though the distance field text and the coloremoji may share the same run, they
SkGlyphCache::AttachCache(*cache);
}
*desc = newDesc;
- *cache = SkGlyphCache::DetachCache(run->fTypeface, *desc);
+ *cache = SkGlyphCache::DetachCache(run->fTypeface, run->fEffects, *desc);
*scaler = GrTextUtils::GetGrFontScaler(*cache);
*typeface = run->fTypeface;
}
ctx->resourceProvider()->findAndRefResourceByUniqueKey(fGlyphPathsKey));
if (nullptr == glyphs) {
if (fUsingRawGlyphPaths) {
- glyphs = ctx->resourceProvider()->createGlyphs(fFont.getTypeface(), nullptr, fStroke);
+ SkScalerContextEffects noeffects;
+ glyphs = ctx->resourceProvider()->createGlyphs(fFont.getTypeface(), noeffects,
+ nullptr, fStroke);
} else {
SkGlyphCache* cache = this->getGlyphCache();
glyphs = ctx->resourceProvider()->createGlyphs(cache->getScalerContext()->getTypeface(),
+ cache->getScalerContext()->getEffects(),
&cache->getDescriptor(),
fStroke);
}
SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true);
SkAutoDescriptor desc;
+ SkScalerContextEffects effects;
// 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).
- skPaint.getScalerContextDescriptor(&desc, props, SkPaint::kNone_ScalerContextFlags, nullptr);
- SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface(),
+ skPaint.getScalerContextDescriptor(&effects, &desc, props, SkPaint::kNone_ScalerContextFlags,
+ nullptr);
+ SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface(), effects,
desc.getDesc());
SkTArray<SkScalar> positions;
class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base {
public:
- SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc);
+ SkScalerContext_FreeType(SkTypeface*, const SkScalerContextEffects&, const SkDescriptor* desc);
virtual ~SkScalerContext_FreeType();
bool success() const {
bothZero(rec.fPost2x2[0][0], rec.fPost2x2[1][1]));
}
-SkScalerContext* SkTypeface_FreeType::onCreateScalerContext(
- const SkDescriptor* desc) const {
+SkScalerContext* SkTypeface_FreeType::onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const {
SkScalerContext_FreeType* c =
- new SkScalerContext_FreeType(const_cast<SkTypeface_FreeType*>(this), desc);
+ new SkScalerContext_FreeType(const_cast<SkTypeface_FreeType*>(this), effects, desc);
if (!c->success()) {
delete c;
c = nullptr;
return chosenStrikeIndex;
}
-SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface, const SkDescriptor* desc)
- : SkScalerContext_FreeType_Base(typeface, desc)
+SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface,
+ const SkScalerContextEffects& effects,
+ const SkDescriptor* desc)
+ : SkScalerContext_FreeType_Base(typeface, effects, desc)
, fFace(nullptr)
, fFTSize(nullptr)
, fStrikeIndex(-1)
// This value was chosen by eyeballing the result in Firefox and trying to match it.
static const FT_Pos kBitmapEmboldenStrength = 1 << 6;
- SkScalerContext_FreeType_Base(SkTypeface* typeface, const SkDescriptor *desc)
- : INHERITED(typeface, desc)
+ SkScalerContext_FreeType_Base(SkTypeface* typeface, const SkScalerContextEffects& effects,
+ const SkDescriptor *desc)
+ : INHERITED(typeface, effects, desc)
{}
void generateGlyphImage(FT_Face face, const SkGlyph& glyph);
, fGlyphCount(-1)
{}
- virtual SkScalerContext* onCreateScalerContext(
- const SkDescriptor*) const override;
+ virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo, const uint32_t*, uint32_t) const override;
int onGetTableTags(SkFontTableTag tags[]) const override;
virtual size_t onGetTableData(SkFontTableTag, size_t offset,
size_t length, void* data) const override;
- SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
class SkScalerContext_Mac : public SkScalerContext {
public:
- SkScalerContext_Mac(SkTypeface_Mac*, const SkDescriptor*);
+ SkScalerContext_Mac(SkTypeface_Mac*, const SkScalerContextEffects&, const SkDescriptor*);
protected:
unsigned generateGlyphCount(void) override;
}
SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
+ const SkScalerContextEffects& effects,
const SkDescriptor* desc)
- : INHERITED(typeface, desc)
+ : INHERITED(typeface, effects, desc)
, fFBoundingBoxes()
, fFBoundingBoxesGlyphOffset(0)
, fGeneratedFBoundingBoxes(false)
return length;
}
-SkScalerContext* SkTypeface_Mac::onCreateScalerContext(const SkDescriptor* desc) const {
- return new SkScalerContext_Mac(const_cast<SkTypeface_Mac*>(this), desc);
+SkScalerContext* SkTypeface_Mac::onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const {
+ return new SkScalerContext_Mac(const_cast<SkTypeface_Mac*>(this), effects, desc);
}
void SkTypeface_Mac::onFilterRec(SkScalerContextRec* rec) const {
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
- SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo, const uint32_t*, uint32_t) const override;
class SkScalerContext_GDI : public SkScalerContext {
public:
- SkScalerContext_GDI(SkTypeface*, const SkDescriptor* desc);
+ SkScalerContext_GDI(SkTypeface*, const SkScalerContextEffects&, const SkDescriptor* desc);
virtual ~SkScalerContext_GDI();
// Returns true if the constructor was able to complete all of its
}
SkScalerContext_GDI::SkScalerContext_GDI(SkTypeface* rawTypeface,
- const SkDescriptor* desc)
- : SkScalerContext(rawTypeface, desc)
+ const SkScalerContextEffects& effects,
+ const SkDescriptor* desc)
+ : SkScalerContext(rawTypeface, effects, desc)
, fDDC(0)
, fSavefont(0)
, fFont(0)
return bufferSize == GDI_ERROR ? 0 : bufferSize;
}
-SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const {
- SkScalerContext_GDI* ctx = new SkScalerContext_GDI(const_cast<LogFontTypeface*>(this), desc);
+SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const {
+ SkScalerContext_GDI* ctx = new SkScalerContext_GDI(const_cast<LogFontTypeface*>(this),
+ effects, desc);
if (!ctx->isValid()) {
delete ctx;
ctx = nullptr;
}
SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface,
+ const SkScalerContextEffects& effects,
const SkDescriptor* desc)
- : SkScalerContext(typeface, desc)
+ : SkScalerContext(typeface, effects, desc)
, fTypeface(SkRef(typeface))
, fGlyphCount(-1) {
class SkScalerContext_DW : public SkScalerContext {
public:
- SkScalerContext_DW(DWriteFontTypeface*, const SkDescriptor* desc);
+ SkScalerContext_DW(DWriteFontTypeface*, const SkScalerContextEffects&, const SkDescriptor*);
virtual ~SkScalerContext_DW();
protected:
return new SkDWriteFontFileStream(fontFileStream.get());
}
-SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const {
- return new SkScalerContext_DW(const_cast<DWriteFontTypeface*>(this), desc);
+SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const {
+ return new SkScalerContext_DW(const_cast<DWriteFontTypeface*>(this), effects, desc);
}
void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
}
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
- SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
PerGlyphInfo, const uint32_t*, uint32_t) const override;
TestTypeface(const SkFontStyle& fontStyle, SkFontID id) : SkTypeface(fontStyle, id, false){}
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
- SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override {
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+ const SkDescriptor*) const override {
return nullptr;
}
void onFilterRec(SkScalerContextRec*) const override { }