summaryrefslogtreecommitdiffstats
path: root/skia/corecg
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 21:01:41 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-12 21:01:41 +0000
commit52e935d04c59135739c3a68fb6e19d313dc6d5ad (patch)
tree95f7ab178b045bef4456cbf92c6aa7e476becd99 /skia/corecg
parent30fab79877b4bb067944b74d98346ac9bb6bfc7e (diff)
downloadchromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.zip
chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.gz
chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.bz2
New drop of Skia. This is up to CL 121320.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/corecg')
-rw-r--r--skia/corecg/Android.mk3
-rw-r--r--skia/corecg/NOTICE37
-rw-r--r--skia/corecg/Sk64.cpp2
-rw-r--r--skia/corecg/SkBuffer.cpp2
-rw-r--r--skia/corecg/SkChunkAlloc.cpp2
-rw-r--r--skia/corecg/SkCordic.cpp2
-rw-r--r--skia/corecg/SkCordic.h2
-rw-r--r--skia/corecg/SkDebug.cpp2
-rw-r--r--skia/corecg/SkDebug_stdio.cpp6
-rw-r--r--skia/corecg/SkFloat.cpp2
-rw-r--r--skia/corecg/SkFloat.h2
-rw-r--r--skia/corecg/SkFloatBits.cpp205
-rw-r--r--skia/corecg/SkFloatBits.h45
-rw-r--r--skia/corecg/SkInterpolator.cpp4
-rw-r--r--skia/corecg/SkMath.cpp122
-rw-r--r--skia/corecg/SkMatrix.cpp33
-rw-r--r--skia/corecg/SkMemory_stdlib.cpp2
-rw-r--r--skia/corecg/SkPageFlipper.cpp85
-rw-r--r--skia/corecg/SkPoint.cpp2
-rw-r--r--skia/corecg/SkRect.cpp60
-rw-r--r--skia/corecg/SkRegion.cpp42
-rw-r--r--skia/corecg/SkRegionPriv.h2
-rw-r--r--skia/corecg/SkSinTable.h2
-rw-r--r--skia/corecg/SkTSort.h2
24 files changed, 541 insertions, 127 deletions
diff --git a/skia/corecg/Android.mk b/skia/corecg/Android.mk
index ead28bd..1bcd9ca 100644
--- a/skia/corecg/Android.mk
+++ b/skia/corecg/Android.mk
@@ -10,11 +10,12 @@ LOCAL_SRC_FILES:= \
SkCordic.cpp \
SkDebug.cpp \
SkDebug_stdio.cpp \
- SkFloat.cpp \
+ SkFloatBits.cpp \
SkInterpolator.cpp \
SkMath.cpp \
SkMatrix.cpp \
SkMemory_stdlib.cpp \
+ SkPageFlipper.cpp \
SkPoint.cpp \
SkRect.cpp \
SkRegion.cpp
diff --git a/skia/corecg/NOTICE b/skia/corecg/NOTICE
index 29f81d8..70c5422 100644
--- a/skia/corecg/NOTICE
+++ b/skia/corecg/NOTICE
@@ -1,3 +1,16 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@@ -175,27 +188,3 @@
END OF TERMS AND CONDITIONS
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/skia/corecg/Sk64.cpp b/skia/corecg/Sk64.cpp
index 028a4ae..6013bd7 100644
--- a/skia/corecg/Sk64.cpp
+++ b/skia/corecg/Sk64.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/Sk64.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkBuffer.cpp b/skia/corecg/SkBuffer.cpp
index 1a8f069..5768ca4 100644
--- a/skia/corecg/SkBuffer.cpp
+++ b/skia/corecg/SkBuffer.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkBuffer.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkChunkAlloc.cpp b/skia/corecg/SkChunkAlloc.cpp
index b9cfd90..ae37ec0 100644
--- a/skia/corecg/SkChunkAlloc.cpp
+++ b/skia/corecg/SkChunkAlloc.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkChunkAlloc.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkCordic.cpp b/skia/corecg/SkCordic.cpp
index accbd95..539bc9b 100644
--- a/skia/corecg/SkCordic.cpp
+++ b/skia/corecg/SkCordic.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkCordic.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkCordic.h b/skia/corecg/SkCordic.h
index 70c70b5..9f45a81 100644
--- a/skia/corecg/SkCordic.h
+++ b/skia/corecg/SkCordic.h
@@ -1,6 +1,6 @@
/* libs/corecg/SkCordic.h
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkDebug.cpp b/skia/corecg/SkDebug.cpp
index 5d5518d..64ea8b4 100644
--- a/skia/corecg/SkDebug.cpp
+++ b/skia/corecg/SkDebug.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkDebug.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkDebug_stdio.cpp b/skia/corecg/SkDebug_stdio.cpp
index 6da09af..d455131 100644
--- a/skia/corecg/SkDebug_stdio.cpp
+++ b/skia/corecg/SkDebug_stdio.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkDebug_stdio.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -42,11 +42,12 @@ void Android_SkDebugf(const char* file, int line, const char* function,
va_end(args);
}
-#elif defined(SK_DEBUG)
+#else
#include <stdarg.h>
#include <stdio.h>
+#if 0
void SkDebugf(const char format[], ...)
{
char buffer[kBufferSize + 1];
@@ -56,6 +57,7 @@ void SkDebugf(const char format[], ...)
va_end(args);
fprintf(stderr, buffer);
}
+#endif
#endif
diff --git a/skia/corecg/SkFloat.cpp b/skia/corecg/SkFloat.cpp
index bb96947..504c1d3 100644
--- a/skia/corecg/SkFloat.cpp
+++ b/skia/corecg/SkFloat.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2008 Google Inc.
+ * Copyright (C) 2006-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkFloat.h b/skia/corecg/SkFloat.h
index 2a2abac..31aaeed 100644
--- a/skia/corecg/SkFloat.h
+++ b/skia/corecg/SkFloat.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2008 Google Inc.
+ * Copyright (C) 2006-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkFloatBits.cpp b/skia/corecg/SkFloatBits.cpp
new file mode 100644
index 0000000..1f15df2
--- /dev/null
+++ b/skia/corecg/SkFloatBits.cpp
@@ -0,0 +1,205 @@
+#include "SkFloatBits.h"
+#include "SkMath.h"
+
+/******************************************************************************
+ SkFloatBits_toInt[Floor, Round, Ceil] are identical except for what they
+ do right before they return ... >> exp;
+ Floor - adds nothing
+ Round - adds 1 << (exp - 1)
+ Ceil - adds (1 << exp) - 1
+
+ Floor and Cast are very similar, but Cast applies its sign after all other
+ computations on value. Also, Cast does not need to check for negative zero,
+ as that value (0x80000000) "does the right thing" for Ceil. Note that it
+ doesn't for Floor/Round/Ceil, hence the explicit check.
+******************************************************************************/
+
+#define EXP_BIAS (127+23)
+#define MATISSA_MAGIC_BIG (1 << 23)
+
+static inline int unpack_exp(uint32_t packed) {
+ return (packed << 1 >> 24);
+}
+
+#if 0
+// the ARM compiler generates an extra BIC, so I use the dirty version instead
+static inline int unpack_matissa(uint32_t packed) {
+ // we could mask with 0x7FFFFF, but that is harder for ARM to encode
+ return (packed & ~0xFF000000) | MATISSA_MAGIC_BIG;
+}
+#endif
+
+// returns the low 24-bits, so we need to OR in the magic_bit afterwards
+static inline int unpack_matissa_dirty(uint32_t packed) {
+ return packed & ~0xFF000000;
+}
+
+// same as (int)float
+int32_t SkFloatBits_toIntCast(int32_t packed) {
+ int exp = unpack_exp(packed) - EXP_BIAS;
+ int value = unpack_matissa_dirty(packed) | MATISSA_MAGIC_BIG;
+
+ if (exp >= 0) {
+ if (exp > 7) { // overflow
+ value = SK_MaxS32;
+ } else {
+ value <<= exp;
+ }
+ } else {
+ exp = -exp;
+ if (exp > 25) { // underflow
+ exp = 25;
+ }
+ value >>= exp;
+ }
+ return SkApplySign(value, SkExtractSign(packed));
+}
+
+// same as (int)floor(float)
+int32_t SkFloatBits_toIntFloor(int32_t packed) {
+ // curse you negative 0
+ if ((packed << 1) == 0) {
+ return 0;
+ }
+
+ int exp = unpack_exp(packed) - EXP_BIAS;
+ int value = unpack_matissa_dirty(packed) | MATISSA_MAGIC_BIG;
+
+ if (exp >= 0) {
+ if (exp > 7) { // overflow
+ value = SK_MaxS32;
+ } else {
+ value <<= exp;
+ }
+ // apply the sign after we check for overflow
+ return SkApplySign(value, SkExtractSign(packed));
+ } else {
+ // apply the sign before we right-shift
+ value = SkApplySign(value, SkExtractSign(packed));
+ exp = -exp;
+ if (exp > 25) { // underflow
+ exp = 25;
+ }
+ // int add = 0;
+ return value >> exp;
+ }
+}
+
+// same as (int)floor(float + 0.5)
+int32_t SkFloatBits_toIntRound(int32_t packed) {
+ // curse you negative 0
+ if ((packed << 1) == 0) {
+ return 0;
+ }
+
+ int exp = unpack_exp(packed) - EXP_BIAS;
+ int value = unpack_matissa_dirty(packed) | MATISSA_MAGIC_BIG;
+
+ if (exp >= 0) {
+ if (exp > 7) { // overflow
+ value = SK_MaxS32;
+ } else {
+ value <<= exp;
+ }
+ // apply the sign after we check for overflow
+ return SkApplySign(value, SkExtractSign(packed));
+ } else {
+ // apply the sign before we right-shift
+ value = SkApplySign(value, SkExtractSign(packed));
+ exp = -exp;
+ if (exp > 25) { // underflow
+ exp = 25;
+ }
+ int add = 1 << (exp - 1);
+ return (value + add) >> exp;
+ }
+}
+
+// same as (int)ceil(float)
+int32_t SkFloatBits_toIntCeil(int32_t packed) {
+ // curse you negative 0
+ if ((packed << 1) == 0) {
+ return 0;
+ }
+
+ int exp = unpack_exp(packed) - EXP_BIAS;
+ int value = unpack_matissa_dirty(packed) | MATISSA_MAGIC_BIG;
+
+ if (exp >= 0) {
+ if (exp > 7) { // overflow
+ value = SK_MaxS32;
+ } else {
+ value <<= exp;
+ }
+ // apply the sign after we check for overflow
+ return SkApplySign(value, SkExtractSign(packed));
+ } else {
+ // apply the sign before we right-shift
+ value = SkApplySign(value, SkExtractSign(packed));
+ exp = -exp;
+ if (exp > 25) { // underflow
+ exp = 25;
+ }
+ int add = (1 << exp) - 1;
+ return (value + add) >> exp;
+ }
+}
+
+float SkFloatBits_intToFloatNative(int x);
+float SkFloatBits_intToFloatNative(int x) {
+ return x;
+}
+
+float SkIntToFloatCast(int32_t value) {
+ if (0 == value) {
+ return 0;
+ }
+
+ int shift = EXP_BIAS;
+
+ // record the sign and make value positive
+ int sign = SkExtractSign(value);
+ value = SkApplySign(value, sign);
+
+ if (value >> 24) { // value is too big (has more than 24 bits set)
+ int bias = 8 - SkCLZ(value);
+ SkDebugf("value = %d, bias = %d\n", value, bias);
+ SkASSERT(bias > 0 && bias < 8);
+ value >>= bias; // need to round?
+ shift += bias;
+ } else {
+ int zeros = SkCLZ(value << 8);
+ SkASSERT(zeros >= 0 && zeros <= 23);
+ value <<= zeros;
+ shift -= zeros;
+ }
+
+ // now value is left-aligned to 24 bits
+ SkASSERT((value >> 23) == 1);
+ SkASSERT(shift >= 0 && shift <= 255);
+
+ SkFloatIntUnion data;
+ data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BIG);
+ return data.fFloat;
+}
+
+float SkIntToFloatCast_NoOverflowCheck(int32_t value) {
+ if (0 == value) {
+ return 0;
+ }
+
+ int shift = EXP_BIAS;
+
+ // record the sign and make value positive
+ int sign = SkExtractSign(value);
+ value = SkApplySign(value, sign);
+
+ int zeros = SkCLZ(value << 8);
+ value <<= zeros;
+ shift -= zeros;
+
+ SkFloatIntUnion data;
+ data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BIG);
+ return data.fFloat;
+}
+
diff --git a/skia/corecg/SkFloatBits.h b/skia/corecg/SkFloatBits.h
index 012770a..a1f67d8 100644
--- a/skia/corecg/SkFloatBits.h
+++ b/skia/corecg/SkFloatBits.h
@@ -1,43 +1,2 @@
-#ifndef SkFloatBits_DEFINED
-#define SkFloatBits_DEFINED
-
-#include "SkTypes.h"
-
-/** Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement
- int. This also converts -0 (0x80000000) to 0. Doing this to a float allows
- it to be compared using normal C operators (<, <=, etc.)
-*/
-static inline int32_t SkSignBitTo2sCompliment(int32_t x) {
- if (x < 0) {
- x &= 0x7FFFFFFF;
- x = -x;
- }
- return x;
-}
-
-#ifdef SK_CAN_USE_FLOAT
-
-union SkFloatIntUnion {
- float fFloat;
- int32_t fSignBitInt;
-};
-
-/** Return the float as a 2s compliment int. Just just be used to compare floats
- to each other or against positive float-bit-constants (like 0)
-*/
-static int32_t SkFloatAsInt(float x) {
- SkFloatIntUnion data;
- data.fFloat = x;
- return SkSignBitTo2sCompliment(data.fSignBitInt);
-}
-
-#endif
-
-#ifdef SK_SCALAR_IS_FLOAT
- #define SkScalarAsInt(x) SkFloatAsInt(x)
-#else
- #define SkScalarAsInt(x) (x)
-#endif
-
-#endif
-
+// TODO(brettw) remove this file!
+#include "../include/corecg/SkFloatBits.h"
diff --git a/skia/corecg/SkInterpolator.cpp b/skia/corecg/SkInterpolator.cpp
index 1576708..e4ecd95 100644
--- a/skia/corecg/SkInterpolator.cpp
+++ b/skia/corecg/SkInterpolator.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2008 Google Inc.
+ * Copyright (C) 2006-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -80,7 +80,7 @@ SkInterpolatorBase::Result SkInterpolatorBase::timeToT(SkMSec time, SkScalar* T,
SkASSERT(fFrameCount > 0);
Result result = kNormal_Result;
if (fRepeat != SK_Scalar1) {
- SkMSec startTime = 0, endTime = 0;
+ SkMSec startTime, endTime;
this->getDuration(&startTime, &endTime);
SkMSec totalTime = endTime - startTime;
SkMSec offsetTime = time - startTime;
diff --git a/skia/corecg/SkMath.cpp b/skia/corecg/SkMath.cpp
index 42ea107..c627d9b 100644
--- a/skia/corecg/SkMath.cpp
+++ b/skia/corecg/SkMath.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2008 Google Inc.
+ * Copyright (C) 2006-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
#include "SkMath.h"
#include "SkCordic.h"
+#include "SkFloatBits.h"
#include "SkFloatingPoint.h"
#include "Sk64.h"
#include "SkScalar.h"
@@ -214,7 +215,7 @@ int SkFixedMulCommon(SkFixed a, int b, int bias) {
#endif
SkFixed SkFixedFastInvert(SkFixed x) {
-/* Adapted (stolen) from Mathias' gglRecip()
+/* Adapted (stolen) from gglRecip()
*/
if (x == SK_Fixed1) {
@@ -585,6 +586,116 @@ static void check_length(const SkPoint& p, SkScalar targetLen) {
}
#endif
+#ifdef SK_CAN_USE_FLOAT
+
+static float nextFloat(SkRandom& rand) {
+ SkFloatIntUnion data;
+ data.fSignBitInt = rand.nextU();
+ return data.fFloat;
+}
+
+/* returns true if a == b as resulting from (int)x. Since it is undefined
+ what to do if the float exceeds 2^32-1, we check for that explicitly.
+*/
+static bool equal_float_native_skia(float x, uint32_t ni, uint32_t si) {
+ if (!(x == x)) { // NAN
+ return si == SK_MaxS32 || si == SK_MinS32;
+ }
+ // for out of range, C is undefined, but skia always should return NaN32
+ if (x > SK_MaxS32) {
+ return si == SK_MaxS32;
+ }
+ if (x < -SK_MaxS32) {
+ return si == SK_MinS32;
+ }
+ return si == ni;
+}
+
+static void assert_float_equal(const char op[], float x, uint32_t ni,
+ uint32_t si) {
+ if (!equal_float_native_skia(x, ni, si)) {
+ SkDebugf("-- %s float %g bits %x native %x skia %x\n", op, x, ni, si);
+ SkASSERT(!"oops");
+ }
+}
+
+static void test_float_cast(float x) {
+ int ix = (int)x;
+ int iix = SkFloatToIntCast(x);
+ assert_float_equal("cast", x, ix, iix);
+}
+
+static void test_float_floor(float x) {
+ int ix = (int)floor(x);
+ int iix = SkFloatToIntFloor(x);
+ assert_float_equal("floor", x, ix, iix);
+}
+
+static void test_float_round(float x) {
+ double xx = x + 0.5; // need intermediate double to avoid temp loss
+ int ix = (int)floor(xx);
+ int iix = SkFloatToIntRound(x);
+ assert_float_equal("round", x, ix, iix);
+}
+
+static void test_float_ceil(float x) {
+ int ix = (int)ceil(x);
+ int iix = SkFloatToIntCeil(x);
+ assert_float_equal("ceil", x, ix, iix);
+}
+
+static void test_float_conversions(float x) {
+ test_float_cast(x);
+ test_float_floor(x);
+ test_float_round(x);
+ test_float_ceil(x);
+}
+
+static void test_int2float(int ival) {
+ float x0 = (float)ival;
+ float x1 = SkIntToFloatCast(ival);
+ float x2 = SkIntToFloatCast_NoOverflowCheck(ival);
+ SkASSERT(x0 == x1);
+ SkASSERT(x0 == x2);
+}
+
+static void unittest_fastfloat() {
+ SkRandom rand;
+ size_t i;
+
+ static const float gFloats[] = {
+ 0.f, 1.f, 0.5f, 0.499999f, 0.5000001f, 1.f/3,
+ 0.000000001f, 1000000000.f, // doesn't overflow
+ 0.0000000001f, 10000000000.f // does overflow
+ };
+ for (i = 0; i < SK_ARRAY_COUNT(gFloats); i++) {
+// SkDebugf("---- test floats %g %d\n", gFloats[i], (int)gFloats[i]);
+ test_float_conversions(gFloats[i]);
+ test_float_conversions(-gFloats[i]);
+ }
+
+ for (int outer = 0; outer < 100; outer++) {
+ rand.setSeed(outer);
+ for (i = 0; i < 100000; i++) {
+ float x = nextFloat(rand);
+ test_float_conversions(x);
+ }
+
+ test_int2float(0);
+ test_int2float(1);
+ test_int2float(-1);
+ for (i = 0; i < 100000; i++) {
+ // for now only test ints that are 24bits or less, since we don't
+ // round (down) large ints the same as IEEE...
+ int ival = rand.nextU() & 0xFFFFFF;
+ test_int2float(ival);
+ test_int2float(-ival);
+ }
+ }
+}
+
+#endif
+
static void test_muldiv255() {
for (int a = 0; a <= 255; a++) {
for (int b = 0; b <= 255; b++) {
@@ -606,7 +717,7 @@ static void test_muldiv255() {
}
}
-void SkMath::UnitTest() {
+void SkMath::UnitTest() {
#ifdef SK_SUPPORT_UNITTEST
int i;
int32_t x;
@@ -696,8 +807,10 @@ void SkMath::UnitTest() {
SkASSERT(result == 1);
}
+#ifdef SK_CAN_USE_FLOAT
+ unittest_fastfloat();
+#endif
-
#ifdef SkLONGLONG
for (i = 0; i < 100000; i++) {
SkFixed numer = rand.nextS();
@@ -817,4 +930,3 @@ void SkMath::UnitTest() {
}
#endif
-
diff --git a/skia/corecg/SkMatrix.cpp b/skia/corecg/SkMatrix.cpp
index 4c9a087..d556884 100644
--- a/skia/corecg/SkMatrix.cpp
+++ b/skia/corecg/SkMatrix.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkMatrix.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -65,19 +65,21 @@ enum {
uint8_t SkMatrix::computeTypeMask() const {
unsigned mask = 0;
- if (SkScalarAsInt(fMat[kMPersp0]) | SkScalarAsInt(fMat[kMPersp1]) |
- (SkScalarAsInt(fMat[kMPersp2]) - kPersp1Int)) {
+ if (SkScalarAs2sCompliment(fMat[kMPersp0]) |
+ SkScalarAs2sCompliment(fMat[kMPersp1]) |
+ (SkScalarAs2sCompliment(fMat[kMPersp2]) - kPersp1Int)) {
mask |= kPerspective_Mask;
}
- if (SkScalarAsInt(fMat[kMTransX]) | SkScalarAsInt(fMat[kMTransY])) {
+ if (SkScalarAs2sCompliment(fMat[kMTransX]) |
+ SkScalarAs2sCompliment(fMat[kMTransY])) {
mask |= kTranslate_Mask;
}
- int m00 = SkScalarAsInt(fMat[SkMatrix::kMScaleX]);
- int m01 = SkScalarAsInt(fMat[SkMatrix::kMSkewX]);
- int m10 = SkScalarAsInt(fMat[SkMatrix::kMSkewY]);
- int m11 = SkScalarAsInt(fMat[SkMatrix::kMScaleY]);
+ int m00 = SkScalarAs2sCompliment(fMat[SkMatrix::kMScaleX]);
+ int m01 = SkScalarAs2sCompliment(fMat[SkMatrix::kMSkewX]);
+ int m10 = SkScalarAs2sCompliment(fMat[SkMatrix::kMSkewY]);
+ int m11 = SkScalarAs2sCompliment(fMat[SkMatrix::kMScaleY]);
if (m01 | m10) {
mask |= kAffine_Mask;
@@ -112,7 +114,7 @@ uint8_t SkMatrix::computeTypeMask() const {
///////////////////////////////////////////////////////////////////////////////
void SkMatrix::setTranslate(SkScalar dx, SkScalar dy) {
- if (SkScalarAsInt(dx) | SkScalarAsInt(dy)) {
+ if (SkScalarAs2sCompliment(dx) | SkScalarAs2sCompliment(dy)) {
fMat[kMTransX] = dx;
fMat[kMTransY] = dy;
@@ -134,7 +136,7 @@ bool SkMatrix::preTranslate(SkScalar dx, SkScalar dy) {
return this->preConcat(m);
}
- if (SkScalarAsInt(dx) | SkScalarAsInt(dy)) {
+ if (SkScalarAs2sCompliment(dx) | SkScalarAs2sCompliment(dy)) {
fMat[kMTransX] += SkScalarMul(fMat[kMScaleX], dx) +
SkScalarMul(fMat[kMSkewX], dy);
fMat[kMTransY] += SkScalarMul(fMat[kMSkewY], dx) +
@@ -152,7 +154,7 @@ bool SkMatrix::postTranslate(SkScalar dx, SkScalar dy) {
return this->postConcat(m);
}
- if (SkScalarAsInt(dx) | SkScalarAsInt(dy)) {
+ if (SkScalarAs2sCompliment(dx) | SkScalarAs2sCompliment(dy)) {
fMat[kMTransX] += dx;
fMat[kMTransY] += dy;
this->setTypeMask(kUnknown_Mask);
@@ -643,11 +645,15 @@ bool SkMatrix::setConcat(const SkMatrix& a, const SkMatrix& b) {
}
bool SkMatrix::preConcat(const SkMatrix& mat) {
- return this->setConcat(*this, mat);
+ // check for identity first, so we don't do a needless copy of ourselves
+ // to ourselves inside setConcat()
+ return mat.isIdentity() || this->setConcat(*this, mat);
}
bool SkMatrix::postConcat(const SkMatrix& mat) {
- return this->setConcat(mat, *this);
+ // check for identity first, so we don't do a needless copy of ourselves
+ // to ourselves inside setConcat()
+ return mat.isIdentity() || this->setConcat(mat, *this);
}
///////////////////////////////////////////////////////////////////////////////
@@ -672,7 +678,6 @@ bool SkMatrix::postConcat(const SkMatrix& mat) {
if (SkScalarNearlyZero((float)det, SK_ScalarNearlyZero * SK_ScalarNearlyZero)) {
return 0;
}
-
return (float)(1.0 / det);
}
#else
diff --git a/skia/corecg/SkMemory_stdlib.cpp b/skia/corecg/SkMemory_stdlib.cpp
index 6ceca33..befcda6 100644
--- a/skia/corecg/SkMemory_stdlib.cpp
+++ b/skia/corecg/SkMemory_stdlib.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkMemory_stdlib.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkPageFlipper.cpp b/skia/corecg/SkPageFlipper.cpp
new file mode 100644
index 0000000..526ba09
--- /dev/null
+++ b/skia/corecg/SkPageFlipper.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SkPageFlipper.h"
+
+SkPageFlipper::SkPageFlipper() {
+ fWidth = 0;
+ fHeight = 0;
+ fDirty0 = &fDirty0Storage;
+ fDirty1 = &fDirty1Storage;
+
+ fDirty0->setEmpty();
+ fDirty1->setEmpty();
+}
+
+SkPageFlipper::SkPageFlipper(int width, int height) {
+ fWidth = width;
+ fHeight = height;
+ fDirty0 = &fDirty0Storage;
+ fDirty1 = &fDirty1Storage;
+
+ fDirty0->setRect(0, 0, width, height);
+ fDirty1->setEmpty();
+}
+
+void SkPageFlipper::resize(int width, int height) {
+ fWidth = width;
+ fHeight = height;
+
+ // this is the opposite of the constructors
+ fDirty1->setRect(0, 0, width, height);
+ fDirty0->setEmpty();
+}
+
+void SkPageFlipper::inval() {
+ fDirty1->setRect(0, 0, fWidth, fHeight);
+}
+
+void SkPageFlipper::inval(const SkIRect& rect) {
+ SkIRect r;
+ r.set(0, 0, fWidth, fHeight);
+ if (r.intersect(rect)) {
+ fDirty1->op(r, SkRegion::kUnion_Op);
+ }
+}
+
+void SkPageFlipper::inval(const SkRegion& rgn) {
+ SkRegion r;
+ r.setRect(0, 0, fWidth, fHeight);
+ if (r.op(rgn, SkRegion::kIntersect_Op)) {
+ fDirty1->op(r, SkRegion::kUnion_Op);
+ }
+}
+
+void SkPageFlipper::inval(const SkRect& rect, bool antialias) {
+ SkIRect r;
+ rect.round(&r);
+ if (antialias) {
+ r.inset(-1, -1);
+ }
+ this->inval(r);
+}
+
+const SkRegion& SkPageFlipper::update(SkRegion* copyBits) {
+ // Copy over anything new from page0 that isn't dirty in page1
+ copyBits->op(*fDirty0, *fDirty1, SkRegion::kDifference_Op);
+ SkTSwap<SkRegion*>(fDirty0, fDirty1);
+ fDirty1->setEmpty();
+ return *fDirty0;
+}
+
+
diff --git a/skia/corecg/SkPoint.cpp b/skia/corecg/SkPoint.cpp
index 9d6acdf..704c2ba 100644
--- a/skia/corecg/SkPoint.cpp
+++ b/skia/corecg/SkPoint.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2008 Google Inc.
+ * Copyright (C) 2006-2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkRect.cpp b/skia/corecg/SkRect.cpp
index f32b27e..d602754 100644
--- a/skia/corecg/SkRect.cpp
+++ b/skia/corecg/SkRect.cpp
@@ -1,19 +1,18 @@
-/* libs/corecg/SkRect.cpp
-**
-** Copyright 2006, Google Inc.
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include "SkRect.h"
@@ -67,17 +66,33 @@ void SkRect::set(const SkPoint pts[], int count)
{
SkASSERT((pts && count > 0) || count == 0);
- if (count <= 0)
- memset(this, 0, sizeof(SkRect));
- else
- {
+ if (count <= 0) {
+ bzero(this, sizeof(SkRect));
+ } else {
+#ifdef SK_SCALAR_SLOW_COMPARES
+ int32_t l, t, r, b;
+
+ l = r = SkScalarAs2sCompliment(pts[0].fX);
+ t = b = SkScalarAs2sCompliment(pts[0].fY);
+
+ for (int i = 1; i < count; i++) {
+ int32_t x = SkScalarAs2sCompliment(pts[i].fX);
+ int32_t y = SkScalarAs2sCompliment(pts[i].fY);
+
+ if (x < l) l = x; else if (x > r) r = x;
+ if (y < t) t = y; else if (y > b) b = y;
+ }
+ this->set(Sk2sComplimentAsScalar(l),
+ Sk2sComplimentAsScalar(t),
+ Sk2sComplimentAsScalar(r),
+ Sk2sComplimentAsScalar(b));
+#else
SkScalar l, t, r, b;
l = r = pts[0].fX;
t = b = pts[0].fY;
- for (int i = 1; i < count; i++)
- {
+ for (int i = 1; i < count; i++) {
SkScalar x = pts[i].fX;
SkScalar y = pts[i].fY;
@@ -85,6 +100,7 @@ void SkRect::set(const SkPoint pts[], int count)
if (y < t) t = y; else if (y > b) b = y;
}
this->set(l, t, r, b);
+#endif
}
}
diff --git a/skia/corecg/SkRegion.cpp b/skia/corecg/SkRegion.cpp
index a0860b6e..4edd222 100644
--- a/skia/corecg/SkRegion.cpp
+++ b/skia/corecg/SkRegion.cpp
@@ -1,6 +1,6 @@
/* libs/corecg/SkRegion.cpp
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -430,6 +430,46 @@ const SkRegion::RunType* SkRegion::getRuns(RunType tmpStorage[], int* count) con
/////////////////////////////////////////////////////////////////////////////////////
+bool SkRegion::intersects(const SkIRect& r) const {
+ if (this->isEmpty() || r.isEmpty()) {
+ return false;
+ }
+
+ if (!SkIRect::Intersects(fBounds, r)) {
+ return false;
+ }
+
+ if (this->isRect()) {
+ return true;
+ }
+
+ // we are complex
+ SkRegion tmp;
+ return tmp.op(*this, r, kIntersect_Op);
+}
+
+bool SkRegion::intersects(const SkRegion& rgn) const {
+ if (this->isEmpty() || rgn.isEmpty()) {
+ return false;
+ }
+
+ if (!SkIRect::Intersects(fBounds, rgn.fBounds)) {
+ return false;
+ }
+
+ if (this->isRect() && rgn.isRect()) {
+ return true;
+ }
+
+ // one or both of us is complex
+ // TODO: write a faster version that aborts as soon as we write the first
+ // non-empty span, to avoid build the entire result
+ SkRegion tmp;
+ return tmp.op(*this, rgn, kIntersect_Op);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+
int operator==(const SkRegion& a, const SkRegion& b)
{
SkDEBUGCODE(a.validate();)
diff --git a/skia/corecg/SkRegionPriv.h b/skia/corecg/SkRegionPriv.h
index 80e2e83..70f8828 100644
--- a/skia/corecg/SkRegionPriv.h
+++ b/skia/corecg/SkRegionPriv.h
@@ -1,6 +1,6 @@
/* libs/corecg/SkRegionPriv.h
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkSinTable.h b/skia/corecg/SkSinTable.h
index eb3a31c..9b4477d 100644
--- a/skia/corecg/SkSinTable.h
+++ b/skia/corecg/SkSinTable.h
@@ -1,6 +1,6 @@
/* libs/corecg/SkSinTable.h
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
diff --git a/skia/corecg/SkTSort.h b/skia/corecg/SkTSort.h
index 44f05bb..6193dff 100644
--- a/skia/corecg/SkTSort.h
+++ b/skia/corecg/SkTSort.h
@@ -1,6 +1,6 @@
/* libs/corecg/SkTSort.h
**
-** Copyright 2006, Google Inc.
+** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.