Bug 1490938. Pass the high quality scaling flag when we request decode of images in most cases. r=aosmond
authorTimothy Nikkel <tnikkel@gmail.com>
Thu, 27 Sep 2018 18:30:17 -0500
changeset 439148 912ad8891041d872998e36a7090ea60246310ceb
parent 439147 e25673baab2319936db94f1111ac1f6c2d0529f0
child 439149 90003e4c4f3a7dd9aa624371516d13340a05bed9
push id34757
push userrgurzau@mozilla.com
push dateTue, 02 Oct 2018 16:04:13 +0000
treeherdermozilla-central@17c314f6930d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaosmond
bugs1490938
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1490938. Pass the high quality scaling flag when we request decode of images in most cases. r=aosmond If we do not pass the high quality scaling flag than the resulting surface will be marked as cannot substitute, which is not accurate, so we don't want. The only place that actually tries to be smart about the size is nsImageFrame::MaybeDecodeForPredictedSize. All other cases just ask for the intrinsic size. The two most likely cases are that there are no decoded copies of the image, or there is one decoded (or in progress) copy of the image. In the first case we will request decode at the instrinsic size, and then if we draw at a different size that draw will request the proper size. This doesn't change with this patch. In the second case there is a decoded copy already available, this is likely from a draw call on the image, and that is the surface size that we want. So we save a decode. If we are actually drawing the image at two different sizes the second size will be slightly delayed, but we have the wrongly sized copy of the image that we can draw until then. This seems like a good tradeoff to avoid always decoding an instrinic size copy of images.
image/MultipartImage.cpp
image/RasterImage.cpp
layout/generic/nsBulletFrame.cpp
layout/generic/nsImageFrame.cpp
toolkit/components/alerts/AlertNotification.cpp
widget/cocoa/nsMenuItemIconX.mm
--- a/image/MultipartImage.cpp
+++ b/image/MultipartImage.cpp
@@ -77,17 +77,18 @@ public:
     // Retrieve the image's intrinsic size.
     int32_t width = 0;
     int32_t height = 0;
     mImage->GetWidth(&width);
     mImage->GetHeight(&height);
 
     // Request decoding at the intrinsic size.
     mImage->RequestDecodeForSize(IntSize(width, height),
-                                 imgIContainer::DECODE_FLAGS_DEFAULT);
+                                 imgIContainer::DECODE_FLAGS_DEFAULT |
+                                 imgIContainer::FLAG_HIGH_QUALITY_SCALING);
 
     // If there's already an error, we may never get a FRAME_COMPLETE
     // notification, so go ahead and notify our owner right away.
     RefPtr<ProgressTracker> tracker = mImage->GetProgressTracker();
     if (tracker->GetProgress() & FLAG_HAS_ERROR) {
       FinishObserving();
     }
   }
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1131,33 +1131,35 @@ RasterImage::StartDecoding(uint32_t aFla
     return NS_ERROR_FAILURE;
   }
 
   if (!mHasSize) {
     mWantFullDecode = true;
     return NS_OK;
   }
 
