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

Side by Side Diff: bench/ImageBench.cpp

Issue 1534443003: remove drawSprite from canvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: really tired of unused variable warnings 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 | gm/dropshadowimagefilter.cpp » ('j') | src/core/SkPicturePlayback.cpp » ('J')
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DEF_BENCH( return new Image2RasterBench; )
65
66 //////////////////////////////////////////////////////////////////////////////// ///////////////////
67
68 #include "SkOffsetImageFilter.h"
69
70 #if SK_SUPPORT_GPU
71 #include "SkGrPixelRef.h"
72 #endif
73
74 enum MyDrawType {
75 kSprite_Type,
76 kBitmap_Type,
77 kImage_Type,
78 };
79
80 /*
81 * Want to time drawing images/bitmaps via drawSprite, and via drawBitmap/drawI mage but with
82 * a non-scaling matrix and a clip that is tight to the image bounds. In this s cenario, we
83 * should be able to match the speed of drawSprite.
84 *
85 * An optimal result should be that all three types: sprite/bitmap/image draw a t the same speed.
86 */
87 class ImageFilterSpriteBench : public Benchmark {
88 SkAutoTUnref<SkImage> fImage;
89 SkBitmap fBitmap;
90 SkString fName;
91 MyDrawType fType;
92
93 public:
94 ImageFilterSpriteBench(MyDrawType dt, const char suffix[]) : fType(dt) {
95 fName.printf("image-filter-sprite-draw-%s", suffix);
96 }
97
98 bool isSuitableFor(Backend backend) override {
99 return kGPU_Backend == backend || kRaster_Backend == backend;
100 }
101
102 protected:
103 bool isVisual() override {
104 return true;
105 }
106
107 const char* onGetName() override {
108 return fName.c_str();
109 }
110
111 void onPerCanvasPreDraw(SkCanvas* canvas) override {
112 const SkImageInfo info = SkImageInfo::MakeN32Premul(500, 500);
113 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
114
115 surface->getCanvas()->drawColor(SK_ColorRED);
116 fImage.reset(surface->newImageSnapshot());
117
118 fBitmap.setInfo(info);
119 if (fImage->getTexture()) {
120 #if SK_SUPPORT_GPU
121 fBitmap.setPixelRef(new SkGrPixelRef(info, fImage->getTexture()))->u nref();
122 #endif
123 } else {
124 SkPixmap pmap;
125 if (!fImage->peekPixels(&pmap)) {
126 sk_throw();
127 }
128 fBitmap.installPixels(pmap);
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 fImage.reset(nullptr);
136 fBitmap.reset();
137 }
138
139 void onDraw(int loops, SkCanvas* canvas) override {
140 // This clip is important; it allows the drawImage/drawBitmap code to fa ll into the
141 // fast (sprite) case, since the imagefilter's output should match.
142 //
143 // When we address skbug.com/4526 we should be able to remove the need f or this clip.
144 //
145 canvas->clipRect(SkRect::MakeIWH(fImage->width(), fImage->height()));
146
147 const SkScalar kDelta = 10;
148 SkPaint paint;
149 for (int i = 0; i < loops; i++) {
150 for (int inner = 0; inner < 10; ++inner) {
151 // build the filter everytime, so we don't accidentally draw a c ached version,
152 // since the point of this bench is to time the actual imagefilt er
153 // handling/overhead.
154 SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(k Delta, kDelta));
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 | gm/dropshadowimagefilter.cpp » ('j') | src/core/SkPicturePlayback.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698