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/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"
18 namespace trace_event
{
24 class SimpleEnclosedRegion
;
26 class CC_EXPORT Region
{
29 Region(const Region
& region
);
30 Region(const gfx::Rect
& rect
); // NOLINT(runtime/explicit)
33 const Region
& operator=(const gfx::Rect
& rect
);
34 const Region
& operator=(const Region
& region
);
36 void Swap(Region
* region
);
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
{
71 explicit Iterator(const Region
& region
);
74 gfx::Rect
rect() const {
75 return gfx::SkIRectToRect(it_
.rect());
82 bool has_rect() const {
87 SkRegion::Iterator it_
;
94 inline bool operator==(const Region
& a
, const Region
& b
) {
98 inline bool operator!=(const Region
& a
, const Region
& b
) {
102 inline Region
SubtractRegions(const Region
& a
, const Region
& b
) {
108 inline Region
SubtractRegions(const Region
& a
, const gfx::Rect
& b
) {
114 inline Region
IntersectRegions(const Region
& a
, const Region
& b
) {
120 inline Region
IntersectRegions(const Region
& a
, const gfx::Rect
& b
) {
126 inline Region
UnionRegions(const Region
& a
, const Region
& b
) {
132 inline Region
UnionRegions(const Region
& a
, const gfx::Rect
& b
) {
140 #endif // CC_BASE_REGION_H_