b=574481; fix layers lifetime issues; part 1 - add API; r=roc
authorVladimir Vukicevic <vladimir@pobox.com>
Fri, 06 Aug 2010 22:09:17 -0700
changeset 49070 48f38be9610c5466d34506a3bc0ccb75ec384fa9
parent 49069 f53e379c34483c0454f23c1ee0d6a813be65053f
child 49071 de9137456817269f99751e8bccea7e039ddcb655
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs574481
milestone2.0b4pre
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
b=574481; fix layers lifetime issues; part 1 - add API; r=roc
gfx/layers/ImageLayers.h
gfx/layers/Layers.h
--- a/gfx/layers/ImageLayers.h
+++ b/gfx/layers/ImageLayers.h
@@ -167,16 +167,23 @@ public:
     return mManager;
   }
 
   /**
    * Returns the size of the image in pixels.
    */
   virtual gfxIntSize GetCurrentSize() = 0;
 
+  /**
+   * Set a new layer manager for this image container.  It must be
+   * either of the same type as the container's current layer manager,
+   * or null.  TRUE is returned on success.
+   */
+  virtual PRBool SetLayerManager(LayerManager *aManager) = 0;
+
 protected:
   LayerManager* mManager;
 
   ImageContainer(LayerManager* aManager) : mManager(aManager) {}
 };
 
 /**
  * A Layer which renders an Image.
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -137,23 +137,32 @@ class THEBES_API LayerManager {
 
 public:
   enum LayersBackend {
     LAYERS_BASIC = 0,
     LAYERS_OPENGL,
     LAYERS_D3D9
   };
 
-  LayerManager() : mUserData(nsnull)
+  LayerManager() : mUserData(nsnull), mDestroyed(PR_FALSE)
   {
     InitLog();
   }
   virtual ~LayerManager() {}
 
   /**
+   * Release layers and resources held by this layer manager, and mark
+   * it as destroyed.  Should do any cleanup necessary in preparation
+   * for its widget going away.  After this call, only user data calls
+   * are valid on the layer manager.
+   */
+  virtual void Destroy() { mDestroyed = PR_TRUE; }
+  PRBool IsDestroyed() { return mDestroyed; }
+
+  /**
    * Start a new transaction. Nested transactions are not allowed so
    * there must be no transaction currently in progress.
    * This transaction will update the state of the window from which
    * this LayerManager was obtained.
    */
   virtual void BeginTransaction() = 0;
   /**
    * Start a new transaction. Nested transactions are not allowed so
@@ -292,16 +301,17 @@ public:
   void LogSelf(const char* aPrefix="");
 
   static bool IsLogEnabled();
   static PRLogModuleInfo* GetLog() { return sLog; }
 
 protected:
   nsRefPtr<Layer> mRoot;
   void* mUserData;
+  PRPackedBool mDestroyed;
 
   // Print interesting information about this into aTo.  Internally
   // used to implement Dump*() and Log*().
   virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
 
   static void InitLog();
   static PRLogModuleInfo* sLog;
 };
@@ -323,17 +333,19 @@ public:
     TYPE_COLOR,
     TYPE_CANVAS,
     TYPE_SHADOW
   };
 
   virtual ~Layer() {}
 
   /**
-   * Returns the LayoutManager this Layer belongs to. Cannot be null.
+   * Returns the LayerManager this Layer belongs to. Note that the layer
+   * manager might be in a destroyed state, at which point it's only
+   * valid to set/get user data from it.
    */
   LayerManager* Manager() { return mManager; }
 
   /**
    * CONSTRUCTION PHASE ONLY
    * If this is called with aOpaque set to true, the caller is promising
    * that by the end of this transaction the entire visible region
    * (as specified by SetVisibleRegion) will be filled with opaque
@@ -382,16 +394,17 @@ public:
   void SetClipRect(const nsIntRect* aRect)
   {
     mUseClipRect = aRect != nsnull;
     if (aRect) {
       mClipRect = *aRect;
     }
     Mutated();
   }
+
   /**
    * CONSTRUCTION PHASE ONLY
    * Set a clip rect which will be applied to this layer as it is
    * composited to the destination. The coordinates are relative to
    * the parent layer (i.e. the contents of this layer
    * are transformed before this clip rect is applied).
    * For the root layer, the coordinates are relative to the widget,
    * in device pixels.