Bug 1751053 - Avoid intermediate surface allocation to premultiply in ClientWebGLContext::GetSurfaceSnapshot. r=jgilbert, a=RyanVM

The intermediate allocation could fail and it was not handled, causing
an infrequent OOM crash. This patch makes it so we just reuse the
surface buffer we have and does the premultiply inline without requiring
an additional allocation.

Differential Revision: https://phabricator.services.mozilla.com/D136410
This commit is contained in:
Andrew Osmond 2022-01-20 12:33:46 +00:00
parent 24aab41cda
commit ffa4e37fed

View File

@ -837,11 +837,16 @@ already_AddRefed<gfx::SourceSurface> ClientWebGLContext::GetSurfaceSnapshot(
} else {
// Expects Opaque or Premult
if (srcAlphaType == gfxAlphaType::NonPremult) {
const auto nonPremultSurf = ret;
const auto& size = nonPremultSurf->GetSize();
const auto format = nonPremultSurf->GetFormat();
ret = gfx::Factory::CreateDataSourceSurface(size, format, /*zero=*/false);
gfxUtils::PremultiplyDataSurface(nonPremultSurf, ret);
const gfx::DataSourceSurface::ScopedMap map(
ret, gfx::DataSourceSurface::READ_WRITE);
MOZ_RELEASE_ASSERT(map.IsMapped(), "Failed to map snapshot surface!");
const auto& size = ret->GetSize();
const auto format = ret->GetFormat();
bool rv =
gfx::PremultiplyData(map.GetData(), map.GetStride(), format,
map.GetData(), map.GetStride(), format, size);
MOZ_RELEASE_ASSERT(rv, "PremultiplyData failed!");
}
}