Bug 616469 - Video sync is slow because of slow yuv2rgb conversion. GetOffscreenFormat r=roc a=b-f
authorOleg Romashin <romaxa@gmail.com>
Wed, 15 Dec 2010 10:17:26 -0800
changeset 59199 fae6da8a664c6d4c73df880c8e1af5aa1dec6993
parent 59198 06802b3064902aae1264f64e991468af547e981a
child 59200 513cc1daf58f5bc303e89b8964f59184c681f305
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersroc, b-f
bugs616469
milestone2.0b9pre
Bug 616469 - Video sync is slow because of slow yuv2rgb conversion. GetOffscreenFormat r=roc a=b-f
gfx/thebes/gfxAndroidPlatform.cpp
gfx/thebes/gfxAndroidPlatform.h
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxPlatformGtk.h
gfx/thebes/gfxQtPlatform.cpp
gfx/thebes/gfxQtPlatform.h
--- a/gfx/thebes/gfxAndroidPlatform.cpp
+++ b/gfx/thebes/gfxAndroidPlatform.cpp
@@ -86,17 +86,17 @@ gfxAndroidPlatform::~gfxAndroidPlatform(
 }
 
 already_AddRefed<gfxASurface>
 gfxAndroidPlatform::CreateOffscreenSurface(const gfxIntSize& size,
                                       gfxASurface::gfxContentType contentType)
 {
     nsRefPtr<gfxASurface> newSurface;
     if (contentType == gfxImageSurface::CONTENT_COLOR)
-        newSurface = new gfxImageSurface (size, gfxASurface::ImageFormatRGB16_565);
+        newSurface = new gfxImageSurface (size, GetOffscreenFormat());
     else
         newSurface = new gfxImageSurface (size, gfxASurface::FormatFromContent(contentType));
 
     return newSurface.forget();
 }
 
 struct FontListData {
     FontListData(nsIAtom *aLangGroup, const nsACString& aGenericFamily, nsTArray<nsString>& aListOfFonts) :
--- a/gfx/thebes/gfxAndroidPlatform.h
+++ b/gfx/thebes/gfxAndroidPlatform.h
@@ -86,16 +86,18 @@ public:
     FontFamily *FindFontFamily(const nsAString& aName);
     FontEntry *FindFontEntry(const nsAString& aFamilyName, const gfxFontStyle& aFontStyle);
     already_AddRefed<gfxFont> FindFontForChar(PRUint32 aCh, gfxFont *aFont);
     PRBool GetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList);
     void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
 
     FT_Library GetFTLibrary();
 
+    virtual gfxImageFormat GetOffscreenFormat() { return gfxASurface::ImageFormatRGB16_565; }
+
 protected:
     void AppendFacesFromFontFile(const char *aFileName);
 
     typedef nsDataHashtable<nsStringHashKey, nsRefPtr<FontFamily> > FontTable;
 
     FontTable mFonts;
     FontTable mFontAliases;
     FontTable mFontSubstitutes;
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -118,16 +118,18 @@ enum eCMSMode {
     eCMSMode_AllCount     = 3
 };
 
 // when searching through pref langs, max number of pref langs
 const PRUint32 kMaxLenPrefLangList = 32;
 
 #define UNINITIALIZED_VALUE  (-1)
 
