Bug 1312770 - Part 3, increase loading priority for images that are visible in viewport. r?tnikkel draft
authorShih-Chiang Chien <schien@mozilla.com>
Tue, 21 Mar 2017 09:51:35 +0800
changeset 501867 6dd03d02996448b5b7e7a410a97b5106f2ea7fc2
parent 501866 13e9755bd62bccb6764e645defcab3d0734dc134
child 550020 d54c19976fefa3d381b910208c99083813fe1ab7
push id50136
push userbmo:schien@mozilla.com
push dateTue, 21 Mar 2017 02:23:02 +0000
reviewerstnikkel
bugs1312770
milestone55.0a1
Bug 1312770 - Part 3, increase loading priority for images that are visible in viewport. r?tnikkel MozReview-Commit-ID: EsKRyMzZCKc
layout/generic/nsImageFrame.cpp
layout/generic/nsImageFrame.h
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -1783,16 +1783,24 @@ nsImageFrame::BuildDisplayList(nsDisplay
       // decoded yet. And we are not going to ask the image to draw, so this
       // may be the only chance to tell it that it should decode.
       if (currentRequest) {
         uint32_t status = 0;
         currentRequest->GetImageStatus(&status);
         if (!(status & imgIRequest::STATUS_DECODE_COMPLETE)) {
           MaybeDecodeForPredictedSize();
         }
+
+        // Increase loading priority if the image is ready to be displayed.
+        if (!(status & imgIRequest::STATUS_LOAD_COMPLETE) &&
+            !mBoostLoadingForDisplay) {
+          mBoostLoadingForDisplay = true;
+          currentRequest->ForceAdjustPriority(nsISupportsPriority::PRIORITY_HIGH);
+        }
+
       }
     } else {
       aLists.Content()->AppendNewToTop(new (aBuilder)
         nsDisplayImage(aBuilder, this, mImage, mPrevImage));
 
       // If we were previously displaying an icon, we're not anymore
       if (mDisplayingIcon) {
         gIconLoad->RemoveIconObserver(this);
--- a/layout/generic/nsImageFrame.h
+++ b/layout/generic/nsImageFrame.h
@@ -335,16 +335,19 @@ private:
   mozilla::IntrinsicSize mIntrinsicSize;
   nsSize mIntrinsicRatio;
 
   bool mDisplayingIcon;
   bool mFirstFrameComplete;
   bool mReflowCallbackPosted;
   bool mForceSyncDecoding;
 
+  // True if image has increased loading priority for rendering
+  bool mBoostLoadingForDisplay = false;
+
   static nsIIOService* sIOService;
   
   /* loading / broken image icon support */
 
   // XXXbz this should be handled by the prescontext, I think; that
   // way we would have a single iconload per mozilla session instead
   // of one per document...