Bug 792207 - Part 5: Add code to Azure to allow initializing recording. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Mon, 24 Sep 2012 15:02:50 +0000
changeset 108023 ee2e60a3093430208d734ad3851c1236be5532e0
parent 108022 ed2e2da7d09890078d98b08d64b57c21de4b56a6
child 108024 5ad72b579f8784d7329ff0a5b9756a06f5d69002
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjrmuizel
bugs792207
milestone18.0a1
Bug 792207 - Part 5: Add code to Azure to allow initializing recording. r=jrmuizel
gfx/2d/2D.h
gfx/2d/Factory.cpp
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -31,16 +31,17 @@ struct ID3D10Texture2D;
 struct IDWriteRenderingParams;
 
 namespace mozilla {
 namespace gfx {
 
 class SourceSurface;
 class DataSourceSurface;
 class DrawTarget;
+class DrawEventRecorder;
 
 struct NativeSurface {
   NativeSurfaceType mType;
   SurfaceFormat mFormat;
   void *mSurface;
 };
 
 struct NativeFont {
@@ -843,17 +844,20 @@ class GFX2D_API Factory
 {
 public:
   static bool HasSSE2();
 
   static TemporaryRef<DrawTarget> CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface, const IntSize& aSize);
 
   static TemporaryRef<DrawTarget>
     CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFormat aFormat);
-  
+
+  static TemporaryRef<DrawTarget>
+    CreateRecordingDrawTarget(DrawEventRecorder *aRecorder, DrawTarget *aDT);
+     
   static TemporaryRef<DrawTarget>
     CreateDrawTargetForData(BackendType aBackend, unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
 
   static TemporaryRef<ScaledFont>
     CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize);
 
   /**
    * This creates a ScaledFont from TrueType data.
@@ -888,16 +892,21 @@ public:
    * wrap this data and the data for this source surface. The caller is
    * responsible for deallocating the memory only after destruction of the
    * surface.
    */
   static TemporaryRef<DataSourceSurface>
     CreateWrappingDataSourceSurface(uint8_t *aData, int32_t aStride,
                                     const IntSize &aSize, SurfaceFormat aFormat);
 
+  static TemporaryRef<DrawEventRecorder>
+    CreateEventRecorderForFile(const char *aFilename);
+
+  static void SetGlobalEventRecorder(DrawEventRecorder *aRecorder);
+
 #ifdef WIN32
   static TemporaryRef<DrawTarget> CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat);
   static TemporaryRef<DrawTarget>
     CreateDualDrawTargetForD3D10Textures(ID3D10Texture2D *aTextureA,
                                          ID3D10Texture2D *aTextureB,
                                          SurfaceFormat aFormat);
 
   static void SetDirect3D10Device(ID3D10Device1 *aDevice);
@@ -907,14 +916,16 @@ public:
     CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams);
 
   static uint64_t GetD2DVRAMUsageDrawTarget();
   static uint64_t GetD2DVRAMUsageSourceSurface();
 
 private:
   static ID3D10Device1 *mD3D10Device;
 #endif
+
+  static DrawEventRecorder *mRecorder;
 };
 
 }
 }
 
 #endif // _MOZILLA_GFX_2D_H
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -33,19 +33,22 @@
 
 #ifdef WIN32
 #include "DrawTargetD2D.h"
 #include "ScaledFontDWrite.h"
 #include <d3d10_1.h>
 #endif
 
 #include "DrawTargetDual.h"
+#include "DrawTargetRecording.h"
 
 #include "SourceSurfaceRawData.h"
 
+#include "DrawEventRecorder.h"
+
 #include "Logging.h"
 
 #ifdef PR_LOGGING
 PRLogModuleInfo *sGFX2DLog = PR_NewLogModule("gfx2d");
 #endif
 
 // The following code was largely taken from xpcom/glue/SSE.cpp and
 // made a little simpler.
