Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/gpu/GrFontScaler.cpp

Issue 385263002: Refactor SkGrFontScaler and SkGrFontKey into non-virtual versions. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase to ToT Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/SkGr.h ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrTemplates.h" 10 #include "GrTemplates.h"
11 #include "SkGr.h" 11 #include "GrFontScaler.h"
12 #include "SkDescriptor.h" 12 #include "SkDescriptor.h"
13 #include "SkDistanceFieldGen.h" 13 #include "SkDistanceFieldGen.h"
14 #include "SkGlyphCache.h" 14 #include "SkGlyphCache.h"
15 15
16 class SkGrDescKey : public GrKey {
17 public:
18 explicit SkGrDescKey(const SkDescriptor& desc);
19 virtual ~SkGrDescKey();
20
21 protected:
22 // overrides
23 virtual bool lt(const GrKey& rh) const;
24 virtual bool eq(const GrKey& rh) const;
25
26 private:
27 SkDescriptor* fDesc;
28 enum {
29 kMaxStorageInts = 16
30 };
31 uint32_t fStorage[kMaxStorageInts];
32 };
33
34 /////////////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////////////
35 17
36 SkGrDescKey::SkGrDescKey(const SkDescriptor& desc) : GrKey(desc.getChecksum()) { 18 GrFontDescKey::GrFontDescKey(const SkDescriptor& desc) : fHash(desc.getChecksum( )) {
37 size_t size = desc.getLength(); 19 size_t size = desc.getLength();
38 if (size <= sizeof(fStorage)) { 20 if (size <= sizeof(fStorage)) {
39 fDesc = GrTCast<SkDescriptor*>(fStorage); 21 fDesc = GrTCast<SkDescriptor*>(fStorage);
40 } else { 22 } else {
41 fDesc = SkDescriptor::Alloc(size); 23 fDesc = SkDescriptor::Alloc(size);
42 } 24 }
43 memcpy(fDesc, &desc, size); 25 memcpy(fDesc, &desc, size);
44 } 26 }
45 27
46 SkGrDescKey::~SkGrDescKey() { 28 GrFontDescKey::~GrFontDescKey() {
47 if (fDesc != GrTCast<SkDescriptor*>(fStorage)) { 29 if (fDesc != GrTCast<SkDescriptor*>(fStorage)) {
48 SkDescriptor::Free(fDesc); 30 SkDescriptor::Free(fDesc);
49 } 31 }
50 } 32 }
51 33
52 bool SkGrDescKey::lt(const GrKey& rh) const { 34 bool GrFontDescKey::lt(const GrFontDescKey& rh) const {
53 const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc; 35 const SkDescriptor* srcDesc = (&rh)->fDesc;
54 size_t lenLH = fDesc->getLength(); 36 size_t lenLH = fDesc->getLength();
55 size_t lenRH = srcDesc->getLength(); 37 size_t lenRH = srcDesc->getLength();
56 int cmp = memcmp(fDesc, srcDesc, SkTMin<size_t>(lenLH, lenRH)); 38 int cmp = memcmp(fDesc, srcDesc, SkTMin<size_t>(lenLH, lenRH));
57 if (0 == cmp) { 39 if (0 == cmp) {
58 return lenLH < lenRH; 40 return lenLH < lenRH;
59 } else { 41 } else {
60 return cmp < 0; 42 return cmp < 0;
61 } 43 }
62 } 44 }
63 45
64 bool SkGrDescKey::eq(const GrKey& rh) const { 46 bool GrFontDescKey::eq(const GrFontDescKey& rh) const {
65 const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc; 47 const SkDescriptor* srcDesc = (&rh)->fDesc;
66 return fDesc->equals(*srcDesc); 48 return fDesc->equals(*srcDesc);
67 } 49 }
68 50
69 /////////////////////////////////////////////////////////////////////////////// 51 ///////////////////////////////////////////////////////////////////////////////
70 52
71 SkGrFontScaler::SkGrFontScaler(SkGlyphCache* strike) { 53 GrFontScaler::GrFontScaler(SkGlyphCache* strike) {
72 fStrike = strike; 54 fStrike = strike;
73 fKey = NULL; 55 fKey = NULL;
74 } 56 }
75 57
76 SkGrFontScaler::~SkGrFontScaler() { 58 GrFontScaler::~GrFontScaler() {
77 SkSafeUnref(fKey); 59 SkSafeUnref(fKey);
78 } 60 }
79 61
80 GrMaskFormat SkGrFontScaler::getMaskFormat() { 62 GrMaskFormat GrFontScaler::getMaskFormat() {
81 SkMask::Format format = fStrike->getMaskFormat(); 63 SkMask::Format format = fStrike->getMaskFormat();
82 switch (format) { 64 switch (format) {
83 case SkMask::kBW_Format: 65 case SkMask::kBW_Format:
84 // fall through to kA8 -- we store BW glyphs in our 8-bit cache 66 // fall through to kA8 -- we store BW glyphs in our 8-bit cache
85 case SkMask::kA8_Format: 67 case SkMask::kA8_Format:
86 return kA8_GrMaskFormat; 68 return kA8_GrMaskFormat;
87 case SkMask::kLCD16_Format: 69 case SkMask::kLCD16_Format:
88 return kA565_GrMaskFormat; 70 return kA565_GrMaskFormat;
89 case SkMask::kLCD32_Format: 71 case SkMask::kLCD32_Format:
90 return kA888_GrMaskFormat; 72 return kA888_GrMaskFormat;
91 case SkMask::kARGB32_Format: 73 case SkMask::kARGB32_Format:
92 return kARGB_GrMaskFormat; 74 return kARGB_GrMaskFormat;
93 default: 75 default:
94 SkDEBUGFAIL("unsupported SkMask::Format"); 76 SkDEBUGFAIL("unsupported SkMask::Format");
95 return kA8_GrMaskFormat; 77 return kA8_GrMaskFormat;
96 } 78 }
97 } 79 }
98 80
99 const GrKey* SkGrFontScaler::getKey() { 81 const GrFontDescKey* GrFontScaler::getKey() {
100 if (NULL == fKey) { 82 if (NULL == fKey) {
101 fKey = SkNEW_ARGS(SkGrDescKey, (fStrike->getDescriptor())); 83 fKey = SkNEW_ARGS(GrFontDescKey, (fStrike->getDescriptor()));
102 } 84 }
103 return fKey; 85 return fKey;
104 } 86 }
105 87
106 bool SkGrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bou nds) { 88 bool GrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bound s) {
107 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), 89 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
108 GrGlyph::UnpackFixedX(pack ed), 90 GrGlyph::UnpackFixedX(pack ed),
109 GrGlyph::UnpackFixedY(pack ed)); 91 GrGlyph::UnpackFixedY(pack ed));
110 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); 92 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
111 93
112 return true; 94 return true;
113 } 95 }
114 96
115 bool SkGrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed, SkIRect* b ounds) { 97 bool GrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed, SkIRect* bou nds) {
116 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), 98 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
117 GrGlyph::UnpackFixedX(pack ed), 99 GrGlyph::UnpackFixedX(pack ed),
118 GrGlyph::UnpackFixedY(pack ed)); 100 GrGlyph::UnpackFixedY(pack ed));
119 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); 101 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
120 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad); 102 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad);
121 103
122 return true; 104 return true;
123 } 105 }
124 106
125 namespace { 107 namespace {
(...skipping 15 matching lines...) Expand all
141 for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) { 123 for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) {
142 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; 124 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0;
143 } 125 }
144 } 126 }
145 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR owBytes); 127 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR owBytes);
146 src += srcRowBytes; 128 src += srcRowBytes;
147 } 129 }
148 } 130 }
149 } 131 }
150 132
151 bool SkGrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed, 133 bool GrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed,
152 int width, int height, 134 int width, int height,
153 int dstRB, void* dst) { 135 int dstRB, void* dst) {
154 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), 136 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
155 GrGlyph::UnpackFixedX(pack ed), 137 GrGlyph::UnpackFixedX(pack ed),
156 GrGlyph::UnpackFixedY(pack ed)); 138 GrGlyph::UnpackFixedY(pack ed));
157 SkASSERT(glyph.fWidth == width); 139 SkASSERT(glyph.fWidth == width);
158 SkASSERT(glyph.fHeight == height); 140 SkASSERT(glyph.fHeight == height);
159 const void* src = fStrike->findImage(glyph); 141 const void* src = fStrike->findImage(glyph);
160 if (NULL == src) { 142 if (NULL == src) {
161 return false; 143 return false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); 175 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat());
194 for (int y = 0; y < height; y++) { 176 for (int y = 0; y < height; y++) {
195 memcpy(dst, src, width * bbp); 177 memcpy(dst, src, width * bbp);
196 src = (const char*)src + srcRB; 178 src = (const char*)src + srcRB;
197 dst = (char*)dst + dstRB; 179 dst = (char*)dst + dstRB;
198 } 180 }
199 } 181 }
200 return true; 182 return true;
201 } 183 }
202 184
203 bool SkGrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed, 185 bool GrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed,
204 int width, int height, 186 int width, int height,
205 void* dst) { 187 void* dst) {
206 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), 188 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
207 GrGlyph::UnpackFixedX(pack ed), 189 GrGlyph::UnpackFixedX(pack ed),
208 GrGlyph::UnpackFixedY(pack ed)); 190 GrGlyph::UnpackFixedY(pack ed));
209 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); 191 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
210 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); 192 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);
211 const void* src = fStrike->findDistanceField(glyph); 193 const void* src = fStrike->findDistanceField(glyph);
212 if (NULL == src) { 194 if (NULL == src) {
213 return false; 195 return false;
214 } 196 }
215 197
216 memcpy(dst, src, width * height); 198 memcpy(dst, src, width * height);
217 199
218 return true; 200 return true;
219 } 201 }
220 202
221 // we should just return const SkPath* (NULL means false) 203 // we should just return const SkPath* (NULL means false)
222 bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) { 204 bool GrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) {
223 205
224 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID); 206 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID);
225 const SkPath* skPath = fStrike->findPath(glyph); 207 const SkPath* skPath = fStrike->findPath(glyph);
226 if (skPath) { 208 if (skPath) {
227 *path = *skPath; 209 *path = *skPath;
228 return true; 210 return true;
229 } 211 }
230 return false; 212 return false;
231 } 213 }
OLDNEW
« no previous file with comments | « include/gpu/SkGr.h ('k') | src/gpu/GrTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698