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

Unified Diff: src/effects/gradients/SkGradientShaderPriv.h

Issue 1767163003: Use float rather than SkFixed for gradient TileProcs. (Closed) Base URL: https://skia.googlesource.com/skia@scalar-pin-to-fixed
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/gradients/SkClampRange.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkGradientShaderPriv.h
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 5b1b09b9fccece7273a90d25d3414c00f8788523..ef16250dc189fa583b39b12b9c3dcddf7b99c414 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -8,6 +8,8 @@
#ifndef SkGradientShaderPriv_DEFINED
#define SkGradientShaderPriv_DEFINED
+#include "math.h"
+
#include "SkGradientBitmapCache.h"
#include "SkGradientShader.h"
#include "SkClampRange.h"
@@ -39,14 +41,23 @@ static inline void sk_memset32_dither(uint32_t dst[], uint32_t v0, uint32_t v1,
// Clamp
-static inline SkFixed clamp_tileproc(SkFixed x) {
- return SkClampMax(x, 0xFFFF);
+static inline unsigned clamp_tileproc(float x) {
+ unsigned result = (unsigned)(0xFFFF * SkTPin(x, 0.0f, 1.0f));
+ if (result > 0xFFFF) {
+ SkDebugf("clamp_tileproc: x: %f result: %d\n", x, result);
+ }
+ return result;
}
// Repeat
-static inline SkFixed repeat_tileproc(SkFixed x) {
- return x & 0xFFFF;
+static inline unsigned repeat_tileproc(float x) {
+ float modulo = fmod(x, 1.0f);
+ unsigned result = (unsigned)(0xFFFF * modulo);
+ if (result > 0xFFFF) {
+ SkDebugf("repeat_tileproc: x: %f modulo: %f result: %d\n", x, modulo, result);
+ }
+ return result;
}
// Mirror
@@ -57,9 +68,17 @@ static inline SkFixed repeat_tileproc(SkFixed x) {
#pragma optimize("", off)
#endif
-static inline SkFixed mirror_tileproc(SkFixed x) {
- int s = SkLeftShift(x, 15) >> 31;
- return (x ^ s) & 0xFFFF;
+static inline unsigned mirror_tileproc(float x) {
+ const float x_mod_2 = fmod(x, 2.0f);
+ int x_17bits = (int)(x_mod_2 * 0x10000);
+ if (x_17bits & 0x10000) {
+ x_17bits = ~x_17bits;
+ }
+ unsigned result = x_17bits & 0xFFFF;
+ if (result > 0xFFFF) {
+ SkDebugf("mirror_tileproc: x: %f x_mod_2: %f x_17bits: %d result: %d\n", x, x_mod_2, x_17bits, result);
+ }
+ return result;
}
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
@@ -68,7 +87,7 @@ static inline SkFixed mirror_tileproc(SkFixed x) {
///////////////////////////////////////////////////////////////////////////////
-typedef SkFixed (*TileProc)(SkFixed);
+typedef unsigned (*TileProc)(float);
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « src/effects/gradients/SkClampRange.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698