Bug 1137019 (Part 2) - Replace imgRequest's image decoding methods with a single minimal method that updates an atomic. r=baku
authorSeth Fowler <seth@mozilla.com>
Mon, 23 Mar 2015 19:37:45 -0700
changeset 264068 97aacb3e7b80f2c3a8a4c36cce44f86df78dc7f5
parent 264067 3143c0a3e1a56972a0f06ff25a49111afabd3dfb
child 264069 88e94209b29bd50da93bd0500ae8c675ff8fb383
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1137019
milestone39.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 1137019 (Part 2) - Replace imgRequest's image decoding methods with a single minimal method that updates an atomic. r=baku
image/src/imgRequest.cpp
image/src/imgRequest.h
image/src/imgRequestProxy.cpp
--- a/image/src/imgRequest.cpp
+++ b/image/src/imgRequest.cpp
@@ -573,44 +573,16 @@ imgRequest::CacheChanged(nsIRequest* aNe
   }
 
   // When we get here, app caches differ or app cache is involved
   // just in one of the loads what we also consider as a change
   // in a loading cache.
   return true;
 }
 
-nsresult
-imgRequest::RequestDecode()
-{
-  // If we've initialized our image, we can request a decode.
-  if (mImage) {
-    return mImage->RequestDecode();
-  }
-
-  // Otherwise, flag to do it when we get the image
-  mDecodeRequested = true;
-
-  return NS_OK;
-}
-
-nsresult
-imgRequest::StartDecoding()
-{
-  // If we've initialized our image, we can request a decode.
-  if (mImage) {
-    return mImage->StartDecoding();
-  }
-
-  // Otherwise, flag to do it when we get the image
-  mDecodeRequested = true;
-
-  return NS_OK;
-}
-
 /** nsIRequestObserver methods **/
 
 /* void onStartRequest (in nsIRequest request, in nsISupports ctxt); */
 NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt)
 {
   LOG_SCOPE(GetImgLog(), "imgRequest::OnStartRequest");
 
   mNewPartPending = true;
--- a/image/src/imgRequest.h
+++ b/image/src/imgRequest.h
@@ -14,16 +14,17 @@
 #include "nsIPrincipal.h"
 
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsProxyRelease.h"
 #include "nsStringGlue.h"
 #include "nsError.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
+#include "mozilla/Atomics.h"
 #include "mozilla/net/ReferrerPolicy.h"
 
 class imgCacheValidator;
 class imgLoader;
 class imgRequestProxy;
 class imgCacheEntry;
 class imgMemoryReporter;
 class imgRequestNotifyRunnable;
@@ -82,20 +83,18 @@ public:
   void CancelAndAbort(nsresult aStatus);
 
   // Called or dispatched by cancel for main thread only execution.
   void ContinueCancel(nsresult aStatus);
 
   // Called or dispatched by EvictFromCache for main thread only execution.
   void ContinueEvict();
 
-  // Methods that get forwarded to the Image, or deferred until it's
-  // instantiated.
-  nsresult StartDecoding();
-  nsresult RequestDecode();
+  // Request that we start decoding the image as soon as data becomes available.
+  void RequestDecode() { mDecodeRequested = true; }
 
   inline void SetInnerWindowID(uint64_t aInnerWindowId) {
     mInnerWindowId = aInnerWindowId;
   }
 
   inline uint64_t InnerWindowID() const {
     return mInnerWindowId;
   }
@@ -257,19 +256,17 @@ private:
   // default, imgIRequest::CORS_NONE.
   int32_t mCORSMode;
 
   // The Referrer Policy (defined in ReferrerPolicy.h) used for this image.
   ReferrerPolicy mReferrerPolicy;
 
   nsresult mImageErrorCode;
 
-  // Sometimes consumers want to do things before the image is ready. Let them,
-  // and apply the action when the image becomes available.
-  bool mDecodeRequested : 1;
+  mozilla::Atomic<bool> mDecodeRequested;
 
   bool mIsMultiPartChannel : 1;
   bool mGotData : 1;
   bool mIsInCache : 1;
   bool mBlockingOnload : 1;
   bool mNewPartPending : 1;
 };
 
--- a/image/src/imgRequestProxy.cpp
+++ b/image/src/imgRequestProxy.cpp
@@ -219,18 +219,19 @@ nsresult imgRequestProxy::ChangeOwner(im
   // (see bug 601723).
   for (uint32_t i = 0; i < oldAnimationConsumers; i++)
     IncrementAnimationConsumers();
 
   GetOwner()->AddProxy(this);
 
   // If we were decoded, or if we'd previously requested a decode, request a
   // decode on the new image
-  if (wasDecoded || mDecodeRequested)
-    GetOwner()->StartDecoding();
+  if (wasDecoded || mDecodeRequested) {
+    StartDecoding();
+  }
 
   return NS_OK;
 }
 
 void imgRequestProxy::AddToLoadGroup()
 {
   NS_ASSERTION(!mIsInLoadGroup, "Whaa, we're already in the loadgroup!");
 
@@ -347,38 +348,48 @@ NS_IMETHODIMP imgRequestProxy::CancelAnd
 
   return NS_OK;
 }
 
 /* void startDecode (); */
 NS_IMETHODIMP
 imgRequestProxy::StartDecoding()
 {
-  if (!GetOwner())
-    return NS_ERROR_FAILURE;
-
   // Flag this, so we know to transfer the request if our owner changes
   mDecodeRequested = true;
 
-  // Forward the request
-  return GetOwner()->StartDecoding();
+  nsRefPtr<Image> image = GetImage();
+  if (image) {
+    return image->StartDecoding();
+  }
+
+  if (GetOwner()) {
+    GetOwner()->RequestDecode();
+  }
+
+  return NS_OK;
 }
 
 /* void requestDecode (); */
 NS_IMETHODIMP
 imgRequestProxy::RequestDecode()
 {
-  if (!GetOwner())
-    return NS_ERROR_FAILURE;
-
   // Flag this, so we know to transfer the request if our owner changes
   mDecodeRequested = true;
 
-  // Forward the request
-  return GetOwner()->RequestDecode();
+  nsRefPtr<Image> image = GetImage();
+  if (image) {
+    return image->RequestDecode();
+  }
+
+  if (GetOwner()) {
+    GetOwner()->RequestDecode();
+  }
+
+  return NS_OK;
 }
 
 
 /* void lockImage (); */
 NS_IMETHODIMP
 imgRequestProxy::LockImage()
 {
   mLockCount++;