Bug 648484, part D: Allow PuppetWidgets to create D3D10 layer managers (for the time being). r=roc
authorChris Jones <jones.chris.g@gmail.com>
Tue, 09 Aug 2011 12:38:27 -0700
changeset 74143 787338296ce8fefc9d581f0d0b4765a7d4be98fa
parent 74142 92d5c3fa405b4da8501f6d1bc149ffbd4cd794bf
child 74144 dcd3d5a27f8a32ffbd7103776acb2659f10835c0
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersroc
bugs648484
milestone8.0a1
Bug 648484, part D: Allow PuppetWidgets to create D3D10 layer managers (for the time being). r=roc
layout/ipc/RenderFrameParent.cpp
widget/src/xpwidgets/Makefile.in
widget/src/xpwidgets/PuppetWidget.cpp
--- a/layout/ipc/RenderFrameParent.cpp
+++ b/layout/ipc/RenderFrameParent.cpp
@@ -723,39 +723,24 @@ RenderFrameParent::ActorDestroy(ActorDes
 
 PLayersParent*
 RenderFrameParent::AllocPLayers(LayerManager::LayersBackend* aBackendType)
 {
   if (!mFrameLoader) {
     *aBackendType = LayerManager::LAYERS_NONE;
     return nsnull;
   }
-
   LayerManager* lm = GetLayerManager();
-  switch (*aBackendType = lm->GetBackendType()) {
-  case LayerManager::LAYERS_BASIC: {
-    BasicShadowLayerManager* bslm = static_cast<BasicShadowLayerManager*>(lm);
-    return new ShadowLayersParent(bslm);
-  }
-  case LayerManager::LAYERS_OPENGL: {
-    LayerManagerOGL* lmo = static_cast<LayerManagerOGL*>(lm);
-    return new ShadowLayersParent(lmo);
+  ShadowLayerManager* slm = lm->AsShadowManager();
+  if (!slm) {
+     NS_WARNING("shadow layers no sprechen D3D backend yet");
+     return nsnull;
   }
-#ifdef MOZ_ENABLE_D3D9_LAYER
-  case LayerManager::LAYERS_D3D9: {
-    LayerManagerD3D9* lmd3d9 = static_cast<LayerManagerD3D9*>(lm);
-    return new ShadowLayersParent(lmd3d9);
-  }
-#endif //MOZ_ENABLE_D3D9_LAYER
-  default: {
-    NS_WARNING("shadow layers no sprechen D3D backend yet");
-    *aBackendType = LayerManager::LAYERS_NONE;
-    return nsnull;
-  }
-  }
+  *aBackendType = lm->GetBackendType();
+  return new ShadowLayersParent(slm);
 }
 
 bool
 RenderFrameParent::DeallocPLayers(PLayersParent* aLayers)
 {
   delete aLayers;
   return true;
 }
--- a/widget/src/xpwidgets/Makefile.in
+++ b/widget/src/xpwidgets/Makefile.in
@@ -92,16 +92,20 @@ ifneq (,$(filter qt gtk2 windows cocoa,$
 CPPSRCS += nsNativeTheme.cpp
 endif
 
 SHARED_LIBRARY_LIBS = ../shared/$(LIB_PREFIX)widget_shared.$(LIB_SUFFIX)
 ifdef MOZ_X11
 SHARED_LIBRARY_LIBS += ../shared/x11/$(LIB_PREFIX)widget_shared_x11.$(LIB_SUFFIX)
 endif
 
+ifdef MOZ_ENABLE_D3D10_LAYER
+DEFINES		+= -DMOZ_ENABLE_D3D10_LAYER
+endif
+
 LOCAL_INCLUDES	+= \
 		-I$(srcdir)/../$(MOZ_WIDGET_TOOLKIT) \
 		-I$(srcdir)/../shared \
 		-I$(topsrcdir)/layout/forms \
 		-I$(topsrcdir)/layout/generic \
 		-I$(topsrcdir)/layout/xul/base/src \
 		-I$(srcdir) \
 		$(NULL)
--- a/widget/src/xpwidgets/PuppetWidget.cpp
+++ b/widget/src/xpwidgets/PuppetWidget.cpp
@@ -35,16 +35,19 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/dom/PBrowserChild.h"
 #include "BasicLayers.h"
+#if defined(MOZ_ENABLE_D3D10_LAYER)
+# include "LayerManagerD3D10.h"
+#endif
 
 #include "gfxPlatform.h"
 #include "PuppetWidget.h"
 
 using namespace mozilla::layers;
 using namespace mozilla::widget;
 using namespace mozilla::dom;
 
@@ -331,18 +334,31 @@ PuppetWidget::DispatchEvent(nsGUIEvent* 
 
 LayerManager*
 PuppetWidget::GetLayerManager(PLayersChild* aShadowManager,
                               LayersBackend aBackendHint,
                               LayerManagerPersistence aPersistence,
                               bool* aAllowRetaining)
 {
   if (!mLayerManager) {
-    mLayerManager = new BasicShadowLayerManager(this);
-    mLayerManager->AsShadowForwarder()->SetShadowManager(aShadowManager);
+    // The backend hint is a temporary placeholder until Azure, when
+    // all content-process layer managers will be BasicLayerManagers.
+#if defined(MOZ_ENABLE_D3D10_LAYER)
+    if (LayerManager::LAYERS_D3D10 == aBackendHint) {
+      nsRefPtr<LayerManagerD3D10> m = new LayerManagerD3D10(this);
+      m->AsShadowForwarder()->SetShadowManager(aShadowManager);
+      if (m->Initialize()) {
+        mLayerManager = m;
+      }
+    }
+#endif
+    if (!mLayerManager) {
+      mLayerManager = new BasicShadowLayerManager(this);
+      mLayerManager->AsShadowForwarder()->SetShadowManager(aShadowManager);
+    }
   }
   if (aAllowRetaining) {
     *aAllowRetaining = true;
   }
   return mLayerManager;
 }
 
 gfxASurface*
@@ -537,20 +553,25 @@ PuppetWidget::DispatchPaintEvent()
 
   nsEventStatus status;
   {
 #ifdef DEBUG
     debug_DumpPaintEvent(stderr, this, &event,
                          nsCAutoString("PuppetWidget"), nsnull);
 #endif
 
-    nsRefPtr<gfxContext> ctx = new gfxContext(mSurface);
-    AutoLayerManagerSetup setupLayerManager(this, ctx,
-                                            BasicLayerManager::BUFFER_NONE);
-    DispatchEvent(&event, status);  
+    LayerManager* lm = GetLayerManager();
+    if (LayerManager::LAYERS_D3D10 == mLayerManager->GetBackendType()) {
+      DispatchEvent(&event, status);
+    } else {
+      nsRefPtr<gfxContext> ctx = new gfxContext(mSurface);
+      AutoLayerManagerSetup setupLayerManager(this, ctx,
+                                              BasicLayerManager::BUFFER_NONE);
+      DispatchEvent(&event, status);  
+    }
   }
 
   nsPaintEvent didPaintEvent(PR_TRUE, NS_DID_PAINT, this);
   DispatchEvent(&didPaintEvent, status);
 
   return NS_OK;
 }