Make output path to render_pictures optional
Review URL: https://codereview.appspot.com/6779049 git-svn-id: http://skia.googlecode.com/svn/trunk@6136 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
08283afc26
commit
070d354d51
@ -163,7 +163,10 @@ bool PipePictureRenderer::render(const SkString* path) {
|
||||
pipeCanvas->drawPicture(*fPicture);
|
||||
writer.endRecording();
|
||||
fCanvas->flush();
|
||||
return path != NULL && write(fCanvas, *path);
|
||||
if (NULL != path) {
|
||||
return write(fCanvas, *path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -177,7 +180,10 @@ bool SimplePictureRenderer::render(const SkString* path) {
|
||||
|
||||
fCanvas->drawPicture(*fPicture);
|
||||
fCanvas->flush();
|
||||
return path != NULL && write(fCanvas, *path);
|
||||
if (NULL != path) {
|
||||
return write(fCanvas, *path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -382,7 +388,8 @@ static void DrawTile(void* data) {
|
||||
int32_t i;
|
||||
while ((i = tileData->nextTile(&tileRect)) != -1) {
|
||||
DrawTileToCanvas(tileData->fCanvas, tileRect, tileData->fController);
|
||||
if (!writeAppendNumber(tileData->fCanvas, tileData->fPath, i)) {
|
||||
if (NULL != tileData->fPath &&
|
||||
!writeAppendNumber(tileData->fCanvas, tileData->fPath, i)) {
|
||||
*tileData->fSuccess = false;
|
||||
break;
|
||||
}
|
||||
@ -412,7 +419,8 @@ static void DrawClonedTiles(void* data) {
|
||||
int32_t i;
|
||||
while ((i = cloneData->nextTile(&tileRect)) != -1) {
|
||||
DrawTileToCanvas(cloneData->fCanvas, tileRect, cloneData->fClone);
|
||||
if (!writeAppendNumber(cloneData->fCanvas, cloneData->fPath, i)) {
|
||||
if (NULL != cloneData->fPath &&
|
||||
!writeAppendNumber(cloneData->fCanvas, cloneData->fPath, i)) {
|
||||
*cloneData->fSuccess = false;
|
||||
break;
|
||||
}
|
||||
@ -486,13 +494,14 @@ bool TiledPictureRenderer::render(const SkString* path) {
|
||||
SkCanvas* canvas = this->setupCanvas(fTileWidth, fTileHeight);
|
||||
SkAutoUnref aur(canvas);
|
||||
|
||||
bool success = true;
|
||||
for (int i = 0; i < fTileRects.count(); ++i) {
|
||||
DrawTileToCanvas(canvas, fTileRects[i], fPicture);
|
||||
if (!writeAppendNumber(canvas, path, i)) {
|
||||
return false;
|
||||
if (NULL != path) {
|
||||
success &= writeAppendNumber(canvas, path, i);
|
||||
}
|
||||
}
|
||||
return path != NULL;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,8 @@ public:
|
||||
* If path is non-null, subclass implementations should call write().
|
||||
* @param path If non-null, also write the output to the file specified by path. path should
|
||||
* have no extension; it will be added by write().
|
||||
* @return bool True if path is non-null and the output is successfully written to a file.
|
||||
* @return bool True if rendering succeeded and, if path is non-null, the output was
|
||||
* successfully written to a file.
|
||||
*/
|
||||
virtual bool render(const SkString* path) = 0;
|
||||
|
||||
|
@ -23,7 +23,8 @@ static void usage(const char* argv0) {
|
||||
SkDebugf("SkPicture rendering tool\n");
|
||||
SkDebugf("\n"
|
||||
"Usage: \n"
|
||||
" %s <input>... <outputDir> \n"
|
||||
" %s <input>... \n"
|
||||
" [-w <outputDir>]"
|
||||
" [--mode pow2tile minWidth height[%] | simple\n"
|
||||
" | tile width[%] height[%]]\n"
|
||||
" [--pipe]\n"
|
||||
@ -84,7 +85,7 @@ static void make_output_filepath(SkString* path, const SkString& dir,
|
||||
path->remove(path->size() - 4, 4);
|
||||
}
|
||||
|
||||
static bool render_picture(const SkString& inputPath, const SkString& outputDir,
|
||||
static bool render_picture(const SkString& inputPath, const SkString* outputDir,
|
||||
sk_tools::PictureRenderer& renderer) {
|
||||
SkString inputFilename;
|
||||
sk_tools::get_basename(&inputFilename, inputPath);
|
||||
@ -109,12 +110,17 @@ static bool render_picture(const SkString& inputPath, const SkString& outputDir,
|
||||
renderer.init(&picture);
|
||||
renderer.setup();
|
||||
|
||||
SkString outputPath;
|
||||
make_output_filepath(&outputPath, outputDir, inputFilename);
|
||||
|
||||
success = renderer.render(&outputPath);
|
||||
if (!success) {
|
||||
SkDebugf("Could not write to file %s\n", outputPath.c_str());
|
||||
SkString* outputPath = NULL;
|
||||
if (NULL != outputDir) {
|
||||
outputPath = SkNEW(SkString);
|
||||
make_output_filepath(outputPath, *outputDir, inputFilename);
|
||||
}
|
||||
success = renderer.render(outputPath);
|
||||
if (outputPath) {
|
||||
if (!success) {
|
||||
SkDebugf("Could not write to file %s\n", outputPath->c_str());
|
||||
}
|
||||
SkDELETE(outputPath);
|
||||
}
|
||||
|
||||
renderer.resetState();
|
||||
@ -123,11 +129,12 @@ static bool render_picture(const SkString& inputPath, const SkString& outputDir,
|
||||
return success;
|
||||
}
|
||||
|
||||
static int process_input(const SkString& input, const SkString& outputDir,
|
||||
static int process_input(const SkString& input, const SkString* outputDir,
|
||||
sk_tools::PictureRenderer& renderer) {
|
||||
SkOSFile::Iter iter(input.c_str(), "skp");
|
||||
SkString inputFilename;
|
||||
int failures = 0;
|
||||
SkDebugf("process_input, %s\n", input.c_str());
|
||||
if (iter.next(&inputFilename)) {
|
||||
do {
|
||||
SkString inputPath;
|
||||
@ -150,7 +157,7 @@ static int process_input(const SkString& input, const SkString& outputDir,
|
||||
}
|
||||
|
||||
static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
|
||||
sk_tools::PictureRenderer*& renderer){
|
||||
sk_tools::PictureRenderer*& renderer, SkString*& outputDir){
|
||||
const char* argv0 = argv[0];
|
||||
char* const* stop = argv + argc;
|
||||
|
||||
@ -247,6 +254,14 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
|
||||
SkDELETE(renderer);
|
||||
usage(argv0);
|
||||
exit(-1);
|
||||
} else if (0 == strcmp(*argv, "-w")) {
|
||||
++argv;
|
||||
if (argv >= stop) {
|
||||
SkDebugf("Missing output directory for -w\n");
|
||||
usage(argv0);
|
||||
exit(-1);
|
||||
}
|
||||
outputDir = SkNEW_ARGS(SkString, (*argv));
|
||||
} else {
|
||||
inputs->push_back(SkString(*argv));
|
||||
}
|
||||
@ -325,8 +340,11 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
|
||||
renderer = SkNEW(sk_tools::PipePictureRenderer);
|
||||
}
|
||||
|
||||
if (inputs->count() < 2) {
|
||||
if (inputs->empty()) {
|
||||
SkDELETE(renderer);
|
||||
if (NULL != outputDir) {
|
||||
SkDELETE(outputDir);
|
||||
}
|
||||
usage(argv0);
|
||||
exit(-1);
|
||||
}
|
||||
@ -343,13 +361,12 @@ int tool_main(int argc, char** argv) {
|
||||
SkAutoGraphics ag;
|
||||
SkTArray<SkString> inputs;
|
||||
sk_tools::PictureRenderer* renderer = NULL;
|
||||
|
||||
parse_commandline(argc, argv, &inputs, renderer);
|
||||
SkString outputDir = inputs[inputs.count() - 1];
|
||||
SkString* outputDir = NULL;
|
||||
parse_commandline(argc, argv, &inputs, renderer, outputDir);
|
||||
SkASSERT(renderer);
|
||||
|
||||
int failures = 0;
|
||||
for (int i = 0; i < inputs.count() - 1; i ++) {
|
||||
for (int i = 0; i < inputs.count(); i ++) {
|
||||
failures += process_input(inputs[i], outputDir, *renderer);
|
||||
}
|
||||
if (failures != 0) {
|
||||
@ -365,7 +382,9 @@ int tool_main(int argc, char** argv) {
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (NULL != outputDir) {
|
||||
SkDELETE(outputDir);
|
||||
}
|
||||
SkDELETE(renderer);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user