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

Side by Side Diff: src/fonts/SkRandomScalerContext.cpp

Issue 1260473004: Adding debug SkScalerContext which returns random mask formats (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc Created 5 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 | « src/fonts/SkRandomScalerContext.h ('k') | no next file » | 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 * Copyright 2013 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGScalerContext.h" 8 #include "SkRandomScalerContext.h"
9 #include "SkGlyph.h" 9 #include "SkGlyph.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 12
13 class SkGScalerContext : public SkScalerContext { 13 class SkRandomScalerContext : public SkScalerContext {
14 public: 14 public:
15 SkGScalerContext(SkGTypeface*, const SkDescriptor*); 15 SkRandomScalerContext(SkRandomTypeface*, const SkDescriptor*);
16 virtual ~SkGScalerContext(); 16 virtual ~SkRandomScalerContext();
17 17
18 protected: 18 protected:
19 unsigned generateGlyphCount() override; 19 unsigned generateGlyphCount() override;
20 uint16_t generateCharToGlyph(SkUnichar) override; 20 uint16_t generateCharToGlyph(SkUnichar) override;
21 void generateAdvance(SkGlyph*) override; 21 void generateAdvance(SkGlyph*) override;
22 void generateMetrics(SkGlyph*) override; 22 void generateMetrics(SkGlyph*) override;
23 void generateImage(const SkGlyph&) override; 23 void generateImage(const SkGlyph&) override;
24 void generatePath(const SkGlyph&, SkPath*) override; 24 void generatePath(const SkGlyph&, SkPath*) override;
25 void generateFontMetrics(SkPaint::FontMetrics*) override; 25 void generateFontMetrics(SkPaint::FontMetrics*) override;
26 26
27 private: 27 private:
28 SkGTypeface* fFace; 28 SkRandomTypeface* fFace;
29 SkScalerContext* fProxy; 29 SkScalerContext* fProxy;
30 SkMatrix fMatrix; 30 SkMatrix fMatrix;
31 }; 31 };
32 32
33 #define STD_SIZE 1 33 #define STD_SIZE 1
34 34
35 #include "SkDescriptor.h" 35 #include "SkDescriptor.h"
36 36
37 SkGScalerContext::SkGScalerContext(SkGTypeface* face, const SkDescriptor* desc) 37 SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDes criptor* desc)
38 : SkScalerContext(face, desc) 38 : SkScalerContext(face, desc)
39 , fFace(face) 39 , fFace(face) {
40 {
41
42 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext ::Rec); 40 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext ::Rec);
43 SkAutoDescriptor ad(descSize); 41 SkAutoDescriptor ad(descSize);
44 SkDescriptor* newDesc = ad.getDesc(); 42 SkDescriptor* newDesc = ad.getDesc();
45 43
46 newDesc->init(); 44 newDesc->init();
47 void* entry = newDesc->addEntry(kRec_SkDescriptorTag, 45 void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
48 sizeof(SkScalerContext::Rec), &fRec); 46 sizeof(SkScalerContext::Rec), &fRec);
49 { 47 {
50 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry; 48 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
51 rec->fTextSize = STD_SIZE; 49 rec->fTextSize = STD_SIZE;
52 rec->fPreScaleX = SK_Scalar1; 50 rec->fPreScaleX = SK_Scalar1;
53 rec->fPreSkewX = 0; 51 rec->fPreSkewX = 0;
54 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1; 52 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
55 rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0; 53 rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
56 } 54 }
57 SkASSERT(descSize == newDesc->getLength()); 55 SkASSERT(descSize == newDesc->getLength());
58 newDesc->computeChecksum(); 56 newDesc->computeChecksum();
59 57
60 fProxy = face->proxy()->createScalerContext(newDesc); 58 fProxy = face->proxy()->createScalerContext(newDesc);
61 59
62 fRec.getSingleMatrix(&fMatrix); 60 fRec.getSingleMatrix(&fMatrix);
63 fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE); 61 fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
64 } 62 }
65 63
66 SkGScalerContext::~SkGScalerContext() { 64 SkRandomScalerContext::~SkRandomScalerContext() {
67 SkDELETE(fProxy); 65 SkDELETE(fProxy);
68 } 66 }
69 67
70 unsigned SkGScalerContext::generateGlyphCount() { 68 unsigned SkRandomScalerContext::generateGlyphCount() {
71 return fProxy->getGlyphCount(); 69 return fProxy->getGlyphCount();
72 } 70 }
73 71
74 uint16_t SkGScalerContext::generateCharToGlyph(SkUnichar uni) { 72 uint16_t SkRandomScalerContext::generateCharToGlyph(SkUnichar uni) {
75 return fProxy->charToGlyphID(uni); 73 return fProxy->charToGlyphID(uni);
76 } 74 }
77 75
78 void SkGScalerContext::generateAdvance(SkGlyph* glyph) { 76 void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) {
79 fProxy->getAdvance(glyph); 77 fProxy->getAdvance(glyph);
80 78
81 SkVector advance; 79 SkVector advance;
82 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), 80 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
83 SkFixedToScalar(glyph->fAdvanceY), &advance); 81 SkFixedToScalar(glyph->fAdvanceY), &advance);
84 glyph->fAdvanceX = SkScalarToFixed(advance.fX); 82 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
85 glyph->fAdvanceY = SkScalarToFixed(advance.fY); 83 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
86 } 84 }
87 85
88 void SkGScalerContext::generateMetrics(SkGlyph* glyph) { 86 void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
89 fProxy->getMetrics(glyph); 87 fProxy->getMetrics(glyph);
90 88
91 SkVector advance; 89 SkVector advance;
92 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), 90 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
93 SkFixedToScalar(glyph->fAdvanceY), &advance); 91 SkFixedToScalar(glyph->fAdvanceY), &advance);
94 glyph->fAdvanceX = SkScalarToFixed(advance.fX); 92 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
95 glyph->fAdvanceY = SkScalarToFixed(advance.fY); 93 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
96 94
97 SkPath path; 95 SkPath path;
98 fProxy->getPath(*glyph, &path); 96 fProxy->getPath(*glyph, &path);
99 path.transform(fMatrix); 97 path.transform(fMatrix);
100 98
101 SkRect storage; 99 SkRect storage;
102 const SkPaint& paint = fFace->paint(); 100 const SkPaint& paint = fFace->paint();
103 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(), 101 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
104 &storage, 102 &storage,
105 SkPaint::kFill_Style); 103 SkPaint::kFill_Style);
106 SkIRect ibounds; 104 SkIRect ibounds;
107 newBounds.roundOut(&ibounds); 105 newBounds.roundOut(&ibounds);
108 glyph->fLeft = ibounds.fLeft; 106 glyph->fLeft = ibounds.fLeft;
109 glyph->fTop = ibounds.fTop; 107 glyph->fTop = ibounds.fTop;
110 glyph->fWidth = ibounds.width(); 108 glyph->fWidth = ibounds.width();
111 glyph->fHeight = ibounds.height(); 109 glyph->fHeight = ibounds.height();
112 glyph->fMaskFormat = SkMask::kARGB32_Format; 110
111 // Here we will change the mask format of the glyph
112 // NOTE this is being overridden by the base class
113 SkMask::Format format;
114 switch (glyph->getGlyphID() % 3) {
115 case 0:
116 format = SkMask::kLCD16_Format;
117 break;
118 case 1:
119 format = SkMask::kA8_Format;
120 break;
121 default:
122 format = SkMask::kARGB32_Format;
123 }
124
125 glyph->fMaskFormat = format;
113 } 126 }
114 127
115 void SkGScalerContext::generateImage(const SkGlyph& glyph) { 128 void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
129 SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat);
116 if (SkMask::kARGB32_Format == glyph.fMaskFormat) { 130 if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
117 SkPath path; 131 SkPath path;
118 fProxy->getPath(glyph, &path); 132 fProxy->getPath(glyph, &path);
119 133
120 SkBitmap bm; 134 SkBitmap bm;
121 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight) , 135 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight) ,
122 glyph.fImage, glyph.rowBytes()); 136 glyph.fImage, glyph.rowBytes());
123 bm.eraseColor(0); 137 bm.eraseColor(0);
124 138
125 SkCanvas canvas(bm); 139 SkCanvas canvas(bm);
126 canvas.translate(-SkIntToScalar(glyph.fLeft), 140 canvas.translate(-SkIntToScalar(glyph.fLeft),
127 -SkIntToScalar(glyph.fTop)); 141 -SkIntToScalar(glyph.fTop));
128 canvas.concat(fMatrix); 142 canvas.concat(fMatrix);
129 canvas.drawPath(path, fFace->paint()); 143 canvas.drawPath(path, fFace->paint());
130 } else { 144 } else {
131 fProxy->getImage(glyph); 145 fProxy->getImage(glyph);
132 } 146 }
147
148 SkASSERT(glyph.fMaskFormat == format);
bungeman-skia 2015/07/24 18:43:53 Even with SkScalerContext not overriding things, t
133 } 149 }
134 150
135 void SkGScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) { 151 void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) {
136 fProxy->getPath(glyph, path); 152 fProxy->getPath(glyph, path);
137 path->transform(fMatrix); 153 path->transform(fMatrix);
138 } 154 }
139 155
140 void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { 156 void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
141 fProxy->getFontMetrics(metrics); 157 fProxy->getFontMetrics(metrics);
142 if (metrics) { 158 if (metrics) {
143 SkScalar scale = fMatrix.getScaleY(); 159 SkScalar scale = fMatrix.getScaleY();
144 metrics->fTop = SkScalarMul(metrics->fTop, scale); 160 metrics->fTop = SkScalarMul(metrics->fTop, scale);
145 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); 161 metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
146 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); 162 metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
147 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); 163 metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
148 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); 164 metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
149 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); 165 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
150 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); 166 metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
151 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); 167 metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
152 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale); 168 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
153 } 169 }
154 } 170 }
155 171
156 /////////////////////////////////////////////////////////////////////////////// 172 ///////////////////////////////////////////////////////////////////////////////
157 173
158 #include "SkTypefaceCache.h" 174 #include "SkTypefaceCache.h"
159 175
160 SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint) 176 SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint)
161 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false) 177 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
162 , fProxy(SkRef(proxy)) 178 , fProxy(SkRef(proxy))
163 , fPaint(paint) {} 179 , fPaint(paint) {}
164 180
165 SkGTypeface::~SkGTypeface() { 181 SkRandomTypeface::~SkRandomTypeface() {
166 fProxy->unref(); 182 fProxy->unref();
167 } 183 }
168 184
169 SkScalerContext* SkGTypeface::onCreateScalerContext( 185 SkScalerContext* SkRandomTypeface::onCreateScalerContext(
170 const SkDescriptor* desc) const { 186 const SkDescriptor* desc) const {
171 return SkNEW_ARGS(SkGScalerContext, (const_cast<SkGTypeface*>(this), desc)); 187 return SkNEW_ARGS(SkRandomScalerContext, (const_cast<SkRandomTypeface*>(this ), desc));
172 } 188 }
173 189
174 void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const { 190 void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {
175 fProxy->filterRec(rec); 191 fProxy->filterRec(rec);
176 rec->setHinting(SkPaint::kNo_Hinting); 192 rec->setHinting(SkPaint::kNo_Hinting);
177 rec->fMaskFormat = SkMask::kARGB32_Format; 193 rec->fMaskFormat = SkMask::kARGB32_Format;
178 } 194 }
179 195
180 SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics( 196 SkAdvancedTypefaceMetrics* SkRandomTypeface::onGetAdvancedTypefaceMetrics(
181 PerGlyphInfo info, 197 PerGlyphInfo info,
182 const uint32_t* glyphIDs, 198 const uint32_t* glyphIDs,
183 uint32_t glyphIDsCount) const { 199 uint32_t glyphIDsCount) const {
184 return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); 200 return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
185 } 201 }
186 202
187 SkStreamAsset* SkGTypeface::onOpenStream(int* ttcIndex) const { 203 SkStreamAsset* SkRandomTypeface::onOpenStream(int* ttcIndex) const {
188 return fProxy->openStream(ttcIndex); 204 return fProxy->openStream(ttcIndex);
189 } 205 }
190 206
191 void SkGTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 207 void SkRandomTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
192 bool* isLocal) const { 208 bool* isLocal) const {
193 fProxy->getFontDescriptor(desc, isLocal); 209 fProxy->getFontDescriptor(desc, isLocal);
194 } 210 }
195 211
196 int SkGTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, 212 int SkRandomTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
197 uint16_t glyphs[], int glyphCount) const { 213 uint16_t glyphs[], int glyphCount) const {
198 return fProxy->charsToGlyphs(chars, encoding, glyphs, glyphCount); 214 return fProxy->charsToGlyphs(chars, encoding, glyphs, glyphCount);
199 } 215 }
200 216
201 int SkGTypeface::onCountGlyphs() const { 217 int SkRandomTypeface::onCountGlyphs() const {
202 return fProxy->countGlyphs(); 218 return fProxy->countGlyphs();
203 } 219 }
204 220
205 int SkGTypeface::onGetUPEM() const { 221 int SkRandomTypeface::onGetUPEM() const {
206 return fProxy->getUnitsPerEm(); 222 return fProxy->getUnitsPerEm();
207 } 223 }
208 224
209 void SkGTypeface::onGetFamilyName(SkString* familyName) const { 225 void SkRandomTypeface::onGetFamilyName(SkString* familyName) const {
210 fProxy->getFamilyName(familyName); 226 fProxy->getFamilyName(familyName);
211 } 227 }
212 228
213 SkTypeface::LocalizedStrings* SkGTypeface::onCreateFamilyNameIterator() const { 229 SkTypeface::LocalizedStrings* SkRandomTypeface::onCreateFamilyNameIterator() con st {
214 return fProxy->createFamilyNameIterator(); 230 return fProxy->createFamilyNameIterator();
215 } 231 }
216 232
217 int SkGTypeface::onGetTableTags(SkFontTableTag tags[]) const { 233 int SkRandomTypeface::onGetTableTags(SkFontTableTag tags[]) const {
218 return fProxy->getTableTags(tags); 234 return fProxy->getTableTags(tags);
219 } 235 }
220 236
221 size_t SkGTypeface::onGetTableData(SkFontTableTag tag, size_t offset, 237 size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
222 size_t length, void* data) const { 238 size_t length, void* data) const {
223 return fProxy->getTableData(tag, offset, length, data); 239 return fProxy->getTableData(tag, offset, length, data);
224 } 240 }
225 241
226 ///////////////////////////////////////////////////////////////////////////////
227
228 #if 0
229 // under construction -- defining a font purely in terms of skia primitives
230 // ala an SVG-font.
231 class SkGFont : public SkRefCnt {
232 public:
233 virtual ~SkGFont();
234
235 int unicharToGlyph(SkUnichar) const;
236
237 int countGlyphs() const { return fCount; }
238
239 float getAdvance(int index) const {
240 SkASSERT((unsigned)index < (unsigned)fCount);
241 return fGlyphs[index].fAdvance;
242 }
243
244 const SkPath& getPath(int index) const {
245 SkASSERT((unsigned)index < (unsigned)fCount);
246 return fGlyphs[index].fPath;
247 }
248
249 private:
250 struct Glyph {
251 SkUnichar fUni;
252 float fAdvance;
253 SkPath fPath;
254 };
255 int fCount;
256 Glyph* fGlyphs;
257
258 friend class SkGFontBuilder;
259 SkGFont(int count, Glyph* array);
260 };
261
262 class SkGFontBuilder {
263 public:
264
265 };
266 #endif
OLDNEW
« no previous file with comments | « src/fonts/SkRandomScalerContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698