blob: 037603813561bd59f2997235e4f6383422b61825 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#ifndef GrFontScaler_DEFINED
9#define GrFontScaler_DEFINED
10
11#include "GrGlyph.h"
jvanverth733f5f52014-07-11 19:45:16 -070012#include "GrTypes.h"
13
14#include "SkDescriptor.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015
reed@google.com07f3ee12011-05-16 17:21:57 +000016class SkPath;
reed@google.comac10a2d2010-12-22 21:39:39 +000017
jvanverth733f5f52014-07-11 19:45:16 -070018/*
19 * Wrapper class to turn a font cache descriptor into a key
20 * for GrFontScaler-related lookups
21 */
22class GrFontDescKey : public SkRefCnt {
23public:
bungemand6aeb6d2014-07-25 11:52:47 -070024 SK_DECLARE_INST_COUNT(GrFontDescKey)
jvanverth733f5f52014-07-11 19:45:16 -070025
26 typedef uint32_t Hash;
27
28 explicit GrFontDescKey(const SkDescriptor& desc);
29 virtual ~GrFontDescKey();
30
31 Hash getHash() const { return fHash; }
32
33 bool operator<(const GrFontDescKey& rh) const {
34 return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh));
35 }
36 bool operator==(const GrFontDescKey& rh) const {
37 return fHash == rh.fHash && this->eq(rh);
38 }
39
40private:
41 // helper functions for comparisons
42 bool lt(const GrFontDescKey& rh) const;
43 bool eq(const GrFontDescKey& rh) const;
44
45 SkDescriptor* fDesc;
46 enum {
47 kMaxStorageInts = 16
48 };
49 uint32_t fStorage[kMaxStorageInts];
50 const Hash fHash;
51
52 typedef SkRefCnt INHERITED;
53};
54
55/*
56 * This is Gr's interface to the host platform's font scaler.
reed@google.comac10a2d2010-12-22 21:39:39 +000057 *
jvanverth733f5f52014-07-11 19:45:16 -070058 * The client is responsible for instantiating this. The instance is created
59 * for a specific font+size+matrix.
reed@google.comac10a2d2010-12-22 21:39:39 +000060 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000061class GrFontScaler : public SkRefCnt {
reed@google.comac10a2d2010-12-22 21:39:39 +000062public:
reed@google.comfa35e3d2012-06-26 20:16:17 +000063 SK_DECLARE_INST_COUNT(GrFontScaler)
64
jvanverth733f5f52014-07-11 19:45:16 -070065 explicit GrFontScaler(SkGlyphCache* strike);
66 virtual ~GrFontScaler();
67
68 const GrFontDescKey* getKey();
69 GrMaskFormat getMaskFormat();
70 bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds);
71 bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
72 int rowBytes, void* image);
73 bool getPackedGlyphDFBounds(GrGlyph::PackedID, SkIRect* bounds);
74 bool getPackedGlyphDFImage(GrGlyph::PackedID, int width, int height,
75 void* image);
76 bool getGlyphPath(uint16_t glyphID, SkPath*);
77
reed@google.comfa35e3d2012-06-26 20:16:17 +000078private:
jvanverth733f5f52014-07-11 19:45:16 -070079 SkGlyphCache* fStrike;
80 GrFontDescKey* fKey;
81
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000082 typedef SkRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000083};
84
85#endif