@@ -137,16 +140,18 @@ namespace gfx {
 
 // XXX - Need to define an API to set this.
 int sGfxLogLevel = LOG_DEBUG;
 
 #ifdef WIN32
 ID3D10Device1 *Factory::mD3D10Device;
 #endif
 
+DrawEventRecorder *Factory::mRecorder;
+
 bool
 Factory::HasSSE2()
 {
 #if defined(__SSE2__) || defined(_M_X64) || \
     (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
   // gcc with -msse2 (default on OSX and x86-64)
   // cl.exe with -arch:SSE2 (default on x64 compiler)
   return true;
@@ -155,106 +160,129 @@ Factory::HasSSE2()
 #else
   return false;
 #endif
 }
 
 TemporaryRef<DrawTarget>
 Factory::CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFormat aFormat)
 {
+  RefPtr<DrawTarget> retVal;
   switch (aBackend) {
 #ifdef WIN32
   case BACKEND_DIRECT2D:
     {
       RefPtr<DrawTargetD2D> newTarget;
       newTarget = new DrawTargetD2D();
       if (newTarget->Init(aSize, aFormat)) {
-        return newTarget;
+        retVal = newTarget;
       }
       break;
     }
 #elif defined XP_MACOSX
   case BACKEND_COREGRAPHICS:
   case BACKEND_COREGRAPHICS_ACCELERATED:
     {
       RefPtr<DrawTargetCG> newTarget;
       newTarget = new DrawTargetCG();
       if (newTarget->Init(aBackend, aSize, aFormat)) {
-        return newTarget;
+        retVal = newTarget;
       }
       break;
     }
 #endif
 #ifdef USE_SKIA
   case BACKEND_SKIA:
     {
       RefPtr<DrawTargetSkia> newTarget;
       newTarget = new DrawTargetSkia();
       if (newTarget->Init(aSize, aFormat)) {
-        return newTarget;
+        retVal = newTarget;
       }
       break;
     }
 #endif
   default:
     gfxDebug() << "Invalid draw target type specified.";
     return nullptr;
   }
 
-  gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize;
-  // Failed
-  return nullptr;
+  if (mRecorder && retVal) {
+    RefPtr<DrawTarget> recordDT;
+    recordDT = new DrawTargetRecording(mRecorder, retVal);
+    return recordDT;
+  }
+
+  if (!retVal) {
+    // Failed
+    gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize;
+  }
+  
+  return retVal;
+}
+
+TemporaryRef<DrawTarget>
+Factory::CreateRecordingDrawTarget(DrawEventRecorder *aRecorder, DrawTarget *aDT)
+{
+  return new DrawTargetRecording(aRecorder, aDT);
 }
 
 TemporaryRef<DrawTarget>
 Factory::CreateDrawTargetForData(BackendType aBackend, 
                                  unsigned char *aData, 
                                  const IntSize &aSize, 
                                  int32_t aStride, 
                                  SurfaceFormat aFormat)
 {
+  RefPtr<DrawTarget> retVal;
+
   switch (aBackend) {
 #ifdef USE_SKIA
   case BACKEND_SKIA:
     {
       RefPtr<DrawTargetSkia> newTarget;
       newTarget = new DrawTargetSkia();
       newTarget->Init(aData, aSize, aStride, aFormat);
-      return newTarget;
+      retVal = newTarget;
     }
 #endif
 #ifdef XP_MACOSX
   case BACKEND_COREGRAPHICS:
     {
       RefPtr<DrawTargetCG> newTarget = new DrawTargetCG();
       if (newTarget->Init(aBackend, aData, aSize, aStride, aFormat))
         return newTarget;
       break;
     }
 #endif
   default:
     gfxDebug() << "Invalid draw target type specified.";
     return nullptr;
   }
 
+  if (mRecorder && retVal) {
+    RefPtr<DrawTarget> recordDT = new DrawTargetRecording(mRecorder, retVal);
+    return recordDT;
+  }
+
   gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize;
   // Failed
   return nullptr;
 }
 
 TemporaryRef<ScaledFont>
 Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize)
 {
   switch (aNativeFont.mType) {
 #ifdef WIN32
   case NATIVE_FONT_DWRITE_FONT_FACE:
     {
       return new ScaledFontDWrite(static_cast<IDWriteFontFace*>(aNativeFont.mFont), aSize);
     }
-#if defined(USE_SKIA)
+#if defined(USE_CAIRO) || defined(USE_SKIA)
   case NATIVE_FONT_GDI_FONT_FACE:
     {
       return new ScaledFontWin(static_cast<LOGFONT*>(aNativeFont.mFont), aSize);
     }
 #endif
 #endif
 #ifdef XP_MACOSX
   case NATIVE_FONT_MAC_FONT_FACE:
@@ -321,17 +349,23 @@ Factory::CreateScaledFontWithCairo(const
 #ifdef WIN32
 TemporaryRef<DrawTarget>
 Factory::CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat)
 {
   RefPtr<DrawTargetD2D> newTarget;
 
   newTarget = new DrawTargetD2D();
   if (newTarget->Init(aTexture, aFormat)) {
-    return newTarget;
+    RefPtr<DrawTarget> retVal = newTarget;
+
+    if (mRecorder) {
+      retVal = new DrawTargetRecording(mRecorder, retVal);
+    }
+
+    return retVal;
   }
 
   gfxWarning() << "Failed to create draw target for D3D10 texture.";
 
   // Failed
   return nullptr;
 }
 
@@ -353,17 +387,23 @@ Factory::CreateDualDrawTargetForD3D10Tex
   if (!newTargetB->Init(aTextureB, aFormat)) {
     gfxWarning() << "Failed to create draw target for D3D10 texture.";
     return nullptr;
   }
 
   RefPtr<DrawTarget> newTarget =
     new DrawTargetDual(newTargetA, newTargetB);
 
-  return newTarget;
+  RefPtr<DrawTarget> retVal = newTarget;
+
+  if (mRecorder) {
+    retVal = new DrawTargetRecording(mRecorder, retVal);
+  }
+
+  return retVal;
 }
 
 void
 Factory::SetDirect3D10Device(ID3D10Device1 *aDevice)
 {
   mD3D10Device = aDevice;
 }
 
@@ -394,34 +434,53 @@ Factory::GetD2DVRAMUsageSourceSurface()
   return DrawTargetD2D::mVRAMUsageSS;
 }
 
 #endif // XP_WIN
 
 TemporaryRef<DrawTarget>
 Factory::CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface, const IntSize& aSize)
 {
+  RefPtr<DrawTarget> retVal;
+
 #ifdef USE_CAIRO
   RefPtr<DrawTargetCairo> newTarget = new DrawTargetCairo();
+
   if (newTarget->Init(aSurface, aSize)) {
-    return newTarget;
+    retVal = newTarget;
   }
 
+  if (mRecorder && retVal) {
+    RefPtr<DrawTarget> recordDT = new DrawTargetRecording(mRecorder, retVal);
+    return recordDT;
+  }
 #endif
-  return nullptr;
+  return retVal;
 }
 
 TemporaryRef<DataSourceSurface>
 Factory::CreateWrappingDataSourceSurface(uint8_t *aData, int32_t aStride,
                                          const IntSize &aSize,
                                          SurfaceFormat aFormat)
 {
   RefPtr<SourceSurfaceRawData> newSurf = new SourceSurfaceRawData();
 
   if (newSurf->InitWrappingData(aData, aSize, aStride, aFormat, false)) {
     return newSurf;
   }
 
   return nullptr;
 }
 
+TemporaryRef<DrawEventRecorder>
+Factory::CreateEventRecorderForFile(const char *aFilename)
+{
+  return new DrawEventRecorderFile(aFilename);
+}
+
+void
+Factory::SetGlobalEventRecorder(DrawEventRecorder *aRecorder)
+{
+  mRecorder = aRecorder;
+}
+
 }
 }