diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 06:26:50 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 06:26:50 +0000 |
commit | ac7c7f5ddf7ccddac616fd7700b020bd30446069 (patch) | |
tree | de606bdf0eda10da177b6c184762364dc09d5202 /cc/region.h | |
parent | 12a11e2b86333af3bf71dbcf5b61e48f3d43a5bc (diff) | |
download | chromium_src-ac7c7f5ddf7ccddac616fd7700b020bd30446069.zip chromium_src-ac7c7f5ddf7ccddac616fd7700b020bd30446069.tar.gz chromium_src-ac7c7f5ddf7ccddac616fd7700b020bd30446069.tar.bz2 |
cc: Create a Region class that wraps SkRegion, to replace use of WebCore::Region.
We create a class in cc/ called Region which provides a gfx:: type-friendly API
to SkRegion, and allows for easily swapping out region implementations in the
future if required.
During the process, I removed tests dependency on a "size()" method on Region,
that used to give the number of rects in the Region's internal representation.
Instead, we always create a Region in the tests from our expected rects, and
compare the Regions directly. We use ToString() comparisons to get useful
failure outputs, similar to the unit tests of other geometry types in ui/gfx.
This uncovered a WTF::Vector holdout in the OcclusionTracker class, which is
converted to a std::vector.
Covered by existing tests; no change in behaviour.
R=enne
BUG=147395
Review URL: https://chromiumcodereview.appspot.com/11366094
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166617 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/region.h')
-rw-r--r-- | cc/region.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/cc/region.h b/cc/region.h new file mode 100644 index 0000000..49ad5f3 --- /dev/null +++ b/cc/region.h @@ -0,0 +1,125 @@ +// 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(); + + const Region& operator=(gfx::Rect rect); + const Region& operator=(const Region& region); + + bool IsEmpty() const; + + bool Contains(gfx::Point point) const; + bool Contains(gfx::Rect rect) const; + bool Contains(const Region& region) const; + + bool Intersects(gfx::Rect rect) const; + bool Intersects(const Region& region) const; + + void Subtract(gfx::Rect rect); + void Subtract(const Region& region); + void Union(gfx::Rect rect); + void Union(const Region& region); + void Intersect(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 CC_EXPORT 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_ |