From 73d5de5763b4813c87e523adf2002ab48d3f4278 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Fri, 17 Jul 2015 06:19:19 -0700 Subject: Cleanup of GrFontDescKey BUG=skia: Review URL: https://codereview.chromium.org/1238473004 --- src/core/SkDescriptor.h | 5 +++++ src/gpu/GrFontScaler.cpp | 35 ----------------------------------- src/gpu/GrFontScaler.h | 30 ++++++------------------------ 3 files changed, 11 insertions(+), 59 deletions(-) diff --git a/src/core/SkDescriptor.h b/src/core/SkDescriptor.h index 0693ccfe60..e559215cb1 100644 --- a/src/core/SkDescriptor.h +++ b/src/core/SkDescriptor.h @@ -136,6 +136,11 @@ class SkAutoDescriptor : SkNoncopyable { public: SkAutoDescriptor() : fDesc(NULL) {} SkAutoDescriptor(size_t size) : fDesc(NULL) { this->reset(size); } + SkAutoDescriptor(const SkDescriptor& desc) : fDesc(NULL) { + size_t size = desc.getLength(); + this->reset(size); + memcpy(fDesc, &desc, size); + } ~SkAutoDescriptor() { this->free(); } diff --git a/src/gpu/GrFontScaler.cpp b/src/gpu/GrFontScaler.cpp index ed1970e262..364944eef9 100644 --- a/src/gpu/GrFontScaler.cpp +++ b/src/gpu/GrFontScaler.cpp @@ -15,41 +15,6 @@ /////////////////////////////////////////////////////////////////////////////// -GrFontDescKey::GrFontDescKey(const SkDescriptor& desc) : fHash(desc.getChecksum()) { - size_t size = desc.getLength(); - if (size <= sizeof(fStorage)) { - fDesc = GrTCast(fStorage); - } else { - fDesc = SkDescriptor::Alloc(size); - } - memcpy(fDesc, &desc, size); -} - -GrFontDescKey::~GrFontDescKey() { - if (fDesc != GrTCast(fStorage)) { - SkDescriptor::Free(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(lenLH, lenRH)); - if (0 == cmp) { - return lenLH < lenRH; - } else { - return cmp < 0; - } -} - -bool GrFontDescKey::eq(const GrFontDescKey& rh) const { - const SkDescriptor* srcDesc = (&rh)->fDesc; - return fDesc->equals(*srcDesc); -} - -/////////////////////////////////////////////////////////////////////////////// - GrFontScaler::GrFontScaler(SkGlyphCache* strike) { fStrike = strike; fKey = NULL; diff --git a/src/gpu/GrFontScaler.h b/src/gpu/GrFontScaler.h index 5e769905d0..644c8b719e 100644 --- a/src/gpu/GrFontScaler.h +++ b/src/gpu/GrFontScaler.h @@ -21,33 +21,17 @@ class SkPath; */ class GrFontDescKey : public SkRefCnt { public: + explicit GrFontDescKey(const SkDescriptor& desc) : fDesc(desc), fHash(desc.getChecksum()) {} - - 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)); - } + uint32_t getHash() const { return fHash; } + bool operator==(const GrFontDescKey& rh) const { - return fHash == rh.fHash && this->eq(rh); + return fHash == rh.fHash && fDesc.getDesc()->equals(*rh.fDesc.getDesc()); } 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; + SkAutoDescriptor fDesc; + uint32_t fHash; typedef SkRefCnt INHERITED; }; @@ -60,8 +44,6 @@ private: */ class GrFontScaler : public SkRefCnt { public: - - explicit GrFontScaler(SkGlyphCache* strike); virtual ~GrFontScaler(); -- cgit v1.2.3