Bug 602431, part 2: Add a ShadowColorLayer base class and BasicShadowColorLayer implementation. sr=roc
authorChris Jones <jones.chris.g@gmail.com>
Wed, 13 Oct 2010 17:55:45 -0500
changeset 55444 a27e7290bad9d49fe4de2f326534ba699dbf85c7
parent 55443 0a5ff3652a09c8bcf720f934d7ec2422c20500f8
child 55445 0beb5c409b692ada0471e9d7c1b10fa7543b3af7
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs602431
milestone2.0b8pre
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 602431, part 2: Add a ShadowColorLayer base class and BasicShadowColorLayer implementation. sr=roc
gfx/layers/basic/BasicLayers.cpp
gfx/layers/basic/BasicLayers.h
gfx/layers/ipc/ShadowLayers.h
gfx/layers/ipc/ShadowLayersParent.cpp
--- a/gfx/layers/basic/BasicLayers.cpp
+++ b/gfx/layers/basic/BasicLayers.cpp
@@ -671,32 +671,36 @@ public:
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ColorLayer::SetVisibleRegion(aRegion);
   }
 
   virtual void Paint(gfxContext* aContext,
                      LayerManager::DrawThebesLayerCallback aCallback,
                      void* aCallbackData,
-                     float aOpacity);
+                     float aOpacity)
+  {
+    PaintColorTo(mColor, mOpacity, aContext);
+  }
+
+  static void PaintColorTo(gfxRGBA aColor, float aOpacity,
+                           gfxContext* aContext);
 
 protected:
   BasicLayerManager* BasicManager()
   {
     return static_cast<BasicLayerManager*>(mManager);
   }
 };
 
-void
-BasicColorLayer::Paint(gfxContext* aContext,
-                       LayerManager::DrawThebesLayerCallback aCallback,
-                       void* aCallbackData,
-                       float aOpacity)
+/*static*/ void
+BasicColorLayer::PaintColorTo(gfxRGBA aColor, float aOpacity,
+                              gfxContext* aContext)
 {
-  aContext->SetColor(mColor);
+  aContext->SetColor(aColor);
   aContext->Paint(aOpacity);
 }
 
 class BasicCanvasLayer : public CanvasLayer,
                          BasicImplData
 {
 public:
   BasicCanvasLayer(BasicLayerManager* aLayerManager) :
@@ -2037,16 +2041,39 @@ BasicShadowImageLayer::Paint(gfxContext*
     return;
   }
 
   nsRefPtr<gfxPattern> pat = new gfxPattern(mFrontSurface);
   pat->SetFilter(mFilter);
   BasicImageLayer::PaintContext(pat, mSize, aOpacity, aContext);
 }
 
