diff options
author | 2013-07-19 13:55:41 +0000 | |
---|---|---|
committer | 2013-07-19 13:55:41 +0000 | |
commit | 88682b77d108a7413a166e3158e187f43211c46b (patch) | |
tree | cb94c9fd0429a6eae968bf0a8a1dc334136eb5d1 /gm/gmmain.cpp | |
parent | a79919883e275e7a5e00afc50be10cc721f6ba1d (diff) |
Add a detachAsStream to SkDynamicMemoryWStream.
R=reed@google.com
Committed: https://code.google.com/p/skia/source/detail?r=10171
Review URL: https://codereview.chromium.org/19677002
git-svn-id: http://skia.googlecode.com/svn/trunk@10178 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/gmmain.cpp')
-rw-r--r-- | gm/gmmain.cpp | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp index 98525a5394..3c01156653 100644 --- a/gm/gmmain.cpp +++ b/gm/gmmain.cpp @@ -410,11 +410,9 @@ public: gm_fprintf(stdout, "(results marked with [*] will cause nonzero return value)\n"); } - static bool write_document(const SkString& path, - const SkDynamicMemoryWStream& document) { + static bool write_document(const SkString& path, SkStreamAsset* asset) { SkFILEWStream stream(path.c_str()); - SkAutoDataUnref data(document.copyToData()); - return stream.write(data->data(), data->size()); + return stream.writeStream(asset, asset->getLength()); } /** @@ -665,7 +663,7 @@ public: const char renderModeDescriptor [], const char *shortName, const BitmapAndDigest* bitmapAndDigest, - SkDynamicMemoryWStream* document) { + SkStreamAsset* document) { SkString path; bool success = false; if (gRec.fBackend == kRaster_Backend || @@ -679,12 +677,12 @@ public: if (kPDF_Backend == gRec.fBackend) { path = make_filename(writePath, shortName, gRec.fName, renderModeDescriptor, "pdf"); - success = write_document(path, *document); + success = write_document(path, document); } if (kXPS_Backend == gRec.fBackend) { path = make_filename(writePath, shortName, gRec.fName, renderModeDescriptor, "xps"); - success = write_document(path, *document); + success = write_document(path, document); } if (success) { return kEmpty_ErrorCombination; @@ -911,7 +909,7 @@ public: */ ErrorCombination compare_test_results_to_stored_expectations( GM* gm, const ConfigData& gRec, const char writePath[], - const BitmapAndDigest* actualBitmapAndDigest, SkDynamicMemoryWStream* document) { + const BitmapAndDigest* actualBitmapAndDigest, SkStreamAsset* document) { SkString shortNamePlusConfig = make_shortname_plus_config(gm->shortName(), gRec.fName); SkString nameWithExtension(shortNamePlusConfig); @@ -1025,24 +1023,10 @@ public: } static SkPicture* stream_to_new_picture(const SkPicture& src) { - - // To do in-memory commiunications with a stream, we need to: - // * create a dynamic memory stream - // * copy it into a buffer - // * create a read stream from it - // ?!?! - SkDynamicMemoryWStream storage; src.serialize(&storage); - - size_t streamSize = storage.getOffset(); - SkAutoMalloc dstStorage(streamSize); - void* dst = dstStorage.get(); - //char* dst = new char [streamSize]; - //@todo thudson 22 April 2011 when can we safely delete [] dst? - storage.copyTo(dst); - SkMemoryStream pictReadback(dst, streamSize); - SkPicture* retval = SkPicture::CreateFromStream(&pictReadback); + SkAutoTUnref<SkStreamAsset> pictReadback(storage.detatchAsStream()); + SkPicture* retval = SkPicture::CreateFromStream(pictReadback); return retval; } @@ -1079,13 +1063,14 @@ public: bitmap = NULL; // we don't generate a bitmap rendering of the XPS file } + SkAutoTUnref<SkStreamAsset> documentStream(document.detatchAsStream()); if (NULL == bitmap) { return compare_test_results_to_stored_expectations( - gm, gRec, writePath, NULL, &document); + gm, gRec, writePath, NULL, documentStream); } else { BitmapAndDigest bitmapAndDigest(*bitmap); return compare_test_results_to_stored_expectations( - gm, gRec, writePath, &bitmapAndDigest, &document); + gm, gRec, writePath, &bitmapAndDigest, documentStream); } } @@ -1093,8 +1078,6 @@ public: const ConfigData& gRec, const SkBitmap& referenceBitmap, GrSurface* gpuTarget) { - SkDynamicMemoryWStream document; - if (gRec.fBackend == kRaster_Backend || gRec.fBackend == kGPU_Backend) { const char renderModeDescriptor[] = "-deferred"; |