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_
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"
23 class CC_EXPORT Region
{
26 Region(const Region
& region
);
27 Region(const gfx::Rect
& rect
); // NOLINT(runtime/explicit)
30 const Region
& operator=(const gfx::Rect
& rect
);
31 const Region
& operator=(const Region
& region
);
33 void Swap(Region
* region
);
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
{
66 explicit Iterator(const Region
& region
);
69 gfx::Rect
rect() const {
70 return gfx::SkIRectToRect(it_
.rect());
77 bool has_rect() const {
82 SkRegion::Iterator it_
;
89 inline bool operator==(const Region
& a
, const Region
& b
) {
93 inline bool operator!=(const Region
& a
, const Region
& b
) {
97 inline Region
SubtractRegions(const Region
& a
, const Region
& b
) {
103 inline Region
SubtractRegions(const Region
& a
, const gfx::Rect
& b
) {
109 inline Region
IntersectRegions(const Region
& a
, const Region
& b
) {
115 inline Region
IntersectRegions(const Region
& a
, const gfx::Rect
& b
) {
121 inline Region
UnionRegions(const Region
& a
, const Region
& b
) {
127 inline Region
UnionRegions(const Region
& a
, const gfx::Rect
& b
) {
135 #endif // CC_BASE_REGION_H_