Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: bench/XfermodeBench.cpp

Issue 13334011: Add Xfermode bench. Also clear before rendering in bench (rather than after). (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | bench/benchmain.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "SkBenchmark.h"
10 #include "SkCanvas.h"
11 #include "SkPaint.h"
12 #include "SkRandom.h"
13 #include "SkString.h"
14 #include "SkXfermode.h"
15
16 // Benchmark that draws non-AA rects with an SkXfermode::Mode
17 class XfermodeBench : public SkBenchmark {
18 public:
19 XfermodeBench(void* param, SkXfermode::Mode mode) : SkBenchmark(param) {
20 fXfermode.reset(SkXfermode::Create(mode));
21 SkASSERT(NULL != fXfermode.get() || SkXfermode::kSrcOver_Mode == mode);
22 fName.printf("Xfermode_%s", SkXfermode::ModeName(mode));
23 }
24
25 protected:
26 virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); }
27
28 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
29 SkISize size = canvas->getDeviceSize();
30 SkMWCRandom random;
31 for (int i = 0; i < kNumRects; ++i) {
32 SkPaint paint;
33 paint.setXfermode(fXfermode.get());
34 paint.setColor(random.nextU());
35 SkScalar w = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntTo Scalar(kMaxSize));
36 SkScalar h = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntTo Scalar(kMaxSize));
37 SkRect rect = SkRect::MakeXYWH(
38 random.nextUScalar1() * (size.fWidth - w),
39 random.nextUScalar1() * (size.fHeight - h),
40 w,
41 h
42 );
43 canvas->drawRect(rect, paint);
44 }
45 }
46
47 private:
48 enum {
49 kNumRects = SkBENCHLOOP(1000),
50 kMinSize = 10,
51 kMaxSize = 400,
52 };
53 SkAutoTUnref<SkXfermode> fXfermode;
54 SkString fName;
55
56 typedef SkBenchmark INHERITED;
57 };
58
59 //////////////////////////////////////////////////////////////////////////////
60
61
robertphillips 2013/03/31 16:44:13 What about just adding a bench for each xfermode (
62 // These modes were chosen because they are expected to be successively harder f or the GPU.
63 // kSrc can disable blending, kSrcOver cannot, kDarken requires reading the dst pixel in the shader.
64 static SkBenchmark* Fact0(void* p) { return new XfermodeBench(p, SkXfermode::kSr c_Mode); }
65 static SkBenchmark* Fact1(void* p) { return new XfermodeBench(p, SkXfermode::kSr cOver_Mode); }
66 static SkBenchmark* Fact2(void* p) { return new XfermodeBench(p, SkXfermode::kDa rken_Mode); }
67
68 static BenchRegistry gReg0(Fact0);
69 static BenchRegistry gReg1(Fact1);
70 static BenchRegistry gReg2(Fact2);
OLDNEW
« no previous file with comments | « no previous file | bench/benchmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698