Bug 675837 - Add gfxContext::ClipContainsRect. r=roc
authorMatt Woodrow <mwoodrow@mozilla.com>
Sat, 27 Aug 2011 12:03:04 +1200
changeset 77288 40e4402d497275ffc668b121ef1c4921ba5dc7c7
parent 77287 1de7e151b2ad93b5c1261053bb8fd36a00a83f7d
child 77289 7ccff3faa2a3a2655cfc6a6c6c8850b0aa86679a
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs675837
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 675837 - Add gfxContext::ClipContainsRect. r=roc
gfx/thebes/gfxContext.cpp
gfx/thebes/gfxContext.h
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -691,16 +691,39 @@ gfxContext::UpdateSurfaceClip()
 gfxRect
 gfxContext::GetClipExtents()
 {
     double xmin, ymin, xmax, ymax;
     cairo_clip_extents(mCairo, &xmin, &ymin, &xmax, &ymax);
     return gfxRect(xmin, ymin, xmax - xmin, ymax - ymin);
 }
 
+PRBool
+gfxContext::ClipContainsRect(const gfxRect& aRect)
+{
+    cairo_rectangle_list_t *clip =
+        cairo_copy_clip_rectangle_list(mCairo);
+
+    PRBool result = PR_FALSE;
+
+    if (clip->status == CAIRO_STATUS_SUCCESS) {
+        for (int i = 0; i < clip->num_rectangles; i++) {
+            gfxRect rect(clip->rectangles[i].x, clip->rectangles[i].y,
+                         clip->rectangles[i].width, clip->rectangles[i].height);
+            if (rect.Contains(aRect)) {
+                result = PR_TRUE;
+                break;
+            }
+        }
+    }
+
+   cairo_rectangle_list_destroy(clip);
+   return result;
+}
+
 // rendering sources
 
 void
 gfxContext::SetColor(const gfxRGBA& c)
 {
     if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
 
         gfxRGBA cms;
--- a/gfx/thebes/gfxContext.h
+++ b/gfx/thebes/gfxContext.h
@@ -601,16 +601,23 @@ public:
 
     /**
      * This will return the current bounds of the clip region in user
      * space.
      */
     gfxRect GetClipExtents();
 
     /**
+     * Returns true if the given rectangle is fully contained in the current clip. 
+     * This is conservative; it may return false even when the given rectangle is 
+     * fully contained by the current clip.
+     */
+    PRBool ClipContainsRect(const gfxRect& aRect);
+
+    /**
      * Groups
      */
     void PushGroup(gfxASurface::gfxContentType content = gfxASurface::CONTENT_COLOR);
     /**
      * Like PushGroup, but if the current surface is CONTENT_COLOR and
      * content is CONTENT_COLOR_ALPHA, makes the pushed surface CONTENT_COLOR
      * instead and copies the contents of the current surface to the pushed
      * surface. This is good for pushing opacity groups, since blending the