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

Side by Side Diff: bench/BlendBench.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 | « no previous file | bench/ColorFilterBench.cpp » ('j') | bench/ColorFilterBench.cpp » ('J')
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 "SkBlendImageFilter.h"
10 #include "SkCanvas.h"
11 #include "SkDevice.h"
12
13 class BlendBench : public SkBenchmark {
14 public:
15 BlendBench(void* param) : INHERITED(param) {
16 }
17
18 protected:
19 virtual const char* onGetName() SK_OVERRIDE {
20 return "blend";
21 }
22
23 virtual void onPreDraw() SK_OVERRIDE {
24 if (!fInitialized) {
25 make_bitmap();
26 make_checkerboard();
27 fInitialized = true;
28 }
29 }
30
31 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
32 canvas->clear(0x00000000);
33 SkPaint paint;
34 SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fChec kerboard)));
35 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
36 (SkBlendImageFilter::kNormal_Mode, background)))->unref();
Stephen White 2013/04/15 15:34:21 I think it would be better to break out each of th
sugoi1 2013/04/19 18:09:42 Done.
37 drawClippedBitmap(canvas, paint, 0);
38 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
39 (SkBlendImageFilter::kMultiply_Mode, background)))->unref();
40 drawClippedBitmap(canvas, paint, 100);
41 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
42 (SkBlendImageFilter::kScreen_Mode, background)))->unref();
43 drawClippedBitmap(canvas, paint, 200);
44 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
45 (SkBlendImageFilter::kDarken_Mode, background)))->unref();
46 drawClippedBitmap(canvas, paint, 300);
47 paint.setImageFilter(SkNEW_ARGS(SkBlendImageFilter,
48 (SkBlendImageFilter::kLighten_Mode, background)))->unref();
49 drawClippedBitmap(canvas, paint, 400);
50 }
51
52 private:
53 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x) {
54 canvas->save();
55 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), 0,
56 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())));
57 canvas->drawBitmap(fBitmap, SkIntToScalar(x), 0, &paint);
58 canvas->restore();
59 }
60
61 void make_bitmap() {
62 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
63 fBitmap.allocPixels();
64 SkDevice device(fBitmap);
65 SkCanvas canvas(&device);
66 canvas.clear(0x00000000);
67 SkPaint paint;
68 paint.setAntiAlias(true);
69 paint.setColor(0xD000D000);
70 paint.setTextSize(SkIntToScalar(96));
71 const char* str = "e";
72 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(65), paint);
73 }
74
75 void make_checkerboard() {
76 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
77 fCheckerboard.allocPixels();
78 SkDevice device(fCheckerboard);
79 SkCanvas canvas(&device);
80 canvas.clear(0x00000000);
81 SkPaint darkPaint;
82 darkPaint.setColor(0xFF404040);
83 SkPaint lightPaint;
84 lightPaint.setColor(0xFFA0A0A0);
85 for (int y = 0; y < 80; y += 16) {
86 for (int x = 0; x < 80; x += 16) {
87 canvas.save();
88 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
89 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
90 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
91 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
92 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
93 canvas.restore();
94 }
95 }
96 }
97
98 typedef SkBenchmark INHERITED;
99 SkBitmap fBitmap, fCheckerboard;
100 bool fInitialized;
101 };
102
103 ///////////////////////////////////////////////////////////////////////////////
104
105 DEF_BENCH( return new BlendBench(p); )
106
OLDNEW
« no previous file with comments | « no previous file | bench/ColorFilterBench.cpp » ('j') | bench/ColorFilterBench.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698