Part A: Setup PCompositor (in progress)
authorBenoit Girard <b56girard@gmail.com>
Mon, 12 Dec 2011 10:15:57 -0500
changeset 92323 f129b37aa3a075b9531fcba48e452b2de36906df
parent 92322 5e9f5795f9dcd30c7f52388f28446ed005994ec5
child 92324 a945782a1b3914bfe13949464708f4bf45c73eee
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone11.0a1
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
Part A: Setup PCompositor (in progress)
gfx/layers/Makefile.in
gfx/layers/ipc/CompositorChild.cpp
gfx/layers/ipc/CompositorChild.h
gfx/layers/ipc/CompositorParent.cpp
gfx/layers/ipc/CompositorParent.h
gfx/layers/ipc/PCompositor.ipdl
gfx/layers/ipc/PLayers.ipdl
gfx/layers/ipc/ShadowLayersParent.cpp
gfx/layers/ipc/ipdl.mk
widget/src/xpwidgets/nsBaseWidget.cpp
--- a/gfx/layers/Makefile.in
+++ b/gfx/layers/Makefile.in
@@ -125,23 +125,27 @@ CPPSRCS += \
 	ShadowLayerUtilsD3D10.cpp \
         ThebesLayerD3D10.cpp \
         $(NULL)
 endif
 endif
 
 EXPORTS_NAMESPACES = IPC mozilla/layers
 EXPORTS_IPC = ShadowLayerUtils.h
-EXPORTS_mozilla/layers =\
+EXPORTS_mozilla/layers = \
+        CompositorChild.h \
+        CompositorParent.h \
         ShadowLayers.h \
         ShadowLayersChild.h \
         ShadowLayersParent.h \
         $(NULL)
 
 CPPSRCS += \
+        CompositorChild.cpp \
+        CompositorParent.cpp \
         ShadowLayers.cpp \
         ShadowLayerChild.cpp \
         ShadowLayersChild.cpp \
         ShadowLayerParent.cpp \
         ShadowLayersParent.cpp \
         $(NULL)
 
 ifdef MOZ_X11 #{
