epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame^] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkFDot6_DEFINED |
| 11 | #define SkFDot6_DEFINED |
| 12 | |
| 13 | #include "SkMath.h" |
| 14 | |
| 15 | typedef int32_t SkFDot6; |
| 16 | |
mike@reedtribe.org | bcc1d33 | 2011-04-09 19:16:54 +0000 | [diff] [blame] | 17 | #define SK_FDot6One (64) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | #define SK_FDot6Half (32) |
| 19 | |
| 20 | #ifdef SK_DEBUG |
mike@reedtribe.org | bcc1d33 | 2011-04-09 19:16:54 +0000 | [diff] [blame] | 21 | inline SkFDot6 SkIntToFDot6(S16CPU x) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | SkASSERT(SkToS16(x) == x); |
| 23 | return x << 6; |
| 24 | } |
| 25 | #else |
| 26 | #define SkIntToFDot6(x) ((x) << 6) |
| 27 | #endif |
| 28 | |
| 29 | #define SkFDot6Floor(x) ((x) >> 6) |
| 30 | #define SkFDot6Ceil(x) (((x) + 63) >> 6) |
| 31 | #define SkFDot6Round(x) (((x) + 32) >> 6) |
| 32 | |
| 33 | #define SkFixedToFDot6(x) ((x) >> 10) |
| 34 | |
mike@reedtribe.org | bcc1d33 | 2011-04-09 19:16:54 +0000 | [diff] [blame] | 35 | inline SkFixed SkFDot6ToFixed(SkFDot6 x) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | SkASSERT((x << 10 >> 10) == x); |
| 37 | |
| 38 | return x << 10; |
| 39 | } |
| 40 | |
| 41 | #ifdef SK_SCALAR_IS_FLOAT |
| 42 | #define SkScalarToFDot6(x) (SkFDot6)((x) * 64) |
| 43 | #else |
| 44 | #define SkScalarToFDot6(x) ((x) >> 10) |
| 45 | #endif |
| 46 | |
mike@reedtribe.org | bcc1d33 | 2011-04-09 19:16:54 +0000 | [diff] [blame] | 47 | inline SkFixed SkFDot6Div(SkFDot6 a, SkFDot6 b) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | SkASSERT(b != 0); |
| 49 | |
mike@reedtribe.org | bcc1d33 | 2011-04-09 19:16:54 +0000 | [diff] [blame] | 50 | if (a == (int16_t)a) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | return (a << 16) / b; |
mike@reedtribe.org | bcc1d33 | 2011-04-09 19:16:54 +0000 | [diff] [blame] | 52 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | return SkFixedDiv(a, b); |
mike@reedtribe.org | bcc1d33 | 2011-04-09 19:16:54 +0000 | [diff] [blame] | 54 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | #endif |
| 58 | |