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

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

Issue 1267623004: Revert of Modifying TextBlobCacheTest to use SkRandomScalerContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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') | src/gpu/GrAtlasTextContext.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 * Copyright 2015 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 "SkRandomScalerContext.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 #include "SkRasterizer.h"
13 12
14 class SkRandomScalerContext : public SkScalerContext { 13 class SkRandomScalerContext : public SkScalerContext {
15 public: 14 public:
16 SkRandomScalerContext(SkRandomTypeface*, const SkDescriptor*, bool fFakeIt); 15 SkRandomScalerContext(SkRandomTypeface*, const SkDescriptor*);
17 virtual ~SkRandomScalerContext(); 16 virtual ~SkRandomScalerContext();
18 17
19 protected: 18 protected:
20 unsigned generateGlyphCount() override; 19 unsigned generateGlyphCount() override;
21 uint16_t generateCharToGlyph(SkUnichar) override; 20 uint16_t generateCharToGlyph(SkUnichar) override;
22 void generateAdvance(SkGlyph*) override; 21 void generateAdvance(SkGlyph*) override;
23 void generateMetrics(SkGlyph*) override; 22 void generateMetrics(SkGlyph*) override;
24 void generateImage(const SkGlyph&) override; 23 void generateImage(const SkGlyph&) override;
25 void generatePath(const SkGlyph&, SkPath*) override; 24 void generatePath(const SkGlyph&, SkPath*) override;
26 void generateFontMetrics(SkPaint::FontMetrics*) override; 25 void generateFontMetrics(SkPaint::FontMetrics*) override;
27 26
28 private: 27 private:
29 SkRandomTypeface* fFace; 28 SkRandomTypeface* fFace;
30 SkScalerContext* fProxy; 29 SkScalerContext* fProxy;
31 SkMatrix fMatrix; 30 SkMatrix fMatrix;
32 bool fFakeIt;
33 }; 31 };
34 32
35 #define STD_SIZE 1 33 #define STD_SIZE 1
36 34
37 #include "SkDescriptor.h" 35 #include "SkDescriptor.h"
38 36
39 SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDes criptor* desc, 37 SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDes criptor* desc)
40 bool fakeIt)
41 : SkScalerContext(face, desc) 38 : SkScalerContext(face, desc)
42 , fFace(face) 39 , fFace(face) {
43 , fFakeIt(fakeIt) {
44 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext ::Rec); 40 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext ::Rec);
45 SkAutoDescriptor ad(descSize); 41 SkAutoDescriptor ad(descSize);
46 SkDescriptor* newDesc = ad.getDesc(); 42 SkDescriptor* newDesc = ad.getDesc();
47 43
48 newDesc->init(); 44 newDesc->init();
49 void* entry = newDesc->addEntry(kRec_SkDescriptorTag, 45 void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
50 sizeof(SkScalerContext::Rec), &fRec); 46 sizeof(SkScalerContext::Rec), &fRec);
51 { 47 {
52 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry; 48 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
53 rec->fTextSize = STD_SIZE; 49 rec->fTextSize = STD_SIZE;
(...skipping 27 matching lines...) Expand all
81 fProxy->getAdvance(glyph); 77 fProxy->getAdvance(glyph);
82 78
83 SkVector advance; 79 SkVector advance;
84 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX), 80 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
85 SkFixedToScalar(glyph->fAdvanceY), &advance); 81 SkFixedToScalar(glyph->fAdvanceY), &advance);
86 glyph->fAdvanceX = SkScalarToFixed(advance.fX); 82 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
87 glyph->fAdvanceY = SkScalarToFixed(advance.fY); 83 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
88 } 84 }
89 85
90 void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) { 86 void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
87 fProxy->getAdvance(glyph);
88
89 SkVector advance;
90 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
91 SkFixedToScalar(glyph->fAdvanceY), &advance);
92 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
93 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
94
95 SkPath path;
96 fProxy->getPath(*glyph, &path);
97 path.transform(fMatrix);
98
99 SkRect storage;
100 const SkPaint& paint = fFace->paint();
101 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
102 &storage,
103 SkPaint::kFill_Style);
104 SkIRect ibounds;
105 newBounds.roundOut(&ibounds);
106 glyph->fLeft = ibounds.fLeft;
107 glyph->fTop = ibounds.fTop;
108 glyph->fWidth = ibounds.width();
109 glyph->fHeight = ibounds.height();
110
91 // Here we will change the mask format of the glyph 111 // Here we will change the mask format of the glyph
92 // NOTE this is being overridden by the base class 112 // NOTE this is being overridden by the base class
93 SkMask::Format format; 113 SkMask::Format format;
94 switch (glyph->getGlyphID() % 3) { 114 switch (glyph->getGlyphID() % 6) {
95 case 0: 115 case 0:
96 format = SkMask::kLCD16_Format; 116 format = SkMask::kLCD16_Format;
97 break; 117 break;
98 case 1: 118 case 1:
99 format = SkMask::kA8_Format; 119 format = SkMask::kA8_Format;
100 break; 120 break;
101 case 2: 121 case 2:
102 format = SkMask::kARGB32_Format; 122 format = SkMask::kARGB32_Format;
103 break; 123 break;
124 default:
125 // we will fiddle with these in generate image
126 format = (SkMask::Format)MASK_FORMAT_UNKNOWN;
104 } 127 }
105 128
106 glyph->fMaskFormat = format; 129 glyph->fMaskFormat = format;
107 fProxy->getMetrics(glyph);
108
109 if (SkMask::kARGB32_Format == format) {
110 SkVector advance;
111 fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
112 SkFixedToScalar(glyph->fAdvanceY), &advance);
113 glyph->fAdvanceX = SkScalarToFixed(advance.fX);
114 glyph->fAdvanceY = SkScalarToFixed(advance.fY);
115
116 SkPath path;
117 fProxy->getPath(*glyph, &path);
118 path.transform(fMatrix);
119
120 SkRect storage;
121 const SkPaint& paint = fFace->paint();
122 const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
123 &storage,
124 SkPaint::kFill_Style );
125 SkIRect ibounds;
126 newBounds.roundOut(&ibounds);
127 glyph->fLeft = ibounds.fLeft;
128 glyph->fTop = ibounds.fTop;
129 glyph->fWidth = ibounds.width();
130 glyph->fHeight = ibounds.height();
131 } else {
132 SkPath devPath, fillPath;
133 SkMatrix fillToDevMatrix;
134
135 this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix);
136
137 // just use devPath
138 const SkIRect ir = devPath.getBounds().roundOut();
139
140 if (ir.isEmpty() || !ir.is16Bit()) {
141 glyph->fLeft = 0;
142 glyph->fTop = 0;
143 glyph->fWidth = 0;
144 glyph->fHeight = 0;
145 return;
146 }
147 glyph->fLeft = ir.fLeft;
148 glyph->fTop = ir.fTop;
149 glyph->fWidth = SkToU16(ir.width());
150 glyph->fHeight = SkToU16(ir.height());
151
152 if (glyph->fWidth > 0) {
153 switch (glyph->fMaskFormat) {
154 case SkMask::kLCD16_Format:
155 glyph->fWidth += 2;
156 glyph->fLeft -= 1;
157 break;
158 default:
159 break;
160 }
161 }
162 }
163 } 130 }
164 131
165 void SkRandomScalerContext::generateImage(const SkGlyph& glyph) { 132 void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
166 SkMask::Format format = (SkMask::Format)glyph.fMaskFormat; 133 SkMask::Format format = (SkMask::Format)glyph.fMaskFormat;
167 switch (glyph.getGlyphID() % 3) { 134 switch (glyph.getGlyphID() % 6) {
168 case 0: 135 case 0:
136 case 1:
137 case 2:
138 break;
139 case 3:
169 format = SkMask::kLCD16_Format; 140 format = SkMask::kLCD16_Format;
170 break; 141 break;
171 case 1: 142 case 4:
172 format = SkMask::kA8_Format; 143 format = SkMask::kA8_Format;
173 break; 144 break;
174 case 2: 145 case 5:
175 format = SkMask::kARGB32_Format; 146 format = SkMask::kARGB32_Format;
176 break; 147 break;
177 } 148 }
178 const_cast<SkGlyph&>(glyph).fMaskFormat = format; 149 const_cast<SkGlyph&>(glyph).fMaskFormat = format;
179 150
180 // if the format is ARGB, we just draw the glyph from path ourselves. Other wise, we force 151 // if the format is ARGB, we just draw the glyph from path ourselves. Other wise, we force
181 // our proxy context to generate the image from paths. 152 // our proxy context to generate the image from paths.
182 if (!fFakeIt) { 153 if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
183 if (SkMask::kARGB32_Format == glyph.fMaskFormat) { 154 SkPath path;
184 SkPath path; 155 fProxy->getPath(glyph, &path);
185 fProxy->getPath(glyph, &path);
186 156
187 SkBitmap bm; 157 SkBitmap bm;
188 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHei ght), 158 bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight) ,
189 glyph.fImage, glyph.rowBytes()); 159 glyph.fImage, glyph.rowBytes());
190 bm.eraseColor(0); 160 bm.eraseColor(0);
191 161
192 SkCanvas canvas(bm); 162 SkCanvas canvas(bm);
193 canvas.translate(-SkIntToScalar(glyph.fLeft), 163 canvas.translate(-SkIntToScalar(glyph.fLeft),
194 -SkIntToScalar(glyph.fTop)); 164 -SkIntToScalar(glyph.fTop));
195 canvas.concat(fMatrix); 165 canvas.concat(fMatrix);
196 canvas.drawPath(path, fFace->paint()); 166 canvas.drawPath(path, fFace->paint());
197 } else {
198 fProxy->forceGenerateImageFromPath();
199 fProxy->getImage(glyph);
200 fProxy->forceOffGenerateImageFromPath();
201 }
202 } else { 167 } else {
203 sk_bzero(glyph.fImage, glyph.computeImageSize()); 168 this->forceGenerateImageFromPath();
169 fProxy->getImage(glyph);
170 this->forceOffGenerateImageFromPath();
204 } 171 }
205 } 172 }
206 173
207 void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) { 174 void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) {
208 fProxy->getPath(glyph, path); 175 fProxy->getPath(glyph, path);
209 path->transform(fMatrix); 176 path->transform(fMatrix);
210 } 177 }
211 178
212 void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { 179 void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
213 fProxy->getFontMetrics(metrics); 180 fProxy->getFontMetrics(metrics);
214 if (metrics) { 181 if (metrics) {
215 SkScalar scale = fMatrix.getScaleY(); 182 SkScalar scale = fMatrix.getScaleY();
216 metrics->fTop = SkScalarMul(metrics->fTop, scale); 183 metrics->fTop = SkScalarMul(metrics->fTop, scale);
217 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); 184 metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
218 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); 185 metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
219 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); 186 metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
220 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); 187 metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
221 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); 188 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
222 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); 189 metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
223 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); 190 metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
224 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale); 191 metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
225 } 192 }
226 } 193 }
227 194
228 /////////////////////////////////////////////////////////////////////////////// 195 ///////////////////////////////////////////////////////////////////////////////
229 196
230 #include "SkTypefaceCache.h" 197 #include "SkTypefaceCache.h"
231 198
232 SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint, bool fakeIt) 199 SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint)
233 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false) 200 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
234 , fProxy(SkRef(proxy)) 201 , fProxy(SkRef(proxy))
235 , fPaint(paint) 202 , fPaint(paint) {}
236 , fFakeIt(fakeIt) {}
237 203
238 SkRandomTypeface::~SkRandomTypeface() { 204 SkRandomTypeface::~SkRandomTypeface() {
239 fProxy->unref(); 205 fProxy->unref();
240 } 206 }
241 207
242 SkScalerContext* SkRandomTypeface::onCreateScalerContext( 208 SkScalerContext* SkRandomTypeface::onCreateScalerContext(
243 const SkDescriptor* desc) const { 209 const SkDescriptor* desc) const {
244 return SkNEW_ARGS(SkRandomScalerContext, (const_cast<SkRandomTypeface*>(this ), desc, fFakeIt)); 210 return SkNEW_ARGS(SkRandomScalerContext, (const_cast<SkRandomTypeface*>(this ), desc));
245 } 211 }
246 212
247 void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const { 213 void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {
248 fProxy->filterRec(rec); 214 fProxy->filterRec(rec);
249 rec->setHinting(SkPaint::kNo_Hinting); 215 rec->setHinting(SkPaint::kNo_Hinting);
250 rec->fMaskFormat = SkMask::kARGB32_Format; 216 rec->fMaskFormat = SkMask::kARGB32_Format;
251 } 217 }
252 218
253 SkAdvancedTypefaceMetrics* SkRandomTypeface::onGetAdvancedTypefaceMetrics( 219 SkAdvancedTypefaceMetrics* SkRandomTypeface::onGetAdvancedTypefaceMetrics(
254 PerGlyphInfo info, 220 PerGlyphInfo info,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 255
290 int SkRandomTypeface::onGetTableTags(SkFontTableTag tags[]) const { 256 int SkRandomTypeface::onGetTableTags(SkFontTableTag tags[]) const {
291 return fProxy->getTableTags(tags); 257 return fProxy->getTableTags(tags);
292 } 258 }
293 259
294 size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag, size_t offset, 260 size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
295 size_t length, void* data) const { 261 size_t length, void* data) const {
296 return fProxy->getTableData(tag, offset, length, data); 262 return fProxy->getTableData(tag, offset, length, data);
297 } 263 }
298 264
OLDNEW
« no previous file with comments | « src/fonts/SkRandomScalerContext.h ('k') | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698