Bug 517834 - Use gfxQuartzImageSurface to paint video frames for an 8-23% perf win on Mac. r=roc
authorMatthew Gregan <kinetik@flim.org>
Tue, 22 Sep 2009 12:12:06 +1200
changeset 32937 13473c4b2589f9d7ee7a8d6399cb86c04791beac
parent 32936 144468b735c1c92c190e85e955e57d28267d49f0
child 32938 4ddf3215311241a32d65e60fd3455e7c64d4a4a2
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs517834
milestone1.9.3a1pre
Bug 517834 - Use gfxQuartzImageSurface to paint video frames for an 8-23% perf win on Mac. r=roc
content/media/nsMediaDecoder.cpp
--- a/content/media/nsMediaDecoder.cpp
+++ b/content/media/nsMediaDecoder.cpp
@@ -48,16 +48,20 @@
 #include "nsAutoLock.h"
 #include "nsIRenderingContext.h"
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
 #include "nsPresContext.h"
 #include "nsMediaDecoder.h"
 #include "nsDOMError.h"
 
+#if defined(XP_MACOSX)
+#include "gfxQuartzImageSurface.h"
+#endif
+
 // Number of milliseconds between progress events as defined by spec
 #define PROGRESS_MS 350
 
 // Number of milliseconds of no data before a stall event is fired as defined by spec
 #define STALL_MS 3000
 
 #ifdef PR_LOGGING
 // Logging object for decoder
@@ -241,26 +245,35 @@ void nsMediaDecoder::Paint(gfxContext* a
                            gfxPattern::GraphicsFilter aFilter,
                            const gfxRect& aRect)
 {
   nsAutoLock lock(mVideoUpdateLock);
 
   if (!mRGB)
     return;
 
-  /* Create a surface backed by the RGB */
-  nsRefPtr<gfxASurface> surface = 
-    new gfxImageSurface(mRGB,
-                        gfxIntSize(mRGBWidth, mRGBHeight), 
-                        mRGBWidth * 4,
-                        gfxASurface::ImageFormatRGB24);    
+  nsRefPtr<gfxImageSurface> imgSurface =
+      new gfxImageSurface(mRGB,
+                          gfxIntSize(mRGBWidth, mRGBHeight),
+                          mRGBWidth * 4,
+                          gfxASurface::ImageFormatRGB24);
+  if (!imgSurface)
+    return;
 
-  if (!surface)
+  nsRefPtr<gfxASurface> surface(imgSurface);
+
+#if defined(XP_MACOSX)
+  nsRefPtr<gfxQuartzImageSurface> quartzSurface =
+    new gfxQuartzImageSurface(imgSurface);
+  if (!quartzSurface)
     return;
 
+  surface = quartzSurface;
+#endif
+
   nsRefPtr<gfxPattern> pat = new gfxPattern(surface);
   if (!pat)
     return;
 
   // Make the source image fill the rectangle completely
   pat->SetMatrix(gfxMatrix().Scale(mRGBWidth/aRect.Width(), mRGBHeight/aRect.Height()));
 
   pat->SetFilter(aFilter);
@@ -280,25 +293,10 @@ void nsMediaDecoder::Paint(gfxContext* a
   }
 
   pat->SetExtend(extend);
 
   /* Draw RGB surface onto frame */
   aContext->NewPath();
   aContext->PixelSnappedRectangleAndSetPattern(aRect, pat);
   aContext->Fill();
-
-#ifdef DEBUG_FRAME_RATE
-  {
-    // Output frame rate
-    static float last = double(PR_IntervalToMilliseconds(PR_IntervalNow()))/1000.0;
-    float now = double(PR_IntervalToMilliseconds(PR_IntervalNow()))/1000.0;
-    static int count = 0;
-    count++;
-    if (now-last > 10.0) {
-      LOG(PR_LOG_DEBUG, ("Paint Frame Rate = %f (should be %f)\n", (float)count / (float)(now-last), mFramerate));
-      count = 0;
-      last = double(PR_IntervalToMilliseconds(PR_IntervalNow()))/1000.0;
-    }
-  }   
-#endif
 }