Bug 1118694 - Always retarget OnDataAvailable for RasterImage. r=sworkman
☠☠ backed out by 7967b585efe9 ☠ ☠
authorSeth Fowler <seth@mozilla.com>
Mon, 12 Jan 2015 01:29:23 -0800
changeset 249147 0b1b75d692bfbd52a5300e9f1beaf0df5155dfb8
parent 249146 14cc155b0d6ea19992a0950b8f5dd6c2c74851f4
child 249148 a15929ba55cdbbb56f9c8b23c71d09c5db410266
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs1118694
milestone37.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 1118694 - Always retarget OnDataAvailable for RasterImage. r=sworkman
image/src/ImageFactory.cpp
image/src/ImageFactory.h
image/src/RasterImage.cpp
image/src/RasterImage.h
image/src/imgRequest.cpp
--- a/image/src/ImageFactory.cpp
+++ b/image/src/ImageFactory.cpp
@@ -72,38 +72,16 @@ ComputeImageFlags(ImageURL* uri, bool is
   }
   if (isMultiPart) {
     imageFlags |= Image::INIT_FLAG_TRANSIENT;
   }
 
   return imageFlags;
 }
 
-/* static */ bool
-ImageFactory::CanRetargetOnDataAvailable(ImageURL* aURI, bool aIsMultiPart)
-{
-  // We can't retarget OnDataAvailable safely in cases where we aren't storing
-  // source data (and thus need to sync decode in ODA) because allocating frames
-  // off-main-thread is currently not possible and we don't have a workaround in
-  // place yet. (See bug 967985.) For now, we detect those cases and refuse to
-  // retarget. When the problem is fixed, this function can be removed.
-
-  if (aIsMultiPart) {
-    return false;
-  }
-
-  uint32_t imageFlags = ComputeImageFlags(aURI, aIsMultiPart);
-  if (!(imageFlags & Image::INIT_FLAG_DISCARDABLE) &&
-      !(imageFlags & Image::INIT_FLAG_DECODE_ON_DRAW)) {
-    return false;
-  }
-
-  return true;
-}
-
 /* static */ already_AddRefed<Image>
 ImageFactory::CreateImage(nsIRequest* aRequest,
                           ProgressTracker* aProgressTracker,
                           const nsCString& aMimeType,
                           ImageURL* aURI,
                           bool aIsMultiPart,
                           uint32_t aInnerWindowId)
 {
--- a/image/src/ImageFactory.h
+++ b/image/src/ImageFactory.h
@@ -24,24 +24,16 @@ class ImageFactory
 {
 public:
   /**
    * Registers vars with Preferences. Should only be called on the main thread.
    */
   static void Initialize();
 
   /**
-   * Determines whether it's safe to retarget OnDataAvailable for an image.
-   *
-   * @param aURI          The URI of the image.
-   * @param aIsMultipart  Whether the image is part of a multipart request.
-   */
-  static bool CanRetargetOnDataAvailable(ImageURL* aURI, bool aIsMultiPart);
-
-  /**
    * Creates a new image with the given properties.
    * Can be called on or off the main thread.
    *
    * @param aRequest         The associated request.
    * @param aProgressTracker A status tracker for the image to use.
    * @param aMimeType        The mimetype of the image.
    * @param aURI             The URI of the image.
    * @param aIsMultiPart     Whether the image is part of a multipart request.
--- a/image/src/RasterImage.cpp
+++ b/image/src/RasterImage.cpp
@@ -1170,22 +1170,16 @@ RasterImage::OnImageDataAvailable(nsIReq
 
   NS_ABORT_IF_FALSE(bytesRead == aCount || HasError() || NS_FAILED(rv),
     "WriteToSourceBuffer should consume everything if ReadSegments succeeds or "
     "the image must be in error!");
 
   return rv;
 }
 
-/* static */ already_AddRefed<nsIEventTarget>
-RasterImage::GetEventTarget()
-{
-  return DecodePool::Singleton()->GetEventTarget();
-}
-
 nsresult
 RasterImage::SetSourceSizeHint(uint32_t aSizeHint)
 {
   return mSourceBuffer->ExpectLength(aSizeHint);
 }
 
 /********* Methods to implement lazy allocation of nsIProperties object *************/
 NS_IMETHODIMP
--- a/image/src/RasterImage.h
+++ b/image/src/RasterImage.h
@@ -237,18 +237,16 @@ public:
                                         nsIInputStream* aInStr,
                                         uint64_t aSourceOffset,
                                         uint32_t aCount) MOZ_OVERRIDE;
   virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
                                        nsISupports* aContext,
                                        nsresult aStatus,
                                        bool aLastPart) MOZ_OVERRIDE;
 
-  static already_AddRefed<nsIEventTarget> GetEventTarget();
-
   /**
    * A hint of the number of bytes of source data that the image contains. If
    * called early on, this can help reduce copying and reallocations by
    * appropriately preallocating the source data buffer.
    *
    * We take this approach rather than having the source data management code do
    * something more complicated (like chunklisting) because HTTP is by far the
    * dominant source of images, and the Content-Length header is quite reliable.
--- a/image/src/imgRequest.cpp
+++ b/image/src/imgRequest.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "imgRequest.h"
 #include "ImageLogging.h"
 
 #include "imgLoader.h"
 #include "imgRequestProxy.h"
+#include "DecodePool.h"
 #include "ProgressTracker.h"
 #include "ImageFactory.h"
 #include "Image.h"
 #include "MultipartImage.h"
 #include "RasterImage.h"
 
 #include "nsIChannel.h"
 #include "nsICachingChannel.h"
@@ -689,24 +690,24 @@ NS_IMETHODIMP imgRequest::OnStartRequest
   if (progressTracker->ObserverCount() == 0) {
     this->Cancel(NS_IMAGELIB_ERROR_FAILURE);
   }
 
   // Try to retarget OnDataAvailable to a decode thread.
   nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest);
   nsCOMPtr<nsIThreadRetargetableRequest> retargetable =
     do_QueryInterface(aRequest);
-  if (httpChannel && retargetable &&
-      ImageFactory::CanRetargetOnDataAvailable(mURI, mIsMultiPartChannel)) {
+  if (httpChannel && retargetable) {
     nsAutoCString mimeType;
     nsresult rv = httpChannel->GetContentType(mimeType);
     if (NS_SUCCEEDED(rv) && !mimeType.EqualsLiteral(IMAGE_SVG_XML)) {
       // Image object not created until OnDataAvailable, so forward to static
       // DecodePool directly.
-      nsCOMPtr<nsIEventTarget> target = RasterImage::GetEventTarget();
+      nsCOMPtr<nsIEventTarget> target =
+        DecodePool::Singleton()->GetEventTarget();
       rv = retargetable->RetargetDeliveryTo(target);
     }
     PR_LOG(GetImgLog(), PR_LOG_WARNING,
            ("[this=%p] imgRequest::OnStartRequest -- "
             "RetargetDeliveryTo rv %d=%s\n",
             this, rv, NS_SUCCEEDED(rv) ? "succeeded" : "failed"));
   }