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.cc | |
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.cc')
-rw-r--r-- | cc/region.cc | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/cc/region.cc b/cc/region.cc new file mode 100644 index 0000000..7a5e83c --- /dev/null +++ b/cc/region.cc @@ -0,0 +1,109 @@ +// 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. + +#include "config.h" + +#include "cc/region.h" + +namespace cc { + +// TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists. +static inline SkIRect ToSkIRect(gfx::Rect rect) +{ + return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); +} + +Region::Region() { +} + +Region::Region(const Region& region) + : skregion_(region.skregion_) { +} + +Region::Region(gfx::Rect rect) + : skregion_(ToSkIRect(rect)) { +} + +Region::~Region() { +} + +const Region& Region::operator=(gfx::Rect rect) { + skregion_ = SkRegion(ToSkIRect(rect)); + return *this; +} + +const Region& Region::operator=(const Region& region) { + skregion_ = region.skregion_; + return *this; +} + +bool Region::IsEmpty() const { + return skregion_.isEmpty(); +} + +bool Region::Contains(gfx::Point point) const { + return skregion_.contains(point.x(), point.y()); +} + +bool Region::Contains(gfx::Rect rect) const { + return skregion_.contains(ToSkIRect(rect)); +} + +bool Region::Contains(const Region& region) const { + return skregion_.contains(region.skregion_); +} + +bool Region::Intersects(gfx::Rect rect) const { + return skregion_.intersects(ToSkIRect(rect)); +} + +bool Region::Intersects(const Region& region) const { + return skregion_.intersects(region.skregion_); +} + +void Region::Subtract(gfx::Rect rect) { + skregion_.op(ToSkIRect(rect), SkRegion::kDifference_Op); +} + +void Region::Subtract(const Region& region) { + skregion_.op(region.skregion_, SkRegion::kDifference_Op); +} + +void Region::Union(gfx::Rect rect) { + skregion_.op(ToSkIRect(rect), SkRegion::kUnion_Op); +} + +void Region::Union(const Region& region) { + skregion_.op(region.skregion_, SkRegion::kUnion_Op); +} + +void Region::Intersect(gfx::Rect rect) { + skregion_.op(ToSkIRect(rect), SkRegion::kIntersect_Op); +} + +void Region::Intersect(const Region& region) { + skregion_.op(region.skregion_, SkRegion::kIntersect_Op); +} + +std::string Region::ToString() const { + if (IsEmpty()) + return gfx::Rect().ToString(); + + std::string result; + for (Iterator it(*this); it.has_rect(); it.next()) { + if (!result.empty()) + result += " | "; + result += it.rect().ToString(); + } + return result; +} + +Region::Iterator::Iterator(const Region& region) + : it_(region.skregion_) { +} + +Region::Iterator::~Iterator() { +} + +} // namespace cc |