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

Side by Side Diff: bench/ImageBench.cpp

Issue 1497843003: add bench for sprite-like drawing w/ imagefilters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkImage.h" 10 #include "SkImage.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 } 55 }
56 56
57 private: 57 private:
58 SkString fName; 58 SkString fName;
59 SkAutoTUnref<SkImage> fImage; 59 SkAutoTUnref<SkImage> fImage;
60 SkAutoTUnref<SkSurface> fRasterSurface; 60 SkAutoTUnref<SkSurface> fRasterSurface;
61 61
62 typedef Benchmark INHERITED; 62 typedef Benchmark INHERITED;
63 }; 63 };
64 DEF_BENCH( return new Image2RasterBench; )
64 65
66 //////////////////////////////////////////////////////////////////////////////// ///////////////////
65 67
66 DEF_BENCH( return new Image2RasterBench; ) 68 #include "SkBlurImageFilter.h"
69 #include "SkGrPixelRef.h"
70
71 enum MyDrawType {
72 kSprite_Type,
73 kBitmap_Type,
74 kImage_Type,
75 };
76
77 /*
78 * Want to time drawing images/bitmaps via drawSprite, and via drawBitmap/drawI mage but with
79 * a non-scaling matrix and a clip that is tight to the image bounds. In this s cenario, we
80 * should be able to match the speed of drawSprite.
81 *
82 * An optimal result should be that all three types: sprite/bitmap/image draw a t the same speed.
83 */
84 class ImageFilterSpriteBench : public Benchmark {
robertphillips 2015/12/03 19:30:56 Why do we keep the SkSurface around - can't it be
reed1 2015/12/03 19:37:16 Done.
85 SkAutoTUnref<SkSurface> fSurface;
86 SkAutoTUnref<SkImage> fImage;
87 SkBitmap fBitmap;
robertphillips 2015/12/03 19:30:56 fFilter doesn't seem to be really used ?
reed1 2015/12/03 19:37:15 Done.
88 SkAutoTUnref<SkImageFilter> fFilter;
89 SkString fName;
90 MyDrawType fType;
91
92 public:
93 ImageFilterSpriteBench(MyDrawType dt, const char suffix[]) : fType(dt) {
94 fName.printf("image-filter-sprite-draw-%s", suffix);
95
robertphillips 2015/12/03 19:30:56 kSigma ?
reed1 2015/12/03 19:37:16 Done.
96 const SkScalar sigma = 10;
97 fFilter.reset(SkBlurImageFilter::Create(sigma, sigma));
98 }
99
100 bool isSuitableFor(Backend backend) override {
101 return kGPU_Backend == backend || kRaster_Backend == backend;
102 }
103
104 protected:
105 bool isVisual() override {
106 return true;
107 }
108
109 const char* onGetName() override {
110 return fName.c_str();
111 }
112
113 void onPerCanvasPreDraw(SkCanvas* canvas) override {
114 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
115 fSurface.reset(canvas->newSurface(info));
116
117 fSurface->getCanvas()->drawColor(SK_ColorRED);
118 fImage.reset(fSurface->newImageSnapshot());
119
120 fBitmap.setInfo(info);
121 if (fImage->getTexture()) {
122 fBitmap.setPixelRef(new SkGrPixelRef(info, fImage->getTexture()))->u nref();
123 } else {
124 SkPixmap pmap;
125 if (!fImage->peekPixels(&pmap)) {
126 sk_throw();
127 }
128 fBitmap.installPixels(pmap.info(), pmap.writable_addr(), pmap.rowByt es());
129 }
130 }
131
132 void onPerCanvasPostDraw(SkCanvas*) override {
133 // Release the image and raster surface here to prevent out of order des truction
134 // between these and the gpu interface.
135 fSurface.reset(nullptr);
136 fImage.reset(nullptr);
137 fBitmap.reset();
138 }
139
140 void onDraw(int loops, SkCanvas* canvas) override {
141 // This clip is important; it allows the drawImage/drawBitmap code to fa ll into the
142 // fast (sprite) case, since the imagefilter's output should match.
143 //
144 // When we address skbug.com/4526 we should be able to remove the need f or this clip.
145 //
146 canvas->clipRect(SkRect::MakeIWH(fImage->width(), fImage->height()));
147
robertphillips 2015/12/03 19:30:56 kSigma ?
reed1 2015/12/03 19:37:16 Done.
148 const SkScalar sigma = 10;
149 SkPaint paint;
150 for (int i = 0; i < loops; i++) {
151 for (int inner = 0; inner < 10; ++inner) {
152 // build the filter everytime, so we don't accidentally draw a c ached version,
153 // since the point of this bench is to time the actual blurring/ drawing process.
154 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(sig ma, sigma));
155 paint.setImageFilter(filter);
156
157 switch (fType) {
158 case kSprite_Type:
159 canvas->drawSprite(fBitmap, 0, 0, &paint);
160 break;
161 case kBitmap_Type:
162 canvas->drawBitmap(fBitmap, 0, 0, &paint);
163 break;
164 case kImage_Type:
165 canvas->drawImage(fImage, 0, 0, &paint);
166 break;
167 }
168 }
169 }
170 }
171
172 private:
173 typedef Benchmark INHERITED;
174 };
175 DEF_BENCH( return new ImageFilterSpriteBench(kSprite_Type, "sprite"); )
176 DEF_BENCH( return new ImageFilterSpriteBench(kBitmap_Type, "bitmap"); )
177 DEF_BENCH( return new ImageFilterSpriteBench(kImage_Type, "image"); )
178
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