+typedef gfxASurface::gfxImageFormat gfxImageFormat;
+
 class THEBES_API gfxPlatform {
 public:
     /**
      * Return a pointer to the current active platform.
      * This is a singleton; it contains mostly convenience
      * functions to obtain platform-specific objects.
      */
     static gfxPlatform *GetPlatform();
@@ -352,16 +354,19 @@ public:
     virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
 
     /**
      * Returns a 1x1 surface that can be used to create graphics contexts
      * for measuring text etc as if they will be rendered to the screen
      */
     gfxASurface* ScreenReferenceSurface() { return mScreenReferenceSurface; }
 
+    virtual gfxImageFormat GetOffscreenFormat()
+    { return gfxASurface::FormatFromContent(gfxASurface::CONTENT_COLOR); }
+
 protected:
     gfxPlatform();
     virtual ~gfxPlatform();
 
     static PRBool GetBoolPref(const char *aPref, PRBool aDefault);
 
     void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, 
                             eFontPrefLang aCharLang, eFontPrefLang aPageLang);
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -168,19 +168,19 @@ gfxPlatformGtk::CreateOffscreenSurface(c
     gfxASurface::gfxImageFormat imageFormat = gfxASurface::FormatFromContent(contentType);
 #ifdef MOZ_X11
     // XXX we really need a different interface here, something that passes
     // in more context, including the display and/or target surface type that
     // we should try to match
     GdkScreen *gdkScreen = gdk_screen_get_default();
     if (gdkScreen) {
         // try to optimize it for 16bpp default screen
-        if (gfxASurface::CONTENT_COLOR == contentType
-            && 16 == gdk_visual_get_system()->depth)
-            imageFormat = gfxASurface::ImageFormatRGB16_565;
+        if (gfxASurface::CONTENT_COLOR == contentType) {
+            imageFormat = GetOffscreenFormat();
+        }
 
         if (UseClientSideRendering()) {
             // We're not going to use XRender, so we don't need to
             // search for a render format
             newSurface = new gfxImageSurface(size, imageFormat);
             // The gfxImageSurface ctor zeroes this for us, no need to
             // waste time clearing again
             needsClear = PR_FALSE;
@@ -502,16 +502,26 @@ gfxPlatformGtk::GetDPI()
         if (sDPI <= 0) {
             // Fall back to something sane
             sDPI = 96;
         }
     }
     return sDPI;
 }
 
+gfxImageFormat
+gfxPlatformGtk::GetOffscreenFormat()
+{
+    if (gdk_visual_get_system()->depth == 16) {
+        return gfxASurface::ImageFormatRGB16_565;
+    }
+
+    return gfxASurface::ImageFormatRGB24;
+}
+
 qcms_profile *
 gfxPlatformGtk::GetPlatformCMSOutputProfile()
 {
 #ifdef MOZ_X11
     const char EDID1_ATOM_NAME[] = "XFree86_DDC_EDID1_RAWDATA";
     const char ICC_PROFILE_ATOM_NAME[] = "_ICC_PROFILE";
 
     Atom edidAtom, iccAtom;
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -133,16 +133,18 @@ public:
         // This setting will likely not be relevant when we have
         // GL-accelerated compositing.
         return PR_TRUE;
 #else
         return PR_FALSE;
 #endif
     }
 
+    virtual gfxImageFormat GetOffscreenFormat();
+
 protected:
     static gfxFontconfigUtils *sFontconfigUtils;
 
 private:
     virtual qcms_profile *GetPlatformCMSOutputProfile();
 };
 
 #endif /* GFX_PLATFORM_GTK_H */
--- a/gfx/thebes/gfxQtPlatform.cpp
+++ b/gfx/thebes/gfxQtPlatform.cpp
@@ -198,19 +198,19 @@ gfxQtPlatform::~gfxQtPlatform()
 already_AddRefed<gfxASurface>
 gfxQtPlatform::CreateOffscreenSurface(const gfxIntSize& size,
                                       gfxASurface::gfxContentType contentType)
 {
     nsRefPtr<gfxASurface> newSurface = nsnull;
 
     // try to optimize it for 16bpp screen
     gfxASurface::gfxImageFormat imageFormat = gfxASurface::FormatFromContent(contentType);
-    if (gfxASurface::CONTENT_COLOR == contentType
-        && 16 == QX11Info().depth())
-        imageFormat = gfxASurface::ImageFormatRGB16_565;
+    if (gfxASurface::CONTENT_COLOR == contentType) {
+      imageFormat = GetOffscreenFormat();
+    }
 
 #ifdef CAIRO_HAS_QT_SURFACE
     if (mRenderMode == RENDER_QPAINTER) {
       newSurface = new gfxQPainterSurface(size, imageFormat);
       return newSurface.forget();
     }
 #endif
 
@@ -585,8 +585,18 @@ gfxQtPlatform::SetPrefFontEntries(const 
 
 PRInt32
 gfxQtPlatform::GetDPI()
 {
     QDesktopWidget* rootWindow = qApp->desktop();
     PRInt32 dpi = rootWindow->logicalDpiY(); // y-axis DPI for fonts
     return dpi <= 0 ? 96 : dpi;
 }
+
+gfxImageFormat
+gfxQtPlatform::GetOffscreenFormat()
+{
+    if (QX11Info::appDepth() == 16) {
+        return gfxASurface::ImageFormatRGB16_565;
+    }
+
+    return gfxASurface::ImageFormatRGB24;
+}
--- a/gfx/thebes/gfxQtPlatform.h
+++ b/gfx/thebes/gfxQtPlatform.h
@@ -130,16 +130,18 @@ public:
     FT_Library GetFTLibrary();
 #endif
 
     RenderMode GetRenderMode() { return mRenderMode; }
     void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; }
 
     static PRInt32 GetDPI();
 
+    virtual gfxImageFormat GetOffscreenFormat();
+
 protected:
     static gfxFontconfigUtils *sFontconfigUtils;
 
 private:
     virtual qcms_profile *GetPlatformCMSOutputProfile();
 
     // TODO: unify this with mPrefFonts (NB: holds families, not fonts) in gfxPlatformFontList
     nsDataHashtable<nsCStringHashKey, nsTArray<nsRefPtr<gfxFontEntry> > > mPrefFonts;