Bug 671639 - Part 2: Double buffer using a single CARenderer. r=matt.woodrow
authorBenoit Girard <b56girard@gmail.com>
Wed, 16 Nov 2011 11:38:50 +1300
changeset 81987 c4dbd7dcc81029631cdcac2a889754c3758ccd25
parent 81986 6451c16af7b0e905881e02d83eeb9609f63a2239
child 81988 913ee424d1d22fd43a3f955d686cf9fceaca8f8c
push idunknown
push userunknown
push dateunknown
reviewersmatt
bugs671639
milestone11.0a1
Bug 671639 - Part 2: Double buffer using a single CARenderer. r=matt.woodrow
dom/plugins/ipc/PluginUtilsOSX.h
dom/plugins/ipc/PluginUtilsOSX.mm
--- a/dom/plugins/ipc/PluginUtilsOSX.h
+++ b/dom/plugins/ipc/PluginUtilsOSX.h
@@ -89,18 +89,17 @@ public:
   bool InitFrontSurface(size_t aWidth, size_t aHeight, AllowOfflineRendererEnum aAllowOfflineRenderer);
   void Render();
   void SwapSurfaces();
   void ClearFrontSurface();
   void ClearBackSurface();
 
 private:
   void *mCALayer;
-  nsRefPtr<nsCARenderer> mFrontRenderer;
-  nsRefPtr<nsCARenderer> mBackRenderer;
+  nsRefPtr<nsCARenderer> mCARenderer;
   nsRefPtr<nsIOSurface> mFrontSurface;
   nsRefPtr<nsIOSurface> mBackSurface;
 };
 
 } // namespace PluginUtilsOSX
 } // namespace plugins
 } // namespace mozilla
 
--- a/dom/plugins/ipc/PluginUtilsOSX.mm
+++ b/dom/plugins/ipc/PluginUtilsOSX.mm
@@ -340,75 +340,74 @@ void nsDoubleBufferCARenderer::SetCALaye
 bool nsDoubleBufferCARenderer::InitFrontSurface(size_t aWidth, size_t aHeight,
                                                 AllowOfflineRendererEnum aAllowOfflineRenderer) {
   if (!mCALayer) {
     return false;
   }
 
   mFrontSurface = nsIOSurface::CreateIOSurface(aWidth, aHeight);
   if (!mFrontSurface) {
-    return false;
-  }
-
-  mFrontRenderer = new nsCARenderer();
-  if (!mFrontRenderer) {
-    mFrontSurface = nsnull;
-    return false;
-  }
-
-  nsRefPtr<nsIOSurface> ioSurface = nsIOSurface::LookupSurface(mFrontSurface->GetIOSurfaceID());
-  if (!ioSurface) {
-    mFrontRenderer = nsnull;
-    mFrontSurface = nsnull;
+    mCARenderer = nsnull;
     return false;
   }
 
-  mFrontRenderer->AttachIOSurface(ioSurface);
+  if (!mCARenderer) {
+    mCARenderer = new nsCARenderer();
+    if (!mCARenderer) {
+      mFrontSurface = nsnull;
+      return false;
+    }
 
-  nsresult result = mFrontRenderer->SetupRenderer(mCALayer,
-                        ioSurface->GetWidth(),
-                        ioSurface->GetHeight(),
+    mCARenderer->AttachIOSurface(mFrontSurface);
+
+    nsresult result = mCARenderer->SetupRenderer(mCALayer,
+                        mFrontSurface->GetWidth(),
+                        mFrontSurface->GetHeight(),
                         aAllowOfflineRenderer);
 
-  return result == NS_OK;
+    if (result != NS_OK) {
+      mCARenderer = nsnull;
+      mFrontSurface = nsnull;
+      return false;
+    }
+  } else {
+    mCARenderer->AttachIOSurface(mFrontSurface);
+  }
+
+  return true;
 }
 
 void nsDoubleBufferCARenderer::Render() {
-  if (!HasFrontSurface()) {
+  if (!HasFrontSurface() || !mCARenderer) {
     return;
   }
 
-  mFrontRenderer->Render(GetFrontSurfaceWidth(), GetFrontSurfaceHeight(), nsnull);
+  mCARenderer->Render(GetFrontSurfaceWidth(), GetFrontSurfaceHeight(), nsnull);
 }
 
 void nsDoubleBufferCARenderer::SwapSurfaces() {
-  if (mFrontRenderer) {
-    mFrontRenderer->DettachCALayer();
-  }
-
-  nsRefPtr<nsCARenderer> prevFrontRenderer = mFrontRenderer;
   nsRefPtr<nsIOSurface> prevFrontSurface = mFrontSurface;
-
-  mFrontRenderer = mBackRenderer;
   mFrontSurface = mBackSurface;
-
-  mBackRenderer = prevFrontRenderer;
   mBackSurface = prevFrontSurface;
 
-  if (mFrontRenderer) {
-    mFrontRenderer->AttachCALayer(mCALayer);
+  if (mFrontSurface) {
+    mCARenderer->AttachIOSurface(mFrontSurface);
   }
 }
 
 void nsDoubleBufferCARenderer::ClearFrontSurface() {
-  mFrontRenderer = nsnull;
   mFrontSurface = nsnull;
+  if (!mFrontSurface && !mBackSurface) {
+    mCARenderer = nsnull;
+  }
 }
 
 void nsDoubleBufferCARenderer::ClearBackSurface() {
-  mBackRenderer = nsnull;
   mBackSurface = nsnull;
+  if (!mFrontSurface && !mBackSurface) {
+    mCARenderer = nsnull;
+  }
 }
 
 } //PluginUtilsOSX
 } //plugins
 } //mozilla