Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / base / region.h
blob583311e09fe007618f133e5084db6183f5ddd288
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_BASE_REGION_H_
6 #define CC_BASE_REGION_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/base/cc_export.h"
12 #include "third_party/skia/include/core/SkRegion.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/skia_util.h"
16 namespace base {
17 class Value;
18 namespace trace_event {
19 class TracedValue;
23 namespace cc {
24 class SimpleEnclosedRegion;
26 class CC_EXPORT Region {
27 public:
28 Region();
29 Region(const Region& region);
30 Region(const gfx::Rect& rect); // NOLINT(runtime/explicit)
31 ~Region();
33 const Region& operator=(const gfx::Rect& rect);
34 const Region& operator=(const Region& region);
36 void Swap(Region* region);
37 void Clear();
38 bool IsEmpty() const;
39 int GetRegionComplexity() const;
41 bool Contains(const gfx::Point& point) const;
42 bool Contains(const gfx::Rect& rect) const;
43 bool Contains(const Region& region) const;
45 bool Intersects(const gfx::Rect& rect) const;
46 bool Intersects(const Region& region) const;
48 void Subtract(const gfx::Rect& rect);
49 void Subtract(const Region& region);
50 void Subtract(const SimpleEnclosedRegion& region);
51 void Union(const gfx::Rect& rect);
52 void Union(const Region& region);
53 void Intersect(const gfx::Rect& rect);
54 void Intersect(const Region& region);
56 bool Equals(const Region& other) const {
57 return skregion_ == other.skregion_;
60 gfx::Rect bounds() const {
61 return gfx::SkIRectToRect(skregion_.getBounds());
64 std::string ToString() const;
65 scoped_ptr<base::Value> AsValue() const;
66 void AsValueInto(base::trace_event::TracedValue* array) const;
68 class CC_EXPORT Iterator {
69 public:
70 Iterator();
71 explicit Iterator(const Region& region);
72 ~Iterator();
74 gfx::Rect rect() const {
75 return gfx::SkIRectToRect(it_.rect());
78 void next() {
79 it_.next();
82 bool has_rect() const {
83 return !it_.done();
86 private:
87 SkRegion::Iterator it_;
90 private:
91 SkRegion skregion_;
94 inline bool operator==(const Region& a, const Region& b) {
95 return a.Equals(b);
98 inline bool operator!=(const Region& a, const Region& b) {
99 return !(a == b);
102 inline Region SubtractRegions(const Region& a, const Region& b) {
103 Region result = a;
104 result.Subtract(b);
105 return result;
108 inline Region SubtractRegions(const Region& a, const gfx::Rect& b) {
109 Region result = a;
110 result.Subtract(b);
111 return result;
114 inline Region IntersectRegions(const Region& a, const Region& b) {
115 Region result = a;
116 result.Intersect(b);
117 return result;
120 inline Region IntersectRegions(const Region& a, const gfx::Rect& b) {
121 Region result = a;
122 result.Intersect(b);
123 return result;
126 inline Region UnionRegions(const Region& a, const Region& b) {
127 Region result = a;
128 result.Union(b);
129 return result;
132 inline Region UnionRegions(const Region& a, const gfx::Rect& b) {
133 Region result = a;
134 result.Union(b);
135 return result;
138 } // namespace cc
140 #endif // CC_BASE_REGION_H_