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

Side by Side Diff: cc/region.h

Issue 11366094: cc: Create a Region class that wraps SkRegion, to replace use of WebCore::Region. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move deg2rad etc to MathUtil 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CC_REGION_H_
6 #define CC_REGION_H_
7
8 #include <string>
9
10 #include "base/logging.h"
11 #include "cc/cc_export.h"
12 #include "third_party/skia/include/core/SkRegion.h"
13 #include "ui/gfx/rect.h"
14
15 namespace cc {
16
17 class CC_EXPORT Region {
18 public:
19 Region();
20 Region(const Region& region);
21 Region(gfx::Rect rect);
22 ~Region();
23
24 void operator=(const Region& region);
25
26 bool IsEmpty() const;
27
28 bool Contains(const gfx::Point& point) const;
29 bool Contains(const gfx::Rect& rect) const;
30 void Subtract(const gfx::Rect& rect);
31 void Subtract(const Region& region);
32 void Union(const gfx::Rect& rect);
33 void Union(const Region& region);
34 void Intersect(const gfx::Rect& rect);
35 void Intersect(const Region& region);
36
37 bool Equals(const Region& other) const { return skregion_ == other.skregion_; }
38
39 gfx::Rect bounds() const {
40 SkIRect r = skregion_.getBounds();
41 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists.
42 return gfx::Rect(r.x(), r.y(), r.width(), r.height());
43 }
44
45 std::string ToString() const;
46
47 class Iterator {
48 public:
49 Iterator(const Region& region);
50 ~Iterator();
51
52 gfx::Rect rect() const {
53 SkIRect r = it_.rect();
54 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists.
55 return gfx::Rect(r.x(), r.y(), r.width(), r.height());
56 }
57
58 void next() { it_.next(); }
59 bool has_rect() const { return !it_.done(); }
60
61 private:
62 SkRegion::Iterator it_;
63 };
64
65 private:
66 SkRegion skregion_;
67 };
68
69 inline bool operator==(const Region& a, const Region& b) {
70 return a.Equals(b);
71 }
72
73 inline bool operator!=(const Region& a, const Region& b) {
74 return !(a == b);
75 }
76
77 inline Region SubtractRegions(const Region& a, const Region& b) {
78 Region result = a;
79 result.Subtract(b);
80 return result;
81 }
82
83 inline Region SubtractRegions(const Region& a, gfx::Rect b) {
84 Region result = a;
85 result.Subtract(b);
86 return result;
87 }
88
89 inline Region IntersectRegions(const Region& a, const Region& b) {
90 Region result = a;
91 result.Intersect(b);
92 return result;
93 }
94
95 inline Region IntersectRegions(const Region& a, gfx::Rect b) {
96 Region result = a;
97 result.Intersect(b);
98 return result;
99 }
100
101 inline Region UnionRegions(const Region& a, const Region& b) {
102 Region result = a;
103 result.Union(b);
104 return result;
105 }
106
107 inline Region UnionRegions(const Region& a, gfx::Rect b) {
108 Region result = a;
109 result.Union(b);
110 return result;
111 }
112
113 } // namespace cc
114
115 #endif // CC_REGION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698