Backed out 3 changesets (bug 1594425) for failures on SwizzleSSE2.cpp. CLOSED TREE
authorCsoregi Natalia <ncsoregi@mozilla.com>
Fri, 08 Nov 2019 22:52:02 +0200
changeset 501357 75a3afcd0b4ffb432805b33bfd7ea82969fb0d20
parent 501356 23e460d5c0212fc7999cd5055841ce7d2055a146
child 501358 f9f1ad5a1dfa732bfbdc099db1cf5f7e1f931773
push id114168
push userdluca@mozilla.com
push dateSun, 10 Nov 2019 03:08:55 +0000
treeherdermozilla-inbound@33f64c1ef3e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1594425
milestone72.0a1
backs out90ce21e7e469a6418e2d964aba45bbfe26e9e8fa
54a28220958bbe934eafd7063fa1ed1c046ed54d
f1c1e5f12327eee77905e9b6456e667d548b6c0e
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
Backed out 3 changesets (bug 1594425) for failures on SwizzleSSE2.cpp. CLOSED TREE Backed out changeset 90ce21e7e469 (bug 1594425) Backed out changeset 54a28220958b (bug 1594425) Backed out changeset f1c1e5f12327 (bug 1594425)
gfx/thebes/gfxColor.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
image/ClippedImage.cpp
image/DownscalingFilter.h
image/DynamicImage.cpp
image/OrientedImage.cpp
image/SurfacePipeFactory.h
image/VectorImage.cpp
image/decoders/icon/android/nsIconChannel.cpp
image/decoders/icon/gtk/nsIconChannel.cpp
image/decoders/icon/mac/nsIconChannelCocoa.mm
image/decoders/nsBMPDecoder.cpp
image/decoders/nsGIFDecoder2.cpp
image/decoders/nsICODecoder.cpp
image/decoders/nsIconDecoder.cpp
image/decoders/nsJPEGDecoder.cpp
image/decoders/nsPNGDecoder.cpp
image/decoders/nsWebPDecoder.cpp
image/imgFrame.cpp
image/imgFrame.h
image/test/fuzzing/TestDecoders.cpp
image/test/gtest/Common.cpp
image/test/gtest/Common.h
image/test/gtest/TestADAM7InterpolatingFilter.cpp
image/test/gtest/TestAnimationFrameBuffer.cpp
image/test/gtest/TestBlendAnimationFilter.cpp
image/test/gtest/TestDecodeToSurface.cpp
image/test/gtest/TestDecoders.cpp
image/test/gtest/TestDecodersPerf.cpp
image/test/gtest/TestDeinterlacingFilter.cpp
image/test/gtest/TestDownscalingFilter.cpp
image/test/gtest/TestDownscalingFilterNoSkia.cpp
image/test/gtest/TestRemoveFrameRectFilter.cpp
image/test/gtest/TestSurfacePipeIntegration.cpp
image/test/gtest/TestSurfaceSink.cpp
image/test/gtest/downscaled.icon
image/test/gtest/green.icon
--- a/gfx/thebes/gfxColor.h
+++ b/gfx/thebes/gfxColor.h
@@ -1,18 +1,18 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #ifndef GFX_COLOR_H
 #define GFX_COLOR_H
 
-#include "mozilla/Attributes.h"  // for MOZ_ALWAYS_INLINE
-#include "mozilla/gfx/Types.h"   // for mozilla::gfx::SurfaceFormatBit
+#include "mozilla/Attributes.h"   // for MOZ_ALWAYS_INLINE
+#include "mozilla/EndianUtils.h"  // for mozilla::NativeEndian::swapToBigEndian
 
 /**
  * Fast approximate division by 255. It has the property that
  * for all 0 <= n <= 255*255, GFX_DIVIDE_BY_255(n) == n/255.
  * But it only uses two adds and two shifts instead of an
  * integer division (which is expensive on many processors).
  *
  * equivalent to ((v)/255)
@@ -30,33 +30,28 @@ uint8_t MOZ_ALWAYS_INLINE gfxPreMultiply
 }
 
 /**
  * Pack the 4 8-bit channels (A,R,G,B)
  * into a 32-bit packed NON-premultiplied pixel.
  */
 uint32_t MOZ_ALWAYS_INLINE gfxPackedPixelNoPreMultiply(uint8_t a, uint8_t r,
                                                        uint8_t g, uint8_t b) {
-  return (((a) << mozilla::gfx::SurfaceFormatBit::OS_A) |
-          ((r) << mozilla::gfx::SurfaceFormatBit::OS_R) |
-          ((g) << mozilla::gfx::SurfaceFormatBit::OS_G) |
-          ((b) << mozilla::gfx::SurfaceFormatBit::OS_B));
+  return (((a) << 24) | ((r) << 16) | ((g) << 8) | (b));
 }
 
 /**
  * Pack the 4 8-bit channels (A,R,G,B)
  * into a 32-bit packed premultiplied pixel.
  */
 uint32_t MOZ_ALWAYS_INLINE gfxPackedPixel(uint8_t a, uint8_t r, uint8_t g,
                                           uint8_t b) {
   if (a == 0x00)
     return 0x00000000;
   else if (a == 0xFF) {
     return gfxPackedPixelNoPreMultiply(a, r, g, b);
   } else {
-    return ((a) << mozilla::gfx::SurfaceFormatBit::OS_A) |
-           (gfxPreMultiply(r, a) << mozilla::gfx::SurfaceFormatBit::OS_R) |
-           (gfxPreMultiply(g, a) << mozilla::gfx::SurfaceFormatBit::OS_G) |
-           (gfxPreMultiply(b, a) << mozilla::gfx::SurfaceFormatBit::OS_B);
+    return ((a) << 24) | (gfxPreMultiply(r, a) << 16) |
+           (gfxPreMultiply(g, a) << 8) | (gfxPreMultiply(b, a));
   }
 }
 
 #endif /* _GFX_COLOR_H */
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -2190,40 +2190,16 @@ qcms_transform* gfxPlatform::GetCMSBGRAT
     gCMSBGRATransform =
         qcms_transform_create(inProfile, QCMS_DATA_BGRA_8, outProfile,
                               QCMS_DATA_BGRA_8, QCMS_INTENT_PERCEPTUAL);
   }
 
   return gCMSBGRATransform;
 }
 
