Bug 740580 - Add Azure support to nsCanvasFrame. r=roc
authorAnthony Jones <ajones@mozilla.com>
Tue, 02 Oct 2012 22:09:12 -0400
changeset 109098 0ae09da96f63b1d283822be4de3f5a90e60e9ae7
parent 109097 5ff5e81e6de6b5640188f03294be1ec643c3dd11
child 109099 fe034183d766cabe18311f5dc1f8a290f67c823a
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersroc
bugs740580
milestone18.0a1
Bug 740580 - Add Azure support to nsCanvasFrame. r=roc
layout/generic/nsCanvasFrame.cpp
--- a/layout/generic/nsCanvasFrame.cpp
+++ b/layout/generic/nsCanvasFrame.cpp
@@ -17,16 +17,17 @@
 #include "nsStyleConsts.h"
 #include "nsGkAtoms.h"
 #include "nsEventStateManager.h"
 #include "nsIPresShell.h"
 #include "nsIScrollPositionListener.h"
 #include "nsDisplayList.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsFrameManager.h"
+#include "gfxPlatform.h"
 
 // for focus
 #include "nsIScrollableFrame.h"
 #include "nsIDocShell.h"
 
 #ifdef DEBUG_rods
 //#define DEBUG_CANVAS_FOCUS
 #endif
@@ -205,22 +206,42 @@ nsDisplayCanvasBackground::Paint(nsDispl
   nsRect bounds = GetBounds(aBuilder, &snap);
   nsRenderingContext context;
   nsRefPtr<gfxContext> dest = aCtx->ThebesContext();
   nsRefPtr<gfxASurface> surf;
   nsRefPtr<gfxContext> ctx;
 #ifndef MOZ_GFX_OPTIMIZE_MOBILE
   if (IsSingleFixedPositionImage(aBuilder, bgClipRect) && aBuilder->IsPaintingToWindow() && !aBuilder->IsCompositingCheap()) {
     surf = static_cast<gfxASurface*>(GetUnderlyingFrame()->Properties().Get(nsIFrame::CachedBackgroundImage()));
-    nsRefPtr<gfxASurface> destSurf = dest->CurrentSurface();
-    if (surf && surf->GetType() == destSurf->GetType()) {
-      BlitSurface(dest, mDestRect, surf);
-      return;
+    if (dest->IsCairo()) {
+      nsRefPtr<gfxASurface> destSurf = dest->CurrentSurface();
+      if (surf && surf->GetType() == destSurf->GetType()) {
+        BlitSurface(dest, mDestRect, surf);
+        return;
+      }
+      surf = destSurf->CreateSimilarSurface(
+          gfxASurface::CONTENT_COLOR_ALPHA,
+          gfxIntSize(ceil(mDestRect.width), ceil(mDestRect.height)));
+    } else {
+      if (surf) {
+        mozilla::gfx::DrawTarget* dt = dest->GetDrawTarget();
+        mozilla::RefPtr<mozilla::gfx::SourceSurface> source =
+            gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, surf);
+        if (source) {
+          // Could be non-integer pixel alignment
+          dt->DrawSurface(source,
+                          mozilla::gfx::Rect(mDestRect.x, mDestRect.y, mDestRect.width, mDestRect.height),
+                          mozilla::gfx::Rect(0, 0, mDestRect.width, mDestRect.height));
+          return;
+        }
+      }
+      surf = gfxPlatform::GetPlatform()->CreateOffscreenImageSurface(
+          gfxIntSize(ceil(mDestRect.width), ceil(mDestRect.height)),
+          gfxASurface::CONTENT_COLOR_ALPHA);
     }
-    surf = destSurf->CreateSimilarSurface(gfxASurface::CONTENT_COLOR_ALPHA, gfxIntSize(ceil(mDestRect.width), ceil(mDestRect.height)));
     if (surf) {
       ctx = new gfxContext(surf);
       ctx->Translate(-gfxPoint(mDestRect.x, mDestRect.y));
       context.Init(aCtx->DeviceContext(), ctx);
     }
   }
 #endif