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

Side by Side Diff: bench/ImageFilterSpriteVsBitmap.cpp

Issue 1401173006: Add new bench to compare drawSprite() and drawBitmap(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | 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 2015 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
8 #include "Benchmark.h"
9 #include "SkOffsetImageFilter.h"
10 #include "SkGradientShader.h"
11 #include "SkCanvas.h"
12
13 static const int kWidth = 2048, kHeight = 2048;
14
15 class ImageFilterSpriteVsBitmapBench : public Benchmark {
16 public:
17 ImageFilterSpriteVsBitmapBench(bool useSprite) : fUseSprite(useSprite), fIni tialized(false) {}
18
19 protected:
20 const char* onGetName() override {
21 if (fUseSprite) {
22 return "image_filter_drawsprite";
23 } else {
24 return "image_filter_drawbitmap";
25 }
26 }
27
28 SkIPoint onGetSize() override {
29 return SkIPoint::Make(kWidth, kHeight);
30 }
31
32 void init() {
33 fBitmap.allocN32Pixels(kWidth, kHeight);
34 fBitmap.eraseColor(SK_ColorTRANSPARENT);
35
36 SkCanvas canvas(fBitmap);
37 SkPaint paint;
38 SkPoint pts[] = { {0, 0}, {SkIntToScalar(kWidth), SkIntToScalar(kHeight) } };
39 SkColor colors[] = {
40 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN,
41 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE
42 };
43 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(
44 pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kCla mp_TileMode
45 ));
46 paint.setShader(shader);
47 canvas.drawPaint(paint);
48 }
49
50 void onDraw(int loops, SkCanvas* canvas) override {
51 if (!fInitialized) {
52 init();
53 fInitialized = true;
54 }
55 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(SK_Scalar 1, SK_Scalar1));
56 SkPaint paint;
57 paint.setImageFilter(filter);
58 canvas->clipRect(SkRect::Make(fBitmap.bounds()));
59 for (int j = 0; j < loops; j++) {
60 if (fUseSprite) {
61 canvas->drawSprite(fBitmap, 0, 0, &paint);
62 } else {
63 canvas->drawBitmap(fBitmap, 0, 0, &paint);
64 }
65 }
66 }
67
68 private:
69 typedef Benchmark INHERITED;
70 SkBitmap fBitmap;
71 bool fUseSprite;
72 bool fInitialized;
73 };
74
75 DEF_BENCH(return new ImageFilterSpriteVsBitmapBench(true);)
76 DEF_BENCH(return new ImageFilterSpriteVsBitmapBench(false);)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698