Bug 1358828, part 3 - Split AutoSVGRenderingState into two separate classes. r=longsonr
authorJonathan Watt <jwatt@jwatt.org>
Mon, 03 Apr 2017 10:40:13 +0100
changeset 354830 72f0302be66e5fcef5fb406b126bd2d723d917e5
parent 354829 0498fdd7a14a25a176221155df8bc9e24b2edf09
child 354831 1f22418d5d8fac399fcd2b59b9244010386d4050
push id31714
push userkwierso@gmail.com
push dateTue, 25 Apr 2017 20:53:09 +0000
treeherdermozilla-central@2c497462f25e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1358828
milestone55.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 1358828, part 3 - Split AutoSVGRenderingState into two separate classes. r=longsonr MozReview-Commit-ID: CmBB3MHU4Dt
dom/svg/SVGSVGElement.h
image/VectorImage.cpp
--- a/dom/svg/SVGSVGElement.h
+++ b/dom/svg/SVGSVGElement.h
@@ -24,17 +24,18 @@ nsresult NS_NewSVGSVGElement(nsIContent 
                              already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
                              mozilla::dom::FromParser aFromParser);
 
 class nsSMILTimeContainer;
 class nsSVGOuterSVGFrame;
 class nsSVGInnerSVGFrame;
 
 namespace mozilla {
-class AutoSVGRenderingState;
+class AutoPreserveAspectRatioOverride;
+class AutoSVGTimeSetRestore;
 class DOMSVGAnimatedPreserveAspectRatio;
 class DOMSVGLength;
 class DOMSVGNumber;
 class EventChainPreVisitor;
 class SVGFragmentIdentifier;
 class AutoSVGViewHandler;
 
 namespace dom {
@@ -103,20 +104,21 @@ private:
 };
 
 typedef SVGGraphicsElement SVGSVGElementBase;
 
 class SVGSVGElement final : public SVGSVGElementBase
 {
   friend class ::nsSVGOuterSVGFrame;
   friend class ::nsSVGInnerSVGFrame;
+  friend class mozilla::AutoPreserveAspectRatioOverride;
+  friend class mozilla::AutoSVGTimeSetRestore;
   friend class mozilla::dom::SVGView;
   friend class mozilla::SVGFragmentIdentifier;
   friend class mozilla::AutoSVGViewHandler;
-  friend class mozilla::AutoSVGRenderingState;
 
   SVGSVGElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
                 FromParser aFromParser);
   virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   friend nsresult (::NS_NewSVGSVGElement(nsIContent **aResult,
                                          already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
                                          mozilla::dom::FromParser aFromParser));
@@ -301,18 +303,18 @@ private:
                               bool aCompileEventHandlers) override;
   virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
 
   // implementation helpers:
 
   SVGViewElement* GetCurrentViewElement() const;
 
   // Methods for <image> elements to override my "PreserveAspectRatio" value.
-  // These are private so that only our friends (AutoSVGRenderingState in
-  // particular) have access.
+  // These are private so that only our friends
+  // (AutoPreserveAspectRatioOverride in particular) have access.
   void SetImageOverridePreserveAspectRatio(const SVGPreserveAspectRatio& aPAR);
   void ClearImageOverridePreserveAspectRatio();
 
   // Set/Clear properties to hold old version of preserveAspectRatio
   // when it's being overridden by an <image> element that we are inside of.
   bool SetPreserveAspectRatioProperty(const SVGPreserveAspectRatio& aPAR);
   const SVGPreserveAspectRatio* GetPreserveAspectRatioProperty() const;
   bool ClearPreserveAspectRatioProperty();
@@ -418,53 +420,70 @@ private:
   // to manually kick off animation when they are bound to the tree.
   bool     mStartAnimationOnBindToTree;
   bool     mImageNeedsTransformInvalidation;
   bool     mHasChildrenOnlyTransform;
 };
 
 } // namespace dom
 
