Bug 958008 - Avoid copying images on Android/Gonk when there's nothing to optimize. r=jrmuizel, a=1.3+
authorMichael Wu <mwu@mozilla.com>
Tue, 14 Jan 2014 11:12:36 +0800
changeset 175979 d53dc428fc555acb3999b6c4a58cf2f05d949766
parent 175978 995f9a8971a5cbadf6f4f72ae461b09f2ce247dc
child 175980 f6b914730a9c4ba01b2b7799a159859f2cae174a
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, 1
bugs958008
milestone28.0a2
Bug 958008 - Avoid copying images on Android/Gonk when there's nothing to optimize. r=jrmuizel, a=1.3+
gfx/thebes/gfxAndroidPlatform.cpp
gfx/thebes/gfxAndroidPlatform.h
--- a/gfx/thebes/gfxAndroidPlatform.cpp
+++ b/gfx/thebes/gfxAndroidPlatform.cpp
@@ -128,16 +128,29 @@ gfxAndroidPlatform::CreateOffscreenSurfa
                                       gfxContentType contentType)
 {
     nsRefPtr<gfxASurface> newSurface;
     newSurface = new gfxImageSurface(size, OptimalFormatForContent(contentType));
 
     return newSurface.forget();
 }
 
+already_AddRefed<gfxASurface>
+gfxAndroidPlatform::OptimizeImage(gfxImageSurface *aSurface,
+                                  gfxImageFormat format)
+{
+    /* Android/Gonk have no special offscreen surfaces so we can avoid a copy */
+    if (OptimalFormatForContent(gfxASurface::ContentFromFormat(format)) ==
+        format) {
+        return nullptr;
+    }
+
+    return gfxPlatform::OptimizeImage(aSurface, format);
+}
+
 static bool
 IsJapaneseLocale()
 {
     static bool sInitialized = false;
     static bool sIsJapanese = false;
 
     if (!sInitialized) {
         sInitialized = true;
--- a/gfx/thebes/gfxAndroidPlatform.h
+++ b/gfx/thebes/gfxAndroidPlatform.h
@@ -30,16 +30,19 @@ public:
 
     static gfxAndroidPlatform *GetPlatform() {
         return (gfxAndroidPlatform*) gfxPlatform::GetPlatform();
     }
 
     virtual already_AddRefed<gfxASurface>
     CreateOffscreenSurface(const gfxIntSize& size,
                            gfxContentType contentType);
+    virtual already_AddRefed<gfxASurface>
+    OptimizeImage(gfxImageSurface *aSurface,
+                  gfxImageFormat format) MOZ_OVERRIDE;
     
     virtual gfxImageFormat GetOffscreenFormat() { return mOffscreenFormat; }
     
     mozilla::TemporaryRef<mozilla::gfx::ScaledFont>
       GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont);
 
     // to support IPC font list (sharing between chrome and content)
     void GetFontList(InfallibleTArray<FontListEntry>* retValue);