diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index ecb7a5f00cdc..d8df0809e515 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1430,7 +1430,35 @@ nsDisplayImage::CanOptimizeToImageLayer(LayerManager* aManager, ? imgIContainer::FLAG_SYNC_DECODE : imgIContainer::FLAG_NONE; - return mImage->IsImageContainerAvailable(aManager, flags); + if (!mImage->IsImageContainerAvailable(aManager, flags)) { + return false; + } + + int32_t imageWidth; + int32_t imageHeight; + mImage->GetWidth(&imageWidth); + mImage->GetHeight(&imageHeight); + + if (imageWidth == 0 || imageHeight == 0) { + NS_ASSERTION(false, "invalid image size"); + return false; + } + + const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel(); + const LayoutDeviceRect destRect = + LayoutDeviceRect::FromAppUnits(GetDestRect(), factor); + + // Calculate the scaling factor for the frame. + const gfxSize scale = gfxSize(destRect.width / imageWidth, + destRect.height / imageHeight); + + if (scale.width < 0.2 || scale.height < 0.2) { + // This would look awful as long as we can't use high-quality downscaling + // for image layers (bug 803703), so don't turn this into an image layer. + return false; + } + + return true; } already_AddRefed