b=777946 implement SCALE_STRETCH through ComputeEffectiveTransforms r=Bas
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 18 Sep 2012 15:16:15 +1200
changeset 107420 e8382a09b0e5c02b36fc9744f89329d2da05da75
parent 107419 e300ca85fb382846a778c55b8c555a5b8f1a2aba
child 107421 1b9d7c2c4310f5a24c5077f5232d099108c7865e
push id15022
push userktomlinson@mozilla.com
push dateTue, 18 Sep 2012 21:04:42 +0000
treeherdermozilla-inbound@9c659fdb19f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs777946
milestone18.0a1
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=777946 implement SCALE_STRETCH through ComputeEffectiveTransforms r=Bas
gfx/layers/ImageLayers.cpp
gfx/layers/ImageLayers.h
gfx/layers/basic/BasicImageLayer.cpp
gfx/layers/d3d10/ImageLayerD3D10.cpp
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/opengl/ImageLayerOGL.cpp
--- a/gfx/layers/ImageLayers.cpp
+++ b/gfx/layers/ImageLayers.cpp
@@ -19,26 +19,34 @@ ImageLayer::~ImageLayer()
 
 void ImageLayer::SetContainer(ImageContainer* aContainer) 
 {
   mContainer = aContainer;
 }
 
 void ImageLayer::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
 {
+  gfx3DMatrix local = GetLocalTransform();
+
   // Snap image edges to pixel boundaries
-  gfxRect snap(0, 0, 0, 0);
+  gfxRect sourceRect(0, 0, 0, 0);
   if (mContainer) {
-    gfxIntSize size = mContainer->GetCurrentSize();
-    snap.SizeTo(gfxSize(size.width, size.height));
+    sourceRect.SizeTo(mContainer->GetCurrentSize());
+    if (mScaleMode != SCALE_NONE &&
+        sourceRect.width != 0.0 && sourceRect.height != 0.0) {
+      NS_ASSERTION(mScaleMode == SCALE_STRETCH,
+                   "No other scalemodes than stretch and none supported yet.");
+      local.Scale(mScaleToSize.width / sourceRect.width,
+                  mScaleToSize.height / sourceRect.height, 1.0);
+    }
   }
   // Snap our local transform first, and snap the inherited transform as well.
   // This makes our snapping equivalent to what would happen if our content
   // was drawn into a ThebesLayer (gfxContext would snap using the local
   // transform, then we'd snap again when compositing the ThebesLayer).
   mEffectiveTransform =
-      SnapTransform(GetLocalTransform(), snap, nullptr)*
+      SnapTransform(local, sourceRect, nullptr) *
       SnapTransform(aTransformToSurface, gfxRect(0, 0, 0, 0), nullptr);
   ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
 }
 
 }
 }
--- a/gfx/layers/ImageLayers.h
+++ b/gfx/layers/ImageLayers.h
@@ -19,17 +19,17 @@ class ImageContainer;
 
 /**
  * A Layer which renders an Image.
  */
 class THEBES_API ImageLayer : public Layer {
 public:
   enum ScaleMode {
     SCALE_NONE,
-    SCALE_STRETCH // Unimplemented on GL layers and e10s
+    SCALE_STRETCH
   // Unimplemented - SCALE_PRESERVE_ASPECT_RATIO_CONTAIN
   };
 
   /**
    * CONSTRUCTION PHASE ONLY
    * Set the ImageContainer. aContainer must have the same layer manager
    * as this layer.
    */
--- a/gfx/layers/basic/BasicImageLayer.cpp
+++ b/gfx/layers/basic/BasicImageLayer.cpp
@@ -93,25 +93,16 @@ BasicImageLayer::GetAndPaintCurrentImage
   }
 
   nsRefPtr<gfxPattern> pat = new gfxPattern(surface);
   if (!pat) {
     return nullptr;
   }
 
   pat->SetFilter(mFilter);
-  gfxIntSize sourceSize = surface->GetSize();
-  if (mScaleMode != SCALE_NONE) {
-    NS_ASSERTION(mScaleMode == SCALE_STRETCH,
-      "No other scalemodes than stretch and none supported yet.");
-    gfxMatrix mat = pat->GetMatrix();
-    mat.Scale(float(sourceSize.width) / mScaleToSize.width, float(sourceSize.height) / mScaleToSize.height);
-    pat->SetMatrix(mat);
-    size = mScaleToSize;
-  }
 
   // The visible region can extend outside the image, so just draw
   // within the image bounds.
   if (aContext) {
     AutoSetOperator setOperator(aContext, GetOperator());
     PaintContext(pat,
                  nsIntRegion(nsIntRect(0, 0, size.width, size.height)),
                  aOpacity, aContext, aMaskLayer);
--- a/gfx/layers/d3d10/ImageLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ImageLayerD3D10.cpp
@@ -176,17 +176,17 @@ ImageLayerD3D10::RenderLayer()
 
   AutoLockImage autoLock(container);
 
   Image *image = autoLock.GetImage();
   if (!image) {
     return;
   }
 
-  gfxIntSize size = mScaleMode == SCALE_NONE ? image->GetSize() : mScaleToSize;
+  gfxIntSize size = image->GetSize();
 
   SetEffectTransformAndOpacity();
 
   ID3D10EffectTechnique *technique;
   nsRefPtr<IDXGIKeyedMutex> keyedMutex;
 
   if (image->GetFormat() == ImageFormat::CAIRO_SURFACE || image->GetFormat() == ImageFormat::REMOTE_IMAGE_BITMAP ||
       image->GetFormat() == ImageFormat::REMOTE_IMAGE_DXGI_TEXTURE)
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -363,17 +363,17 @@ ImageLayerD3D9::RenderLayer()
 
   Image *image = autoLock.GetImage();
   if (!image) {
     return;
   }
 
   SetShaderTransformAndOpacity();
 
-  gfxIntSize size = mScaleMode == SCALE_NONE ? image->GetSize() : mScaleToSize;
+  gfxIntSize size = image->GetSize();
 
   if (image->GetFormat() == CAIRO_SURFACE ||
       image->GetFormat() == REMOTE_IMAGE_BITMAP)
   {
     NS_ASSERTION(image->GetFormat() != CAIRO_SURFACE ||
                  !static_cast<CairoImage*>(image)->mSurface ||
                  static_cast<CairoImage*>(image)->mSurface->GetContentType() != gfxASurface::CONTENT_ALPHA,
                  "Image layer has alpha image");
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -242,18 +242,16 @@ ImageLayerOGL::RenderLayer(int,
 
   Image *image = autoLock.GetImage();
   if (!image) {
     return;
   }
 
   NS_ASSERTION(image->GetFormat() != REMOTE_IMAGE_BITMAP,
     "Remote images aren't handled yet in OGL layers!");
-  NS_ASSERTION(mScaleMode == SCALE_NONE,
-    "Scale modes other than none not handled yet in OGL layers!");
 
   if (image->GetFormat() == PLANAR_YCBCR) {
     PlanarYCbCrImage *yuvImage =
       static_cast<PlanarYCbCrImage*>(image);
 
     if (!yuvImage->IsValid()) {
       return;
     }