IndexedDB: fsync after transactions.
[chromium-blink-merge.git] / cc / base / region.h
blobf3f5cb87ddb0554b2965f08101d90456d0df0407
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/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/base/cc_export.h"
13 #include "third_party/skia/include/core/SkRegion.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/skia_util.h"
17 namespace base {
18 class Value;
21 namespace cc {
23 class CC_EXPORT Region {
24 public:
25 Region();
26 Region(const Region& region);
27 Region(const gfx::Rect& rect); // NOLINT(runtime/explicit)
28 ~Region();
30 const Region& operator=(const gfx::Rect& rect);
31 const Region& operator=(const Region& region);
33 void Swap(Region* region);
34 void Clear();
35 bool IsEmpty() const;
36 int GetRegionComplexity() const;
38 bool Contains(gfx::Point point) const;
39 bool Contains(const gfx::Rect& rect) const;
40 bool Contains(const Region& region) const;
42 bool Intersects(const gfx::Rect& rect) const;
43 bool Intersects(const Region& region) const;
45 void Subtract(const gfx::Rect& rect);
46 void Subtract(const Region& region);
47 void Union(const gfx::Rect& rect);
48 void Union(const Region& region);
49 void Intersect(const gfx::Rect& rect);
50 void Intersect(const Region& region);
52 bool Equals(const Region& other) const {
53 return skregion_ == other.skregion_;
56 gfx::Rect bounds() const {
57 return gfx::SkIRectToRect(skregion_.getBounds());
60 std::string ToString() const;
61 scoped_ptr<base::Value> AsValue() const;
63 class CC_EXPORT Iterator {
64 public:
65 Iterator();
66 explicit Iterator(const Region& region);
67 ~Iterator();
69 gfx::Rect rect() const {
70 return gfx::SkIRectToRect(it_.rect());
73 void next() {
74 it_.next();
77 bool has_rect() const {
78 return !it_.done();
81 private:
82 SkRegion::Iterator it_;
85 private:
86 SkRegion skregion_;
89 inline bool operator==(const Region& a, const Region& b) {
90 return a.Equals(b);
93 inline bool operator!=(const Region& a, const Region& b) {
94 return !(a == b);
97 inline Region SubtractRegions(const Region& a, const Region& b) {
98 Region result = a;
99 result.Subtract(b);
100 return result;
103 inline Region SubtractRegions(const Region& a, const gfx::Rect& b) {
104 Region result = a;
105 result.Subtract(b);
106 return result;
109 inline Region IntersectRegions(const Region& a, const Region& b) {
110 Region result = a;
111 result.Intersect(b);
112 return result;
115 inline Region IntersectRegions(const Region& a, const gfx::Rect& b) {
116 Region result = a;
117 result.Intersect(b);
118 return result;
121 inline Region UnionRegions(const Region& a, const Region& b) {
122 Region result = a;
123 result.Union(b);
124 return result;
127 inline Region UnionRegions(const Region& a, const gfx::Rect& b) {
128 Region result = a;
129 result.Union(b);
130 return result;
133 } // namespace cc
135 #endif // CC_BASE_REGION_H_