Bug 651469 - Add FastMovePixels to gfxASurface and use it where appropriate. r=roc

This commit is contained in:
Matt Woodrow 2011-05-08 13:19:11 +12:00
Родитель b8ad9e935d
Коммит cc174c5b89
5 изменённых файлов: 54 добавлений и 6 удалений

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

@ -501,15 +501,13 @@ gfxASurface::BytePerPixelFromFormat(gfxImageFormat format)
}
void
gfxASurface::MovePixels(const nsIntRect& aSourceRect,
const nsIntPoint& aDestTopLeft)
gfxASurface::FastMovePixels(const nsIntRect& aSourceRect,
const nsIntPoint& aDestTopLeft)
{
// Used when the backend can internally handle self copies.
gfxIntSize size = GetSize();
nsIntRect dest(aDestTopLeft, aSourceRect.Size());
// Assume that our cairo backend already knows how to properly
// self-copy. gfxASurface subtypes whose backend can't self-copy
// need their own implementations, or their backends need to be
// fixed.
nsRefPtr<gfxContext> ctx = new gfxContext(this);
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
nsIntPoint srcOrigin = dest.TopLeft() - aSourceRect.TopLeft();
@ -518,6 +516,30 @@ gfxASurface::MovePixels(const nsIntRect& aSourceRect,
ctx->Fill();
}
void
gfxASurface::MovePixels(const nsIntRect& aSourceRect,
const nsIntPoint& aDestTopLeft)
{
// Assume the backend can't handle self copying well and allocate
// a temporary surface instead.
nsRefPtr<gfxASurface> tmp =
CreateSimilarSurface(GetContentType(),
gfxIntSize(aSourceRect.width, aSourceRect.height));
nsRefPtr<gfxContext> ctx = new gfxContext(tmp);
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
ctx->SetSource(this, gfxPoint(-aSourceRect.x, -aSourceRect.y));
ctx->Paint();
ctx = new gfxContext(this);
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
ctx->SetSource(tmp, gfxPoint(aDestTopLeft.x, aDestTopLeft.y));
ctx->Rectangle(gfxRect(aDestTopLeft.x,
aDestTopLeft.y,
aSourceRect.width,
aSourceRect.height));
ctx->Fill();
}
/** Memory reporting **/
static const char *sSurfaceNamesForSurfaceType[] = {

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

@ -256,6 +256,14 @@ protected:
static gfxASurface* GetSurfaceWrapper(cairo_surface_t *csurf);
static void SetSurfaceWrapper(cairo_surface_t *csurf, gfxASurface *asurf);
/**
* An implementation of MovePixels that assumes the backend can
* internally handle this operation and doesn't allocate any
* temporary surfaces.
*/
void FastMovePixels(const nsIntRect& aSourceRect,
const nsIntPoint& aDestTopLeft);
// NB: Init() *must* be called from within subclass's
// constructors. It's unsafe to call it after the ctor finishes;
// leaks and use-after-frees are possible.

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

@ -59,6 +59,12 @@ public:
gfxD2DSurface(cairo_surface_t *csurf);
void MovePixels(const nsIntRect& aSourceRect,
const nsIntPoint& aDestTopLeft)
{
FastMovePixels(aSourceRect, aDestTopLeft);
}
virtual ~gfxD2DSurface();
void Present();

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

@ -68,6 +68,12 @@ public:
already_AddRefed<gfxImageSurface> GetAsImageSurface();
void MovePixels(const nsIntRect& aSourceRect,
const nsIntPoint& aDestTopLeft)
{
FastMovePixels(aSourceRect, aDestTopLeft);
}
protected:
CGContextRef mCGContext;
gfxSize mSize;

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

@ -92,6 +92,12 @@ public:
virtual PRInt32 GetDefaultContextFlags() const;
void MovePixels(const nsIntRect& aSourceRect,
const nsIntPoint& aDestTopLeft)
{
FastMovePixels(aSourceRect, aDestTopLeft);
}
private:
PRPackedBool mOwnsDC;
PRPackedBool mForPrinting;