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

Side by Side Diff: bench/GeometryBench.cpp

Issue 640723004: cleanup and optimize rect intersect routines (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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 | bench/RegionBench.cpp » ('j') | src/core/SkRect.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 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 "SkGeometry.h"
10 #include "SkRandom.h"
11 #include "SkRect.h"
12
13 class GeometryBench : public Benchmark {
14 public:
15 GeometryBench(const char suffix[]) : fVolatileInt(0) {
16 fName.printf("geo_%s", suffix);
17 }
18
19 virtual const char* onGetName() SK_OVERRIDE {
20 return fName.c_str();
21 }
22
23 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
24 return kNonRendering_Backend == backend;
25 }
26
27 protected:
28 volatile int fVolatileInt;
29
30 virtual void virtualCallToFoilOptimizers(int) {}
31
32 private:
33 SkString fName;
34 };
35
36 class GeoRectBench : public GeometryBench {
37 public:
38 GeoRectBench(const char suffix[]) : GeometryBench(suffix) {}
39
40 protected:
41 SkRect fRects[2048];
42
43 virtual void onPreDraw() {
44 const SkScalar min = -100;
45 const SkScalar max = 100;
46 SkRandom rand;
47 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
48 SkScalar x = rand.nextRangeScalar(min, max);
49 SkScalar y = rand.nextRangeScalar(min, max);
50 SkScalar w = rand.nextRangeScalar(min, max);
51 SkScalar h = rand.nextRangeScalar(min, max);
52 fRects[i].setXYWH(x, y, w, h);
53 }
54 }
55 };
56
57 class GeoRectBench_intersect : public GeoRectBench {
58 public:
59 GeoRectBench_intersect() : GeoRectBench("rect_intersect") {}
60
61 protected:
62 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
63 for (int outer = 0; outer < loops; ++outer) {
64 int count = 0;
65 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
66 SkRect r = fRects[0];
67 count += r.intersect(fRects[i]);
68 }
69 this->virtualCallToFoilOptimizers(count);
70 }
71 }
72 };
73
74 class GeoRectBench_intersect_rect : public GeoRectBench {
75 public:
76 GeoRectBench_intersect_rect() : GeoRectBench("rect_intersect_rect") {}
77
78 protected:
79 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
80 for (int outer = 0; outer < loops; ++outer) {
81 int count = 0;
82 SkRect r;
83 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
84 count += r.intersect(fRects[0], fRects[i]);
85 }
86 this->virtualCallToFoilOptimizers(count);
87 }
88 }
89 };
90
91 class GeoRectBench_Intersects : public GeoRectBench {
92 public:
93 GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {}
94
95 protected:
96 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
97 for (int outer = 0; outer < loops; ++outer) {
98 int count = 0;
99 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
100 fVolatileInt += SkRect::Intersects(fRects[0], fRects[i]);
101 }
102 this->virtualCallToFoilOptimizers(count);
103 }
104 }
105 };
106
107 DEF_BENCH( return new GeoRectBench_intersect; )
108 DEF_BENCH( return new GeoRectBench_intersect_rect; )
109 DEF_BENCH( return new GeoRectBench_Intersects; )
OLDNEW
« no previous file with comments | « no previous file | bench/RegionBench.cpp » ('j') | src/core/SkRect.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698