Bug 732988 - Part 1: Add ScaleToSize API to ImageLayers. r=roc

This commit is contained in:
Bas Schouten
2012-03-13 01:41:29 +00:00
parent fd76aea573
commit 623684cf39
5 changed files with 43 additions and 13 deletions

View File

@@ -926,7 +926,7 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext,
nsRefPtr<gfxASurface> surface;
AutoLockImage autoLock(mContainer, getter_AddRefs(surface));
Image *image = autoLock.GetImage();
mSize = autoLock.GetSize();
gfxIntSize size = mSize = autoLock.GetSize();
if (!surface || surface->CairoStatus()) {
return nsnull;
@@ -938,6 +938,15 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext,
}
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. If we're not
// tiling, we don't want to draw into that area, so just draw within
@@ -945,7 +954,7 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext,
const nsIntRect* tileSrcRect = GetTileSourceRect();
AutoSetOperator setOperator(aContext, GetOperator());
PaintContext(pat,
tileSrcRect ? GetVisibleRegion() : nsIntRegion(nsIntRect(0, 0, mSize.width, mSize.height)),
tileSrcRect ? GetVisibleRegion() : nsIntRegion(nsIntRect(0, 0, size.width, size.height)),
tileSrcRect,
aOpacity, aContext);