Bug 922942 - Do image scaling in imgTools using azure. r=seth
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 16 Oct 2013 14:00:31 +1300
changeset 164691 53c610770178a15e0754b1f214c2d35ec07f9323
parent 164690 d0fc1cc4c62b1b219ef3498e76b89a93c1b8cdd1
child 164692 c62ad7dd57cdd08b7bdb888173a5c1057ff4fa1b
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [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
toolkit/components/places/tests/favicons/expected-favicon-big4.jpg.png
toolkit/components/places/tests/favicons/expected-favicon-scale160x3.jpg.png
toolkit/components/places/tests/favicons/expected-favicon-scale3x160.jpg.png
--- 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#O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$$a{KDlY>tcLIe_onA?yE%$N@F1*R$AY
zq|I#RLn~HrYgSgceDmf|U0t2p+}x~o)_B!Zzu2sH8Z*?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++;
index 1175ba32034339ca14228d18eab23747e411a58f..01ef1cb21af23c0b9a98c7f7d7528c146003ceae
GIT binary patch
literal 221
zc$@*<03!d1P)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV0001_Nkl<ZIE~$t
zv5iDA2t>c+kdTmoz-3Sd1rWF#il7)5LMgMc?}t8Vr5)*|FMyfnc^+KyPl7Q9hzQIK
z5rL{6hzOV&M1(QMTR=pZbHdEv?udv3cZZo_&IuxV3z!*ZhP4(l6IFGPnOJMV%)rcV
zfr!A}k(t<gqq`6G-pEY2J4ECyP*p?(stVnWzv*sN6(Rzv`jdj|BVNDpx=7bm{@NNp
Xq#?avna<MG00000NkvXXu0mjfgGO3k
index 1b121e9951835972d5540b4f85eff512c0d83e8e..1368150071ef06d0e6ec3e84b9cef72a221e3c39
GIT binary patch
literal 122
zc%17D@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`j-D=#Ar`$yFB=LnIB+l@EN)g&
zQRMVIaiV+2qwZW|XNCrk{miSh*zU?U&+I(-?%0EONk15DoAd(L2g+aiAHRW-Ke6+V
V!9|6Q#X!RtJYD@<);T3K0RR({C~5!z
index 56021cbd591c8ced583cf2fa158023bd73832bf0..0bfe1378e6707666d4164f9ccec2b79a6c406bd5
GIT binary patch
literal 116
zc%17D@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`)}AhoAr`%F&lvI^U=U#nyraPB
z>ER?~^y11Asaf`SD)<?`xfM-HtM<HBmODLVn|h|o_u7I3jO>3{D;N?x{}@~>&#(p>
O!{F)a=d#Wzp$P!{jU+Gt