-qcms_transform* gfxPlatform::GetCMSOSRGBATransform() {
-  switch (SurfaceFormat::OS_RGBA) {
-    case SurfaceFormat::B8G8R8A8:
-      return GetCMSBGRATransform();
-    case SurfaceFormat::R8G8B8A8:
-      return GetCMSRGBATransform();
-    default:
-      // We do not support color management with big endian.
-      return nullptr;
-  }
-}
-
-qcms_data_type gfxPlatform::GetCMSOSRGBAType() {
-  switch (SurfaceFormat::OS_RGBA) {
-    case SurfaceFormat::B8G8R8A8:
-      return QCMS_DATA_BGRA_8;
-    case SurfaceFormat::R8G8B8A8:
-      return QCMS_DATA_RGBA_8;
-    default:
-      // We do not support color management with big endian.
-      return QCMS_DATA_RGBA_8;
-  }
-}
-
 /* Shuts down various transforms and profiles for CMS. */
 static void ShutdownCMS() {
   if (gCMSRGBTransform) {
     qcms_transform_release(gCMSRGBTransform);
     gCMSRGBTransform = nullptr;
   }
   if (gCMSInverseRGBTransform) {
     qcms_transform_release(gCMSInverseRGBTransform);
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -541,30 +541,20 @@ class gfxPlatform : public mozilla::laye
   static qcms_transform* GetCMSInverseRGBTransform();
 
   /**
    * Return sRGBA -> output device transform.
    */
   static qcms_transform* GetCMSRGBATransform();
 
   /**
-   * Return sBGRA -> output device transform.
+   * Return sRGBA -> output device transform.
    */
   static qcms_transform* GetCMSBGRATransform();
 
-  /**
-   * Return OS RGBA -> output device transform.
-   */
-  static qcms_transform* GetCMSOSRGBATransform();
-
-  /**
-   * Return OS RGBA QCMS type.
-   */
-  static qcms_data_type GetCMSOSRGBAType();
-
   virtual void FontsPrefsChanged(const char* aPref);
 
   int32_t GetBidiNumeralOption();
 
   /**
    * This is a bit ugly, but useful... force all presContexts to reflow,
    * by toggling a preference that they observe. This is used when
    * something about platform settings changes that might have an effect
--- a/image/ClippedImage.cpp
+++ b/image/ClippedImage.cpp
@@ -250,17 +250,17 @@ Pair<ImgDrawResult, RefPtr<SourceSurface
 
   float frameToDraw = InnerImage()->GetFrameIndex(aWhichFrame);
   if (!mCachedSurface ||
       !mCachedSurface->Matches(aSize, aSVGContext, frameToDraw, aFlags) ||
       mCachedSurface->NeedsRedraw()) {
     // Create a surface to draw into.
     RefPtr<DrawTarget> target =
         gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
-            IntSize(aSize.width, aSize.height), SurfaceFormat::OS_RGBA);
+            IntSize(aSize.width, aSize.height), SurfaceFormat::B8G8R8A8);
     if (!target || !target->IsValid()) {
       NS_ERROR("Could not create a DrawTarget");
       return MakePair(ImgDrawResult::TEMPORARY_ERROR, RefPtr<SourceSurface>());
     }
 
     RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(target);
     MOZ_ASSERT(ctx);  // already checked the draw target above
 
@@ -269,17 +269,17 @@ Pair<ImgDrawResult, RefPtr<SourceSurface
         new DrawSingleTileCallback(this, aSize, aSVGContext, aWhichFrame,
                                    aFlags, aOpacity);
     RefPtr<gfxDrawable> drawable =
         new gfxCallbackDrawable(drawTileCallback, aSize);
 
     // Actually draw. The callback will end up invoking DrawSingleTile.
     gfxUtils::DrawPixelSnapped(ctx, drawable, SizeDouble(aSize),
                                ImageRegion::Create(aSize),
-                               SurfaceFormat::OS_RGBA, SamplingFilter::LINEAR,
+                               SurfaceFormat::B8G8R8A8, SamplingFilter::LINEAR,
                                imgIContainer::FLAG_CLAMP);
 
     // Cache the resulting surface.
     mCachedSurface = MakeUnique<ClippedImageCachedSurface>(
         target->Snapshot(), aSize, aSVGContext, frameToDraw, aFlags,
         drawTileCallback->GetDrawResult());
   }
 
@@ -380,17 +380,17 @@ ClippedImage::Draw(gfxContext* aContext,
     }
 
     // Create a drawable from that surface.
     RefPtr<gfxSurfaceDrawable> drawable =
         new gfxSurfaceDrawable(surface, aSize);
 
     // Draw.
     gfxUtils::DrawPixelSnapped(aContext, drawable, SizeDouble(aSize), aRegion,
-                               SurfaceFormat::OS_RGBA, aSamplingFilter,
+                               SurfaceFormat::B8G8R8A8, aSamplingFilter,
                                aOpacity);
 
     return result;
   }
 
   return DrawSingleTile(aContext, aSize, aRegion, aWhichFrame, aSamplingFilter,
                         aSVGContext, aFlags, aOpacity);
 }
--- a/image/DownscalingFilter.h
+++ b/image/DownscalingFilter.h
@@ -131,17 +131,17 @@ class DownscalingFilter final : public S
       NS_WARNING("Invalid input size for DownscalingFilter");
       return NS_ERROR_INVALID_ARG;
     }
 
     mInputSize = aConfig.mInputSize;
     gfx::IntSize outputSize = mNext.InputSize();
     mScale = gfxSize(double(mInputSize.width) / outputSize.width,
                      double(mInputSize.height) / outputSize.height);
-    mHasAlpha = aConfig.mFormat == gfx::SurfaceFormat::OS_RGBA;
+    mHasAlpha = aConfig.mFormat == gfx::SurfaceFormat::B8G8R8A8;
 
     ReleaseWindow();
 
     auto resizeMethod = gfx::ConvolutionFilter::ResizeMethod::LANCZOS3;
     if (!mXFilter.ComputeResizeFilter(resizeMethod, mInputSize.width,
                                       outputSize.width) ||
         !mYFilter.ComputeResizeFilter(resizeMethod, mInputSize.height,
                                       outputSize.height)) {
--- a/image/DynamicImage.cpp
+++ b/image/DynamicImage.cpp
@@ -136,17 +136,17 @@ DynamicImage::GetFrame(uint32_t aWhichFr
   return GetFrameAtSize(IntSize(size.width, size.height), aWhichFrame, aFlags);
 }
 
 NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
 DynamicImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
                              uint32_t aFlags) {
   RefPtr<DrawTarget> dt =
       gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
-          aSize, SurfaceFormat::OS_RGBA);
+          aSize, SurfaceFormat::B8G8R8A8);
   if (!dt || !dt->IsValid()) {
     gfxWarning()
         << "DynamicImage::GetFrame failed in CreateOffscreenContentDrawTarget";
     return nullptr;
   }
   RefPtr<gfxContext> context = gfxContext::CreateOrNull(dt);
   MOZ_ASSERT(context);  // already checked the draw target above
 
@@ -193,32 +193,32 @@ DynamicImage::Draw(gfxContext* aContext,
                    const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
                    float aOpacity) {
   MOZ_ASSERT(!aSize.IsEmpty(), "Unexpected empty size");
 
   IntSize drawableSize(mDrawable->Size());
 
   if (aSize == drawableSize) {
     gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize),
-                               aRegion, SurfaceFormat::OS_RGBA, aSamplingFilter,
-                               aOpacity);
+                               aRegion, SurfaceFormat::B8G8R8A8,
+                               aSamplingFilter, aOpacity);
     return ImgDrawResult::SUCCESS;
   }
 
   gfxSize scale(double(aSize.width) / drawableSize.width,
                 double(aSize.height) / drawableSize.height);
 
   ImageRegion region(aRegion);
   region.Scale(1.0 / scale.width, 1.0 / scale.height);
 
   gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
   aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
 
   gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize),
-                             region, SurfaceFormat::OS_RGBA, aSamplingFilter,
+                             region, SurfaceFormat::B8G8R8A8, aSamplingFilter,
                              aOpacity);
   return ImgDrawResult::SUCCESS;
 }
 
 NS_IMETHODIMP
 DynamicImage::StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) {
   return NS_OK;
 }
--- a/image/OrientedImage.cpp
+++ b/image/OrientedImage.cpp
@@ -88,19 +88,19 @@ OrientedImage::GetFrame(uint32_t aWhichF
   rv = InnerImage()->GetWidth(&size.width);
   NS_ENSURE_SUCCESS(rv, nullptr);
   rv = InnerImage()->GetHeight(&size.height);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   // Determine an appropriate format for the surface.
   gfx::SurfaceFormat surfaceFormat;
   if (InnerImage()->WillDrawOpaqueNow()) {
-    surfaceFormat = gfx::SurfaceFormat::OS_RGBX;
+    surfaceFormat = gfx::SurfaceFormat::B8G8R8X8;
   } else {
-    surfaceFormat = gfx::SurfaceFormat::OS_RGBA;
+    surfaceFormat = gfx::SurfaceFormat::B8G8R8A8;
   }
 
   // Create a surface to draw into.
   RefPtr<DrawTarget> target =
       gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
           size, surfaceFormat);
   if (!target || !target->IsValid()) {
     NS_ERROR("Could not create a DrawTarget");
--- a/image/SurfacePipeFactory.h
+++ b/image/SurfacePipeFactory.h
@@ -102,50 +102,45 @@ class SurfacePipeFactory {
     const bool downscale = aInputSize != aOutputSize;
     const bool removeFrameRect = !aFrameRect.IsEqualEdges(
         nsIntRect(0, 0, aInputSize.width, aInputSize.height));
     const bool blendAnimation = aAnimParams.isSome();
     const bool colorManagement = aTransform != nullptr;
     const bool premultiplyAlpha =
         bool(aFlags & SurfacePipeFlags::PREMULTIPLY_ALPHA);
 
+    // Early swizzles are for unpacking RGB or forcing RGBA/BGRA to RGBX/BGRX.
+    // We should never want to premultiply in either case, because the image's
+    // alpha channel will always be opaque. This must be done before downscaling
+    // and color management.
+    bool unpackOrMaskSwizzle = aInFormat == gfx::SurfaceFormat::R8G8B8 ||
+                               ((aInFormat == gfx::SurfaceFormat::R8G8B8A8 &&
+                                 aOutFormat == gfx::SurfaceFormat::R8G8B8X8) ||
+                                (aInFormat == gfx::SurfaceFormat::B8G8R8A8 &&
+                                 aOutFormat == gfx::SurfaceFormat::B8G8R8X8));
+
+    // Late swizzles are for premultiplying RGBA/BGRA and/or possible converting
+    // between RGBA and BGRA. It must happen after color management, and before
+    // downscaling.
+    bool swapOrAlphaSwizzle = ((aInFormat == gfx::SurfaceFormat::R8G8B8A8 &&
+                                aOutFormat == gfx::SurfaceFormat::B8G8R8A8) ||
+                               (aInFormat == gfx::SurfaceFormat::B8G8R8A8 &&
+                                aOutFormat == gfx::SurfaceFormat::R8G8B8A8)) ||
+                              premultiplyAlpha;
+
     MOZ_ASSERT(aInFormat == gfx::SurfaceFormat::R8G8B8 ||
                aInFormat == gfx::SurfaceFormat::R8G8B8A8 ||
                aInFormat == gfx::SurfaceFormat::R8G8B8X8 ||
-               aInFormat == gfx::SurfaceFormat::OS_RGBA ||
-               aInFormat == gfx::SurfaceFormat::OS_RGBX);
-
-    MOZ_ASSERT(aOutFormat == gfx::SurfaceFormat::OS_RGBA ||
-               aOutFormat == gfx::SurfaceFormat::OS_RGBX);
-
-    const bool inFormatRgb = aInFormat == gfx::SurfaceFormat::R8G8B8;
-
-    const bool inFormatOpaque = aInFormat == gfx::SurfaceFormat::OS_RGBX ||
-                                aInFormat == gfx::SurfaceFormat::R8G8B8X8 ||
-                                inFormatRgb;
-    const bool outFormatOpaque = aOutFormat == gfx::SurfaceFormat::OS_RGBX;
+               aInFormat == gfx::SurfaceFormat::B8G8R8A8 ||
+               aInFormat == gfx::SurfaceFormat::B8G8R8X8);
 
-    const bool inFormatOrder = aInFormat == gfx::SurfaceFormat::R8G8B8A8 ||
-                               aInFormat == gfx::SurfaceFormat::R8G8B8X8;
-    const bool outFormatOrder = aOutFormat == gfx::SurfaceFormat::R8G8B8A8 ||
-                                aOutFormat == gfx::SurfaceFormat::R8G8B8X8;
-
-    // Early swizzles are for unpacking RGB or forcing RGBA/BGRA_U32 to
-    // RGBX/BGRX_U32. We should never want to premultiply in either case,
-    // because the image's alpha channel will always be opaque. This must be
-    // done before downscaling and color management.
-    bool unpackOrMaskSwizzle =
-        inFormatRgb ||
-        (!inFormatOpaque && outFormatOpaque && inFormatOrder == outFormatOrder);
-
-    // Late swizzles are for premultiplying RGBA/BGRA_U32 and/or possible
-    // converting between RGBA and BGRA_U32. It must happen after color
-    // management, and before downscaling.
-    bool swapOrAlphaSwizzle =
-        (!inFormatRgb && inFormatOrder != outFormatOrder) || premultiplyAlpha;
+    MOZ_ASSERT(aOutFormat == gfx::SurfaceFormat::R8G8B8A8 ||
+               aOutFormat == gfx::SurfaceFormat::R8G8B8X8 ||
+               aOutFormat == gfx::SurfaceFormat::B8G8R8A8 ||
+               aOutFormat == gfx::SurfaceFormat::B8G8R8X8);
 
     if (unpackOrMaskSwizzle && swapOrAlphaSwizzle) {
       MOZ_ASSERT_UNREACHABLE("Early and late swizzles not supported");
       return Nothing();
     }
 
     if (!unpackOrMaskSwizzle && !swapOrAlphaSwizzle &&
         aInFormat != aOutFormat) {
--- a/image/VectorImage.cpp
+++ b/image/VectorImage.cpp
@@ -1096,18 +1096,18 @@ already_AddRefed<SourceSurface> VectorIm
   BackendType backend =
       aParams.context ? aParams.context->GetDrawTarget()->GetBackendType()
                       : gfxPlatform::GetPlatform()->GetDefaultContentBackend();
 
   // Try to create an imgFrame, initializing the surface it contains by drawing
   // our gfxDrawable into it. (We use FILTER_NEAREST since we never scale here.)
   auto frame = MakeNotNull<RefPtr<imgFrame>>();
   nsresult rv = frame->InitWithDrawable(
-      aSVGDrawable, aParams.size, SurfaceFormat::OS_RGBA, SamplingFilter::POINT,
-      aParams.flags, backend);
+      aSVGDrawable, aParams.size, SurfaceFormat::B8G8R8A8,
+      SamplingFilter::POINT, aParams.flags, backend);
 
   // If we couldn't create the frame, it was probably because it would end
   // up way too big. Generally it also wouldn't fit in the cache, but the prefs
   // could be set such that the cache isn't the limiting factor.
   if (NS_FAILED(rv)) {
     aWillCache = false;
     return nullptr;
   }
@@ -1177,17 +1177,17 @@ void VectorImage::Show(gfxDrawable* aDra
                     double(aParams.drawSize.height) / aParams.size.height);
     aParams.context->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
     region.Scale(1.0 / scale.width, 1.0 / scale.height);
   }
 
   MOZ_ASSERT(aDrawable, "Should have a gfxDrawable by now");
   gfxUtils::DrawPixelSnapped(aParams.context, aDrawable,
                              SizeDouble(aParams.size), region,
-                             SurfaceFormat::OS_RGBA, aParams.samplingFilter,
+                             SurfaceFormat::B8G8R8A8, aParams.samplingFilter,
                              aParams.flags, aParams.opacity, false);
 
 #ifdef DEBUG
   NotifyDrawingObservers();
 #endif
 
   MOZ_ASSERT(mRenderingObserver, "Should have a rendering observer by now");
   mRenderingObserver->ResumeHonoringInvalidations();
--- a/image/decoders/icon/android/nsIconChannel.cpp
+++ b/image/decoders/icon/android/nsIconChannel.cpp
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 <stdlib.h>
-#include "mozilla/gfx/Swizzle.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/NullPrincipal.h"
 #include "nsMimeTypes.h"
 #include "nsIURL.h"
 #include "nsXULAppAPI.h"
 #include "AndroidBridge.h"
 #include "nsIconChannel.h"
 #include "nsIStringStream.h"
@@ -71,32 +70,41 @@ static nsresult moz_icon_to_channel(nsIU
   if (!buf_size.isValid()) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   uint8_t* const buf = (uint8_t*)moz_xmalloc(buf_size.value());
   uint8_t* out = buf;
 
   *(out++) = width;
   *(out++) = height;
-  *(out++) = uint8_t(mozilla::gfx::SurfaceFormat::OS_RGBA);
-  *(out++) = 0;
 
   nsresult rv;
   if (XRE_IsParentProcess()) {
     rv = GetIconForExtension(aFileExt, aIconSize, out);
   } else {
     rv = CallRemoteGetIconForExtension(aFileExt, aIconSize, out);
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Encode the RGBA data
-  int32_t stride = 4 * width;
-  gfx::PremultiplyData(out, stride, gfx::SurfaceFormat::R8G8B8A8, out, stride,
-                       gfx::SurfaceFormat::OS_RGBA,
-                       gfx::IntSize(width, height));
+  const uint8_t* in = out;
+  for (int y = 0; y < height; ++y) {
+    for (int x = 0; x < width; ++x) {
+      uint8_t r = *(in++);
+      uint8_t g = *(in++);
+      uint8_t b = *(in++);
+      uint8_t a = *(in++);
+#define DO_PREMULTIPLY(c_) uint8_t(uint16_t(c_) * uint16_t(a) / uint16_t(255))
+      *(out++) = DO_PREMULTIPLY(b);
+      *(out++) = DO_PREMULTIPLY(g);
+      *(out++) = DO_PREMULTIPLY(r);
+      *(out++) = a;
+#undef DO_PREMULTIPLY
+    }
+  }
 
   nsCOMPtr<nsIStringInputStream> stream =
       do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = stream->AdoptData((char*)buf, buf_size.value());
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/image/decoders/icon/gtk/nsIconChannel.cpp
+++ b/image/decoders/icon/gtk/nsIconChannel.cpp
@@ -7,17 +7,16 @@
 
 #include <stdlib.h>
 #include <unistd.h>
 
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EndianUtils.h"
 #include "mozilla/NullPrincipal.h"
 #include "mozilla/CheckedInt.h"
-#include "mozilla/gfx/Swizzle.h"
 #include <algorithm>
 
 #include <gio/gio.h>
 
 #include <gtk/gtk.h>
 
 #include "nsMimeTypes.h"
 #include "nsIMIMEService.h"
@@ -53,28 +52,45 @@ static nsresult moz_gdk_pixbuf_to_channe
   if (!buf_size.isValid()) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   uint8_t* const buf = (uint8_t*)moz_xmalloc(buf_size.value());
   uint8_t* out = buf;
 
   *(out++) = width;
   *(out++) = height;
-  *(out++) = uint8_t(mozilla::gfx::SurfaceFormat::OS_RGBA);
-  *(out++) = 0;
 
   const guchar* const pixels = gdk_pixbuf_get_pixels(aPixbuf);
-  int instride = gdk_pixbuf_get_rowstride(aPixbuf);
-  int outstride = width * n_channels;
+  int rowextra = gdk_pixbuf_get_rowstride(aPixbuf) - width * n_channels;
 
   // encode the RGB data and the A data
-  mozilla::gfx::PremultiplyData(pixels, instride,
-                                mozilla::gfx::SurfaceFormat::R8G8B8A8, out,
-                                outstride, mozilla::gfx::SurfaceFormat::OS_RGBA,
-                                mozilla::gfx::IntSize(width, height));
+  const guchar* in = pixels;
+  for (int y = 0; y < height; ++y, in += rowextra) {
+    for (int x = 0; x < width; ++x) {
+      uint8_t r = *(in++);
+      uint8_t g = *(in++);
+      uint8_t b = *(in++);
+      uint8_t a = *(in++);
+#define DO_PREMULTIPLY(c_) uint8_t(uint16_t(c_) * uint16_t(a) / uint16_t(255))
+#if MOZ_LITTLE_ENDIAN
+      *(out++) = DO_PREMULTIPLY(b);
+      *(out++) = DO_PREMULTIPLY(g);
+      *(out++) = DO_PREMULTIPLY(r);
+      *(out++) = a;
+#else
+      *(out++) = a;
+      *(out++) = DO_PREMULTIPLY(r);
+      *(out++) = DO_PREMULTIPLY(g);
+      *(out++) = DO_PREMULTIPLY(b);
+#endif
+#undef DO_PREMULTIPLY
+    }
+  }
+
+  NS_ASSERTION(out == buf + buf_size.value(), "size miscalculation");
 
   nsresult rv;
   nsCOMPtr<nsIStringInputStream> stream =
       do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
 
   // Prevent the leaking of buf
   if (NS_WARN_IF(NS_FAILED(rv))) {
     free(buf);
--- a/image/decoders/icon/mac/nsIconChannelCocoa.mm
+++ b/image/decoders/icon/mac/nsIconChannelCocoa.mm
@@ -282,23 +282,21 @@ nsresult nsIconChannel::MakeInputStream(
   uint32_t width = size;
   uint32_t height = size;
 
   // The "image format" we're outputting here (and which gets decoded by
   // nsIconDecoder) has the following format:
   //  - 1 byte for the image width, as u8
   //  - 1 byte for the image height, as u8
   //  - the raw image data as BGRA, width * height * 4 bytes.
-  size_t bufferCapacity = 4 + width * height * 4;
+  size_t bufferCapacity = 2 + width * height * 4;
   UniquePtr<uint8_t[]> fileBuf = MakeUnique<uint8_t[]>(bufferCapacity);
   fileBuf[0] = uint8_t(width);
   fileBuf[1] = uint8_t(height);
-  fileBuf[2] = uint8_t(mozilla::gfx::SurfaceFormat::B8G8R8A8);
-  fileBuf[3] = 0;
-  uint8_t* imageBuf = &fileBuf[4];
+  uint8_t* imageBuf = &fileBuf[2];
 
   // Create a CGBitmapContext around imageBuf and draw iconImage to it.
   // This gives us the image data in the format we want: BGRA, four bytes per
   // pixel, in host endianness, with premultiplied alpha.
   CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
   CGContextRef ctx =
       CGBitmapContextCreate(imageBuf, width, height, 8 /* bitsPerComponent */, width * 4, cs,
                             kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst);
--- a/image/decoders/nsBMPDecoder.cpp
+++ b/image/decoders/nsBMPDecoder.cpp
@@ -653,18 +653,18 @@ LexerTransition<nsBMPDecoder::State> nsB
     memset(mColors.get(), 0, 256 * sizeof(ColorTableEntry));
 
     // OS/2 Bitmaps have no padding byte.
     mBytesPerColor = (mH.mBIHSize == InfoHeaderLength::WIN_V2) ? 3 : 4;
   }
 
   MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
   nsresult rv = AllocateFrame(OutputSize(), mMayHaveTransparency
-                                                ? SurfaceFormat::OS_RGBA
-                                                : SurfaceFormat::OS_RGBX);
+                                                ? SurfaceFormat::B8G8R8A8
+                                                : SurfaceFormat::B8G8R8X8);
   if (NS_FAILED(rv)) {
     return Transition::TerminateFailure();
   }
   MOZ_ASSERT(mImageData, "Should have a buffer now");
 
   if (mDownscaler) {
     // BMPs store their rows in reverse order, so the downscaler needs to
     // reverse them again when writing its output. Unless the height is
--- a/image/decoders/nsGIFDecoder2.cpp
+++ b/image/decoders/nsGIFDecoder2.cpp
@@ -91,17 +91,17 @@ nsGIFDecoder2::nsGIFDecoder2(RasterImage
       mColorMask('\0'),
       mGIFOpen(false),
       mSawTransparency(false),
       mSwizzleFn(nullptr) {
   // Clear out the structure, excluding the arrays.
   memset(&mGIFStruct, 0, sizeof(mGIFStruct));
 
   // Each color table will need to be unpacked.
-  mSwizzleFn = SwizzleRow(SurfaceFormat::R8G8B8, SurfaceFormat::OS_RGBA);
+  mSwizzleFn = SwizzleRow(SurfaceFormat::R8G8B8, SurfaceFormat::B8G8R8A8);
   MOZ_ASSERT(mSwizzleFn);
 }
 
 nsGIFDecoder2::~nsGIFDecoder2() { free(mGIFStruct.local_colormap); }
 
 nsresult nsGIFDecoder2::FinishInternal() {
   MOZ_ASSERT(!HasError(), "Shouldn't call FinishInternal after error!");
 
@@ -186,19 +186,20 @@ nsresult nsGIFDecoder2::BeginImageFrame(
   SurfacePipeFlags pipeFlags =
       aIsInterlaced ? SurfacePipeFlags::DEINTERLACE : SurfacePipeFlags();
 
   gfx::SurfaceFormat format;
   if (mGIFStruct.images_decoded == 0) {
     // The first frame may be displayed progressively.
     pipeFlags |= SurfacePipeFlags::PROGRESSIVE_DISPLAY;
 
-    format = hasTransparency ? SurfaceFormat::OS_RGBA : SurfaceFormat::OS_RGBX;
+    format =
+        hasTransparency ? SurfaceFormat::B8G8R8A8 : SurfaceFormat::B8G8R8X8;
   } else {
-    format = SurfaceFormat::OS_RGBA;
+    format = SurfaceFormat::B8G8R8A8;
   }
 
   Maybe<SurfacePipe> pipe = SurfacePipeFactory::CreateSurfacePipe(
       this, Size(), OutputSize(), aFrameRect, format, format, animParams,
       mTransform, pipeFlags);
   mCurrentFrameIndex = mGIFStruct.images_decoded;
 
   if (!pipe) {
--- a/image/decoders/nsICODecoder.cpp
+++ b/image/decoders/nsICODecoder.cpp
@@ -578,20 +578,20 @@ LexerTransition<ICOState> nsICODecoder::
     // Iterate through the alpha values, copying from mask to image.
     MOZ_ASSERT(mMaskBuffer);
     MOZ_ASSERT(bmpDecoder->GetImageDataLength() > 0);
     for (size_t i = 3; i < bmpDecoder->GetImageDataLength(); i += 4) {
       imageData[i] = mMaskBuffer[i];
     }
     int32_t stride = mDownscaler->TargetSize().width * sizeof(uint32_t);
     DebugOnly<bool> ret =
-        // We know the format is OS_RGBA because we always assume bmp's inside
+        // We know the format is B8G8R8A8 because we always assume bmp's inside
         // ico's are transparent.
-        PremultiplyData(imageData, stride, SurfaceFormat::OS_RGBA, imageData,
-                        stride, SurfaceFormat::OS_RGBA,
+        PremultiplyData(imageData, stride, SurfaceFormat::B8G8R8A8, imageData,
+                        stride, SurfaceFormat::B8G8R8A8,
                         mDownscaler->TargetSize());
     MOZ_ASSERT(ret);
   }
 
   return Transition::To(ICOState::FINISHED_RESOURCE, 0);
 }
 
 LexerTransition<ICOState> nsICODecoder::FinishResource() {
--- a/image/decoders/nsIconDecoder.cpp
+++ b/image/decoders/nsIconDecoder.cpp
@@ -8,17 +8,17 @@
 #include "RasterImage.h"
 #include "SurfacePipeFactory.h"
 
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace image {
 
-static const uint32_t ICON_HEADER_SIZE = 4;
+static const uint32_t ICON_HEADER_SIZE = 2;
 
 nsIconDecoder::nsIconDecoder(RasterImage* aImage)
     : Decoder(aImage),
       mLexer(Transition::To(State::HEADER, ICON_HEADER_SIZE),
              Transition::TerminateSuccess()),
       mBytesPerRow()  // set by ReadHeader()
 {
   // Nothing to do
@@ -45,17 +45,16 @@ LexerResult nsIconDecoder::DoDecode(Sour
                     });
 }
 
 LexerTransition<nsIconDecoder::State> nsIconDecoder::ReadHeader(
     const char* aData) {
   // Grab the width and height.
   uint8_t width = uint8_t(aData[0]);
   uint8_t height = uint8_t(aData[1]);
-  SurfaceFormat format = SurfaceFormat(aData[2]);
 
   // The input is 32bpp, so we expect 4 bytes of data per pixel.
   mBytesPerRow = width * 4;
 
   // Post our size to the superclass.
   PostSize(width, height);
 
   // Icons have alpha.
@@ -63,34 +62,47 @@ LexerTransition<nsIconDecoder::State> ns
 
   // If we're doing a metadata decode, we're done.
   if (IsMetadataDecode()) {
     return Transition::TerminateSuccess();
   }
 
   MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
   Maybe<SurfacePipe> pipe = SurfacePipeFactory::CreateSurfacePipe(
-      this, Size(), OutputSize(), FullFrame(), format, SurfaceFormat::OS_RGBA,
+      this, Size(), OutputSize(), FullFrame(), SurfaceFormat::B8G8R8A8,
+      SurfaceFormat::B8G8R8A8,
       /* aAnimParams */ Nothing(), mTransform, SurfacePipeFlags());
   if (!pipe) {
     return Transition::TerminateFailure();
   }
 
   mPipe = std::move(*pipe);
 
   MOZ_ASSERT(mImageData, "Should have a buffer now");
 
   return Transition::To(State::ROW_OF_PIXELS, mBytesPerRow);
 }
 
 LexerTransition<nsIconDecoder::State> nsIconDecoder::ReadRowOfPixels(
     const char* aData, size_t aLength) {
   MOZ_ASSERT(aLength % 4 == 0, "Rows should contain a multiple of four bytes");
 
-  auto result = mPipe.WriteBuffer(reinterpret_cast<const uint32_t*>(aData));
+  auto result = mPipe.WritePixels<uint32_t>([&]() -> NextPixel<uint32_t> {
+    if (aLength == 0) {
+      return AsVariant(WriteState::NEED_MORE_DATA);  // Done with this row.
+    }
+
+    uint32_t pixel;
+    memcpy(&pixel, aData, 4);
+    aData += 4;
+    aLength -= 4;
+
+    return AsVariant(pixel);
+  });
+
   MOZ_ASSERT(result != WriteState::FAILURE);
 
   Maybe<SurfaceInvalidRect> invalidRect = mPipe.TakeInvalidRect();
   if (invalidRect) {
     PostInvalidation(invalidRect->mInputSpaceRect,
                      Some(invalidRect->mOutputSpaceRect));
   }
 
--- a/image/decoders/nsJPEGDecoder.cpp
+++ b/image/decoders/nsJPEGDecoder.cpp
@@ -258,30 +258,17 @@ LexerTransition<nsJPEGDecoder::State> ns
 
       // We're doing a full decode.
       switch (mInfo.jpeg_color_space) {
         case JCS_GRAYSCALE:
         case JCS_RGB:
         case JCS_YCbCr:
           // By default, we will output directly to BGRA. If we need to apply
           // special color transforms, this may change.
-          switch (SurfaceFormat::OS_RGBX) {
-            case SurfaceFormat::B8G8R8X8:
-              mInfo.out_color_space = JCS_EXT_BGRX;
-              break;
-            case SurfaceFormat::X8R8G8B8:
-              mInfo.out_color_space = JCS_EXT_XRGB;
-              break;
-            case SurfaceFormat::R8G8B8X8:
-              mInfo.out_color_space = JCS_EXT_RGBX;
-              break;
-            default:
-              mState = JPEG_ERROR;
-              return Transition::TerminateFailure();
-          }
+          mInfo.out_color_space = MOZ_JCS_EXT_NATIVE_ENDIAN_XRGB;
           break;
         case JCS_CMYK:
         case JCS_YCCK:
           // libjpeg can convert from YCCK to CMYK, but not to XRGB.
           mInfo.out_color_space = JCS_CMYK;
           break;
         default:
           mState = JPEG_ERROR;
@@ -293,56 +280,55 @@ LexerTransition<nsJPEGDecoder::State> ns
       if (mCMSMode != eCMSMode_Off) {
         if ((mInProfile = GetICCProfile(mInfo)) != nullptr &&
             gfxPlatform::GetCMSOutputProfile()) {
           uint32_t profileSpace = qcms_profile_get_color_space(mInProfile);
 
 #ifdef DEBUG_tor
           fprintf(stderr, "JPEG profileSpace: 0x%08X\n", profileSpace);
 #endif
-          qcms_data_type outputType = gfxPlatform::GetCMSOSRGBAType();
-          Maybe<qcms_data_type> inputType;
+          Maybe<qcms_data_type> type;
           if (profileSpace == icSigRgbData) {
             // We can always color manage RGB profiles since it happens at the
             // end of the pipeline.
-            inputType.emplace(outputType);
+            type.emplace(QCMS_DATA_BGRA_8);
           } else if (profileSpace == icSigGrayData &&
                      mInfo.jpeg_color_space == JCS_GRAYSCALE) {
             // We can only color manage gray profiles if the original color
             // space is grayscale. This means we must downscale after color
             // management since the downscaler assumes BGRA.
             mInfo.out_color_space = JCS_GRAYSCALE;
-            inputType.emplace(QCMS_DATA_GRAY_8);
+            type.emplace(QCMS_DATA_GRAY_8);
           }
 
 #if 0
           // We don't currently support CMYK profiles. The following
           // code dealt with lcms types. Add something like this
           // back when we gain support for CMYK.
 
           // Adobe Photoshop writes YCCK/CMYK files with inverted data
           if (mInfo.out_color_space == JCS_CMYK) {
             type |= FLAVOR_SH(mInfo.saw_Adobe_marker ? 1 : 0);
           }
 #endif
 
-          if (inputType) {
+          if (type) {
             // Calculate rendering intent.
             int intent = gfxPlatform::GetRenderingIntent();
             if (intent == -1) {
               intent = qcms_profile_get_rendering_intent(mInProfile);
             }
 
             // Create the color management transform.
             mTransform = qcms_transform_create(
-                mInProfile, *inputType, gfxPlatform::GetCMSOutputProfile(),
-                outputType, (qcms_intent)intent);
+                mInProfile, *type, gfxPlatform::GetCMSOutputProfile(),
+                QCMS_DATA_BGRA_8, (qcms_intent)intent);
           }
         } else if (mCMSMode == eCMSMode_All) {
-          mTransform = gfxPlatform::GetCMSOSRGBATransform();
+          mTransform = gfxPlatform::GetCMSBGRATransform();
         }
       }
 
       // We don't want to use the pipe buffers directly because we don't want
       // any reads on non-BGRA formatted data.
       if (mInfo.out_color_space == JCS_GRAYSCALE ||
           mInfo.out_color_space == JCS_CMYK) {
         mCMSLine = new (std::nothrow) uint32_t[mInfo.image_width];
@@ -365,18 +351,19 @@ LexerTransition<nsJPEGDecoder::State> ns
       // We handle the transform outside the pipeline if we are outputting in
       // grayscale, because the pipeline wants BGRA pixels, particularly the
       // downscaling filter, so we can't handle it after downscaling as would
       // be optimal.
       qcms_transform* pipeTransform =
           mInfo.out_color_space != JCS_GRAYSCALE ? mTransform : nullptr;
 
       Maybe<SurfacePipe> pipe = SurfacePipeFactory::CreateSurfacePipe(
-          this, Size(), OutputSize(), FullFrame(), SurfaceFormat::OS_RGBX,
-          SurfaceFormat::OS_RGBX, Nothing(), pipeTransform, SurfacePipeFlags());
+          this, Size(), OutputSize(), FullFrame(), SurfaceFormat::B8G8R8X8,
+          SurfaceFormat::B8G8R8X8, Nothing(), pipeTransform,
+          SurfacePipeFlags());
       if (!pipe) {
         mState = JPEG_ERROR;
         MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
                 ("} (could not initialize surface pipe)"));
         return Transition::TerminateFailure();
       }
 
       mPipe = std::move(*pipe);
@@ -870,16 +857,17 @@ term_source(j_decompress_ptr jd) {
 /// Output is RGB stored as 3 bytes per pixel.
 /// @param aInput Points to row buffer containing the CMYK bytes for each pixel
 ///               in the row.
 /// @param aOutput Points to row buffer to write BGRA to.
 /// @param aWidth Number of pixels in the row.
 static void cmyk_convert_bgra(uint32_t* aInput, uint32_t* aOutput,
                               int32_t aWidth) {
   uint8_t* input = reinterpret_cast<uint8_t*>(aInput);
+  uint8_t* output = reinterpret_cast<uint8_t*>(aOutput);
 
   for (int32_t i = 0; i < aWidth; ++i) {
     // Source is 'Inverted CMYK', output is RGB.
     // See: http://www.easyrgb.com/math.php?MATH=M12#text12
     // Or:  http://www.ilkeratalay.com/colorspacesfaq.php#rgb
 
     // From CMYK to CMY
     // C = ( C * ( 1 - K ) + K )
@@ -895,19 +883,24 @@ static void cmyk_convert_bgra(uint32_t* 
     // G = 1 - M => 1 - (1 - iM*iK) => iM*iK
     // B = 1 - Y => 1 - (1 - iY*iK) => iY*iK
 
     // Convert from Inverted CMYK (0..255) to RGB (0..255)
     const uint32_t iC = input[0];
     const uint32_t iM = input[1];
     const uint32_t iY = input[2];
     const uint32_t iK = input[3];
-
-    const uint8_t r = iC * iK / 255;
-    const uint8_t g = iM * iK / 255;
-    const uint8_t b = iY * iK / 255;
+#if MOZ_BIG_ENDIAN
+    output[0] = 0xFF;           // Alpha
+    output[1] = iC * iK / 255;  // Red
+    output[2] = iM * iK / 255;  // Green
+    output[3] = iY * iK / 255;  // Blue
+#else
+    output[0] = iY * iK / 255;  // Blue
+    output[1] = iM * iK / 255;  // Green
+    output[2] = iC * iK / 255;  // Red
+    output[3] = 0xFF;           // Alpha
+#endif
 
-    *aOutput++ = (0xFF << SurfaceFormatBit::OS_A) |
-                 (r << SurfaceFormatBit::OS_R) | (g << SurfaceFormatBit::OS_G) |
-                 (b << SurfaceFormatBit::OS_B);
     input += 4;
+    output += 4;
   }
 }
--- a/image/decoders/nsPNGDecoder.cpp
+++ b/image/decoders/nsPNGDecoder.cpp
@@ -170,18 +170,18 @@ void nsPNGDecoder::PostHasTransparencyIf
 // CreateFrame() is used for both simple and animated images.
 nsresult nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo) {
   MOZ_ASSERT(HasSize());
   MOZ_ASSERT(!IsMetadataDecode());
 
   // Check if we have transparency, and send notifications if needed.
   auto transparency = GetTransparencyType(aFrameInfo.mFrameRect);
   PostHasTransparencyIfNeeded(transparency);
-  mFormat = transparency == TransparencyType::eNone ? SurfaceFormat::OS_RGBX
-                                                    : SurfaceFormat::OS_RGBA;
+  mFormat = transparency == TransparencyType::eNone ? SurfaceFormat::B8G8R8X8
+                                                    : SurfaceFormat::B8G8R8A8;
 
   // Make sure there's no animation or padding if we're downscaling.
   MOZ_ASSERT_IF(Size() != OutputSize(), mNumFrames == 0);
   MOZ_ASSERT_IF(Size() != OutputSize(), !GetImageMetadata().HasAnimation());
   MOZ_ASSERT_IF(Size() != OutputSize(),
                 transparency != TransparencyType::eFrameRect);
 
   Maybe<AnimationParams> animParams;
@@ -258,17 +258,17 @@ nsresult nsPNGDecoder::CreateFrame(const
 // set timeout and frame disposal method for the current frame
 void nsPNGDecoder::EndImageFrame() {
   if (mFrameIsHidden) {
     return;
   }
 
   mNumFrames++;
 
-  Opacity opacity = mFormat == SurfaceFormat::OS_RGBX
+  Opacity opacity = mFormat == SurfaceFormat::B8G8R8X8
                         ? Opacity::FULLY_OPAQUE
                         : Opacity::SOME_TRANSPARENCY;
 
   PostFrameStop(opacity);
 }
 
 nsresult nsPNGDecoder::InitInternal() {
   mCMSMode = gfxPlatform::GetCMSMode();
@@ -675,26 +675,26 @@ void nsPNGDecoder::info_callback(png_str
       // If the transform happens with SurfacePipe, it will be in RGBA if we
       // have an alpha channel, because the swizzle and premultiplication
       // happens after color management. Otherwise it will be in BGRA because
       // the swizzle happens at the start.
       if (transparency == TransparencyType::eAlpha) {
         inType = QCMS_DATA_RGBA_8;
         outType = QCMS_DATA_RGBA_8;
       } else {
-        inType = gfxPlatform::GetCMSOSRGBAType();
-        outType = inType;
+        inType = QCMS_DATA_BGRA_8;
+        outType = QCMS_DATA_BGRA_8;
       }
     } else {
       if (color_type & PNG_COLOR_MASK_ALPHA) {
         inType = QCMS_DATA_GRAYA_8;
-        outType = gfxPlatform::GetCMSOSRGBAType();
+        outType = QCMS_DATA_BGRA_8;
       } else {
         inType = QCMS_DATA_GRAY_8;
-        outType = gfxPlatform::GetCMSOSRGBAType();
+        outType = QCMS_DATA_BGRA_8;
       }
     }
 
     decoder->mTransform = qcms_transform_create(
         decoder->mInProfile, inType, gfxPlatform::GetCMSOutputProfile(),
         outType, (qcms_intent)intent);
   } else if (decoder->mCMSMode == eCMSMode_All) {
     // If the transform happens with SurfacePipe, it will be in RGBA if we
--- a/image/decoders/nsWebPDecoder.cpp
+++ b/image/decoders/nsWebPDecoder.cpp
@@ -18,17 +18,17 @@ namespace image {
 static LazyLogModule sWebPLog("WebPDecoder");
 
 nsWebPDecoder::nsWebPDecoder(RasterImage* aImage)
     : Decoder(aImage),
       mDecoder(nullptr),
       mBlend(BlendMethod::OVER),
       mDisposal(DisposalMethod::KEEP),
       mTimeout(FrameTimeout::Forever()),
-      mFormat(SurfaceFormat::OS_RGBX),
+      mFormat(SurfaceFormat::B8G8R8X8),
       mLastRow(0),
       mCurrentFrame(0),
       mData(nullptr),
       mLength(0),
       mIteratorComplete(false),
       mNeedDemuxer(true),
       mGotColorProfile(false) {
   MOZ_LOG(sWebPLog, LogLevel::Debug,
@@ -200,52 +200,38 @@ nsresult nsWebPDecoder::CreateFrame(cons
             ("[this=%p] nsWebPDecoder::CreateFrame -- bad frame rect\n", this));
     return NS_ERROR_FAILURE;
   }
 
   // If this is our first frame in an animation and it doesn't cover the
   // full frame, then we are transparent even if there is no alpha
   if (mCurrentFrame == 0 && !aFrameRect.IsEqualEdges(FullFrame())) {
     MOZ_ASSERT(HasAnimation());
-    mFormat = SurfaceFormat::OS_RGBA;
+    mFormat = SurfaceFormat::B8G8R8A8;
     PostHasTransparency();
   }
 
   WebPInitDecBuffer(&mBuffer);
-
-  switch (SurfaceFormat::OS_RGBA) {
-    case SurfaceFormat::B8G8R8A8:
-      mBuffer.colorspace = MODE_BGRA;
-      break;
-    case SurfaceFormat::A8R8G8B8:
-      mBuffer.colorspace = MODE_ARGB;
-      break;
-    case SurfaceFormat::R8G8B8A8:
-      mBuffer.colorspace = MODE_RGBA;
-      break;
-    default:
-      MOZ_ASSERT_UNREACHABLE("Unknown OS_RGBA");
-      return NS_ERROR_FAILURE;
-  }
+  mBuffer.colorspace = MODE_BGRA;
 
   mDecoder = WebPINewDecoder(&mBuffer);
   if (!mDecoder) {
     MOZ_LOG(sWebPLog, LogLevel::Error,
             ("[this=%p] nsWebPDecoder::CreateFrame -- create decoder error\n",
              this));
     return NS_ERROR_FAILURE;
   }
 
   // WebP doesn't guarantee that the alpha generated matches the hint in the
   // header, so we always need to claim the input is BGRA. If the output is
   // BGRX, swizzling will mask off the alpha channel.
-  SurfaceFormat inFormat = SurfaceFormat::OS_RGBA;
+  SurfaceFormat inFormat = SurfaceFormat::B8G8R8A8;
 
   SurfacePipeFlags pipeFlags = SurfacePipeFlags();
-  if (mFormat == SurfaceFormat::OS_RGBA &&
+  if (mFormat == SurfaceFormat::B8G8R8A8 &&
       !(GetSurfaceFlags() & SurfaceFlags::NO_PREMULTIPLY_ALPHA)) {
     pipeFlags |= SurfacePipeFlags::PREMULTIPLY_ALPHA;
   }
 
   Maybe<AnimationParams> animParams;
   if (!IsFirstFrameDecode()) {
     animParams.emplace(aFrameRect, mTimeout, mCurrentFrame, mBlend, mDisposal);
   }
@@ -263,18 +249,18 @@ nsresult nsWebPDecoder::CreateFrame(cons
   mPipe = std::move(*pipe);
   return NS_OK;
 }
 
 void nsWebPDecoder::EndFrame() {
   MOZ_ASSERT(HasSize());
   MOZ_ASSERT(mDecoder);
 
-  auto opacity = mFormat == SurfaceFormat::OS_RGBA ? Opacity::SOME_TRANSPARENCY
-                                                   : Opacity::FULLY_OPAQUE;
+  auto opacity = mFormat == SurfaceFormat::B8G8R8A8 ? Opacity::SOME_TRANSPARENCY
+                                                    : Opacity::FULLY_OPAQUE;
 
   MOZ_LOG(sWebPLog, LogLevel::Debug,
           ("[this=%p] nsWebPDecoder::EndFrame -- frame %u, opacity %d, "
            "disposal %d, timeout %d, blend %d\n",
            this, mCurrentFrame, (int)opacity, (int)mDisposal,
            mTimeout.AsEncodedValueDeprecated(), (int)mBlend));
 
   PostFrameStop(opacity);
@@ -329,20 +315,19 @@ void nsWebPDecoder::ApplyColorProfile(co
 
   // Calculate rendering intent.
   int intent = gfxPlatform::GetRenderingIntent();
   if (intent == -1) {
     intent = qcms_profile_get_rendering_intent(mInProfile);
   }
 
   // Create the color management transform.
-  qcms_data_type type = gfxPlatform::GetCMSOSRGBAType();
-  mTransform = qcms_transform_create(mInProfile, type,
-                                     gfxPlatform::GetCMSOutputProfile(), type,
-                                     (qcms_intent)intent);
+  mTransform = qcms_transform_create(mInProfile, QCMS_DATA_BGRA_8,
+                                     gfxPlatform::GetCMSOutputProfile(),
+                                     QCMS_DATA_BGRA_8, (qcms_intent)intent);
   MOZ_LOG(sWebPLog, LogLevel::Debug,
           ("[this=%p] nsWebPDecoder::ApplyColorProfile -- use tagged "
            "transform\n",
            this));
 }
 
 LexerResult nsWebPDecoder::ReadHeader(WebPDemuxer* aDemuxer, bool aIsComplete) {
   MOZ_ASSERT(aDemuxer);
@@ -390,17 +375,17 @@ LexerResult nsWebPDecoder::ReadHeader(We
   if (width > INT32_MAX || height > INT32_MAX) {
     return LexerResult(TerminalState::FAILURE);
   }
 
   PostSize(width, height);
 
   bool alpha = flags & WebPFeatureFlags::ALPHA_FLAG;
   if (alpha) {
-    mFormat = SurfaceFormat::OS_RGBA;
+    mFormat = SurfaceFormat::B8G8R8A8;
     PostHasTransparency();
   }
 
   MOZ_LOG(sWebPLog, LogLevel::Debug,
           ("[this=%p] nsWebPDecoder::ReadHeader -- %u x %u, alpha %d, "
            "animation %d, metadata decode %d, first frame decode %d\n",
            this, width, height, alpha, HasAnimation(), IsMetadataDecode(),
            IsFirstFrameDecode()));
@@ -548,18 +533,18 @@ LexerResult nsWebPDecoder::ReadMultiple(
       case WEBP_MUX_DISPOSE_BACKGROUND:
         mDisposal = DisposalMethod::CLEAR;
         break;
       default:
         MOZ_ASSERT_UNREACHABLE("Unhandled dispose method");
         break;
     }
 
-    mFormat = iter.has_alpha || mCurrentFrame > 0 ? SurfaceFormat::OS_RGBA
-                                                  : SurfaceFormat::OS_RGBX;
+    mFormat = iter.has_alpha || mCurrentFrame > 0 ? SurfaceFormat::B8G8R8A8
+                                                  : SurfaceFormat::B8G8R8X8;
     mTimeout = FrameTimeout::FromRawMilliseconds(iter.duration);
     nsIntRect frameRect(iter.x_offset, iter.y_offset, iter.width, iter.height);
 
     rv = ReadSingle(iter.fragment.bytes, iter.fragment.size, frameRect);
     complete = complete && !WebPDemuxNextFrame(&iter);
     WebPDemuxReleaseIterator(&iter);
   }
 
--- a/image/imgFrame.cpp
+++ b/image/imgFrame.cpp
@@ -153,17 +153,17 @@ static bool GreenSurface(DataSourceSurfa
 }
 
 static bool ClearSurface(DataSourceSurface* aSurface, const IntSize& aSize,
                          SurfaceFormat aFormat) {
   int32_t stride = aSurface->Stride();
   uint8_t* data = aSurface->GetData();
   MOZ_ASSERT(data);
 
-  if (aFormat == SurfaceFormat::OS_RGBX) {
+  if (aFormat == SurfaceFormat::B8G8R8X8) {
     // Skia doesn't support RGBX surfaces, so ensure the alpha value is set
     // to opaque white. While it would be nice to only do this for Skia,
     // imgFrame can run off main thread and past shutdown where
     // we might not have gfxPlatform, so just memset every time instead.
     memset(data, 0xFF, stride * aSize.height);
   } else if (aSurface->OnHeap()) {
     // We only need to memset it if the buffer was allocated on the heap.
     // Otherwise, it's allocated via mmap and refers to a zeroed page and will
@@ -225,17 +225,17 @@ nsresult imgFrame::InitForDecoder(const 
     mBlendRect = GetRect();
   }
 
   if (aShouldRecycle) {
     // If we are recycling then we should always use BGRA for the underlying
     // surface because if we use BGRX, the next frame composited into the
     // surface could be BGRA and cause rendering problems.
     MOZ_ASSERT(aAnimParams);
-    mFormat = SurfaceFormat::OS_RGBA;
+    mFormat = SurfaceFormat::B8G8R8A8;
   } else {
     mFormat = aFormat;
   }
 
   mNonPremult = aNonPremult;
   mShouldRecycle = aShouldRecycle;
 
   MOZ_ASSERT(!mLockedSurface, "Called imgFrame::InitForDecoder() twice?");
@@ -549,17 +549,17 @@ imgFrame::SurfaceWithFormat imgFrame::Su
       gfxRect(mDecoded.X(), mDecoded.Y(), mDecoded.Width(), mDecoded.Height());
 
   if (aDoTile) {
     // Create a temporary surface.
     // Give this surface an alpha channel because there are
     // transparent pixels in the padding or undecoded area
     RefPtr<DrawTarget> target =
         gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
-            mImageSize, SurfaceFormat::OS_RGBA);
+            mImageSize, SurfaceFormat::B8G8R8A8);
     if (!target) {
       return SurfaceWithFormat();
     }
 
     SurfacePattern pattern(aSurface, aRegion.GetExtendMode(),
                            Matrix::Translation(mDecoded.X(), mDecoded.Y()));
     target->FillRect(ToRect(aRegion.Intersect(available).Rect()), pattern);
 
--- a/image/imgFrame.h
+++ b/image/imgFrame.h
@@ -165,17 +165,17 @@ class imgFrame {
   IntRect GetRect() const { return IntRect(IntPoint(0, 0), mImageSize); }
   const IntRect& GetBlendRect() const { return mBlendRect; }
   IntRect GetBoundedBlendRect() const {
     return mBlendRect.Intersect(GetRect());
   }
   FrameTimeout GetTimeout() const { return mTimeout; }
   BlendMethod GetBlendMethod() const { return mBlendMethod; }
   DisposalMethod GetDisposalMethod() const { return mDisposalMethod; }
-  bool FormatHasAlpha() const { return mFormat == SurfaceFormat::OS_RGBA; }
+  bool FormatHasAlpha() const { return mFormat == SurfaceFormat::B8G8R8A8; }
   void GetImageData(uint8_t** aData, uint32_t* length) const;
   uint8_t* GetImageData() const;
 
   const IntRect& GetDirtyRect() const { return mDirtyRect; }
   void SetDirtyRect(const IntRect& aDirtyRect) { mDirtyRect = aDirtyRect; }
 
   void SetOptimizable();
 
--- a/image/test/fuzzing/TestDecoders.cpp
+++ b/image/test/fuzzing/TestDecoders.cpp
@@ -51,18 +51,18 @@ class DecodeToSurfaceRunnableFuzzing : p
   }
 
   void Go() {
     mSurface = ImageOps::DecodeToSurface(mInputStream.forget(), mMimeType,
                                          imgIContainer::DECODE_FLAGS_DEFAULT);
     if (!mSurface) return;
 
     if (mSurface->GetType() == SurfaceType::DATA) {
-      if (mSurface->GetFormat() == SurfaceFormat::OS_RGBX ||
-          mSurface->GetFormat() == SurfaceFormat::OS_RGBA) {
+      if (mSurface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
+          mSurface->GetFormat() == SurfaceFormat::B8G8R8A8) {
         DUMMY_IF(IntSize(1, 1) == mSurface->GetSize());
         DUMMY_IF(IsSolidColor(mSurface, BGRAColor::Green(), 1));
       }
     }
   }
 
  private:
   RefPtr<SourceSurface>& mSurface;
--- a/image/test/gtest/Common.cpp
+++ b/image/test/gtest/Common.cpp
@@ -19,16 +19,17 @@
 #include "nsStreamUtils.h"
 #include "nsString.h"
 
 namespace mozilla {
 namespace image {
 
 using namespace gfx;
 
+using std::abs;
 using std::vector;
 
 static bool sImageLibInitialized = false;
 
 AutoInitializeImageLib::AutoInitializeImageLib() {
   if (MOZ_LIKELY(sImageLibInitialized)) {
     return;
   }
@@ -187,35 +188,30 @@ bool RectIsSolidColor(SourceSurface* aSu
                                        DataSourceSurface::MapType::READ);
   ASSERT_TRUE_OR_RETURN(mapping.IsMapped(), false);
   ASSERT_EQ_OR_RETURN(mapping.GetStride(), surfaceSize.width * 4, false);
 
   uint8_t* data = mapping.GetData();
   ASSERT_TRUE_OR_RETURN(data != nullptr, false);
 
   BGRAColor pmColor = aColor.Premultiply();
-  uint32_t expectedPixel = pmColor.AsPixel();
-
   int32_t rowLength = mapping.GetStride();
   for (int32_t row = rect.Y(); row < rect.YMost(); ++row) {
     for (int32_t col = rect.X(); col < rect.XMost(); ++col) {
       int32_t i = row * rowLength + col * 4;
-      uint32_t gotPixel = *reinterpret_cast<uint32_t*>(data + i);
-      if (expectedPixel != gotPixel) {
-        BGRAColor gotColor = BGRAColor::FromPixel(gotPixel);
-        if (abs(pmColor.mBlue - gotColor.mBlue) > aFuzz ||
-            abs(pmColor.mGreen - gotColor.mGreen) > aFuzz ||
-            abs(pmColor.mRed - gotColor.mRed) > aFuzz ||
-            abs(pmColor.mAlpha - gotColor.mAlpha) > aFuzz) {
-          EXPECT_EQ(pmColor.mBlue, gotColor.mBlue);
-          EXPECT_EQ(pmColor.mGreen, gotColor.mGreen);
-          EXPECT_EQ(pmColor.mRed, gotColor.mRed);
-          EXPECT_EQ(pmColor.mAlpha, gotColor.mAlpha);
-          ASSERT_EQ_OR_RETURN(expectedPixel, gotPixel, false);
-        }
+      if (aFuzz != 0) {
+        ASSERT_LE_OR_RETURN(abs(pmColor.mBlue - data[i + 0]), aFuzz, false);
+        ASSERT_LE_OR_RETURN(abs(pmColor.mGreen - data[i + 1]), aFuzz, false);
+        ASSERT_LE_OR_RETURN(abs(pmColor.mRed - data[i + 2]), aFuzz, false);
+        ASSERT_LE_OR_RETURN(abs(pmColor.mAlpha - data[i + 3]), aFuzz, false);
+      } else {
+        ASSERT_EQ_OR_RETURN(pmColor.mBlue, data[i + 0], false);
+        ASSERT_EQ_OR_RETURN(pmColor.mGreen, data[i + 1], false);
+        ASSERT_EQ_OR_RETURN(pmColor.mRed, data[i + 2], false);
+        ASSERT_EQ_OR_RETURN(pmColor.mAlpha, data[i + 3], false);
       }
     }
   }
 
   return true;
 }
 
 bool RowHasPixels(SourceSurface* aSurface, int32_t aRow,
@@ -235,23 +231,20 @@ bool RowHasPixels(SourceSurface* aSurfac
   ASSERT_EQ_OR_RETURN(mapping.GetStride(), surfaceSize.width * 4, false);
 
   uint8_t* data = mapping.GetData();
   ASSERT_TRUE_OR_RETURN(data != nullptr, false);
 
   int32_t rowLength = mapping.GetStride();
   for (int32_t col = 0; col < surfaceSize.width; ++col) {
     int32_t i = aRow * rowLength + col * 4;
-    uint32_t gotPixelData = *reinterpret_cast<uint32_t*>(data + i);
-    BGRAColor gotPixel = BGRAColor::FromPixel(gotPixelData);
-    EXPECT_EQ(aPixels[col].mBlue, gotPixel.mBlue);
-    EXPECT_EQ(aPixels[col].mGreen, gotPixel.mGreen);
-    EXPECT_EQ(aPixels[col].mRed, gotPixel.mRed);
-    EXPECT_EQ(aPixels[col].mAlpha, gotPixel.mAlpha);
-    ASSERT_EQ_OR_RETURN(aPixels[col].AsPixel(), gotPixelData, false);
+    ASSERT_EQ_OR_RETURN(aPixels[col].mBlue, data[i + 0], false);
+    ASSERT_EQ_OR_RETURN(aPixels[col].mGreen, data[i + 1], false);
+    ASSERT_EQ_OR_RETURN(aPixels[col].mRed, data[i + 2], false);
+    ASSERT_EQ_OR_RETURN(aPixels[col].mAlpha, data[i + 3], false);
   }
 
   return true;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // SurfacePipe Helpers
 ///////////////////////////////////////////////////////////////////////////////
--- a/image/test/gtest/Common.h
+++ b/image/test/gtest/Common.h
@@ -42,25 +42,16 @@ struct BGRAColor {
         mAlpha(aAlpha),
         mPremultiplied(aPremultiplied) {}
 
   static BGRAColor Green() { return BGRAColor(0x00, 0xFF, 0x00, 0xFF); }
   static BGRAColor Red() { return BGRAColor(0x00, 0x00, 0xFF, 0xFF); }
   static BGRAColor Blue() { return BGRAColor(0xFF, 0x00, 0x00, 0xFF); }
   static BGRAColor Transparent() { return BGRAColor(0x00, 0x00, 0x00, 0x00); }
 
-  static BGRAColor FromPixel(uint32_t aPixel) {
-    uint8_t r, g, b, a;
-    r = (aPixel >> gfx::SurfaceFormatBit::OS_R) & 0xFF;
-    g = (aPixel >> gfx::SurfaceFormatBit::OS_G) & 0xFF;
-    b = (aPixel >> gfx::SurfaceFormatBit::OS_B) & 0xFF;
-    a = (aPixel >> gfx::SurfaceFormatBit::OS_A) & 0xFF;
-    return BGRAColor(b, g, r, a, true);
-  }
-
   BGRAColor Premultiply() const {
     if (!mPremultiplied) {
       return BGRAColor(gfxPreMultiply(mBlue, mAlpha),
                        gfxPreMultiply(mGreen, mAlpha),
                        gfxPreMultiply(mRed, mAlpha), mAlpha, true);
     }
     return *this;
   }
--- a/image/test/gtest/TestADAM7InterpolatingFilter.cpp
+++ b/image/test/gtest/TestADAM7InterpolatingFilter.cpp
@@ -27,26 +27,26 @@ using std::vector;
 
 template <typename Func>
 void WithADAM7InterpolatingFilter(const IntSize& aSize, Func aFunc) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(bool(decoder));
 
   WithFilterPipeline(
       decoder, std::forward<Func>(aFunc), ADAM7InterpolatingConfig{},
-      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
+      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 void AssertConfiguringADAM7InterpolatingFilterFails(const IntSize& aSize) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(bool(decoder));
 
   AssertConfiguringPipelineFails(
       decoder, ADAM7InterpolatingConfig{},
-      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
+      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 uint8_t InterpolateByte(uint8_t aByteA, uint8_t aByteB, float aWeight) {
   return uint8_t(aByteA * aWeight + aByteB * (1.0f - aWeight));
 }
 
 BGRAColor InterpolateColors(BGRAColor aColor1, BGRAColor aColor2,
                             float aWeight) {
--- a/image/test/gtest/TestAnimationFrameBuffer.cpp
+++ b/image/test/gtest/TestAnimationFrameBuffer.cpp
@@ -13,17 +13,17 @@ using namespace mozilla::image;
 
 static already_AddRefed<imgFrame> CreateEmptyFrame(
     const IntSize& aSize = IntSize(1, 1),
     const IntRect& aFrameRect = IntRect(0, 0, 1, 1), bool aCanRecycle = true) {
   RefPtr<imgFrame> frame = new imgFrame();
   AnimationParams animParams{aFrameRect, FrameTimeout::Forever(),
                              /* aFrameNum */ 1, BlendMethod::OVER,
                              DisposalMethod::NOT_SPECIFIED};
-  nsresult rv = frame->InitForDecoder(aSize, SurfaceFormat::OS_RGBA, false,
+  nsresult rv = frame->InitForDecoder(aSize, SurfaceFormat::B8G8R8A8, false,
                                       Some(animParams), aCanRecycle);
   EXPECT_TRUE(NS_SUCCEEDED(rv));
   RawAccessFrameRef frameRef = frame->RawAccessRef();
   frame->SetRawAccessOnly();
   // Normally the blend animation filter would set the dirty rect, but since
   // we aren't producing an actual animation here, we need to fake it.
   frame->SetDirtyRect(aFrameRect);
   frame->Finish();
--- a/image/test/gtest/TestBlendAnimationFilter.cpp
+++ b/image/test/gtest/TestBlendAnimationFilter.cpp
@@ -35,17 +35,17 @@ RawAccessFrameRef WithBlendAnimationFilt
                                            Func aFunc) {
   DecoderTestHelper decoderHelper(aDecoder);
 
   if (!aDecoder->HasAnimation()) {
     decoderHelper.PostIsAnimated(aAnimParams.mTimeout);
   }
 
   BlendAnimationConfig blendAnim{aDecoder};
-  SurfaceConfig surfaceSink{aDecoder, aOutputSize, SurfaceFormat::OS_RGBA,
+  SurfaceConfig surfaceSink{aDecoder, aOutputSize, SurfaceFormat::B8G8R8A8,
                             false, Some(aAnimParams)};
 
   auto func = [&](Decoder* aDecoder, SurfaceFilter* aFilter) {
     aFunc(aDecoder, aFilter);
   };
 
   WithFilterPipeline(aDecoder, func, false, blendAnim, surfaceSink);
 
@@ -60,18 +60,18 @@ RawAccessFrameRef WithBlendAnimationFilt
 void AssertConfiguringBlendAnimationFilterFails(const IntRect& aFrameRect,
                                                 const IntSize& aOutputSize) {
   RefPtr<Decoder> decoder = CreateTrivialBlendingDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   AnimationParams animParams{aFrameRect, FrameTimeout::FromRawMilliseconds(0),
                              0, BlendMethod::SOURCE, DisposalMethod::KEEP};
   BlendAnimationConfig blendAnim{decoder};
-  SurfaceConfig surfaceSink{decoder, aOutputSize, SurfaceFormat::OS_RGBA, false,
-                            Some(animParams)};
+  SurfaceConfig surfaceSink{decoder, aOutputSize, SurfaceFormat::B8G8R8A8,
+                            false, Some(animParams)};
   AssertConfiguringPipelineFails(decoder, blendAnim, surfaceSink);
 }
 
 TEST(ImageBlendAnimationFilter, BlendFailsForNegativeFrameRect)
 {
   // A negative frame rect size is disallowed.
   AssertConfiguringBlendAnimationFilterFails(
       IntRect(IntPoint(0, 0), IntSize(-1, -1)), IntSize(100, 100));
--- a/image/test/gtest/TestDecodeToSurface.cpp
+++ b/image/test/gtest/TestDecodeToSurface.cpp
@@ -52,18 +52,18 @@ class DecodeToSurfaceRunnable : public R
     } else {
       mSurface = ImageOps::DecodeToSurface(
           mInputStream.forget(), nsDependentCString(mTestCase.mMimeType),
           imgIContainer::DECODE_FLAGS_DEFAULT, outputSize);
     }
     ASSERT_TRUE(mSurface != nullptr);
 
     EXPECT_TRUE(mSurface->IsDataSourceSurface());
-    EXPECT_TRUE(mSurface->GetFormat() == SurfaceFormat::OS_RGBX ||
-                mSurface->GetFormat() == SurfaceFormat::OS_RGBA);
+    EXPECT_TRUE(mSurface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
+                mSurface->GetFormat() == SurfaceFormat::B8G8R8A8);
 
     if (outputSize) {
       EXPECT_EQ(*outputSize, mSurface->GetSize());
     } else {
       EXPECT_EQ(mTestCase.mSize, mSurface->GetSize());
     }
 
     EXPECT_TRUE(IsSolidColor(mSurface, BGRAColor::Green(),
--- a/image/test/gtest/TestDecoders.cpp
+++ b/image/test/gtest/TestDecoders.cpp
@@ -65,18 +65,18 @@ static already_AddRefed<SourceSurface> C
 
   // Get the current frame, which is always the first frame of the image
   // because CreateAnonymousDecoder() forces a first-frame-only decode.
   RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
   RefPtr<SourceSurface> surface = currentFrame->GetSourceSurface();
 
   // Verify that the resulting surfaces matches our expectations.
   EXPECT_TRUE(surface->IsDataSourceSurface());
-  EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::OS_RGBX ||
-              surface->GetFormat() == SurfaceFormat::OS_RGBA);
+  EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
+              surface->GetFormat() == SurfaceFormat::B8G8R8A8);
   EXPECT_EQ(aTestCase.mOutputSize, surface->GetSize());
 
   return surface.forget();
 }
 
 static void CheckDecoderResults(const ImageTestCase& aTestCase,
                                 Decoder* aDecoder) {
   RefPtr<SourceSurface> surface = CheckDecoderState(aTestCase, aDecoder);
@@ -291,18 +291,18 @@ static void CheckAnimationDecoderResults
     EXPECT_TRUE(NS_SUCCEEDED(rv));
 
     // Check the first frame, all green.
     RawAccessFrameRef rawFrame = drawableSurface->RawAccessRef();
     RefPtr<SourceSurface> surface = rawFrame->GetSourceSurface();
 
     // Verify that the resulting surfaces matches our expectations.
     EXPECT_TRUE(surface->IsDataSourceSurface());
-    EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::OS_RGBX ||
-                surface->GetFormat() == SurfaceFormat::OS_RGBA);
+    EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
+                surface->GetFormat() == SurfaceFormat::B8G8R8A8);
     EXPECT_EQ(aTestCase.mOutputSize, surface->GetSize());
     EXPECT_TRUE(IsSolidColor(surface, framePixels[i],
                              aTestCase.mFlags & TEST_CASE_IS_FUZZY ? 1 : 0));
   }
 
   // Should be no more frames.
   nsresult rv = drawableSurface.Seek(framePixels.Length());
   EXPECT_TRUE(NS_FAILED(rv));
--- a/image/test/gtest/TestDecodersPerf.cpp
+++ b/image/test/gtest/TestDecodersPerf.cpp
@@ -49,18 +49,18 @@ static void CheckDecoderState(const Imag
 
   // Get the current frame, which is always the first frame of the image
   // because CreateAnonymousDecoder() forces a first-frame-only decode.
   RawAccessFrameRef currentFrame = aDecoder->GetCurrentFrameRef();
   RefPtr<SourceSurface> surface = currentFrame->GetSourceSurface();
 
   // Verify that the resulting surfaces matches our expectations.
   EXPECT_TRUE(surface->IsDataSourceSurface());
-  EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::OS_RGBX ||
-              surface->GetFormat() == SurfaceFormat::OS_RGBA);
+  EXPECT_TRUE(surface->GetFormat() == SurfaceFormat::B8G8R8X8 ||
+              surface->GetFormat() == SurfaceFormat::B8G8R8A8);
   EXPECT_EQ(aOutputSize, surface->GetSize());
 }
 
 template <typename Func>
 static void WithSingleChunkDecode(const ImageTestCase& aTestCase,
                                   SourceBuffer* aSourceBuffer,
                                   const Maybe<IntSize>& aOutputSize,
                                   Func aResultChecker) {
--- a/image/test/gtest/TestDeinterlacingFilter.cpp
+++ b/image/test/gtest/TestDeinterlacingFilter.cpp
@@ -22,26 +22,26 @@ template <typename Func>
 void WithDeinterlacingFilter(const IntSize& aSize, bool aProgressiveDisplay,
                              Func aFunc) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(bool(decoder));
 
   WithFilterPipeline(
       decoder, std::forward<Func>(aFunc),
       DeinterlacingConfig<uint32_t>{aProgressiveDisplay},
-      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
+      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 void AssertConfiguringDeinterlacingFilterFails(const IntSize& aSize) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   AssertConfiguringPipelineFails(
       decoder, DeinterlacingConfig<uint32_t>{/* mProgressiveDisplay = */ true},
-      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
+      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 class ImageDeinterlacingFilter : public ::testing::Test {
  protected:
   AutoInitializeImageLib mInit;
 };
 
 TEST_F(ImageDeinterlacingFilter, WritePixels100_100) {
--- a/image/test/gtest/TestDownscalingFilter.cpp
+++ b/image/test/gtest/TestDownscalingFilter.cpp
@@ -21,28 +21,28 @@ using namespace mozilla::image;
 template <typename Func>
 void WithDownscalingFilter(const IntSize& aInputSize,
                            const IntSize& aOutputSize, Func aFunc) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   WithFilterPipeline(
       decoder, std::forward<Func>(aFunc),
-      DownscalingConfig{aInputSize, SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, aOutputSize, SurfaceFormat::OS_RGBA, false});
+      DownscalingConfig{aInputSize, SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, aOutputSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 void AssertConfiguringDownscalingFilterFails(const IntSize& aInputSize,
                                              const IntSize& aOutputSize) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   AssertConfiguringPipelineFails(
-      decoder, DownscalingConfig{aInputSize, SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, aOutputSize, SurfaceFormat::OS_RGBA, false});
+      decoder, DownscalingConfig{aInputSize, SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, aOutputSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 TEST(ImageDownscalingFilter, WritePixels100_100to99_99)
 {
   WithDownscalingFilter(IntSize(100, 100), IntSize(99, 99),
                         [](Decoder* aDecoder, SurfaceFilter* aFilter) {
                           CheckWritePixels(
                               aDecoder, aFilter,
--- a/image/test/gtest/TestDownscalingFilterNoSkia.cpp
+++ b/image/test/gtest/TestDownscalingFilterNoSkia.cpp
@@ -45,11 +45,11 @@ using namespace mozilla::image;
 
 TEST(ImageDownscalingFilter, NoSkia)
 {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(bool(decoder));
 
   // Configuring a DownscalingFilter should fail without Skia.
   AssertConfiguringPipelineFails(
-      decoder, DownscalingConfig{IntSize(100, 100), SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, IntSize(50, 50), SurfaceFormat::OS_RGBA, false});
+      decoder, DownscalingConfig{IntSize(100, 100), SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, IntSize(50, 50), SurfaceFormat::B8G8R8A8, false});
 }
--- a/image/test/gtest/TestRemoveFrameRectFilter.cpp
+++ b/image/test/gtest/TestRemoveFrameRectFilter.cpp
@@ -21,27 +21,27 @@ using namespace mozilla::image;
 template <typename Func>
 void WithRemoveFrameRectFilter(const IntSize& aSize, const IntRect& aFrameRect,
                                Func aFunc) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   WithFilterPipeline(
       decoder, std::forward<Func>(aFunc), RemoveFrameRectConfig{aFrameRect},
-      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
+      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 void AssertConfiguringRemoveFrameRectFilterFails(const IntSize& aSize,
                                                  const IntRect& aFrameRect) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   AssertConfiguringPipelineFails(
       decoder, RemoveFrameRectConfig{aFrameRect},
-      SurfaceConfig{decoder, aSize, SurfaceFormat::OS_RGBA, false});
+      SurfaceConfig{decoder, aSize, SurfaceFormat::B8G8R8A8, false});
 }
 
 TEST(ImageRemoveFrameRectFilter, WritePixels100_100_to_0_0_100_100)
 {
   WithRemoveFrameRectFilter(
       IntSize(100, 100), IntRect(0, 0, 100, 100),
       [](Decoder* aDecoder, SurfaceFilter* aFilter) {
         CheckWritePixels(aDecoder, aFilter,
--- a/image/test/gtest/TestSurfacePipeIntegration.cpp
+++ b/image/test/gtest/TestSurfacePipeIntegration.cpp
@@ -92,18 +92,18 @@ TEST_F(ImageSurfacePipeIntegration, Surf
   // Test that SurfacePipe objects can be move assigned.
   pipe = TestSurfacePipeFactory::SimpleSurfacePipe();
 
   // Test that SurfacePipe objects can be initialized with a pipeline.
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   auto sink = MakeUnique<SurfaceSink>();
-  nsresult rv = sink->Configure(
-      SurfaceConfig{decoder, IntSize(100, 100), SurfaceFormat::OS_RGBA, false});
+  nsresult rv = sink->Configure(SurfaceConfig{decoder, IntSize(100, 100),
+                                              SurfaceFormat::B8G8R8A8, false});
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   pipe = TestSurfacePipeFactory::SurfacePipeFromPipeline(sink);
 
   // Test that WritePixels() gets passed through to the underlying pipeline.
   {
     uint32_t count = 0;
     auto result = pipe.WritePixels<uint32_t>([&]() {
@@ -191,18 +191,18 @@ TEST_F(ImageSurfacePipeIntegration, Dein
   auto test = [](Decoder* aDecoder, SurfaceFilter* aFilter) {
     CheckWritePixels(aDecoder, aFilter,
                      /* aOutputRect = */ Some(IntRect(0, 0, 25, 25)));
   };
 
   WithFilterPipeline(
       decoder, test,
       DeinterlacingConfig<uint32_t>{/* mProgressiveDisplay = */ true},
-      DownscalingConfig{IntSize(100, 100), SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, IntSize(25, 25), SurfaceFormat::OS_RGBA, false});
+      DownscalingConfig{IntSize(100, 100), SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, IntSize(25, 25), SurfaceFormat::B8G8R8A8, false});
 }
 
 TEST_F(ImageSurfacePipeIntegration,
        RemoveFrameRectBottomRightDownscaleWritePixels) {
   // This test case uses a frame rect that extends beyond the borders of the
   // image to the bottom and to the right. It looks roughly like this (with the
   // box made of '#'s representing the frame rect):
   //
@@ -246,18 +246,18 @@ TEST_F(ImageSurfacePipeIntegration,
                      /* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
                      /* aInputWriteRect = */ Some(IntRect(50, 50, 100, 50)),
                      /* aOutputWriteRect = */ Some(IntRect(10, 10, 10, 10)),
                      /* aFuzz = */ 0x33);
   };
 
   WithFilterPipeline(
       decoder, test, RemoveFrameRectConfig{IntRect(50, 50, 100, 100)},
-      DownscalingConfig{IntSize(100, 100), SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, IntSize(20, 20), SurfaceFormat::OS_RGBA, false});
+      DownscalingConfig{IntSize(100, 100), SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, IntSize(20, 20), SurfaceFormat::B8G8R8A8, false});
 }
 
 TEST_F(ImageSurfacePipeIntegration,
        RemoveFrameRectTopLeftDownscaleWritePixels) {
   // This test case uses a frame rect that extends beyond the borders of the
   // image to the top and to the left. It looks roughly like this (with the
   // box made of '#'s representing the frame rect):
   //
@@ -278,18 +278,18 @@ TEST_F(ImageSurfacePipeIntegration,
                      /* aInputRect = */ Some(IntRect(0, 0, 100, 100)),
                      /* aInputWriteRect = */ Some(IntRect(0, 0, 100, 100)),
                      /* aOutputWriteRect = */ Some(IntRect(0, 0, 10, 10)),
                      /* aFuzz = */ 0x21);
   };
 
   WithFilterPipeline(
       decoder, test, RemoveFrameRectConfig{IntRect(-50, -50, 100, 100)},
-      DownscalingConfig{IntSize(100, 100), SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, IntSize(20, 20), SurfaceFormat::OS_RGBA, false});
+      DownscalingConfig{IntSize(100, 100), SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, IntSize(20, 20), SurfaceFormat::B8G8R8A8, false});
 }
 
 TEST_F(ImageSurfacePipeIntegration, DeinterlaceRemoveFrameRectWritePixels) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   // Note that aInputRect is the full 100x100 size even though
   // RemoveFrameRectFilter is part of this pipeline, because deinterlacing
@@ -302,17 +302,18 @@ TEST_F(ImageSurfacePipeIntegration, Dein
                      /* aInputWriteRect = */ Some(IntRect(50, 50, 100, 100)),
                      /* aOutputWriteRect = */ Some(IntRect(50, 50, 50, 50)));
   };
 
   WithFilterPipeline(
       decoder, test,
       DeinterlacingConfig<uint32_t>{/* mProgressiveDisplay = */ true},
       RemoveFrameRectConfig{IntRect(50, 50, 100, 100)},
-      SurfaceConfig{decoder, IntSize(100, 100), SurfaceFormat::OS_RGBA, false});
+      SurfaceConfig{decoder, IntSize(100, 100), SurfaceFormat::B8G8R8A8,
+                    false});
 }
 
 TEST_F(ImageSurfacePipeIntegration,
        DeinterlaceRemoveFrameRectDownscaleWritePixels) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   auto test = [](Decoder* aDecoder, SurfaceFilter* aFilter) {
@@ -323,27 +324,28 @@ TEST_F(ImageSurfacePipeIntegration,
                      /* aOutputWriteRect = */ Some(IntRect(10, 10, 10, 10)),
                      /* aFuzz = */ 33);
   };
 
   WithFilterPipeline(
       decoder, test,
       DeinterlacingConfig<uint32_t>{/* mProgressiveDisplay = */ true},
       RemoveFrameRectConfig{IntRect(50, 50, 100, 100)},
-      DownscalingConfig{IntSize(100, 100), SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, IntSize(20, 20), SurfaceFormat::OS_RGBA, false});
+      DownscalingConfig{IntSize(100, 100), SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, IntSize(20, 20), SurfaceFormat::B8G8R8A8, false});
 }
 
 TEST_F(ImageSurfacePipeIntegration, ConfiguringHugeDeinterlacingBufferFails) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   // When DownscalingFilter is used, we may succeed in allocating an output
   // surface for huge images, because we only need to store the scaled-down
   // version of the image. However, regardless of downscaling,
   // DeinterlacingFilter needs to allocate a buffer as large as the size of the
   // input. This can cause OOMs on operating systems that allow overcommit. This
   // test makes sure that we reject such allocations.
   AssertConfiguringPipelineFails(
       decoder, DeinterlacingConfig<uint32_t>{/* mProgressiveDisplay = */ true},
-      DownscalingConfig{IntSize(60000, 60000), SurfaceFormat::OS_RGBA},
-      SurfaceConfig{decoder, IntSize(600, 600), SurfaceFormat::OS_RGBA, false});
+      DownscalingConfig{IntSize(60000, 60000), SurfaceFormat::B8G8R8A8},
+      SurfaceConfig{decoder, IntSize(600, 600), SurfaceFormat::B8G8R8A8,
+                    false});
 }
--- a/image/test/gtest/TestSurfaceSink.cpp
+++ b/image/test/gtest/TestSurfaceSink.cpp
@@ -38,17 +38,17 @@ template <Orient Orientation, typename F
 void WithSurfaceSink(Func aFunc) {
   RefPtr<Decoder> decoder = CreateTrivialDecoder();
   ASSERT_TRUE(decoder != nullptr);
 
   const bool flipVertically = Orientation == Orient::FLIP_VERTICALLY;
 
   WithFilterPipeline(decoder, std::forward<Func>(aFunc),
                      SurfaceConfig{decoder, IntSize(100, 100),
-                                   SurfaceFormat::OS_RGBA, flipVertically});
+                                   SurfaceFormat::B8G8R8A8, flipVertically});
 }
 
 void ResetForNextPass(SurfaceFilter* aSink) {
   aSink->ResetToFirstRow();
   EXPECT_FALSE(aSink->IsSurfaceFinished());
   Maybe<SurfaceInvalidRect> invalidRect = aSink->TakeInvalidRect();
   EXPECT_TRUE(invalidRect.isNothing());
 }
index 0ec91398663658a419d0cca1533b284e4b52e036..19785f5dcb84a0a3f1fd541f0de8ef9f3e8b4076
GIT binary patch
literal 40003
zc%1FpK?wjr2mnFfm(%_gyb^*a!!j*4GfI*qNs=T<k|arzBuSE_14RJ<000000002M
jev%|fk|arzBuSDaNs=U8X!^$k0000000000fClda<TTed
index 99772bada06081066c64fb962af0d1a8872d89af..c74e62fee5f8638a051fea2806a55f2ceb402ed9
GIT binary patch
literal 40002
zc%1FRK@k7|3<98qwSR^AvIPgpJpcdz00000000000000000000000000000000000
M000000000m1%i{;EC2ui