diff options
| author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-04 12:05:43 +0000 |
|---|---|---|
| committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-04 12:05:43 +0000 |
| commit | 1830c7aa3c4045af438fb24ee0bd22598f1bfca7 (patch) | |
| tree | 50d3053bc3406df8d90c85d668121779551f9381 /samplecode/SampleApp.cpp | |
| parent | 5d0c62f0f654127b7d66358405d824266868bd1d (diff) | |
--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
Diffstat (limited to 'samplecode/SampleApp.cpp')
| -rw-r--r-- | samplecode/SampleApp.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 6bfa897128..bc1b929301 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 inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType } 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 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev : INHERITED(hwnd) , fDevManager(NULL) { + this->registerPictFileSamples(argv, argc); SkGMRegistyToSampleRegistry(); { const SkViewRegister* reg = SkViewRegister::Head(); @@ -867,6 +880,38 @@ SampleWindow::~SampleWindow() { 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++) { |
