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

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

Issue 1779083003: Ensure only fractional floats are converted to SkFixed in SubpixelAlignment. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 9 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 | « no previous file | no next file » | 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return {kSubpixelRounding, kSubpixelRounding}; 374 return {kSubpixelRounding, kSubpixelRounding};
375 } 375 }
376 SkFAIL("Should not get here."); 376 SkFAIL("Should not get here.");
377 return {0.0f, 0.0f}; 377 return {0.0f, 0.0f};
378 } 378 }
379 379
380 // The SubpixelAlignment function produces a suitable position for the glyph cache to 380 // The SubpixelAlignment function produces a suitable position for the glyph cache to
381 // produce the correct sub-pixel alignment. If a position is aligned with an axis a shortcut 381 // produce the correct sub-pixel alignment. If a position is aligned with an axis a shortcut
382 // of 0 is used for the sub-pixel position. 382 // of 0 is used for the sub-pixel position.
383 static SkIPoint SubpixelAlignment(SkAxisAlignment axisAlignment, SkPoint pos ition) { 383 static SkIPoint SubpixelAlignment(SkAxisAlignment axisAlignment, SkPoint pos ition) {
384 // Only the fractional part of position.fX and position.fY matter, becau se the result of
385 // this function will just be passed to FixedToSub.
384 switch (axisAlignment) { 386 switch (axisAlignment) {
385 case kX_SkAxisAlignment: 387 case kX_SkAxisAlignment:
386 return {SkScalarToFixed(position.fX + kSubpixelRounding), 0}; 388 return {SkScalarToFixed(SkScalarFraction(position.fX) + kSubpixe lRounding), 0};
bungeman-skia 2016/03/10 20:55:58 SkScalarFraction is currently really super slow. I
dogben 2016/03/10 21:16:22 I maybe ought to always return positive numbers to
bungeman-skia 2016/03/10 21:37:49 Always returning positive numbers would just be ex
387 case kY_SkAxisAlignment: 389 case kY_SkAxisAlignment:
388 return {0, SkScalarToFixed(position.fY + kSubpixelRounding)}; 390 return {0, SkScalarToFixed(SkScalarFraction(position.fY) + kSubp ixelRounding)};
389 case kNone_SkAxisAlignment: 391 case kNone_SkAxisAlignment:
390 return {SkScalarToFixed(position.fX + kSubpixelRounding), 392 return {SkScalarToFixed(SkScalarFraction(position.fX) + kSubpixe lRounding),
391 SkScalarToFixed(position.fY + kSubpixelRounding)}; 393 SkScalarToFixed(SkScalarFraction(position.fY) + kSubpixe lRounding)};
392 } 394 }
393 SkFAIL("Should not get here."); 395 SkFAIL("Should not get here.");
394 return {0, 0}; 396 return {0, 0};
395 } 397 }
396 398
397 #undef kSubpixelRounding 399 #undef kSubpixelRounding
398 400
399 // GlyphFindAndPlaceInterface given the text and position finds the correct glyph and does 401 // GlyphFindAndPlaceInterface given the text and position finds the correct glyph and does
400 // glyph specific position adjustment. The findAndPositionGlyph method takes text and 402 // glyph specific position adjustment. The findAndPositionGlyph method takes text and
401 // position and calls processOneGlyph with the correct glyph, final position and rounding 403 // position and calls processOneGlyph with the correct glyph, final position and rounding
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 SkPoint current = offset; 727 SkPoint current = offset;
726 while (text < stop) { 728 while (text < stop) {
727 current = 729 current =
728 findAndPosition->findAndPositionGlyph( 730 findAndPosition->findAndPositionGlyph(
729 &text, current, std::forward<ProcessOneGlyph>(processOneGlyph)); 731 &text, current, std::forward<ProcessOneGlyph>(processOneGlyph));
730 732
731 } 733 }
732 } 734 }
733 735
734 #endif // SkFindAndPositionGlyph_DEFINED 736 #endif // SkFindAndPositionGlyph_DEFINED
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698