almost there on gm (need to fix image writes/reads/compares)
move SkAutoGraphics into SkGraphics.h
add [] operators to SkString
git-svn-id: http://skia.googlecode.com/svn/trunk@228 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/Makefile b/Makefile
index 91e92fd..4c5bc61 100644
--- a/Makefile
+++ b/Makefile
@@ -56,6 +56,7 @@
LINKER_OPTS += -lpng
DEFINES += -DSK_BUILD_FOR_UNIX
+ SRC_LIST += src/ports/SkFontHost_none.cpp
# these are our registry-based factories
SRC_LIST += src/images/SkImageDecoder_Factory.cpp
SRC_LIST += src/images/SkImageEncoder_Factory.cpp
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index f92277a..99bdbd7 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -152,16 +152,6 @@
return -1;
}
-class SkAutoGraphics {
-public:
- SkAutoGraphics() {
- SkGraphics::Init();
- }
- ~SkAutoGraphics() {
- SkGraphics::Term();
- }
-};
-
int main (int argc, char * const argv[]) {
SkAutoGraphics ag;
diff --git a/gm/gm.h b/gm/gm.h
index 23d98e1..ab92ff6 100644
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -10,7 +10,7 @@
namespace skiagm {
- static SkISize make_isize(int w, int h) {
+ static inline SkISize make_isize(int w, int h) {
SkISize sz;
sz.set(w, h);
return sz;
@@ -23,10 +23,20 @@
void draw(SkCanvas*);
SkISize getISize() { return this->onISize(); }
+ const char* shortName() {
+ if (fShortName.size() == 0) {
+ fShortName = this->onShortName();
+ }
+ return fShortName.c_str();
+ }
protected:
- virtual void onDraw(SkCanvas*) {}
- virtual SkISize onISize() { return make_isize(0, 0); }
+ virtual void onDraw(SkCanvas*) = 0;
+ virtual SkISize onISize() = 0;
+ virtual SkString onShortName() = 0;
+
+ private:
+ SkString fShortName;
};
typedef SkTRegistry<GM*, void*> GMRegistry;
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 2417881..62ac44e 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -1,5 +1,7 @@
-#include "SkGraphics.h"
#include "gm.h"
+#include "SkGraphics.h"
+#include "SkImageDecoder.h"
+#include "SkImageEncoder.h"
using namespace skiagm;
@@ -35,15 +37,24 @@
const GMRegistry* fReg;
};
-class SkAutoGraphics {
-public:
- SkAutoGraphics() {
- SkGraphics::Init();
+static SkString make_name(const char shortName[], const char configName[]) {
+ SkString name(shortName);
+ name.appendf("_%s", configName);
+ return name;
+}
+
+static SkString make_filename(const char path[], const SkString& name) {
+ SkString filename(path);
+ if (filename.size() && filename[filename.size() - 1] != '/') {
+ filename.append("/");
}
- ~SkAutoGraphics() {
- SkGraphics::Term();
- }
-};
+ filename.append(name);
+ return filename;
+}
+
+static void compare(const SkBitmap& target, const SkBitmap& base,
+ const SkString& name) {
+}
static const struct {
SkBitmap::Config fConfig;
@@ -59,12 +70,32 @@
int main (int argc, char * const argv[]) {
SkAutoGraphics ag;
+ const char* writePath = NULL; // if non-null, where we write the originals
+ const char* readPath = NULL; // if non-null, were we read from to compare
+
+ char* const* stop = argv + argc;
+ for (++argv; argv < stop; ++argv) {
+ if (strcmp(*argv, "-w") == 0) {
+ argv++;
+ if (argv < stop && **argv) {
+ writePath = *argv;
+ }
+ } else if (strcmp(*argv, "-r") == 0) {
+ argv++;
+ if (argv < stop && **argv) {
+ readPath = *argv;
+ }
+ }
+ }
+
Iter iter;
GM* gm;
-
+
while ((gm = iter.next()) != NULL) {
SkISize size = gm->getISize();
- SkDebugf("---- gm %p [%d %d]\n", gm, size.width(), size.height());
+ SkDebugf("---- %s [%d %d]\n", gm->shortName(),
+ size.width(), size.height());
+
SkBitmap bitmap;
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
bitmap.setConfig(gRec[i].fConfig, size.width(), size.height());
@@ -72,16 +103,29 @@
bitmap.eraseColor(0);
SkCanvas canvas(bitmap);
- SkDebugf("------- drawing to %s config\n", gRec[i].fName);
gm->draw(&canvas);
-#if 0
- if (gRec[i].fUsePicture) {
- SkPicture picture;
- gm->draw(picture.beginRecording(size.width(), size.height(), 0));
- canvas.drawPicture(picture);
- } else {
- }
-#endif
+
+ SkString name = make_name(gm->shortName(), gRec[i].fName);
+
+ if (writePath) {
+ SkString path = make_filename(writePath, name);
+ bool success = SkImageEncoder::EncodeFile(path.c_str(), bitmap,
+ SkImageEncoder::kPNG_Type, 100);
+ if (!success) {
+ fprintf(stderr, "FAILED to write %s\n", path.c_str());
+ }
+ } else if (readPath) {
+ SkString path = make_filename(writePath, name);
+ SkBitmap orig;
+ bool success = SkImageDecoder::DecodeFile(path.c_str(), &orig,
+ SkBitmap::kARGB_8888_Config,
+ SkImageDecoder::kDecodePixels_Mode, NULL);
+ if (success) {
+ compare(bitmap, orig, name);
+ } else {
+ fprintf(stderr, "FAILED to read %s\n", path.c_str());
+ }
+ }
}
SkDELETE(gm);
}
diff --git a/gm/xfermodes.cpp b/gm/xfermodes.cpp
index 18b0bbb..e82c057 100644
--- a/gm/xfermodes.cpp
+++ b/gm/xfermodes.cpp
@@ -63,6 +63,10 @@
}
protected:
+ SkString onShortName() {
+ return SkString("xfermodes");
+ }
+
SkISize onISize() { return make_isize(400, 250); }
void drawBG(SkCanvas* canvas) {
diff --git a/include/core/SkGraphics.h b/include/core/SkGraphics.h
index 1862a2b..dd5808a 100644
--- a/include/core/SkGraphics.h
+++ b/include/core/SkGraphics.h
@@ -42,5 +42,15 @@
static void InstallNewHandler();
};
+class SkAutoGraphics {
+public:
+ SkAutoGraphics() {
+ SkGraphics::Init();
+ }
+ ~SkAutoGraphics() {
+ SkGraphics::Term();
+ }
+};
+
#endif
diff --git a/include/core/SkString.h b/include/core/SkString.h
index ae204dc..5ecfb1e 100644
--- a/include/core/SkString.h
+++ b/include/core/SkString.h
@@ -43,12 +43,13 @@
explicit SkString(size_t len);
explicit SkString(const char text[]);
SkString(const char text[], size_t len);
- explicit SkString(const SkString&);
+ SkString(const SkString&);
~SkString();
bool isEmpty() const { return fRec->fLength == 0; }
size_t size() const { return (size_t) fRec->fLength; }
const char* c_str() const { return fRec->data(); }
+ char operator[](size_t n) const { return this->c_str()[n]; }
bool equals(const SkString&) const;
bool equals(const char text[]) const;
@@ -77,6 +78,7 @@
SkString& operator=(const SkString&);
char* writable_str();
+ char& operator[](size_t n) { return this->writable_str()[n]; }
void reset();
void resize(size_t len) { this->set(NULL, len); }
diff --git a/src/ports/ports_files.mk b/src/ports/ports_files.mk
index 8760ae1..563f20b 100644
--- a/src/ports/ports_files.mk
+++ b/src/ports/ports_files.mk
@@ -1,6 +1,5 @@
SOURCE := \
SkDebug_stdio.cpp \
- SkFontHost_none.cpp \
SkGlobals_global.cpp \
SkOSFile_stdio.cpp \
SkThread_pthread.cpp \
diff --git a/tests/testmain.cpp b/tests/testmain.cpp
index f09fded..25248a3 100644
--- a/tests/testmain.cpp
+++ b/tests/testmain.cpp
@@ -95,16 +95,6 @@
bool fAndroidMode;
};
-class SkAutoGraphics {
-public:
- SkAutoGraphics() {
- SkGraphics::Init();
- }
- ~SkAutoGraphics() {
- SkGraphics::Term();
- }
-};
-
int main (int argc, char * const argv[]) {
SkAutoGraphics ag;
diff --git a/tools/skimage_main.cpp b/tools/skimage_main.cpp
index 575078c..8656d92 100644
--- a/tools/skimage_main.cpp
+++ b/tools/skimage_main.cpp
@@ -31,16 +31,6 @@
///////////////////////////////////////////////////////////////////////////////
-class SkAutoGraphics {
-public:
- SkAutoGraphics() {
- SkGraphics::Init();
- }
- ~SkAutoGraphics() {
- SkGraphics::Term();
- }
-};
-
static void show_help() {
SkDebugf("usage: skiamge [-o out-dir] inputfiles...\n");
}