[mq]: Backout of df6f10906476
authorDoug Turner <dougt@dougt.org>
Wed, 19 Jan 2011 20:47:45 -0800
changeset 60914 a02a04f6b6b7c0dc246a314b70e073f4287dd656
parent 60913 41ae1ee9085fac976c20d0c75e230f504115c608
child 60915 9b6a73bdb2370d78459660c9b403aad1eb15a2ef
push id18161
push userdougt@mozilla.com
push dateThu, 20 Jan 2011 04:51:24 +0000
treeherdermozilla-central@9b6a73bdb237 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0b10pre
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
[mq]: Backout of df6f10906476
gfx/layers/d3d10/ThebesLayerD3D10.cpp
gfx/layers/d3d10/ThebesLayerD3D10.h
--- a/gfx/layers/d3d10/ThebesLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.cpp
@@ -60,54 +60,96 @@ ThebesLayerD3D10::~ThebesLayerD3D10()
 /**
  * Retention threshold - amount of pixels intersection required to enable
  * layer content retention. This is a guesstimate. Profiling could be done to
  * figure out the optimal threshold.
  */
 #define RETENTION_THRESHOLD 16384
 
 void
-
-ThebesLayerD3D10::InvalidateRegion(const nsIntRegion &aRegion)
+ThebesLayerD3D10::SetVisibleRegion(const nsIntRegion &aRegion)
 {
-  mValidRegion.Sub(mValidRegion, aRegion);
-}
+  if (aRegion.IsEqual(mVisibleRegion)) {
+    return;
+  }
+
+  nsIntRegion oldVisibleRegion = mVisibleRegion;
+  ThebesLayer::SetVisibleRegion(aRegion);
+
+  if (!mTexture) {
+    // If we don't need to retain content initialize lazily. This is good also
+    // because we might get mIsOpaqueSurface set later than the first call to
+    // SetVisibleRegion.
+    return;
+  }
+
+  VerifyContentType();
+
+  nsRefPtr<ID3D10Texture2D> oldTexture = mTexture;
+
+  nsIntRect oldBounds = oldVisibleRegion.GetBounds();
+  nsIntRect newBounds = mVisibleRegion.GetBounds();
 
