Bug 777700 - Part 1: Add a way to check validity of SourceSurfaces. r=jrmuizel

This commit is contained in:
Bas Schouten 2012-07-28 02:33:08 +02:00
parent acd3d18d8f
commit 69cb6d9312
3 changed files with 19 additions and 0 deletions

View File

@ -303,6 +303,13 @@ public:
virtual IntSize GetSize() const = 0;
virtual SurfaceFormat GetFormat() const = 0;
/* This returns false if some event has made this source surface invalid for
* usage with current DrawTargets. For example in the case of Direct2D this
* could return false if we have switched devices since this surface was
* created.
*/
virtual bool IsValid() const { return true; }
/*
* This function will get a DataSourceSurface for this surface, a
* DataSourceSurface's data can be accessed directly.

View File

@ -34,6 +34,12 @@ SourceSurfaceD2D::GetFormat() const
return mFormat;
}
bool
SourceSurfaceD2D::IsValid() const
{
return mDevice == Factory::GetDirect3D10Device();
}
TemporaryRef<DataSourceSurface>
SourceSurfaceD2D::GetDataSurface()
{
@ -68,6 +74,7 @@ SourceSurfaceD2D::InitFromData(unsigned char *aData,
}
DrawTargetD2D::mVRAMUsageSS += GetByteSize();
mDevice = Factory::GetDirect3D10Device();
return true;
}
@ -103,6 +110,7 @@ SourceSurfaceD2D::InitFromTexture(ID3D10Texture2D *aTexture,
return false;
}
aTexture->GetDevice(byRef(mDevice));
DrawTargetD2D::mVRAMUsageSS += GetByteSize();
return true;

View File

@ -22,6 +22,8 @@ public:
virtual SurfaceType GetType() const { return SURFACE_D2D1_BITMAP; }
virtual IntSize GetSize() const;
virtual SurfaceFormat GetFormat() const;
virtual bool IsValid() const;
virtual TemporaryRef<DataSourceSurface> GetDataSurface();
ID2D1Bitmap *GetBitmap() { return mBitmap; }
@ -41,6 +43,8 @@ private:
uint32_t GetByteSize() const;
RefPtr<ID2D1Bitmap> mBitmap;
// We need to keep this pointer here to check surface validity.
RefPtr<ID3D10Device> mDevice;
SurfaceFormat mFormat;
IntSize mSize;
};