diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-01 12:51:34 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-01 12:51:34 +0000 |
commit | d7aaf6034e519ea9b70649c1d344f2f24de90ccb (patch) | |
tree | d3ee4c9a59476d4fc95861b107de61369a591101 | |
parent | bb5c46591c50d05418467cd1c4e927ceb85c2ba9 (diff) |
Add Xfermode bench. Also clear before rendering in bench (rather than after).
Author: bsalomon@google.com
Reviewed By: robertphillips@google.com
Review URL: https://chromiumcodereview.appspot.com/13334011
git-svn-id: http://skia.googlecode.com/svn/trunk@8454 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/XfermodeBench.cpp | 70 | ||||
-rw-r--r-- | bench/benchmain.cpp | 2 | ||||
-rw-r--r-- | gyp/bench.gypi | 1 | ||||
-rw-r--r-- | include/core/SkXfermode.h | 5 | ||||
-rw-r--r-- | src/core/SkXfermode.cpp | 20 |
5 files changed, 90 insertions, 8 deletions
diff --git a/bench/XfermodeBench.cpp b/bench/XfermodeBench.cpp new file mode 100644 index 0000000000..8045a26ed9 --- /dev/null +++ b/bench/XfermodeBench.cpp @@ -0,0 +1,70 @@ + +/* + * 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 "SkCanvas.h" +#include "SkPaint.h" +#include "SkRandom.h" +#include "SkString.h" +#include "SkXfermode.h" + +// Benchmark that draws non-AA rects with an SkXfermode::Mode +class XfermodeBench : public SkBenchmark { +public: + XfermodeBench(void* param, SkXfermode::Mode mode) : SkBenchmark(param) { + fXfermode.reset(SkXfermode::Create(mode)); + SkASSERT(NULL != fXfermode.get() || SkXfermode::kSrcOver_Mode == mode); + fName.printf("Xfermode_%s", SkXfermode::ModeName(mode)); + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkISize size = canvas->getDeviceSize(); + SkMWCRandom random; + for (int i = 0; i < kNumRects; ++i) { + SkPaint paint; + paint.setXfermode(fXfermode.get()); + paint.setColor(random.nextU()); + SkScalar w = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize)); + SkScalar h = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize)); + SkRect rect = SkRect::MakeXYWH( + random.nextUScalar1() * (size.fWidth - w), + random.nextUScalar1() * (size.fHeight - h), + w, + h + ); + canvas->drawRect(rect, paint); + } + } + +private: + enum { + kNumRects = SkBENCHLOOP(1000), + kMinSize = 10, + kMaxSize = 400, + }; + SkAutoTUnref<SkXfermode> fXfermode; + SkString fName; + + typedef SkBenchmark INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + + +// These modes were chosen because they are expected to be successively harder for the GPU. +// kSrc can disable blending, kSrcOver cannot, kDarken requires reading the dst pixel in the shader. +static SkBenchmark* Fact0(void* p) { return new XfermodeBench(p, SkXfermode::kSrc_Mode); } +static SkBenchmark* Fact1(void* p) { return new XfermodeBench(p, SkXfermode::kSrcOver_Mode); } +static SkBenchmark* Fact2(void* p) { return new XfermodeBench(p, SkXfermode::kDarken_Mode); } + +static BenchRegistry gReg0(Fact0); +static BenchRegistry gReg1(Fact1); +static BenchRegistry gReg2(Fact2); diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index 4bc56c4b17..9f357c661d 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -822,6 +822,7 @@ int tool_main(int argc, char** argv) { SkASSERT(0); } device->unref(); + canvas->clear(SK_ColorWHITE); } SkAutoUnref canvasUnref(canvas); @@ -928,7 +929,6 @@ int tool_main(int argc, char** argv) { if (outDir.size() > 0 && kNonRendering_Backend != backend) { saveFile(bench->getName(), configName, outDir.c_str(), device->accessBitmap(false)); - canvas->clear(SK_ColorWHITE); } } if (loggedBenchStart) { diff --git a/gyp/bench.gypi b/gyp/bench.gypi index a18ace8a0a..f5aa1e3b45 100644 --- a/gyp/bench.gypi +++ b/gyp/bench.gypi @@ -50,6 +50,7 @@ '../bench/TileBench.cpp', '../bench/VertBench.cpp', '../bench/WriterBench.cpp', + '../bench/XfermodeBench.cpp', '../bench/SkBenchLogger.h', '../bench/SkBenchLogger.cpp', diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h index 92e240b6c2..38273ac153 100644 --- a/include/core/SkXfermode.h +++ b/include/core/SkXfermode.h @@ -128,6 +128,11 @@ public: kLastMode = kLuminosity_Mode }; + + /** + * Gets the name of the Mode as a string. + */ + static const char* ModeName(Mode); /** * If the xfermode is one of the modes in the Mode enum, then asMode() diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp index 6f22aa43a6..d1a0f7a76e 100644 --- a/src/core/SkXfermode.cpp +++ b/src/core/SkXfermode.cpp @@ -1107,19 +1107,25 @@ private: typedef SkProcXfermode INHERITED; }; -#ifdef SK_DEVELOPER -void SkProcCoeffXfermode::toString(SkString* str) const { - str->append("SkProcCoeffXfermode: "); - - const char *gModeStrings[kLastMode+1] = { +const char* SkXfermode::ModeName(Mode mode) { + SkASSERT((unsigned) mode <= (unsigned)kLastMode); + const char* gModeStrings[] = { "Clear", "Src", "Dst", "SrcOver", "DstOver", "SrcIn", "DstIn", "SrcOut", "DstOut", "SrcATop", "DstATop", "Xor", "Plus", "Modulate", "Screen", "Overlay", "Darken", "Lighten", "ColorDodge", - "ColorBurn", "HardLight", "SoftLight", "Difference", "Exclusion" + "ColorBurn", "HardLight", "SoftLight", "Difference", "Exclusion", + "Multiply", "Hue", "Saturation", "Color", "Luminosity" }; + return gModeStrings[mode]; + SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gModeStrings) == kLastMode + 1, mode_count); +} + +#ifdef SK_DEVELOPER +void SkProcCoeffXfermode::toString(SkString* str) const { + str->append("SkProcCoeffXfermode: "); str->append("mode: "); - str->append(gModeStrings[fMode]); + str->append(ModeName(fMode)); static const char* gCoeffStrings[kCoeffCount] = { "Zero", "One", "SC", "ISC", "DC", "IDC", "SA", "ISA", "DA", "IDA" |