From d47ec8dfc5cdfb8878121a3646f672674e3a69f5 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Tue, 14 Jul 2015 12:06:27 -0400 Subject: [PATCH] Bug 1182929 - Work around bug 803703 by refusing to turn heavily-downscaled images into image layers. r=seth --- layout/generic/nsImageFrame.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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