-// Helper class to automatically manage temporary changes to an SVG document's
-// state for rendering purposes.
-class MOZ_RAII AutoSVGRenderingState
+class MOZ_RAII AutoPreserveAspectRatioOverride
 {
 public:
-  AutoSVGRenderingState(const Maybe<SVGImageContext>& aSVGContext,
-                        float aFrameTime,
-                        dom::SVGSVGElement* aRootElem
-                        MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
-    : mHaveOverrides(aSVGContext.isSome() &&
-                     aSVGContext->GetPreserveAspectRatio().isSome())
-    , mRootElem(aRootElem)
+  AutoPreserveAspectRatioOverride(const Maybe<SVGImageContext>& aSVGContext,
+                                  dom::SVGSVGElement* aRootElem
+                                  MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
+    : mRootElem(aRootElem)
   {
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     MOZ_ASSERT(mRootElem, "No SVG node to manage?");
-    if (mHaveOverrides) {
+
+    if (aSVGContext.isSome() &&
+        aSVGContext->GetPreserveAspectRatio().isSome()) {
       // Override preserveAspectRatio in our helper document.
       // XXXdholbert We should technically be overriding the helper doc's clip
       // and overflow properties here, too. See bug 272288 comment 36.
       mRootElem->SetImageOverridePreserveAspectRatio(
-          *aSVGContext->GetPreserveAspectRatio());
+                   *aSVGContext->GetPreserveAspectRatio());
+      mDidOverride = true;
     }
-
-    mOriginalTime = mRootElem->GetCurrentTime();
-    mRootElem->SetCurrentTime(aFrameTime); // Does nothing if there's no change.
   }
 
-  ~AutoSVGRenderingState()
+  ~AutoPreserveAspectRatioOverride()
   {
-    mRootElem->SetCurrentTime(mOriginalTime);
-    if (mHaveOverrides) {
+    if (mDidOverride) {
       mRootElem->ClearImageOverridePreserveAspectRatio();
     }
   }
 
 private:
-  const bool mHaveOverrides;
-  float mOriginalTime;
   const RefPtr<dom::SVGSVGElement> mRootElem;
+  bool mDidOverride;
+  MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
+};
+
+class MOZ_RAII AutoSVGTimeSetRestore
+{
+public:
+  AutoSVGTimeSetRestore(dom::SVGSVGElement* aRootElem,
+                        float aFrameTime
+                        MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
+    : mRootElem(aRootElem)
+    , mOriginalTime(mRootElem->GetCurrentTime())
+  {
+    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
+    mRootElem->SetCurrentTime(aFrameTime); // Does nothing if there's no change.
+  }
+
+  ~AutoSVGTimeSetRestore()
+  {
+    mRootElem->SetCurrentTime(mOriginalTime);
+  }
+
+private:
+  const RefPtr<dom::SVGSVGElement> mRootElem;
+  const float mOriginalTime;
   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 } // namespace mozilla
 
 #endif // SVGSVGElement_h
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -884,20 +884,23 @@ VectorImage::Draw(gfxContext* aContext,
   if (mIsDrawing) {
     NS_WARNING("Refusing to make re-entrant call to VectorImage::Draw");
     return DrawResult::TEMPORARY_ERROR;
   }
   AutoRestore<bool> autoRestoreIsDrawing(mIsDrawing);
   mIsDrawing = true;
 
   // Apply any 'preserveAspectRatio' override (if specified) to the root
-  // element, and set the animation time:
-  AutoSVGRenderingState autoSVGState(newSVGContext ? newSVGContext : aSVGContext,
-                                     animTime,
-                                     mSVGDocumentWrapper->GetRootSVGElem());
+  // element:
+  AutoPreserveAspectRatioOverride autoPAR(newSVGContext ? newSVGContext : aSVGContext,
+                                          mSVGDocumentWrapper->GetRootSVGElem());
+
+  // Set the animation time:
+  AutoSVGTimeSetRestore autoSVGTime(mSVGDocumentWrapper->GetRootSVGElem(),
+                                    animTime);
 
   // Set context paint (if specified) on the document:
   Maybe<AutoSetRestoreSVGContextPaint> autoContextPaint;
   if (aSVGContext &&
       aSVGContext->GetContextPaint()) {
     autoContextPaint.emplace(aSVGContext->GetContextPaint(),
                              mSVGDocumentWrapper->GetDocument());
   }