Bug 1385164 - Using gfxContextAutoSaveRestore to prevent unpaired gfxContext::Save/Restore. draft
authorcku <cku@mozilla.com>
Fri, 28 Jul 2017 11:34:50 +0800
changeset 617185 f80aad877ff2aa5f7a2be14ea282b68417501329
parent 616205 f1693d664f8e8ee4c79801630c181c28095cad56
child 639738 d1e02f5782e076c2b9c530ceb8fd07e472407c70
push id70971
push usercku@mozilla.com
push dateFri, 28 Jul 2017 03:35:53 +0000
bugs1385164
milestone56.0a1
Bug 1385164 - Using gfxContextAutoSaveRestore to prevent unpaired gfxContext::Save/Restore. MozReview-Commit-ID: 8JtqftYQTHN
gfx/layers/basic/BasicLayerManager.cpp
--- a/gfx/layers/basic/BasicLayerManager.cpp
+++ b/gfx/layers/basic/BasicLayerManager.cpp
@@ -87,17 +87,17 @@ BasicLayerManager::PushGroupForLayer(gfx
   // If we need to call PushGroup, we should clip to the smallest possible
   // area first to minimize the size of the temporary surface.
   bool didCompleteClip = ClipToContain(aContext, aRegion.GetBounds());
 
   bool canPushGroup = aGroupResult.mOperator == CompositionOp::OP_OVER ||
     (aGroupResult.mOperator == CompositionOp::OP_SOURCE && (aLayer->CanUseOpaqueSurface() || aLayer->GetContentFlags() & Layer::CONTENT_COMPONENT_ALPHA));
 
   if (!canPushGroup) {
-    aContext->Save();
+    gfxContextAutoSaveRestore autoSR(aContext);
     gfxUtils::ClipToRegion(aGroupResult.mFinalTarget, aGroupResult.mVisibleRegion);
 
     // PushGroup/PopGroup do not support non operator over.
     gfxMatrix oldMat = aContext->CurrentMatrix();
     aContext->SetMatrix(gfxMatrix());
     gfxRect rect = aContext->GetClipExtents();
     aContext->SetMatrix(oldMat);
     rect.RoundOut();
@@ -116,17 +116,16 @@ BasicLayerManager::PushGroupForLayer(gfx
       ctx->SetMatrix(oldMat);
 
       aGroupResult.mGroupOffset = surfRect.TopLeft();
       aGroupResult.mGroupTarget = ctx;
 
       aGroupResult.mMaskSurface = GetMaskForLayer(aLayer, &aGroupResult.mMaskTransform);
       return true;
     }
-    aContext->Restore();
   }
 
   Matrix maskTransform;
   RefPtr<SourceSurface> maskSurf = GetMaskForLayer(aLayer, &maskTransform);
 
   if (maskSurf) {
     // The returned transform will transform the mask to device space on the
     // destination. Since the User->Device space transform will be applied