-void ThebesLayerD3D10::CopyRegion(ID3D10Texture2D* aSrc, const nsIntPoint &aSrcOffset,
-                                  ID3D10Texture2D* aDest, const nsIntPoint &aDestOffset,
-                                  const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion)
-{
+  CreateNewTexture(gfxIntSize(newBounds.width, newBounds.height));
+
+  // Old visible region will become the region that is covered by both the
+  // old and the new visible region.
+  oldVisibleRegion.And(oldVisibleRegion, mVisibleRegion);
+  // No point in retaining parts which were not valid.
+  oldVisibleRegion.And(oldVisibleRegion, mValidRegion);
+
+  nsIntRect largeRect = oldVisibleRegion.GetLargestRectangle();
+
+  // If we had no hardware texture before or have no retained area larger than
+  // the retention threshold, we're not retaining and are done here. If our
+  // texture creation failed this can mean a device reset is pending and we
+  // should silently ignore the failure. In the future when device failures
+  // are properly handled we should test for the type of failure and gracefully
+  // handle different failures. See bug 569081.
+  if (!oldTexture || !mTexture ||
+      largeRect.width * largeRect.height < RETENTION_THRESHOLD) {
+    mValidRegion.SetEmpty();
+    return;
+  }
+
   nsIntRegion retainedRegion;
-  nsIntRegionRectIterator iter(aCopyRegion);
+  nsIntRegionRectIterator iter(oldVisibleRegion);
   const nsIntRect *r;
   while ((r = iter.Next())) {
     if (r->width * r->height > RETENTION_THRESHOLD) {
       // Calculate the retained rectangle's position on the old and the new
       // surface.
       D3D10_BOX box;
-      box.left = r->x - aSrcOffset.x;
-      box.top = r->y - aSrcOffset.y;
+      box.left = r->x - oldBounds.x;
+      box.top = r->y - oldBounds.y;
       box.right = box.left + r->width;
       box.bottom = box.top + r->height;
-      box.back = 1;
+      box.back = 1.0f;
       box.front = 0;
 
-      device()->CopySubresourceRegion(aDest, 0,
-                                      r->x - aDestOffset.x,
-                                      r->y - aDestOffset.y,
+      device()->CopySubresourceRegion(mTexture, 0,
+                                      r->x - newBounds.x,
+                                      r->y - newBounds.y,
                                       0,
-                                      aSrc, 0,
+                                      oldTexture, 0,
                                       &box);
 
       retainedRegion.Or(retainedRegion, *r);
     }
   }
 
   // Areas which were valid and were retained are still valid
-  aValidRegion->And(*aValidRegion, retainedRegion);  
+  mValidRegion.And(mValidRegion, retainedRegion);  
+}
+
+
+void
+ThebesLayerD3D10::InvalidateRegion(const nsIntRegion &aRegion)
+{
+  mValidRegion.Sub(mValidRegion, aRegion);
 }
 
 void
 ThebesLayerD3D10::RenderLayer()
 {
   if (!mTexture) {
     return;
   }
@@ -163,52 +205,16 @@ ThebesLayerD3D10::Validate()
   if (mVisibleRegion.IsEmpty()) {
     return;
   }
 
   VerifyContentType();
 
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
 
-  if (mTexture) {
-    if (!mTextureRegion.IsEqual(mVisibleRegion)) {
-      nsRefPtr<ID3D10Texture2D> oldTexture = mTexture;
-
-      nsIntRegion retainRegion = mTextureRegion;
-      nsIntRect oldBounds = mTextureRegion.GetBounds();
-      nsIntRect newBounds = mVisibleRegion.GetBounds();
-
-      CreateNewTexture(gfxIntSize(newBounds.width, newBounds.height));
-
-      // Old visible region will become the region that is covered by both the
-      // old and the new visible region.
-      retainRegion.And(retainRegion, mVisibleRegion);
-      // No point in retaining parts which were not valid.
-      retainRegion.And(retainRegion, mValidRegion);
-
-      nsIntRect largeRect = retainRegion.GetLargestRectangle();
-
-      // If we had no hardware texture before or have no retained area larger than
-      // the retention threshold, we're not retaining and are done here. If our
-      // texture creation failed this can mean a device reset is pending and we
-      // should silently ignore the failure. In the future when device failures
-      // are properly handled we should test for the type of failure and gracefully
-      // handle different failures. See bug 569081.
-      if (!oldTexture || !mTexture ||
-          largeRect.width * largeRect.height < RETENTION_THRESHOLD) {
-        mValidRegion.SetEmpty();
-      } else {
-        CopyRegion(oldTexture, oldBounds.TopLeft(),
-                   mTexture, newBounds.TopLeft(),
-                   retainRegion, &mValidRegion);
-      }
-      mTextureRegion = mVisibleRegion;
-    }
-  }
-
   if (!mTexture) {
     CreateNewTexture(gfxIntSize(visibleRect.width, visibleRect.height));
     mValidRegion.SetEmpty();
   }
 
   if (!mValidRegion.IsEqual(mVisibleRegion)) {
     LayerManagerD3D10::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
     if (!cbInfo.Callback) {
@@ -261,16 +267,17 @@ ThebesLayerD3D10::VerifyContentType()
       mValidRegion.SetEmpty();
     }
   }
 }
 
 void
 ThebesLayerD3D10::DrawRegion(const nsIntRegion &aRegion)
 {
+  HRESULT hr;
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
 
   if (!mD2DSurface) {
     return;
   }
 
   nsRefPtr<gfxContext> context = new gfxContext(mD2DSurface);
 
--- a/gfx/layers/d3d10/ThebesLayerD3D10.h
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.h
@@ -46,48 +46,43 @@ namespace layers {
 
 class ThebesLayerD3D10 : public ThebesLayer,
                          public LayerD3D10
 {
 public:
   ThebesLayerD3D10(LayerManagerD3D10 *aManager);
   virtual ~ThebesLayerD3D10();
 
+  /* Layer implementation */
+  void SetVisibleRegion(const nsIntRegion& aRegion);
+
   /* ThebesLayer implementation */
   void InvalidateRegion(const nsIntRegion& aRegion);
 
   /* LayerD3D10 implementation */
   virtual Layer* GetLayer();
   virtual void RenderLayer();
   virtual void Validate();
   virtual void LayerManagerDestroyed();
 
 private:
   /* Texture with our surface data */
   nsRefPtr<ID3D10Texture2D> mTexture;
 
   /* Shader resource view for our texture */
   nsRefPtr<ID3D10ShaderResourceView> mSRView;
 
-  /* Visible region used when we drew the contents of the textures */
-  nsIntRegion mTextureRegion;
-
   /* Checks if our D2D surface has the right content type */
   void VerifyContentType();
 
   /* This contains the thebes surface */
   nsRefPtr<gfxASurface> mD2DSurface;
 
   /* Have a region of our layer drawn */
   void DrawRegion(const nsIntRegion &aRegion);
 
   /* Create a new texture */
   void CreateNewTexture(const gfxIntSize &aSize);
-
-  /* Copy a texture region */
-  void CopyRegion(ID3D10Texture2D* aSrc, const nsIntPoint &aSrcOffset,
-                  ID3D10Texture2D* aDest, const nsIntPoint &aDestOffset,
-                  const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion);
 };
 
 } /* layers */
 } /* mozilla */
 #endif /* GFX_THEBESLAYERD3D10_H */