add typefacecache
speedup lcd blits
clean up some samples
git-svn-id: http://skia.googlecode.com/svn/trunk@1220 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index 17b2829..f57bf38 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -343,23 +343,9 @@
#endif
}
-static void test_math()
-{
- float x;
- const float PI = 3.141593f;
-
- for (x = 0; x < 1; x += 0.05f)
- printf("atan(%g) = %g\n", x, atanf(x) * 180/PI);
- for (x = 1; x < 10000000; x *= 2)
- printf("atan(%g) = %g\n", x, atanf(x) * 180/PI);
-}
-
class DemoView : public SkView {
public:
- DemoView()
- {
- test_math();
- }
+ DemoView() {}
protected:
// overrides from SkEventSink
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 88c7f4b..266264e 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -1337,12 +1337,34 @@
return this->INHERITED::onQuery(evt);
}
+#define TEST_GPIPEx
+#include "SkGPipe.h"
+
void SampleView::onDraw(SkCanvas* canvas) {
this->onDrawBackground(canvas);
+
+#ifdef TEST_GPIPE
+ SkGPipeWriter writer;
+ SkCanvas* origCanvas = canvas;
+ canvas = writer.startRecording();
+#endif
+
for (int i = 0; i < fRepeatCount; i++) {
SkAutoCanvasRestore acr(canvas, true);
this->onDrawContent(canvas);
}
+
+#ifdef TEST_GPIPE
+ writer.endRecording();
+
+ size_t size = writer.flatten(NULL);
+ SkAutoMalloc storage(size);
+ writer.flatten(storage.get());
+
+ SkGPipeReader reader(origCanvas);
+ SkGPipeReader::Status status = reader.playback(storage.get(), size);
+ SkASSERT(SkGPipeReader::kDone_Status == status);
+#endif
}
void SampleView::onDrawBackground(SkCanvas* canvas) {
diff --git a/samplecode/SampleDraw.cpp b/samplecode/SampleDraw.cpp
index 39a64cf..54070d1 100644
--- a/samplecode/SampleDraw.cpp
+++ b/samplecode/SampleDraw.cpp
@@ -4,6 +4,30 @@
#include "SkGraphics.h"
#include "SkRandom.h"
+static void test_clearonlayers(SkCanvas* canvas) {
+ SkCanvas& c = *canvas;
+
+ SkPaint paint;
+ paint.setColor(SK_ColorBLUE);
+ paint.setStyle(SkPaint::kStrokeAndFill_Style);
+ SkRect rect = SkRect::MakeXYWH(25, 25, 50, 50);
+ c.drawRect(rect, paint);
+
+ c.clipRect(rect);
+
+ c.saveLayer(NULL, NULL);
+ rect = SkRect::MakeXYWH(50, 10, 40, 80);
+ c.clipRect(rect, SkRegion::kUnion_Op);
+
+ rect = SkRect::MakeXYWH(50, 0, 50, 100);
+ // You might draw something here, but it's not necessary.
+ // paint.setColor(SK_ColorRED);
+ // c.drawRect(rect, paint);
+ paint.setXfermodeMode(SkXfermode::kClear_Mode);
+ c.drawRect(rect, paint);
+ c.restore();
+}
+
static void test_strokerect(SkCanvas* canvas, const SkRect& r) {
SkPaint p;
@@ -277,8 +301,8 @@
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
- // test_strokerect(canvas);
- // return;
+ test_clearonlayers(canvas); return;
+ // test_strokerect(canvas); return;
for (Draw** iter = fList.begin(); iter < fList.end(); iter++) {
(*iter)->draw(canvas);
diff --git a/samplecode/SampleFontScalerTest.cpp b/samplecode/SampleFontScalerTest.cpp
index c481503..0b0d349 100644
--- a/samplecode/SampleFontScalerTest.cpp
+++ b/samplecode/SampleFontScalerTest.cpp
@@ -29,7 +29,7 @@
static const int gFaceCount = SK_ARRAY_COUNT(gFaces);
-class FontScalerTestView : public SkView {
+class FontScalerTestView : public SampleView {
SkTypeface* fFaces[gFaceCount];
public:
@@ -38,6 +38,7 @@
fFaces[i] = SkTypeface::CreateFromName(gFaces[i].fName,
gFaces[i].fStyle);
}
+ this->setBGColor(0xFFDDDDDD);
}
virtual ~FontScalerTestView() {
@@ -56,13 +57,7 @@
return this->INHERITED::onQuery(evt);
}
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
- virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
+ virtual void onDrawContent(SkCanvas* canvas) {
SkPaint paint;
// test handling of obscene cubic values (currently broken)
diff --git a/samplecode/SampleLines.cpp b/samplecode/SampleLines.cpp
index 4d05a9a..24291f3 100644
--- a/samplecode/SampleLines.cpp
+++ b/samplecode/SampleLines.cpp
@@ -25,30 +25,7 @@
class LinesView : public SkView {
public:
- LinesView()
- {
- unsigned r = 0x1F;
- unsigned g = 0x3F;
- for (unsigned a = 0; a <= 0xF; a++) {
- unsigned scale = 16 - SkAlpha15To16(a);
- unsigned sr = (a << 1) | (a >> 3);
- unsigned dr = r * scale >> 4;
- unsigned sg = (a << 2) | (a >> 2);
- unsigned dg = g * scale >> 4;
-
- unsigned ssg = sg & ~(~(a >> 3) & 1);
-
- printf("4444 sa=%d sr=%d sg=%d da=%d dr=%d dg=%d total-r=%d total-g=%d %d\n",
- a, sr, sg, scale, dr, dg, sr+dr, sg+dg, ssg+dg);
- }
-
- for (unsigned aa = 0; aa <= 0xFF; aa++) {
- unsigned invScale = SkAlpha255To256(255 - aa);
- unsigned dst = SkAlphaMul(0xFF, invScale);
- printf("8888 sa=%02x dst=%02x sum=%d %s\n", aa, dst, aa+dst,
- (aa+dst) > 0xFF ? "OVERFLOW" : "");
- }
- }
+ LinesView() {}
protected:
// overrides from SkEventSink
diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp
index 6c018b7..00a9d2e 100644
--- a/samplecode/SamplePicture.cpp
+++ b/samplecode/SamplePicture.cpp
@@ -33,7 +33,7 @@
protected:
virtual void onDraw(SkCanvas* canvas) {
- SkDebugf("---- sc %d\n", canvas->getSaveCount() - 1);
+ // SkDebugf("---- sc %d\n", canvas->getSaveCount() - 1);
}
private:
diff --git a/samplecode/SamplePolyToPoly.cpp b/samplecode/SamplePolyToPoly.cpp
index 4b6686d..ccfe430 100644
--- a/samplecode/SamplePolyToPoly.cpp
+++ b/samplecode/SamplePolyToPoly.cpp
@@ -19,7 +19,6 @@
bool success;
success = m1.setPolyToPoly(src, dst, 3);
- SkDebugf("--- setPolyToPoly1 %d\n", success);
m2.reset();
m2.set(SkMatrix::kMScaleX, dst[1].fX - dst[0].fX);
@@ -40,7 +39,6 @@
};
success = m2.setPolyToPoly((const SkPoint*)src1, (SkPoint*)dst1, 4);
- SkDebugf("--- setPolyToPoly2 %d\n", success);
{
const SkPoint src[] = {
@@ -57,8 +55,8 @@
SkMatrix m0, m1;
m0.setPolyToPoly(src, dst, 3);
// SkSetPoly3To3(&m1, src, dst);
- m0.dump();
- m1.dump();
+ // m0.dump();
+ // m1.dump();
}
}
}
diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp
index c1090ee..459923a 100644
--- a/samplecode/SampleText.cpp
+++ b/samplecode/SampleText.cpp
@@ -138,7 +138,7 @@
mm = m;
}
- int length2 = paint.breakText(text, length, width, &mm);
+ SkDEBUGCODE(int length2 =) paint.breakText(text, length, width, &mm);
SkASSERT(length2 == length);
SkASSERT(mm == width);
}
@@ -222,12 +222,6 @@
{ "Subpixel", SkPaint::kSubpixelText_Flag, true }
};
-#ifdef SK_DEBUG
- #define REPEAT_COUNT 1
-#else
- #define REPEAT_COUNT 5
-#endif
-
static int count_char_points(const SkPaint& paint, char c)
{
SkPath path;
@@ -488,210 +482,8 @@
virtual void onDraw(SkCanvas* canvas)
{
- inval(NULL);
- if (false)
- {
- canvas->translate(SkIntToScalar(480), 0);
- canvas->rotate(SkIntToScalar(90));
- }
-
this->drawBG(canvas);
- if (false)
- {
- SkPaint p;
-
- p.setAntiAlias(true);
- p.setSubpixelText(true);
- // p.setLinearText(true);
-
- SkScalar size = SkIntToScalar(6);
- SkMSec dur = 0;
- const int LOOP = 16;
- const int TIMES = 10;
-
- for (int times = 0; times < TIMES; times++)
- {
- SkMSec now = SkTime::GetMSecs();
- for (int loop = 0; loop < LOOP; loop++)
- {
- p.setTextSize(size);
- size += SK_Scalar1/5;
- canvas->drawText("Hamburgefons", 12, SkIntToScalar(10), SkIntToScalar(50), p);
- }
- dur += SkTime::GetMSecs() - now;
- SkGraphics::SetFontCacheUsed(0);
- }
-
- printf("----- duration = %g\n", dur * 1.0 / TIMES);
- this->inval(NULL);
- return;
- }
-
- if (false)
- {
- SkPaint p;
- p.setAntiAlias(true);
- for (int i = 6; i <= 36; i++)
- {
- SkRect r;
- SkPaint::FontMetrics m;
- p.setTextSize(SkIntToScalar(i));
- p.getFontMetrics(&m);
- int ascent = SkScalarRound(m.fAscent);
- int descent = SkScalarRound(m.fDescent);
- for (uint8_t c = ' '; c <= 127; c++)
- {
- p.getTextWidths(&c, 1, NULL, &r);
- if (SkScalarRound(r.fTop) < ascent)
- printf("PS %d --- %c [%d] top=%g, ascent=%g ymax=%g\n", i, c, c,
- SkScalarToFloat(r.fTop), SkScalarToFloat(m.fAscent), SkScalarToFloat(m.fTop));
- if (SkScalarRound(r.fBottom) > descent)
- printf("PS %d --- %c [%d] bottom=%g, descent=%g ymin=%g\n", i, c, c,
- SkScalarToFloat(r.fBottom), SkScalarToFloat(m.fDescent), SkScalarToFloat(m.fBottom));
- }
- }
- }
-
- if (false)
- {
- SkPaint p;
- p.setShader(fGradient);
-
-#ifdef SK_RELEASE
- SkMSec now = SkTime::GetMSecs();
- for (int i = 0; i < 100; i++)
-#endif
- canvas->drawPaint(p);
-#ifdef SK_RELEASE
- printf("----- %d ms\n", SkTime::GetMSecs() - now);
- this->inval(NULL);
-#endif
- return;
- }
-
- if (false)
- {
- SkBitmap bm;
-
- make_textstrip(&bm);
- canvas->translate(0, SkIntToScalar(50));
- for (int i = 0; i < 10; i++)
- {
- float gamma = 1 + i * 0.2f;
- SkPowerMode mode(SkFloatToScalar(1 / gamma));
- SkPaint p;
- p.setXfermode(&mode);
-
- canvas->drawBitmap(bm, 0, SkIntToScalar(i) * bm.height(), &p);
- }
- return;
- }
-
- if (false)
- {
- SkPaint paint;
-
- paint.setAntiAlias(true);
- paint.setDevKernText(true);
- SkMSec now = SkTime::GetMSecs();
- for (int i = 0; i < 1000000; i++)
- {
- paint.measureText("Hamburgefons", 15, NULL, NULL);
- }
- printf("--------- measure %d\n", SkTime::GetMSecs() - now);
- this->inval(NULL);
- return;
- }
-
- if (false)
- {
- SkRegion rgn;
- SkPath path;
- SkPaint paint;
-
- // make_badrgn(&rgn, -2);
-
- if (false)
- {
- paint.setColor(SK_ColorBLUE);
- canvas->drawIRect(rgn.getBounds(), paint);
- }
- paint.setColor(SK_ColorRED);
- draw_rgn(rgn, canvas, paint);
-
- rgn.getBoundaryPath(&path);
- paint.setARGB(0x80, 0, 0, 0xFF);
- canvas->drawPath(path, paint);
- return;
- }
-
- if (false)
- {
- SkRect r = { SkIntToScalar(50), SkIntToScalar(50), SkIntToScalar(300), SkIntToScalar(300) };
- SkPaint p;
-
- p.setStyle(SkPaint::kStroke_Style);
- p.setAlpha(0x80);
- p.setStrokeWidth(SkIntToScalar(20));
- canvas->drawRect(r, p);
- }
-
- if (false)
- {
- SkPaint p;
- SkRect r = { SkIntToScalar(100), SkIntToScalar(100), SkIntToScalar(104), SkIntToScalar(104) };
- // r.offset(SK_ScalarHalf, SK_ScalarHalf);
- p.setStyle(SkPaint::kStroke_Style);
- p.setStrokeWidth(SK_Scalar1*2);
- // p.setAntiAliasOn(true);
- canvas->drawRect(r, p);
- return;
- }
-
- if (false)
- {
- Sk64 aa, bb;
- int64_t a = (int64_t)6062080 * -30596;
- int64_t b = (int64_t)4816896 * 57957;
- aa.setMul(6062080, -30596);
- bb.setMul(4816896, 57957);
-
- a += b;
- b = a >> 16;
-
-// SkFixed c = aa.addGetFixed(bb);
-
- printf("%d %d\n", (int)a, a >> 32);
-
- SkBitmap bm;
- SkPaint paint;
- SkScalar scale = SkFloatToScalar(0.5625f);
- SkScalar x = SkIntToScalar(100);
- SkScalar y = SkIntToScalar(100);
-
- //paint.setFilterType(SkPaint::kBilinear_FilterType);
-
- SkImageDecoder::DecodeFile("/app_web_browser.png", &bm);
-
- // canvas->drawBitmap(bm, x, y, paint);
- x += SkIntToScalar(100);
- canvas->save();
- canvas->translate(x, y);
- canvas->scale(SkIntToScalar(2)/1, SkIntToScalar(2)/1);
- canvas->translate(-x, -y);
- canvas->drawBitmap(bm, x, y, &paint);
- canvas->restore();
- x += SkIntToScalar(100);
- canvas->save();
- canvas->translate(x, y);
- canvas->scale(scale, scale);
- canvas->translate(-x, -y);
- // canvas->drawBitmap(bm, x, y, paint);
- canvas->restore();
- return;
- }
-
SkAutoCanvasRestore restore(canvas, false);
{
SkRect r;
@@ -713,10 +505,6 @@
paint.setAntiAlias(true);
paint.setFlags(paint.getFlags() | gHints[index].fFlags);
- SkMSec now = 0;
- if (REPEAT_COUNT > 1)
- now = SkTime::GetMSecs();
-
SkRect clip;
clip.set(SkIntToScalar(25), SkIntToScalar(34), SkIntToScalar(88), SkIntToScalar(155));
@@ -743,26 +531,17 @@
}
#endif
- for (int j = 0; j < REPEAT_COUNT; j++)
- {
- SkScalar y = SkIntToScalar(0);
- for (int i = 9; i <= 24; i++) {
- paint.setTextSize(SkIntToScalar(i) /*+ (gRand.nextU() & 0xFFFF)*/);
- for (SkScalar dx = 0; dx <= SkIntToScalar(3)/4; dx += SkIntToScalar(1) /* /4 */)
- {
- y += paint.getFontSpacing();
- DrawTheText(canvas, text, length, SkIntToScalar(20) + dx, y, paint, fClickX, fMF);
- }
- }
- if (gHints[index].fFlushCache) {
-// SkGraphics::SetFontCacheUsed(0);
+ SkScalar y = SkIntToScalar(0);
+ for (int i = 9; i <= 24; i++) {
+ paint.setTextSize(SkIntToScalar(i) /*+ (gRand.nextU() & 0xFFFF)*/);
+ for (SkScalar dx = 0; dx <= SkIntToScalar(3)/4; dx += SkIntToScalar(1) /* /4 */)
+ {
+ y += paint.getFontSpacing();
+ DrawTheText(canvas, text, length, SkIntToScalar(20) + dx, y, paint, fClickX, fMF);
}
}
-
- if (REPEAT_COUNT > 1)
- {
- printf("--------- FPS = %g\n", REPEAT_COUNT * 1000. / (SkTime::GetMSecs() - now));
- this->inval(NULL);
+ if (gHints[index].fFlushCache) {
+// SkGraphics::SetFontCacheUsed(0);
}
}
diff --git a/samplecode/SampleTypeface.cpp b/samplecode/SampleTypeface.cpp
index 5442e5f..63f1d5a 100644
--- a/samplecode/SampleTypeface.cpp
+++ b/samplecode/SampleTypeface.cpp
@@ -13,6 +13,7 @@
#include "SkColorPriv.h"
#include "SkColorFilter.h"
#include "SkDither.h"
+#include "SkTypefaceCache.h"
static int dither_4444(int x) {
return ((x << 1) - ((x >> 4 << 4) | (x >> 4))) >> 4;
@@ -82,6 +83,8 @@
for (int i = 0; i < gFaceCount; i++) {
SkSafeUnref(fFaces[i]);
}
+
+ SkTypefaceCache::Dump();
}
protected:
@@ -99,11 +102,6 @@
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(30));
- if (false) {
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(SkIntToScalar(1));
- }
-
const char* text = "Hamburgefons";
const size_t textLen = strlen(text);
@@ -111,50 +109,12 @@
SkScalar dy = paint.getFontMetrics(NULL);
SkScalar y = dy;
+ paint.setLinearText(true);
for (int i = 0; i < gFaceCount; i++) {
paint.setTypeface(fFaces[i]);
canvas->drawText(text, textLen, x, y, paint);
y += dy;
}
-
- SkRect r;
- if (false) {
- r.set(10, 10, 100, 100);
- paint.setStyle(SkPaint::kStrokeAndFill_Style);
- paint.setColor(SK_ColorBLUE);
- paint.setStrokeWidth(1);
- canvas->drawRect(r, paint);
- paint.setStrokeWidth(0);
- }
-
- if (false) {
- r.set(294912.75f, 294912.75f, 884738.25f, 884738.25f);
- canvas->scale(2.4414E-4f, 2.4414E-4f);
- paint.setStyle(SkPaint::kFill_Style);
- canvas->drawRect(r, paint);
- }
-
- if (false) {
- SkScalar rad = 90;
- SkScalar angle = 210;
- SkScalar cx = 150;
- SkScalar cy = 105;
- r.set(cx - rad, cy - rad, cx + rad, cy + rad);
- SkPath path;
- path.arcTo(r, angle, -(angle + 90), true);
- path.close();
-
- paint.setColor(SK_ColorRED);
- canvas->drawRect(path.getBounds(), paint);
- paint.setColor(SK_ColorBLUE);
- canvas->drawPath(path, paint);
-
- paint.setColor(SK_ColorGREEN);
- SkPoint pts[100];
- int count = path.getPoints(pts, 100);
- paint.setStrokeWidth(5);
- canvas->drawPoints(SkCanvas::kPoints_PointMode, count, pts, paint);
- }
}
private: