2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkMatrix44.h"
13 class Matrix44Bench : public Benchmark {
16 Matrix44Bench(const char name[]) {
17 fName.printf("matrix44_%s", name);
20 bool isSuitableFor(Backend backend) SK_OVERRIDE {
21 return backend == kNonRendering_Backend;
24 virtual void performTest() = 0;
27 virtual int mulLoopCount() const { return 1; }
29 virtual const char* onGetName() {
33 virtual void onDraw(const int loops, SkCanvas*) {
34 for (int i = 0; i < loops; i++) {
40 typedef Benchmark INHERITED;
43 class EqualsMatrix44Bench : public Matrix44Bench {
47 , fM0(SkMatrix44::kIdentity_Constructor)
48 , fM1(SkMatrix44::kIdentity_Constructor)
49 , fM2(SkMatrix44::kIdentity_Constructor)
55 virtual void performTest() {
56 for (int i = 0; i < 10; ++i) {
63 SkMatrix44 fM0, fM1, fM2;
64 typedef Matrix44Bench INHERITED;
67 class SetIdentityMatrix44Bench : public Matrix44Bench {
69 SetIdentityMatrix44Bench()
70 : INHERITED("setidentity")
71 , mat(SkMatrix44::kIdentity_Constructor)
78 mat.setRowMajord(rowMajor);
81 virtual void performTest() {
82 for (int i = 0; i < 10; ++i) {
88 typedef Matrix44Bench INHERITED;
91 class PreScaleMatrix44Bench : public Matrix44Bench {
93 PreScaleMatrix44Bench()
94 : INHERITED("prescale")
95 , fM0(SkMatrix44::kUninitialized_Constructor)
97 fX = fY = fZ = SkDoubleToMScalar(1.5);
100 virtual void performTest() {
102 for (int i = 0; i < 10; ++i) {
103 fM0.preScale(fX, fY, fZ);
108 SkMScalar fX, fY, fZ;
109 typedef Matrix44Bench INHERITED;
112 class InvertMatrix44Bench : public Matrix44Bench {
114 InvertMatrix44Bench()
115 : INHERITED("invert")
116 , fM0(SkMatrix44::kUninitialized_Constructor)
117 , fM1(SkMatrix44::kUninitialized_Constructor)
130 fM0.set(2, 3, -12.1);
131 fM0.set(3, 0, -13.1);
133 fM0.set(3, 2, -15.1);
137 virtual void performTest() {
138 for (int i = 0; i < 10; ++i) {
144 typedef Matrix44Bench INHERITED;
147 class InvertAffineMatrix44Bench : public Matrix44Bench {
149 InvertAffineMatrix44Bench()
150 : INHERITED("invertaffine")
151 , fM0(SkMatrix44::kIdentity_Constructor)
152 , fM1(SkMatrix44::kUninitialized_Constructor)
165 fM0.set(2, 3, -12.1);
166 // bottom row (perspective component) remains (0, 0, 0, 1).
169 virtual void performTest() {
170 for (int i = 0; i < 10; ++i) {
176 typedef Matrix44Bench INHERITED;
179 class InvertScaleTranslateMatrix44Bench : public Matrix44Bench {
181 InvertScaleTranslateMatrix44Bench()
182 : INHERITED("invertscaletranslate")
183 , fM0(SkMatrix44::kIdentity_Constructor)
184 , fM1(SkMatrix44::kUninitialized_Constructor)
193 fM0.set(2, 3, -12.1);
196 virtual void performTest() {
197 for (int i = 0; i < 10; ++i) {
203 typedef Matrix44Bench INHERITED;
206 class InvertTranslateMatrix44Bench : public Matrix44Bench {
208 InvertTranslateMatrix44Bench()
209 : INHERITED("inverttranslate")
210 , fM0(SkMatrix44::kIdentity_Constructor)
211 , fM1(SkMatrix44::kUninitialized_Constructor)
215 fM0.set(2, 3, -12.1);
218 virtual void performTest() {
219 for (int i = 0; i < 10; ++i) {
225 typedef Matrix44Bench INHERITED;
228 class PostScaleMatrix44Bench : public Matrix44Bench {
230 PostScaleMatrix44Bench()
231 : INHERITED("postscale")
232 , fM0(SkMatrix44::kUninitialized_Constructor)
234 fX = fY = fZ = SkDoubleToMScalar(1.5);
237 virtual void performTest() {
239 for (int i = 0; i < 10; ++i) {
240 fM0.postScale(fX, fY, fZ);
245 SkMScalar fX, fY, fZ;
246 typedef Matrix44Bench INHERITED;
249 class SetConcatMatrix44Bench : public Matrix44Bench {
251 SetConcatMatrix44Bench()
252 : INHERITED("setconcat")
253 , fM0(SkMatrix44::kUninitialized_Constructor)
254 , fM1(SkMatrix44::kUninitialized_Constructor)
255 , fM2(SkMatrix44::kUninitialized_Constructor)
257 fX = fY = fZ = SkDoubleToMScalar(1.5);
258 fM1.setScale(fX, fY, fZ);
259 fM2.setTranslate(fX, fY, fZ);
262 virtual void performTest() {
263 fM0.reset(); // just to normalize this test with prescale/postscale
264 for (int i = 0; i < 10; ++i) {
265 fM0.setConcat(fM1, fM2);
269 SkMatrix44 fM0, fM1, fM2;
270 SkMScalar fX, fY, fZ;
271 typedef Matrix44Bench INHERITED;
274 class GetTypeMatrix44Bench : public Matrix44Bench {
276 GetTypeMatrix44Bench()
277 : INHERITED("gettype")
278 , fMatrix(SkMatrix44::kIdentity_Constructor)
281 // Putting random generation of the matrix inside performTest()
282 // would help us avoid anomalous runs, but takes up 25% or
283 // more of the function time.
284 virtual void performTest() {
285 for (int i = 0; i < 20; ++i) {
286 fMatrix.set(1, 2, 1); // to invalidate the type-cache
292 typedef Matrix44Bench INHERITED;
295 DEF_BENCH( return new SetIdentityMatrix44Bench(); )
296 DEF_BENCH( return new EqualsMatrix44Bench(); )
297 DEF_BENCH( return new PreScaleMatrix44Bench(); )
298 DEF_BENCH( return new PostScaleMatrix44Bench(); )
299 DEF_BENCH( return new InvertMatrix44Bench(); )
300 DEF_BENCH( return new InvertAffineMatrix44Bench(); )
301 DEF_BENCH( return new InvertScaleTranslateMatrix44Bench(); )
302 DEF_BENCH( return new InvertTranslateMatrix44Bench(); )
303 DEF_BENCH( return new SetConcatMatrix44Bench(); )
304 DEF_BENCH( return new GetTypeMatrix44Bench(); )