diff options
author | 2013-09-25 21:42:12 +0000 | |
---|---|---|
committer | 2013-09-25 21:42:12 +0000 | |
commit | 111fd11e11cbc296c97225ea16b7ff174a4bcdb5 (patch) | |
tree | 1d7bb5d480fb78b7fa637a27c04485f357d3326a | |
parent | b5571b3324cf18629a255ec85e189447069c9b14 (diff) |
Bench baseline for mostly 0 image.
Add a baseline for decoding a mostly 0 image. This is in advance of
https://codereview.chromium.org/24269006/ which provides an option to
skip writing those 0s (as part of BUG=skia:1661). On my Nexus 4, the
benchmark does not slow down after that change.
As suggested in https://codereview.chromium.org/24269006/ add a
resourcePath flag to bench. Will require a change in buildbot in order
to actually use the flag.
Add an image used by the test.
Until https://codereview.chromium.org/24448002 is submitted,
the test will not actually be run by the bots (since it
won't know where to find the file).
BUG=skia:1661
R=djsollen@google.com, mtklein@google.com
Review URL: https://codereview.chromium.org/24440002
git-svn-id: http://skia.googlecode.com/svn/trunk@11461 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/SkBenchmark.cpp | 3 | ||||
-rw-r--r-- | bench/SkBenchmark.h | 6 | ||||
-rw-r--r-- | bench/SkipZeroesBench.cpp | 115 | ||||
-rw-r--r-- | bench/benchmain.cpp | 6 | ||||
-rw-r--r-- | gyp/bench.gypi | 1 | ||||
-rw-r--r-- | resources/arrow.png | bin | 0 -> 3926 bytes |
6 files changed, 130 insertions, 1 deletions
diff --git a/bench/SkBenchmark.cpp b/bench/SkBenchmark.cpp index 4d361e7416..e11ebcf328 100644 --- a/bench/SkBenchmark.cpp +++ b/bench/SkBenchmark.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2011 Google Inc. * @@ -15,6 +14,8 @@ SK_DEFINE_INST_COUNT(SkBenchmark) template BenchRegistry* BenchRegistry::gHead; +SkString SkBenchmark::gResourcePath; + SkBenchmark::SkBenchmark() { fForceAlpha = 0xFF; fForceAA = true; diff --git a/bench/SkBenchmark.h b/bench/SkBenchmark.h index 811a1db2c8..ec40077527 100644 --- a/bench/SkBenchmark.h +++ b/bench/SkBenchmark.h @@ -10,6 +10,7 @@ #include "SkRefCnt.h" #include "SkPoint.h" +#include "SkString.h" #include "SkTRegistry.h" #define DEF_BENCH(code) \ @@ -106,6 +107,10 @@ public: // for (int i = 0; i < this->getLoops(); i++) { <work here> } int getLoops() const { return fLoops; } + static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath); } + + static SkString& GetResourcePath() { return gResourcePath; } + protected: virtual void setupPaint(SkPaint* paint); @@ -125,6 +130,7 @@ private: SkTriState::State fDither; uint32_t fOrMask, fClearMask; int fLoops; + static SkString gResourcePath; typedef SkRefCnt INHERITED; }; diff --git a/bench/SkipZeroesBench.cpp b/bench/SkipZeroesBench.cpp new file mode 100644 index 0000000000..6e4b54bdf6 --- /dev/null +++ b/bench/SkipZeroesBench.cpp @@ -0,0 +1,115 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBenchmark.h" +#include "SkBitmap.h" +#include "SkData.h" +#include "SkForceLinking.h" +#include "SkImageDecoder.h" +#include "SkOSFile.h" +#include "SkStream.h" +#include "SkString.h" + +__SK_FORCE_IMAGE_DECODER_LINKING; + +class SkCanvas; + +class SkipZeroesBench : public SkBenchmark { +public: + SkipZeroesBench(const char* filename, bool skipZeroes) + : fName("SkipZeroes_") + , fDecoder(NULL) + , fFilename(filename) + , fStream() + , fSkipZeroes(skipZeroes) + , fValid(false) { + fName.append(filename); + if (skipZeroes) { + fName.append("_skip_zeroes"); + } else { + fName.append("_write_zeroes"); + } + fIsRendering = false; + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fName.c_str(); + } + + virtual void onPreDraw() SK_OVERRIDE { + const char* resPath = GetResourcePath().c_str(); + if (NULL == resPath) { + fValid = false; + return; + } + + SkString fullPath = SkOSPath::SkPathJoin(resPath, fFilename.c_str()); + SkFILEStream fileStream(fullPath.c_str()); + fValid = fileStream.isValid() && fileStream.getLength() > 0; + if (fValid) { + const size_t size = fileStream.getLength(); + void* data = sk_malloc_throw(size); + if (fileStream.read(data, size) < size) { + fValid = false; + } else { + SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size)); + fStream.setData(skdata.get()); + fDecoder.reset(SkImageDecoder::Factory(&fStream)); + if (fDecoder.get()) { + // Disabling until the feature is checked in. + // See https://codereview.chromium.org/24269006/ + //fDecoder->setSkipWritingZeroes(fSkipZeroes); + } else { + fValid = false; + } + } + } + } + + virtual void onDraw(SkCanvas*) SK_OVERRIDE { + if (!fValid) { +#ifdef SK_DEBUG + SkDebugf("stream was invalid: %s\n", fFilename.c_str()); +#endif + return; + } + // Decode a bunch of times + SkBitmap bm; + for (int i = 0; i < this->getLoops(); ++i) { + SkDEBUGCODE(bool success =) fDecoder->decode(&fStream, &bm, + SkImageDecoder::kDecodePixels_Mode); +#ifdef SK_DEBUG + if (!success) { + SkDebugf("failed to decode %s\n", fFilename.c_str()); + return; + } +#endif + SkDEBUGCODE(success =) fStream.rewind(); +#ifdef SK_DEBUG + if (!success) { + SkDebugf("failed to rewind %s\n", fFilename.c_str()); + return; + } +#endif + } + } + +private: + SkString fName; + SkAutoTDelete<SkImageDecoder> fDecoder; + const SkString fFilename; + SkMemoryStream fStream; + bool fSkipZeroes; + bool fValid; + + typedef SkBenchmark INHERITED; +}; + +// Enable the true version once the feature is checked in. +//DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", true))); +DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", false))); diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index 78993c1641..57dfdd20bd 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -284,6 +284,7 @@ DEFINE_double(error, 0.01, "Ratio of subsequent bench measurements must drop within 1±error to converge."); DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops."); DEFINE_bool2(verbose, v, false, "Print more."); +DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); // Has this bench converged? First arguments are milliseconds / loop iteration, // last is overall runtime in milliseconds. @@ -357,6 +358,11 @@ int tool_main(int argc, char** argv) { } } } + // Set the resource path. + if (!FLAGS_resourcePath.isEmpty()) { + SkBenchmark::SetResourcePath(FLAGS_resourcePath[0]); + } + #if SK_SUPPORT_GPU for (int i = 0; i < configs.count(); ++i) { const Config& config = gConfigs[configs[i]]; diff --git a/gyp/bench.gypi b/gyp/bench.gypi index 9f4bdb6547..32902b4134 100644 --- a/gyp/bench.gypi +++ b/gyp/bench.gypi @@ -62,6 +62,7 @@ '../bench/RTreeBench.cpp', '../bench/ScalarBench.cpp', '../bench/ShaderMaskBench.cpp', + '../bench/SkipZeroesBench.cpp', '../bench/SortBench.cpp', '../bench/StrokeBench.cpp', '../bench/TableBench.cpp', diff --git a/resources/arrow.png b/resources/arrow.png Binary files differnew file mode 100644 index 0000000000..382ef39040 --- /dev/null +++ b/resources/arrow.png |