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/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: Move GrFontScaler back to public interface 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
« no previous file with comments | « src/gpu/GrTextStrike.cpp ('k') | src/gpu/effects/GrDistanceFieldTextureEffect.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 "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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 96 }
96 } 97 }
97 98
98 const GrKey* SkGrFontScaler::getKey() { 99 const GrKey* SkGrFontScaler::getKey() {
99 if (NULL == fKey) { 100 if (NULL == fKey) {
100 fKey = SkNEW_ARGS(SkGrDescKey, (fStrike->getDescriptor())); 101 fKey = SkNEW_ARGS(SkGrDescKey, (fStrike->getDescriptor()));
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, SkIRect* bou nds) {
106 SkIRect* bounds) {
107 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), 107 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
108 GrGlyph::UnpackFixedX(packed), 108 GrGlyph::UnpackFixedX(pack ed),
109 GrGlyph::UnpackFixedY(packed)); 109 GrGlyph::UnpackFixedY(pack ed));
110 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); 110 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
111
111 return true; 112 return true;
113 }
112 114
115 bool SkGrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed, SkIRect* b ounds) {
116 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
117 GrGlyph::UnpackFixedX(pack ed),
118 GrGlyph::UnpackFixedY(pack ed));
119 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight);
120 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad);
121
122 return true;
113 } 123 }
114 124
115 namespace { 125 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 126 // 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. 127 // A8, RGB565, or RGBA8888.
118 template <typename INT_TYPE> 128 template <typename INT_TYPE>
119 void expand_bits(INT_TYPE* dst, 129 void expand_bits(INT_TYPE* dst,
120 const uint8_t* src, 130 const uint8_t* src,
121 int width, 131 int width,
122 int height, 132 int height,
(...skipping 12 matching lines...) Expand all
135 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR owBytes); 145 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR owBytes);
136 src += srcRowBytes; 146 src += srcRowBytes;
137 } 147 }
138 } 148 }
139 } 149 }
140 150
141 bool SkGrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed, 151 bool SkGrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed,
142 int width, int height, 152 int width, int height,
143 int dstRB, void* dst) { 153 int dstRB, void* dst) {
144 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), 154 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
145 GrGlyph::UnpackFixedX(packed), 155 GrGlyph::UnpackFixedX(pack ed),
146 GrGlyph::UnpackFixedY(packed)); 156 GrGlyph::UnpackFixedY(pack ed));
147 SkASSERT(glyph.fWidth == width); 157 SkASSERT(glyph.fWidth == width);
148 SkASSERT(glyph.fHeight == height); 158 SkASSERT(glyph.fHeight == height);
149 const void* src = fStrike->findImage(glyph); 159 const void* src = fStrike->findImage(glyph);
150 if (NULL == src) { 160 if (NULL == src) {
151 return false; 161 return false;
152 } 162 }
153 163
154 int srcRB = glyph.rowBytes(); 164 int srcRB = glyph.rowBytes();
155 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i s important here to 165 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i s important here to
156 // check the glyph's format, not the strike's format, and to be able to conv ert to any of the 166 // check the glyph's format, not the strike's format, and to be able to conv ert to any of the
(...skipping 26 matching lines...) Expand all
183 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); 193 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat());
184 for (int y = 0; y < height; y++) { 194 for (int y = 0; y < height; y++) {
185 memcpy(dst, src, width * bbp); 195 memcpy(dst, src, width * bbp);
186 src = (const char*)src + srcRB; 196 src = (const char*)src + srcRB;
187 dst = (char*)dst + dstRB; 197 dst = (char*)dst + dstRB;
188 } 198 }
189 } 199 }
190 return true; 200 return true;
191 } 201 }
192 202
203 bool SkGrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed,
204 int width, int height,
205 void* dst) {
206 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
207 GrGlyph::UnpackFixedX(pack ed),
208 GrGlyph::UnpackFixedY(pack ed));
209 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width);
210 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height);
211 const void* src = fStrike->findDistanceField(glyph);
212 if (NULL == src) {
213 return false;
214 }
215
216 memcpy(dst, src, width * height);
217
218 return true;
219 }
220
193 // we should just return const SkPath* (NULL means false) 221 // we should just return const SkPath* (NULL means false)
194 bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) { 222 bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) {
195 223
196 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID); 224 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID);
197 const SkPath* skPath = fStrike->findPath(glyph); 225 const SkPath* skPath = fStrike->findPath(glyph);
198 if (skPath) { 226 if (skPath) {
199 *path = *skPath; 227 *path = *skPath;
200 return true; 228 return true;
201 } 229 }
202 return false; 230 return false;
203 } 231 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextStrike.cpp ('k') | src/gpu/effects/GrDistanceFieldTextureEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698