-  uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST;
+  uint32_t flags =
+    (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST | FLAG_HIGH_QUALITY_SCALING;
   return RequestDecodeForSize(mSize, flags);
 }
 
 bool
 RasterImage::StartDecodingWithResult(uint32_t aFlags)
 {
   if (mError) {
     return false;
   }
 
   if (!mHasSize) {
     mWantFullDecode = true;
     return false;
   }
 
-  uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST;
+  uint32_t flags =
+    (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST | FLAG_HIGH_QUALITY_SCALING;
   DrawableSurface surface = RequestDecodeForSizeInternal(mSize, flags);
   return surface && surface->IsFinished();
 }
 
 NS_IMETHODIMP
 RasterImage::RequestDecodeForSize(const IntSize& aSize, uint32_t aFlags)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -1809,17 +1811,17 @@ RasterImage::NotifyDecodeComplete(const 
     if (mLoadProgress) {
       NotifyForLoadEvent(*mLoadProgress);
       mLoadProgress = Nothing();
     }
 
     // If we were a metadata decode and a full decode was requested, do it.
     if (mWantFullDecode) {
       mWantFullDecode = false;
-      RequestDecodeForSize(mSize, DECODE_FLAGS_DEFAULT);
+      RequestDecodeForSize(mSize, DECODE_FLAGS_DEFAULT | FLAG_HIGH_QUALITY_SCALING);
     }
   }
 }
 
 void
 RasterImage::ReportDecoderError()
 {
   nsCOMPtr<nsIConsoleService> consoleService =
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -1181,17 +1181,18 @@ nsBulletFrame::Notify(imgIRequest *aRequ
       // Retrieve the intrinsic size of the image.
       int32_t width = 0;
       int32_t height = 0;
       container->GetWidth(&width);
       container->GetHeight(&height);
 
       // Request a decode at that size.
       container->RequestDecodeForSize(IntSize(width, height),
-                                      imgIContainer::DECODE_FLAGS_DEFAULT);
+                                      imgIContainer::DECODE_FLAGS_DEFAULT |
+                                      imgIContainer::FLAG_HIGH_QUALITY_SCALING);
     }
 
     InvalidateFrame();
   }
 
   if (aType == imgINotificationObserver::DECODE_COMPLETE) {
     if (nsIDocument* parent = GetOurCurrentDoc()) {
       nsCOMPtr<imgIContainer> container;
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -2553,17 +2553,18 @@ nsImageFrame::IconLoad::Notify(imgIReque
     // Retrieve the image's intrinsic size.
     int32_t width = 0;
     int32_t height = 0;
     image->GetWidth(&width);
     image->GetHeight(&height);
 
     // Request a decode at that size.
     image->RequestDecodeForSize(IntSize(width, height),
-                                imgIContainer::DECODE_FLAGS_DEFAULT);
+                                imgIContainer::DECODE_FLAGS_DEFAULT |
+                                imgIContainer::FLAG_HIGH_QUALITY_SCALING);
   }
 
   nsTObserverArray<nsImageFrame*>::ForwardIterator iter(mIconObservers);
   nsImageFrame *frame;
   while (iter.HasMore()) {
     frame = iter.GetNext();
     frame->InvalidateFrame();
   }
--- a/toolkit/components/alerts/AlertNotification.cpp
+++ b/toolkit/components/alerts/AlertNotification.cpp
@@ -246,17 +246,18 @@ AlertImageRequest::Notify(imgIRequest* a
       if (NS_WARN_IF(NS_FAILED(rv) || !image)) {
         return NotifyMissing();
       }
 
       // Ask the image to decode at its intrinsic size.
       int32_t width = 0, height = 0;
       image->GetWidth(&width);
       image->GetHeight(&height);
-      image->RequestDecodeForSize(gfx::IntSize(width, height), imgIContainer::FLAG_NONE);
+      image->RequestDecodeForSize(gfx::IntSize(width, height),
+                                  imgIContainer::FLAG_HIGH_QUALITY_SCALING);
     }
     return NS_OK;
   }
 
   if (aType == imgINotificationObserver::FRAME_COMPLETE) {
     return NotifyComplete();
   }
 
--- a/widget/cocoa/nsMenuItemIconX.mm
+++ b/widget/cocoa/nsMenuItemIconX.mm
@@ -284,17 +284,18 @@ nsMenuItemIconX::Notify(imgIRequest* aRe
     nsCOMPtr<imgIContainer> image;
     aRequest->GetImage(getter_AddRefs(image));
     MOZ_ASSERT(image);
 
     // Ask the image to decode at its intrinsic size.
     int32_t width = 0, height = 0;
     image->GetWidth(&width);
     image->GetHeight(&height);
-    image->RequestDecodeForSize(nsIntSize(width, height), imgIContainer::FLAG_NONE);
+    image->RequestDecodeForSize(nsIntSize(width, height),
+                                imgIContainer::FLAG_HIGH_QUALITY_SCALING);
   }
 
   if (aType == imgINotificationObserver::FRAME_COMPLETE) {
     return OnFrameComplete(aRequest);
   }
 
   if (aType == imgINotificationObserver::DECODE_COMPLETE) {
     if (mIconRequest && mIconRequest == aRequest) {