Bug 739679 - Part 2.5: Add TiledBuffer IPC code. r=cjones
authorBenoit Girard <b56girard@gmail.com>
Fri, 13 Apr 2012 11:17:39 -0400
changeset 92201 2f5d290dc23414758ae3f746153b986411c3c68f
parent 92192 1b2dbf32886bba885d4fde24fe1fff5079bf9ed2
child 92202 6aac1347aa358aba72753df5d366d84e87505cc8
push idunknown
push userunknown
push dateunknown
reviewerscjones
bugs739679
milestone14.0a1
Bug 739679 - Part 2.5: Add TiledBuffer IPC code. r=cjones
gfx/layers/ipc/PLayers.ipdl
gfx/layers/ipc/ShadowLayers.cpp
gfx/layers/ipc/ShadowLayers.h
gfx/layers/ipc/ShadowLayersParent.cpp
--- a/gfx/layers/ipc/PLayers.ipdl
+++ b/gfx/layers/ipc/PLayers.ipdl
@@ -157,16 +157,23 @@ struct OpRemoveChild  { PLayer container
 
 // Paint (buffer update)
 struct OpPaintThebesBuffer {
   PLayer layer;
   ThebesBuffer newFrontBuffer;
   nsIntRegion updatedRegion;
 };
 
+struct OpPaintTiledLayerBuffer {
+  PLayer layer;
+  // Bug 747811
+  // FIXME: We need to support sharing tile across process.
+  uintptr_t tiledLayerBuffer;
+};
+
 struct OpPaintCanvas  {
   PLayer layer;
   CanvasSurface newFrontBuffer;
   bool needYFlip;
 };
 
 struct OpPaintImage  {
   PLayer layer;
@@ -185,16 +192,17 @@ union Edit {
   OpSetLayerAttributes;
 
   OpSetRoot;
   OpInsertAfter;
   OpAppendChild;
   OpRemoveChild;
 
   OpPaintThebesBuffer;
+  OpPaintTiledLayerBuffer;
   OpPaintCanvas;
   OpPaintImage;
 };
 
 
 // Replies to operations
 struct OpBufferSwap   { PLayer layer; CanvasSurface newBackBuffer; };
 
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -47,16 +47,17 @@
 #include "mozilla/layers/PLayerChild.h"
 #include "mozilla/layers/PLayersChild.h"
 #include "mozilla/layers/PLayersParent.h"
 #include "ShadowLayers.h"
 #include "ShadowLayerChild.h"
 #include "gfxipc/ShadowLayerUtils.h"
 #include "RenderTrace.h"
 #include "sampler.h"
+#include "nsXULAppAPI.h"
 
 using namespace mozilla::ipc;
 
 namespace mozilla {
 namespace layers {
 
 typedef nsTArray<SurfaceDescriptor> BufferArray; 
 typedef std::vector<Edit> EditVector;
@@ -234,16 +235,27 @@ ShadowLayerForwarder::PaintedThebesBuffe
                                           const SurfaceDescriptor& aNewFrontBuffer)
 {
   mTxn->AddPaint(OpPaintThebesBuffer(NULL, Shadow(aThebes),
                                      ThebesBuffer(aNewFrontBuffer,
                                                   aBufferRect,
                                                   aBufferRotation),
                                      aUpdatedRegion));
 }
+
+void
+ShadowLayerForwarder::PaintedTiledLayerBuffer(ShadowableLayer* aLayer,
+                                              BasicTiledLayerBuffer* aTiledLayerBuffer)
+{
+  if (XRE_GetProcessType() != GeckoProcessType_Default)
+    NS_RUNTIMEABORT("PaintedTiledLayerBuffer must be made IPC safe (not share pointers)");
+  mTxn->AddPaint(OpPaintTiledLayerBuffer(NULL, Shadow(aLayer),
+                                         uintptr_t(aTiledLayerBuffer)));
+}
+
 void
 ShadowLayerForwarder::PaintedImage(ShadowableLayer* aImage,
                                    const SharedImage& aNewFrontImage)
 {
   mTxn->AddPaint(OpPaintImage(NULL, Shadow(aImage),
                               aNewFrontImage));
 }
 void
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -60,19 +60,21 @@ class PLayersParent;
 class ShadowableLayer;
 class ShadowThebesLayer;
 class ShadowContainerLayer;
 class ShadowImageLayer;
 class ShadowColorLayer;
 class ShadowCanvasLayer;
 class SurfaceDescriptor;
 class ThebesBuffer;
+class TiledLayerComposer;
 class Transaction;
 class SharedImage;
 class CanvasSurface;
+class BasicTiledLayerBuffer;
 
 /**
  * We want to share layer trees across thread contexts and address
  * spaces for several reasons; chief among them
  *
  *  - a parent process can paint a child process's layer tree while
  *    the child process is blocked, say on content script.  This is
  *    important on mobile devices where UI responsiveness is key.
@@ -182,16 +184,27 @@ public:
    * possibly-toroidally-rotated |aNewFrontBuffer|.  |aBufferRotation|
    * is buffer's rotation, if any.
    */
   void PaintedThebesBuffer(ShadowableLayer* aThebes,
                            const nsIntRegion& aUpdatedRegion,
                            const nsIntRect& aBufferRect,
                            const nsIntPoint& aBufferRotation,
                            const SurfaceDescriptor& aNewFrontBuffer);
+
+  /**
+   * Notify the compositor that a tiled layer buffer has changed
+   * that needs to be synced to the shadow retained copy. The tiled
+   * layer buffer will operate directly on the shadow retained buffer
+   * and is free to choose it's own internal representation (double buffering,
+   * copy on write, tiling).
+   */
+  void PaintedTiledLayerBuffer(ShadowableLayer* aThebes,
+                               BasicTiledLayerBuffer* aTiledLayerBuffer);
+
   /**
    * NB: this initial implementation only forwards RGBA data for
    * ImageLayers.  This is slow, and will be optimized.
    */
   void PaintedImage(ShadowableLayer* aImage,
                     const SharedImage& aNewFrontImage);
   void PaintedCanvas(ShadowableLayer* aCanvas,
                      bool aNeedYFlip,
@@ -463,16 +476,18 @@ public:
     mShadowTransform = aMatrix;
   }
 
   // These getters can be used anytime.
   const nsIntRect* GetShadowClipRect() { return mUseShadowClipRect ? &mShadowClipRect : nsnull; }
   const nsIntRegion& GetShadowVisibleRegion() { return mShadowVisibleRegion; }
   const gfx3DMatrix& GetShadowTransform() { return mShadowTransform; }
 
+  virtual TiledLayerComposer* AsTiledLayerComposer() { return NULL; }
+
 protected:
   ShadowLayer()
     : mAllocator(nsnull)
     , mUseShadowClipRect(false)
   {}
 
   ISurfaceDeAllocator* mAllocator;
   nsIntRegion mShadowVisibleRegion;
--- a/gfx/layers/ipc/ShadowLayersParent.cpp
+++ b/gfx/layers/ipc/ShadowLayersParent.cpp
@@ -47,16 +47,17 @@
 
 #include "mozilla/unused.h"
 
 #include "mozilla/layout/RenderFrameParent.h"
 #include "CompositorParent.h"
 
 #include "gfxSharedImageSurface.h"
 
+#include "TiledLayerBuffer.h"
 #include "ImageLayers.h"
 
 typedef std::vector<mozilla::layers::EditReply> EditReplyVector;
 
 using mozilla::layout::RenderFrameParent;
 
 namespace mozilla {
 namespace layers {
@@ -309,16 +310,30 @@ ShadowLayersParent::RecvUpdate(const Inf
       MOZ_LAYERS_LOG(("[ParentSide] RemoveChild"));
 
       const OpRemoveChild& orc = edit.get_OpRemoveChild();
       Layer* childLayer = ShadowChild(orc)->AsLayer();
       ShadowContainer(orc)->AsContainer()->RemoveChild(childLayer);
       break;
     }
 
+    case Edit::TOpPaintTiledLayerBuffer: {
+      MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer"));
+      const OpPaintTiledLayerBuffer& op = edit.get_OpPaintTiledLayerBuffer();
+      ShadowLayerParent* shadow = AsShadowLayer(op);
+
+      ShadowThebesLayer* shadowLayer = static_cast<ShadowThebesLayer*>(shadow->AsLayer());
+      TiledLayerComposer* tileComposer = shadowLayer->AsTiledLayerComposer();
+
+      NS_ASSERTION(tileComposer, "shadowLayer is not a tile composer");
+
+      BasicTiledLayerBuffer* p = (BasicTiledLayerBuffer*)op.tiledLayerBuffer();
+      tileComposer->PaintedTiledLayerBuffer(p);
+      break;
+    }
     case Edit::TOpPaintThebesBuffer: {
       MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer"));
 
       const OpPaintThebesBuffer& op = edit.get_OpPaintThebesBuffer();
       ShadowLayerParent* shadow = AsShadowLayer(op);
       ShadowThebesLayer* thebes =
         static_cast<ShadowThebesLayer*>(shadow->AsLayer());
       const ThebesBuffer& newFront = op.newFrontBuffer();