--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
This commit is contained in:
parent
5d0c62f0f6
commit
1830c7aa3c
@ -83,6 +83,7 @@
|
||||
'../samplecode/SamplePathClip.cpp',
|
||||
'../samplecode/SamplePathEffects.cpp',
|
||||
'../samplecode/SamplePicture.cpp',
|
||||
'../samplecode/SamplePictFile.cpp',
|
||||
'../samplecode/SamplePoints.cpp',
|
||||
'../samplecode/SamplePolyToPoly.cpp',
|
||||
'../samplecode/SampleRegion.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++) {
|
||||
|
@ -123,6 +123,8 @@ protected:
|
||||
virtual bool onClick(Click* click);
|
||||
virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
|
||||
|
||||
void registerPictFileSamples(char** argv, int argc);
|
||||
|
||||
private:
|
||||
class DefaultDeviceManager;
|
||||
|
||||
|
78
samplecode/SamplePictFile.cpp
Normal file
78
samplecode/SamplePictFile.cpp
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user