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

Side by Side Diff: src/core/SkFindAndPlaceGlyph.h

Issue 1424173005: Replace glyph find and position with common code for the gpu bitmap case. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: keep blitter choose alive Created 5 years, 1 month 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/core/SkDraw.cpp ('k') | src/gpu/GrAtlasTextContext.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 #ifndef SkFindAndPositionGlyph_DEFINED 8 #ifndef SkFindAndPositionGlyph_DEFINED
9 #define SkFindAndPositionGlyph_DEFINED 9 #define SkFindAndPositionGlyph_DEFINED
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // to a whole coordinate instead of using sub-pixel positioning. 46 // to a whole coordinate instead of using sub-pixel positioning.
47 // The number of variations is 108 for sub-pixel and 36 for full-pixel. 47 // The number of variations is 108 for sub-pixel and 36 for full-pixel.
48 // This routine handles all of them using inline polymorphic variable (no he ap allocation). 48 // This routine handles all of them using inline polymorphic variable (no he ap allocation).
49 template<typename ProcessOneGlyph> 49 template<typename ProcessOneGlyph>
50 static void ProcessPosText(const char text[], size_t byteLength, 50 static void ProcessPosText(const char text[], size_t byteLength,
51 const SkPoint& offset, const SkMatrix& matrix, 51 const SkPoint& offset, const SkMatrix& matrix,
52 const SkScalar pos[], int scalarsPerPosition, 52 const SkScalar pos[], int scalarsPerPosition,
53 SkPaint::Align textAlignment, SkDrawCacheProc& gl yphCacheProc, 53 SkPaint::Align textAlignment, SkDrawCacheProc& gl yphCacheProc,
54 SkGlyphCache* cache, ProcessOneGlyph&& processOne Glyph); 54 SkGlyphCache* cache, ProcessOneGlyph&& processOne Glyph);
55 55
56 // SpecializedProcessPosText is a version of ProcessPosText that de-virtuali zes the
57 // different components used. It returns true if it can handle the situation , otherwise it
58 // returns false. This allows greater inlining freedom to the compiler. Curr ently, there is
59 // only one specialized variant: sub-pixel position, left-aligned, x-axis-al igned,
60 // translation, and one scalar per position entry.
61 // * This is by far the most common type of text Blink draws.
62 template<typename ProcessOneGlyph>
63 static bool SpecializedProcessPosText(const char* const text, size_t byteLen gth,
64 const SkPoint& offset, const SkMatrix& matrix,
65 const SkScalar pos[], int scalarsPerPo sition,
66 SkPaint::Align textAlignment,
67 SkDrawCacheProc& glyphCacheProc,
68 SkGlyphCache* cache,
69 ProcessOneGlyph&& processOneGlyph);
70
71 private: 56 private:
72 // UntaggedVariant is a pile of memory that can hold one of the Ts. It provi des a way 57 // UntaggedVariant is a pile of memory that can hold one of the Ts. It provi des a way
73 // to initialize that memory in a typesafe way. 58 // to initialize that memory in a typesafe way.
74 template<typename... Ts> 59 template<typename... Ts>
75 class UntaggedVariant { 60 class UntaggedVariant {
76 public: 61 public:
77 UntaggedVariant() { } 62 UntaggedVariant() { }
78 63
79 ~UntaggedVariant() { } 64 ~UntaggedVariant() { }
80 UntaggedVariant(const UntaggedVariant&) = delete; 65 UntaggedVariant(const UntaggedVariant&) = delete;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 395 }
411 } 396 }
412 }; 397 };
413 398
414 template<typename ProcessOneGlyph> 399 template<typename ProcessOneGlyph>
415 inline void SkFindAndPlaceGlyph::ProcessPosText( 400 inline void SkFindAndPlaceGlyph::ProcessPosText(
416 const char text[], size_t byteLength, const SkPoint& offset, const SkMatrix& matrix, 401 const char text[], size_t byteLength, const SkPoint& offset, const SkMatrix& matrix,
417 const SkScalar pos[], int scalarsPerPosition, SkPaint::Align textAlignment, 402 const SkScalar pos[], int scalarsPerPosition, SkPaint::Align textAlignment,
418 SkDrawCacheProc& glyphCacheProc, SkGlyphCache* cache, ProcessOneGlyph&& proc essOneGlyph) { 403 SkDrawCacheProc& glyphCacheProc, SkGlyphCache* cache, ProcessOneGlyph&& proc essOneGlyph) {
419 404
405 SkAxisAlignment axisAlignment = SkComputeAxisAlignmentForHText(matrix);
406 uint32_t mtype = matrix.getType();
407
408 // Specialized code for handling the most common case for blink. The while l oop is totally
409 // de-virtualized.
410 if (scalarsPerPosition == 1
411 && textAlignment == SkPaint::kLeft_Align
412 && axisAlignment == kX_SkAxisAlignment
413 && cache->isSubpixel()
414 && mtype <= SkMatrix::kTranslate_Mask) {
415 typedef GlyphFindAndPlaceSubpixel<
416 ProcessOneGlyph, SkPaint::kLeft_Align, kX_SkAxisAlignment> Positione r;
417 HorizontalPositions positions{pos};
418 TranslationMapper mapper{matrix, offset};
419 Positioner positioner(cache, glyphCacheProc);
420 const char* cursor = text;
421 const char* stop = text + byteLength;
422 while (cursor < stop) {
423 SkPoint mappedPoint = mapper.TranslationMapper::map(
424 positions.HorizontalPositions::nextPoint());
425 positioner.Positioner::findAndPositionGlyph(
426 &cursor, mappedPoint, skstd::forward<ProcessOneGlyph>(processOne Glyph));
427 }
428 return;
429 }
430
420 PositionReader positionReader{ 431 PositionReader positionReader{
421 [&](PositionReader::Variants* to_init) { 432 [&](PositionReader::Variants* to_init) {
422 if (2 == scalarsPerPosition) { 433 if (2 == scalarsPerPosition) {
423 to_init->initialize<ArbitraryPositions>(pos); 434 to_init->initialize<ArbitraryPositions>(pos);
424 } else { 435 } else {
425 to_init->initialize<HorizontalPositions>(pos); 436 to_init->initialize<HorizontalPositions>(pos);
426 } 437 }
427 } 438 }
428 }; 439 };
429 440
430 Mapper mapper{ 441 Mapper mapper{
431 [&](Mapper::Variants* to_init) { 442 [&](Mapper::Variants* to_init) {
432 uint32_t mtype = matrix.getType();
433 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask) 443 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)
434 || scalarsPerPosition == 2) { 444 || scalarsPerPosition == 2) {
435 to_init->initialize<GeneralMapper>(matrix, offset); 445 to_init->initialize<GeneralMapper>(matrix, offset);
436 } else if (mtype & SkMatrix::kScale_Mask) { 446 } else if (mtype & SkMatrix::kScale_Mask) {
437 to_init->initialize<XScaleMapper>(matrix, offset); 447 to_init->initialize<XScaleMapper>(matrix, offset);
438 } else { 448 } else {
439 to_init->initialize<TranslationMapper>(matrix, offset); 449 to_init->initialize<TranslationMapper>(matrix, offset);
440 } 450 }
441 } 451 }
442 }; 452 };
443 453
444 GlyphFindAndPlace<ProcessOneGlyph> findAndPosition{ 454 GlyphFindAndPlace<ProcessOneGlyph> findAndPosition{
445 [&](typename GlyphFindAndPlace<ProcessOneGlyph>::Variants* to_init) { 455 [&](typename GlyphFindAndPlace<ProcessOneGlyph>::Variants* to_init) {
446 if (cache->isSubpixel()) { 456 if (cache->isSubpixel()) {
447 SkAxisAlignment axisAlignment = SkComputeAxisAlignmentForHText(m atrix);
448 switch (textAlignment) { 457 switch (textAlignment) {
449 case SkPaint::kLeft_Align: 458 case SkPaint::kLeft_Align:
450 InitSubpixel<ProcessOneGlyph, SkPaint::kLeft_Align>( 459 InitSubpixel<ProcessOneGlyph, SkPaint::kLeft_Align>(
451 to_init, axisAlignment, cache, glyphCacheProc); 460 to_init, axisAlignment, cache, glyphCacheProc);
452 break; 461 break;
453 case SkPaint::kCenter_Align: 462 case SkPaint::kCenter_Align:
454 InitSubpixel<ProcessOneGlyph, SkPaint::kCenter_Align>( 463 InitSubpixel<ProcessOneGlyph, SkPaint::kCenter_Align>(
455 to_init, axisAlignment, cache, glyphCacheProc); 464 to_init, axisAlignment, cache, glyphCacheProc);
456 break; 465 break;
457 case SkPaint::kRight_Align: 466 case SkPaint::kRight_Align:
(...skipping 24 matching lines...) Expand all
482 }; 491 };
483 492
484 const char* stop = text + byteLength; 493 const char* stop = text + byteLength;
485 while (text < stop) { 494 while (text < stop) {
486 SkPoint mappedPoint = mapper->map(positionReader->nextPoint()); 495 SkPoint mappedPoint = mapper->map(positionReader->nextPoint());
487 findAndPosition->findAndPositionGlyph( 496 findAndPosition->findAndPositionGlyph(
488 &text, mappedPoint, skstd::forward<ProcessOneGlyph>(processOneGlyph) ); 497 &text, mappedPoint, skstd::forward<ProcessOneGlyph>(processOneGlyph) );
489 } 498 }
490 } 499 }
491 500
492 template<typename ProcessOneGlyph>
493 inline bool SkFindAndPlaceGlyph::SpecializedProcessPosText(
494 const char* const text, size_t byteLength, const SkPoint& offset, const SkMa trix& matrix,
495 const SkScalar pos[], int scalarsPerPosition, SkPaint::Align textAlignment,
496 SkDrawCacheProc& glyphCacheProc, SkGlyphCache* cache, ProcessOneGlyph&& proc essOneGlyph) {
497 SkAxisAlignment axisAlignment = SkComputeAxisAlignmentForHText(matrix);
498 uint32_t mtype = matrix.getType();
499 if (scalarsPerPosition == 1
500 && textAlignment == SkPaint::kLeft_Align
501 && axisAlignment == kX_SkAxisAlignment
502 && cache->isSubpixel()
503 && mtype <= SkMatrix::kTranslate_Mask) {
504 typedef GlyphFindAndPlaceSubpixel<
505 ProcessOneGlyph, SkPaint::kLeft_Align, kX_SkAxisAlignment> Positioner;
506 HorizontalPositions positions{pos};
507 TranslationMapper mapper{matrix, offset};
508 Positioner positioner(cache, glyphCacheProc);
509 const char* cursor = text;
510 const char* stop = text + byteLength;
511 while (cursor < stop) {
512 SkPoint mappedPoint = mapper.TranslationMapper::map(
513 positions.HorizontalPositions::nextPoint());
514 positioner.Positioner::findAndPositionGlyph(
515 &cursor, mappedPoint, skstd::forward<ProcessOneGlyph>(processOne Glyph));
516 }
517 return true;
518 }
519 return false;
520 }
521
522
523 #endif // SkFindAndPositionGlyph_DEFINED 501 #endif // SkFindAndPositionGlyph_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698