зеркало из https://github.com/mozilla/moz-skia.git
Refactor SkGrFontScaler and SkGrFontKey into non-virtual versions.
This is a pre-cleanup for another change, but has the side benefit of making the code simpler in general. No perf increase, despite removing virtual functions. R=bsalomon@google.com, egdaniel@google.com Author: jvanverth@google.com Review URL: https://codereview.chromium.org/385263002
This commit is contained in:
Родитель
93de7a27e0
Коммит
733f5f5dbc
11
gyp/gpu.gypi
11
gyp/gpu.gypi
|
@ -22,7 +22,6 @@
|
|||
'<(skia_include_path)/gpu/GrFontScaler.h',
|
||||
'<(skia_include_path)/gpu/GrGlyph.h',
|
||||
'<(skia_include_path)/gpu/GrGpuObject.h',
|
||||
'<(skia_include_path)/gpu/GrKey.h',
|
||||
'<(skia_include_path)/gpu/GrPaint.h',
|
||||
'<(skia_include_path)/gpu/GrPathRendererChain.h',
|
||||
'<(skia_include_path)/gpu/GrRect.h',
|
||||
|
@ -61,6 +60,10 @@
|
|||
'<(skia_src_path)/gpu/GrCacheable.cpp',
|
||||
'<(skia_src_path)/gpu/GrCacheID.cpp',
|
||||
'<(skia_src_path)/gpu/GrClipData.cpp',
|
||||
'<(skia_src_path)/gpu/GrClipMaskCache.h',
|
||||
'<(skia_src_path)/gpu/GrClipMaskCache.cpp',
|
||||
'<(skia_src_path)/gpu/GrClipMaskManager.h',
|
||||
'<(skia_src_path)/gpu/GrClipMaskManager.cpp',
|
||||
'<(skia_src_path)/gpu/GrContext.cpp',
|
||||
'<(skia_src_path)/gpu/GrDefaultPathRenderer.cpp',
|
||||
'<(skia_src_path)/gpu/GrDefaultPathRenderer.h',
|
||||
|
@ -72,11 +75,8 @@
|
|||
'<(skia_src_path)/gpu/GrDrawTarget.h',
|
||||
'<(skia_src_path)/gpu/GrDrawTargetCaps.h',
|
||||
'<(skia_src_path)/gpu/GrEffect.cpp',
|
||||
'<(skia_src_path)/gpu/GrFontScaler.cpp',
|
||||
'<(skia_src_path)/gpu/GrGeometryBuffer.h',
|
||||
'<(skia_src_path)/gpu/GrClipMaskCache.h',
|
||||
'<(skia_src_path)/gpu/GrClipMaskCache.cpp',
|
||||
'<(skia_src_path)/gpu/GrClipMaskManager.h',
|
||||
'<(skia_src_path)/gpu/GrClipMaskManager.cpp',
|
||||
'<(skia_src_path)/gpu/GrGpu.cpp',
|
||||
'<(skia_src_path)/gpu/GrGpu.h',
|
||||
'<(skia_src_path)/gpu/GrGpuObject.cpp',
|
||||
|
@ -241,7 +241,6 @@
|
|||
|
||||
'<(skia_src_path)/gpu/SkGpuDevice.cpp',
|
||||
'<(skia_src_path)/gpu/SkGr.cpp',
|
||||
'<(skia_src_path)/gpu/SkGrFontScaler.cpp',
|
||||
'<(skia_src_path)/gpu/SkGrPixelRef.cpp',
|
||||
'<(skia_src_path)/gpu/SkGrTexturePixelRef.cpp',
|
||||
|
||||
|
|
|
@ -9,35 +9,76 @@
|
|||
#define GrFontScaler_DEFINED
|
||||
|
||||
#include "GrGlyph.h"
|
||||
#include "GrKey.h"
|
||||
#include "GrTypes.h"
|
||||
|
||||
#include "SkDescriptor.h"
|
||||
|
||||
class SkPath;
|
||||
|
||||
/**
|
||||
* This is a virtual base class which Gr's interface to the host platform's
|
||||
* font scaler.
|
||||
/*
|
||||
* Wrapper class to turn a font cache descriptor into a key
|
||||
* for GrFontScaler-related lookups
|
||||
*/
|
||||
class GrFontDescKey : public SkRefCnt {
|
||||
public:
|
||||
SK_DECLARE_INST_COUNT(SkGrDescKey)
|
||||
|
||||
typedef uint32_t Hash;
|
||||
|
||||
explicit GrFontDescKey(const SkDescriptor& desc);
|
||||
virtual ~GrFontDescKey();
|
||||
|
||||
Hash getHash() const { return fHash; }
|
||||
|
||||
bool operator<(const GrFontDescKey& rh) const {
|
||||
return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh));
|
||||
}
|
||||
bool operator==(const GrFontDescKey& rh) const {
|
||||
return fHash == rh.fHash && this->eq(rh);
|
||||
}
|
||||
|
||||
private:
|
||||
// helper functions for comparisons
|
||||
bool lt(const GrFontDescKey& rh) const;
|
||||
bool eq(const GrFontDescKey& rh) const;
|
||||
|
||||
SkDescriptor* fDesc;
|
||||
enum {
|
||||
kMaxStorageInts = 16
|
||||
};
|
||||
uint32_t fStorage[kMaxStorageInts];
|
||||
const Hash fHash;
|
||||
|
||||
typedef SkRefCnt INHERITED;
|
||||
};
|
||||
|
||||
/*
|
||||
* This is Gr's interface to the host platform's font scaler.
|
||||
*
|
||||
* The client is responsible for subclassing, and instantiating this. The
|
||||
* instance is created for a specific font+size+matrix.
|
||||
* The client is responsible for instantiating this. The instance is created
|
||||
* for a specific font+size+matrix.
|
||||
*/
|
||||
class GrFontScaler : public SkRefCnt {
|
||||
public:
|
||||
SK_DECLARE_INST_COUNT(GrFontScaler)
|
||||
|
||||
virtual const GrKey* getKey() = 0;
|
||||
virtual GrMaskFormat getMaskFormat() = 0;
|
||||
virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds) = 0;
|
||||
virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
|
||||
int rowBytes, void* image) = 0;
|
||||
// get bounds for distance field associated with packed ID
|
||||
virtual bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds) = 0;
|
||||
// copies distance field bytes into pre-allocated dfImage
|
||||
// (should be width*height bytes in size)
|
||||
virtual bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height,
|
||||
void* dfImage) = 0;
|
||||
virtual bool getGlyphPath(uint16_t glyphID, SkPath*) = 0;
|
||||
|
||||
explicit GrFontScaler(SkGlyphCache* strike);
|
||||
virtual ~GrFontScaler();
|
||||
|
||||
const GrFontDescKey* getKey();
|
||||
GrMaskFormat getMaskFormat();
|
||||
bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds);
|
||||
bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
|
||||
int rowBytes, void* image);
|
||||
bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds);
|
||||
bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height,
|
||||
void* image);
|
||||
bool getGlyphPath(uint16_t glyphID, SkPath*);
|
||||
|
||||
private:
|
||||
SkGlyphCache* fStrike;
|
||||
GrFontDescKey* fKey;
|
||||
|
||||
typedef SkRefCnt INHERITED;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrKey_DEFINED
|
||||
#define GrKey_DEFINED
|
||||
|
||||
class GrKey : public SkRefCnt {
|
||||
public:
|
||||
SK_DECLARE_INST_COUNT(GrKey)
|
||||
|
||||
typedef intptr_t Hash;
|
||||
|
||||
explicit GrKey(Hash hash) : fHash(hash) {}
|
||||
|
||||
intptr_t getHash() const { return fHash; }
|
||||
|
||||
bool operator<(const GrKey& rh) const {
|
||||
return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh));
|
||||
}
|
||||
bool operator==(const GrKey& rh) const {
|
||||
return fHash == rh.fHash && this->eq(rh);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool lt(const GrKey& rh) const = 0;
|
||||
virtual bool eq(const GrKey& rh) const = 0;
|
||||
|
||||
private:
|
||||
const Hash fHash;
|
||||
|
||||
typedef SkRefCnt INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -16,7 +16,6 @@
|
|||
// Gr headers
|
||||
#include "GrTypes.h"
|
||||
#include "GrContext.h"
|
||||
#include "GrFontScaler.h"
|
||||
|
||||
// skia headers
|
||||
#include "SkBitmap.h"
|
||||
|
@ -104,28 +103,6 @@ void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
|
|||
|
||||
class SkGlyphCache;
|
||||
|
||||
class SkGrFontScaler : public GrFontScaler {
|
||||
public:
|
||||
explicit SkGrFontScaler(SkGlyphCache* strike);
|
||||
virtual ~SkGrFontScaler();
|
||||
|
||||
// overrides
|
||||
virtual const GrKey* getKey();
|
||||
virtual GrMaskFormat getMaskFormat();
|
||||
virtual bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE;
|
||||
virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
|
||||
int rowBytes, void* image) SK_OVERRIDE;
|
||||
virtual bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds) SK_OVERRIDE;
|
||||
virtual bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height,
|
||||
void* image) SK_OVERRIDE;
|
||||
virtual bool getGlyphPath(uint16_t glyphID, SkPath*);
|
||||
|
||||
private:
|
||||
SkGlyphCache* fStrike;
|
||||
GrKey* fKey;
|
||||
// DECLARE_INSTANCE_COUNTER(SkGrFontScaler);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,32 +8,14 @@
|
|||
|
||||
|
||||
#include "GrTemplates.h"
|
||||
#include "SkGr.h"
|
||||
#include "GrFontScaler.h"
|
||||
#include "SkDescriptor.h"
|
||||
#include "SkDistanceFieldGen.h"
|
||||
#include "SkGlyphCache.h"
|
||||
|
||||
class SkGrDescKey : public GrKey {
|
||||
public:
|
||||
explicit SkGrDescKey(const SkDescriptor& desc);
|
||||
virtual ~SkGrDescKey();
|
||||
|
||||
protected:
|
||||
// overrides
|
||||
virtual bool lt(const GrKey& rh) const;
|
||||
virtual bool eq(const GrKey& rh) const;
|
||||
|
||||
private:
|
||||
SkDescriptor* fDesc;
|
||||
enum {
|
||||
kMaxStorageInts = 16
|
||||
};
|
||||
uint32_t fStorage[kMaxStorageInts];
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkGrDescKey::SkGrDescKey(const SkDescriptor& desc) : GrKey(desc.getChecksum()) {
|
||||
GrFontDescKey::GrFontDescKey(const SkDescriptor& desc) : fHash(desc.getChecksum()) {
|
||||
size_t size = desc.getLength();
|
||||
if (size <= sizeof(fStorage)) {
|
||||
fDesc = GrTCast<SkDescriptor*>(fStorage);
|
||||
|
@ -43,14 +25,14 @@ SkGrDescKey::SkGrDescKey(const SkDescriptor& desc) : GrKey(desc.getChecksum()) {
|
|||
memcpy(fDesc, &desc, size);
|
||||
}
|
||||
|
||||
SkGrDescKey::~SkGrDescKey() {
|
||||
GrFontDescKey::~GrFontDescKey() {
|
||||
if (fDesc != GrTCast<SkDescriptor*>(fStorage)) {
|
||||
SkDescriptor::Free(fDesc);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkGrDescKey::lt(const GrKey& rh) const {
|
||||
const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc;
|
||||
bool GrFontDescKey::lt(const GrFontDescKey& rh) const {
|
||||
const SkDescriptor* srcDesc = (&rh)->fDesc;
|
||||
size_t lenLH = fDesc->getLength();
|
||||
size_t lenRH = srcDesc->getLength();
|
||||
int cmp = memcmp(fDesc, srcDesc, SkTMin<size_t>(lenLH, lenRH));
|
||||
|
@ -61,23 +43,23 @@ bool SkGrDescKey::lt(const GrKey& rh) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool SkGrDescKey::eq(const GrKey& rh) const {
|
||||
const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc;
|
||||
bool GrFontDescKey::eq(const GrFontDescKey& rh) const {
|
||||
const SkDescriptor* srcDesc = (&rh)->fDesc;
|
||||
return fDesc->equals(*srcDesc);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkGrFontScaler::SkGrFontScaler(SkGlyphCache* strike) {
|
||||
GrFontScaler::GrFontScaler(SkGlyphCache* strike) {
|
||||
fStrike = strike;
|
||||
fKey = NULL;
|
||||
}
|
||||
|
||||
SkGrFontScaler::~SkGrFontScaler() {
|
||||
GrFontScaler::~GrFontScaler() {
|
||||
SkSafeUnref(fKey);
|
||||
}
|
||||
|
||||
GrMaskFormat SkGrFontScaler::getMaskFormat() {
|
||||
GrMaskFormat GrFontScaler::getMaskFormat() {
|
||||
SkMask::Format format = fStrike->getMaskFormat();
|
||||
switch (format) {
|
||||
case SkMask::kBW_Format:
|
||||
|
@ -96,14 +78,14 @@ GrMaskFormat SkGrFontScaler::getMaskFormat() {
|
|||
}
|
||||
}
|
||||
|
||||
const GrKey* SkGrFontScaler::getKey() {
|
||||
const GrFontDescKey* GrFontScaler::getKey() {
|
||||
if (NULL == fKey) {
|
||||
fKey = SkNEW_ARGS(SkGrDescKey, (fStrike->getDescriptor()));
|
||||
fKey = SkNEW_ARGS(GrFontDescKey, (fStrike->getDescriptor()));
|
||||
}
|
||||
return fKey;
|
||||
}
|
||||
|
||||
bool SkGrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bounds) {
|
||||
bool GrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bounds) {
|
||||
const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
|
||||
GrGlyph::UnpackFixedX(packed),
|
||||
GrGlyph::UnpackFixedY(packed));
|
||||
|
@ -112,7 +94,7 @@ bool SkGrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bou
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SkGrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed, SkIRect* bounds) {
|
||||
bool GrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed, SkIRect* bounds) {
|
||||
const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
|
||||
GrGlyph::UnpackFixedX(packed),
|
||||
GrGlyph::UnpackFixedY(packed));
|
||||
|
@ -148,7 +130,7 @@ void expand_bits(INT_TYPE* dst,
|
|||
}
|
||||
}
|
||||
|
||||
bool SkGrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed,
|
||||
bool GrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed,
|
||||
int width, int height,
|
||||
int dstRB, void* dst) {
|
||||
const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
|
||||
|
@ -200,7 +182,7 @@ bool SkGrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SkGrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed,
|
||||
bool GrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed,
|
||||
int width, int height,
|
||||
void* dst) {
|
||||
const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
|
||||
|
@ -219,7 +201,7 @@ bool SkGrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed,
|
|||
}
|
||||
|
||||
// we should just return const SkPath* (NULL means false)
|
||||
bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) {
|
||||
bool GrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) {
|
||||
|
||||
const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID);
|
||||
const SkPath* skPath = fStrike->findPath(glyph);
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "SkAutoKern.h"
|
||||
#include "SkGlyphCache.h"
|
||||
#include "SkGr.h"
|
||||
#include "GrFontScaler.h"
|
||||
|
||||
GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& properties) :
|
||||
fContext(context), fDeviceProperties(properties), fDrawTarget(NULL) {
|
||||
|
@ -69,7 +69,7 @@ GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) {
|
|||
scaler = (GrFontScaler*)auxData;
|
||||
}
|
||||
if (NULL == scaler) {
|
||||
scaler = SkNEW_ARGS(SkGrFontScaler, (cache));
|
||||
scaler = SkNEW_ARGS(GrFontScaler, (cache));
|
||||
cache->setAuxProc(GlyphCacheAuxProc, scaler);
|
||||
}
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ void GrFontCache::dump() const {
|
|||
atlas and a position within that texture.
|
||||
*/
|
||||
|
||||
GrTextStrike::GrTextStrike(GrFontCache* cache, const GrKey* key,
|
||||
GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key,
|
||||
GrMaskFormat format,
|
||||
GrAtlas* atlas) : fPool(64) {
|
||||
fFontScalerKey = key;
|
||||
|
|
|
@ -28,10 +28,10 @@ class GrFontPurgeListener;
|
|||
*/
|
||||
class GrTextStrike {
|
||||
public:
|
||||
GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlas*);
|
||||
GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey, GrMaskFormat, GrAtlas*);
|
||||
~GrTextStrike();
|
||||
|
||||
const GrKey* getFontScalerKey() const { return fFontScalerKey; }
|
||||
const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
|
||||
GrFontCache* getFontCache() const { return fFontCache; }
|
||||
GrMaskFormat getMaskFormat() const { return fMaskFormat; }
|
||||
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
private:
|
||||
class Key;
|
||||
GrTHashTable<GrGlyph, Key, 7> fCache;
|
||||
const GrKey* fFontScalerKey;
|
||||
const GrFontDescKey* fFontScalerKey;
|
||||
GrTAllocPool<GrGlyph> fPool;
|
||||
|
||||
GrFontCache* fFontCache;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class GrFontCache::Key {
|
||||
public:
|
||||
explicit Key(const GrKey* fontScalarKey) {
|
||||
explicit Key(const GrFontDescKey* fontScalarKey) {
|
||||
fFontScalerKey = fontScalarKey;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
const GrKey* fFontScalerKey;
|
||||
const GrFontDescKey* fFontScalerKey;
|
||||
};
|
||||
|
||||
void GrFontCache::detachStrikeFromList(GrTextStrike* strike) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче