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

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

Issue 227593010: Move distance field generation to the glyph cache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Re-disable distance fields Created 6 years, 8 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 9
10 #include "GrTemplates.h" 10 #include "GrTemplates.h"
11 #include "SkGr.h" 11 #include "SkGr.h"
12 #include "SkDescriptor.h" 12 #include "SkDescriptor.h"
13 #include "SkDistanceFieldGen.h"
13 #include "SkGlyphCache.h" 14 #include "SkGlyphCache.h"
14 15
15 class SkGrDescKey : public GrKey { 16 class SkGrDescKey : public GrKey {
16 public: 17 public:
17 explicit SkGrDescKey(const SkDescriptor& desc); 18 explicit SkGrDescKey(const SkDescriptor& desc);
18 virtual ~SkGrDescKey(); 19 virtual ~SkGrDescKey();
19 20
20 protected: 21 protected:
21 // overrides 22 // overrides
22 virtual bool lt(const GrKey& rh) const; 23 virtual bool lt(const GrKey& rh) const;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 102 }
102 return fKey; 103 return fKey;
103 } 104 }
104 105
105 bool SkGrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, 106 bool SkGrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed,
106 SkIRect* bounds) { 107 SkIRect* bounds) {
107 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), 108 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
108 GrGlyph::UnpackFixedX(packed), 109 GrGlyph::UnpackFixedX(packed),
109 GrGlyph::UnpackFixedY(packed)); 110 GrGlyph::UnpackFixedY(packed));
110 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); 111 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
112
111 return true; 113 return true;
114 }
112 115
116 bool SkGrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed,
robertphillips 2014/04/11 14:13:00 Align or fit on one line?
jvanverth1 2014/04/11 17:54:14 Done.
117 SkIRect* bounds) {
118 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
robertphillips 2014/04/11 14:13:00 align?
jvanverth1 2014/04/11 17:54:14 Done.
119 GrGlyph::UnpackFixedX(packed),
120 GrGlyph::UnpackFixedY(packed));
121 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
122 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad);
123
124 return true;
113 } 125 }
114 126
115 namespace { 127 namespace {
116 // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a B W glyph mask to 128 // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a B W glyph mask to
117 // A8, RGB565, or RGBA8888. 129 // A8, RGB565, or RGBA8888.
118 template <typename INT_TYPE> 130 template <typename INT_TYPE>
119 void expand_bits(INT_TYPE* dst, 131 void expand_bits(INT_TYPE* dst,
120 const uint8_t* src, 132 const uint8_t* src,
121 int width, 133 int width,
122 int height, 134 int height,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); 195 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat());
184 for (int y = 0; y < height; y++) { 196 for (int y = 0; y < height; y++) {
185 memcpy(dst, src, width * bbp); 197 memcpy(dst, src, width * bbp);
186 src = (const char*)src + srcRB; 198 src = (const char*)src + srcRB;
187 dst = (char*)dst + dstRB; 199 dst = (char*)dst + dstRB;
188 } 200 }
189 } 201 }
190 return true; 202 return true;
191 } 203 }
192 204
205 bool SkGrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed,
206 int width, int height,
207 int dstRB, void* dst) {
208 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
robertphillips 2014/04/11 14:13:00 align?
jvanverth1 2014/04/11 17:54:14 Done.
209 GrGlyph::UnpackFixedX(packed),
210 GrGlyph::UnpackFixedY(packed));
211 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
212 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);
213 const void* src = fStrike->findDistanceField(glyph);
214 if (NULL == src) {
215 return false;
216 }
217
robertphillips 2014/04/11 14:13:00 At a higher-level why are we copying out here?
jvanverth1 2014/04/11 17:54:14 The short answer is: to match getPackedGlyphImage.
218 memcpy(dst, src, width * height);
219
220 return true;
221 }
222
193 // we should just return const SkPath* (NULL means false) 223 // we should just return const SkPath* (NULL means false)
194 bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) { 224 bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) {
195 225
196 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID); 226 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID);
197 const SkPath* skPath = fStrike->findPath(glyph); 227 const SkPath* skPath = fStrike->findPath(glyph);
198 if (skPath) { 228 if (skPath) {
199 *path = *skPath; 229 *path = *skPath;
200 return true; 230 return true;
201 } 231 }
202 return false; 232 return false;
203 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698