Reduce dependency of TiclInvalidationService on Profile
[chromium-blink-merge.git] / cc / base / region.cc
blob906bc6e3c9d1e6f0ccce6445e078015e4754b78a
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 #include "cc/base/region.h"
6 #include "base/values.h"
8 namespace cc {
10 Region::Region() {
13 Region::Region(const Region& region)
14 : skregion_(region.skregion_) {
17 Region::Region(const gfx::Rect& rect)
18 : skregion_(gfx::RectToSkIRect(rect)) {
21 Region::~Region() {
24 const Region& Region::operator=(const gfx::Rect& rect) {
25 skregion_ = SkRegion(gfx::RectToSkIRect(rect));
26 return *this;
29 const Region& Region::operator=(const Region& region) {
30 skregion_ = region.skregion_;
31 return *this;
34 void Region::Swap(Region* region) {
35 region->skregion_.swap(skregion_);
38 void Region::Clear() {
39 skregion_.setEmpty();
42 bool Region::IsEmpty() const {
43 return skregion_.isEmpty();
46 int Region::GetRegionComplexity() const {
47 return skregion_.computeRegionComplexity();
50 bool Region::Contains(const gfx::Point& point) const {
51 return skregion_.contains(point.x(), point.y());
54 bool Region::Contains(const gfx::Rect& rect) const {
55 if (rect.IsEmpty())
56 return true;
57 return skregion_.contains(gfx::RectToSkIRect(rect));
60 bool Region::Contains(const Region& region) const {
61 if (region.IsEmpty())
62 return true;
63 return skregion_.contains(region.skregion_);
66 bool Region::Intersects(const gfx::Rect& rect) const {
67 return skregion_.intersects(gfx::RectToSkIRect(rect));
70 bool Region::Intersects(const Region& region) const {
71 return skregion_.intersects(region.skregion_);
74 void Region::Subtract(const gfx::Rect& rect) {
75 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kDifference_Op);
78 void Region::Subtract(const Region& region) {
79 skregion_.op(region.skregion_, SkRegion::kDifference_Op);
82 void Region::Union(const gfx::Rect& rect) {
83 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op);
86 void Region::Union(const Region& region) {
87 skregion_.op(region.skregion_, SkRegion::kUnion_Op);
90 void Region::Intersect(const gfx::Rect& rect) {
91 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kIntersect_Op);
94 void Region::Intersect(const Region& region) {
95 skregion_.op(region.skregion_, SkRegion::kIntersect_Op);
98 std::string Region::ToString() const {
99 if (IsEmpty())
100 return gfx::Rect().ToString();
102 std::string result;
103 for (Iterator it(*this); it.has_rect(); it.next()) {
104 if (!result.empty())
105 result += " | ";
106 result += it.rect().ToString();
108 return result;
111 scoped_ptr<base::Value> Region::AsValue() const {
112 scoped_ptr<base::ListValue> result(new base::ListValue());
113 for (Iterator it(*this); it.has_rect(); it.next()) {
114 gfx::Rect rect(it.rect());
115 result->AppendInteger(rect.x());
116 result->AppendInteger(rect.y());
117 result->AppendInteger(rect.width());
118 result->AppendInteger(rect.height());
120 return result.PassAs<base::Value>();
123 Region::Iterator::Iterator() {
126 Region::Iterator::Iterator(const Region& region)
127 : it_(region.skregion_) {
130 Region::Iterator::~Iterator() {
133 } // namespace cc