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

Side by Side Diff: bench/MergeBench.cpp

Issue 14234019: Added a few bench for some image filters (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 | « bench/MagnifierBench.cpp ('k') | gyp/bench.gypi » ('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 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkBenchmark.h"
8 #include "SkBitmapSource.h"
9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h"
11 #include "SkDevice.h"
12 #include "SkMergeImageFilter.h"
13
14 #define FILTER_WIDTH_SMALL SkIntToScalar(32)
15 #define FILTER_HEIGHT_SMALL SkIntToScalar(32)
16 #define FILTER_WIDTH_LARGE SkIntToScalar(256)
17 #define FILTER_HEIGHT_LARGE SkIntToScalar(256)
18
19 class MergeBench : public SkBenchmark {
20 public:
21 MergeBench(void* param, bool small) : INHERITED(param), fIsSmall(small), fIn itialized(false) {
22 }
23
24 protected:
25 virtual const char* onGetName() SK_OVERRIDE {
26 return fIsSmall ? "merge_small" : "merge_large";
27 }
28
29 virtual void onPreDraw() SK_OVERRIDE {
30 if (!fInitialized) {
31 make_bitmap();
32 make_checkerboard();
33 fInitialized = true;
34 }
35 }
36
37 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
38 SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_S MALL) :
39 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L ARGE);
40 SkPaint paint;
41 paint.setImageFilter(mergeBitmaps())->unref();
42 canvas->drawRect(r, paint);
43 }
44
45 private:
46 SkImageFilter* mergeBitmaps() {
47 SkImageFilter* first = new SkBitmapSource(fCheckerboard);
48 SkImageFilter* second = new SkBitmapSource(fBitmap);
49 SkAutoUnref aur0(first);
50 SkAutoUnref aur1(second);
51 return new SkMergeImageFilter(first, second);
52 }
53
54 void make_bitmap() {
55 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
56 fBitmap.allocPixels();
57 SkDevice device(fBitmap);
58 SkCanvas canvas(&device);
59 canvas.clear(0x00000000);
60 SkPaint paint;
61 paint.setAntiAlias(true);
62 paint.setColor(0xFF884422);
63 paint.setTextSize(SkIntToScalar(96));
64 const char* str = "g";
65 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint);
66 }
67
68 void make_checkerboard() {
69 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
70 fCheckerboard.allocPixels();
71 SkDevice device(fCheckerboard);
72 SkCanvas canvas(&device);
73 canvas.clear(0x00000000);
74 SkPaint darkPaint;
75 darkPaint.setColor(0xFF804020);
76 SkPaint lightPaint;
77 lightPaint.setColor(0xFF244484);
78 for (int y = 0; y < 80; y += 16) {
79 for (int x = 0; x < 80; x += 16) {
80 canvas.save();
81 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
82 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
83 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
84 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
85 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
86 canvas.restore();
87 }
88 }
89 }
90
91 bool fIsSmall;
92 bool fInitialized;
93 SkBitmap fBitmap, fCheckerboard;
94
95 typedef SkBenchmark INHERITED;
96 };
97
98 ///////////////////////////////////////////////////////////////////////////////
99
100 DEF_BENCH( return new MergeBench(p, true); )
101 DEF_BENCH( return new MergeBench(p, false); )
102
OLDNEW
« no previous file with comments | « bench/MagnifierBench.cpp ('k') | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698