mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 892910: Deal with newSize becoming empty in CreatePartialBitmapForSurface. r=BenWa
This patch deals with the situation where newSize becomes empty and causes a division by 0 in the current code. It also ensures all the callers will abort any potential drawing when CreatePartialBitmapForSurface returns a nullptr.
This commit is contained in:
parent
1a735f100b
commit
f62c69e9d3
@ -2417,7 +2417,9 @@ DrawTargetD2D::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
|
||||
|
||||
bitmap = CreatePartialBitmapForSurface(dataSurf, mTransform, mSize, pat->mExtendMode, mat, mRT, &sourceRect);
|
||||
if (!bitmap) {
|
||||
return nullptr;
|
||||
RefPtr<ID2D1SolidColorBrush> colBrush;
|
||||
mRT->CreateSolidColorBrush(D2D1::ColorF(0, 0), byRef(colBrush));
|
||||
return colBrush.forget();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -191,6 +191,11 @@ DrawTargetD2D1::DrawSurfaceWithShadow(SourceSurface *aSurface,
|
||||
Matrix mat;
|
||||
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, mat, ExtendMode::CLAMP);
|
||||
|
||||
if (!image) {
|
||||
gfxWarning() << "Couldn't get image for surface.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mat.IsIdentity()) {
|
||||
gfxDebug() << *this << ": At this point complex partial uploads are not supported for Shadow surfaces.";
|
||||
return;
|
||||
@ -264,12 +269,19 @@ DrawTargetD2D1::MaskSurface(const Pattern &aSource,
|
||||
Point aOffset,
|
||||
const DrawOptions &aOptions)
|
||||
{
|
||||
PrepareForDrawing(aOptions.mCompositionOp, aSource);
|
||||
MarkChanged();
|
||||
|
||||
RefPtr<ID2D1Bitmap> bitmap;
|
||||
|
||||
RefPtr<ID2D1Image> image = GetImageForSurface(aMask, ExtendMode::CLAMP);
|
||||
|
||||
if (!image) {
|
||||
gfxWarning() << "Failed to get image for surface.";
|
||||
return;
|
||||
}
|
||||
|
||||
PrepareForDrawing(aOptions.mCompositionOp, aSource);
|
||||
|
||||
// FillOpacityMask only works if the antialias mode is MODE_ALIASED
|
||||
mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
|
||||
|
||||
@ -305,6 +317,11 @@ DrawTargetD2D1::CopySurface(SourceSurface *aSurface,
|
||||
Matrix mat;
|
||||
RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, mat, ExtendMode::CLAMP);
|
||||
|
||||
if (!image) {
|
||||
gfxWarning() << "Couldn't get image for surface.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mat.IsIdentity()) {
|
||||
gfxDebug() << *this << ": At this point complex partial uploads are not supported for CopySurface.";
|
||||
return;
|
||||
@ -1256,6 +1273,11 @@ DrawTargetD2D1::CreateBrushForPattern(const Pattern &aPattern, Float aAlpha)
|
||||
|
||||
RefPtr<ID2D1ImageBrush> imageBrush;
|
||||
RefPtr<ID2D1Image> image = GetImageForSurface(pat->mSurface, mat, pat->mExtendMode, !pat->mSamplingRect.IsEmpty() ? &pat->mSamplingRect : nullptr);
|
||||
|
||||
if (!image) {
|
||||
return CreateTransparentBlackBrush();
|
||||
}
|
||||
|
||||
mDC->CreateImageBrush(image,
|
||||
D2D1::ImageBrushProperties(samplingBounds,
|
||||
D2DExtend(pat->mExtendMode),
|
||||
|
@ -629,14 +629,18 @@ CreatePartialBitmapForSurface(DataSourceSurface *aSurface, const Matrix &aDestin
|
||||
scaler.ScaleForSize(scaleSize);
|
||||
|
||||
IntSize newSize = scaler.GetSize();
|
||||
|
||||
if (newSize.IsEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
aRT->CreateBitmap(D2D1::SizeU(newSize.width, newSize.height),
|
||||
scaler.GetScaledData(), scaler.GetStride(),
|
||||
D2D1::BitmapProperties(D2DPixelFormat(aSurface->GetFormat())),
|
||||
byRef(bitmap));
|
||||
|
||||
aSourceTransform.PreScale(Float(size.width / newSize.width),
|
||||
Float(size.height / newSize.height));
|
||||
aSourceTransform.PreScale(Float(size.width) / newSize.width,
|
||||
Float(size.height) / newSize.height);
|
||||
return bitmap.forget();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user