1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkBlurMask.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRandom.h"
#include "SkShader.h"
#include "SkString.h"
class BitmapScaleBench: public Benchmark {
int fLoopCount;
int fInputSize;
int fOutputSize;
SkString fName;
public:
BitmapScaleBench( int is, int os) {
fInputSize = is;
fOutputSize = os;
fLoopCount = 20;
}
protected:
SkBitmap fInputBitmap, fOutputBitmap;
SkMatrix fMatrix;
const char* onGetName() override {
return fName.c_str();
}
int inputSize() const {
return fInputSize;
}
int outputSize() const {
return fOutputSize;
}
float scale() const {
return float(outputSize())/inputSize();
}
SkIPoint onGetSize() override {
return SkIPoint::Make( fOutputSize, fOutputSize );
}
void setName(const char * name) {
fName.printf( "bitmap_scale_%s_%d_%d", name, fInputSize, fOutputSize );
}
void onDelayedSetup() override {
fInputBitmap.allocN32Pixels(fInputSize, fInputSize, true);
fInputBitmap.eraseColor(SK_ColorWHITE);
fOutputBitmap.allocN32Pixels(fOutputSize, fOutputSize, true);
fMatrix.setScale( scale(), scale() );
}
void onDraw(int loops, SkCanvas*) override {
SkPaint paint;
this->setupPaint(&paint);
preBenchSetup();
for (int i = 0; i < loops; i++) {
doScaleImage();
}
}
virtual void doScaleImage() = 0;
virtual void preBenchSetup() {}
private:
typedef Benchmark INHERITED;
};
class BitmapFilterScaleBench: public BitmapScaleBench {
public:
BitmapFilterScaleBench( int is, int os) : INHERITED(is, os) {
setName( "filter" );
}
protected:
void doScaleImage() override {
SkCanvas canvas( fOutputBitmap );
SkPaint paint;
paint.setFilterQuality(kHigh_SkFilterQuality);
fInputBitmap.notifyPixelsChanged();
canvas.concat(fMatrix);
canvas.drawBitmap(fInputBitmap, 0, 0, &paint );
}
private:
typedef BitmapScaleBench INHERITED;
};
DEF_BENCH(return new BitmapFilterScaleBench(10, 90);)
DEF_BENCH(return new BitmapFilterScaleBench(30, 90);)
DEF_BENCH(return new BitmapFilterScaleBench(80, 90);)
DEF_BENCH(return new BitmapFilterScaleBench(90, 90);)
DEF_BENCH(return new BitmapFilterScaleBench(90, 80);)
DEF_BENCH(return new BitmapFilterScaleBench(90, 30);)
DEF_BENCH(return new BitmapFilterScaleBench(90, 10);)
DEF_BENCH(return new BitmapFilterScaleBench(256, 64);)
DEF_BENCH(return new BitmapFilterScaleBench(64, 256);)
///////////////////////////////////////////////////////////////////////////////////////////////
#include "SkBitmapScaler.h"
class PixmapScalerBench: public Benchmark {
SkBitmapScaler::ResizeMethod fMethod;
SkString fName;
SkBitmap fSrc, fDst;
public:
PixmapScalerBench(SkBitmapScaler::ResizeMethod method, const char suffix[]) : fMethod(method) {
fName.printf("pixmapscaler_%s", suffix);
}
protected:
const char* onGetName() override {
return fName.c_str();
}
SkIPoint onGetSize() override { return{ 100, 100 }; }
bool isSuitableFor(Backend backend) override {
return backend == kNonRendering_Backend;
}
void onDelayedSetup() override {
fSrc.allocN32Pixels(640, 480);
fSrc.eraseColor(SK_ColorWHITE);
fDst.allocN32Pixels(300, 250);
}
void onDraw(int loops, SkCanvas*) override {
SkPixmap src, dst;
fSrc.peekPixels(&src);
fDst.peekPixels(&dst);
for (int i = 0; i < loops * 16; i++) {
SkBitmapScaler::Resize(dst, src, fMethod);
}
}
private:
typedef Benchmark INHERITED;
};
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_LANCZOS3, "lanczos"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_MITCHELL, "mitchell"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_HAMMING, "hamming"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_TRIANGLE, "triangle"); )
DEF_BENCH( return new PixmapScalerBench(SkBitmapScaler::RESIZE_BOX, "box"); )
|