Bug 997551 - Avoid copying data in GetSourceSurfaceForSurface whenever possible. r=Bas

This commit is contained in:
Matt Woodrow 2014-04-25 15:31:53 +12:00
Родитель 8063163ac9
Коммит d8e88266a3
3 изменённых файлов: 16 добавлений и 66 удалений

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

@ -1222,7 +1222,7 @@ DrawTargetD2D::OptimizeSourceSurface(SourceSurface *aSurface) const
data->Unmap();
if (!success) {
return nullptr;
return data;
}
return newSurf;
}

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

@ -943,7 +943,7 @@ DrawTargetD2D1::OptimizeSourceSurface(SourceSurface* aSurface) const
data->Unmap();
if (!bitmap) {
return nullptr;
return data;
}
return new SourceSurfaceD2D1(bitmap.get(), mDC, data->GetFormat(), data->GetSize());

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

@ -754,76 +754,26 @@ gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget, gfxASurface *aSurfa
if (!srcBuffer) {
nsRefPtr<gfxImageSurface> imgSurface = aSurface->GetAsImageSurface();
RefPtr<DataSourceSurface> copy;
if (!imgSurface) {
copy = CopySurface(aSurface);
RefPtr<DataSourceSurface> dataSurf;
if (!copy) {
return nullptr;
}
DataSourceSurface::MappedSurface map;
DebugOnly<bool> result = copy->Map(DataSourceSurface::WRITE, &map);
MOZ_ASSERT(result, "Should always succeed mapping raw data surfaces!");
imgSurface = new gfxImageSurface(map.mData, aSurface->GetSize(), map.mStride,
SurfaceFormatToImageFormat(copy->GetFormat()));
if (imgSurface) {
dataSurf = GetWrappedDataSourceSurface(aSurface);
} else {
dataSurf = CopySurface(aSurface);
}
gfxImageFormat cairoFormat = imgSurface->Format();
switch(cairoFormat) {
case gfxImageFormat::ARGB32:
format = SurfaceFormat::B8G8R8A8;
break;
case gfxImageFormat::RGB24:
format = SurfaceFormat::B8G8R8X8;
break;
case gfxImageFormat::A8:
format = SurfaceFormat::A8;
break;
case gfxImageFormat::RGB16_565:
format = SurfaceFormat::R5G6B5;
break;
default:
NS_RUNTIMEABORT("Invalid surface format!");
}
IntSize size = IntSize(imgSurface->GetSize().width, imgSurface->GetSize().height);
srcBuffer = aTarget->CreateSourceSurfaceFromData(imgSurface->Data(),
size,
imgSurface->Stride(),
format);
if (copy) {
copy->Unmap();
}
if (!srcBuffer) {
// If we had to make a copy, then just return that. Otherwise aSurface
// must have supported GetAsImageSurface, so we can just wrap that data.
if (copy) {
srcBuffer = copy;
} else {
return GetWrappedDataSourceSurface(aSurface);
}
}
if (!srcBuffer) {
if (!dataSurf) {
return nullptr;
}
#if MOZ_TREE_CAIRO
cairo_surface_t *nullSurf =
cairo_null_surface_create(CAIRO_CONTENT_COLOR_ALPHA);
cairo_surface_set_user_data(nullSurf,
&kSourceSurface,
imgSurface,
nullptr);
cairo_surface_attach_snapshot(imgSurface->CairoSurface(), nullSurf, SourceSnapshotDetached);
cairo_surface_destroy(nullSurf);
#else
cairo_surface_set_mime_data(imgSurface->CairoSurface(), "mozilla/magic", (const unsigned char*) "data", 4, SourceSnapshotDetached, imgSurface.get());
#endif
srcBuffer = aTarget->OptimizeSourceSurface(dataSurf);
if (imgSurface && srcBuffer == dataSurf) {
// Our wrapping surface will hold a reference to its image surface. We cause
// a reference cycle if we add it to the cache. And caching it is pretty
// pointless since we'll just wrap it again next use.
return srcBuffer;
}
}
// Add user data to aSurface so we can cache lookups in the future.