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

Side by Side Diff: cc/region.h

Issue 11369103: Compare SkRegion and android::Region performance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « cc/cc.gyp ('k') | cc/region.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_REGION_H_ 5 #ifndef CC_REGION_H_
6 #define CC_REGION_H_ 6 #define CC_REGION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "cc/cc_export.h" 11 #include "cc/cc_export.h"
12 #include "ui/gfx/rect.h"
13
14 #define USE_ANDROID_REGION
15
16 #ifdef USE_ANDROID_REGION
17 #include "cc/android_region.h"
18 #else
12 #include "third_party/skia/include/core/SkRegion.h" 19 #include "third_party/skia/include/core/SkRegion.h"
13 #include "ui/gfx/rect.h" 20 #endif
14 21
15 namespace cc { 22 namespace cc {
16 23
17 class CC_EXPORT Region { 24 class CC_EXPORT Region {
18 public: 25 public:
19 Region(); 26 Region();
20 Region(const Region& region); 27 Region(const Region& region);
21 Region(gfx::Rect rect); 28 Region(gfx::Rect rect);
22 ~Region(); 29 ~Region();
23 30
24 const Region& operator=(gfx::Rect rect); 31 const Region& operator=(gfx::Rect rect);
25 const Region& operator=(const Region& region); 32 const Region& operator=(const Region& region);
26 33
27 bool IsEmpty() const; 34 bool IsEmpty() const;
28 35
29 bool Contains(gfx::Point point) const; 36 bool Contains(gfx::Point point) const;
30 bool Contains(gfx::Rect rect) const; 37 bool Contains(gfx::Rect rect) const;
31 bool Contains(const Region& region) const; 38 bool Contains(const Region& region) const;
32 39
33 bool Intersects(gfx::Rect rect) const; 40 bool Intersects(gfx::Rect rect) const;
34 bool Intersects(const Region& region) const; 41 bool Intersects(const Region& region) const;
35 42
36 void Subtract(gfx::Rect rect); 43 void Subtract(gfx::Rect rect);
37 void Subtract(const Region& region); 44 void Subtract(const Region& region);
38 void Union(gfx::Rect rect); 45 void Union(gfx::Rect rect);
39 void Union(const Region& region); 46 void Union(const Region& region);
40 void Intersect(gfx::Rect rect); 47 void Intersect(gfx::Rect rect);
41 void Intersect(const Region& region); 48 void Intersect(const Region& region);
42 49
43 bool Equals(const Region& other) const { return skregion_ == other.skregion_; } 50 bool Equals(const Region& other) const;
44 51
45 gfx::Rect bounds() const { 52 gfx::Rect bounds() const {
53 #ifdef USE_ANDROID_REGION
54 SkIRect r = droidregion_.bounds();
55 #else
46 SkIRect r = skregion_.getBounds(); 56 SkIRect r = skregion_.getBounds();
57 #endif
47 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists. 58 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists.
48 return gfx::Rect(r.x(), r.y(), r.width(), r.height()); 59 return gfx::Rect(r.x(), r.y(), r.width(), r.height());
49 } 60 }
50 61
51 std::string ToString() const; 62 std::string ToString() const;
52 63
53 class Iterator { 64 class Iterator {
54 public: 65 public:
55 Iterator(const Region& region); 66 Iterator(const Region& region);
56 ~Iterator(); 67 ~Iterator();
57 68
58 gfx::Rect rect() const { 69 gfx::Rect rect() const {
70 #ifdef USE_ANDROID_REGION
71 SkIRect r = *it_;
72 #else
59 SkIRect r = it_.rect(); 73 SkIRect r = it_.rect();
74 #endif
60 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists. 75 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists.
61 return gfx::Rect(r.x(), r.y(), r.width(), r.height()); 76 return gfx::Rect(r.x(), r.y(), r.width(), r.height());
62 } 77 }
63 78
64 void next() { 79 void next() {
80 #ifdef USE_ANDROID_REGION
81 ++it_;
82 #else
65 it_.next(); 83 it_.next();
84 #endif
66 } 85 }
67 bool has_rect() const { 86 bool has_rect() const {
87 #ifdef USE_ANDROID_REGION
88 return it_ != droidregion_.end();
89 #else
68 return !it_.done(); 90 return !it_.done();
91 #endif
69 } 92 }
70 93
71 private: 94 private:
95 #ifdef USE_ANDROID_REGION
96 const android::Region& droidregion_;
97 android::Region::const_iterator it_;
98 #else
72 SkRegion::Iterator it_; 99 SkRegion::Iterator it_;
100 #endif
73 }; 101 };
74 102
75 private: 103 private:
104 #ifdef USE_ANDROID_REGION
105 android::Region droidregion_;
106 #else
76 SkRegion skregion_; 107 SkRegion skregion_;
108 #endif
77 }; 109 };
78 110
79 inline bool operator==(const Region& a, const Region& b) { 111 inline bool operator==(const Region& a, const Region& b) {
80 return a.Equals(b); 112 return a.Equals(b);
81 } 113 }
82 114
83 inline bool operator!=(const Region& a, const Region& b) { 115 inline bool operator!=(const Region& a, const Region& b) {
84 return !(a == b); 116 return !(a == b);
85 } 117 }
86 118
(...skipping 29 matching lines...) Expand all
116 148
117 inline Region UnionRegions(const Region& a, gfx::Rect b) { 149 inline Region UnionRegions(const Region& a, gfx::Rect b) {
118 Region result = a; 150 Region result = a;
119 result.Union(b); 151 result.Union(b);
120 return result; 152 return result;
121 } 153 }
122 154
123 } // namespace cc 155 } // namespace cc
124 156
125 #endif // CC_REGION_H_ 157 #endif // CC_REGION_H_
OLDNEW
« no previous file with comments | « cc/cc.gyp ('k') | cc/region.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698