Bug 637852. Part 7: Remove resolution support from D3D10 layers. r=mattwoodrow
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 23 Jun 2011 00:11:27 +1200
changeset 71796 198d6364abb9747d612f4c20e244fe02e49a1e77
parent 71795 45b7622bc948e52af00b993d08fb2a5a98471f62
child 71797 602d13dcab537ff844d20e9698658619d35f24fa
push idunknown
push userunknown
push dateunknown
reviewersmattwoodrow
bugs637852
milestone7.0a1
Bug 637852. Part 7: Remove resolution support from D3D10 layers. r=mattwoodrow Layer-system resolution support is no longer needed.
gfx/layers/d3d10/ThebesLayerD3D10.cpp
gfx/layers/d3d10/ThebesLayerD3D10.h
--- a/gfx/layers/d3d10/ThebesLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.cpp
@@ -74,38 +74,36 @@ void
 
 ThebesLayerD3D10::InvalidateRegion(const nsIntRegion &aRegion)
 {
   mValidRegion.Sub(mValidRegion, aRegion);
 }
 
 void ThebesLayerD3D10::CopyRegion(ID3D10Texture2D* aSrc, const nsIntPoint &aSrcOffset,
                                   ID3D10Texture2D* aDest, const nsIntPoint &aDestOffset,
-                                  const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion,
-                                  float aXRes, float aYRes)
+                                  const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion)
 {
   nsIntRegion retainedRegion;
   nsIntRegionRectIterator iter(aCopyRegion);
   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. We need to scale these rectangles since the visible 
-      // region is in unscaled units, and the texture size has been scaled.
+      // surface.
       D3D10_BOX box;
-      box.left = UINT(floor((r->x - aSrcOffset.x) * aXRes));
-      box.top = UINT(floor((r->y - aSrcOffset.y) * aYRes));
-      box.right = box.left + UINT(ceil(r->width * aXRes));
-      box.bottom = box.top + UINT(ceil(r->height * aYRes));
+      box.left = r->x - aSrcOffset.x;
+      box.top = r->y - aSrcOffset.y;
+      box.right = box.left + r->width;
+      box.bottom = box.top + r->height;
       box.back = 1;
       box.front = 0;
 
       device()->CopySubresourceRegion(aDest, 0,
-                                      UINT(floor((r->x - aDestOffset.x) * aXRes)),
-                                      UINT(floor((r->y - aDestOffset.y) * aYRes)),
+                                      r->x - aDestOffset.x,
+                                      r->y - aDestOffset.y,
                                       0,
                                       aSrc, 0,
                                       &box);
 
       retainedRegion.Or(retainedRegion, *r);
     }
   }
 
@@ -207,25 +205,16 @@ ThebesLayerD3D10::Validate(ReadbackProce
         mode = SURFACE_SINGLE_CHANNEL_ALPHA;
       }
     }
   }
   mCurrentSurfaceMode = mode;
 
   VerifyContentType(mode);
 
