gfx/src/nsRegion.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/src/nsRegion.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,609 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +
     1.9 +#ifndef nsRegion_h__
    1.10 +#define nsRegion_h__
    1.11 +
    1.12 +#include <stddef.h>                     // for size_t
    1.13 +#include <stdint.h>                     // for uint32_t, uint64_t
    1.14 +#include <sys/types.h>                  // for int32_t
    1.15 +#include "gfxCore.h"                    // for NS_GFX
    1.16 +#include "nsCoord.h"                    // for nscoord
    1.17 +#include "nsError.h"                    // for nsresult
    1.18 +#include "nsPoint.h"                    // for nsIntPoint, nsPoint
    1.19 +#include "nsRect.h"                     // for nsIntRect, nsRect
    1.20 +#include "nsMargin.h"                   // for nsIntMargin
    1.21 +#include "nsStringGlue.h"               // for nsCString
    1.22 +#include "xpcom-config.h"               // for CPP_THROW_NEW
    1.23 +
    1.24 +class nsIntRegion;
    1.25 +
    1.26 +#include "pixman.h"
    1.27 +
    1.28 +/* For information on the internal representation look at pixman-region.c
    1.29 + *
    1.30 + * This replaces an older homebrew implementation of nsRegion. The
    1.31 + * representation used here may use more rectangles than nsRegion however, the
    1.32 + * representation is canonical.  This means that there's no need for an
    1.33 + * Optimize() method because for a paticular region there is only one
    1.34 + * representation. This means that nsIntRegion will have more predictable
    1.35 + * performance characteristics than the old nsRegion and should not become
    1.36 + * degenerate.
    1.37 + *
    1.38 + * The pixman region code originates from X11 which has spread to a variety of
    1.39 + * projects including Qt, Gtk, Wine. It should perform reasonably well.
    1.40 + */
    1.41 +
    1.42 +class nsRegionRectIterator;
    1.43 +
    1.44 +class nsRegion
    1.45 +{
    1.46 +
    1.47 +  friend class nsRegionRectIterator;
    1.48 +
    1.49 +public:
    1.50 +  nsRegion () { pixman_region32_init(&mImpl); }
    1.51 +  nsRegion (const nsRect& aRect) { pixman_region32_init_rect(&mImpl,
    1.52 +                                                                    aRect.x,
    1.53 +                                                                    aRect.y,
    1.54 +                                                                    aRect.width,
    1.55 +                                                                    aRect.height); }
    1.56 +  nsRegion (const nsRegion& aRegion) { pixman_region32_init(&mImpl); pixman_region32_copy(&mImpl,aRegion.Impl()); }
    1.57 + ~nsRegion () { pixman_region32_fini(&mImpl); }
    1.58 +  nsRegion& operator = (const nsRect& aRect) { Copy (aRect); return *this; }
    1.59 +  nsRegion& operator = (const nsRegion& aRegion) { Copy (aRegion); return *this; }
    1.60 +  bool operator==(const nsRegion& aRgn) const
    1.61 +  {
    1.62 +    return IsEqual(aRgn);
    1.63 +  }
    1.64 +
    1.65 +  void Swap(nsRegion* aOther)
    1.66 +  {
    1.67 +    pixman_region32_t tmp = mImpl;
    1.68 +    mImpl = aOther->mImpl;
    1.69 +    aOther->mImpl = tmp;
    1.70 +  }
    1.71 +
    1.72 +  static
    1.73 +  nsresult InitStatic()
    1.74 +  {
    1.75 +    return NS_OK;
    1.76 +  }
    1.77 +
    1.78 +  static
    1.79 +  void ShutdownStatic() {}
    1.80 +
    1.81 +  nsRegion& And(const nsRegion& aRgn1,   const nsRegion& aRgn2)
    1.82 +  {
    1.83 +    pixman_region32_intersect(&mImpl, aRgn1.Impl(), aRgn2.Impl());
    1.84 +    return *this;
    1.85 +  }
    1.86 +  nsRegion& And(const nsRect& aRect, const nsRegion& aRegion)
    1.87 +  {
    1.88 +    return And(aRegion, aRect);
    1.89 +  }
    1.90 +  nsRegion& And(const nsRegion& aRegion, const nsRect& aRect)
    1.91 +  {
    1.92 +    pixman_region32_intersect_rect(&mImpl, aRegion.Impl(), aRect.x, aRect.y, aRect.width, aRect.height);
    1.93 +    return *this;
    1.94 +  }
    1.95 +  nsRegion& And(const nsRect& aRect1, const nsRect& aRect2)
    1.96 +  {
    1.97 +    nsRect TmpRect;
    1.98 +
    1.99 +    TmpRect.IntersectRect(aRect1, aRect2);
   1.100 +    return Copy(TmpRect);
   1.101 +  }
   1.102 +
   1.103 +  nsRegion& Or(const nsRegion& aRgn1, const nsRegion& aRgn2)
   1.104 +  {
   1.105 +    pixman_region32_union(&mImpl, aRgn1.Impl(), aRgn2.Impl());
   1.106 +    return *this;
   1.107 +  }
   1.108 +  nsRegion& Or(const nsRegion& aRegion, const nsRect& aRect)
   1.109 +  {
   1.110 +    pixman_region32_union_rect(&mImpl, aRegion.Impl(), aRect.x, aRect.y, aRect.width, aRect.height);
   1.111 +    return *this;
   1.112 +  }
   1.113 +  nsRegion& Or(const nsRect& aRect, const nsRegion& aRegion)
   1.114 +  {
   1.115 +    return  Or(aRegion, aRect);
   1.116 +  }
   1.117 +  nsRegion& Or(const nsRect& aRect1, const nsRect& aRect2)
   1.118 +  {
   1.119 +    Copy (aRect1);
   1.120 +    return Or (*this, aRect2);
   1.121 +  }
   1.122 +
   1.123 +  nsRegion& Xor(const nsRegion& aRgn1,   const nsRegion& aRgn2)
   1.124 +  {
   1.125 +    // this could be implemented better if pixman had direct
   1.126 +    // support for xoring regions.
   1.127 +    nsRegion p;
   1.128 +    p.Sub(aRgn1, aRgn2);
   1.129 +    nsRegion q;
   1.130 +    q.Sub(aRgn2, aRgn1);
   1.131 +    return Or(p, q);
   1.132 +  }
   1.133 +  nsRegion& Xor(const nsRegion& aRegion, const nsRect& aRect)
   1.134 +  {
   1.135 +    return Xor(aRegion, nsRegion(aRect));
   1.136 +  }
   1.137 +  nsRegion& Xor(const nsRect& aRect, const nsRegion& aRegion)
   1.138 +  {
   1.139 +    return Xor(nsRegion(aRect), aRegion);
   1.140 +  }
   1.141 +  nsRegion& Xor(const nsRect& aRect1, const nsRect& aRect2)
   1.142 +  {
   1.143 +    return Xor(nsRegion(aRect1), nsRegion(aRect2));
   1.144 +  }
   1.145 +
   1.146 +  nsRegion ToAppUnits (nscoord aAppUnitsPerPixel) const;
   1.147 +  nsRegion& Sub(const nsRegion& aRgn1, const nsRegion& aRgn2)
   1.148 +  {
   1.149 +    pixman_region32_subtract(&mImpl, aRgn1.Impl(), aRgn2.Impl());
   1.150 +    return *this;
   1.151 +  }
   1.152 +  nsRegion& Sub(const nsRegion& aRegion, const nsRect& aRect)
   1.153 +  {
   1.154 +    return Sub(aRegion, nsRegion(aRect));
   1.155 +  }
   1.156 +  nsRegion& Sub(const nsRect& aRect, const nsRegion& aRegion)
   1.157 +  {
   1.158 +    return Sub(nsRegion(aRect), aRegion);
   1.159 +  }
   1.160 +  nsRegion& Sub(const nsRect& aRect1, const nsRect& aRect2)
   1.161 +  {
   1.162 +    Copy(aRect1);
   1.163 +    return Sub(*this, aRect2);
   1.164 +  }
   1.165 +
   1.166 +  bool Contains (const nsRect& aRect) const
   1.167 +  {
   1.168 +    pixman_box32_t box = RectToBox(aRect);
   1.169 +    return pixman_region32_contains_rectangle(Impl(), &box) == PIXMAN_REGION_IN;
   1.170 +  }
   1.171 +  bool Contains (const nsRegion& aRgn) const;
   1.172 +  bool Intersects (const nsRect& aRect) const;
   1.173 +
   1.174 +  void MoveBy (int32_t aXOffset, int32_t aYOffset)
   1.175 +  {
   1.176 +    MoveBy (nsPoint (aXOffset, aYOffset));
   1.177 +  }
   1.178 +  void MoveBy (nsPoint aPt) { pixman_region32_translate(&mImpl, aPt.x, aPt.y); }
   1.179 +  void SetEmpty ()
   1.180 +  {
   1.181 +    pixman_region32_clear(&mImpl);
   1.182 +  }
   1.183 +
   1.184 +  nsRegion MovedBy(int32_t aXOffset, int32_t aYOffset) const
   1.185 +  {
   1.186 +    return MovedBy(nsPoint(aXOffset, aYOffset));
   1.187 +  }
   1.188 +  nsRegion MovedBy(const nsPoint& aPt) const
   1.189 +  {
   1.190 +    nsRegion copy(*this);
   1.191 +    copy.MoveBy(aPt);
   1.192 +    return copy;
   1.193 +  }
   1.194 +
   1.195 +  nsRegion Intersect(const nsRegion& aOther) const
   1.196 +  {
   1.197 +    nsRegion intersection;
   1.198 +    intersection.And(*this, aOther);
   1.199 +    return intersection;
   1.200 +  }
   1.201 +
   1.202 +  void Inflate(const nsMargin& aMargin);
   1.203 +
   1.204 +  nsRegion Inflated(const nsMargin& aMargin) const
   1.205 +  {
   1.206 +    nsRegion copy(*this);
   1.207 +    copy.Inflate(aMargin);
   1.208 +    return copy;
   1.209 +  }
   1.210 +
   1.211 +  bool IsEmpty () const { return !pixman_region32_not_empty(Impl()); }
   1.212 +  bool IsComplex () const { return GetNumRects() > 1; }
   1.213 +  bool IsEqual (const nsRegion& aRegion) const
   1.214 +  {
   1.215 +    return pixman_region32_equal(Impl(), aRegion.Impl());
   1.216 +  }
   1.217 +  uint32_t GetNumRects () const { return pixman_region32_n_rects(Impl()); }
   1.218 +  const nsRect GetBounds () const { return BoxToRect(mImpl.extents); }
   1.219 +  uint64_t Area () const;
   1.220 +  // Converts this region from aFromAPP, an appunits per pixel ratio, to
   1.221 +  // aToAPP. This applies nsRect::ConvertAppUnitsRoundOut/In to each rect of
   1.222 +  // the region.
   1.223 +  nsRegion ConvertAppUnitsRoundOut (int32_t aFromAPP, int32_t aToAPP) const;
   1.224 +  nsRegion ConvertAppUnitsRoundIn (int32_t aFromAPP, int32_t aToAPP) const;
   1.225 +  nsRegion& ScaleRoundOut(float aXScale, float aYScale);
   1.226 +  nsRegion& ScaleInverseRoundOut(float aXScale, float aYScale);
   1.227 +  nsIntRegion ScaleToOutsidePixels (float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const;
   1.228 +  nsIntRegion ScaleToInsidePixels (float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const;
   1.229 +  nsIntRegion ScaleToNearestPixels (float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const;
   1.230 +  nsIntRegion ToOutsidePixels (nscoord aAppUnitsPerPixel) const;
   1.231 +  nsIntRegion ToNearestPixels (nscoord aAppUnitsPerPixel) const;
   1.232 +
   1.233 +  /**
   1.234 +   * Gets the largest rectangle contained in the region.
   1.235 +   * @param aContainingRect if non-empty, we choose a rectangle that
   1.236 +   * maximizes the area intersecting with aContainingRect (and break ties by
   1.237 +   * then choosing the largest rectangle overall)
   1.238 +   */
   1.239 +  nsRect GetLargestRectangle (const nsRect& aContainingRect = nsRect()) const;
   1.240 +
   1.241 +  /**
   1.242 +   * Make sure the region has at most aMaxRects by adding area to it
   1.243 +   * if necessary. The simplified region will be a superset of the
   1.244 +   * original region. The simplified region's bounding box will be
   1.245 +   * the same as for the current region.
   1.246 +   */
   1.247 +  void SimplifyOutward (uint32_t aMaxRects);
   1.248 +  /**
   1.249 +   * Simplify the region by adding at most aThreshold area between spans of
   1.250 +   * rects.  The simplified region will be a superset of the original region.
   1.251 +   * The simplified region's bounding box will be the same as for the current
   1.252 +   * region.
   1.253 +   */
   1.254 +  void SimplifyOutwardByArea(uint32_t aThreshold);
   1.255 +  /**
   1.256 +   * Make sure the region has at most aMaxRects by removing area from
   1.257 +   * it if necessary. The simplified region will be a subset of the
   1.258 +   * original region.
   1.259 +   */
   1.260 +  void SimplifyInward (uint32_t aMaxRects);
   1.261 +
   1.262 +  nsCString ToString() const;
   1.263 +private:
   1.264 +  pixman_region32_t mImpl;
   1.265 +
   1.266 +  nsIntRegion ToPixels(nscoord aAppUnitsPerPixel, bool aOutsidePixels) const;
   1.267 +
   1.268 +  nsRegion& Copy (const nsRegion& aRegion)
   1.269 +  {
   1.270 +    pixman_region32_copy(&mImpl, aRegion.Impl());
   1.271 +    return *this;
   1.272 +  }
   1.273 +
   1.274 +  nsRegion& Copy (const nsRect& aRect)
   1.275 +  {
   1.276 +    // pixman needs to distinguish between an empty region and a region
   1.277 +    // with one rect so that it can return a different number of rectangles.
   1.278 +    // Empty rect: data = empty_box
   1.279 +    //     1 rect: data = null
   1.280 +    //    >1 rect: data = rects
   1.281 +    if (aRect.IsEmpty()) {
   1.282 +      pixman_region32_clear(&mImpl);
   1.283 +    } else {
   1.284 +      pixman_box32_t box = RectToBox(aRect);
   1.285 +      pixman_region32_reset(&mImpl, &box);
   1.286 +    }
   1.287 +    return *this;
   1.288 +  }
   1.289 +
   1.290 +  static inline pixman_box32_t RectToBox(const nsRect &aRect)
   1.291 +  {
   1.292 +    pixman_box32_t box = { aRect.x, aRect.y, aRect.XMost(), aRect.YMost() };
   1.293 +    return box;
   1.294 +  }
   1.295 +
   1.296 +  static inline pixman_box32_t RectToBox(const nsIntRect &aRect)
   1.297 +  {
   1.298 +    pixman_box32_t box = { aRect.x, aRect.y, aRect.XMost(), aRect.YMost() };
   1.299 +    return box;
   1.300 +  }
   1.301 +
   1.302 +
   1.303 +  static inline nsRect BoxToRect(const pixman_box32_t &aBox)
   1.304 +  {
   1.305 +    return nsRect(aBox.x1, aBox.y1,
   1.306 +                  aBox.x2 - aBox.x1,
   1.307 +                  aBox.y2 - aBox.y1);
   1.308 +  }
   1.309 +
   1.310 +  pixman_region32_t* Impl() const
   1.311 +  {
   1.312 +    return const_cast<pixman_region32_t*>(&mImpl);
   1.313 +  }
   1.314 +
   1.315 +};
   1.316 +
   1.317 +
   1.318 +class NS_GFX nsRegionRectIterator
   1.319 +{
   1.320 +  const nsRegion*  mRegion;
   1.321 +  int i;
   1.322 +  int n;
   1.323 +  nsRect rect;
   1.324 +  pixman_box32_t *boxes;
   1.325 +
   1.326 +public:
   1.327 +  nsRegionRectIterator (const nsRegion& aRegion)
   1.328 +  {
   1.329 +    mRegion = &aRegion;
   1.330 +    i = 0;
   1.331 +    boxes = pixman_region32_rectangles(aRegion.Impl(), &n);
   1.332 +  }
   1.333 +
   1.334 +  const nsRect* Next ()
   1.335 +  {
   1.336 +    if (i == n)
   1.337 +      return nullptr;
   1.338 +    rect = nsRegion::BoxToRect(boxes[i]);
   1.339 +    i++;
   1.340 +    return &rect;
   1.341 +  }
   1.342 +
   1.343 +  const nsRect* Prev ()
   1.344 +  {
   1.345 +    if (i == -1)
   1.346 +      return nullptr;
   1.347 +    rect = nsRegion::BoxToRect(boxes[i]);
   1.348 +    i--;
   1.349 +    return &rect;
   1.350 +  }
   1.351 +
   1.352 +  void Reset ()
   1.353 +  {
   1.354 +    i = 0;
   1.355 +  }
   1.356 +};
   1.357 +
   1.358 +/**
   1.359 + * nsIntRegions use int32_t coordinates and nsIntRects.
   1.360 + */
   1.361 +class NS_GFX nsIntRegion
   1.362 +{
   1.363 +  friend class nsIntRegionRectIterator;
   1.364 +  friend class nsRegion;
   1.365 +
   1.366 +public:
   1.367 +  nsIntRegion () {}
   1.368 +  nsIntRegion (const nsIntRect& aRect) : mImpl (ToRect(aRect)) {}
   1.369 +  nsIntRegion (const nsIntRegion& aRegion) : mImpl (aRegion.mImpl) {}
   1.370 +  nsIntRegion& operator = (const nsIntRect& aRect) { mImpl = ToRect (aRect); return *this; }
   1.371 +  nsIntRegion& operator = (const nsIntRegion& aRegion) { mImpl = aRegion.mImpl; return *this; }
   1.372 +
   1.373 +  bool operator==(const nsIntRegion& aRgn) const
   1.374 +  {
   1.375 +    return IsEqual(aRgn);
   1.376 +  }
   1.377 +
   1.378 +  void Swap(nsIntRegion* aOther)
   1.379 +  {
   1.380 +    mImpl.Swap(&aOther->mImpl);
   1.381 +  }
   1.382 +
   1.383 +  nsIntRegion& And  (const nsIntRegion& aRgn1,   const nsIntRegion& aRgn2)
   1.384 +  {
   1.385 +    mImpl.And (aRgn1.mImpl, aRgn2.mImpl);
   1.386 +    return *this;
   1.387 +  }
   1.388 +  nsIntRegion& And  (const nsIntRegion& aRegion, const nsIntRect& aRect)
   1.389 +  {
   1.390 +    mImpl.And (aRegion.mImpl, ToRect (aRect));
   1.391 +    return *this;
   1.392 +  }
   1.393 +  nsIntRegion& And  (const nsIntRect& aRect, const nsIntRegion& aRegion)
   1.394 +  {
   1.395 +    return  And  (aRegion, aRect);
   1.396 +  }
   1.397 +  nsIntRegion& And  (const nsIntRect& aRect1, const nsIntRect& aRect2)
   1.398 +  {
   1.399 +    nsIntRect TmpRect;
   1.400 +
   1.401 +    TmpRect.IntersectRect (aRect1, aRect2);
   1.402 +    mImpl = ToRect (TmpRect);
   1.403 +    return *this;
   1.404 +  }
   1.405 +
   1.406 +  nsIntRegion& Or   (const nsIntRegion& aRgn1,   const nsIntRegion& aRgn2)
   1.407 +  {
   1.408 +    mImpl.Or (aRgn1.mImpl, aRgn2.mImpl);
   1.409 +    return *this;
   1.410 +  }
   1.411 +  nsIntRegion& Or   (const nsIntRegion& aRegion, const nsIntRect& aRect)
   1.412 +  {
   1.413 +    mImpl.Or (aRegion.mImpl, ToRect (aRect));
   1.414 +    return *this;
   1.415 +  }
   1.416 +  nsIntRegion& Or   (const nsIntRect& aRect, const nsIntRegion& aRegion)
   1.417 +  {
   1.418 +    return  Or   (aRegion, aRect);
   1.419 +  }
   1.420 +  nsIntRegion& Or   (const nsIntRect& aRect1, const nsIntRect& aRect2)
   1.421 +  {
   1.422 +    mImpl = ToRect (aRect1);
   1.423 +    return Or (*this, aRect2);
   1.424 +  }
   1.425 +
   1.426 +  nsIntRegion& Xor  (const nsIntRegion& aRgn1,   const nsIntRegion& aRgn2)
   1.427 +  {
   1.428 +    mImpl.Xor (aRgn1.mImpl, aRgn2.mImpl);
   1.429 +    return *this;
   1.430 +  }
   1.431 +  nsIntRegion& Xor  (const nsIntRegion& aRegion, const nsIntRect& aRect)
   1.432 +  {
   1.433 +    mImpl.Xor (aRegion.mImpl, ToRect (aRect));
   1.434 +    return *this;
   1.435 +  }
   1.436 +  nsIntRegion& Xor  (const nsIntRect& aRect, const nsIntRegion& aRegion)
   1.437 +  {
   1.438 +    return  Xor  (aRegion, aRect);
   1.439 +  }
   1.440 +  nsIntRegion& Xor  (const nsIntRect& aRect1, const nsIntRect& aRect2)
   1.441 +  {
   1.442 +    mImpl = ToRect (aRect1);
   1.443 +    return Xor (*this, aRect2);
   1.444 +  }
   1.445 +
   1.446 +  nsIntRegion& Sub  (const nsIntRegion& aRgn1,   const nsIntRegion& aRgn2)
   1.447 +  {
   1.448 +    mImpl.Sub (aRgn1.mImpl, aRgn2.mImpl);
   1.449 +    return *this;
   1.450 +  }
   1.451 +  nsIntRegion& Sub  (const nsIntRegion& aRegion, const nsIntRect& aRect)
   1.452 +  {
   1.453 +    mImpl.Sub (aRegion.mImpl, ToRect (aRect));
   1.454 +    return *this;
   1.455 +  }
   1.456 +  nsIntRegion& Sub  (const nsIntRect& aRect, const nsIntRegion& aRegion)
   1.457 +  {
   1.458 +    return Sub (nsIntRegion (aRect), aRegion);
   1.459 +  }
   1.460 +  nsIntRegion& Sub  (const nsIntRect& aRect1, const nsIntRect& aRect2)
   1.461 +  {
   1.462 +    mImpl = ToRect (aRect1);
   1.463 +    return Sub (*this, aRect2);
   1.464 +  }
   1.465 +
   1.466 +  bool Contains (const nsIntRect& aRect) const
   1.467 +  {
   1.468 +    return mImpl.Contains (ToRect (aRect));
   1.469 +  }
   1.470 +  bool Contains (const nsIntRegion& aRgn) const
   1.471 +  {
   1.472 +    return mImpl.Contains (aRgn.mImpl);
   1.473 +  }
   1.474 +  bool Intersects (const nsIntRect& aRect) const
   1.475 +  {
   1.476 +    return mImpl.Intersects (ToRect (aRect));
   1.477 +  }
   1.478 +
   1.479 +  void MoveBy (int32_t aXOffset, int32_t aYOffset)
   1.480 +  {
   1.481 +    MoveBy (nsIntPoint (aXOffset, aYOffset));
   1.482 +  }
   1.483 +  void MoveBy (nsIntPoint aPt)
   1.484 +  {
   1.485 +    mImpl.MoveBy (aPt.x, aPt.y);
   1.486 +  }
   1.487 +  nsIntRegion MovedBy(int32_t aXOffset, int32_t aYOffset) const
   1.488 +  {
   1.489 +    return MovedBy(nsIntPoint(aXOffset, aYOffset));
   1.490 +  }
   1.491 +  nsIntRegion MovedBy(const nsIntPoint& aPt) const
   1.492 +  {
   1.493 +    nsIntRegion copy(*this);
   1.494 +    copy.MoveBy(aPt);
   1.495 +    return copy;
   1.496 +  }
   1.497 +
   1.498 +  nsIntRegion Intersect(const nsIntRegion& aOther) const
   1.499 +  {
   1.500 +    nsIntRegion intersection;
   1.501 +    intersection.And(*this, aOther);
   1.502 +    return intersection;
   1.503 +  }
   1.504 +
   1.505 +  void Inflate(const nsIntMargin& aMargin)
   1.506 +  {
   1.507 +    mImpl.Inflate(nsMargin(aMargin.top, aMargin.right, aMargin.bottom, aMargin.left));
   1.508 +  }
   1.509 +  nsIntRegion Inflated(const nsIntMargin& aMargin) const
   1.510 +  {
   1.511 +    nsIntRegion copy(*this);
   1.512 +    copy.Inflate(aMargin);
   1.513 +    return copy;
   1.514 +  }
   1.515 +
   1.516 +  void SetEmpty ()
   1.517 +  {
   1.518 +    mImpl.SetEmpty  ();
   1.519 +  }
   1.520 +
   1.521 +  bool IsEmpty () const { return mImpl.IsEmpty (); }
   1.522 +  bool IsComplex () const { return mImpl.IsComplex (); }
   1.523 +  bool IsEqual (const nsIntRegion& aRegion) const
   1.524 +  {
   1.525 +    return mImpl.IsEqual (aRegion.mImpl);
   1.526 +  }
   1.527 +  uint32_t GetNumRects () const { return mImpl.GetNumRects (); }
   1.528 +  nsIntRect GetBounds () const { return FromRect (mImpl.GetBounds ()); }
   1.529 +  uint64_t Area () const { return mImpl.Area(); }
   1.530 +  nsRegion ToAppUnits (nscoord aAppUnitsPerPixel) const;
   1.531 +  nsIntRect GetLargestRectangle (const nsIntRect& aContainingRect = nsIntRect()) const
   1.532 +  {
   1.533 +    return FromRect (mImpl.GetLargestRectangle( ToRect(aContainingRect) ));
   1.534 +  }
   1.535 +
   1.536 +  nsIntRegion& ScaleRoundOut (float aXScale, float aYScale)
   1.537 +  {
   1.538 +    mImpl.ScaleRoundOut(aXScale, aYScale);
   1.539 +    return *this;
   1.540 +  }
   1.541 +
   1.542 +  /**
   1.543 +   * Make sure the region has at most aMaxRects by adding area to it
   1.544 +   * if necessary. The simplified region will be a superset of the
   1.545 +   * original region. The simplified region's bounding box will be
   1.546 +   * the same as for the current region.
   1.547 +   */
   1.548 +  void SimplifyOutward (uint32_t aMaxRects)
   1.549 +  {
   1.550 +    mImpl.SimplifyOutward (aMaxRects);
   1.551 +  }
   1.552 +  void SimplifyOutwardByArea (uint32_t aThreshold)
   1.553 +  {
   1.554 +    mImpl.SimplifyOutwardByArea (aThreshold);
   1.555 +  }
   1.556 +  /**
   1.557 +   * Make sure the region has at most aMaxRects by removing area from
   1.558 +   * it if necessary. The simplified region will be a subset of the
   1.559 +   * original region.
   1.560 +   */
   1.561 +  void SimplifyInward (uint32_t aMaxRects)
   1.562 +  {
   1.563 +    mImpl.SimplifyInward (aMaxRects);
   1.564 +  }
   1.565 +
   1.566 +  nsCString ToString() const { return mImpl.ToString(); }
   1.567 +
   1.568 +private:
   1.569 +  nsRegion mImpl;
   1.570 +
   1.571 +  static nsRect ToRect(const nsIntRect& aRect)
   1.572 +  {
   1.573 +    return nsRect (aRect.x, aRect.y, aRect.width, aRect.height);
   1.574 +  }
   1.575 +  static nsIntRect FromRect(const nsRect& aRect)
   1.576 +  {
   1.577 +    return nsIntRect (aRect.x, aRect.y, aRect.width, aRect.height);
   1.578 +  }
   1.579 +};
   1.580 +
   1.581 +class NS_GFX nsIntRegionRectIterator
   1.582 +{
   1.583 +  nsRegionRectIterator mImpl;
   1.584 +  nsIntRect mTmp;
   1.585 +
   1.586 +public:
   1.587 +  nsIntRegionRectIterator (const nsIntRegion& aRegion) : mImpl (aRegion.mImpl) {}
   1.588 +
   1.589 +  const nsIntRect* Next ()
   1.590 +  {
   1.591 +    const nsRect* r = mImpl.Next();
   1.592 +    if (!r)
   1.593 +      return nullptr;
   1.594 +    mTmp = nsIntRegion::FromRect (*r);
   1.595 +    return &mTmp;
   1.596 +  }
   1.597 +
   1.598 +  const nsIntRect* Prev ()
   1.599 +  {
   1.600 +    const nsRect* r = mImpl.Prev();
   1.601 +    if (!r)
   1.602 +      return nullptr;
   1.603 +    mTmp = nsIntRegion::FromRect (*r);
   1.604 +    return &mTmp;
   1.605 +  }
   1.606 +
   1.607 +  void Reset ()
   1.608 +  {
   1.609 +    mImpl.Reset ();
   1.610 +  }
   1.611 +};
   1.612 +#endif

mercurial