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

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

Issue 1718423002: Simplify and combine SkDrawCacheProc and SkMeasureCacheProc to SkPaint::GlyphCacheProc. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: 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
« no previous file with comments | « src/gpu/text/GrStencilAndCoverTextContext.cpp ('k') | src/pdf/SkPDFDevice.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 "GrTextUtils.h" 8 #include "GrTextUtils.h"
9 9
10 #include "GrAtlasTextBlob.h" 10 #include "GrAtlasTextBlob.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const SkMatrix& viewMatrix, 251 const SkMatrix& viewMatrix,
252 const char text[], size_t byteLength, 252 const char text[], size_t byteLength,
253 SkScalar x, SkScalar y) { 253 SkScalar x, SkScalar y) {
254 SkASSERT(byteLength == 0 || text != nullptr); 254 SkASSERT(byteLength == 0 || text != nullptr);
255 255
256 // nothing to draw 256 // nothing to draw
257 if (text == nullptr || byteLength == 0) { 257 if (text == nullptr || byteLength == 0) {
258 return; 258 return;
259 } 259 }
260 260
261 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); 261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true);
262 SkAutoDescriptor desc; 262 SkAutoDescriptor desc;
263 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu llptr); 263 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu llptr);
264 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (), 264 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (),
265 desc.getDesc()); 265 desc.getDesc());
266 266
267 SkTArray<SkScalar> positions; 267 SkTArray<SkScalar> positions;
268 268
269 const char* textPtr = text; 269 const char* textPtr = text;
270 SkFixed stopX = 0; 270 SkFixed stopX = 0;
271 SkFixed stopY = 0; 271 SkFixed stopY = 0;
272 SkFixed origin = 0; 272 SkFixed origin = 0;
273 switch (skPaint.getTextAlign()) { 273 switch (skPaint.getTextAlign()) {
274 case SkPaint::kRight_Align: origin = SK_Fixed1; break; 274 case SkPaint::kRight_Align: origin = SK_Fixed1; break;
275 case SkPaint::kCenter_Align: origin = SK_FixedHalf; break; 275 case SkPaint::kCenter_Align: origin = SK_FixedHalf; break;
276 case SkPaint::kLeft_Align: origin = 0; break; 276 case SkPaint::kLeft_Align: origin = 0; break;
277 } 277 }
278 278
279 SkAutoKern autokern; 279 SkAutoKern autokern;
280 const char* stop = text + byteLength; 280 const char* stop = text + byteLength;
281 while (textPtr < stop) { 281 while (textPtr < stop) {
282 // don't need x, y here, since all subpixel variants will have the 282 // don't need x, y here, since all subpixel variants will have the
283 // same advance 283 // same advance
284 const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr, 0, 0); 284 const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr);
285 285
286 SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph); 286 SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph);
287 positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width))); 287 positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width)));
288 288
289 SkFixed height = glyph.fAdvanceY; 289 SkFixed height = glyph.fAdvanceY;
290 positions.push_back(SkFixedToScalar(stopY + SkFixedMul(origin, height))) ; 290 positions.push_back(SkFixedToScalar(stopY + SkFixedMul(origin, height))) ;
291 291
292 stopX += width; 292 stopX += width;
293 stopY += height; 293 stopY += height;
294 } 294 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 SkScalar textRatio; 336 SkScalar textRatio;
337 SkPaint dfPaint(origPaint); 337 SkPaint dfPaint(origPaint);
338 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix); 338 GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix);
339 blob->setHasDistanceField(); 339 blob->setHasDistanceField();
340 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText()); 340 blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText());
341 341
342 GrBatchTextStrike* currStrike = nullptr; 342 GrBatchTextStrike* currStrike = nullptr;
343 343
344 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma:: Off, 344 SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma:: Off,
345 dfPaint, nullptr); 345 dfPaint, nullptr);
346 SkDrawCacheProc glyphCacheProc = dfPaint.getDrawCacheProc(); 346 SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true);
347 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); 347 GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache);
348 348
349 const char* stop = text + byteLength; 349 const char* stop = text + byteLength;
350 350
351 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) { 351 if (SkPaint::kLeft_Align == dfPaint.getTextAlign()) {
352 while (text < stop) { 352 while (text < stop) {
353 const char* lastText = text; 353 const char* lastText = text;
354 // the last 2 parameters are ignored 354 // the last 2 parameters are ignored
355 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 355 const SkGlyph& glyph = glyphCacheProc(cache, &text);
356 356
357 if (glyph.fWidth) { 357 if (glyph.fWidth) {
358 SkScalar x = offset.x() + pos[0]; 358 SkScalar x = offset.x() + pos[0];
359 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; 359 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ;
360 360
361 if (!DfAppendGlyph(blob, 361 if (!DfAppendGlyph(blob,
362 runIndex, 362 runIndex,
363 fontCache, 363 fontCache,
364 &currStrike, 364 &currStrike,
365 glyph, 365 glyph,
366 x, y, color, fontScaler, 366 x, y, color, fontScaler,
367 textRatio, viewMatrix)) { 367 textRatio, viewMatrix)) {
368 // couldn't append, send to fallback 368 // couldn't append, send to fallback
369 fallbackTxt.append(SkToInt(text-lastText), lastText); 369 fallbackTxt.append(SkToInt(text-lastText), lastText);
370 *fallbackPos.append() = pos[0]; 370 *fallbackPos.append() = pos[0];
371 if (2 == scalarsPerPosition) { 371 if (2 == scalarsPerPosition) {
372 *fallbackPos.append() = pos[1]; 372 *fallbackPos.append() = pos[1];
373 } 373 }
374 } 374 }
375 } 375 }
376 pos += scalarsPerPosition; 376 pos += scalarsPerPosition;
377 } 377 }
378 } else { 378 } else {
379 SkScalar alignMul = SkPaint::kCenter_Align == dfPaint.getTextAlign() ? S K_ScalarHalf 379 SkScalar alignMul = SkPaint::kCenter_Align == dfPaint.getTextAlign() ? S K_ScalarHalf
380 : S K_Scalar1; 380 : S K_Scalar1;
381 while (text < stop) { 381 while (text < stop) {
382 const char* lastText = text; 382 const char* lastText = text;
383 // the last 2 parameters are ignored 383 // the last 2 parameters are ignored
384 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 384 const SkGlyph& glyph = glyphCacheProc(cache, &text);
385 385
386 if (glyph.fWidth) { 386 if (glyph.fWidth) {
387 SkScalar x = offset.x() + pos[0]; 387 SkScalar x = offset.x() + pos[0];
388 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; 388 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ;
389 389
390 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio; 390 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio;
391 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio; 391 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio;
392 392
393 if (!DfAppendGlyph(blob, 393 if (!DfAppendGlyph(blob,
394 runIndex, 394 runIndex,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 SkPaint paint(origPaint); 500 SkPaint paint(origPaint);
501 SkScalar matrixScale = paint.setupForAsPaths(); 501 SkScalar matrixScale = paint.setupForAsPaths();
502 502
503 SkMatrix matrix; 503 SkMatrix matrix;
504 matrix.setScale(matrixScale, matrixScale); 504 matrix.setScale(matrixScale, matrixScale);
505 505
506 // Temporarily jam in kFill, so we only ever ask for the raw outline from th e cache. 506 // Temporarily jam in kFill, so we only ever ask for the raw outline from th e cache.
507 paint.setStyle(SkPaint::kFill_Style); 507 paint.setStyle(SkPaint::kFill_Style);
508 paint.setPathEffect(nullptr); 508 paint.setPathEffect(nullptr);
509 509
510 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 510 SkPaint::GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(true);
511 SkAutoGlyphCache autoCache(paint, &props, nullptr); 511 SkAutoGlyphCache autoCache(paint, &props, nullptr);
512 SkGlyphCache* cache = autoCache.getCache(); 512 SkGlyphCache* cache = autoCache.getCache();
513 513
514 const char* stop = text + byteLength; 514 const char* stop = text + byteLength;
515 SkTextAlignProc alignProc(paint.getTextAlign()); 515 SkTextAlignProc alignProc(paint.getTextAlign());
516 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); 516 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
517 517
518 // Now restore the original settings, so we "draw" with whatever style/strok ing. 518 // Now restore the original settings, so we "draw" with whatever style/strok ing.
519 paint.setStyle(origPaint.getStyle()); 519 paint.setStyle(origPaint.getStyle());
520 paint.setPathEffect(origPaint.getPathEffect()); 520 paint.setPathEffect(origPaint.getPathEffect());
521 521
522 while (text < stop) { 522 while (text < stop) {
523 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 523 const SkGlyph& glyph = glyphCacheProc(cache, &text);
524 if (glyph.fWidth) { 524 if (glyph.fWidth) {
525 const SkPath* path = cache->findPath(glyph); 525 const SkPath* path = cache->findPath(glyph);
526 if (path) { 526 if (path) {
527 SkPoint tmsLoc; 527 SkPoint tmsLoc;
528 tmsProc(pos, &tmsLoc); 528 tmsProc(pos, &tmsLoc);
529 SkPoint loc; 529 SkPoint loc;
530 alignProc(tmsLoc, glyph, &loc); 530 alignProc(tmsLoc, glyph, &loc);
531 531
532 matrix[SkMatrix::kMTransX] = loc.fX; 532 matrix[SkMatrix::kMTransX] = loc.fX;
533 matrix[SkMatrix::kMTransY] = loc.fY; 533 matrix[SkMatrix::kMTransY] = loc.fY;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) { 575 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) {
576 scaler = (GrFontScaler*)auxData; 576 scaler = (GrFontScaler*)auxData;
577 } 577 }
578 if (nullptr == scaler) { 578 if (nullptr == scaler) {
579 scaler = new GrFontScaler(cache); 579 scaler = new GrFontScaler(cache);
580 cache->setAuxProc(glyph_cache_aux_proc, scaler); 580 cache->setAuxProc(glyph_cache_aux_proc, scaler);
581 } 581 }
582 582
583 return scaler; 583 return scaler;
584 } 584 }
OLDNEW
« no previous file with comments | « src/gpu/text/GrStencilAndCoverTextContext.cpp ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698