Bug 1058040, part 6 - When copying SVGImageContexts use the copy ctor. r=dholbert
authorJonathan Watt <jwatt@jwatt.org>
Mon, 09 Jan 2017 19:12:02 +0000
changeset 340973 b6959c93a4f797df7a6ce95e79a5490bc9004f04
parent 340972 8475919c50b5e7874af3856ae8a8cc4778939102
child 340974 d3db704e690efdd091d32d5ae41d348db8ff5e48
push id31322
push userkwierso@gmail.com
push dateTue, 07 Feb 2017 01:45:28 +0000
treeherdermozilla-central@af8a2573d0f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1058040
milestone54.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 1058040, part 6 - When copying SVGImageContexts use the copy ctor. r=dholbert Prior to this patch whenever we wanted to pass on a modified SVGImageContext we would pass on a new object initialized with some of the data of the object we were given and with the new data we wanted to change. Unfortunately we were sometimes failing to faithfully copy member data that we do not want to modify (because of default arguments). This patch fixes that by making us fully copy the object we were given using its copy constructor and then explicitly override the data we want to change.
image/ClippedImage.cpp
image/OrientedImage.cpp
image/VectorImage.cpp
layout/svg/SVGImageContext.h
--- a/image/ClippedImage.cpp
+++ b/image/ClippedImage.cpp
@@ -467,18 +467,19 @@ ClippedImage::DrawSingleTile(gfxContext*
     // The size in pixels at which the output will ultimately be drawn is
     // irrelevant here since the purpose of the SVG viewport size is to
     // determine what *region* of the SVG document will be drawn.
     CSSIntSize vSize(aOldContext.GetViewportSize());
     vSize.width = ceil(vSize.width * double(innerSize.width) / mClip.width);
     vSize.height =
       ceil(vSize.height * double(innerSize.height) / mClip.height);
 
-    return SVGImageContext(vSize,
-                           aOldContext.GetPreserveAspectRatio());
+    SVGImageContext context(aOldContext);
+    context.SetViewportSize(vSize);
+    return context;
   };
 
   return InnerImage()->Draw(aContext, size, region,
                             aWhichFrame, aSamplingFilter,
                             aSVGContext.map(unclipViewport),
                             aFlags, aOpacity);
 }
 
--- a/image/OrientedImage.cpp
+++ b/image/OrientedImage.cpp
@@ -292,18 +292,19 @@ OrientedImage::Draw(gfxContext* aContext
   ImageRegion region(aRegion);
   region.TransformBoundsBy(inverseMatrix);
 
   auto orientViewport = [&](const SVGImageContext& aOldContext) {
     CSSIntSize viewportSize(aOldContext.GetViewportSize());
     if (mOrientation.SwapsWidthAndHeight()) {
       swap(viewportSize.width, viewportSize.height);
     }
-    return SVGImageContext(viewportSize,
-                           aOldContext.GetPreserveAspectRatio());
+    SVGImageContext context(aOldContext);
+    context.SetViewportSize(viewportSize);
+    return context;
   };
 
   return InnerImage()->Draw(aContext, size, region, aWhichFrame,
                             aSamplingFilter,
                             aSVGContext.map(orientViewport), aFlags,
                             aOpacity);
 }
 
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -850,19 +850,18 @@ VectorImage::Draw(gfxContext* aContext,
   // overwrite SVG preserveAspectRatio attibute of this image with none, and
   // always stretch this image to viewport non-uniformly.
   // And we can do this only if the caller pass in the the SVG viewport, via
   // aSVGContext.
   if ((aFlags & FLAG_FORCE_PRESERVEASPECTRATIO_NONE) && aSVGContext.isSome()) {
     Maybe<SVGPreserveAspectRatio> aspectRatio =
       Some(SVGPreserveAspectRatio(SVG_PRESERVEASPECTRATIO_NONE,
                                   SVG_MEETORSLICE_UNKNOWN));
-    svgContext =
-      Some(SVGImageContext(aSVGContext->GetViewportSize(),
-                           aspectRatio));
+    svgContext = Some(SVGImageContext(*aSVGContext)); // copy
+    svgContext->SetPreserveAspectRatio(aspectRatio);
   } else {
     svgContext = aSVGContext;
   }
 
   float animTime =
     (aWhichFrame == FRAME_FIRST) ? 0.0f
                                  : mSVGDocumentWrapper->GetCurrentTime();
   AutoSVGRenderingState autoSVGState(svgContext, animTime,
--- a/layout/svg/SVGImageContext.h
+++ b/layout/svg/SVGImageContext.h
@@ -35,20 +35,28 @@ public:
     , mGlobalOpacity(aOpacity)
     , mIsPaintingSVGImageElement(aIsPaintingSVGImageElement)
   { }
 
   const CSSIntSize& GetViewportSize() const {
     return mViewportSize;
   }
 
+  void SetViewportSize(const CSSIntSize& aSize) {
+    mViewportSize = aSize;
+  }
+
   const Maybe<SVGPreserveAspectRatio>& GetPreserveAspectRatio() const {
     return mPreserveAspectRatio;
   }
 
+  void SetPreserveAspectRatio(const Maybe<SVGPreserveAspectRatio>& aPAR) {
+    mPreserveAspectRatio = aPAR;
+  }
+
   gfxFloat GetGlobalOpacity() const {
     return mGlobalOpacity;
   }
 
   bool IsPaintingForSVGImageElement() const {
     return mIsPaintingSVGImageElement;
   }