Bug 627273, part 3: Add gfxContext::FillWithOpacity. sr=vlad
authorChris Jones <jones.chris.g@gmail.com>
Wed, 26 Jan 2011 00:26:37 -0600
changeset 61311 da677975bab102f9a06af64c7448c53dc47e2f74
parent 61310 3bdbbd75eb04786b2560dcf762c4da9172983aea
child 61312 73bfa3627d0c9cf0e21d3c630760926543285b92
push idunknown
push userunknown
push dateunknown
reviewersvlad
bugs627273
milestone2.0b11pre
Bug 627273, part 3: Add gfxContext::FillWithOpacity. sr=vlad
gfx/layers/basic/BasicLayers.cpp
gfx/thebes/gfxContext.cpp
gfx/thebes/gfxContext.h
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -738,24 +738,17 @@ BasicImageLayer::PaintContext(gfxPattern
 
   aPattern->SetExtend(extend);
 
   /* Draw RGB surface onto frame */
   aContext->NewPath();
   // No need to snap here; our transform has already taken care of it.
   aContext->Rectangle(gfxRect(0, 0, aSize.width, aSize.height));
   aContext->SetPattern(aPattern);
-  if (aOpacity != 1.0) {
-    aContext->Save();
-    aContext->Clip();
-    aContext->Paint(aOpacity);
-    aContext->Restore();
-  } else {
-    aContext->Fill();
-  }
+  aContext->FillWithOpacity(aOpacity);
 }
 
 class BasicColorLayer : public ColorLayer, BasicImplData {
 public:
   BasicColorLayer(BasicLayerManager* aLayerManager) :
     ColorLayer(aLayerManager, static_cast<BasicImplData*>(this))
   {
     MOZ_COUNT_CTOR(BasicColorLayer);
@@ -957,24 +950,17 @@ BasicCanvasLayer::PaintWithOpacity(gfxCo
     aContext->Translate(gfxPoint(0.0, mBounds.height));
     aContext->Scale(1.0, -1.0);
   }
 
   aContext->NewPath();
   // No need to snap here; our transform is already set up to snap our rect
   aContext->Rectangle(gfxRect(0, 0, mBounds.width, mBounds.height));
   aContext->SetPattern(pat);
-  if (aOpacity != 1.0) {
-    aContext->Save();
-    aContext->Clip();
-    aContext->Paint(aOpacity);
-    aContext->Restore();
-  } else {
-    aContext->Fill();
-  }
+  aContext->FillWithOpacity(aOpacity);
 
   if (mNeedsYFlip) {
     aContext->SetMatrix(m);
   }
 
   mUpdatedRect.Empty();
 }
 
@@ -2491,17 +2477,17 @@ BasicShadowCanvasLayer::Paint(gfxContext
   pat->SetFilter(mFilter);
   pat->SetExtend(gfxPattern::EXTEND_PAD);
 
   gfxRect r(0, 0, mBounds.width, mBounds.height);
   aContext->NewPath();
   // No need to snap here; our transform has already taken care of it
   aContext->Rectangle(r);
   aContext->SetPattern(pat);
-  aContext->Fill();
+  aContext->FillWithOpacity(GetEffectiveOpacity());
 }
 
 // Create a shadow layer (PLayerChild) for aLayer, if we're forwarding
 // our layer tree to a parent process.  Record the new layer creation
 // in the current open transaction as a side effect.
 template<typename CreatedMethod>
 static void
 MaybeCreateShadowFor(BasicShadowableLayer* aLayer,
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -147,16 +147,31 @@ gfxContext::Stroke()
 
 void
 gfxContext::Fill()
 {
     cairo_fill_preserve(mCairo);
 }
 
 void
+gfxContext::FillWithOpacity(gfxFloat aOpacity)
+{
+  // This method exists in the hope that one day cairo gets a direct
+  // API for this, and then we would change this method to use that
+  // API instead.
+  if (aOpacity != 1.0) {
+    gfxContextAutoSaveRestore saveRestore(this);
+    Clip();
+    Paint(aOpacity);
+  } else {
+    Fill();
+  }
+}
+
+void
 gfxContext::MoveTo(const gfxPoint& pt)
 {
     cairo_move_to(mCairo, pt.x, pt.y);
 }
 
 void
 gfxContext::NewSubPath()
 {
--- a/gfx/thebes/gfxContext.h
+++ b/gfx/thebes/gfxContext.h
@@ -125,16 +125,24 @@ public:
     /**
      * Fill the current path according to the current settings.
      *
      * Does not consume the current path.
      */
     void Fill();
 
     /**
+     * Fill the current path according to the current settings and
+     * with |aOpacity|.
+     *
+     * Does not consume the current path.
+     */
+    void FillWithOpacity(gfxFloat aOpacity);
+
+    /**
      * Forgets the current path.
      */
     void NewPath();
 
     /**
      * Closes the path, i.e. connects the last drawn point to the first one.
      *
      * Filling a path will implicitly close it.