new file mode 100644
--- /dev/null
+++ b/gfx/layers/ipc/CompositorChild.cpp
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim: set sw=4 ts=8 et tw=80 : */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Content App.
+ *
+ * The Initial Developer of the Original Code is
+ *   The Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Benoit Girard <bgirard@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * 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 "CompositorChild.h"
+#include "mozilla/layers/ShadowLayersChild.h"
+
+using mozilla::layers::ShadowLayersChild;
+
+namespace mozilla {
+namespace layers {
+
+CompositorChild::CompositorChild()
+{
+    
+    MOZ_COUNT_CTOR(CompositorChild);
+	printf("Alloc CompositorChild\n");
+}
+
+CompositorChild::~CompositorChild()
+{
+    MOZ_COUNT_DTOR(CompositorChild);
+}
+
+PLayersChild*
+CompositorChild::AllocPLayers(const LayersBackend &backend)
+{
+    return new ShadowLayersChild();
+}
+
+bool
+CompositorChild::DeallocPLayers(PLayersChild* actor)
+{
+	delete actor;
+    return true;
+}
+
+} // namespace layers
+} // namespace mozilla
+
new file mode 100644
--- /dev/null
+++ b/gfx/layers/ipc/CompositorChild.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim: set sw=4 ts=8 et tw=80 : */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Content App.
+ *
+ * The Initial Developer of the Original Code is
+ *   The Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Benoit Girard <bgirard@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * 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 ***** */
+
+#ifndef mozilla_layers_CompositorChild_h
+#define mozilla_layers_CompositorChild_h
+
+#include "mozilla/layers/PCompositorChild.h"
+
+namespace mozilla {
+namespace layers {
+
+class CompositorChild : public PCompositorChild
+{
+
+public:
+  CompositorChild();
+  virtual ~CompositorChild();
+
+protected:
+  virtual PLayersChild* AllocPLayers(const LayersBackend &backend);
+  virtual bool DeallocPLayers(PLayersChild *aChild);
+};
+
+} // lauers
+} // mozilla
+
+#endif // mozilla_layers_CompositorChild_h
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/gfx/layers/ipc/CompositorParent.h
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim: set sw=4 ts=8 et tw=80 : */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Content App.
+ *
+ * The Initial Developer of the Original Code is
+ *   The Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Benoit Girard <bgirard@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * 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 ***** */
+
+#ifndef mozilla_layers_CompositorParent_h
+#define mozilla_layers_CompositorParent_h
+
+#include "mozilla/layers/PCompositorParent.h"
+#include "mozilla/layers/PLayersParent.h"
+
+namespace mozilla {
+namespace layers {
+
+class CompositorParent : public PCompositorParent
+{
+
+public:
+  CompositorParent() {}
+  virtual ~CompositorParent() {}
+
+  bool AnswerInit() {
+    printf("Answer init\n");
+    return true;
+  }
+
+protected:
+  virtual PLayersParent* AllocPLayers(const LayersBackend &backend) {
+    printf("Alloc PLayers :)\n");
+    //ShadowLayerManager* slm = aLayerManager->AsShadowManager();
+    //if (!slm) {
+       return nsnull;
+    //}
+
+    //return new ShadowLayersParent(slm);
+  }
+
+  virtual bool DeallocPLayers(PLayersParent* aLayers) {
+    delete aLayers;
+    return true;
+   }
+};
+
+} // layers
+} // mozilla
+
+#endif // mozilla_layers_CompositorParent_h
new file mode 100644
--- /dev/null
+++ b/gfx/layers/ipc/PCompositor.ipdl
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=8 et :
+ */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at:
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Code.
+ *
+ * The Initial Developer of the Original Code is
+ *   The Mozilla Foundation
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Benoit Girard <bgirard@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * 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 protocol PLayers;
+
+using mozilla::LayersBackend;
+
+namespace mozilla {
+namespace layers {
+
+/**
+ * The PCompositor protocol is used to manage communication between
+ * the main thread and the compositor thread context. It's primary
+ * purpose is to manage the PLayers sub protocol.
+ */
+rpc protocol PCompositor
+{
+  // Compositor can manage many Layer Manager (PLayers)
+  manages PLayers;
+
+parent:  
+
+  rpc Init();
+  async PLayers(LayersBackend backend);
+
+//parent:
+//  rpc PLayers();
+
+};
+
+} // layers
+} // mozilla
--- a/gfx/layers/ipc/PLayers.ipdl
+++ b/gfx/layers/ipc/PLayers.ipdl
@@ -33,17 +33,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * 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 protocol PCompositor;
+include protocol PCompositor;
 include protocol PLayer;
 include protocol PRenderFrame;
 
 include "IPC/ShadowLayerUtils.h";
 
 using gfx3DMatrix;
 using gfxRGBA;
 using nsIntPoint;
