diff options
author | sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-24 19:36:44 +0000 |
---|---|---|
committer | sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-24 19:36:44 +0000 |
commit | 5d71adf4b187b41858139675a499a704af15b2cb (patch) | |
tree | 6e7a4c42eec33c863796e1c6730b9090bfaeedab | |
parent | 58104a9c2517b25355d6838844ace2ea876f3a1c (diff) |
Adding new bench tests for lighting and blur
Review URL: https://codereview.chromium.org/14474004
git-svn-id: http://skia.googlecode.com/svn/trunk@8846 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/BlurImageFilterBench.cpp | 89 | ||||
-rw-r--r-- | bench/LightingBench.cpp | 227 | ||||
-rw-r--r-- | gyp/bench.gypi | 2 |
3 files changed, 318 insertions, 0 deletions
diff --git a/bench/BlurImageFilterBench.cpp b/bench/BlurImageFilterBench.cpp new file mode 100644 index 0000000000..0bc92406ab --- /dev/null +++ b/bench/BlurImageFilterBench.cpp @@ -0,0 +1,89 @@ +/* + * 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 "SkBlurImageFilter.h" +#include "SkCanvas.h" +#include "SkDevice.h" +#include "SkPaint.h" +#include "SkRandom.h" +#include "SkShader.h" +#include "SkString.h" + +#define FILTER_WIDTH_SMALL 32 +#define FILTER_HEIGHT_SMALL 32 +#define FILTER_WIDTH_LARGE 256 +#define FILTER_HEIGHT_LARGE 256 +#define BLUR_SIGMA_SMALL SkFloatToScalar(1.0f) +#define BLUR_SIGMA_LARGE SkFloatToScalar(10.0f) + +class BlurImageFilterBench : public SkBenchmark { +public: + BlurImageFilterBench(void* param, SkScalar sigmaX, SkScalar sigmaY, bool small) : + INHERITED(param), fIsSmall(small), fInitialized(false), fSigmaX(sigmaX), fSigmaY(sigmaY) { + fName.printf("blur_image_filter_%s_%.2f_%.2f", fIsSmall ? "small" : "large", + SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY)); + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fName.c_str(); + } + + virtual void onPreDraw() SK_OVERRIDE { + if (!fInitialized) { + make_checkerboard(); + fInitialized = true; + } + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkPaint paint; + paint.setImageFilter(new SkBlurImageFilter(fSigmaX, fSigmaY))->unref(); + canvas->drawBitmap(fCheckerboard, 0, 0, &paint); + } + +private: + void make_checkerboard() { + const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; + const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; + fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, w, h); + fCheckerboard.allocPixels(); + SkDevice device(fCheckerboard); + SkCanvas canvas(&device); + canvas.clear(0x00000000); + SkPaint darkPaint; + darkPaint.setColor(0xFF804020); + SkPaint lightPaint; + lightPaint.setColor(0xFF244484); + for (int y = 0; y < h; y += 16) { + for (int x = 0; x < w; x += 16) { + canvas.save(); + canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); + canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); + canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); + canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); + canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); + canvas.restore(); + } + } + } + + SkString fName; + bool fIsSmall; + bool fInitialized; + SkBitmap fCheckerboard; + SkScalar fSigmaX, fSigmaY; + typedef SkBenchmark INHERITED; +}; + +DEF_BENCH(return new BlurImageFilterBench(p, BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true);) +DEF_BENCH(return new BlurImageFilterBench(p, BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false);) +DEF_BENCH(return new BlurImageFilterBench(p, BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true);) +DEF_BENCH(return new BlurImageFilterBench(p, BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, false);) + + diff --git a/bench/LightingBench.cpp b/bench/LightingBench.cpp new file mode 100644 index 0000000000..16c928fe2f --- /dev/null +++ b/bench/LightingBench.cpp @@ -0,0 +1,227 @@ +/* + * 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 "SkBitmapSource.h" +#include "SkCanvas.h" +#include "SkDevice.h" +#include "SkLightingImageFilter.h" + +#define FILTER_WIDTH_SMALL SkIntToScalar(32) +#define FILTER_HEIGHT_SMALL SkIntToScalar(32) +#define FILTER_WIDTH_LARGE SkIntToScalar(256) +#define FILTER_HEIGHT_LARGE SkIntToScalar(256) + +class LightingBaseBench : public SkBenchmark { +public: + LightingBaseBench(void* param, bool small) : INHERITED(param), fIsSmall(small) { + } + +protected: + void draw(SkCanvas* canvas, SkImageFilter* imageFilter) const { + SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) : + SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE); + SkPaint paint; + paint.setImageFilter(imageFilter)->unref(); + canvas->drawRect(r, paint); + } + + static SkPoint3 getPointLocation() { + static SkPoint3 pointLocation(0, 0, SkIntToScalar(10)); + return pointLocation; + } + + static SkPoint3 getDistantDirection() { + static SkScalar azimuthRad = SkDegreesToRadians(SkIntToScalar(225)); + static SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); + static SkPoint3 distantDirection(SkScalarMul(SkScalarCos(azimuthRad), + SkScalarCos(elevationRad)), + SkScalarMul(SkScalarSin(azimuthRad), + SkScalarCos(elevationRad)), + SkScalarSin(elevationRad)); + return distantDirection; + } + + static SkPoint3 getSpotLocation() { + static SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToScalar(20)); + return spotLocation; + } + + static SkPoint3 getSpotTarget() { + static SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0); + return spotTarget; + } + + static SkScalar getSpotExponent() { + static SkScalar spotExponent = SK_Scalar1; + return spotExponent; + } + + static SkScalar getCutoffAngle() { + static SkScalar cutoffAngle = SkIntToScalar(15); + return cutoffAngle; + } + + static SkScalar getKd() { + static SkScalar kd = SkIntToScalar(2); + return kd; + } + + static SkScalar getKs() { + static SkScalar ks = SkIntToScalar(1); + return ks; + } + + static SkScalar getShininess() { + static SkScalar shininess = SkIntToScalar(8); + return shininess; + } + + static SkScalar getSurfaceScale() { + static SkScalar surfaceScale = SkIntToScalar(1); + return surfaceScale; + } + + static SkColor getWhite() { + static SkColor white(0xFFFFFFFF); + return white; + } + + bool fIsSmall; + typedef SkBenchmark INHERITED; +}; + +class LightingPointLitDiffuseBench : public LightingBaseBench { +public: + LightingPointLitDiffuseBench(void* param, bool small) : INHERITED(param, small) { + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fIsSmall ? "lightingpointlitdiffuse_small" : "lightingpointlitdiffuse_large"; + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + draw(canvas, SkLightingImageFilter::CreatePointLitDiffuse(getPointLocation(), getWhite(), + getSurfaceScale(), getKd())); + } + +private: + typedef LightingBaseBench INHERITED; +}; + +class LightingDistantLitDiffuseBench : public LightingBaseBench { +public: + LightingDistantLitDiffuseBench(void* param, bool small) : INHERITED(param, small) { + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fIsSmall ? "lightingdistantlitdiffuse_small" : "lightingdistantlitdiffuse_large"; + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + draw(canvas, SkLightingImageFilter::CreateDistantLitDiffuse(getDistantDirection(), + getWhite(), getSurfaceScale(), getKd())); + } + +private: + typedef LightingBaseBench INHERITED; +}; + +class LightingSpotLitDiffuseBench : public LightingBaseBench { +public: + LightingSpotLitDiffuseBench(void* param, bool small) : INHERITED(param, small) { + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fIsSmall ? "lightingspotlitdiffuse_small" : "lightingspotlitdiffuse_large"; + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + draw(canvas, SkLightingImageFilter::CreateSpotLitDiffuse(getSpotLocation(), + getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), getSurfaceScale(), + getKd())); + } + +private: + typedef LightingBaseBench INHERITED; +}; + +class LightingPointLitSpecularBench : public LightingBaseBench { +public: + LightingPointLitSpecularBench(void* param, bool small) : INHERITED(param, small) { + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fIsSmall ? "lightingpointlitspecular_small" : "lightingpointlitspecular_large"; + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + draw(canvas, SkLightingImageFilter::CreatePointLitSpecular(getPointLocation(), getWhite(), + getSurfaceScale(), getKs(), getShininess())); + } + +private: + typedef LightingBaseBench INHERITED; +}; + +class LightingDistantLitSpecularBench : public LightingBaseBench { +public: + LightingDistantLitSpecularBench(void* param, bool small) : INHERITED(param, small) { + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fIsSmall ? "lightingdistantlitspecular_small" : "lightingdistantlitspecular_large"; + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + draw(canvas, SkLightingImageFilter::CreateDistantLitSpecular(getDistantDirection(), + getWhite(), getSurfaceScale(), getKs(), getShininess())); + } + +private: + typedef LightingBaseBench INHERITED; +}; + +class LightingSpotLitSpecularBench : public LightingBaseBench { +public: + LightingSpotLitSpecularBench(void* param, bool small) : INHERITED(param, small) { + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fIsSmall ? "lightingspotlitspecular_small" : "lightingspotlitspecular_large"; + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + draw(canvas, SkLightingImageFilter::CreateSpotLitSpecular(getSpotLocation(), + getSpotTarget(), getSpotExponent(), getCutoffAngle(), getWhite(), getSurfaceScale(), + getKs(), getShininess())); + } + +private: + typedef LightingBaseBench INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// + +DEF_BENCH( return new LightingPointLitDiffuseBench(p, true); ) +DEF_BENCH( return new LightingPointLitDiffuseBench(p, false); ) +DEF_BENCH( return new LightingDistantLitDiffuseBench(p, true); ) +DEF_BENCH( return new LightingDistantLitDiffuseBench(p, false); ) +DEF_BENCH( return new LightingSpotLitDiffuseBench(p, true); ) +DEF_BENCH( return new LightingSpotLitDiffuseBench(p, false); ) +DEF_BENCH( return new LightingPointLitSpecularBench(p, true); ) +DEF_BENCH( return new LightingPointLitSpecularBench(p, false); ) +DEF_BENCH( return new LightingDistantLitSpecularBench(p, true); ) +DEF_BENCH( return new LightingDistantLitSpecularBench(p, false); ) +DEF_BENCH( return new LightingSpotLitSpecularBench(p, true); ) +DEF_BENCH( return new LightingSpotLitSpecularBench(p, false); ) + diff --git a/gyp/bench.gypi b/gyp/bench.gypi index 8bae9b7588..baf7d4488d 100644 --- a/gyp/bench.gypi +++ b/gyp/bench.gypi @@ -12,6 +12,7 @@ '../bench/BitmapRectBench.cpp', '../bench/BlendBench.cpp', '../bench/BlurBench.cpp', + '../bench/BlurImageFilterBench.cpp', '../bench/BlurRectBench.cpp', '../bench/ChecksumBench.cpp', '../bench/ChartBench.cpp', @@ -27,6 +28,7 @@ '../bench/GrMemoryPoolBench.cpp', '../bench/InterpBench.cpp', '../bench/LineBench.cpp', + '../bench/LightingBench.cpp', '../bench/MagnifierBench.cpp', '../bench/MathBench.cpp', '../bench/Matrix44Bench.cpp', |