aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-05 14:34:31 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-05 14:34:31 -0800
commit3298d565d8a70b84f28b455f6289293883c85494 (patch)
tree3ca78e8673ac147dfcc86e9feeb2155b40ef9005 /src
parent0910916c0f7b951ee55c4b7c6358295b9bca0565 (diff)
downloadexternal_skia-3298d565d8a70b84f28b455f6289293883c85494.zip
external_skia-3298d565d8a70b84f28b455f6289293883c85494.tar.gz
external_skia-3298d565d8a70b84f28b455f6289293883c85494.tar.bz2
auto import from //depot/cupcake/@136594
Diffstat (limited to 'src')
-rw-r--r--src/core/Sk64.cpp205
-rw-r--r--src/core/SkCanvas.cpp10
-rw-r--r--src/core/SkGeometry.cpp23
-rw-r--r--src/core/SkGraphics.cpp7
-rw-r--r--src/core/SkMath.cpp393
-rw-r--r--src/core/SkMatrix.cpp82
-rw-r--r--src/core/SkPath.cpp95
-rw-r--r--src/core/SkString.cpp59
-rw-r--r--src/core/SkTypeface.cpp55
-rw-r--r--src/core/SkUtils.cpp123
-rw-r--r--src/core/SkXfermode.cpp23
-rw-r--r--src/ports/SkFontHost_FONTPATH.cpp18
-rw-r--r--src/ports/SkFontHost_FreeType.cpp5
-rw-r--r--src/ports/SkFontHost_android.cpp71
-rw-r--r--src/ports/SkFontHost_linux.cpp90
-rwxr-xr-xsrc/ports/SkFontHost_mac.cpp15
-rw-r--r--src/ports/SkFontHost_none.cpp24
-rw-r--r--src/ports/SkFontHost_win.cpp5
18 files changed, 152 insertions, 1151 deletions
diff --git a/src/core/Sk64.cpp b/src/core/Sk64.cpp
index 2715d23..4381b50 100644
--- a/src/core/Sk64.cpp
+++ b/src/core/Sk64.cpp
@@ -368,208 +368,3 @@ SkFixed Sk64::getFixedDiv(const Sk64& denom) const
return SkApplySign(result, sign);
}
-///////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-#include "SkRandom.h"
-#include <math.h>
-
-#ifdef SK_SUPPORT_UNITTEST
-struct BoolTable {
- int8_t zero, pos, neg, toBool, sign;
-};
-
-static void bool_table_test(const Sk64& a, const BoolTable& table)
-{
- SkASSERT(a.isZero() != a.nonZero());
-
- SkASSERT(!a.isZero() == !table.zero);
- SkASSERT(!a.isPos() == !table.pos);
- SkASSERT(!a.isNeg() == !table.neg);
- SkASSERT(a.getSign() == table.sign);
-}
-
-#ifdef SkLONGLONG
- static SkLONGLONG asLL(const Sk64& a)
- {
- return ((SkLONGLONG)a.fHi << 32) | a.fLo;
- }
-#endif
-#endif
-
-void Sk64::UnitTest()
-{
-#ifdef SK_SUPPORT_UNITTEST
- enum BoolTests {
- kZero_BoolTest,
- kPos_BoolTest,
- kNeg_BoolTest
- };
- static const BoolTable gBoolTable[] = {
- { 1, 0, 0, 0, 0 },
- { 0, 1, 0, 1, 1 },
- { 0, 0, 1, 1, -1 }
- };
-
- Sk64 a, b, c;
-
- a.fHi = a.fLo = 0;
- b.set(0);
- c.setZero();
- SkASSERT(a == b);
- SkASSERT(a == c);
- bool_table_test(a, gBoolTable[kZero_BoolTest]);
-
- a.fHi = 0; a.fLo = 5;
- b.set(5);
- SkASSERT(a == b);
- SkASSERT(a.is32() && a.get32() == 5 && !a.is64());
- bool_table_test(a, gBoolTable[kPos_BoolTest]);
-
- a.fHi = -1; a.fLo = (uint32_t)-5;
- b.set(-5);
- SkASSERT(a == b);
- SkASSERT(a.is32() && a.get32() == -5 && !a.is64());
- bool_table_test(a, gBoolTable[kNeg_BoolTest]);
-
- a.setZero();
- b.set(6);
- c.set(-6);
- SkASSERT(a != b && b != c && a != c);
- SkASSERT(!(a == b) && !(a == b) && !(a == b));
- SkASSERT(a < b && b > a && a <= b && b >= a);
- SkASSERT(c < a && a > c && c <= a && a >= c);
- SkASSERT(c < b && b > c && c <= b && b >= c);
-
- // Now test add/sub
-
- SkRandom rand;
- int i;
-
- for (i = 0; i < 1000; i++)
- {
- int aa = rand.nextS() >> 1;
- int bb = rand.nextS() >> 1;
- a.set(aa);
- b.set(bb);
- SkASSERT(a.get32() == aa && b.get32() == bb);
- c = a; c.add(bb);
- SkASSERT(c.get32() == aa + bb);
- c = a; c.add(-bb);
- SkASSERT(c.get32() == aa - bb);
- c = a; c.add(b);
- SkASSERT(c.get32() == aa + bb);
- c = a; c.sub(b);
- SkASSERT(c.get32() == aa - bb);
- }
-
-#ifdef SkLONGLONG
- for (i = 0; i < 1000; i++)
- {
- rand.next64(&a); //a.fHi >>= 1; // avoid overflow
- rand.next64(&b); //b.fHi >>= 1; // avoid overflow
-
- if (!(i & 3)) // want to explicitly test these cases
- {
- a.fLo = 0;
- b.fLo = 0;
- }
- else if (!(i & 7)) // want to explicitly test these cases
- {
- a.fHi = 0;
- b.fHi = 0;
- }
-
- SkLONGLONG aa = asLL(a);
- SkLONGLONG bb = asLL(b);
-
- SkASSERT((a < b) == (aa < bb));
- SkASSERT((a <= b) == (aa <= bb));
- SkASSERT((a > b) == (aa > bb));
- SkASSERT((a >= b) == (aa >= bb));
- SkASSERT((a == b) == (aa == bb));
- SkASSERT((a != b) == (aa != bb));
-
- c = a; c.add(b);
- SkASSERT(asLL(c) == aa + bb);
- c = a; c.sub(b);
- SkASSERT(asLL(c) == aa - bb);
- c = a; c.rsub(b);
- SkASSERT(asLL(c) == bb - aa);
- c = a; c.negate();
- SkASSERT(asLL(c) == -aa);
-
- int bits = rand.nextU() & 63;
- c = a; c.shiftLeft(bits);
- SkASSERT(asLL(c) == (aa << bits));
- c = a; c.shiftRight(bits);
- SkASSERT(asLL(c) == (aa >> bits));
- c = a; c.roundRight(bits);
-
- SkLONGLONG tmp;
-
- tmp = aa;
- if (bits > 0)
- tmp += (SkLONGLONG)1 << (bits - 1);
- SkASSERT(asLL(c) == (tmp >> bits));
-
- c.setMul(a.fHi, b.fHi);
- tmp = (SkLONGLONG)a.fHi * b.fHi;
- SkASSERT(asLL(c) == tmp);
- }
-
-
- for (i = 0; i < 100000; i++)
- {
- Sk64 wide;
- int32_t denom = rand.nextS();
-
- while (denom == 0)
- denom = rand.nextS();
- wide.setMul(rand.nextS(), rand.nextS());
- SkLONGLONG check = wide.getLongLong();
-
- wide.div(denom, Sk64::kTrunc_DivOption);
- check /= denom;
- SkLONGLONG w = wide.getLongLong();
-
- SkASSERT(check == w);
-
-#ifdef SK_CAN_USE_FLOATx
- wide.setMul(rand.nextS(), rand.nextS());
- wide.abs();
- denom = wide.getSqrt();
- int32_t ck = (int32_t)sqrt((double)wide.getLongLong());
- int diff = denom - ck;
- SkASSERT(SkAbs32(diff) <= 1);
-
- wide.setMul(rand.nextS(), rand.nextS());
- Sk64 dwide;
- dwide.setMul(rand.nextS(), rand.nextS());
- SkFixed fixdiv = wide.getFixedDiv(dwide);
- double dnumer = (double)wide.getLongLong();
- double ddenom = (double)dwide.getLongLong();
- double ddiv = dnumer / ddenom;
- SkFixed dfixdiv;
- if (ddiv >= (double)SK_MaxS32 / (double)SK_Fixed1)
- dfixdiv = SK_MaxS32;
- else if (ddiv <= -(double)SK_MaxS32 / (double)SK_Fixed1)
- dfixdiv = SK_MinS32;
- else
- dfixdiv = SkFloatToFixed(dnumer / ddenom);
- diff = fixdiv - dfixdiv;
-
- if (SkAbs32(diff) > 1) {
- SkDebugf(" %d === numer %g denom %g div %g xdiv %x fxdiv %x\n",
- i, dnumer, ddenom, ddiv, dfixdiv, fixdiv);
- }
-// SkASSERT(SkAbs32(diff) <= 1);
-#endif
- }
-#endif
-#endif
-}
-
-#endif
-
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 9b1f768..00461b0 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -813,6 +813,10 @@ bool SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op) {
fLocalBoundsCompareTypeDirty = true;
if (fMCRec->fMatrix->rectStaysRect()) {
+ // for these simpler matrices, we can stay a rect ever after applying
+ // the matrix. This means we don't have to a) make a path, and b) tell
+ // the region code to scan-convert the path, only to discover that it
+ // is really just a rect.
SkRect r;
SkIRect ir;
@@ -820,10 +824,14 @@ bool SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op) {
r.round(&ir);
return fMCRec->fRegion->op(ir, op);
} else {
+ // since we're rotate or some such thing, we convert the rect to a path
+ // and clip against that, since it can handle any matrix. However, to
+ // avoid recursion in the case where we are subclassed (e.g. Pictures)
+ // we explicitly call "our" version of clipPath.
SkPath path;
path.addRect(rect);
- return this->clipPath(path, op);
+ return this->SkCanvas::clipPath(path, op);
}
}
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index 7e2d424..229c3d8 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -1047,26 +1047,3 @@ int SkBuildQuadArc(const SkVector& uStart, const SkVector& uStop,
return pointCount;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-void SkGeometry::UnitTest()
-{
-#ifdef SK_SUPPORT_UNITTEST
- SkPoint pts[3], dst[5];
-
- pts[0].set(0, 0);
- pts[1].set(100, 50);
- pts[2].set(0, 100);
-
- int count = SkChopQuadAtMaxCurvature(pts, dst);
- SkASSERT(count == 1 || count == 2);
-#endif
-}
-
-#endif
-
-
diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp
index 7536ca8..ff41f0c 100644
--- a/src/core/SkGraphics.cpp
+++ b/src/core/SkGraphics.cpp
@@ -344,13 +344,6 @@ void SkGraphics::Init(bool runUnitTests)
const char* fTypeName;
void (*fUnitTest)();
} gUnitTests[] = {
- unittestline(Sk64),
- unittestline(SkMath),
- unittestline(SkUtils),
- unittestline(SkString),
- unittestline(SkMatrix),
- unittestline(SkGeometry),
- unittestline(SkPath),
unittestline(SkPathMeasure),
unittestline(SkStream),
unittestline(SkWStream),
diff --git a/src/core/SkMath.cpp b/src/core/SkMath.cpp
index e0babeb..649b518 100644
--- a/src/core/SkMath.cpp
+++ b/src/core/SkMath.cpp
@@ -543,396 +543,3 @@ SkFixed SkFixedATan2(SkFixed y, SkFixed x) { return SkCordicATan2(y, x); }
SkFixed SkFixedExp(SkFixed x) { return SkCordicExp(x); }
SkFixed SkFixedLog(SkFixed x) { return SkCordicLog(x); }
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-#include "SkRandom.h"
-
-#if defined(SkLONGLONG) && defined(SK_SUPPORT_UNITTEST)
-static int symmetric_fixmul(int a, int b) {
- int sa = SkExtractSign(a);
- int sb = SkExtractSign(b);
-
- a = SkApplySign(a, sa);
- b = SkApplySign(b, sb);
-
-#if 1
- int c = (int)(((SkLONGLONG)a * b) >> 16);
-
- return SkApplySign(c, sa ^ sb);
-#else
- SkLONGLONG ab = (SkLONGLONG)a * b;
- if (sa ^ sb) {
- ab = -ab;
- }
- return ab >> 16;
-#endif
-}
-#endif
-
-#include "SkPoint.h"
-
-#ifdef SK_SUPPORT_UNITTEST
-static void check_length(const SkPoint& p, SkScalar targetLen) {
-#ifdef SK_CAN_USE_FLOAT
- float x = SkScalarToFloat(p.fX);
- float y = SkScalarToFloat(p.fY);
- float len = sk_float_sqrt(x*x + y*y);
-
- len /= SkScalarToFloat(targetLen);
-
- SkASSERT(len > 0.999f && len < 1.001f);
-#endif
-}
-#endif
-
-#if defined(SK_CAN_USE_FLOAT) && defined(SK_SUPPORT_UNITTEST)
-
-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
-
-#ifdef SK_SUPPORT_UNITTEST
-static void test_muldiv255() {
-#ifdef SK_CAN_USE_FLOAT
- for (int a = 0; a <= 255; a++) {
- for (int b = 0; b <= 255; b++) {
- int ab = a * b;
- float s = ab / 255.0f;
- int round = (int)floorf(s + 0.5f);
- int trunc = (int)floorf(s);
-
- int iround = SkMulDiv255Round(a, b);
- int itrunc = SkMulDiv255Trunc(a, b);
-
- SkASSERT(iround == round);
- SkASSERT(itrunc == trunc);
-
- SkASSERT(itrunc <= iround);
- SkASSERT(iround <= a);
- SkASSERT(iround <= b);
- }
- }
-#endif
-}
-#endif
-
-void SkMath::UnitTest() {
-#ifdef SK_SUPPORT_UNITTEST
- int i;
- int32_t x;
- SkRandom rand;
-
- SkToS8(127); SkToS8(-128); SkToU8(255);
- SkToS16(32767); SkToS16(-32768); SkToU16(65535);
- SkToS32(2*1024*1024); SkToS32(-2*1024*1024); SkToU32(4*1024*1024);
-
- SkCordic_UnitTest();
-
- // these should assert
-#if 0
- SkToS8(128);
- SkToS8(-129);
- SkToU8(256);
- SkToU8(-5);
-
- SkToS16(32768);
- SkToS16(-32769);
- SkToU16(65536);
- SkToU16(-5);
-
- if (sizeof(size_t) > 4) {
- SkToS32(4*1024*1024);
- SkToS32(-4*1024*1024);
- SkToU32(5*1024*1024);
- SkToU32(-5);
- }
-#endif
-
- test_muldiv255();
-
-#ifdef SK_DEBUG
- {
- SkScalar x = SK_ScalarNaN;
- SkASSERT(SkScalarIsNaN(x));
- }
-#endif
-
- for (i = 1; i <= 10; i++) {
- x = SkCubeRootBits(i*i*i, 11);
- SkASSERT(x == i);
- }
-
- x = SkFixedSqrt(SK_Fixed1);
- SkASSERT(x == SK_Fixed1);
- x = SkFixedSqrt(SK_Fixed1/4);
- SkASSERT(x == SK_Fixed1/2);
- x = SkFixedSqrt(SK_Fixed1*4);
- SkASSERT(x == SK_Fixed1*2);
-
- x = SkFractSqrt(SK_Fract1);
- SkASSERT(x == SK_Fract1);
- x = SkFractSqrt(SK_Fract1/4);
- SkASSERT(x == SK_Fract1/2);
- x = SkFractSqrt(SK_Fract1/16);
- SkASSERT(x == SK_Fract1/4);
-
- for (i = 1; i < 100; i++) {
- x = SkFixedSqrt(SK_Fixed1 * i * i);
- SkASSERT(x == SK_Fixed1 * i);
- }
-
- for (i = 0; i < 1000; i++) {
- int value = rand.nextS16();
- int max = rand.nextU16();
-
- int clamp = SkClampMax(value, max);
- int clamp2 = value < 0 ? 0 : (value > max ? max : value);
- SkASSERT(clamp == clamp2);
- }
-
- for (i = 0; i < 100000; i++) {
- SkPoint p;
-
- p.setLength(rand.nextS(), rand.nextS(), SK_Scalar1);
- check_length(p, SK_Scalar1);
- p.setLength(rand.nextS() >> 13, rand.nextS() >> 13, SK_Scalar1);
- check_length(p, SK_Scalar1);
- }
-
- {
- SkFixed result = SkFixedDiv(100, 100);
- SkASSERT(result == SK_Fixed1);
- result = SkFixedDiv(1, SK_Fixed1);
- SkASSERT(result == 1);
- }
-
-#ifdef SK_CAN_USE_FLOAT
- unittest_fastfloat();
-#endif
-
-#ifdef SkLONGLONG
- for (i = 0; i < 100000; i++) {
- SkFixed numer = rand.nextS();
- SkFixed denom = rand.nextS();
- SkFixed result = SkFixedDiv(numer, denom);
- SkLONGLONG check = ((SkLONGLONG)numer << 16) / denom;
-
- (void)SkCLZ(numer);
- (void)SkCLZ(denom);
-
- SkASSERT(result != (SkFixed)SK_NaN32);
- if (check > SK_MaxS32) {
- check = SK_MaxS32;
- } else if (check < -SK_MaxS32) {
- check = SK_MinS32;
- }
- SkASSERT(result == (int32_t)check);
-
- result = SkFractDiv(numer, denom);
- check = ((SkLONGLONG)numer << 30) / denom;
-
- SkASSERT(result != (SkFixed)SK_NaN32);
- if (check > SK_MaxS32) {
- check = SK_MaxS32;
- } else if (check < -SK_MaxS32) {
- check = SK_MinS32;
- }
- SkASSERT(result == (int32_t)check);
-
- // make them <= 2^24, so we don't overflow in fixmul
- numer = numer << 8 >> 8;
- denom = denom << 8 >> 8;
-
- result = SkFixedMul(numer, denom);
- SkFixed r2 = symmetric_fixmul(numer, denom);
-// SkASSERT(result == r2);
-
- result = SkFixedMul(numer, numer);
- r2 = SkFixedSquare(numer);
- SkASSERT(result == r2);
-
-#ifdef SK_CAN_USE_FLOAT
- if (numer >= 0 && denom >= 0) {
- SkFixed mean = SkFixedMean(numer, denom);
- float fm = sk_float_sqrt(sk_float_abs(SkFixedToFloat(numer) * SkFixedToFloat(denom)));
- SkFixed mean2 = SkFloatToFixed(fm);
- int diff = SkAbs32(mean - mean2);
- SkASSERT(diff <= 1);
- }
-
- {
- SkFixed mod = SkFixedMod(numer, denom);
- float n = SkFixedToFloat(numer);
- float d = SkFixedToFloat(denom);
- float m = sk_float_mod(n, d);
-#if 0
- SkDebugf("%g mod %g = %g [%g]\n",
- SkFixedToFloat(numer), SkFixedToFloat(denom),
- SkFixedToFloat(mod), m);
-#endif
- SkASSERT(mod == 0 || (mod < 0) == (m < 0)); // ensure the same sign
- int diff = SkAbs32(mod - SkFloatToFixed(m));
- SkASSERT((diff >> 7) == 0);
- }
-#endif
- }
-#endif
-
-#ifdef SK_CAN_USE_FLOAT
- for (i = 0; i < 100000; i++) {
- SkFract x = rand.nextU() >> 1;
- double xx = (double)x / SK_Fract1;
- SkFract xr = SkFractSqrt(x);
- SkFract check = SkFloatToFract(sqrt(xx));
- SkASSERT(xr == check || xr == check-1 || xr == check+1);
-
- xr = SkFixedSqrt(x);
- xx = (double)x / SK_Fixed1;
- check = SkFloatToFixed(sqrt(xx));
- SkASSERT(xr == check || xr == check-1);
-
- xr = SkSqrt32(x);
- xx = (double)x;
- check = (int32_t)sqrt(xx);
- SkASSERT(xr == check || xr == check-1);
- }
-#endif
-
-#if !defined(SK_SCALAR_IS_FLOAT) && defined(SK_CAN_USE_FLOAT)
- {
- SkFixed s, c;
- s = SkFixedSinCos(0, &c);
- SkASSERT(s == 0);
- SkASSERT(c == SK_Fixed1);
- }
-
- int maxDiff = 0;
- for (i = 0; i < 10000; i++) {
- SkFixed rads = rand.nextS() >> 10;
- double frads = SkFixedToFloat(rads);
-
- SkFixed s, c;
- s = SkScalarSinCos(rads, &c);
-
- double fs = sin(frads);
- double fc = cos(frads);
-
- SkFixed is = SkFloatToFixed(fs);
- SkFixed ic = SkFloatToFixed(fc);
-
- maxDiff = SkMax32(maxDiff, SkAbs32(is - s));
- maxDiff = SkMax32(maxDiff, SkAbs32(ic - c));
- }
- SkDebugf("SinCos: maximum error = %d\n", maxDiff);
-#endif
-#endif
-}
-
-#endif
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 893aea1..ac5ae92 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1606,85 +1606,3 @@ void SkMatrix::toDumpString(SkString* str) const {
#endif
}
-///////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-void SkMatrix::UnitTest() {
-#ifdef SK_SUPPORT_UNITTEST
- SkMatrix mat, inverse, iden1, iden2;
-
- mat.reset();
- mat.setTranslate(SK_Scalar1, SK_Scalar1);
- mat.invert(&inverse);
- inverse.dump();
- iden1.setConcat(mat, inverse);
- iden1.dump();
-
- mat.setScale(SkIntToScalar(2), SkIntToScalar(2));
- mat.invert(&inverse);
- inverse.dump();
- iden1.setConcat(mat, inverse);
- iden1.dump();
-
- mat.setScale(SK_Scalar1/2, SK_Scalar1/2);
- mat.invert(&inverse);
- inverse.dump();
- iden1.setConcat(mat, inverse);
- iden1.dump();
- SkASSERT(iden1.isIdentity());
-
- mat.setScale(SkIntToScalar(3), SkIntToScalar(5), SkIntToScalar(20), 0);
- mat.postRotate(SkIntToScalar(25));
-
- SkASSERT(mat.invert(NULL));
- mat.invert(&inverse);
-
- iden1.setConcat(mat, inverse);
- iden2.setConcat(inverse, mat);
-
- iden1.dump();
-// SkASSERT(iden1.isIdentity());
- iden2.dump();
-// SkASSERT(iden2.isIdentity());
-
- // rectStaysRect test
- {
- static const struct {
- SkScalar m00, m01, m10, m11;
- bool mStaysRect;
- }
- gRectStaysRectSamples[] = {
- { 0, 0, 0, 0, false },
- { 0, 0, 0, SK_Scalar1, false },
- { 0, 0, SK_Scalar1, 0, false },
- { 0, 0, SK_Scalar1, SK_Scalar1, false },
- { 0, SK_Scalar1, 0, 0, false },
- { 0, SK_Scalar1, 0, SK_Scalar1, false },
- { 0, SK_Scalar1, SK_Scalar1, 0, true },
- { 0, SK_Scalar1, SK_Scalar1, SK_Scalar1, false },
- { SK_Scalar1, 0, 0, 0, false },
- { SK_Scalar1, 0, 0, SK_Scalar1, true },
- { SK_Scalar1, 0, SK_Scalar1, 0, false },
- { SK_Scalar1, 0, SK_Scalar1, SK_Scalar1, false },
- { SK_Scalar1, SK_Scalar1, 0, 0, false },
- { SK_Scalar1, SK_Scalar1, 0, SK_Scalar1, false },
- { SK_Scalar1, SK_Scalar1, SK_Scalar1, 0, false },
- { SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, false }
- };
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gRectStaysRectSamples); i++) {
- SkMatrix m;
-
- m.reset();
- m.set(SkMatrix::kMScaleX, gRectStaysRectSamples[i].m00);
- m.set(SkMatrix::kMSkewX, gRectStaysRectSamples[i].m01);
- m.set(SkMatrix::kMSkewY, gRectStaysRectSamples[i].m10);
- m.set(SkMatrix::kMScaleY, gRectStaysRectSamples[i].m11);
- SkASSERT(m.rectStaysRect() == gRectStaysRectSamples[i].mStaysRect);
- }
- }
-#endif
-}
-
-#endif
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 82eb980..de90896 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -114,6 +114,11 @@ SkPath& SkPath::operator=(const SkPath& src) {
return *this;
}
+bool operator==(const SkPath& a, const SkPath& b) {
+ return &a == &b ||
+ (a.fFillType == b.fFillType && a.fVerbs == b.fVerbs && a.fPts == b.fPts);
+}
+
void SkPath::swap(SkPath& other) {
SkASSERT(&other != NULL);
@@ -151,7 +156,7 @@ bool SkPath::isEmpty() const {
bool SkPath::isRect(SkRect*) const {
SkDEBUGCODE(this->validate();)
-
+
SkASSERT(!"unimplemented");
return false;
}
@@ -1287,57 +1292,6 @@ void SkPath::validate() const {
}
}
-#if 0 // test to ensure that the iterator returns the same data as the path
-void SkPath::test() const
-{
- Iter iter(*this, false);
- SkPoint pts[4];
- Verb verb;
-
- const uint8_t* verbs = fVerbs.begin();
- const SkPoint* points = fPts.begin();
-
- while ((verb = iter.next(pts)) != kDone_Verb)
- {
- SkASSERT(*verbs == verb);
- verbs += 1;
-
- int count;
- switch (verb) {
- case kMove_Verb:
- count = 1;
- break;
- case kLine_Verb:
- count = 2;
- break;
- case kQuad_Verb:
- count = 3;
- break;
- case kCubic_Verb:
- count = 4;
- break;
- case kClose_Verb:
- default:
- count = 0;
- break;
- }
- if (count > 1)
- points -= 1;
- SkASSERT(memcmp(pts, points, count * sizeof(SkPoint)) == 0);
- points += count;
- }
-
- int vc = fVerbs.count(), pc = fPts.count();
- if (vc && fVerbs.begin()[vc-1] == kMove_Verb)
- {
- vc -= 1;
- pc -= 1;
- }
- SkASSERT(verbs - fVerbs.begin() == vc);
- SkASSERT(points - fPts.begin() == pc);
-}
-#endif
-
void SkPath::dump(bool forceClose, const char title[]) const {
Iter iter(*this, forceClose);
SkPoint pts[4];
@@ -1398,41 +1352,4 @@ void SkPath::dump(bool forceClose, const char title[]) const {
SkDebugf("path: done %s\n", title ? title : "");
}
-#include "SkTSort.h"
-
-void SkPath::UnitTest() {
-#ifdef SK_SUPPORT_UNITTEST
- SkPath p;
- SkRect r;
-
- r.set(0, 0, 10, 20);
- p.addRect(r);
- p.dump(false);
- p.dump(true);
-
- {
- int array[] = { 5, 3, 7, 2, 6, 1, 2, 9, 5, 0 };
- int i;
-
- for (i = 0; i < (int)SK_ARRAY_COUNT(array); i++) {
- SkDebugf(" %d", array[i]);
- }
- SkDebugf("\n");
- SkTHeapSort<int>(array, SK_ARRAY_COUNT(array));
- for (i = 0; i < (int)SK_ARRAY_COUNT(array); i++)
- SkDebugf(" %d", array[i]);
- SkDebugf("\n");
- }
-
- {
- SkPath p;
- SkPoint pt;
-
- p.moveTo(SK_Scalar1, 0);
- p.getLastPt(&pt);
- SkASSERT(pt.fX == SK_Scalar1);
- }
-#endif
-}
-
#endif
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index 2e5d946..d595d51 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -581,62 +581,3 @@ SkAutoUCS2::~SkAutoUCS2()
delete[] fUCS2;
}
-/////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-void SkString::UnitTest()
-{
-#ifdef SK_SUPPORT_UNITTEST
- SkString a;
- SkString b((size_t)0);
- SkString c("");
- SkString d(NULL, 0);
-
- SkASSERT(a.isEmpty());
- SkASSERT(a == b && a == c && a == d);
-
- a.set("hello");
- b.set("hellox", 5);
- c.set(a);
- d.resize(5);
- memcpy(d.writable_str(), "helloz", 5);
-
- SkASSERT(!a.isEmpty());
- SkASSERT(a.size() == 5);
- SkASSERT(a == b && a == c && a == d);
- SkASSERT(a.equals("hello", 5));
- SkASSERT(a.equals("hello"));
- SkASSERT(!a.equals("help"));
-
- SkString e(a);
- SkString f("hello");
- SkString g("helloz", 5);
-
- SkASSERT(a == e && a == f && a == g);
-
- b.set("world");
- c = b;
- SkASSERT(a != b && a != c && b == c);
-
- a.append(" world");
- e.append("worldz", 5);
- e.insert(5, " ");
- f.set("world");
- f.prepend("hello ");
- SkASSERT(a.equals("hello world") && a == e && a == f);
-
- a.reset();
- b.resize(0);
- SkASSERT(a.isEmpty() && b.isEmpty() && a == b);
-
- a.set("a");
- a.set("ab");
- a.set("abc");
- a.set("abcd");
-#endif
-}
-
-#endif
-
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 4604f6d..38d0e01 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -1,50 +1,45 @@
#include "SkTypeface.h"
#include "SkFontHost.h"
-static const SkTypeface* resolve_null_typeface(const SkTypeface* face)
-{
- if (NULL == face) {
- face = SkFontHost::FindTypeface(NULL, NULL, SkTypeface::kNormal);
- SkASSERT(face);
+uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
+ if (face) {
+ return face->uniqueID();
}
- return face;
-}
-uint32_t SkTypeface::UniqueID(const SkTypeface* face)
-{
- return resolve_null_typeface(face)->uniqueID();
+ // We cache the default fontID, assuming it will not change during a boot
+ // The initial value of 0 is fine, since a typeface's uniqueID should not
+ // be zero.
+ static uint32_t gDefaultFontID;
+
+ if (0 == gDefaultFontID) {
+ SkTypeface* defaultFace = SkFontHost::CreateTypeface(NULL, NULL,
+ SkTypeface::kNormal);
+ SkASSERT(defaultFace);
+ gDefaultFontID = defaultFace->uniqueID();
+ defaultFace->unref();
+ }
+ return gDefaultFontID;
}
-bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb)
-{
- return resolve_null_typeface(facea)->uniqueID() ==
- resolve_null_typeface(faceb)->uniqueID();
+bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
+ return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb);
}
///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkTypeface::Create(const char name[], Style style)
-{
- SkTypeface* face = SkFontHost::FindTypeface(NULL, name, style);
- face->ref();
- return face;
+SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
+ return SkFontHost::CreateTypeface(NULL, name, style);
}
-SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s)
-{
- family = resolve_null_typeface(family);
- SkTypeface* face = SkFontHost::FindTypeface(family, NULL, s);
- face->ref();
- return face;
+SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
+ return SkFontHost::CreateTypeface(family, NULL, s);
}
-SkTypeface* SkTypeface::CreateFromStream(SkStream* stream)
-{
- return SkFontHost::CreateTypeface(stream);
+SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) {
+ return SkFontHost::CreateTypefaceFromStream(stream);
}
-SkTypeface* SkTypeface::CreateFromFile(const char path[])
-{
+SkTypeface* SkTypeface::CreateFromFile(const char path[]) {
return SkFontHost::CreateTypefaceFromFile(path);
}
diff --git a/src/core/SkUtils.cpp b/src/core/SkUtils.cpp
index a4c6c16..edc5b74 100644
--- a/src/core/SkUtils.cpp
+++ b/src/core/SkUtils.cpp
@@ -458,126 +458,3 @@ SkAutoMemoryUsageProbe::~SkAutoMemoryUsageProbe()
#endif
}
-////////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-#include "SkRandom.h"
-#include "SkTSearch.h"
-#include "SkTSort.h"
-
-#define kSEARCH_COUNT 91
-
-#ifdef SK_SUPPORT_UNITTEST
-static void test_search()
-{
- int i, array[kSEARCH_COUNT];
- SkRandom rand;
-
- for (i = 0; i < kSEARCH_COUNT; i++)
- array[i] = rand.nextS();
-
- SkTHeapSort<int>(array, kSEARCH_COUNT);
- // make sure we got sorted properly
- for (i = 1; i < kSEARCH_COUNT; i++)
- SkASSERT(array[i-1] <= array[i]);
-
- // make sure we can find all of our values
- for (i = 0; i < kSEARCH_COUNT; i++)
- {
- int index = SkTSearch<int>(array, kSEARCH_COUNT, array[i], sizeof(int));
- SkASSERT(index == i);
- }
-
- // make sure that random values are either found, or the correct
- // insertion index is returned
- for (i = 0; i < 10000; i++)
- {
- int value = rand.nextS();
- int index = SkTSearch<int>(array, kSEARCH_COUNT, value, sizeof(int));
-
- if (index >= 0)
- SkASSERT(index < kSEARCH_COUNT && array[index] == value);
- else
- {
- index = ~index;
- SkASSERT(index <= kSEARCH_COUNT);
- if (index < kSEARCH_COUNT)
- {
- SkASSERT(value < array[index]);
- if (index > 0)
- SkASSERT(value > array[index - 1]);
- }
- else // we should append the new value
- {
- SkASSERT(value > array[kSEARCH_COUNT - 1]);
- }
- }
- }
-}
-
-static void test_utf16()
-{
- static const SkUnichar gUni[] = {
- 0x10000, 0x18080, 0x20202, 0xFFFFF, 0x101234
- };
-
- uint16_t buf[2];
-
- for (unsigned i = 0; i < SK_ARRAY_COUNT(gUni); i++)
- {
- size_t count = SkUTF16_FromUnichar(gUni[i], buf);
- SkASSERT(count == 2);
- size_t count2 = SkUTF16_CountUnichars(buf, 2);
- SkASSERT(count2 == 1);
- const uint16_t* ptr = buf;
- SkUnichar c = SkUTF16_NextUnichar(&ptr);
- SkASSERT(c == gUni[i]);
- SkASSERT(ptr - buf == 2);
- }
-}
-
-#endif
-
-void SkUtils::UnitTest()
-{
-#ifdef SK_SUPPORT_UNITTEST
- static const struct {
- const char* fUtf8;
- SkUnichar fUni;
- } gTest[] = {
- { "a", 'a' },
- { "\x7f", 0x7f },
- { "\xC2\x80", 0x80 },
- { "\xC3\x83", (3 << 6) | 3 },
- { "\xDF\xBF", 0x7ff },
- { "\xE0\xA0\x80", 0x800 },
- { "\xE0\xB0\xB8", 0xC38 },
- { "\xE3\x83\x83", (3 << 12) | (3 << 6) | 3 },
- { "\xEF\xBF\xBF", 0xFFFF },
- { "\xF0\x90\x80\x80", 0x10000 },
- { "\xF3\x83\x83\x83", (3 << 18) | (3 << 12) | (3 << 6) | 3 }
- };
-
- for (unsigned i = 0; i < SK_ARRAY_COUNT(gTest); i++)
- {
- const char* p = gTest[i].fUtf8;
- int n = SkUTF8_CountUnichars(p);
- SkUnichar u0 = SkUTF8_ToUnichar(gTest[i].fUtf8);
- SkUnichar u1 = SkUTF8_NextUnichar(&p);
-
- SkASSERT(n == 1);
- SkASSERT(u0 == u1);
- SkASSERT(u0 == gTest[i].fUni);
- SkASSERT(p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8));
- }
-
- test_utf16();
-
- test_search();
-#endif
-}
-
-#endif
-
-
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index 80bafce..7c336c2 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -344,21 +344,24 @@ static SkPMColor dst_modeproc(SkPMColor src, SkPMColor dst) {
return dst;
}
-// kSrcOver_Mode, //!< [Sa + (1 - Sa)*Da, Sc + (1 - Sa)*Dc]
+// kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Sc + (1 - Sa)*Dc]
static SkPMColor srcover_modeproc(SkPMColor src, SkPMColor dst) {
+#if 0
+ // this is the old, more-correct way, but it doesn't guarantee that dst==255
+ // will always stay opaque
return src + SkAlphaMulQ(dst, SkAlpha255To256(255 - SkGetPackedA32(src)));
+#else
+ // this is slightly faster, but more importantly guarantees that dst==255
+ // will always stay opaque
+ return src + SkAlphaMulQ(dst, 256 - SkGetPackedA32(src));
+#endif
}
-// kDstOver_Mode, //!< [Sa + (1 - Sa)*Da, Dc + (1 - Da)*Sc]
+// kDstOver_Mode, //!< [Sa + Da - Sa*Da, Dc + (1 - Da)*Sc]
static SkPMColor dstover_modeproc(SkPMColor src, SkPMColor dst) {
- unsigned sa = SkGetPackedA32(src);
- unsigned da = SkGetPackedA32(dst);
- unsigned ida = 255 - da;
-
- return SkPackARGB32(sa + da - SkAlphaMulAlpha(sa, da),
- SkGetPackedR32(dst) + SkAlphaMulAlpha(ida, SkGetPackedR32(src)),
- SkGetPackedG32(dst) + SkAlphaMulAlpha(ida, SkGetPackedG32(src)),
- SkGetPackedB32(dst) + SkAlphaMulAlpha(ida, SkGetPackedB32(src)));
+ // this is the reverse of srcover, just flipping src and dst
+ // see srcover's comment about the 256 for opaqueness guarantees
+ return dst + SkAlphaMulQ(src, 256 - SkGetPackedA32(dst));
}
// kSrcIn_Mode, //!< [Sa * Da, Sc * Da]
diff --git a/src/ports/SkFontHost_FONTPATH.cpp b/src/ports/SkFontHost_FONTPATH.cpp
index 84ff664..ceab395 100644
--- a/src/ports/SkFontHost_FONTPATH.cpp
+++ b/src/ports/SkFontHost_FONTPATH.cpp
@@ -239,9 +239,9 @@ static uint32_t ptr2uint32(const void* p)
return (uint32_t)((char*)p - (char*)0);
}
-SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
- const char familyName[],
- SkTypeface::Style style)
+SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
+ const char familyName[],
+ SkTypeface::Style style)
{
const FontFamilyRec* family;
@@ -268,7 +268,7 @@ SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
return SkNEW_ARGS(FontFaceRec_Typeface, (face));
}
-SkTypeface* SkFontHost::CreateTypeface(SkStream* stream) {
+SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
sk_throw(); // not implemented
return NULL;
}
@@ -278,10 +278,8 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
return NULL;
}
-SkTypeface* SkFontHost::ResolveTypeface(uint32_t fontID) {
- // TODO: this should just return a bool if fontID is valid
- // since we don't keep a global-list, this will leak at the moment
- return new FontFaceRec_Typeface(*get_default_face());
+bool SkFontHost::ValidFontID(uint32_t fontID) {
+ return get_id(*get_default_face()) == fontID;
}
SkStream* SkFontHost::OpenStream(uint32_t fontID) {
@@ -289,10 +287,6 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) {
return NULL;
}
-void SkFontHost::CloseStream(uint32_t fontID, SkStream* stream) {
- // not implemented
-}
-
void SkFontHost::Serialize(const SkTypeface* tface, SkWStream* stream) {
const FontFaceRec* face = &((const FontFaceRec_Typeface*)tface)->fFace;
stream->write(face, sizeof(face));
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 742a861..a241e38 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -102,9 +102,10 @@ struct SkFaceRec {
uint32_t fRefCnt;
uint32_t fFontID;
+ // assumes ownership of the stream, will call unref() when its done
SkFaceRec(SkStream* strm, uint32_t fontID);
~SkFaceRec() {
- SkFontHost::CloseStream(fFontID, fSkStream);
+ fSkStream->unref();
}
};
@@ -387,7 +388,7 @@ FT_Error SkScalerContext_FreeType::setupSize() {
killing all of the contexts when we know that a given fontID is going
away...
*/
- if (SkFontHost::ResolveTypeface(fRec.fFontID) == NULL) {
+ if (!SkFontHost::ValidFontID(fRec.fFontID)) {
return (FT_Error)-1;
}
diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp
index 1cd2e3b..67c78fb 100644
--- a/src/ports/SkFontHost_android.cpp
+++ b/src/ports/SkFontHost_android.cpp
@@ -127,7 +127,10 @@ static FamilyRec* find_family(const SkTypeface* member)
return NULL;
}
-static SkTypeface* resolve_uniqueID(uint32_t uniqueID)
+/* Returns the matching typeface, or NULL. If a typeface is found, its refcnt
+ is not modified.
+ */
+static SkTypeface* find_from_uniqueID(uint32_t uniqueID)
{
FamilyRec* curr = gFamilyHead;
while (curr != NULL) {
@@ -275,7 +278,6 @@ public:
bool isSysFont() const { return fIsSysFont; }
virtual SkStream* openStream() = 0;
- virtual void closeStream(SkStream*) = 0;
virtual const char* getUniqueString() const = 0;
private:
@@ -292,16 +294,21 @@ public:
SkStream* stream)
: INHERITED(style, sysFont, familyMember)
{
+ SkASSERT(stream);
+ stream->ref();
fStream = stream;
}
- virtual ~StreamTypeface()
- {
- SkDELETE(fStream);
+ virtual ~StreamTypeface() {
+ fStream->unref();
}
// overrides
- virtual SkStream* openStream() { return fStream; }
- virtual void closeStream(SkStream*) {}
+ virtual SkStream* openStream() {
+ // we just ref our existing stream, since the caller will call unref()
+ // when they are through
+ fStream->ref();
+ return fStream;
+ }
virtual const char* getUniqueString() const { return NULL; }
private:
@@ -342,10 +349,6 @@ public:
}
return stream;
}
- virtual void closeStream(SkStream* stream)
- {
- SkDELETE(stream);
- }
virtual const char* getUniqueString() const {
const char* str = strrchr(fPath.c_str(), '/');
if (str) {
@@ -495,7 +498,7 @@ static void load_system_fonts()
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
const char* name = ((FamilyTypeface*)face)->getUniqueString();
- stream->write8((uint8_t)face->getStyle());
+ stream->write8((uint8_t)face->style());
if (NULL == name || 0 == *name) {
stream->writePackedUInt(0);
@@ -504,7 +507,7 @@ void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
uint32_t len = strlen(name);
stream->writePackedUInt(len);
stream->write(name, len);
-// SkDebugf("--- fonthost serialize <%s> %d\n", name, face->getStyle());
+// SkDebugf("--- fonthost serialize <%s> %d\n", name, face->style());
}
}
@@ -525,21 +528,21 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
// backup until we hit the fNames
for (int j = i; j >= 0; --j) {
if (rec[j].fNames != NULL) {
- return SkFontHost::FindTypeface(NULL, rec[j].fNames[0],
- (SkTypeface::Style)style);
+ return SkFontHost::CreateTypeface(NULL,
+ rec[j].fNames[0], (SkTypeface::Style)style);
}
}
}
}
}
- return SkFontHost::FindTypeface(NULL, NULL, (SkTypeface::Style)style);
+ return SkFontHost::CreateTypeface(NULL, NULL, (SkTypeface::Style)style);
}
///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
- const char familyName[],
- SkTypeface::Style style)
+SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
+ const char familyName[],
+ SkTypeface::Style style)
{
load_system_fonts();
@@ -561,37 +564,32 @@ SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
tf = find_best_face(gDefaultFamily, style);
}
+ // we ref(), since the symantic is to return a new instance
+ tf->ref();
return tf;
}
-SkTypeface* SkFontHost::ResolveTypeface(uint32_t fontID)
+bool SkFontHost::ValidFontID(uint32_t fontID)
{
SkAutoMutexAcquire ac(gFamilyMutex);
- return resolve_uniqueID(fontID);
+ return find_from_uniqueID(fontID) != NULL;
}
SkStream* SkFontHost::OpenStream(uint32_t fontID)
{
+ SkAutoMutexAcquire ac(gFamilyMutex);
- FamilyTypeface* tf = (FamilyTypeface*)SkFontHost::ResolveTypeface(fontID);
+ FamilyTypeface* tf = (FamilyTypeface*)find_from_uniqueID(fontID);
SkStream* stream = tf ? tf->openStream() : NULL;
- if (NULL == stream || stream->getLength() == 0) {
- delete stream;
+ if (stream && stream->getLength() == 0) {
+ stream->unref();
stream = NULL;
}
return stream;
}
-void SkFontHost::CloseStream(uint32_t fontID, SkStream* stream)
-{
- FamilyTypeface* tf = (FamilyTypeface*)SkFontHost::ResolveTypeface(fontID);
- if (NULL != tf) {
- tf->closeStream(stream);
- }
-}
-
SkScalerContext* SkFontHost::CreateFallbackScalerContext(
const SkScalerContext::Rec& rec)
{
@@ -612,10 +610,9 @@ SkScalerContext* SkFontHost::CreateFallbackScalerContext(
///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkFontHost::CreateTypeface(SkStream* stream)
+SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream)
{
if (NULL == stream || stream->getLength() <= 0) {
- SkDELETE(stream);
return NULL;
}
@@ -627,7 +624,11 @@ SkTypeface* SkFontHost::CreateTypeface(SkStream* stream)
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[])
{
- return SkFontHost::CreateTypeface(SkNEW_ARGS(SkMMAPStream, (path)));
+ SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path));
+ SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream);
+ // since we created the stream, we let go of our ref() here
+ stream->unref();
+ return face;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index 75d4cba..0c69126 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -86,8 +86,7 @@ struct FamilyRec {
};
static SkTypeface* find_best_face(const FamilyRec* family,
- SkTypeface::Style style)
-{
+ SkTypeface::Style style) {
SkTypeface* const* faces = family->fFaces;
if (faces[style] != NULL) { // exact match
@@ -113,8 +112,7 @@ static SkTypeface* find_best_face(const FamilyRec* family,
return NULL;
}
-static FamilyRec* find_family(const SkTypeface* member)
-{
+static FamilyRec* find_family(const SkTypeface* member) {
FamilyRec* curr = gFamilyHead;
while (curr != NULL) {
for (int i = 0; i < 4; i++) {
@@ -127,26 +125,24 @@ static FamilyRec* find_family(const SkTypeface* member)
return NULL;
}
-static SkTypeface* resolve_uniqueID(uint32_t uniqueID)
-{
+static bool valid_uniqueID(uint32_t uniqueID) {
FamilyRec* curr = gFamilyHead;
while (curr != NULL) {
for (int i = 0; i < 4; i++) {
SkTypeface* face = curr->fFaces[i];
if (face != NULL && face->uniqueID() == uniqueID) {
- return face;
+ return true;
}
}
curr = curr->fNext;
}
- return NULL;
+ return false;
}
/* Remove reference to this face from its family. If the resulting family
is empty (has no faces), return that family, otherwise return NULL
*/
-static FamilyRec* remove_from_family(const SkTypeface* face)
-{
+static FamilyRec* remove_from_family(const SkTypeface* face) {
FamilyRec* family = find_family(face);
SkASSERT(family->fFaces[face->style()] == face);
family->fFaces[face->style()] = NULL;
@@ -160,8 +156,7 @@ static FamilyRec* remove_from_family(const SkTypeface* face)
}
// maybe we should make FamilyRec be doubly-linked
-static void detach_and_delete_family(FamilyRec* family)
-{
+static void detach_and_delete_family(FamilyRec* family) {
FamilyRec* curr = gFamilyHead;
FamilyRec* prev = NULL;
@@ -195,14 +190,12 @@ static SkTypeface* find_typeface(const char name[], SkTypeface::Style style) {
}
static SkTypeface* find_typeface(const SkTypeface* familyMember,
- SkTypeface::Style style)
-{
+ SkTypeface::Style style) {
const FamilyRec* family = find_family(familyMember);
return family ? find_best_face(family, style) : NULL;
}
-static void add_name(const char name[], FamilyRec* family)
-{
+static void add_name(const char name[], FamilyRec* family) {
SkAutoAsciiToLC tolc(name);
name = tolc.lc();
@@ -217,8 +210,7 @@ static void add_name(const char name[], FamilyRec* family)
}
}
-static void remove_from_names(FamilyRec* emptyFamily)
-{
+static void remove_from_names(FamilyRec* emptyFamily) {
#ifdef SK_DEBUG
for (int i = 0; i < 4; i++) {
SkASSERT(emptyFamily->fFaces[i] == NULL);
@@ -242,8 +234,7 @@ static void remove_from_names(FamilyRec* emptyFamily)
class FamilyTypeface : public SkTypeface {
public:
FamilyTypeface(Style style, bool sysFont, FamilyRec* family)
- : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1)
- {
+ : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1) {
fIsSysFont = sysFont;
SkAutoMutexAcquire ac(gFamilyMutex);
@@ -255,8 +246,7 @@ public:
fFamilyRec = family; // just record it so we can return it if asked
}
- virtual ~FamilyTypeface()
- {
+ virtual ~FamilyTypeface() {
SkAutoMutexAcquire ac(gFamilyMutex);
// remove us from our family. If the family is now empty, we return
@@ -288,12 +278,10 @@ class StreamTypeface : public FamilyTypeface {
public:
StreamTypeface(Style style, bool sysFont, FamilyRec* family,
SkStream* stream)
- : INHERITED(style, sysFont, family)
- {
+ : INHERITED(style, sysFont, family) {
fStream = stream;
}
- virtual ~StreamTypeface()
- {
+ virtual ~StreamTypeface() {
SkDELETE(fStream);
}
@@ -355,8 +343,7 @@ private:
///////////////////////////////////////////////////////////////////////////////
static bool get_name_and_style(const char path[], SkString* name,
- SkTypeface::Style* style)
-{
+ SkTypeface::Style* style) {
SkMMAPStream stream(path);
if (stream.getLength() > 0) {
*style = find_name_and_style(&stream, name);
@@ -379,8 +366,7 @@ static SkTypeface* gFallBackTypeface;
static FamilyRec* gDefaultFamily;
static SkTypeface* gDefaultNormal;
-static void load_system_fonts()
-{
+static void load_system_fonts() {
// check if we've already be called
if (NULL != gDefaultNormal) {
return;
@@ -490,14 +476,14 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
// backup until we hit the fNames
for (int j = i; j >= 0; --j) {
if (rec[j].fNames != NULL) {
- return SkFontHost::FindTypeface(NULL, rec[j].fNames[0],
- (SkTypeface::Style)style);
+ return SkFontHost::CreateTypeface(NULL, rec[j].fNames[0],
+ (SkTypeface::Style)style);
}
}
}
}
}
- return SkFontHost::FindTypeface(NULL, NULL, (SkTypeface::Style)style);
+ return SkFontHost::CreateTypeface(NULL, NULL, (SkTypeface::Style)style);
#endif
sk_throw();
return NULL;
@@ -505,10 +491,9 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
- const char familyName[],
- SkTypeface::Style style)
-{
+SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
+ const char familyName[],
+ SkTypeface::Style style) {
load_system_fonts();
SkAutoMutexAcquire ac(gFamilyMutex);
@@ -532,16 +517,13 @@ SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
return tf;
}
-SkTypeface* SkFontHost::ResolveTypeface(uint32_t fontID)
-{
+SkTypeface* SkFontHost::ValidFontID(uint32_t fontID) {
SkAutoMutexAcquire ac(gFamilyMutex);
- return resolve_uniqueID(fontID);
+ return valid_uniqueID(fontID);
}
-SkStream* SkFontHost::OpenStream(uint32_t fontID)
-{
-
+SkStream* SkFontHost::OpenStream(uint32_t fontID) {
FamilyTypeface* tf = (FamilyTypeface*)SkFontHost::ResolveTypeface(fontID);
SkStream* stream = tf ? tf->openStream() : NULL;
@@ -552,8 +534,7 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID)
return stream;
}
-void SkFontHost::CloseStream(uint32_t fontID, SkStream* stream)
-{
+void SkFontHost::CloseStream(uint32_t fontID, SkStream* stream) {
FamilyTypeface* tf = (FamilyTypeface*)SkFontHost::ResolveTypeface(fontID);
if (NULL != tf) {
tf->closeStream(stream);
@@ -561,8 +542,7 @@ void SkFontHost::CloseStream(uint32_t fontID, SkStream* stream)
}
SkScalerContext* SkFontHost::CreateFallbackScalerContext(
- const SkScalerContext::Rec& rec)
-{
+ const SkScalerContext::Rec& rec) {
load_system_fonts();
SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1));
@@ -580,8 +560,7 @@ SkScalerContext* SkFontHost::CreateFallbackScalerContext(
///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkFontHost::CreateTypeface(SkStream* stream)
-{
+SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
if (NULL == stream || stream->getLength() <= 0) {
SkDELETE(stream);
return NULL;
@@ -593,15 +572,20 @@ SkTypeface* SkFontHost::CreateTypeface(SkStream* stream)
return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream));
}
-SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[])
-{
+SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
+ SkTypeface* face = NULL;
+ SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path));
+
+ if (stream->isValid()) {
+ return CreateTypeface(stream);
+ }
+ stream->unref();
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
-size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar)
-{
+size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) {
if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET)
return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET;
else
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 969808e..f0e3a93 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -484,7 +484,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
return NULL;
}
-SkTypeface* SkFontHost::CreateTypeface(SkStream* stream) {
+SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
//Should not be used on Mac, keep linker happy
SkASSERT(false);
@@ -517,17 +517,8 @@ SkScalerContext* SkFontHost::CreateFallbackScalerContext(const SkScalerContext::
return SkFontHost::CreateScalerContext(desc);
}
-
- /** Return the closest matching typeface given either an existing family
- (specified by a typeface in that family) or by a familyName, and a
- requested style.
- 1) If familyFace is null, use famillyName.
- 2) If famillyName is null, use familyFace.
- 3) If both are null, return the default font that best matches style
- This MUST not return NULL.
- */
-
-SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace, const char familyName[], SkTypeface::Style style) {
+SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
+ const char familyName[], SkTypeface::Style style) {
SkAutoMutexAcquire ac(gFTMutex);
diff --git a/src/ports/SkFontHost_none.cpp b/src/ports/SkFontHost_none.cpp
index 09854ae..608ee29 100644
--- a/src/ports/SkFontHost_none.cpp
+++ b/src/ports/SkFontHost_none.cpp
@@ -15,34 +15,32 @@
#include "SkFontHost.h"
-SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
+SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
const char famillyName[],
SkTypeface::Style style) {
SkASSERT(!"SkFontHost::FindTypeface unimplemented");
return NULL;
}
-SkTypeface* SkFontHost::ResolveTypeface(uint32_t uniqueID) {
- SkASSERT(!"SkFontHost::ResolveTypeface unimplemented");
+SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream*) {
+ SkASSERT(!"SkFontHost::CreateTypeface unimplemented");
return NULL;
}
-SkStream* SkFontHost::OpenStream(uint32_t uniqueID) {
- SkASSERT(!"SkFontHost::OpenStream unimplemented");
+SkTypeface* SkFontHost::CreateTypefaceFromFile(char const*) {
+ SkASSERT(!"SkFontHost::CreateTypefaceFromFile unimplemented");
return NULL;
}
-void SkFontHost::CloseStream(uint32_t uniqueID, SkStream*) {
- SkASSERT(!"SkFontHost::CloseStream unimplemented");
-}
+///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkFontHost::CreateTypeface(SkStream*) {
- SkASSERT(!"SkFontHost::CreateTypeface unimplemented");
- return NULL;
+bool SkFontHost::ValidFontID(uint32_t uniqueID) {
+ SkASSERT(!"SkFontHost::ResolveTypeface unimplemented");
+ return false;
}
-SkTypeface* SkFontHost::CreateTypefaceFromFile(char const*) {
- SkASSERT(!"SkFontHost::CreateTypefaceFromFile unimplemented");
+SkStream* SkFontHost::OpenStream(uint32_t uniqueID) {
+ SkASSERT(!"SkFontHost::OpenStream unimplemented");
return NULL;
}
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index c2ee51e..4cc04b5 100644
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -482,7 +482,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
return NULL;
}
-SkTypeface* SkFontHost::CreateTypeface(SkStream* stream) {
+SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
//Should not be used on Windows, keep linker happy
SkASSERT(false);
@@ -521,7 +521,8 @@ SkScalerContext* SkFontHost::CreateFallbackScalerContext(const SkScalerContext::
This MUST not return NULL.
*/
-SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace, const char familyName[], SkTypeface::Style style) {
+SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
+ const char familyName[], SkTypeface::Style style) {
SkAutoMutexAcquire ac(gFTMutex);