SkPDF/Bench: add bench for SkPDFSharedStream (deflate)

Also, simplify gyp.

BUG=skia:5009
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1730833003

Review URL: https://codereview.chromium.org/1730833003
This commit is contained in:
halcanary 2016-02-24 15:17:19 -08:00 committed by Commit bot
parent f7b8b8affe
commit 1e440510d8
5 changed files with 4854 additions and 22 deletions

View File

@ -7,13 +7,10 @@
#include "Benchmark.h" #include "Benchmark.h"
#include "Resources.h" #include "Resources.h"
#include "SkImage.h"
#include "SkPixmap.h"
#include "SkData.h" #include "SkData.h"
#include "SkImage.h"
#if SK_SUPPORT_PDF
#include "SkPDFBitmap.h" #include "SkPDFBitmap.h"
#include "SkPixmap.h"
namespace { namespace {
struct NullWStream : public SkWStream { struct NullWStream : public SkWStream {
@ -23,13 +20,7 @@ struct NullWStream : public SkWStream {
size_t fN; size_t fN;
}; };
static void test_pdf_image_serialization(SkImage* img) { static void test_pdf_object_serialization(SkPDFObject* object) {
SkAutoTUnref<SkPDFObject> object(
SkPDFCreateBitmapObject(img, nullptr));
if (!object) {
SkDEBUGFAIL("");
return;
}
// SkDebugWStream wStream; // SkDebugWStream wStream;
NullWStream wStream; NullWStream wStream;
SkPDFSubstituteMap substitutes; SkPDFSubstituteMap substitutes;
@ -72,7 +63,13 @@ protected:
return; return;
} }
while (loops-- > 0) { while (loops-- > 0) {
test_pdf_image_serialization(fImage); SkAutoTUnref<SkPDFObject> object(
SkPDFCreateBitmapObject(fImage, nullptr));
SkASSERT(object);
if (!object) {
return;
}
test_pdf_object_serialization(object);
} }
} }
@ -105,7 +102,13 @@ protected:
return; return;
} }
while (loops-- > 0) { while (loops-- > 0) {
test_pdf_image_serialization(fImage); SkAutoTUnref<SkPDFObject> object(
SkPDFCreateBitmapObject(fImage, nullptr));
SkASSERT(object);
if (!object) {
return;
}
test_pdf_object_serialization(object);
} }
} }
@ -113,8 +116,36 @@ private:
SkAutoTUnref<SkImage> fImage; SkAutoTUnref<SkImage> fImage;
}; };
/** Test calling DEFLATE on a 78k PDF command stream. Used for measuring
alternate zlib settings, usage, and library versions. */
class PDFCompressionBench : public Benchmark {
public:
PDFCompressionBench() {}
virtual ~PDFCompressionBench() {}
protected:
const char* onGetName() override { return "PDFCompression"; }
bool isSuitableFor(Backend backend) override {
return backend == kNonRendering_Backend;
}
void onDelayedSetup() override {
fAsset.reset(GetResourceAsStream("pdf_command_stream.txt"));
}
void onDraw(int loops, SkCanvas*) override {
SkASSERT(fAsset);
if (!fAsset) { return; }
while (loops-- > 0) {
SkAutoTUnref<SkPDFObject> object(
new SkPDFSharedStream(fAsset->duplicate()));
test_pdf_object_serialization(object);
}
}
private:
SkAutoTDelete<SkStreamAsset> fAsset;
};
} // namespace } // namespace
DEF_BENCH(return new PDFImageBench;) DEF_BENCH(return new PDFImageBench;)
DEF_BENCH(return new PDFJpegImageBench;) DEF_BENCH(return new PDFJpegImageBench;)
DEF_BENCH(return new PDFCompressionBench;)
#endif // SK_SUPPORT_PDF

View File

@ -25,8 +25,8 @@
'skia_lib.gyp:skia_lib', 'skia_lib.gyp:skia_lib',
'tools.gyp:crash_handler', 'tools.gyp:crash_handler',
'tools.gyp:proc_stats', 'tools.gyp:proc_stats',
'tools.gyp:timer',
'tools.gyp:thermal_manager', 'tools.gyp:thermal_manager',
'tools.gyp:timer',
], ],
'conditions': [ 'conditions': [
['skia_android_framework', { ['skia_android_framework', {
@ -41,11 +41,6 @@
'tools.gyp:android_utils', 'tools.gyp:android_utils',
], ],
}], }],
[ 'skia_pdf',
{ 'dependencies': [ 'pdf.gyp:pdf' ],
'include_dirs': [ '../src/pdf' ], },
{ 'dependencies': [ 'pdf.gyp:nopdf' ], }
],
], ],
}, },
], ],

View File

@ -10,12 +10,14 @@
'../src/core', '../src/core',
'../src/effects', '../src/effects',
'../src/gpu', '../src/gpu',
'../src/pdf',
'../src/utils', '../src/utils',
], ],
'sources': [ '<!@(python find.py ../bench "*.cpp")' ], 'sources': [ '<!@(python find.py ../bench "*.cpp")' ],
'dependencies': [ 'dependencies': [
'etc1.gyp:libetc1', 'etc1.gyp:libetc1',
'pdf.gyp:pdf',
'skia_lib.gyp:skia_lib', 'skia_lib.gyp:skia_lib',
'tools.gyp:resources', 'tools.gyp:resources',
'tools.gyp:sk_tool_utils', 'tools.gyp:sk_tool_utils',

View File

@ -21,6 +21,7 @@
'../src/core', '../src/core',
'../src/effects', '../src/effects',
'../src/images', '../src/images',
'../src/pdf',
], ],
'sources': [ 'sources': [
'../gm/gm.cpp', '../gm/gm.cpp',
@ -37,6 +38,7 @@
'flags.gyp:flags', 'flags.gyp:flags',
'jsoncpp.gyp:jsoncpp', 'jsoncpp.gyp:jsoncpp',
'gputest.gyp:skgputest', 'gputest.gyp:skgputest',
'pdf.gyp:pdf',
'skia_lib.gyp:skia_lib', 'skia_lib.gyp:skia_lib',
'tools.gyp:proc_stats', 'tools.gyp:proc_stats',
'tools.gyp:sk_tool_utils', 'tools.gyp:sk_tool_utils',

File diff suppressed because it is too large Load Diff