mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 05:30:29 +00:00
Bug 651469 - Add FastMovePixels to gfxASurface and use it where appropriate. r=roc
This commit is contained in:
parent
b8ad9e935d
commit
cc174c5b89
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user