+class BasicShadowColorLayer : public ShadowColorLayer,
+                              BasicImplData
+{
+public:
+  BasicShadowColorLayer(BasicShadowLayerManager* aLayerManager) :
+    ShadowColorLayer(aLayerManager, static_cast<BasicImplData*>(this))
+  {
+    MOZ_COUNT_CTOR(BasicShadowColorLayer);
+  }
+  virtual ~BasicShadowColorLayer()
+  {
+    MOZ_COUNT_DTOR(BasicShadowColorLayer);
+  }
+
+  virtual void Paint(gfxContext* aContext,
+                     LayerManager::DrawThebesLayerCallback aCallback,
+                     void* aCallbackData,
+                     float aOpacity)
+  {
+    BasicColorLayer::PaintColorTo(mColor, aOpacity, aContext);
+  }
+};
+
 class BasicShadowCanvasLayer : public ShadowCanvasLayer,
                                BasicImplData
 {
 public:
   BasicShadowCanvasLayer(BasicShadowLayerManager* aLayerManager) :
     ShadowCanvasLayer(aLayerManager, static_cast<BasicImplData*>(this))
   {
     MOZ_COUNT_CTOR(BasicShadowCanvasLayer);
@@ -2222,16 +2249,24 @@ BasicShadowLayerManager::CreateShadowThe
 already_AddRefed<ShadowImageLayer>
 BasicShadowLayerManager::CreateShadowImageLayer()
 {
   NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
   nsRefPtr<ShadowImageLayer> layer = new BasicShadowImageLayer(this);
   return layer.forget();
 }
 
+already_AddRefed<ShadowColorLayer>
+BasicShadowLayerManager::CreateShadowColorLayer()
+{
+  NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
+  nsRefPtr<ShadowColorLayer> layer = new BasicShadowColorLayer(this);
+  return layer.forget();
+}
+
 already_AddRefed<ShadowCanvasLayer>
 BasicShadowLayerManager::CreateShadowCanvasLayer()
 {
   NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
   nsRefPtr<ShadowCanvasLayer> layer = new BasicShadowCanvasLayer(this);
   return layer.forget();
 }
 
--- a/gfx/layers/basic/BasicLayers.h
+++ b/gfx/layers/basic/BasicLayers.h
@@ -148,16 +148,18 @@ public:
   virtual already_AddRefed<ImageLayer> CreateImageLayer();
   virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
   virtual already_AddRefed<ImageContainer> CreateImageContainer();
   virtual already_AddRefed<ColorLayer> CreateColorLayer();
   virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer()
   { return NULL; }
   virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer()
   { return NULL; }
+  virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer()
+  { return NULL; }
   virtual already_AddRefed<ShadowCanvasLayer> CreateShadowCanvasLayer()
   { return NULL; }
 
   virtual LayersBackend GetBackendType() { return LAYERS_BASIC; }
   virtual void GetBackendName(nsAString& name) { name.AssignLiteral("Basic"); }
 
 #ifdef DEBUG
   PRBool InConstruction() { return mPhase == PHASE_CONSTRUCTION; }
@@ -239,16 +241,17 @@ public:
 
   virtual already_AddRefed<ThebesLayer> CreateThebesLayer();
   virtual already_AddRefed<ContainerLayer> CreateContainerLayer();
   virtual already_AddRefed<ImageLayer> CreateImageLayer();
   virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
   virtual already_AddRefed<ColorLayer> CreateColorLayer();
   virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer();
   virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer();
+  virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer();
   virtual already_AddRefed<ShadowCanvasLayer> CreateShadowCanvasLayer();
 
   ShadowableLayer* Hold(Layer* aLayer);
 
   PLayersChild* GetShadowManager() const { return mShadowManager; }
 
   void SetShadowManager(PLayersChild* aShadowManager)
   {
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -54,16 +54,17 @@ namespace layers {
 struct Edit;
 struct EditReply;
 class PLayerChild;
 class PLayersChild;
 class PLayersParent;
 class ShadowableLayer;
 class ShadowThebesLayer;
 class ShadowImageLayer;
+class ShadowColorLayer;
 class ShadowCanvasLayer;
 class SurfaceDescriptor;
 class ThebesBuffer;
 class Transaction;
 
 /**
  * We want to share layer trees across thread contexts and address
  * spaces for several reasons; chief among them
@@ -337,16 +338,18 @@ public:
   void DestroySharedSurface(SurfaceDescriptor* aSurface,
                             PLayersParent* aDeallocator);
 
   /** CONSTRUCTION PHASE ONLY */
   virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer() = 0;
   /** CONSTRUCTION PHASE ONLY */
   virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer() = 0;
   /** CONSTRUCTION PHASE ONLY */
+  virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer() = 0;
+  /** CONSTRUCTION PHASE ONLY */
   virtual already_AddRefed<ShadowCanvasLayer> CreateShadowCanvasLayer() = 0;
 
   static void PlatformSyncBeforeReplyUpdate();
 
 protected:
   ShadowLayerManager() {}
 
   PRBool PlatformDestroySharedSurface(SurfaceDescriptor* aSurface);
@@ -585,12 +588,27 @@ public:
 
 protected:
   ShadowImageLayer(LayerManager* aManager, void* aImplData)
     : ImageLayer(aManager, aImplData)
   {}
 };
 
 
+class ShadowColorLayer : public ShadowLayer,
+                         public ColorLayer
+{
+public:
+  virtual ShadowLayer* AsShadowLayer() { return this; }
+
+  MOZ_LAYER_DECL_NAME("ShadowColorLayer", TYPE_SHADOW)
+
+protected:
+  ShadowColorLayer(LayerManager* aManager, void* aImplData)
+    : ColorLayer(aManager, aImplData)
+  {}
+};
+
+
 } // namespace layers
 } // namespace mozilla
 
 #endif // ifndef mozilla_layers_ShadowLayers_h
--- a/gfx/layers/ipc/ShadowLayersParent.cpp
+++ b/gfx/layers/ipc/ShadowLayersParent.cpp
@@ -170,17 +170,17 @@ ShadowLayersParent::RecvUpdate(const nsT
         layer_manager()->CreateShadowImageLayer();
       layer->SetAllocator(this);
       AsShadowLayer(edit.get_OpCreateImageLayer())->Bind(layer);
       break;
     }
     case Edit::TOpCreateColorLayer: {
       MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer"));
 
-      nsRefPtr<ColorLayer> layer = layer_manager()->CreateColorLayer();
+      nsRefPtr<ShadowColorLayer> layer = layer_manager()->CreateShadowColorLayer();
       AsShadowLayer(edit.get_OpCreateColorLayer())->Bind(layer);
       break;
     }
     case Edit::TOpCreateCanvasLayer: {
       MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer"));
 
       nsRefPtr<ShadowCanvasLayer> layer = 
         layer_manager()->CreateShadowCanvasLayer();