Bug 922942 - Do image scaling in imgTools using azure. r=seth
☠☠ backed out by da01cc64591f ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 16 Oct 2013 14:00:31 +1300
changeset 165622 c0e5db20b6556eed713a25e9ccd93489e5eb71ed
parent 165621 95427fe5f9b95b68cc7031c68d8e0dbd87592e5c
child 165623 d1881913d9a676f2a6ef45a6da3bf20c0f33c8f6
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth
bugs922942
milestone27.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 922942 - Do image scaling in imgTools using azure. r=seth
image/src/imgTools.cpp
image/test/unit/image3ico32x32.png
image/test/unit/test_imgtools.js
--- a/image/src/imgTools.cpp
+++ b/image/src/imgTools.cpp
@@ -18,18 +18,21 @@
 #include "nsComponentManagerUtils.h"
 #include "nsStreamUtils.h"
 #include "nsNetUtil.h"
 #include "nsContentUtils.h"
 #include "ImageFactory.h"
 #include "Image.h"
 #include "ScriptedNotificationObserver.h"
 #include "imgIScriptedNotificationObserver.h"
+#include "gfxPlatform.h"
 
+using namespace mozilla;
 using namespace mozilla::image;
+using namespace mozilla::gfx;
 
 /* ========== imgITools implementation ========== */
 
 
 
 NS_IMPL_ISUPPORTS1(imgTools, imgITools)
 
 imgTools::imgTools()
@@ -139,27 +142,43 @@ NS_IMETHODIMP imgTools::EncodeScaledImag
     aScaledWidth = frameWidth;
   } else if (aScaledHeight == 0) {
     aScaledHeight = frameHeight;
   }
 
   // Create a temporary image surface
   nsRefPtr<gfxImageSurface> dest = new gfxImageSurface(gfxIntSize(aScaledWidth, aScaledHeight),
                                                        gfxImageFormatARGB32);
-  gfxContext ctx(dest);
+  if (gfxPlatform::GetPlatform()->SupportsAzureContent()) {
+    RefPtr<DrawTarget> dt =
+      gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(dest, IntSize(aScaledWidth, aScaledHeight));
+    RefPtr<SourceSurface> source = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, frame);
+
+    dt->DrawSurface(source,
+                    Rect(0, 0, aScaledWidth, aScaledHeight),
+                    Rect(0, 0, frameWidth, frameHeight),
+                    DrawSurfaceOptions(),
+                    DrawOptions(1.0f, OP_SOURCE));
+  } else {
+    gfxContext ctx(dest);
 
-  // Set scaling
-  gfxFloat sw = (double) aScaledWidth / frameWidth;
-  gfxFloat sh = (double) aScaledHeight / frameHeight;
-  ctx.Scale(sw, sh);
+    // Set scaling
+    gfxFloat sw = (double) aScaledWidth / frameWidth;
+    gfxFloat sh = (double) aScaledHeight / frameHeight;
+    ctx.Scale(sw, sh);
 
-  // Paint a scaled image
-  ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
-  ctx.SetSource(frame);
-  ctx.Paint();
+    // Paint a scaled image
+    ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
+
+    nsRefPtr<gfxPattern> pat = new gfxPattern(frame);
+    pat->SetExtend(gfxPattern::EXTEND_PAD);
+    ctx.SetPattern(pat);
+    ctx.Paint();
+  }
+
 
   return EncodeImageData(dest, aMimeType, aOutputOptions, aStream);
 }
 
 NS_IMETHODIMP imgTools::EncodeCroppedImage(imgIContainer *aContainer,
                                            const nsACString& aMimeType,
                                            int32_t aOffsetX,
                                            int32_t aOffsetY,
index 421b9ce30d13399ab7520119b5edb9f737eb2319..58497e3fa006eb6fc457aec0c05eedd7035fa20f
GIT binary patch
literal 2285
zc$@+42om>+P)<h;3K|Lk000e1NJLTq001BW001Be1^@s6b9#F8000QINkl<ZScT1(
zZA@HM8pr?4oerEbGNmI3<*qPgm_mUL(-A5*^>*nS6s82|P#OU{xHF>&4x}%L6_K{I
zL)(>teWS}#ERY(sR0*bj&|F@&apRIqccXDvv(e}#nl+n=o0>K8!+$@_g{@6Z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?g45R9DWvWMx98`ygM|(#`
zM!s8$Yin!S($d0X$Bwb<si#<PwbBFd_#Lu-0bnF5idA|&A6l`3yEbp;uXgVa)$iIB
zsH>|}nwy)Ij@@3RU*4j07_ExSYE)dVOy%g&c4cH_#6CVg{-49hYPG6fuUGBs>kEyI
zjfHy;9b!dxHg_P>fLyyph0g(gpmjvQiPf=E7`Wm7`@?(O?$Ch)2YTDu+J0D5s@Llk
ztJSJ_y<R043<i37dO~}BJ{GTB$$BlTZ*_hRk&b9o2D{S@+$x)yla?0RwsB*it*y=8
z*4Fmp+w$Ybk1N4oP~F?u$l~m5J}Ly?l%&OqxRCuX2=IsuKA9QIqMUTv?RGUcH}~$X
z*WGMlVnUgim{5C9oM1(9F)L-6{X#5O#D(nttpxf7Semk&C4~hnE-qF}N=kk@z}(!N
zeP(8+cW`h}b-UfF+u;bE%*zYEZng4;(a86;v)~Lsmrlq0q$IjFZDLJLjk<gH?w<}Y
zKR<7po13!_4Gk%7w_AD6?+?7v(-V5FsflA&D+d9dMdZlMHyD_in#vuerSy0_s>kE`
z=>WIef+DY-I;Eb<%Tu2R)aL>9F-cN0V`5Z`#iEv%m#aRXuh;MQ|M)A}_t}CXll}cl
zzr&#%0+d65;sKP*m>4B3ElqK`T#DcCxBGm)pYKxozqEe?4Z#qjs*EUi00000NkvXX
Hu0mjf-V|(k
--- a/image/test/unit/test_imgtools.js
+++ b/image/test/unit/test_imgtools.js
@@ -284,17 +284,17 @@ testdesc = "test encoding a scaled PNG";
 // we'll reuse the container from the previous test
 istream = imgTools.encodeScaledImage(container, "image/png", 32, 32);
 encodedBytes = streamToArray(istream);
 
 // Get bytes for exected result
 refName = "image3ico32x32.png";
 refFile = do_get_file(refName);
 istream = getFileInputStream(refFile);
-do_check_eq(istream.available(), 2281);
+do_check_eq(istream.available(), 2285);
 referenceBytes = streamToArray(istream);
 
 // compare the encoder's output to the reference file.
 compareArrays(encodedBytes, referenceBytes);
 
 
 /* ========== 9 ========== */
 testnum++;