Bug 572680 - Add nsLayoutUtils::DrawPixelSnapped. r=roc

This commit is contained in:
Markus Stange 2010-08-13 15:30:37 +02:00
Родитель c0e4ac43e7
Коммит 1824fa271f
2 изменённых файлов: 69 добавлений и 0 удалений

Просмотреть файл

@ -95,6 +95,8 @@
#include "ImageLayers.h"
#include "mozilla/dom/Element.h"
#include "nsCanvasFrame.h"
#include "gfxDrawable.h"
#include "gfxUtils.h"
#ifdef MOZ_SVG
#include "nsSVGUtils.h"
@ -3034,6 +3036,49 @@ DrawImageInternal(nsIRenderingContext* aRenderingContext,
return NS_OK;
}
/* static */ void
nsLayoutUtils::DrawPixelSnapped(nsIRenderingContext* aRenderingContext,
gfxDrawable* aDrawable,
gfxPattern::GraphicsFilter aFilter,
const nsRect& aDest,
const nsRect& aFill,
const nsPoint& aAnchor,
const nsRect& aDirty)
{
nsCOMPtr<nsIDeviceContext> dc;
aRenderingContext->GetDeviceContext(*getter_AddRefs(dc));
PRInt32 appUnitsPerDevPixel = dc->AppUnitsPerDevPixel();
gfxContext* ctx = aRenderingContext->ThebesContext();
gfxIntSize drawableSize = aDrawable->Size();
nsIntSize imageSize(drawableSize.width, drawableSize.height);
SnappedImageDrawingParameters drawingParams =
ComputeSnappedImageDrawingParameters(ctx, appUnitsPerDevPixel, aDest, aFill,
aAnchor, aDirty, imageSize);
if (!drawingParams.mShouldDraw)
return;
gfxContextMatrixAutoSaveRestore saveMatrix(ctx);
if (drawingParams.mResetCTM) {
ctx->IdentityMatrix();
}
gfxRect sourceRect =
drawingParams.mUserSpaceToImageSpace.Transform(drawingParams.mFillRect);
gfxRect imageRect(0, 0, imageSize.width, imageSize.height);
gfxRect subimage(drawingParams.mSubimage.x, drawingParams.mSubimage.y,
drawingParams.mSubimage.width, drawingParams.mSubimage.height);
NS_ASSERTION(!sourceRect.Intersect(subimage).IsEmpty(),
"We must be allowed to sample *some* source pixels!");
gfxUtils::DrawPixelSnapped(ctx, aDrawable,
drawingParams.mUserSpaceToImageSpace, subimage,
sourceRect, imageRect, drawingParams.mFillRect,
gfxASurface::ImageFormatARGB32, aFilter);
}
/* static */ nsresult
nsLayoutUtils::DrawSingleUnscaledImage(nsIRenderingContext* aRenderingContext,
imgIContainer* aImage,

Просмотреть файл

@ -66,6 +66,7 @@ class nsClientRectList;
#include "nsCSSPseudoElements.h"
class nsBlockFrame;
class gfxDrawable;
/**
* nsLayoutUtils is a namespace class used for various helper
@ -907,6 +908,29 @@ public:
const nsRect& aDirty,
PRUint32 aImageFlags);
/**
* Draw a drawable using the pixel snapping algorithm.
* See https://wiki.mozilla.org/Gecko:Image_Snapping_and_Rendering
* @param aRenderingContext Where to draw the image, set up with an
* appropriate scale and transform for drawing in
* app units.
* @param aDrawable The drawable we want to draw.
* @param aFilter The graphics filter we should draw with.
* @param aDest Where one copy of the image should mapped to.
* @param aFill The area to be filled with copies of the
* image.
* @param aAnchor A point in aFill which we will ensure is
* pixel-aligned in the output.
* @param aDirty Pixels outside this area may be skipped.
*/
static void DrawPixelSnapped(nsIRenderingContext* aRenderingContext,
gfxDrawable* aDrawable,
gfxPattern::GraphicsFilter aFilter,
const nsRect& aDest,
const nsRect& aFill,
const nsPoint& aAnchor,
const nsRect& aDirty);
/**
* Draw a whole image without scaling or tiling.
*