aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-07 21:35:13 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-07 21:35:13 +0000
commit4b163ed2c22facbe8891616874ae07ba7827d9c9 (patch)
treea6c54760e3ded8456cc4a410beb9da4a5bfeabcf
parent2ddff9388694263c7be9347de7eb768cd0847997 (diff)
Privatization:
move SkFDot.h to private move parts of SkMath.h into SkMathPriv.h Review URL: https://codereview.appspot.com/6461045 git-svn-id: http://skia.googlecode.com/svn/trunk@4997 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkMath.h196
-rw-r--r--src/core/Sk64.cpp3
-rw-r--r--src/core/SkBitmapProcState_matrix.h1
-rw-r--r--src/core/SkBitmapProcState_shaderproc.h2
-rw-r--r--src/core/SkBlitRow_D16.cpp1
-rw-r--r--src/core/SkConfig8888.cpp1
-rw-r--r--src/core/SkCordic.cpp4
-rw-r--r--src/core/SkFDot6.h (renamed from include/core/SkFDot6.h)0
-rw-r--r--src/core/SkFloat.cpp2
-rw-r--r--src/core/SkFloatBits.cpp4
-rw-r--r--src/core/SkMath.cpp4
-rw-r--r--src/core/SkMathPriv.h94
-rw-r--r--src/core/SkXfermode.cpp1
-rw-r--r--tests/ColorTest.cpp2
-rw-r--r--tests/MathTest.cpp2
-rw-r--r--tests/ReadPixelsTest.cpp1
-rw-r--r--tests/WritePixelsTest.cpp1
17 files changed, 172 insertions, 147 deletions
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index 7a4b707ce7..42f830cf2f 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -12,68 +12,51 @@
#include "SkTypes.h"
-//! Returns the number of leading zero bits (0...32)
-int SkCLZ_portable(uint32_t);
-
-/** Computes the 64bit product of a * b, and then shifts the answer down by
- shift bits, returning the low 32bits. shift must be [0..63]
- e.g. to perform a fixedmul, call SkMulShift(a, b, 16)
-*/
-int32_t SkMulShift(int32_t a, int32_t b, unsigned shift);
-
-/** Computes numer1 * numer2 / denom in full 64 intermediate precision.
- It is an error for denom to be 0. There is no special handling if
- the result overflows 32bits.
-*/
+/**
+ * Computes numer1 * numer2 / denom in full 64 intermediate precision.
+ * It is an error for denom to be 0. There is no special handling if
+ * the result overflows 32bits.
+ */
int32_t SkMulDiv(int32_t numer1, int32_t numer2, int32_t denom);
-/** Computes (numer1 << shift) / denom in full 64 intermediate precision.
- It is an error for denom to be 0. There is no special handling if
- the result overflows 32bits.
-*/
+/**
+ * Computes (numer1 << shift) / denom in full 64 intermediate precision.
+ * It is an error for denom to be 0. There is no special handling if
+ * the result overflows 32bits.
+ */
int32_t SkDivBits(int32_t numer, int32_t denom, int shift);
-/** Return the integer square root of value, with a bias of bitBias
-*/
+/**
+ * Return the integer square root of value, with a bias of bitBias
+ */
int32_t SkSqrtBits(int32_t value, int bitBias);
-/** Return the integer square root of n, treated as a SkFixed (16.16)
-*/
-#define SkSqrt32(n) SkSqrtBits(n, 15)
+///////////////////////////////////////////////////////////////////////////////
-/** Return the integer cube root of value, with a bias of bitBias
- */
-int32_t SkCubeRootBits(int32_t value, int bitBias);
-
-/** Returns -1 if n < 0, else returns 0
-*/
-#define SkExtractSign(n) ((int32_t)(n) >> 31)
-
-/** If sign == -1, returns -n, else sign must be 0, and returns n.
- Typically used in conjunction with SkExtractSign().
-*/
-static inline int32_t SkApplySign(int32_t n, int32_t sign) {
- SkASSERT(sign == 0 || sign == -1);
- return (n ^ sign) - sign;
-}
+//! Returns the number of leading zero bits (0...32)
+int SkCLZ_portable(uint32_t);
-/** Return x with the sign of y */
-static inline int32_t SkCopySign32(int32_t x, int32_t y) {
- return SkApplySign(x, SkExtractSign(x ^ y));
-}
+#if defined(__arm__)
+ #define SkCLZ(x) __builtin_clz(x)
+#endif
+
+#ifndef SkCLZ
+ #define SkCLZ(x) SkCLZ_portable(x)
+#endif
-/** Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches)
-*/
+/**
+ * Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches)
+ */
static inline int SkClampPos(int value) {
return value & ~(value >> 31);
}
/** Given an integer and a positive (max) integer, return the value
- pinned against 0 and max, inclusive.
- @param value The value we want returned pinned between [0...max]
- @param max The positive max value
- @return 0 if value < 0, max if value > max, else value
-*/
+ * pinned against 0 and max, inclusive.
+ * @param value The value we want returned pinned between [0...max]
+ * @param max The positive max value
+ * @return 0 if value < 0, max if value > max, else value
+ */
static inline int SkClampMax(int value, int max) {
// ensure that max is positive
SkASSERT(max >= 0);
@@ -86,62 +69,33 @@ static inline int SkClampMax(int value, int max) {
return value;
}
-/** Given a positive value and a positive max, return the value
- pinned against max.
- Note: only works as long as max - value doesn't wrap around
- @return max if value >= max, else value
-*/
-static inline unsigned SkClampUMax(unsigned value, unsigned max) {
-#ifdef SK_CPU_HAS_CONDITIONAL_INSTR
- if (value > max) {
- value = max;
- }
- return value;
-#else
- int diff = max - value;
- // clear diff if diff is positive
- diff &= diff >> 31;
-
- return value + diff;
-#endif
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-#if defined(__arm__)
- #define SkCLZ(x) __builtin_clz(x)
-#endif
-
-#ifndef SkCLZ
- #define SkCLZ(x) SkCLZ_portable(x)
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-
-/** Returns the smallest power-of-2 that is >= the specified value. If value
- is already a power of 2, then it is returned unchanged. It is undefined
- if value is <= 0.
-*/
+/**
+ * Returns the smallest power-of-2 that is >= the specified value. If value
+ * is already a power of 2, then it is returned unchanged. It is undefined
+ * if value is <= 0.
+ */
static inline int SkNextPow2(int value) {
SkASSERT(value > 0);
return 1 << (32 - SkCLZ(value - 1));
}
-/** Returns the log2 of the specified value, were that value to be rounded up
- to the next power of 2. It is undefined to pass 0. Examples:
- SkNextLog2(1) -> 0
- SkNextLog2(2) -> 1
- SkNextLog2(3) -> 2
- SkNextLog2(4) -> 2
- SkNextLog2(5) -> 3
-*/
+/**
+ * Returns the log2 of the specified value, were that value to be rounded up
+ * to the next power of 2. It is undefined to pass 0. Examples:
+ * SkNextLog2(1) -> 0
+ * SkNextLog2(2) -> 1
+ * SkNextLog2(3) -> 2
+ * SkNextLog2(4) -> 2
+ * SkNextLog2(5) -> 3
+ */
static inline int SkNextLog2(uint32_t value) {
SkASSERT(value != 0);
return 32 - SkCLZ(value - 1);
}
-/** Returns true if value is a power of 2. Does not explicitly check for
- value <= 0.
+/**
+ * Returns true if value is a power of 2. Does not explicitly check for
+ * value <= 0.
*/
static inline bool SkIsPow2(int value) {
return (value & (value - 1)) == 0;
@@ -149,10 +103,11 @@ static inline bool SkIsPow2(int value) {
///////////////////////////////////////////////////////////////////////////////
-/** SkMulS16(a, b) multiplies a * b, but requires that a and b are both int16_t.
- With this requirement, we can generate faster instructions on some
- architectures.
-*/
+/**
+ * SkMulS16(a, b) multiplies a * b, but requires that a and b are both int16_t.
+ * With this requirement, we can generate faster instructions on some
+ * architectures.
+ */
#ifdef SK_ARM_HAS_EDSP
static inline int32_t SkMulS16(S16CPU x, S16CPU y) {
SkASSERT((int16_t)x == x);
@@ -176,39 +131,10 @@ static inline bool SkIsPow2(int value) {
#endif
#endif
-/** Return a*b/255, truncating away any fractional bits. Only valid if both
- a and b are 0..255
-*/
-static inline U8CPU SkMulDiv255Trunc(U8CPU a, U8CPU b) {
- SkASSERT((uint8_t)a == a);
- SkASSERT((uint8_t)b == b);
- unsigned prod = SkMulS16(a, b) + 1;
- return (prod + (prod >> 8)) >> 8;
-}
-
-/** Return a*b/255, rounding any fractional bits. Only valid if both
- a and b are 0..255
+/**
+ * Return a*b/((1 << shift) - 1), rounding any fractional bits.
+ * Only valid if a and b are unsigned and <= 32767 and shift is > 0 and <= 8
*/
-static inline U8CPU SkMulDiv255Round(U8CPU a, U8CPU b) {
- SkASSERT((uint8_t)a == a);
- SkASSERT((uint8_t)b == b);
- unsigned prod = SkMulS16(a, b) + 128;
- return (prod + (prod >> 8)) >> 8;
-}
-
-/** Return (a*b)/255, taking the ceiling of any fractional bits. Only valid if
- both a and b are 0..255. The expected result equals (a * b + 254) / 255.
- */
-static inline U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b) {
- SkASSERT((uint8_t)a == a);
- SkASSERT((uint8_t)b == b);
- unsigned prod = SkMulS16(a, b) + 255;
- return (prod + (prod >> 8)) >> 8;
-}
-
-/** Return a*b/((1 << shift) - 1), rounding any fractional bits.
- Only valid if a and b are unsigned and <= 32767 and shift is > 0 and <= 8
-*/
static inline unsigned SkMul16ShiftRound(unsigned a, unsigned b, int shift) {
SkASSERT(a <= 32767);
SkASSERT(b <= 32767);
@@ -217,10 +143,14 @@ static inline unsigned SkMul16ShiftRound(unsigned a, unsigned b, int shift) {
return (prod + (prod >> shift)) >> shift;
}
-/** Just the rounding step in SkDiv255Round: round(value / 255)
+/**
+ * Return a*b/255, rounding any fractional bits. Only valid if both
+ * a and b are 0..255
*/
-static inline unsigned SkDiv255Round(unsigned prod) {
- prod += 128;
+static inline U8CPU SkMulDiv255Round(U8CPU a, U8CPU b) {
+ SkASSERT((uint8_t)a == a);
+ SkASSERT((uint8_t)b == b);
+ unsigned prod = SkMulS16(a, b) + 128;
return (prod + (prod >> 8)) >> 8;
}
diff --git a/src/core/Sk64.cpp b/src/core/Sk64.cpp
index f3506564a5..c530ed866f 100644
--- a/src/core/Sk64.cpp
+++ b/src/core/Sk64.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -7,7 +6,7 @@
*/
#include "Sk64.h"
-#include "SkMath.h"
+#include "SkMathPriv.h"
#define shift_left(hi, lo) \
hi = (hi << 1) | (lo >> 31); \
diff --git a/src/core/SkBitmapProcState_matrix.h b/src/core/SkBitmapProcState_matrix.h
index 469cbf3ad4..317c98437e 100644
--- a/src/core/SkBitmapProcState_matrix.h
+++ b/src/core/SkBitmapProcState_matrix.h
@@ -7,6 +7,7 @@
*/
#include "SkMath.h"
+#include "SkMathPriv.h"
#define SCALE_NOFILTER_NAME MAKENAME(_nofilter_scale)
#define SCALE_FILTER_NAME MAKENAME(_filter_scale)
diff --git a/src/core/SkBitmapProcState_shaderproc.h b/src/core/SkBitmapProcState_shaderproc.h
index a3a8a99c0d..ead57f123e 100644
--- a/src/core/SkBitmapProcState_shaderproc.h
+++ b/src/core/SkBitmapProcState_shaderproc.h
@@ -6,7 +6,7 @@
* found in the LICENSE file.
*/
-
+#include "SkMathPriv.h"
#define SCALE_FILTER_NAME MAKENAME(_filter_DX_shaderproc)
diff --git a/src/core/SkBlitRow_D16.cpp b/src/core/SkBlitRow_D16.cpp
index c815468bb6..5e675e5493 100644
--- a/src/core/SkBlitRow_D16.cpp
+++ b/src/core/SkBlitRow_D16.cpp
@@ -8,6 +8,7 @@
#include "SkBlitRow.h"
#include "SkColorPriv.h"
#include "SkDither.h"
+#include "SkMathPriv.h"
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkConfig8888.cpp b/src/core/SkConfig8888.cpp
index 10a1b36614..f889f20744 100644
--- a/src/core/SkConfig8888.cpp
+++ b/src/core/SkConfig8888.cpp
@@ -1,4 +1,5 @@
#include "SkConfig8888.h"
+#include "SkMathPriv.h"
namespace {
diff --git a/src/core/SkCordic.cpp b/src/core/SkCordic.cpp
index 14d34fb9fd..56cb4606c5 100644
--- a/src/core/SkCordic.cpp
+++ b/src/core/SkCordic.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -6,9 +5,8 @@
* found in the LICENSE file.
*/
-
#include "SkCordic.h"
-#include "SkMath.h"
+#include "SkMathPriv.h"
#include "Sk64.h"
// 0x20000000 equals pi / 4
diff --git a/include/core/SkFDot6.h b/src/core/SkFDot6.h
index aa588572f8..aa588572f8 100644
--- a/include/core/SkFDot6.h
+++ b/src/core/SkFDot6.h
diff --git a/src/core/SkFloat.cpp b/src/core/SkFloat.cpp
index ec785f320b..dffb0d7803 100644
--- a/src/core/SkFloat.cpp
+++ b/src/core/SkFloat.cpp
@@ -8,7 +8,7 @@
#include "SkFloat.h"
-#include "SkMath.h"
+#include "SkMathPriv.h"
#define EXP_BIAS (127+23)
diff --git a/src/core/SkFloatBits.cpp b/src/core/SkFloatBits.cpp
index 378f98db43..fe4a1b9ab8 100644
--- a/src/core/SkFloatBits.cpp
+++ b/src/core/SkFloatBits.cpp
@@ -1,12 +1,12 @@
-
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "SkFloatBits.h"
-#include "SkMath.h"
+#include "SkMathPriv.h"
/******************************************************************************
SkFloatBits_toInt[Floor, Round, Ceil] are identical except for what they
diff --git a/src/core/SkMath.cpp b/src/core/SkMath.cpp
index 7b753057cc..a149625297 100644
--- a/src/core/SkMath.cpp
+++ b/src/core/SkMath.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2008 The Android Open Source Project
*
@@ -6,8 +5,7 @@
* found in the LICENSE file.
*/
-
-#include "SkMath.h"
+#include "SkMathPriv.h"
#include "SkCordic.h"
#include "SkFloatBits.h"
#include "SkFloatingPoint.h"
diff --git a/src/core/SkMathPriv.h b/src/core/SkMathPriv.h
new file mode 100644
index 0000000000..055acc4ebd
--- /dev/null
+++ b/src/core/SkMathPriv.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkMathPriv_DEFINED
+#define SkMathPriv_DEFINED
+
+#include "SkMath.h"
+
+/** Returns -1 if n < 0, else returns 0
+ */
+#define SkExtractSign(n) ((int32_t)(n) >> 31)
+
+/** If sign == -1, returns -n, else sign must be 0, and returns n.
+ Typically used in conjunction with SkExtractSign().
+ */
+static inline int32_t SkApplySign(int32_t n, int32_t sign) {
+ SkASSERT(sign == 0 || sign == -1);
+ return (n ^ sign) - sign;
+}
+
+/** Return x with the sign of y */
+static inline int32_t SkCopySign32(int32_t x, int32_t y) {
+ return SkApplySign(x, SkExtractSign(x ^ y));
+}
+
+/** Given a positive value and a positive max, return the value
+ pinned against max.
+ Note: only works as long as max - value doesn't wrap around
+ @return max if value >= max, else value
+ */
+static inline unsigned SkClampUMax(unsigned value, unsigned max) {
+#ifdef SK_CPU_HAS_CONDITIONAL_INSTR
+ if (value > max) {
+ value = max;
+ }
+ return value;
+#else
+ int diff = max - value;
+ // clear diff if diff is positive
+ diff &= diff >> 31;
+
+ return value + diff;
+#endif
+}
+
+/** Computes the 64bit product of a * b, and then shifts the answer down by
+ shift bits, returning the low 32bits. shift must be [0..63]
+ e.g. to perform a fixedmul, call SkMulShift(a, b, 16)
+ */
+int32_t SkMulShift(int32_t a, int32_t b, unsigned shift);
+
+/** Return the integer square root of n, treated as a SkFixed (16.16)
+ */
+#define SkSqrt32(n) SkSqrtBits(n, 15)
+
+/** Return the integer cube root of value, with a bias of bitBias
+ */
+int32_t SkCubeRootBits(int32_t value, int bitBias);
+
+///////////////////////////////////////////////////////////////////////////////
+
+/** Return a*b/255, truncating away any fractional bits. Only valid if both
+ a and b are 0..255
+ */
+static inline U8CPU SkMulDiv255Trunc(U8CPU a, U8CPU b) {
+ SkASSERT((uint8_t)a == a);
+ SkASSERT((uint8_t)b == b);
+ unsigned prod = SkMulS16(a, b) + 1;
+ return (prod + (prod >> 8)) >> 8;
+}
+
+/** Return (a*b)/255, taking the ceiling of any fractional bits. Only valid if
+ both a and b are 0..255. The expected result equals (a * b + 254) / 255.
+ */
+static inline U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b) {
+ SkASSERT((uint8_t)a == a);
+ SkASSERT((uint8_t)b == b);
+ unsigned prod = SkMulS16(a, b) + 255;
+ return (prod + (prod >> 8)) >> 8;
+}
+
+/** Just the rounding step in SkDiv255Round: round(value / 255)
+ */
+static inline unsigned SkDiv255Round(unsigned prod) {
+ prod += 128;
+ return (prod + (prod >> 8)) >> 8;
+}
+
+#endif
+
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index 74097be67b..aeed9cc26e 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -10,6 +10,7 @@
#include "SkXfermode.h"
#include "SkColorPriv.h"
#include "SkFlattenableBuffers.h"
+#include "SkMathPriv.h"
SK_DEFINE_INST_COUNT(SkXfermode)
diff --git a/tests/ColorTest.cpp b/tests/ColorTest.cpp
index 83e2e3fada..86729d2756 100644
--- a/tests/ColorTest.cpp
+++ b/tests/ColorTest.cpp
@@ -8,7 +8,7 @@
#include "Test.h"
#include "SkColor.h"
#include "SkColorPriv.h"
-#include "SkMath.h"
+#include "SkMathPriv.h"
#include "SkRandom.h"
#include "SkUnPreMultiply.h"
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index b41c47147d..e2e63c5da4 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -7,7 +7,7 @@
*/
#include "Test.h"
#include "SkFloatingPoint.h"
-#include "SkMath.h"
+#include "SkMathPriv.h"
#include "SkPoint.h"
#include "SkRandom.h"
#include "SkColorPriv.h"
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index 730be05177..a0eee04e5a 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -10,6 +10,7 @@
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkDevice.h"
+#include "SkMathPriv.h"
#include "SkRegion.h"
#if SK_SUPPORT_GPU
#include "SkGpuDevice.h"
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index 688aa5d227..5911b800bc 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -10,6 +10,7 @@
#include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkDevice.h"
+#include "SkMathPriv.h"
#include "SkRegion.h"
#if SK_SUPPORT_GPU
#include "SkGpuDevice.h"