Bug 1794360 - Fail to clone ImageBitmap if no data surface available. r=gfx-reviewers,lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D229927
This commit is contained in:
Andrew Osmond 2024-11-22 14:59:39 +00:00
parent 22cb24bd81
commit 96445f317f

View File

@ -950,9 +950,6 @@ UniquePtr<ImageBitmapCloneData> ImageBitmap::ToCloneData() const {
return nullptr;
}
UniquePtr<ImageBitmapCloneData> result(new ImageBitmapCloneData());
result->mPictureRect = mPictureRect;
result->mAlphaType = mAlphaType;
RefPtr<SourceSurface> surface = mData->GetAsSourceSurface();
if (!surface) {
// It might just not be possible to get/map the surface. (e.g. from another
@ -960,10 +957,18 @@ UniquePtr<ImageBitmapCloneData> ImageBitmap::ToCloneData() const {
return nullptr;
}
result->mSurface = surface->GetDataSurface();
MOZ_ASSERT(result->mSurface);
result->mWriteOnly = mWriteOnly;
RefPtr<DataSourceSurface> dataSurface = surface->GetDataSurface();
if (NS_WARN_IF(!dataSurface)) {
// This can reasonably fail in many cases (e.g. canvas state doesn't allow
// reading back the snapshot).
return nullptr;
}
auto result = MakeUnique<ImageBitmapCloneData>();
result->mPictureRect = mPictureRect;
result->mAlphaType = mAlphaType;
result->mSurface = std::move(dataSurface);
result->mWriteOnly = mWriteOnly;
return result;
}