aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2014-07-11 19:45:16 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-11 19:45:16 -0700
commit733f5f5dbca10fc6385ec3c77b3e9ff78227dac7 (patch)
treed9ffdb538bf85fa2d56e977d5081e32e7f4f3ee7 /include
parent93de7a27e05004e1ff3171b43d89d36890f9f868 (diff)
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
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrFontScaler.h79
-rw-r--r--include/gpu/GrKey.h38
-rw-r--r--include/gpu/SkGr.h23
3 files changed, 60 insertions, 80 deletions
diff --git a/include/gpu/GrFontScaler.h b/include/gpu/GrFontScaler.h
index 0132d51304..d90708de8f 100644
--- a/include/gpu/GrFontScaler.h
+++ b/include/gpu/GrFontScaler.h
@@ -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;
};
diff --git a/include/gpu/GrKey.h b/include/gpu/GrKey.h
deleted file mode 100644
index e9d6feb453..0000000000
--- a/include/gpu/GrKey.h
+++ /dev/null
@@ -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
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index e306293e31..2f88679503 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -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