@@ -221,17 +221,17 @@ struct OpThebesBufferSwap {
 union EditReply {
   OpBufferSwap;
   OpThebesBufferSwap;
   OpImageSwap;
 };
 
 
 sync protocol PLayers {
-  manager PRenderFrame /*or PCompositor or PMedia or PPlugin*/;
+  manager PRenderFrame or PCompositor;
   manages PLayer;
 
 parent:
   async PLayer();
 
   sync Update(Edit[] cset)
     returns (EditReply[] reply);
 
--- a/gfx/layers/ipc/ShadowLayersParent.cpp
+++ b/gfx/layers/ipc/ShadowLayersParent.cpp
@@ -398,17 +398,19 @@ ShadowLayersParent::DeallocPLayer(PLayer
 {
   delete actor;
   return true;
 }
 
 RenderFrameParent*
 ShadowLayersParent::Frame()
 {
-  return static_cast<RenderFrameParent*>(Manager());
+  // Fix me, gives: error: ‘Manager’ was not declared in this scope
+  //return static_cast<RenderFrameParent*>(Manager());
+  return NULL;
 }
 
 void
 ShadowLayersParent::DestroySharedSurface(gfxSharedImageSurface* aSurface)
 {
   layer_manager()->DestroySharedSurface(aSurface, this);
 }
 
--- a/gfx/layers/ipc/ipdl.mk
+++ b/gfx/layers/ipc/ipdl.mk
@@ -1,4 +1,5 @@
 IPDLSRCS = \
+  PCompositor.ipdl \
   PLayer.ipdl \
   PLayers.ipdl \
   $(NULL)
--- a/widget/src/xpwidgets/nsBaseWidget.cpp
+++ b/widget/src/xpwidgets/nsBaseWidget.cpp
@@ -50,31 +50,36 @@
 #include "nsIContent.h"
 #include "nsIServiceManager.h"
 #include "mozilla/Preferences.h"
 #include "BasicLayers.h"
 #include "LayerManagerOGL.h"
 #include "nsIXULRuntime.h"
 #include "nsIGfxInfo.h"
 #include "npapi.h"
+#include "base/thread.h"
+#include "mozilla/layers/CompositorChild.h"
+#include "mozilla/layers/CompositorParent.h"
+
 
 #ifdef DEBUG
 #include "nsIObserver.h"
 
 static void debug_RegisterPrefCallbacks();
 
 static bool debug_InSecureKeyboardInputMode = false;
 #endif
 
 #ifdef NOISY_WIDGET_LEAKS
 static PRInt32 gNumWidgets;
 #endif
 
 using namespace mozilla::layers;
 using namespace mozilla;
+using namespace base;
 
 nsIContent* nsBaseWidget::mLastRollup = nsnull;
 
 // nsBaseWidget
 NS_IMPL_ISUPPORTS1(nsBaseWidget, nsIWidget)
 
 
 nsAutoRollup::nsAutoRollup()
@@ -834,26 +839,48 @@ LayerManager* nsBaseWidget::GetLayerMana
                                             LayerManagerPersistence aPersistence,
                                             bool* aAllowRetaining)
 {
   if (!mLayerManager) {
 
     mUseAcceleratedRendering = GetShouldAccelerate();
 
     if (mUseAcceleratedRendering) {
+
       nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(this);
       /**
        * XXX - On several OSes initialization is expected to fail for now.
        * If we'd get a none-basic layer manager they'd crash. This is ok though
        * since on those platforms it will fail. Anyone implementing new
        * platforms on LayerManagerOGL should ensure their widget is able to
        * deal with it though!
        */
       if (layerManager->Initialize()) {
         mLayerManager = layerManager;
+        // TODO Refactor me to support one compositor to many layer manager
+        bool useCompositor =
+          Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
+        if (useCompositor) {
+          Thread* compositorThread = new Thread("CompositorThread");
+          if (compositorThread->Start()) {
+            MessageLoop *parentMessageLoop = MessageLoop::current();
+            MessageLoop *childMessageLoop = compositorThread->message_loop();
+            CompositorParent *compositorParent = new CompositorParent();
+            CompositorChild *compositorChild = new CompositorChild();
+            mozilla::ipc::AsyncChannel *parentChannel = compositorParent->GetIPCChannel();
+            mozilla::ipc::AsyncChannel *childChannel = compositorChild->GetIPCChannel();
+            mozilla::ipc::AsyncChannel::Side childSide =
+              mozilla::ipc::AsyncChannel::Child;
+
+            compositorChild->Open(parentChannel, childMessageLoop, childSide);
+            compositorChild->CallInit();
+            LayerManager::LayersBackend be;
+            PLayersChild* shadowManager = compositorChild->SendPLayersConstructor(LayerManager::LAYERS_OPENGL);
+          }
+        }
       }
     }
     if (!mLayerManager) {
       mBasicLayerManager = mLayerManager = CreateBasicLayerManager();
     }
   }
   if (mTemporarilyUseBasicLayerManager && !mBasicLayerManager) {
     mBasicLayerManager = CreateBasicLayerManager();