-  float xres, yres;
-  GetDesiredResolutions(xres, yres);
-
-  // If our resolution changed, we need new sized textures, delete the old ones.
-  if (ResolutionChanged(xres, yres)) {
-      mTexture = nsnull;
-      mTextureOnWhite = nsnull;
-  }
-
   nsTArray<ReadbackProcessor::Update> readbackUpdates;
   nsIntRegion readbackRegion;
   if (aReadback && UsedForReadback()) {
     aReadback->GetThebesLayerUpdates(this, &readbackUpdates, &readbackRegion);
   }
 
   if (mTexture) {
     if (!mTextureRect.IsEqualInterior(newTextureRect)) {
@@ -240,37 +229,33 @@ ThebesLayerD3D10::Validate(ReadbackProce
       retainRegion.And(retainRegion, mVisibleRegion);
       // No point in retaining parts which were not valid.
       retainRegion.And(retainRegion, mValidRegion);
 
       CreateNewTextures(gfxIntSize(newTextureRect.width, newTextureRect.height), mode);
 
       nsIntRect largeRect = retainRegion.GetLargestRectangle();
 
-      // If we had no hardware texture before, have no retained area larger than
-      // the retention threshold or the requested resolution has changed, 
-      // 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 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 ||
-          ResolutionChanged(xres, yres)) {
+          largeRect.width * largeRect.height < RETENTION_THRESHOLD) {
         mValidRegion.SetEmpty();
       } else {
         CopyRegion(oldTexture, mTextureRect.TopLeft(),
                    mTexture, newTextureRect.TopLeft(),
-                   retainRegion, &mValidRegion,
-                   xres, yres);
+                   retainRegion, &mValidRegion);
         if (oldTextureOnWhite) {
           CopyRegion(oldTextureOnWhite, mTextureRect.TopLeft(),
                      mTextureOnWhite, newTextureRect.TopLeft(),
-                     retainRegion, &mValidRegion,
-                     xres, yres);
+                     retainRegion, &mValidRegion);
         }
       }
     }
   }
   mTextureRect = newTextureRect;
 
   if (!mTexture || (mode == SURFACE_COMPONENT_ALPHA && !mTextureOnWhite)) {
     CreateNewTextures(gfxIntSize(newTextureRect.width, newTextureRect.height), mode);
@@ -348,58 +333,50 @@ ThebesLayerD3D10::VerifyContentType(Surf
       mTextureOnWhite = nsnull;
       mValidRegion.SetEmpty();
     }
   }
 }
 
 static void
 FillSurface(gfxASurface* aSurface, const nsIntRegion& aRegion,
-            const nsIntPoint& aOffset, const gfxRGBA& aColor,
-            float aXRes, float aYRes)
+            const nsIntPoint& aOffset, const gfxRGBA& aColor)
 {
   nsRefPtr<gfxContext> ctx = new gfxContext(aSurface);
-  ctx->Scale(aXRes, aYRes);
   ctx->Translate(-gfxPoint(aOffset.x, aOffset.y));
   gfxUtils::PathFromRegion(ctx, aRegion);
   ctx->SetColor(aColor);
   ctx->Fill();
 }
 
 void
 ThebesLayerD3D10::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode)
 {
   nsIntRect visibleRect = mVisibleRegion.GetBounds();
 
   if (!mD2DSurface) {
     return;
   }
 
-  float xres, yres;
-  GetDesiredResolutions(xres, yres);
-  aRegion.ExtendForScaling(xres, yres);
-
   nsRefPtr<gfxASurface> destinationSurface;
   
   if (aMode == SURFACE_COMPONENT_ALPHA) {
-    FillSurface(mD2DSurface, aRegion, visibleRect.TopLeft(), gfxRGBA(0.0, 0.0, 0.0, 1.0), xres, yres);
-    FillSurface(mD2DSurfaceOnWhite, aRegion, visibleRect.TopLeft(), gfxRGBA(1.0, 1.0, 1.0, 1.0), xres, yres);
+    FillSurface(mD2DSurface, aRegion, visibleRect.TopLeft(), gfxRGBA(0.0, 0.0, 0.0, 1.0));
+    FillSurface(mD2DSurfaceOnWhite, aRegion, visibleRect.TopLeft(), gfxRGBA(1.0, 1.0, 1.0, 1.0));
     gfxASurface* surfaces[2] = { mD2DSurface.get(), mD2DSurfaceOnWhite.get() };
     destinationSurface = new gfxTeeSurface(surfaces, NS_ARRAY_LENGTH(surfaces));
     // Using this surface as a source will likely go horribly wrong, since
     // only the onBlack surface will really be used, so alpha information will
     // be incorrect.
     destinationSurface->SetAllowUseAsSource(PR_FALSE);
   } else {
     destinationSurface = mD2DSurface;
   }
 
   nsRefPtr<gfxContext> context = new gfxContext(destinationSurface);
-  // Draw content scaled at our current resolution.
-  context->Scale(xres, yres);
 
   nsIntRegionRectIterator iter(aRegion);
   context->Translate(gfxPoint(-visibleRect.x, -visibleRect.y));
   context->NewPath();
   const nsIntRect *iterRect;
   while ((iterRect = iter.Next())) {
     context->Rectangle(gfxRect(iterRect->x, iterRect->y, iterRect->width, iterRect->height));      
   }
@@ -420,25 +397,17 @@ ThebesLayerD3D10::DrawRegion(nsIntRegion
 void
 ThebesLayerD3D10::CreateNewTextures(const gfxIntSize &aSize, SurfaceMode aMode)
 {
   if (aSize.width == 0 || aSize.height == 0) {
     // Nothing to do.
     return;
   }
 
-  // Scale the requested size (in unscaled units) to the actual
-  // texture size we require.
-  gfxIntSize scaledSize;
-  float xres, yres;
-  GetDesiredResolutions(xres, yres);
-  scaledSize.width = PRInt32(ceil(aSize.width * xres));
-  scaledSize.height = PRInt32(ceil(aSize.height * yres));
-
-  CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, scaledSize.width, scaledSize.height, 1, 1);
+  CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1);
   desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
   desc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
   HRESULT hr;
 
   if (!mTexture) {
     hr = device()->CreateTexture2D(&desc, NULL, getter_AddRefs(mTexture));
 
     if (FAILED(hr)) {
@@ -480,38 +449,12 @@ ThebesLayerD3D10::CreateNewTextures(cons
     mD2DSurfaceOnWhite = new gfxD2DSurface(mTextureOnWhite, gfxASurface::CONTENT_COLOR);
 
     if (!mD2DSurfaceOnWhite || mD2DSurfaceOnWhite->CairoStatus()) {
       NS_WARNING("Failed to create surface for ThebesLayerD3D10.");
       mD2DSurfaceOnWhite = nsnull;
       return;
     }
   }
-  
-  mXResolution = xres;
-  mYResolution = yres;
-}
-  
-void 
-ThebesLayerD3D10::GetDesiredResolutions(float& aXRes, float& aYRes)
-{
-  const gfx3DMatrix& transform = GetLayer()->GetEffectiveTransform();
-  gfxMatrix transform2d;
-  if (transform.Is2D(&transform2d)) {
-    gfxSize scale = transform2d.ScaleFactors(PR_TRUE);
-    //Scale factors are normalized to a power of 2 to reduce the number of resolution changes
-    aXRes = gfxUtils::ClampToScaleFactor(scale.width);
-    aYRes = gfxUtils::ClampToScaleFactor(scale.height);
-  } else {
-    aXRes = 1.0;
-    aYRes = 1.0;
-  }
-}
-
-bool 
-ThebesLayerD3D10::ResolutionChanged(float aXRes, float aYRes)
-{
-  return aXRes != mXResolution ||
-         aYRes != mYResolution;
 }
 
 } /* namespace layers */
 } /* namespace mozilla */
--- a/gfx/layers/d3d10/ThebesLayerD3D10.h
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.h
@@ -94,25 +94,14 @@ private:
   void DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode);
 
   /* Create a new texture */
   void CreateNewTextures(const gfxIntSize &aSize, SurfaceMode aMode);
 
   /* Copy a texture region */
   void CopyRegion(ID3D10Texture2D* aSrc, const nsIntPoint &aSrcOffset,
                   ID3D10Texture2D* aDest, const nsIntPoint &aDestOffset,
-                  const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion,
-                  float aXRes, float aYRes);
-
-  /**
-   * Calculate the desired texture resolution based on
-   * the layer managers resolution, and the current
-   * transforms scale factor.
-   */
-  void GetDesiredResolutions(float& aXRes, float& aYRes);
-
-  /* Check if the current texture resolution matches the stored resolution. */
-  bool ResolutionChanged(float aXRes, float aYRes);
+                  const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion);
 };
 
 } /* layers */
 } /* mozilla */
 #endif /* GFX_THEBESLAYERD3D10_H */