Bug 793175: Discard a cached SourceSurface if it was created for the wrong BackendType. r=jrmuizel

This commit is contained in:
Bas Schouten 2012-10-08 15:44:36 +13:00
Родитель 555c2a462b
Коммит 29ab97de1c
1 изменённых файлов: 22 добавлений и 7 удалений

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

@ -489,9 +489,22 @@ gfxPlatform::CreateDrawTargetForSurface(gfxASurface *aSurface, const IntSize& aS
cairo_user_data_key_t kSourceSurface;
void SourceBufferDestroy(void *srcBuffer)
/**
* Record the backend that was used to construct the SourceSurface.
* When getting the cached SourceSurface for a gfxASurface/DrawTarget pair,
* we check to make sure the DrawTarget's backend matches the backend
* for the cached SourceSurface, and only use it if they match. This
* can avoid expensive and unnecessary readbacks.
*/
struct SourceSurfaceUserData
{
static_cast<SourceSurface*>(srcBuffer)->Release();
RefPtr<SourceSurface> mSrcSurface;
BackendType mBackendType;
};
void SourceBufferDestroy(void *srcSurfUD)
{
delete static_cast<SourceSurfaceUserData*>(srcSurfUD);
}
void SourceSnapshotDetached(cairo_surface_t *nullSurf)
@ -508,10 +521,10 @@ gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget, gfxASurface *aSurfa
void *userData = aSurface->GetData(&kSourceSurface);
if (userData) {
SourceSurface *surf = static_cast<SourceSurface*>(userData);
SourceSurfaceUserData *surf = static_cast<SourceSurfaceUserData*>(userData);
if (surf->IsValid()) {
return surf;
if (surf->mSrcSurface->IsValid() && surf->mBackendType == aTarget->GetType()) {
return surf->mSrcSurface;
}
// We can just continue here as when setting new user data the destroy
// function will be called for the old user data.
@ -623,8 +636,10 @@ gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget, gfxASurface *aSurfa
cairo_surface_destroy(nullSurf);
}
srcBuffer->AddRef();
aSurface->SetData(&kSourceSurface, srcBuffer, SourceBufferDestroy);
SourceSurfaceUserData *srcSurfUD = new SourceSurfaceUserData;
srcSurfUD->mBackendType = aTarget->GetType();
srcSurfUD->mSrcSurface = srcBuffer;
aSurface->SetData(&kSourceSurface, srcSurfUD, SourceBufferDestroy);
return srcBuffer;
}