*/
SkPicture(const SkPicture& src);
/**
- * Recreate a picture that was serialized into a stream. If an error occurs
- * the picture will be "empty" : width and height == 0
+ * Recreate a picture that was serialized into a stream. *success is set to
+ * true if the picture was deserialized successfully and false otherwise.
*/
- explicit SkPicture(SkStream*);
+ explicit SkPicture(SkStream*, bool* success = NULL);
virtual ~SkPicture();
/**
*/
void endRecording();
- /** Returns true if any draw commands have been recorded since the last
- call to beginRecording.
- */
- bool hasRecorded() const;
-
/** Replays the drawing commands on the specified canvas. This internally
calls endRecording() if that has not already been called.
@param surface the canvas receiving the drawing commands.
return fRecord;
}
-bool SkPicture::hasRecorded() const {
- return NULL != fRecord && fRecord->writeStream().size() > 0;
-}
-
SkCanvas* SkPicture::getRecordingCanvas() const {
// will be null if we are not recording
return fRecord;
// V6 : added serialization of SkPath's bounds (and packed its flags tighter)
#define PICTURE_VERSION 6
-SkPicture::SkPicture(SkStream* stream) : SkRefCnt() {
+SkPicture::SkPicture(SkStream* stream, bool* success) : SkRefCnt() {
+ if (success) {
+ *success = false;
+ }
fRecord = NULL;
fPlayback = NULL;
fWidth = fHeight = 0;
// do this at the end, so that they will be zero if we hit an error.
fWidth = info.fWidth;
fHeight = info.fHeight;
+ if (success) {
+ *success = true;
+ }
}
void SkPicture::serialize(SkWStream* stream) const {
SkBenchLogger gLogger;
-static void run_single_benchmark(const SkString& inputPath,
+static bool run_single_benchmark(const SkString& inputPath,
sk_tools::PictureBenchmark& benchmark) {
SkFILEStream inputStream;
SkString err;
err.printf("Could not open file %s\n", inputPath.c_str());
gLogger.logError(err);
- return;
+ return false;
}
- SkPicture* picture = SkNEW_ARGS(SkPicture, (&inputStream));
+ bool success = false;
+ SkPicture* picture = SkNEW_ARGS(SkPicture, (&inputStream, &success));
SkAutoTUnref<SkPicture> aur(picture);
+ if (!success) {
+ SkString err;
+ err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
+ gLogger.logError(err);
+ return false;
+ }
SkString filename;
sk_tools::get_basename(&filename, inputPath);
sk_tools::resize_if_needed(&aur);
benchmark.run(aur);
+ return true;
}
static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
gLogger.logProgress(commandLine);
}
-static void process_input(const SkString& input, sk_tools::PictureBenchmark& benchmark) {
+static int process_input(const SkString& input,
+ sk_tools::PictureBenchmark& benchmark) {
SkOSFile::Iter iter(input.c_str(), "skp");
SkString inputFilename;
-
+ int failures = 0;
if (iter.next(&inputFilename)) {
do {
SkString inputPath;
sk_tools::make_filepath(&inputPath, input, inputFilename);
- run_single_benchmark(inputPath, benchmark);
+ if (!run_single_benchmark(inputPath, benchmark))
+ ++failures;
} while(iter.next(&inputFilename));
} else {
- run_single_benchmark(input, benchmark);
+ if (!run_single_benchmark(input, benchmark))
+ ++failures;
}
+ return failures;
}
int main(int argc, char* const argv[]) {
parse_commandline(argc, argv, &inputs, &benchmark);
+ int failures = 0;
for (int i = 0; i < inputs.count(); ++i) {
- process_input(inputs[i], benchmark);
+ failures += process_input(inputs[i], benchmark);
+ }
+
+ if (failures != 0) {
+ SkString err;
+ err.printf("Failed to run %i benchmarks.\n", failures);
+ gLogger.logError(err);
+ return 1;
}
}
path->append("png");
}
-static void write_output(const SkString& outputDir, const SkString& inputFilename,
+static bool write_output(const SkString& outputDir, const SkString& inputFilename,
const sk_tools::PictureRenderer& renderer) {
SkString outputPath;
make_output_filepath(&outputPath, outputDir, inputFilename);
if (!isWritten) {
SkDebugf("Could not write to file %s\n", outputPath.c_str());
}
+ return isWritten;
}
-static void 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);
inputStream.setPath(inputPath.c_str());
if (!inputStream.isValid()) {
SkDebugf("Could not open file %s\n", inputPath.c_str());
- return;
+ return false;
}
- SkPicture* picture = SkNEW_ARGS(SkPicture, (&inputStream));
+ bool success = false;
+ SkPicture* picture = SkNEW_ARGS(SkPicture, (&inputStream, &success));
SkAutoTUnref<SkPicture> aur(picture);
+ if (!success) {
+ SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
+ return false;
+ }
SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
inputPath.c_str());
renderer.resetState();
- write_output(outputDir, inputFilename, renderer);
+ success = write_output(outputDir, inputFilename, renderer);
renderer.end();
+ return success;
}
-static void 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;
if (iter.next(&inputFilename)) {
do {
SkString inputPath;
sk_tools::make_filepath(&inputPath, input, inputFilename);
- render_picture(inputPath, outputDir, renderer);
+ if (!render_picture(inputPath, outputDir, renderer))
+ ++failures;
} while(iter.next(&inputFilename));
} else {
SkString inputPath(input);
- render_picture(inputPath, outputDir, renderer);
+ if (!render_picture(inputPath, outputDir, renderer))
+ ++failures;
}
+ return failures;
}
static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
}
int main(int argc, char* const argv[]) {
- SkGraphics::Init();
+ SkAutoGraphics ag;
SkTArray<SkString> inputs;
sk_tools::PictureRenderer* renderer = NULL;
SkString outputDir = inputs[inputs.count() - 1];
SkASSERT(renderer);
+ int failures = 0;
for (int i = 0; i < inputs.count() - 1; i ++) {
- process_input(inputs[i], outputDir, *renderer);
+ failures += process_input(inputs[i], outputDir, *renderer);
+ }
+ if (failures != 0) {
+ SkDebugf("Failed to render %i pictures.\n", failures);
+ return 1;
}
-
#if SK_SUPPORT_GPU
#if GR_CACHE_STATS
if (renderer->isUsingGpuDevice()) {
#endif
SkDELETE(renderer);
- SkGraphics::Term();
}