--pictureDir foo will load serialized pictures <>.skp from the foo directory
git-svn-id: http://skia.googlecode.com/svn/trunk@4132 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 6bfa897..bc1b929 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -26,10 +26,22 @@
#include "gl/GrGLUtil.h"
#include "GrRenderTarget.h"
+#include "SkOSFile.h"
#include "SkPDFDevice.h"
#include "SkPDFDocument.h"
#include "SkStream.h"
+extern SampleView* CreateSamplePictFileView(const char filename[]);
+
+class PictFileFactory : public SkViewFactory {
+ SkString fFilename;
+public:
+ PictFileFactory(const SkString& filename) : fFilename(filename) {}
+ virtual SkView* operator() () const SK_OVERRIDE {
+ return CreateSamplePictFileView(fFilename.c_str());
+ }
+};
+
#define TEST_GPIPE
#ifdef TEST_GPIPE
@@ -655,7 +667,7 @@
}
static void usage(const char * argv0) {
- SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount]\n", argv0);
+ SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--pictureDir path]\n", argv0);
SkDebugf(" sampleName: sample at which to start.\n");
SkDebugf(" resourcePath: directory that stores image resources.\n");
SkDebugf(" msaa: request multisampling with the given sample count.\n");
@@ -665,6 +677,7 @@
: INHERITED(hwnd)
, fDevManager(NULL) {
+ this->registerPictFileSamples(argv, argc);
SkGMRegistyToSampleRegistry();
{
const SkViewRegister* reg = SkViewRegister::Head();
@@ -867,6 +880,38 @@
SkSafeUnref(fDevManager);
}
+static void make_filepath(SkString* path, const char* dir, const SkString& name) {
+ size_t len = strlen(dir);
+ path->set(dir);
+ if (len > 0 && dir[len - 1] != '/') {
+ path->append("/");
+ }
+ path->append(name);
+}
+
+void SampleWindow::registerPictFileSamples(char** argv, int argc) {
+ const char* pictDir = NULL;
+
+ for (int i = 0; i < argc; ++i) {
+ if (!strcmp(argv[i], "--pictureDir")) {
+ i += 1;
+ if (i < argc) {
+ pictDir = argv[i];
+ break;
+ }
+ }
+ }
+ if (pictDir) {
+ SkOSFile::Iter iter(pictDir, "skp");
+ SkString filename;
+ while (iter.next(&filename)) {
+ SkString path;
+ make_filepath(&path, pictDir, filename);
+ *fSamples.append() = new PictFileFactory(path);
+ }
+ }
+}
+
int SampleWindow::findByTitle(const char title[]) {
int i, count = fSamples.count();
for (i = 0; i < count; i++) {
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index e587e1f..c692f9d 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -123,6 +123,8 @@
virtual bool onClick(Click* click);
virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
+ void registerPictFileSamples(char** argv, int argc);
+
private:
class DefaultDeviceManager;
diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp
new file mode 100644
index 0000000..f81a02a
--- /dev/null
+++ b/samplecode/SamplePictFile.cpp
@@ -0,0 +1,78 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SampleCode.h"
+#include "SkDumpCanvas.h"
+#include "SkView.h"
+#include "SkCanvas.h"
+#include "Sk64.h"
+#include "SkGradientShader.h"
+#include "SkGraphics.h"
+#include "SkImageDecoder.h"
+#include "SkPath.h"
+#include "SkPicture.h"
+#include "SkRandom.h"
+#include "SkRegion.h"
+#include "SkShader.h"
+#include "SkUtils.h"
+#include "SkColorPriv.h"
+#include "SkColorFilter.h"
+#include "SkTime.h"
+#include "SkTypeface.h"
+#include "SkXfermode.h"
+
+#include "SkStream.h"
+#include "SkXMLParser.h"
+
+class PictFileView : public SampleView {
+ SkString fFilename;
+ SkPicture* fPicture;
+public:
+ PictFileView(const char name[] = NULL) : fFilename(name) {
+ fPicture = NULL;
+ }
+
+ virtual ~PictFileView() {
+ SkSafeUnref(fPicture);
+ }
+
+protected:
+ // overrides from SkEventSink
+ virtual bool onQuery(SkEvent* evt) {
+ if (SampleCode::TitleQ(*evt)) {
+ SkString name("P:");
+ name.append(fFilename);
+ SampleCode::TitleR(evt, name.c_str());
+ return true;
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+
+ virtual void onDrawContent(SkCanvas* canvas) {
+ if (NULL == fPicture) {
+ SkFILEStream stream(fFilename.c_str());
+ fPicture = SkNEW_ARGS(SkPicture, (&stream));
+ }
+ canvas->drawPicture(*fPicture);
+ }
+
+private:
+ typedef SampleView INHERITED;
+};
+
+SampleView* CreateSamplePictFileView(const char filename[]);
+SampleView* CreateSamplePictFileView(const char filename[]) {
+ return new PictFileView(filename);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+#if 0
+static SkView* MyFactory() { return new PictFileView; }
+static SkViewRegister reg(MyFactory);
+#endif
+