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

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

Issue 659993003: Revert of Change drawText() to generate positions and send to drawPosText() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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/GrDistanceFieldTextContext.h ('k') | src/gpu/GrStencilAndCoverTextContext.h » ('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 2013 Google Inc. 2 * Copyright 2013 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 "GrDistanceFieldTextContext.h" 8 #include "GrDistanceFieldTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrBitmapTextContext.h" 10 #include "GrBitmapTextContext.h"
(...skipping 10 matching lines...) Expand all
21 #include "SkColorFilter.h" 21 #include "SkColorFilter.h"
22 #include "SkDistanceFieldGen.h" 22 #include "SkDistanceFieldGen.h"
23 #include "SkDraw.h" 23 #include "SkDraw.h"
24 #include "SkGlyphCache.h" 24 #include "SkGlyphCache.h"
25 #include "SkGpuDevice.h" 25 #include "SkGpuDevice.h"
26 #include "SkPath.h" 26 #include "SkPath.h"
27 #include "SkRTConf.h" 27 #include "SkRTConf.h"
28 #include "SkStrokeRec.h" 28 #include "SkStrokeRec.h"
29 #include "effects/GrDistanceFieldTextureEffect.h" 29 #include "effects/GrDistanceFieldTextureEffect.h"
30 30
31 #include "SkDrawProcs.h"
32 #include "SkTextMapStateProc.h"
33
34 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, 31 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
35 "Dump the contents of the font cache before every purge."); 32 "Dump the contents of the font cache before every purge.");
36 33
37 static const int kSmallDFFontSize = 32; 34 static const int kSmallDFFontSize = 32;
38 static const int kSmallDFFontLimit = 32; 35 static const int kSmallDFFontLimit = 32;
39 static const int kMediumDFFontSize = 64; 36 static const int kMediumDFFontSize = 64;
40 static const int kMediumDFFontLimit = 64; 37 static const int kMediumDFFontLimit = 64;
41 static const int kLargeDFFontSize = 128; 38 static const int kLargeDFFontSize = 128;
42 39
43 namespace { 40 namespace {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (NULL == *gammaTexture) { 200 if (NULL == *gammaTexture) {
204 return; 201 return;
205 } 202 }
206 203
207 (*gammaTexture)->writePixels(0, 0, width, height, 204 (*gammaTexture)->writePixels(0, 0, width, height,
208 (*gammaTexture)->config(), data.get(), 0, 205 (*gammaTexture)->config(), data.get(), 0,
209 GrContext::kDontFlush_PixelOpsFlag); 206 GrContext::kDontFlush_PixelOpsFlag);
210 } 207 }
211 } 208 }
212 209
210 void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint,
211 const char text[], size_t byteLength,
212 SkScalar x, SkScalar y) {
213 SkASSERT(byteLength == 0 || text != NULL);
214
215 // nothing to draw or can't draw
216 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
217 || fSkPaint.getRasterizer()) {
218 return;
219 }
220
221 this->init(paint, skPaint);
222
223 SkScalar sizeRatio = fTextRatio;
224
225 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
226
227 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
228 SkGlyphCache* cache = autoCache.getCache();
229 GrFontScaler* fontScaler = GetGrFontScaler(cache);
230
231 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
232
233 // need to measure first
234 // TODO - generate positions and pre-load cache as well?
235 const char* stop = text + byteLength;
236 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
237 SkFixed stopX = 0;
238 SkFixed stopY = 0;
239
240 const char* textPtr = text;
241 while (textPtr < stop) {
242 // don't need x, y here, since all subpixel variants will have the
243 // same advance
244 const SkGlyph& glyph = glyphCacheProc(cache, &textPtr, 0, 0);
245
246 stopX += glyph.fAdvanceX;
247 stopY += glyph.fAdvanceY;
248 }
249 SkASSERT(textPtr == stop);
250
251 SkScalar alignX = SkFixedToScalar(stopX)*sizeRatio;
252 SkScalar alignY = SkFixedToScalar(stopY)*sizeRatio;
253
254 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
255 alignX = SkScalarHalf(alignX);
256 alignY = SkScalarHalf(alignY);
257 }
258
259 x -= alignX;
260 y -= alignY;
261 }
262
263 SkFixed fx = SkScalarToFixed(x);
264 SkFixed fy = SkScalarToFixed(y);
265 SkFixed fixedScale = SkScalarToFixed(sizeRatio);
266 while (text < stop) {
267 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
268
269 if (glyph.fWidth) {
270 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
271 glyph.getSubXFixed(),
272 glyph.getSubYFixed()),
273 fx,
274 fy,
275 fontScaler);
276 }
277
278 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale);
279 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale);
280 }
281
282 this->finish();
283 }
284
213 void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai nt& skPaint, 285 void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai nt& skPaint,
214 const char text[], size_t byteLengt h, 286 const char text[], size_t byteLengt h,
215 const SkScalar pos[], int scalarsPe rPosition, 287 const SkScalar pos[], int scalarsPe rPosition,
216 const SkPoint& offset) { 288 const SkPoint& offset) {
217 289
218 SkASSERT(byteLength == 0 || text != NULL); 290 SkASSERT(byteLength == 0 || text != NULL);
219 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 291 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
220 292
221 // nothing to draw 293 // nothing to draw
222 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) { 294 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
(...skipping 24 matching lines...) Expand all
247 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), 319 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
248 glyph.getSubXFixed(), 320 glyph.getSubXFixed(),
249 glyph.getSubYFixed()), 321 glyph.getSubYFixed()),
250 SkScalarToFixed(x), 322 SkScalarToFixed(x),
251 SkScalarToFixed(y), 323 SkScalarToFixed(y),
252 fontScaler); 324 fontScaler);
253 } 325 }
254 pos += scalarsPerPosition; 326 pos += scalarsPerPosition;
255 } 327 }
256 } else { 328 } else {
257 SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? SK_ScalarHalf 329 int alignShift = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? 1 : 0;
258 : SK_Scalar1;
259 while (text < stop) { 330 while (text < stop) {
260 // the last 2 parameters are ignored 331 // the last 2 parameters are ignored
261 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 332 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
262 333
263 if (glyph.fWidth) { 334 if (glyph.fWidth) {
264 SkScalar x = offset.x() + pos[0]; 335 SkScalar x = offset.x() + pos[0];
265 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; 336 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ;
266 337
267 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fT extRatio;
268 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fT extRatio;
269
270 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), 338 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
271 glyph.getSubXFixed(), 339 glyph.getSubXFixed(),
272 glyph.getSubYFixed()), 340 glyph.getSubYFixed()),
273 SkScalarToFixed(x - advanceX), 341 SkScalarToFixed(x) - (glyph.fAdvanceX >> align Shift),
274 SkScalarToFixed(y - advanceY), 342 SkScalarToFixed(y) - (glyph.fAdvanceY >> align Shift),
275 fontScaler); 343 fontScaler);
276 } 344 }
277 pos += scalarsPerPosition; 345 pos += scalarsPerPosition;
278 } 346 }
279 } 347 }
280 348
281 this->finish(); 349 this->finish();
282 } 350 }
283 351
284 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { 352 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 fVertexBounds.setLargestInverted(); 681 fVertexBounds.setLargestInverted();
614 } 682 }
615 } 683 }
616 684
617 inline void GrDistanceFieldTextContext::finish() { 685 inline void GrDistanceFieldTextContext::finish() {
618 this->flush(); 686 this->flush();
619 687
620 GrTextContext::finish(); 688 GrTextContext::finish();
621 } 689 }
622 690
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | src/gpu/GrStencilAndCoverTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698