Bug 605057 - Add gfxASurface::GetAsImageSurface to convert generic surfaces into image surfaces without copies (if possible). r=roc a=b

This commit is contained in:
Matt Woodrow 2010-11-11 15:31:22 -05:00
Родитель c319f0f4a8
Коммит ced3693cdf
16 изменённых файлов: 34 добавлений и 15 удалений

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

@ -183,7 +183,7 @@ CanvasLayerD3D9::Updated(const nsIntRect& aRect)
nsRefPtr<gfxImageSurface> sourceSurface;
if (mSurface->GetType() == gfxASurface::SurfaceTypeWin32) {
sourceSurface = static_cast<gfxWindowsSurface*>(mSurface.get())->GetImageSurface();
sourceSurface = mSurface->GetAsImageSurface();
startBits = sourceSurface->Data() + sourceSurface->Stride() * aRect.y +
aRect.x * 4;
sourceStride = sourceSurface->Stride();

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

@ -160,7 +160,7 @@ CanvasLayerOGL::Updated(const nsIntRect& aRect)
#ifdef XP_WIN
if (sourceSurface->GetType() == gfxASurface::SurfaceTypeWin32) {
sourceSurface = static_cast<gfxWindowsSurface*>(sourceSurface.get())->GetImageSurface();
sourceSurface = sourceSurface->GetAsImageSurface();
if (!sourceSurface)
sourceSurface = mCanvasSurface;
}

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

@ -468,8 +468,7 @@ protected:
nsRefPtr<gfxImageSurface> uploadImage;
if (aUpdateSurface->GetType() == gfxASurface::SurfaceTypeWin32) {
gfxWindowsSurface* ws = static_cast<gfxWindowsSurface*>(aUpdateSurface);
uploadImage = ws->GetImageSurface();
uploadImage = aUpdateSurface->GetAsImageSurface();
} else {
uploadImage = new gfxImageSurface(mUpdateSize, mUpdateFormat);
nsRefPtr<gfxContext> cx(new gfxContext(uploadImage));

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

@ -150,6 +150,17 @@ public:
*/
virtual already_AddRefed<gfxASurface> CreateSimilarSurface(gfxContentType aType,
const gfxIntSize& aSize);
/**
* Returns an image surface for this surface, or nsnull if not supported.
* This will not copy image data, just wraps an image surface around
* pixel data already available in memory.
*/
virtual already_AddRefed<gfxImageSurface> GetAsImageSurface()
{
return nsnull;
}
/**
* Return trues if offscreen surfaces created from this surface
* would behave differently depending on the gfxContentType. Returns

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

@ -79,7 +79,7 @@ LPDIRECTDRAWSURFACE gfxDDrawSurface::GetDDSurface()
}
already_AddRefed<gfxImageSurface>
gfxDDrawSurface::GetImageSurface()
gfxDDrawSurface::GetAsImageSurface()
{
cairo_surface_t *isurf = cairo_ddraw_surface_get_image(CairoSurface());
if (!isurf)

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

@ -57,7 +57,7 @@ public:
virtual ~gfxDDrawSurface();
already_AddRefed<gfxImageSurface> gfxDDrawSurface::GetImageSurface();
already_AddRefed<gfxImageSurface> GetAsImageSurface();
nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
nsresult EndPrinting();

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

@ -224,3 +224,10 @@ gfxSubimageSurface::gfxSubimageSurface(gfxImageSurface* aParent,
, mParent(aParent)
{
}
already_AddRefed<gfxImageSurface>
gfxImageSurface::GetAsImageSurface()
{
nsRefPtr<gfxImageSurface> surface = this;
return surface.forget();
}

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

@ -106,6 +106,8 @@ public:
*/
already_AddRefed<gfxSubimageSurface> GetSubimage(const gfxRect& aRect);
virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
protected:
gfxImageSurface();
void InitWithData(unsigned char *aData, const gfxIntSize& aSize,

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

@ -94,7 +94,7 @@ gfxQPainterSurface::GetQImage()
}
already_AddRefed<gfxImageSurface>
gfxQPainterSurface::GetImageSurface()
gfxQPainterSurface::GetAsImageSurface()
{
if (!mSurfaceValid)
return nsnull;

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

@ -60,7 +60,7 @@ public:
QPainter *GetQPainter() { return mPainter; }
QImage *GetQImage();
already_AddRefed<gfxImageSurface> GetImageSurface();
already_AddRefed<gfxImageSurface> GetAsImageSurface();
protected:
QPainter *mPainter;

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

@ -59,7 +59,7 @@ gfxQuartzImageSurface::~gfxQuartzImageSurface()
}
already_AddRefed<gfxImageSurface>
gfxQuartzImageSurface::GetImageSurface()
gfxQuartzImageSurface::GetAsImageSurface()
{
if (!mSurfaceValid)
return nsnull;

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

@ -48,7 +48,7 @@ public:
virtual ~gfxQuartzImageSurface();
already_AddRefed<gfxImageSurface> GetImageSurface();
already_AddRefed<gfxImageSurface> GetAsImageSurface();
};
#endif /* GFX_QUARTZIMAGESURFACE_H */

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

@ -282,8 +282,8 @@ gfxWindowsNativeDrawing::PaintToContext()
// nothing to do, it already went to the context
mRenderState = RENDER_STATE_DONE;
} else if (mRenderState == RENDER_STATE_ALPHA_RECOVERY_WHITE_DONE) {
nsRefPtr<gfxImageSurface> black = mBlackSurface->GetImageSurface();
nsRefPtr<gfxImageSurface> white = mWhiteSurface->GetImageSurface();
nsRefPtr<gfxImageSurface> black = mBlackSurface->GetAsImageSurface();
nsRefPtr<gfxImageSurface> white = mWhiteSurface->GetAsImageSurface();
if (!gfxAlphaRecovery::RecoverAlpha(black, white)) {
NS_ERROR("Alpha recovery failure");
return;

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

@ -147,7 +147,7 @@ gfxWindowsSurface::GetDCWithClip(gfxContext *ctx)
}
already_AddRefed<gfxImageSurface>
gfxWindowsSurface::GetImageSurface()
gfxWindowsSurface::GetAsImageSurface()
{
if (!mSurfaceValid) {
NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?");

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

@ -75,7 +75,7 @@ public:
HDC GetDCWithClip(gfxContext *);
already_AddRefed<gfxImageSurface> GetImageSurface();
already_AddRefed<gfxImageSurface> GetAsImageSurface();
already_AddRefed<gfxWindowsSurface> OptimizeToDDB(HDC dc,
const gfxIntSize& size,

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

@ -217,7 +217,7 @@ nsresult imgFrame::Init(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
mWinSurface = new gfxWindowsSurface(gfxIntSize(mSize.width, mSize.height), mFormat);
if (mWinSurface && mWinSurface->CairoStatus() == 0) {
// no error
mImageSurface = mWinSurface->GetImageSurface();
mImageSurface = mWinSurface->GetAsImageSurface();
} else {
mWinSurface = nsnull;
}