Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4495)

Unified Diff: cc/region.h

Issue 11366094: cc: Create a Region class that wraps SkRegion, to replace use of WebCore::Region. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move deg2rad etc to MathUtil Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/region.h
diff --git a/cc/region.h b/cc/region.h
new file mode 100644
index 0000000000000000000000000000000000000000..b26c3e4b20d71b2704b0ee7b350616252d88ba0d
--- /dev/null
+++ b/cc/region.h
@@ -0,0 +1,115 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_REGION_H_
+#define CC_REGION_H_
+
+#include <string>
+
+#include "base/logging.h"
+#include "cc/cc_export.h"
+#include "third_party/skia/include/core/SkRegion.h"
+#include "ui/gfx/rect.h"
+
+namespace cc {
+
+class CC_EXPORT Region {
+ public:
+ Region();
+ Region(const Region& region);
+ Region(gfx::Rect rect);
+ ~Region();
+
+ void operator=(const Region& region);
+
+ bool IsEmpty() const;
+
+ bool Contains(const gfx::Point& point) const;
+ bool Contains(const gfx::Rect& rect) const;
+ void Subtract(const gfx::Rect& rect);
+ void Subtract(const Region& region);
+ void Union(const gfx::Rect& rect);
+ void Union(const Region& region);
+ void Intersect(const gfx::Rect& rect);
+ void Intersect(const Region& region);
+
+ bool Equals(const Region& other) const { return skregion_ == other.skregion_; }
+
+ gfx::Rect bounds() const {
+ SkIRect r = skregion_.getBounds();
+ // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists.
+ return gfx::Rect(r.x(), r.y(), r.width(), r.height());
+ }
+
+ std::string ToString() const;
+
+ class Iterator {
+ public:
+ Iterator(const Region& region);
+ ~Iterator();
+
+ gfx::Rect rect() const {
+ SkIRect r = it_.rect();
+ // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists.
+ return gfx::Rect(r.x(), r.y(), r.width(), r.height());
+ }
+
+ void next() { it_.next(); }
+ bool has_rect() const { return !it_.done(); }
+
+ private:
+ SkRegion::Iterator it_;
+ };
+
+ private:
+ SkRegion skregion_;
+};
+
+inline bool operator==(const Region& a, const Region& b) {
+ return a.Equals(b);
+}
+
+inline bool operator!=(const Region& a, const Region& b) {
+ return !(a == b);
+}
+
+inline Region SubtractRegions(const Region& a, const Region& b) {
+ Region result = a;
+ result.Subtract(b);
+ return result;
+}
+
+inline Region SubtractRegions(const Region& a, gfx::Rect b) {
+ Region result = a;
+ result.Subtract(b);
+ return result;
+}
+
+inline Region IntersectRegions(const Region& a, const Region& b) {
+ Region result = a;
+ result.Intersect(b);
+ return result;
+}
+
+inline Region IntersectRegions(const Region& a, gfx::Rect b) {
+ Region result = a;
+ result.Intersect(b);
+ return result;
+}
+
+inline Region UnionRegions(const Region& a, const Region& b) {
+ Region result = a;
+ result.Union(b);
+ return result;
+}
+
+inline Region UnionRegions(const Region& a, gfx::Rect b) {
+ Region result = a;
+ result.Union(b);
+ return result;
+}
+
+} // namespace cc
+
+#endif // CC_REGION_H_

Powered by Google App Engine
This is Rietveld 408576698