Bug 1387325 - Part1. Refactor nsImageBoxFrame::PaintImage to make it easier to add WR support. r=mattwoodrow draft
authorEthan Lin <ethlin@mozilla.com>
Thu, 17 Aug 2017 14:45:21 +0800
changeset 648156 761a860b4a2d9bd1d6b36ea8260ccf4fbf69ebdc
parent 647355 9ab2470a3210324bc11320531b15d195aaf05051
child 648157 dbe9f22f7fdccbab206c16f74e6ef33946c3074f
push id74650
push userbmo:ethlin@mozilla.com
push dateThu, 17 Aug 2017 09:53:13 +0000
reviewersmattwoodrow
bugs1387325
milestone57.0a1
Bug 1387325 - Part1. Refactor nsImageBoxFrame::PaintImage to make it easier to add WR support. r=mattwoodrow MozReview-Commit-ID: AmHPifpVAHZ
layout/xul/nsImageBoxFrame.cpp
layout/xul/nsImageBoxFrame.h
--- a/layout/xul/nsImageBoxFrame.cpp
+++ b/layout/xul/nsImageBoxFrame.cpp
@@ -337,42 +337,63 @@ nsImageBoxFrame::BuildDisplayList(nsDisp
   list.AppendNewToTop(
     new (aBuilder) nsDisplayXULImage(aBuilder, this));
 
   CreateOwnLayerIfNeeded(aBuilder, &list);
 
   aLists.Content()->AppendToTop(&list);
 }
 
-DrawResult
-nsImageBoxFrame::PaintImage(gfxContext& aRenderingContext,
-                            const nsRect& aDirtyRect, nsPoint aPt,
-                            uint32_t aFlags)
+already_AddRefed<imgIContainer>
+nsImageBoxFrame::GetImageContainerForPainting(const nsPoint& aPt,
+                                              DrawResult& aDrawResult,
+                                              Maybe<nsPoint>& aAnchorPoint,
+                                              nsRect& aDest)
 {
   if (!mImageRequest) {
     // This probably means we're drawn by a native theme.
-    return DrawResult::SUCCESS;
+    aDrawResult = DrawResult::SUCCESS;
+    return nullptr;
   }
 
   // Don't draw if the image's size isn't available.
   uint32_t imgStatus;
   if (!NS_SUCCEEDED(mImageRequest->GetImageStatus(&imgStatus)) ||
       !(imgStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) {
-    return DrawResult::NOT_READY;
+    aDrawResult = DrawResult::NOT_READY;
+    return nullptr;
   }
 
   nsCOMPtr<imgIContainer> imgCon;
   mImageRequest->GetImage(getter_AddRefs(imgCon));
 
   if (!imgCon) {
-    return DrawResult::NOT_READY;
+    aDrawResult = DrawResult::NOT_READY;
+    return nullptr;
   }
 
+  aDest = GetDestRect(aPt, aAnchorPoint);
+  aDrawResult = DrawResult::SUCCESS;
+  return imgCon.forget();
+}
+
+DrawResult
+nsImageBoxFrame::PaintImage(gfxContext& aRenderingContext,
+                            const nsRect& aDirtyRect, nsPoint aPt,
+                            uint32_t aFlags)
+{
+  DrawResult result;
   Maybe<nsPoint> anchorPoint;
-  nsRect dest = GetDestRect(aPt, anchorPoint);
+  nsRect dest;
+  nsCOMPtr<imgIContainer> imgCon = GetImageContainerForPainting(aPt, result,
+                                                                anchorPoint,
+                                                                dest);
+  if (!imgCon) {
+    return result;
+  }
 
   // don't draw if the image is not dirty
   // XXX(seth): Can this actually happen anymore?
   nsRect dirty;
   if (!dirty.IntersectRect(aDirtyRect, dest)) {
     return DrawResult::TEMPORARY_ERROR;
   }
 
--- a/layout/xul/nsImageBoxFrame.h
+++ b/layout/xul/nsImageBoxFrame.h
@@ -85,16 +85,21 @@ public:
    */
   void UpdateLoadFlags();
 
   virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                 const nsDisplayListSet& aLists) override;
 
   virtual ~nsImageBoxFrame();
 
+  already_AddRefed<imgIContainer> GetImageContainerForPainting(const nsPoint& aPt,
+                                                               DrawResult& aDrawResult,
+                                                               Maybe<nsPoint>& aAnchorPoint,
+                                                               nsRect& aDest);
+
   DrawResult PaintImage(gfxContext& aRenderingContext,
                         const nsRect& aDirtyRect,
                         nsPoint aPt, uint32_t aFlags);
 
   bool CanOptimizeToImageLayer();
 
   nsRect GetDestRect(const nsPoint& aOffset, Maybe<nsPoint>& aAnchorPoint);