mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
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:
parent
c319f0f4a8
commit
ced3693cdf
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user