| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 SkGradientShaderPriv_DEFINED | 8 #ifndef SkGradientShaderPriv_DEFINED |
| 9 #define SkGradientShaderPriv_DEFINED | 9 #define SkGradientShaderPriv_DEFINED |
| 10 | 10 |
| 11 #include "math.h" |
| 12 |
| 11 #include "SkGradientBitmapCache.h" | 13 #include "SkGradientBitmapCache.h" |
| 12 #include "SkGradientShader.h" | 14 #include "SkGradientShader.h" |
| 13 #include "SkClampRange.h" | 15 #include "SkClampRange.h" |
| 14 #include "SkColorPriv.h" | 16 #include "SkColorPriv.h" |
| 15 #include "SkReadBuffer.h" | 17 #include "SkReadBuffer.h" |
| 16 #include "SkWriteBuffer.h" | 18 #include "SkWriteBuffer.h" |
| 17 #include "SkMallocPixelRef.h" | 19 #include "SkMallocPixelRef.h" |
| 18 #include "SkUtils.h" | 20 #include "SkUtils.h" |
| 19 #include "SkShader.h" | 21 #include "SkShader.h" |
| 20 #include "SkOnce.h" | 22 #include "SkOnce.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 } | 34 } |
| 33 if (count & 1) { | 35 if (count & 1) { |
| 34 *dst = v0; | 36 *dst = v0; |
| 35 } | 37 } |
| 36 } | 38 } |
| 37 } | 39 } |
| 38 } | 40 } |
| 39 | 41 |
| 40 // Clamp | 42 // Clamp |
| 41 | 43 |
| 42 static inline SkFixed clamp_tileproc(SkFixed x) { | 44 static inline unsigned clamp_tileproc(float x) { |
| 43 return SkClampMax(x, 0xFFFF); | 45 unsigned result = (unsigned)(0xFFFF * SkTPin(x, 0.0f, 1.0f)); |
| 46 if (result > 0xFFFF) { |
| 47 SkDebugf("clamp_tileproc: x: %f result: %d\n", x, result); |
| 48 } |
| 49 return result; |
| 44 } | 50 } |
| 45 | 51 |
| 46 // Repeat | 52 // Repeat |
| 47 | 53 |
| 48 static inline SkFixed repeat_tileproc(SkFixed x) { | 54 static inline unsigned repeat_tileproc(float x) { |
| 49 return x & 0xFFFF; | 55 float modulo = fmod(x, 1.0f); |
| 56 unsigned result = (unsigned)(0xFFFF * modulo); |
| 57 if (result > 0xFFFF) { |
| 58 SkDebugf("repeat_tileproc: x: %f modulo: %f result: %d\n", x, modulo, re
sult); |
| 59 } |
| 60 return result; |
| 50 } | 61 } |
| 51 | 62 |
| 52 // Mirror | 63 // Mirror |
| 53 | 64 |
| 54 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. | 65 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. |
| 55 // See http://code.google.com/p/skia/issues/detail?id=472 | 66 // See http://code.google.com/p/skia/issues/detail?id=472 |
| 56 #if defined(_MSC_VER) && (_MSC_VER >= 1600) | 67 #if defined(_MSC_VER) && (_MSC_VER >= 1600) |
| 57 #pragma optimize("", off) | 68 #pragma optimize("", off) |
| 58 #endif | 69 #endif |
| 59 | 70 |
| 60 static inline SkFixed mirror_tileproc(SkFixed x) { | 71 static inline unsigned mirror_tileproc(float x) { |
| 61 int s = SkLeftShift(x, 15) >> 31; | 72 const float x_mod_2 = fmod(x, 2.0f); |
| 62 return (x ^ s) & 0xFFFF; | 73 int x_17bits = (int)(x_mod_2 * 0x10000); |
| 74 if (x_17bits & 0x10000) { |
| 75 x_17bits = ~x_17bits; |
| 76 } |
| 77 unsigned result = x_17bits & 0xFFFF; |
| 78 if (result > 0xFFFF) { |
| 79 SkDebugf("mirror_tileproc: x: %f x_mod_2: %f x_17bits: %d result: %d\n"
, x, x_mod_2, x_17bits, result); |
| 80 } |
| 81 return result; |
| 63 } | 82 } |
| 64 | 83 |
| 65 #if defined(_MSC_VER) && (_MSC_VER >= 1600) | 84 #if defined(_MSC_VER) && (_MSC_VER >= 1600) |
| 66 #pragma optimize("", on) | 85 #pragma optimize("", on) |
| 67 #endif | 86 #endif |
| 68 | 87 |
| 69 /////////////////////////////////////////////////////////////////////////////// | 88 /////////////////////////////////////////////////////////////////////////////// |
| 70 | 89 |
| 71 typedef SkFixed (*TileProc)(SkFixed); | 90 typedef unsigned (*TileProc)(float); |
| 72 | 91 |
| 73 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// |
| 74 | 93 |
| 75 static const TileProc gTileProcs[] = { | 94 static const TileProc gTileProcs[] = { |
| 76 clamp_tileproc, | 95 clamp_tileproc, |
| 77 repeat_tileproc, | 96 repeat_tileproc, |
| 78 mirror_tileproc | 97 mirror_tileproc |
| 79 }; | 98 }; |
| 80 | 99 |
| 81 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 GrGLSLProgramDataManager::UniformHandle fColorStartUni; | 476 GrGLSLProgramDataManager::UniformHandle fColorStartUni; |
| 458 GrGLSLProgramDataManager::UniformHandle fColorMidUni; | 477 GrGLSLProgramDataManager::UniformHandle fColorMidUni; |
| 459 GrGLSLProgramDataManager::UniformHandle fColorEndUni; | 478 GrGLSLProgramDataManager::UniformHandle fColorEndUni; |
| 460 | 479 |
| 461 typedef GrGLSLFragmentProcessor INHERITED; | 480 typedef GrGLSLFragmentProcessor INHERITED; |
| 462 }; | 481 }; |
| 463 | 482 |
| 464 #endif | 483 #endif |
| 465 | 484 |
| 466 #endif | 485 #endif |
| OLD | NEW |