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

Side by Side Diff: include/core/SkFixed.h

Issue 1583453002: clamp fixed divide to 32 bits (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 SkFixed_DEFINED 8 #ifndef SkFixed_DEFINED
9 #define SkFixed_DEFINED 9 #define SkFixed_DEFINED
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000) 79 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000)
80 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000) 80 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000)
81 81
82 #define SkFixedAbs(x) SkAbs32(x) 82 #define SkFixedAbs(x) SkAbs32(x)
83 #define SkFixedAve(a, b) (((a) + (b)) >> 1) 83 #define SkFixedAve(a, b) (((a) + (b)) >> 1)
84 84
85 // Blink layout tests are baselined to Clang optimizing through undefined behavi or in SkDivBits. 85 // Blink layout tests are baselined to Clang optimizing through undefined behavi or in SkDivBits.
86 #if defined(SK_SUPPORT_LEGACY_DIVBITS_UB) 86 #if defined(SK_SUPPORT_LEGACY_DIVBITS_UB)
87 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) 87 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16)
88 #else 88 #else
89 // TODO(reed): this clamp shouldn't be needed. Use SkToS32(). 89 // The divide may exceed 32 bits. Clamp to a signed 32 bit result.
90 #define SkFixedDiv(numer, denom) \ 90 #define SkFixedDiv(numer, denom) \
91 SkTPin<int32_t>((int32_t)(SkLeftShift((int64_t)numer, 16) / denom), SK_M inS32, SK_MaxS32) 91 SkToS32(SkTPin<int64_t>((SkLeftShift((int64_t)numer, 16) / denom), SK_Mi nS32, SK_MaxS32))
92 #endif 92 #endif
93 93
94 //////////////////////////////////////////////////////////////////////////////// ////////////////////// 94 //////////////////////////////////////////////////////////////////////////////// //////////////////////
95 // Now look for ASM overrides for our portable versions (should consider putting this in its own file) 95 // Now look for ASM overrides for our portable versions (should consider putting this in its own file)
96 96
97 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) { 97 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) {
98 return (SkFixed)((int64_t)a * b >> 16); 98 return (SkFixed)((int64_t)a * b >> 16);
99 } 99 }
100 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b) 100 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
101 101
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16) 162 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16)
163 163
164 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) { 164 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) {
165 return static_cast<float>(x * 1.5258789e-5); // x * (1.0f / (1 << 16)) 165 return static_cast<float>(x * 1.5258789e-5); // x * (1.0f / (1 << 16))
166 } 166 }
167 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16))) 167 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16)))
168 168
169 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x) 169 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x)
170 170
171 #endif 171 #endif
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