Bug 1332005 - Remove opaque BGRA8 image surface optimization. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Wed, 18 Jan 2017 12:52:42 -0500
changeset 331470 0f9e64504f9a7d063e4a096605dd59ce3a50891e
parent 331469 9280d791dff29720d5a78b80da04c32be40bf5bf
child 331471 5186852360d6cf46ad5891b9e903fadcaa8c42c1
push id31273
push userphilringnalda@gmail.com
push dateSat, 28 Jan 2017 21:09:18 +0000
treeherdermozilla-central@e7b795db8b5b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1332005
milestone54.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 1332005 - Remove opaque BGRA8 image surface optimization. r=tnikkel
image/imgFrame.cpp
image/imgFrame.h
toolkit/components/telemetry/Histograms.json
--- a/image/imgFrame.cpp
+++ b/image/imgFrame.cpp
@@ -17,17 +17,16 @@
 #include "gfxAlphaRecovery.h"
 
 #include "GeckoProfiler.h"
 #include "MainThreadUtils.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/gfx/Tools.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MemoryReporting.h"
-#include "mozilla/Telemetry.h"
 #include "nsMargin.h"
 #include "nsThreadUtils.h"
 
 
 namespace mozilla {
 
 using namespace gfx;
 
@@ -160,17 +159,16 @@ static bool AllowedImageAndFrameDimensio
 
 imgFrame::imgFrame()
   : mMonitor("imgFrame")
   , mDecoded(0, 0, 0, 0)
   , mLockCount(0)
   , mTimeout(FrameTimeout::FromRawMilliseconds(100))
   , mDisposalMethod(DisposalMethod::NOT_SPECIFIED)
   , mBlendMethod(BlendMethod::OVER)
-  , mHasNoAlpha(false)
   , mAborted(false)
   , mFinished(false)
   , mOptimizable(false)
   , mPalettedImageData(nullptr)
   , mPaletteDepth(0)
   , mNonPremult(false)
   , mCompositingFailed(false)
 {
@@ -378,33 +376,16 @@ imgFrame::InitWithDrawable(gfxDrawable* 
 #ifdef DEBUG
   MonitorAutoLock lock(mMonitor);
   MOZ_ASSERT(AreAllPixelsWritten());
 #endif
 
   return NS_OK;
 }
 
-bool
-imgFrame::CanOptimizeOpaqueImage()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!ShutdownTracker::ShutdownHasStarted());
-  mMonitor.AssertCurrentThreadOwns();
-
-  // If we're using a surface format with alpha but the image has no alpha,
-  // change the format. This doesn't change the underlying data at all, but
-  // allows DrawTargets to avoid blending when drawing known opaque images.
-  // This optimization is free and safe, so we always do it when we can except
-  // if we have a Skia backend. Skia doesn't support RGBX so ensure we don't
-  // optimize to a RGBX surface.
-  return mHasNoAlpha && mFormat == SurfaceFormat::B8G8R8A8 && mImageSurface &&
-         (gfxPlatform::GetPlatform()->GetDefaultContentBackend() != BackendType::SKIA);
-}
-
 nsresult
 imgFrame::Optimize(DrawTarget* aTarget)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mMonitor.AssertCurrentThreadOwns();
   
   if (mLockCount > 0 || !mOptimizable) {
     // Don't optimize right now.
@@ -421,22 +402,16 @@ imgFrame::Optimize(DrawTarget* aTarget)
     hasCheckedOptimize = true;
   }
 
   // Don't optimize during shutdown because gfxPlatform may not be available.
   if (ShutdownTracker::ShutdownHasStarted()) {
     return NS_OK;
   }
 
-  // This optimization is basically free, so we perform it even if optimization is disabled.
-  if (CanOptimizeOpaqueImage()) {
-    mFormat = SurfaceFormat::B8G8R8X8;
-    mImageSurface = CreateLockedSurface(mVBuf, mFrameRect.Size(), mFormat);
-  }
-
   if (gDisableOptimize) {
     return NS_OK;
   }
 
   if (mPalettedImageData || mOptSurface) {
     return NS_OK;
   }
 
@@ -614,22 +589,16 @@ imgFrame::Finish(Opacity aFrameOpacity /
                  FrameTimeout aTimeout
                    /* = FrameTimeout::FromRawMilliseconds(0) */,
                  BlendMethod aBlendMethod /* = BlendMethod::OVER */,
                  const Maybe<IntRect>& aBlendRect /* = Nothing() */)
 {
   MonitorAutoLock lock(mMonitor);
   MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
 
-  if (aFrameOpacity == Opacity::FULLY_OPAQUE) {
-    mHasNoAlpha = true;
-    Telemetry::Accumulate(Telemetry::IMAGE_DECODE_OPAQUE_BGRA,
-                          mFormat == SurfaceFormat::B8G8R8A8);
-  }
-
   mDisposalMethod = aDisposalMethod;
   mTimeout = aTimeout;
   mBlendMethod = aBlendMethod;
   mBlendRect = aBlendRect;
   ImageUpdatedInternal(GetRect());
   mFinished = true;
 
   // The image is now complete, wake up anyone who's waiting.
--- a/image/imgFrame.h
+++ b/image/imgFrame.h
@@ -347,17 +347,16 @@ public:
                               size_t& aNonHeapSizeOut) const;
 
 private: // methods
 
   ~imgFrame();
 
   nsresult LockImageData();
   nsresult UnlockImageData();
-  bool     CanOptimizeOpaqueImage();
   nsresult Optimize(gfx::DrawTarget* aTarget);
 
   void AssertImageDataLocked() const;
 
   bool AreAllPixelsWritten() const;
   nsresult ImageUpdatedInternal(const nsIntRect& aUpdateRect);
   void GetImageDataInternal(uint8_t** aData, uint32_t* length) const;
   uint32_t GetImageBytesPerRow() const;
@@ -410,17 +409,16 @@ private: // data
   //! The timeout for this frame.
   FrameTimeout mTimeout;
 
   DisposalMethod mDisposalMethod;
   BlendMethod    mBlendMethod;
   Maybe<IntRect> mBlendRect;
   SurfaceFormat  mFormat;
 
-  bool mHasNoAlpha;
   bool mAborted;
   bool mFinished;
   bool mOptimizable;
 
 
   //////////////////////////////////////////////////////////////////////////////
   // Effectively const data, only mutated in the Init methods.
   //////////////////////////////////////////////////////////////////////////////
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -1341,23 +1341,16 @@
   },
   "IMAGE_DECODE_COUNT": {
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 500,
     "n_buckets": 50,
     "description": "Decode count"
   },
-  "IMAGE_DECODE_OPAQUE_BGRA": {
-    "alert_emails": ["aosmond@mozilla.com"],
-    "expires_in_version": "53",
-    "kind": "boolean",
-    "description": "Opaque images are BGRA",
-    "bug_numbers": [1311779]
-  },
   "IMAGE_DECODE_SPEED_JPEG": {
     "expires_in_version": "never",
     "kind": "exponential",
     "low": 500,
     "high": 50000000,
     "n_buckets": 50,
     "description": "JPEG image decode speed (Kbytes/sec)"
   },