Bug 846132 - (Part 1) Add gfxASurface methods to produce gfxImageSurfaces. r=jrmuizel

This commit is contained in:
Seth Fowler 2013-03-05 15:39:48 -08:00
parent dfbea1ac80
commit e391985aa5
2 changed files with 42 additions and 0 deletions

View File

@ -310,6 +310,35 @@ gfxASurface::CreateSimilarSurface(gfxContentType aContent,
return result.forget();
}
already_AddRefed<gfxImageSurface>
gfxASurface::GetAsReadableARGB32ImageSurface()
{
nsRefPtr<gfxImageSurface> imgSurface = GetAsImageSurface();
if (!imgSurface || imgSurface->Format() != gfxASurface::ImageFormatARGB32) {
imgSurface = CopyToARGB32ImageSurface();
}
return imgSurface.forget();
}
already_AddRefed<gfxImageSurface>
gfxASurface::CopyToARGB32ImageSurface()
{
if (!mSurface || !mSurfaceValid) {
return nullptr;
}
const gfxIntSize size = GetSize();
nsRefPtr<gfxImageSurface> imgSurface =
new gfxImageSurface(size, gfxASurface::ImageFormatARGB32);
gfxContext ctx(imgSurface);
ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
ctx.SetSource(this);
ctx.Paint();
return imgSurface.forget();
}
int
gfxASurface::CairoStatus()
{

View File

@ -155,6 +155,19 @@ public:
return nullptr;
}
/**
* Returns a read-only ARGB32 image surface for this surface. If this is an
* optimized surface this may require a copy.
* Returns null on error.
*/
virtual already_AddRefed<gfxImageSurface> GetAsReadableARGB32ImageSurface();
/**
* Creates a new ARGB32 image surface with the same contents as this surface.
* Returns null on error.
*/
already_AddRefed<gfxImageSurface> CopyToARGB32ImageSurface();
int CairoStatus();
/* Make sure that the given dimensions don't overflow a 32-bit signed int