Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(198)

Unified Diff: bench/ChromeBench.cpp

Issue 6298071: New chrome-inspired benchmark Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 13 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/ChromeBench.cpp
===================================================================
--- bench/ChromeBench.cpp (revision 4236)
+++ bench/ChromeBench.cpp (working copy)
@@ -5,8 +5,10 @@
* found in the LICENSE file.
*/
#include "SkBenchmark.h"
+#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkPaint.h"
+#include "SkShader.h"
#include "SkString.h"
/**
@@ -491,11 +493,80 @@
typedef SkBenchmark INHERITED;
};
+/// Emulate http://wrapbootstrap.com/preview/WB003517L: tiled alpha-blended
+/// pattern scrolling from frame to frame.
+/// TODO: add soft clipping?
+class AnimateBarBench : public SkBenchmark {
+ SkPaint fPaint;
+ SkPath fClipPath;
+ bool fInit;
+ enum {
+ W = 800,
+ H = 600
+ };
+public:
+ AnimateBarBench(void* param) : INHERITED(param), fInit(false) { }
+
+protected:
+
+ virtual const char* onGetName() { return "chrome_animateBar"; }
+ virtual void onDraw(SkCanvas* canvas) {
+ // Avoid drawing during the constructor
+ if (!fInit) {
+ setup();
+ }
+ SkRect r = SkRect::MakeWH(SkIntToScalar(800), SkIntToScalar(20));
+ SkMatrix m;
+ m.reset();
+ canvas->clipPath(fClipPath, SkRegion::kReplace_Op, true);
+ for (int i = 0; i < SkBENCHLOOP(200); i++) {
+ SkShader* s = fPaint.getShader();
+ m.setTranslateX(SkIntToScalar(i));
+ s->setLocalMatrix(m);
+ canvas->drawRect(r, fPaint);
+ }
+ }
+
+ virtual SkIPoint onGetSize() { return SkIPoint::Make(W, H); }
+
+private:
+
+ void setup() {
+ this->setupPaint(&fPaint);
+ fPaint.setAntiAlias(true);
+ SkMaskFilter* mf = SkBlurMaskFilter::Create(2.0f,
+ SkBlurMaskFilter::kInner_BlurStyle, 0);
+ fPaint.setMaskFilter(mf)->unref();
+ SkBitmap bm;
+ bm.setConfig(SkBitmap::kARGB_8888_Config, 40, 40);
+ bm.allocPixels();
+ bm.eraseColor(0);
+ SkShader* s = SkShader::CreateBitmapShader(bm,
+ SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode);
+ fPaint.setShader(s)->unref();
+
+ SkRect clipRect;
+ clipRect.set(SkIntToScalar(0), SkIntToScalar(0),
+ SkIntToScalar(800), SkIntToScalar(20));
+ fClipPath.addRoundRect(clipRect, SkIntToScalar(5), SkIntToScalar(5));
+
+ fInit = true;
+ }
+
+ typedef SkBenchmark INHERITED;
+};
+
+
+
static SkBenchmark* ScrollGmailFactory(void* p) {
return SkNEW_ARGS(ScrollGmailBench, (p));
}
+static SkBenchmark* AnimateBarFactory(void* p) {
+ return SkNEW_ARGS(AnimateBarBench, (p));
+}
// Disabled this benchmark: it takes 15x longer than any other benchmark
// and is probably not giving us important information.
//static BenchRegistry gScrollGmailReg(ScrollGmailFactory);
+static BenchRegistry gAnimateBarReg(AnimateBarFactory);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b