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

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

Issue 1643143002: Generate Signed Distance Field directly from vector path (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove get direction and add text SDF support Created 4 years, 10 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
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 #include "GrFontScaler.h" 9 #include "GrFontScaler.h"
10 #include "SkDescriptor.h" 10 #include "SkDescriptor.h"
11 #include "SkDistanceFieldGen.h" 11 #include "SkDistanceFieldGen.h"
12 #include "GrDistanceFieldGenFromVector.h"
12 #include "SkGlyphCache.h" 13 #include "SkGlyphCache.h"
13 14
14 /////////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////////
15 16
16 GrFontScaler::GrFontScaler(SkGlyphCache* strike) { 17 GrFontScaler::GrFontScaler(SkGlyphCache* strike) {
17 fStrike = strike; 18 fStrike = strike;
18 fKey = nullptr; 19 fKey = nullptr;
19 } 20 }
20 21
21 GrFontScaler::~GrFontScaler() { 22 GrFontScaler::~GrFontScaler() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 src = (const char*)src + srcRB; 164 src = (const char*)src + srcRB;
164 dst = (char*)dst + dstRB; 165 dst = (char*)dst + dstRB;
165 } 166 }
166 } 167 }
167 return true; 168 return true;
168 } 169 }
169 170
170 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he ight, void* dst) { 171 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he ight, void* dst) {
171 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); 172 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
172 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); 173 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);
173 const void* image = fStrike->findImage(glyph); 174 const SkPath* path = fStrike->findPath(glyph);
174 if (nullptr == image) { 175 if (nullptr == path) {
175 return false;
176 }
177 // now generate the distance field
178 SkASSERT(dst);
179 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
180 if (SkMask::kA8_Format == maskFormat) {
181 // make the distance field from the image
182 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst,
183 (unsigned char*)image,
184 glyph.fWidth, glyph.fHeight,
185 glyph.rowBytes());
186 } else if (SkMask::kBW_Format == maskFormat) {
187 // make the distance field from the image
188 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst,
189 (unsigned char*)image,
190 glyph.fWidth, glyph.fHeight,
191 glyph.rowBytes());
192 } else {
193 return false; 176 return false;
194 } 177 }
195 178
179 SkMatrix drawMatrix;
180 drawMatrix.setTranslate(-glyph.fLeft, -glyph.fTop);
181
182 // now generate the distance field
183 SkASSERT(dst);
184 // Generate signed distance field directly from SkPath
185 GrGenerateDistanceFieldFromPath((unsigned char*)dst,
186 *path, drawMatrix,
187 width, height, width * sizeof(unsigned char) );
188
196 return true; 189 return true;
197 } 190 }
198 191
199 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) { 192 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) {
200 return fStrike->findPath(glyph); 193 return fStrike->findPath(glyph);
201 } 194 }
202 195
203 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) { 196 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) {
204 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id), 197 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id),
205 GrGlyph::UnpackFixedX(id), 198 GrGlyph::UnpackFixedX(id),
206 GrGlyph::UnpackFixedY(id)); 199 GrGlyph::UnpackFixedY(id));
207 } 200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698