Use TargetTransform instead of transform in ConvertPointFor/FromAncestor
[chromium-blink-merge.git] / cc / region.h
blob7478152169df83df9dd3eccd823b12bee273aaa0
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.
5 #ifndef CC_REGION_H_
6 #define CC_REGION_H_
8 #include <string>
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 #include "ui/gfx/skia_util.h"
16 namespace cc {
18 class CC_EXPORT Region {
19 public:
20 Region();
21 Region(const Region& region);
22 Region(gfx::Rect rect);
23 ~Region();
25 const Region& operator=(gfx::Rect rect);
26 const Region& operator=(const Region& region);
28 void Swap(Region& region);
29 void Clear();
30 bool IsEmpty() const;
32 bool Contains(gfx::Point point) const;
33 bool Contains(gfx::Rect rect) const;
34 bool Contains(const Region& region) const;
36 bool Intersects(gfx::Rect rect) const;
37 bool Intersects(const Region& region) const;
39 void Subtract(gfx::Rect rect);
40 void Subtract(const Region& region);
41 void Union(gfx::Rect rect);
42 void Union(const Region& region);
43 void Intersect(gfx::Rect rect);
44 void Intersect(const Region& region);
46 bool Equals(const Region& other) const {
47 return skregion_ == other.skregion_;
50 gfx::Rect bounds() const {
51 return gfx::SkIRectToRect(skregion_.getBounds());
54 std::string ToString() const;
56 class CC_EXPORT Iterator {
57 public:
58 Iterator();
59 Iterator(const Region& region);
60 ~Iterator();
62 gfx::Rect rect() const {
63 return gfx::SkIRectToRect(it_.rect());
66 void next() {
67 it_.next();
70 bool has_rect() const {
71 return !it_.done();
74 private:
75 SkRegion::Iterator it_;
78 private:
79 SkRegion skregion_;
82 inline bool operator==(const Region& a, const Region& b) {
83 return a.Equals(b);
86 inline bool operator!=(const Region& a, const Region& b) {
87 return !(a == b);
90 inline Region SubtractRegions(const Region& a, const Region& b) {
91 Region result = a;
92 result.Subtract(b);
93 return result;
96 inline Region SubtractRegions(const Region& a, gfx::Rect b) {
97 Region result = a;
98 result.Subtract(b);
99 return result;
102 inline Region IntersectRegions(const Region& a, const Region& b) {
103 Region result = a;
104 result.Intersect(b);
105 return result;
108 inline Region IntersectRegions(const Region& a, gfx::Rect b) {
109 Region result = a;
110 result.Intersect(b);
111 return result;
114 inline Region UnionRegions(const Region& a, const Region& b) {
115 Region result = a;
116 result.Union(b);
117 return result;
120 inline Region UnionRegions(const Region& a, gfx::Rect b) {
121 Region result = a;
122 result.Union(b);
123 return result;
126 } // namespace cc
128 #endif // CC_REGION_H_