Bug 733941 - Let callers of imgIContainer::draw choose to clamp instead of tile. r=roc a=blocking-fennec

This commit is contained in:
Ali Juma 2012-04-17 18:04:15 -04:00
parent c28548c766
commit ee7a3a3249
7 changed files with 27 additions and 10 deletions

View File

@ -421,9 +421,11 @@ gfxUtils::DrawPixelSnapped(gfxContext* aContext,
const gfxRect& aImageRect,
const gfxRect& aFill,
const gfxImageSurface::gfxImageFormat aFormat,
const gfxPattern::GraphicsFilter& aFilter)
const gfxPattern::GraphicsFilter& aFilter,
PRUint32 aImageFlags)
{
bool doTile = !aImageRect.Contains(aSourceRect);
bool doTile = !aImageRect.Contains(aSourceRect) &&
!(aImageFlags & imgIContainer::FLAG_CLAMP);
nsRefPtr<gfxASurface> currentTarget = aContext->CurrentSurface();
gfxMatrix deviceSpaceToImageSpace =

View File

@ -43,6 +43,7 @@
#include "gfxImageSurface.h"
#include "ImageLayers.h"
#include "mozilla/gfx/2D.h"
#include "imgIContainer.h"
class gfxDrawable;
class nsIntRegion;
@ -89,7 +90,8 @@ public:
const gfxRect& aImageRect,
const gfxRect& aFill,
const gfxImageSurface::gfxImageFormat aFormat,
const gfxPattern::GraphicsFilter& aFilter);
const gfxPattern::GraphicsFilter& aFilter,
PRUint32 aImageFlags = imgIContainer::FLAG_NONE);
/**
* Clip aContext to the region aRegion.

View File

@ -93,7 +93,7 @@ native gfxGraphicsFilter(gfxPattern::GraphicsFilter);
*
* Internally, imgIContainer also manages animation of images.
*/
[scriptable, uuid(8bf87433-be67-413b-9497-00071c5002bd)]
[scriptable, uuid(ead94080-cfd6-4a3e-8353-bd45333061d2)]
interface imgIContainer : nsISupports
{
/**
@ -156,12 +156,16 @@ interface imgIContainer : nsISupports
* FLAG_DECODE_NO_COLORSPACE_CONVERSION: Do not do any colorspace conversion;
* ignore any embedded profiles, and don't convert to any particular destination
* space.
*
* FLAG_CLAMP: Extend the image to the fill area by clamping image sample
* coordinates instead of by tiling. This only affects 'draw'.
*/
const long FLAG_NONE = 0x0;
const long FLAG_SYNC_DECODE = 0x1;
const long FLAG_DECODE_NO_PREMULTIPLY_ALPHA = 0x2;
const long FLAG_DECODE_NO_COLORSPACE_CONVERSION = 0x4;
const long FLAG_CLAMP = 0x8;
/**
* Constants for specifying various "special" frames.
@ -222,7 +226,9 @@ interface imgIContainer : nsISupports
* @param aFilter The filter to be used if we're scaling the image.
* @param aUserSpaceToImageSpace The transformation from user space (e.g.,
* appunits) to image space.
* @param aFill The area in the context to draw pixels to. Image will be
* @param aFill The area in the context to draw pixels to. When aFlags includes
* FLAG_CLAMP, the image will be extended to this area by clampling
* image sample coordinates. Otherwise, the image will be
* automatically tiled as necessary.
* @param aSubimage The area of the image, in pixels, that we are allowed to
* sample from.

View File

@ -2634,7 +2634,7 @@ RasterImage::Draw(gfxContext *aContext,
mSize.width - framerect.XMost(),
mSize.height - framerect.YMost());
frame->Draw(aContext, aFilter, aUserSpaceToImageSpace, aFill, padding, aSubimage);
frame->Draw(aContext, aFilter, aUserSpaceToImageSpace, aFill, padding, aSubimage, aFlags);
if (mDecoded && !mDrawStartTime.IsNull()) {
TimeDuration drawLatency = TimeStamp::Now() - mDrawStartTime;

View File

@ -466,7 +466,8 @@ imgFrame::SurfaceForDrawing(bool aDoPadding,
void imgFrame::Draw(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter,
const gfxMatrix &aUserSpaceToImageSpace, const gfxRect& aFill,
const nsIntMargin &aPadding, const nsIntRect &aSubimage)
const nsIntMargin &aPadding, const nsIntRect &aSubimage,
PRUint32 aImageFlags)
{
SAMPLE_LABEL("image", "imgFrame::Draw");
NS_ASSERTION(!aFill.IsEmpty(), "zero dest size --- fix caller");
@ -491,7 +492,8 @@ void imgFrame::Draw(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter,
NS_ASSERTION(!sourceRect.Intersect(subimage).IsEmpty(),
"We must be allowed to sample *some* source pixels!");
bool doTile = !imageRect.Contains(sourceRect);
bool doTile = !imageRect.Contains(sourceRect) &&
!(aImageFlags & imgIContainer::FLAG_CLAMP);
SurfaceWithFormat surfaceResult =
SurfaceForDrawing(doPadding, doPartialDecode, doTile, aPadding,
userSpaceToImageSpace, fill, subimage, sourceRect,
@ -501,7 +503,7 @@ void imgFrame::Draw(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter,
gfxUtils::DrawPixelSnapped(aContext, surfaceResult.mDrawable,
userSpaceToImageSpace,
subimage, sourceRect, imageRect, fill,
surfaceResult.mFormat, aFilter);
surfaceResult.mFormat, aFilter, aImageFlags);
}
}

View File

@ -54,6 +54,7 @@
#include "gfxQuartzImageSurface.h"
#endif
#include "nsAutoPtr.h"
#include "imgIContainer.h"
class imgFrame
{
@ -66,7 +67,8 @@ public:
void Draw(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter,
const gfxMatrix &aUserSpaceToImageSpace, const gfxRect& aFill,
const nsIntMargin &aPadding, const nsIntRect &aSubimage);
const nsIntMargin &aPadding, const nsIntRect &aSubimage,
PRUint32 aImageFlags = imgIContainer::FLAG_NONE);
nsresult Extract(const nsIntRect& aRegion, imgFrame** aResult);

View File

@ -3554,6 +3554,9 @@ DrawImageInternal(nsRenderingContext* aRenderingContext,
const nsIntSize& aImageSize,
PRUint32 aImageFlags)
{
if (aDest.Contains(aFill)) {
aImageFlags |= imgIContainer::FLAG_CLAMP;
}
PRInt32 appUnitsPerDevPixel = aRenderingContext->AppUnitsPerDevPixel();
gfxContext* ctx = aRenderingContext->ThebesContext();