Bug 593268 - Part 2: Make Canvas use LayerManager::CreateOptimalSurface. r=vlad
authorBas Schouten <bschouten@mozilla.com>
Wed, 08 Sep 2010 05:27:31 +0200
changeset 52173 a2f13b7d1a62007260a9cfd47c2e739e197a082f
parent 52172 87d1bedd44d9876492744c82929923dc26821c73
child 52174 7ad078323b5259c54cb6009a8b85d328acd8ffd6
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad
bugs593268
milestone2.0b6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 593268 - Part 2: Make Canvas use LayerManager::CreateOptimalSurface. r=vlad
content/canvas/src/nsCanvasRenderingContext2D.cpp
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -1090,18 +1090,32 @@ nsCanvasRenderingContext2D::SetDimension
     gfxIntSize size(width, height);
     if (gfxASurface::CheckSurfaceSize(size, 0xffff)) {
 
         gfxASurface::gfxImageFormat format = GetImageFormat();
 
         if (PR_GetEnv("MOZ_CANVAS_IMAGE_SURFACE")) {
             surface = new gfxImageSurface(gfxIntSize(width, height), format);
         } else {
-            surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface
-                (gfxIntSize(width, height), format);
+            nsCOMPtr<nsIContent> content =
+                do_QueryInterface(static_cast<nsIDOMHTMLCanvasElement*>(mCanvasElement));
+            nsIDocument* ownerDoc = nsnull;
+            if (content)
+                ownerDoc = content->GetOwnerDoc();
+            nsRefPtr<LayerManager> layerManager = nsnull;
+
+            if (ownerDoc)
+              layerManager = nsContentUtils::LayerManagerForDocument(ownerDoc);
+
+            if (layerManager) {
+              surface = layerManager->CreateOptimalSurface(gfxIntSize(width, height), format);
+            } else {
+              surface = gfxPlatform::GetPlatform()->
+                CreateOffscreenSurface(gfxIntSize(width, height), format);
+            }
         }
 
         if (surface && surface->CairoStatus() != 0)
             surface = NULL;
 
 #ifdef MOZ_IPC
         if (mIPC && surface) {
 #ifdef MOZ_X11