Bug 1209812 (part 6) - Convert all gfxImageFormat values to SurfaceFormat equivalents. r=jrmuizel.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 07 Jan 2016 20:57:38 -0800
changeset 316312 2e8b7fe096ec7829790bdfaa02bf31ab002356fe
parent 316311 ecafedaedd09816db5ab492f8696ea42c5ddcbec
child 316313 81d3aec1871657e0c8100905fec5d347400aa953
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1209812
milestone46.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 1209812 (part 6) - Convert all gfxImageFormat values to SurfaceFormat equivalents. r=jrmuizel. This patch: - Makes the following substitutions (plus necessary namespace qualifiers: gfxImageFormat::ARGB32 --> SurfaceFormat::A8R8G8B8_UINT32 gfxImageFormat::RGB24 --> SurfaceFormat::X8R8G8B8_UINT32 gfxImageFormat::A8 --> SurfaceFormat::A8 gfxImageFormat::RGB16_565 --> SurfaceFormat::R5G6B5_UINT16 gfxImageFormat::Unknown --> SurfaceFormat::UNKNOWN - Changes gfxImageFormat to be a typedef to gfx::SurfaceFormat. This will be removed soon. - Removes gfxCairoFormatToImageFormat() and gfxImageFormatToCairoFormat() and replace calls to them with CairoFormatToGfxFormat() and GfxFormatToCairoFormat(). - Removes ParamTraits<gfxImageFormat>. - Add namespace qualifiers to SurfaceFormat instances where necessary.
dom/base/ImageEncoder.cpp
dom/canvas/CanvasRenderingContext2D.cpp
dom/media/android/AndroidMediaReader.cpp
dom/media/webrtc/MediaEngineTabVideoSource.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/ipc/PluginInstanceChild.cpp
dom/plugins/ipc/PluginInstanceParent.cpp
gfx/2d/Types.h
gfx/gl/GLReadTexImageHelper.h
gfx/gl/GLTextureImage.h
gfx/gl/SharedSurfaceGLX.cpp
gfx/gl/TextureImageCGL.h
gfx/gl/TextureImageEGL.h
gfx/ipc/GfxMessageUtils.h
gfx/ipc/SharedDIBSurface.cpp
gfx/layers/ImageContainer.cpp
gfx/layers/ImageDataSerializer.cpp
gfx/layers/basic/BasicLayerManager.cpp
gfx/layers/ipc/SharedRGBImage.cpp
gfx/layers/opengl/CompositorOGL.cpp
gfx/tests/gtest/TestTextures.cpp
gfx/tests/gtest/gfxSurfaceRefCountTest.cpp
gfx/thebes/gfx2DGlue.h
gfx/thebes/gfxASurface.cpp
gfx/thebes/gfxAlphaRecovery.cpp
gfx/thebes/gfxAlphaRecoverySSE2.cpp
gfx/thebes/gfxAndroidPlatform.cpp
gfx/thebes/gfxImageSurface.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxQPainterSurface.cpp
gfx/thebes/gfxQtPlatform.cpp
gfx/thebes/gfxQuartzSurface.cpp
gfx/thebes/gfxTypes.h
gfx/thebes/gfxUtils.cpp
gfx/thebes/gfxUtils.h
gfx/thebes/gfxWindowsSurface.cpp
gfx/thebes/gfxWindowsSurface.h
gfx/thebes/gfxXlibNativeRenderer.cpp
gfx/thebes/gfxXlibSurface.cpp
gfx/ycbcr/YCbCrUtils.cpp
widget/android/AndroidGraphicBuffer.cpp
widget/cocoa/nsDeviceContextSpecX.mm
widget/nsDeviceContextSpecProxy.cpp
widget/windows/TaskbarPreview.cpp
widget/windows/nsWindow.cpp
widget/windows/nsWindowGfx.cpp
--- a/dom/base/ImageEncoder.cpp
+++ b/dom/base/ImageEncoder.cpp
@@ -390,17 +390,17 @@ ImageEncoder::ExtractDataInternal(const 
   } else if (aImage) {
     // It is safe to convert PlanarYCbCr format from YUV to RGB off-main-thread.
     // Other image formats could have problem to convert format off-main-thread.
     // So here it uses a help function GetBRGADataSourceSurfaceSync() to convert
     // format on main thread.
     if (aImage->GetFormat() == ImageFormat::PLANAR_YCBCR) {
       nsTArray<uint8_t> data;
       layers::PlanarYCbCrImage* ycbcrImage = static_cast<layers::PlanarYCbCrImage*> (aImage);
-      gfxImageFormat format = gfxImageFormat::ARGB32;
+      gfxImageFormat format = SurfaceFormat::A8R8G8B8_UINT32;
       uint32_t stride = GetAlignedStride<16>(aSize.width * 4);
       size_t length = BufferSizeFromStrideAndHeight(stride, aSize.height);
       data.SetCapacity(length);
 
       gfxUtils::ConvertYCbCrToRGB(*ycbcrImage->GetData(),
                                   format,
                                   aSize,
                                   data.Elements(),
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -5418,17 +5418,17 @@ CanvasRenderingContext2D::PutImageData_e
   uint32_t len = w * h * 4;
   if (dataLen != len) {
     return NS_ERROR_DOM_INVALID_STATE_ERR;
   }
 
   uint32_t copyWidth = dirtyRect.Width();
   uint32_t copyHeight = dirtyRect.Height();
   RefPtr<gfxImageSurface> imgsurf = new gfxImageSurface(gfx::IntSize(copyWidth, copyHeight),
-                                                          gfxImageFormat::ARGB32,
+                                                          SurfaceFormat::A8R8G8B8_UINT32,
                                                           false);
   if (!imgsurf || imgsurf->CairoStatus()) {
     return NS_ERROR_FAILURE;
   }
 
   uint32_t copyX = dirtyRect.x - x;
   uint32_t copyY = dirtyRect.y - y;
   //uint8_t *src = aArray->Data();
--- a/dom/media/android/AndroidMediaReader.cpp
+++ b/dom/media/android/AndroidMediaReader.cpp
@@ -362,17 +362,17 @@ AndroidMediaReader::ImageBufferCallback:
     return nullptr;
   }
 
   RefPtr<Image> image;
   switch(aColorFormat) {
     case MPAPI::RGB565:
       image = mozilla::layers::CreateSharedRGBImage(mImageContainer,
                                                     nsIntSize(aWidth, aHeight),
-                                                    gfxImageFormat::RGB16_565);
+                                                    SurfaceFormat::R5G6B5_UINT16);
       if (!image) {
         NS_WARNING("Could not create rgb image");
         return nullptr;
       }
 
       mImage = image;
       return image->GetBuffer();
     case MPAPI::I420:
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -239,17 +239,17 @@ MediaEngineTabVideoSource::Draw() {
       const float scaleWidth = (float)mBufWidthMax / (float)deviceWidth;
       const float scaleHeight = (float)mBufHeightMax / (float)deviceHeight;
       const float scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight;
 
       size = IntSize((int)(scale * deviceWidth), (int)(scale * deviceHeight));
     }
   }
 
-  gfxImageFormat format = gfxImageFormat::RGB24;
+  gfxImageFormat format = SurfaceFormat::X8R8G8B8_UINT32;
   uint32_t stride = gfxASurface::FormatStrideForWidth(format, size.width);
 
   if (mDataSize < static_cast<size_t>(stride * size.height)) {
     mDataSize = stride * size.height;
     mData = static_cast<unsigned char*>(malloc(mDataSize));
   }
   if (!mData) {
     return;
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -2917,17 +2917,17 @@ void nsPluginInstanceOwner::Paint(gfxCon
 #ifdef ANP_BITMAP_DRAWING_MODEL
   static RefPtr<gfxImageSurface> pluginSurface;
 
   if (pluginSurface == nullptr ||
       aFrameRect.width  != pluginSurface->Width() ||
       aFrameRect.height != pluginSurface->Height()) {
 
     pluginSurface = new gfxImageSurface(gfx::IntSize(aFrameRect.width, aFrameRect.height),
-                                        gfxImageFormat::ARGB32);
+                                        SurfaceFormat::A8R8G8B8_UINT32);
     if (!pluginSurface)
       return;
   }
 
   // Clears buffer.  I think this is needed.
   gfxUtils::ClearThebesSurface(pluginSurface);
 
   ANPEvent event;
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -3062,25 +3062,25 @@ PluginInstanceChild::CreateOptSurface(vo
     MOZ_ASSERT(mSurfaceType != gfxSurfaceType::Max,
                "Need a valid surface type here");
     NS_ASSERTION(!mCurrentSurface, "mCurrentSurfaceActor can get out of sync.");
 
     RefPtr<gfxASurface> retsurf;
     // Use an opaque surface unless we're transparent and *don't* have
     // a background to source from.
     gfxImageFormat format =
-        (mIsTransparent && !mBackground) ? gfxImageFormat::ARGB32 :
-                                           gfxImageFormat::RGB24;
+        (mIsTransparent && !mBackground) ? SurfaceFormat::A8R8G8B8_UINT32 :
+                                           SurfaceFormat::X8R8G8B8_UINT32;
 
 #ifdef MOZ_X11
     Display* dpy = mWsInfo.display;
     Screen* screen = DefaultScreenOfDisplay(dpy);
-    if (format == gfxImageFormat::RGB24 &&
+    if (format == SurfaceFormat::X8R8G8B8_UINT32 &&
         DefaultDepth(dpy, DefaultScreen(dpy)) == 16) {
-        format = gfxImageFormat::RGB16_565;
+        format = SurfaceFormat::R5G6B5_UINT16;
     }
 
     if (mSurfaceType == gfxSurfaceType::Xlib) {
         if (!mIsTransparent  || mBackground) {
             Visual* defaultVisual = DefaultVisualOfScreen(screen);
             mCurrentSurface =
                 gfxXlibSurface::Create(screen, defaultVisual,
                                        IntSize(mWindow.width, mWindow.height));
@@ -3512,17 +3512,17 @@ PluginInstanceChild::PaintRectWithAlphaE
     // If |aSurface| can be used to paint and can have alpha values
     // recovered directly to it, do that to save a tmp surface and
     // copy.
     bool useSurfaceSubimageForBlack = false;
     if (gfxSurfaceType::Image == aSurface->GetType()) {
         gfxImageSurface* surfaceAsImage =
             static_cast<gfxImageSurface*>(aSurface);
         useSurfaceSubimageForBlack =
-            (surfaceAsImage->Format() == gfxImageFormat::ARGB32);
+            (surfaceAsImage->Format() == SurfaceFormat::A8R8G8B8_UINT32);
         // If we're going to use a subimage, nudge the rect so that we
         // can use optimal alpha recovery.  If we're not using a
         // subimage, the temporaries should automatically get
         // fast-path alpha recovery so we don't need to do anything.
         if (useSurfaceSubimageForBlack) {
             rect =
                 gfxAlphaRecovery::AlignRectForSubimageRecovery(aRect,
                                                                surfaceAsImage);
@@ -3531,17 +3531,17 @@ PluginInstanceChild::PaintRectWithAlphaE
 
     RefPtr<gfxImageSurface> whiteImage;
     RefPtr<gfxImageSurface> blackImage;
     gfxRect targetRect(rect.x, rect.y, rect.width, rect.height);
     IntSize targetSize(rect.width, rect.height);
     gfxPoint deviceOffset = -targetRect.TopLeft();
 
     // We always use a temporary "white image"
-    whiteImage = new gfxImageSurface(targetSize, gfxImageFormat::RGB24);
+    whiteImage = new gfxImageSurface(targetSize, SurfaceFormat::X8R8G8B8_UINT32);
     if (whiteImage->CairoStatus()) {
         return;
     }
 
 #ifdef XP_WIN
     // On windows, we need an HDC and so can't paint directly to
     // vanilla image surfaces.  Bifurcate this painting code so that
     // we don't accidentally attempt that.
@@ -3572,17 +3572,17 @@ PluginInstanceChild::PaintRectWithAlphaE
     whiteImage->SetDeviceOffset(deviceOffset);
     PaintRectToSurface(rect, whiteImage, Color(1.f, 1.f, 1.f));
 
     if (useSurfaceSubimageForBlack) {
         gfxImageSurface *surface = static_cast<gfxImageSurface*>(aSurface);
         blackImage = surface->GetSubimage(targetRect);
     } else {
         blackImage = new gfxImageSurface(targetSize,
-                                         gfxImageFormat::ARGB32);
+                                         SurfaceFormat::A8R8G8B8_UINT32);
     }
 
     // Paint onto black background
     blackImage->SetDeviceOffset(deviceOffset);
     PaintRectToSurface(rect, blackImage, Color(0.f, 0.f, 0.f));
 #endif
 
     MOZ_ASSERT(whiteImage && blackImage, "Didn't paint enough!");
--- a/dom/plugins/ipc/PluginInstanceParent.cpp
+++ b/dom/plugins/ipc/PluginInstanceParent.cpp
@@ -1209,17 +1209,17 @@ PluginInstanceParent::CreateBackground(c
 
 #elif defined(XP_WIN)
     // We have chosen to create an unsafe surface in which the plugin
     // can read from the region while we're writing to it.
     mBackground =
         gfxSharedImageSurface::CreateUnsafe(
             this,
             mozilla::gfx::IntSize(aSize.width, aSize.height),
-            gfxImageFormat::RGB24);
+            mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32);
     return !!mBackground;
 #else
     return false;
 #endif
 }
 
 void
 PluginInstanceParent::DestroyBackground()
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -337,16 +337,19 @@ enum class JobStatus {
     Wait,
     Yield,
     Error
 };
 
 } // namespace gfx
 } // namespace mozilla
 
+// XXX: temporary
+typedef mozilla::gfx::SurfaceFormat gfxImageFormat;
+
 #if defined(XP_WIN) && defined(MOZ_GFX)
 #ifdef GFX2D_INTERNAL
 #define GFX2D_API __declspec(dllexport)
 #else
 #define GFX2D_API __declspec(dllimport)
 #endif
 #else
 #define GFX2D_API
--- a/gfx/gl/GLReadTexImageHelper.h
+++ b/gfx/gl/GLReadTexImageHelper.h
@@ -53,20 +53,20 @@ class GLReadTexImageHelper final
 
 public:
 
     explicit GLReadTexImageHelper(GLContext* gl);
     ~GLReadTexImageHelper();
 
     /**
       * Read the image data contained in aTexture, and return it as an ImageSurface.
-      * If GL_RGBA is given as the format, a gfxImageFormat::ARGB32 surface is returned.
+      * If GL_RGBA is given as the format, a SurfaceFormat::A8R8G8B8_UINT32 surface is returned.
       * Not implemented yet:
-      * If GL_RGB is given as the format, a gfxImageFormat::RGB24 surface is returned.
-      * If GL_LUMINANCE is given as the format, a gfxImageFormat::A8 surface is returned.
+      * If GL_RGB is given as the format, a SurfaceFormat::X8R8G8B8_UINT32 surface is returned.
+      * If GL_LUMINANCE is given as the format, a SurfaceFormat::A8 surface is returned.
       *
       * THIS IS EXPENSIVE.  It is ridiculously expensive.  Only do this
       * if you absolutely positively must, and never in any performance
       * critical path.
       *
       * NOTE: aShaderProgram is really mozilla::layers::ShaderProgramType. It is
       * passed as int to eliminate including LayerManagerOGLProgram.h here.
       */
--- a/gfx/gl/GLTextureImage.h
+++ b/gfx/gl/GLTextureImage.h
@@ -207,17 +207,17 @@ protected:
      * After the ctor, the TextureImage is invalid.  Implementations
      * must allocate resources successfully before returning the new
      * TextureImage from GLContext::CreateTextureImage().  That is,
      * clients must not be given partially-constructed TextureImages.
      */
     TextureImage(const gfx::IntSize& aSize,
                  GLenum aWrapMode, ContentType aContentType,
                  Flags aFlags = NoFlags,
-                 ImageFormat aImageFormat = gfxImageFormat::Unknown);
+                 ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
 
     // Protected destructor, to discourage deletion outside of Release():
     virtual ~TextureImage() {}
 
     virtual gfx::IntRect GetSrcTileRect();
 
     gfx::IntSize mSize;
     GLenum mWrapMode;
@@ -243,17 +243,17 @@ public:
     virtual ~BasicTextureImage();
 
     BasicTextureImage(GLuint aTexture,
                       const gfx::IntSize& aSize,
                       GLenum aWrapMode,
                       ContentType aContentType,
                       GLContext* aContext,
                       TextureImage::Flags aFlags = TextureImage::NoFlags,
-                      TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
+                      TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
 
     virtual void BindTexture(GLenum aTextureUnit);
 
     virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
     virtual void GetUpdateRegion(nsIntRegion& aForRegion);
     virtual void EndUpdate();
     virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0));
     virtual GLuint GetTextureID() { return mTexture; }
@@ -293,17 +293,17 @@ protected:
 class TiledTextureImage final
     : public TextureImage
 {
 public:
     TiledTextureImage(GLContext* aGL,
                       gfx::IntSize aSize,
                       TextureImage::ContentType,
                       TextureImage::Flags aFlags = TextureImage::NoFlags,
-                      TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
+                      TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
     ~TiledTextureImage();
     void DumpDiv();
     virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
     virtual void GetUpdateRegion(nsIntRegion& aForRegion);
     virtual void EndUpdate();
     virtual void Resize(const gfx::IntSize& aSize);
     virtual uint32_t GetTileCount();
     virtual void BeginBigImageIteration();
@@ -343,17 +343,17 @@ protected:
  * In doubt, use GLContext::CreateTextureImage instead.
  */
 already_AddRefed<TextureImage>
 CreateBasicTextureImage(GLContext* aGL,
                         const gfx::IntSize& aSize,
                         TextureImage::ContentType aContentType,
                         GLenum aWrapMode,
                         TextureImage::Flags aFlags,
-                        TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
+                        TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
 
 /**
   * Return a valid, allocated TextureImage of |aSize| with
   * |aContentType|.  If |aContentType| is COLOR, |aImageFormat| can be used
   * to hint at the preferred RGB format, however it is not necessarily
   * respected.  The TextureImage's texture is configured to use
   * |aWrapMode| (usually GL_CLAMP_TO_EDGE or GL_REPEAT) and by
   * default, GL_LINEAR filtering.  Specify
@@ -368,14 +368,14 @@ CreateBasicTextureImage(GLContext* aGL,
   * crashy) behavior.
   */
 already_AddRefed<TextureImage>
 CreateTextureImage(GLContext* gl,
                    const gfx::IntSize& aSize,
                    TextureImage::ContentType aContentType,
                    GLenum aWrapMode,
                    TextureImage::Flags aFlags = TextureImage::NoFlags,
-                   TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
+                   TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
 
 } // namespace gl
 } // namespace mozilla
 
 #endif /* GLTEXTUREIMAGE_H_ */
--- a/gfx/gl/SharedSurfaceGLX.cpp
+++ b/gfx/gl/SharedSurfaceGLX.cpp
@@ -24,17 +24,17 @@ SharedSurface_GLXDrawable::Create(GLCont
                                   const SurfaceCaps& caps,
                                   const gfx::IntSize& size,
                                   bool deallocateClient,
                                   bool inSameProcess)
 {
     UniquePtr<SharedSurface_GLXDrawable> ret;
     Display* display = DefaultXDisplay();
     Screen* screen = XDefaultScreenOfDisplay(display);
-    Visual* visual = gfxXlibSurface::FindVisual(screen, gfxImageFormat::ARGB32);
+    Visual* visual = gfxXlibSurface::FindVisual(screen, gfx::SurfaceFormat::A8R8G8B8_UINT32);
 
     RefPtr<gfxXlibSurface> surf = gfxXlibSurface::Create(screen, visual, size);
     if (!deallocateClient)
         surf->ReleasePixmap();
 
     ret.reset(new SharedSurface_GLXDrawable(prodGL, size, inSameProcess, surf));
     return Move(ret);
 }
--- a/gfx/gl/TextureImageCGL.h
+++ b/gfx/gl/TextureImageCGL.h
@@ -19,17 +19,17 @@ class TextureImageCGL : public BasicText
 public:
 
     TextureImageCGL(GLuint aTexture,
                     const gfx::IntSize& aSize,
                     GLenum aWrapMode,
                     ContentType aContentType,
                     GLContext* aContext,
                     TextureImage::Flags aFlags = TextureImage::NoFlags,
-                    TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
+                    TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
 
     ~TextureImageCGL();
 
 protected:
     bool FinishedSurfaceUpdate();
 
     void FinishedSurfaceUpload();
 
--- a/gfx/gl/TextureImageEGL.h
+++ b/gfx/gl/TextureImageEGL.h
@@ -17,17 +17,17 @@ class TextureImageEGL final
 public:
     TextureImageEGL(GLuint aTexture,
                     const gfx::IntSize& aSize,
                     GLenum aWrapMode,
                     ContentType aContentType,
                     GLContext* aContext,
                     Flags aFlags = TextureImage::NoFlags,
                     TextureState aTextureState = Created,
-                    TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
+                    TextureImage::ImageFormat aImageFormat = SurfaceFormat::UNKNOWN);
 
     virtual ~TextureImageEGL();
 
     virtual void GetUpdateRegion(nsIntRegion& aForRegion);
 
     virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
 
     virtual void EndUpdate();
--- a/gfx/ipc/GfxMessageUtils.h
+++ b/gfx/ipc/GfxMessageUtils.h
@@ -225,24 +225,16 @@ template <>
 struct ParamTraits<mozilla::layers::ScaleMode>
   : public ContiguousEnumSerializer<
              mozilla::layers::ScaleMode,
              mozilla::layers::ScaleMode::SCALE_NONE,
              mozilla::layers::ScaleMode::SENTINEL>
 {};
 
 template <>
-struct ParamTraits<gfxImageFormat>
-  : public ContiguousEnumSerializer<
-             gfxImageFormat,
-             gfxImageFormat::ARGB32,
-             gfxImageFormat::Unknown>
-{};
-
-template <>
 struct ParamTraits<mozilla::gfx::AttributeName>
   : public ContiguousEnumSerializer<
              mozilla::gfx::AttributeName,
              mozilla::gfx::eBlendBlendmode,
              mozilla::gfx::eLastAttributeName>
 {};
 
 template <>
@@ -282,18 +274,18 @@ struct ParamTraits<mozilla::layers::Diag
              mozilla::layers::DiagnosticTypes,
              mozilla::layers::DiagnosticTypes::ALL_BITS>
 {};
 
 /*
 template <>
 struct ParamTraits<mozilla::PixelFormat>
   : public EnumSerializer<mozilla::PixelFormat,
-                          gfxImageFormat::ARGB32,
-                          gfxImageFormat::Unknown>
+                          SurfaceFormat::A8R8G8B8_UINT32,
+                          SurfaceFormat::UNKNOWN>
 {};
 */
 
 template<>
 struct ParamTraits<mozilla::gfx::Color>
 {
   typedef mozilla::gfx::Color paramType;
 
--- a/gfx/ipc/SharedDIBSurface.cpp
+++ b/gfx/ipc/SharedDIBSurface.cpp
@@ -38,17 +38,17 @@ SharedDIBSurface::Attach(Handle aHandle,
 
 void
 SharedDIBSurface::InitSurface(uint32_t aWidth, uint32_t aHeight,
                               bool aTransparent)
 {
   long stride = long(aWidth * SharedDIB::kBytesPerPixel);
   unsigned char* data = reinterpret_cast<unsigned char*>(mSharedDIB.GetBits());
 
-  gfxImageFormat format = aTransparent ? gfxImageFormat::ARGB32 : gfxImageFormat::RGB24;
+  gfxImageFormat format = aTransparent ? SurfaceFormat::A8R8G8B8_UINT32 : SurfaceFormat::X8R8G8B8_UINT32;
 
   gfxImageSurface::InitWithData(data, IntSize(aWidth, aHeight),
                                 stride, format);
 
   cairo_surface_set_user_data(mSurface, &SHAREDDIB_KEY, this, nullptr);
 }
 
 bool
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -373,17 +373,17 @@ ImageContainer::NotifyCompositeInternal(
   if (!aNotification.imageTimeStamp().IsNull()) {
     mPaintDelay = aNotification.firstCompositeTimeStamp() -
         aNotification.imageTimeStamp();
   }
 }
 
 PlanarYCbCrImage::PlanarYCbCrImage()
   : Image(nullptr, ImageFormat::PLANAR_YCBCR)
-  , mOffscreenFormat(gfxImageFormat::Unknown)
+  , mOffscreenFormat(SurfaceFormat::UNKNOWN)
   , mBufferSize(0)
 {
 }
 
 RecyclingPlanarYCbCrImage::~RecyclingPlanarYCbCrImage()
 {
   if (mBuffer) {
     mRecycleBin->RecycleBuffer(Move(mBuffer), mBufferSize);
@@ -475,17 +475,17 @@ bool
 RecyclingPlanarYCbCrImage::SetData(const Data &aData)
 {
   return CopyData(aData);
 }
 
 gfxImageFormat
 PlanarYCbCrImage::GetOffscreenFormat()
 {
-  return mOffscreenFormat == gfxImageFormat::Unknown ?
+  return mOffscreenFormat == SurfaceFormat::UNKNOWN ?
     gfxPlatform::GetPlatform()->GetOffscreenFormat() :
     mOffscreenFormat;
 }
 
 bool
 PlanarYCbCrImage::SetDataNoCopy(const Data &aData)
 {
   mData = aData;
--- a/gfx/layers/ImageDataSerializer.cpp
+++ b/gfx/layers/ImageDataSerializer.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 "ImageDataSerializer.h"
-#include <string.h>                     // for memcpy
 #include "gfx2DGlue.h"                  // for SurfaceFormatToImageFormat
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/gfx/2D.h"             // for DataSourceSurface, Factory
 #include "mozilla/gfx/Logging.h"        // for gfxDebug
 #include "mozilla/gfx/Tools.h"          // for GetAlignedStride, etc
 #include "mozilla/gfx/Types.h"
 #include "mozilla/mozalloc.h"           // for operator delete, etc
--- a/gfx/layers/basic/BasicLayerManager.cpp
+++ b/gfx/layers/basic/BasicLayerManager.cpp
@@ -784,17 +784,17 @@ BasicLayerManager_Matrix3DToPixman(const
 
 static void
 Transform(const gfxImageSurface* aDest,
           RefPtr<DataSourceSurface> aSrc,
           const Matrix4x4& aTransform,
           gfxPoint aDestOffset)
 {
   IntSize destSize = aDest->GetSize();
-  pixman_image_t* dest = pixman_image_create_bits(aDest->Format() == gfxImageFormat::ARGB32 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
+  pixman_image_t* dest = pixman_image_create_bits(aDest->Format() == SurfaceFormat::A8R8G8B8_UINT32 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
                                                   destSize.width,
                                                   destSize.height,
                                                   (uint32_t*)aDest->Data(),
                                                   aDest->Stride());
 
   IntSize srcSize = aSrc->GetSize();
   pixman_image_t* src = pixman_image_create_bits(aSrc->GetFormat() == SurfaceFormat::B8G8R8A8 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
                                                  srcSize.width,
@@ -860,17 +860,17 @@ Transform3D(RefPtr<SourceSurface> aSourc
                 ToRectDouble(aBounds),
                 ToRectDouble(aDest->GetClipExtents())));
   aDestRect.RoundOut();
 
   // Create a surface the size of the transformed object.
   RefPtr<gfxASurface> dest = aDest->CurrentSurface();
   RefPtr<gfxImageSurface> destImage = new gfxImageSurface(IntSize(aDestRect.width,
                                                                     aDestRect.height),
-                                                            gfxImageFormat::ARGB32);
+                                                            SurfaceFormat::A8R8G8B8_UINT32);
   gfxPoint offset = aDestRect.TopLeft();
 
   // Include a translation to the correct origin.
   Matrix4x4 translation = Matrix4x4::Translation(aBounds.x, aBounds.y, 0);
 
   // Transform the content and offset it such that the content begins at the origin.
   Transform(destImage, aSource->GetDataSurface(), translation * aTransform, offset);
 
--- a/gfx/layers/ipc/SharedRGBImage.cpp
+++ b/gfx/layers/ipc/SharedRGBImage.cpp
@@ -26,19 +26,19 @@
 namespace mozilla {
 namespace layers {
 
 already_AddRefed<Image>
 CreateSharedRGBImage(ImageContainer *aImageContainer,
                      gfx::IntSize aSize,
                      gfxImageFormat aImageFormat)
 {
-  NS_ASSERTION(aImageFormat == gfxImageFormat::ARGB32 ||
-               aImageFormat == gfxImageFormat::RGB24 ||
-               aImageFormat == gfxImageFormat::RGB16_565,
+  NS_ASSERTION(aImageFormat == gfx::SurfaceFormat::A8R8G8B8_UINT32 ||
+               aImageFormat == gfx::SurfaceFormat::X8R8G8B8_UINT32 ||
+               aImageFormat == gfx::SurfaceFormat::R5G6B5_UINT16,
                "RGB formats supported only");
 
   if (!aImageContainer) {
     NS_WARNING("No ImageContainer to allocate SharedRGBImage");
     return nullptr;
   }
 
   RefPtr<SharedRGBImage> rgbImage = aImageContainer->CreateSharedRGBImage();
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -110,17 +110,17 @@ CompositorOGL::CreateContext()
     context = gl::GLContextProviderEGL::CreateForWindow(mWidget, false);
   }
 #endif
 
   // Allow to create offscreen GL context for main Layer Manager
   if (!context && gfxEnv::LayersPreferOffscreen()) {
     SurfaceCaps caps = SurfaceCaps::ForRGB();
     caps.preserve = false;
-    caps.bpp16 = gfxPlatform::GetPlatform()->GetOffscreenFormat() == gfxImageFormat::RGB16_565;
+    caps.bpp16 = gfxPlatform::GetPlatform()->GetOffscreenFormat() == SurfaceFormat::R5G6B5_UINT16;
 
     context = GLContextProvider::CreateOffscreen(mSurfaceSize,
                                                  caps, CreateContextFlags::REQUIRE_COMPAT_PROFILE);
   }
 
   if (!context) {
     context = gl::GLContextProvider::CreateForWindow(mWidget,
                 gfxPlatform::GetPlatform()->RequiresAcceleratedGLContextForCompositorOGL());
--- a/gfx/tests/gtest/TestTextures.cpp
+++ b/gfx/tests/gtest/TestTextures.cpp
@@ -208,19 +208,19 @@ void TestTextureClientYCbCr(TextureClien
 }
 
 } // namespace layers
 } // namespace mozilla
 
 TEST(Layers, TextureSerialization) {
   // the test is run on all the following image formats
   gfxImageFormat formats[3] = {
-    gfxImageFormat::ARGB32,
-    gfxImageFormat::RGB24,
-    gfxImageFormat::A8,
+    SurfaceFormat::A8R8G8B8_UINT32,
+    SurfaceFormat::X8R8G8B8_UINT32,
+    SurfaceFormat::A8,
   };
 
   for (int f = 0; f < 3; ++f) {
     RefPtr<gfxImageSurface> surface = new gfxImageSurface(IntSize(400,300), formats[f]);
     SetupSurface(surface.get());
     AssertSurfacesEqual(surface, surface);
 
     auto texData = BufferTextureData::Create(surface->GetSize(),
@@ -235,19 +235,19 @@ TEST(Layers, TextureSerialization) {
 
     TestTextureClientSurface(client, surface);
 
     // XXX - Test more texture client types.
   }
 }
 
 TEST(Layers, TextureYCbCrSerialization) {
-  RefPtr<gfxImageSurface> ySurface = new gfxImageSurface(IntSize(400,300), gfxImageFormat::A8);
-  RefPtr<gfxImageSurface> cbSurface = new gfxImageSurface(IntSize(200,150), gfxImageFormat::A8);
-  RefPtr<gfxImageSurface> crSurface = new gfxImageSurface(IntSize(200,150), gfxImageFormat::A8);
+  RefPtr<gfxImageSurface> ySurface = new gfxImageSurface(IntSize(400,300), SurfaceFormat::A8);
+  RefPtr<gfxImageSurface> cbSurface = new gfxImageSurface(IntSize(200,150), SurfaceFormat::A8);
+  RefPtr<gfxImageSurface> crSurface = new gfxImageSurface(IntSize(200,150), SurfaceFormat::A8);
   SetupSurface(ySurface.get());
   SetupSurface(cbSurface.get());
   SetupSurface(crSurface.get());
 
   PlanarYCbCrData clientData;
   clientData.mYChannel = ySurface->Data();
   clientData.mCbChannel = cbSurface->Data();
   clientData.mCrChannel = crSurface->Data();
--- a/gfx/tests/gtest/gfxSurfaceRefCountTest.cpp
+++ b/gfx/tests/gtest/gfxSurfaceRefCountTest.cpp
@@ -39,17 +39,17 @@ SurfaceDestroyNotifier (void *data) {
     *(int *)data = 1;
 }
 
 int
 TestNewSurface () {
     int failures = 0;
     int destroyed = 0;
 
-    RefPtr<gfxASurface> s = new gfxImageSurface (mozilla::gfx::IntSize(10, 10), gfxImageFormat::ARGB32);
+    RefPtr<gfxASurface> s = new gfxImageSurface (mozilla::gfx::IntSize(10, 10), SurfaceFormat::A8R8G8B8_UINT32);
     cairo_surface_t *cs = s->CairoSurface();
 
     cairo_surface_set_user_data (cs, &destruction_key, &destroyed, SurfaceDestroyNotifier);
 
     failures += CheckInt (GetASurfaceRefCount(s.get()), 1);
     failures += CheckInt (cairo_surface_get_reference_count(cs), 1);
     failures += CheckInt (destroyed, 0);
 
--- a/gfx/thebes/gfx2DGlue.h
+++ b/gfx/thebes/gfx2DGlue.h
@@ -75,41 +75,41 @@ inline gfxRect ThebesRect(const RectDoub
 {
   return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
 }
 
 inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat)
 {
   switch (aFormat) {
   case SurfaceFormat::B8G8R8A8:
-    return gfxImageFormat::ARGB32;
+    return SurfaceFormat::A8R8G8B8_UINT32;
   case SurfaceFormat::B8G8R8X8:
-    return gfxImageFormat::RGB24;
+    return SurfaceFormat::X8R8G8B8_UINT32;
   case SurfaceFormat::R5G6B5_UINT16:
-    return gfxImageFormat::RGB16_565;
+    return SurfaceFormat::R5G6B5_UINT16;
   case SurfaceFormat::A8:
-    return gfxImageFormat::A8;
+    return SurfaceFormat::A8;
   default:
-    return gfxImageFormat::Unknown;
+    return SurfaceFormat::UNKNOWN;
   }
 }
 
 inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat)
 {
   switch (aFormat) {
-  case gfxImageFormat::ARGB32:
+  case SurfaceFormat::A8R8G8B8_UINT32:
     return SurfaceFormat::B8G8R8A8;
-  case gfxImageFormat::RGB24:
+  case SurfaceFormat::X8R8G8B8_UINT32:
     return SurfaceFormat::B8G8R8X8;
-  case gfxImageFormat::RGB16_565:
+  case SurfaceFormat::R5G6B5_UINT16:
     return SurfaceFormat::R5G6B5_UINT16;
-  case gfxImageFormat::A8:
+  case SurfaceFormat::A8:
     return SurfaceFormat::A8;
   default:
-  case gfxImageFormat::Unknown:
+  case SurfaceFormat::UNKNOWN:
     return SurfaceFormat::B8G8R8A8;
   }
 }
 
 inline gfxContentType ContentForFormat(const SurfaceFormat &aFormat)
 {
   switch (aFormat) {
   case SurfaceFormat::R5G6B5_UINT16:
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -339,32 +339,32 @@ gfxASurface::CreateSimilarSurface(gfxCon
     cairo_surface_destroy(surface);
     return result.forget();
 }
 
 already_AddRefed<gfxImageSurface>
 gfxASurface::GetAsReadableARGB32ImageSurface()
 {
     RefPtr<gfxImageSurface> imgSurface = GetAsImageSurface();
-    if (!imgSurface || imgSurface->Format() != gfxImageFormat::ARGB32) {
+    if (!imgSurface || imgSurface->Format() != SurfaceFormat::A8R8G8B8_UINT32) {
       imgSurface = CopyToARGB32ImageSurface();
     }
     return imgSurface.forget();
 }
 
 already_AddRefed<gfxImageSurface>
 gfxASurface::CopyToARGB32ImageSurface()
 {
     if (!mSurface || !mSurfaceValid) {
       return nullptr;
     }
 
     const IntSize size = GetSize();
     RefPtr<gfxImageSurface> imgSurface =
-        new gfxImageSurface(size, gfxImageFormat::ARGB32);
+        new gfxImageSurface(size, SurfaceFormat::A8R8G8B8_UINT32);
 
     RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(imgSurface, IntSize(size.width, size.height));
     RefPtr<SourceSurface> source = gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(dt, this);
 
     dt->CopySurface(source, IntRect(0, 0, size.width, size.height), IntPoint());
 
     return imgSurface.forget();
 }
@@ -420,17 +420,17 @@ gfxASurface::CheckSurfaceSize(const IntS
 
     return true;
 }
 
 /* static */
 int32_t
 gfxASurface::FormatStrideForWidth(gfxImageFormat format, int32_t width)
 {
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
+    cairo_format_t cformat = GfxFormatToCairoFormat(format);
     return cairo_format_stride_for_width(cformat, (int)width);
 }
 
 nsresult
 gfxASurface::BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName)
 {
     return NS_OK;
 }
@@ -458,25 +458,25 @@ gfxASurface::EndPage()
 {
     return NS_OK;
 }
 
 gfxContentType
 gfxASurface::ContentFromFormat(gfxImageFormat format)
 {
     switch (format) {
-        case gfxImageFormat::ARGB32:
+        case SurfaceFormat::A8R8G8B8_UINT32:
             return gfxContentType::COLOR_ALPHA;
-        case gfxImageFormat::RGB24:
-        case gfxImageFormat::RGB16_565:
+        case SurfaceFormat::X8R8G8B8_UINT32:
+        case SurfaceFormat::R5G6B5_UINT16:
             return gfxContentType::COLOR;
-        case gfxImageFormat::A8:
+        case SurfaceFormat::A8:
             return gfxContentType::ALPHA;
 
-        case gfxImageFormat::Unknown:
+        case SurfaceFormat::UNKNOWN:
         default:
             return gfxContentType::COLOR;
     }
 }
 
 void
 gfxASurface::SetSubpixelAntialiasingEnabled(bool aEnabled)
 {
@@ -499,22 +499,22 @@ gfxASurface::GetSubpixelAntialiasingEnab
     return true;
 #endif
 }
 
 int32_t
 gfxASurface::BytePerPixelFromFormat(gfxImageFormat format)
 {
     switch (format) {
-        case gfxImageFormat::ARGB32:
-        case gfxImageFormat::RGB24:
+        case SurfaceFormat::A8R8G8B8_UINT32:
+        case SurfaceFormat::X8R8G8B8_UINT32:
             return 4;
-        case gfxImageFormat::RGB16_565:
+        case SurfaceFormat::R5G6B5_UINT16:
             return 2;
-        case gfxImageFormat::A8:
+        case SurfaceFormat::A8:
             return 1;
         default:
             NS_WARNING("Unknown byte per pixel value for Image format");
     }
     return 0;
 }
 
 /** Memory reporting **/
@@ -662,25 +662,25 @@ gfxASurface::SizeOfIncludingThis(MallocS
 {
     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
 
 /* static */ uint8_t
 gfxASurface::BytesPerPixel(gfxImageFormat aImageFormat)
 {
   switch (aImageFormat) {
-    case gfxImageFormat::ARGB32:
+    case SurfaceFormat::A8R8G8B8_UINT32:
       return 4;
-    case gfxImageFormat::RGB24:
+    case SurfaceFormat::X8R8G8B8_UINT32:
       return 4;
-    case gfxImageFormat::RGB16_565:
+    case SurfaceFormat::R5G6B5_UINT16:
       return 2;
-    case gfxImageFormat::A8:
+    case SurfaceFormat::A8:
       return 1;
-    case gfxImageFormat::Unknown:
+    case SurfaceFormat::UNKNOWN:
     default:
       NS_NOTREACHED("Not really sure what you want me to say here");
       return 0;
   }
 }
 
 void
 gfxASurface::SetOpaqueRect(const gfxRect& aRect)
--- a/gfx/thebes/gfxAlphaRecovery.cpp
+++ b/gfx/thebes/gfxAlphaRecovery.cpp
@@ -12,20 +12,20 @@
 
 /* static */ bool
 gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
                                const gfxImageSurface* whiteSurf)
 {
     mozilla::gfx::IntSize size = blackSurf->GetSize();
 
     if (size != whiteSurf->GetSize() ||
-        (blackSurf->Format() != gfxImageFormat::ARGB32 &&
-         blackSurf->Format() != gfxImageFormat::RGB24) ||
-        (whiteSurf->Format() != gfxImageFormat::ARGB32 &&
-         whiteSurf->Format() != gfxImageFormat::RGB24))
+        (blackSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
+         blackSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) ||
+        (whiteSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
+         whiteSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32))
         return false;
 
 #ifdef MOZILLA_MAY_SUPPORT_SSE2
     if (mozilla::supports_sse2() &&
         RecoverAlphaSSE2(blackSurf, whiteSurf)) {
         return true;
     }
 #endif
--- a/gfx/thebes/gfxAlphaRecoverySSE2.cpp
+++ b/gfx/thebes/gfxAlphaRecoverySSE2.cpp
@@ -28,20 +28,20 @@ static uint32_t alphaMaski[] = { 0xff000
 
 bool
 gfxAlphaRecovery::RecoverAlphaSSE2(gfxImageSurface* blackSurf,
                                    const gfxImageSurface* whiteSurf)
 {
     mozilla::gfx::IntSize size = blackSurf->GetSize();
 
     if (size != whiteSurf->GetSize() ||
-        (blackSurf->Format() != gfxImageFormat::ARGB32 &&
-         blackSurf->Format() != gfxImageFormat::RGB24) ||
-        (whiteSurf->Format() != gfxImageFormat::ARGB32 &&
-         whiteSurf->Format() != gfxImageFormat::RGB24))
+        (blackSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
+         blackSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) ||
+        (whiteSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
+         whiteSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32))
         return false;
 
     blackSurf->Flush();
     whiteSurf->Flush();
 
     unsigned char* blackData = blackSurf->Data();
     unsigned char* whiteData = whiteSurf->Data();
 
@@ -135,17 +135,17 @@ ByteAlignment(int32_t aAlignToLog2, int3
 {
     return (aX + aStride * aY) & ((1 << aAlignToLog2) - 1);
 }
 
 /*static*/ mozilla::gfx::IntRect
 gfxAlphaRecovery::AlignRectForSubimageRecovery(const mozilla::gfx::IntRect& aRect,
                                                gfxImageSurface* aSurface)
 {
-    NS_ASSERTION(gfxImageFormat::ARGB32 == aSurface->Format(),
+    NS_ASSERTION(mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 == aSurface->Format(),
                  "Thebes grew support for non-ARGB32 COLOR_ALPHA?");
     static const int32_t kByteAlignLog2 = GoodAlignmentLog2();
     static const int32_t bpp = 4;
     static const int32_t pixPerAlign = (1 << kByteAlignLog2) / bpp;
     //
     // We're going to create a subimage of the surface with size
     // <sw,sh> for alpha recovery, and want a SIMD fast-path.  The
     // rect <x,y, w,h> /needs/ to be redrawn, but it might not be
--- a/gfx/thebes/gfxAndroidPlatform.cpp
+++ b/gfx/thebes/gfxAndroidPlatform.cpp
@@ -96,21 +96,21 @@ gfxAndroidPlatform::gfxAndroidPlatform()
     // These two calls are equivalent to FT_Init_FreeType(), but allow us to
     // provide a custom memory allocator.
     FT_New_Library(&sFreetypeMemoryRecord, &gPlatformFTLibrary);
     FT_Add_Default_Modules(gPlatformFTLibrary);
 
     RegisterStrongMemoryReporter(new FreetypeReporter());
 
     mOffscreenFormat = GetScreenDepth() == 16
-                       ? gfxImageFormat::RGB16_565
-                       : gfxImageFormat::RGB24;
+                       ? SurfaceFormat::R5G6B5_UINT16
+                       : SurfaceFormat::X8R8G8B8_UINT32;
 
     if (gfxPrefs::AndroidRGB16Force()) {
-        mOffscreenFormat = gfxImageFormat::RGB16_565;
+        mOffscreenFormat = SurfaceFormat::R5G6B5_UINT16;
     }
 
 #ifdef MOZ_WIDGET_GONK
     char propQemu[PROPERTY_VALUE_MAX];
     property_get("ro.kernel.qemu", propQemu, "");
     mIsInGonkEmulator = !strncmp(propQemu, "1", 1);
 #endif
 }
--- a/gfx/thebes/gfxImageSurface.cpp
+++ b/gfx/thebes/gfxImageSurface.cpp
@@ -7,42 +7,43 @@
 #include "mozilla/MemoryReporting.h"
 #if defined(HAVE_POSIX_MEMALIGN)
 #include "gfxAlphaRecovery.h"
 #endif
 #include "gfxImageSurface.h"
 
 #include "cairo.h"
 #include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/HelpersCairo.h"
 #include "gfx2DGlue.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 gfxImageSurface::gfxImageSurface()
   : mSize(0, 0),
     mOwnsData(false),
-    mFormat(gfxImageFormat::Unknown),
+    mFormat(SurfaceFormat::UNKNOWN),
     mStride(0)
 {
 }
 
 void
 gfxImageSurface::InitFromSurface(cairo_surface_t *csurf)
 {
     if (!csurf || cairo_surface_status(csurf)) {
         MakeInvalid();
         return;
     }
 
     mSize.width = cairo_image_surface_get_width(csurf);
     mSize.height = cairo_image_surface_get_height(csurf);
     mData = cairo_image_surface_get_data(csurf);
-    mFormat = gfxCairoFormatToImageFormat(cairo_image_surface_get_format(csurf));
+    mFormat = CairoFormatToGfxFormat(cairo_image_surface_get_format(csurf));
     mOwnsData = false;
     mStride = cairo_image_surface_get_stride(csurf);
 
     Init(csurf, true);
 }
 
 gfxImageSurface::gfxImageSurface(unsigned char *aData, const IntSize& aSize,
                                  long aStride, gfxImageFormat aFormat)
@@ -66,17 +67,17 @@ gfxImageSurface::InitWithData(unsigned c
     mOwnsData = false;
     mData = aData;
     mFormat = aFormat;
     mStride = aStride;
 
     if (!CheckSurfaceSize(aSize))
         MakeInvalid();
 
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(mFormat);
+    cairo_format_t cformat = GfxFormatToCairoFormat(mFormat);
     cairo_surface_t *surface =
         cairo_image_surface_create_for_data((unsigned char*)mData,
                                             cformat,
                                             mSize.width,
                                             mSize.height,
                                             mStride);
 
     // cairo_image_surface_create_for_data can return a 'null' surface
@@ -136,17 +137,17 @@ gfxImageSurface::AllocateAndInit(long aS
         if (!mData)
             return;
         if (aClear)
             memset(mData, 0, aMinimalAllocation);
     }
 
     mOwnsData = true;
 
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(mFormat);
+    cairo_format_t cformat = GfxFormatToCairoFormat(mFormat);
     cairo_surface_t *surface =
         cairo_image_surface_create_for_data((unsigned char*)mData,
                                             cformat,
                                             mSize.width,
                                             mSize.height,
                                             mStride);
 
     Init(surface);
@@ -164,17 +165,17 @@ gfxImageSurface::gfxImageSurface(const I
     AllocateAndInit(aStride, aExtraBytes, aClear);
 }
 
 gfxImageSurface::gfxImageSurface(cairo_surface_t *csurf)
 {
     mSize.width = cairo_image_surface_get_width(csurf);
     mSize.height = cairo_image_surface_get_height(csurf);
     mData = cairo_image_surface_get_data(csurf);
-    mFormat = gfxCairoFormatToImageFormat(cairo_image_surface_get_format(csurf));
+    mFormat = CairoFormatToGfxFormat(cairo_image_surface_get_format(csurf));
     mOwnsData = false;
     mStride = cairo_image_surface_get_stride(csurf);
 
     Init(csurf, true);
 }
 
 gfxImageSurface::~gfxImageSurface()
 {
@@ -182,23 +183,23 @@ gfxImageSurface::~gfxImageSurface()
         free(mData);
 }
 
 /*static*/ long
 gfxImageSurface::ComputeStride(const IntSize& aSize, gfxImageFormat aFormat)
 {
     long stride;
 
-    if (aFormat == gfxImageFormat::ARGB32)
+    if (aFormat == SurfaceFormat::A8R8G8B8_UINT32)
         stride = aSize.width * 4;
-    else if (aFormat == gfxImageFormat::RGB24)
+    else if (aFormat == SurfaceFormat::X8R8G8B8_UINT32)
         stride = aSize.width * 4;
-    else if (aFormat == gfxImageFormat::RGB16_565)
+    else if (aFormat == SurfaceFormat::R5G6B5_UINT16)
         stride = aSize.width * 2;
-    else if (aFormat == gfxImageFormat::A8)
+    else if (aFormat == SurfaceFormat::A8)
         stride = aSize.width;
     else {
         NS_WARNING("Unknown format specified to gfxImageSurface!");
         stride = aSize.width * 4;
     }
 
     stride = ((stride + 3) / 4) * 4;
 
@@ -244,20 +245,20 @@ CopyForStride(unsigned char* aDest, unsi
     }
 }
 
 // helper function for the CopyFrom methods
 static bool
 FormatsAreCompatible(gfxImageFormat a1, gfxImageFormat a2)
 {
     if (a1 != a2 &&
-        !(a1 == gfxImageFormat::ARGB32 &&
-          a2 == gfxImageFormat::RGB24) &&
-        !(a1 == gfxImageFormat::RGB24 &&
-          a2 == gfxImageFormat::ARGB32)) {
+        !(a1 == SurfaceFormat::A8R8G8B8_UINT32 &&
+          a2 == SurfaceFormat::X8R8G8B8_UINT32) &&
+        !(a1 == SurfaceFormat::X8R8G8B8_UINT32 &&
+          a2 == SurfaceFormat::A8R8G8B8_UINT32)) {
         return false;
     }
 
     return true;
 }
 
 bool
 gfxImageSurface::CopyFrom (SourceSurface *aSurface)
@@ -343,19 +344,19 @@ gfxImageSurface::GetSubimage(const gfxRe
     MOZ_ASSERT(gfxRect(0, 0, mSize.width, mSize.height).Contains(r));
 
     gfxImageFormat format = Format();
 
     unsigned char* subData = Data() +
         (Stride() * (int)r.Y()) +
         (int)r.X() * gfxASurface::BytePerPixelFromFormat(Format());
 
-    if (format == gfxImageFormat::ARGB32 &&
+    if (format == SurfaceFormat::A8R8G8B8_UINT32 &&
         GetOpaqueRect().Contains(aRect)) {
-        format = gfxImageFormat::RGB24;
+        format = SurfaceFormat::X8R8G8B8_UINT32;
     }
 
     RefPtr<gfxSubimageSurface> image =
         new gfxSubimageSurface(this, subData,
                                IntSize((int)r.Width(), (int)r.Height()),
                                format);
 
     return image.forget();
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -572,17 +572,17 @@ gfxPlatform::Init()
         rv = gfxPlatformFontList::Init();
         if (NS_FAILED(rv)) {
             NS_RUNTIMEABORT("Could not initialize gfxPlatformFontList");
         }
     }
 
     gPlatform->mScreenReferenceSurface =
         gPlatform->CreateOffscreenSurface(IntSize(1, 1),
-                                          gfxImageFormat::ARGB32);
+                                          SurfaceFormat::A8R8G8B8_UINT32);
     if (!gPlatform->mScreenReferenceSurface) {
         NS_RUNTIMEABORT("Could not initialize mScreenReferenceSurface");
     }
 
     gPlatform->mScreenReferenceDrawTarget =
         gPlatform->CreateOffscreenContentDrawTarget(IntSize(1, 1),
                                                     SurfaceFormat::B8G8R8A8);
     if (!gPlatform->mScreenReferenceDrawTarget) {
@@ -1859,21 +1859,21 @@ gfxPlatform::GetLog(eGfxLog aWhichLog)
 }
 
 mozilla::gfx::SurfaceFormat
 gfxPlatform::Optimal2DFormatForContent(gfxContentType aContent)
 {
   switch (aContent) {
   case gfxContentType::COLOR:
     switch (GetOffscreenFormat()) {
-    case gfxImageFormat::ARGB32:
+    case SurfaceFormat::A8R8G8B8_UINT32:
       return mozilla::gfx::SurfaceFormat::B8G8R8A8;
-    case gfxImageFormat::RGB24:
+    case SurfaceFormat::X8R8G8B8_UINT32:
       return mozilla::gfx::SurfaceFormat::B8G8R8X8;
-    case gfxImageFormat::RGB16_565:
+    case SurfaceFormat::R5G6B5_UINT16:
       return mozilla::gfx::SurfaceFormat::R5G6B5_UINT16;
     default:
       NS_NOTREACHED("unknown gfxImageFormat for gfxContentType::COLOR");
       return mozilla::gfx::SurfaceFormat::B8G8R8A8;
     }
   case gfxContentType::ALPHA:
     return mozilla::gfx::SurfaceFormat::A8;
   case gfxContentType::COLOR_ALPHA:
@@ -1886,22 +1886,22 @@ gfxPlatform::Optimal2DFormatForContent(g
 
 gfxImageFormat
 gfxPlatform::OptimalFormatForContent(gfxContentType aContent)
 {
   switch (aContent) {
   case gfxContentType::COLOR:
     return GetOffscreenFormat();
   case gfxContentType::ALPHA:
-    return gfxImageFormat::A8;
+    return SurfaceFormat::A8;
   case gfxContentType::COLOR_ALPHA:
-    return gfxImageFormat::ARGB32;
+    return SurfaceFormat::A8R8G8B8_UINT32;
   default:
     NS_NOTREACHED("unknown gfxContentType");
-    return gfxImageFormat::ARGB32;
+    return SurfaceFormat::A8R8G8B8_UINT32;
   }
 }
 
 /**
  * There are a number of layers acceleration (or layers in general) preferences
  * that should be consistent for the lifetime of the application (bug 840967).
  * As such, we will evaluate them all as soon as one of them is evaluated
  * and remember the values.  Changing these preferences during the run will
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -531,17 +531,17 @@ public:
     gfxASurface* ScreenReferenceSurface() { return mScreenReferenceSurface; }
     mozilla::gfx::DrawTarget* ScreenReferenceDrawTarget() { return mScreenReferenceDrawTarget; }
 
     virtual mozilla::gfx::SurfaceFormat Optimal2DFormatForContent(gfxContentType aContent);
 
     virtual gfxImageFormat OptimalFormatForContent(gfxContentType aContent);
 
     virtual gfxImageFormat GetOffscreenFormat()
-    { return gfxImageFormat::RGB24; }
+    { return mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32; }
 
     /**
      * Returns a logger if one is available and logging is enabled
      */
     static mozilla::LogModule* GetLog(eGfxLog aWhichLog);
 
     int GetScreenDepth() const { return mScreenDepth; }
     mozilla::gfx::IntSize GetScreenSize() const { return mScreenSize; }
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -360,20 +360,20 @@ gfxPlatformGtk::UseImageOffscreenSurface
 }
 
 gfxImageFormat
 gfxPlatformGtk::GetOffscreenFormat()
 {
     // Make sure there is a screen
     GdkScreen *screen = gdk_screen_get_default();
     if (screen && gdk_visual_get_depth(gdk_visual_get_system()) == 16) {
-        return gfxImageFormat::RGB16_565;
+        return SurfaceFormat::R5G6B5_UINT16;
     }
 
-    return gfxImageFormat::RGB24;
+    return SurfaceFormat::X8R8G8B8_UINT32;
 }
 
 void gfxPlatformGtk::FontsPrefsChanged(const char *aPref)
 {
     // only checking for generic substitions, pass other changes up
     if (strcmp(GFX_PREF_MAX_GENERIC_SUBSTITUTIONS, aPref)) {
         gfxPlatform::FontsPrefsChanged(aPref);
         return;
--- a/gfx/thebes/gfxQPainterSurface.cpp
+++ b/gfx/thebes/gfxQPainterSurface.cpp
@@ -16,17 +16,17 @@ gfxQPainterSurface::gfxQPainterSurface(Q
 
     mPainter = painter;
 
     Init (csurf);
 }
 
 gfxQPainterSurface::gfxQPainterSurface(const mozilla::gfx::IntSize& size, gfxImageFormat format)
 {
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
+    cairo_format_t cformat = GfxFormatToCairoFormat(format);
     cairo_surface_t *csurf =
         cairo_qt_surface_create_with_qimage(cformat, size.width, size.height);
     mPainter = cairo_qt_surface_get_qpainter (csurf);
 
     Init (csurf);
 }
 
 gfxQPainterSurface::gfxQPainterSurface(const mozilla::gfx::IntSize& size, gfxContentType content)
--- a/gfx/thebes/gfxQtPlatform.cpp
+++ b/gfx/thebes/gfxQtPlatform.cpp
@@ -41,26 +41,26 @@
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 using namespace mozilla::unicode;
 using namespace mozilla::gfx;
 
 gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr;
 
-static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24;
+static gfxImageFormat sOffscreenFormat = SurfaceFormat::X8R8G8B8_UINT32;
 
 gfxQtPlatform::gfxQtPlatform()
 {
     if (!sFontconfigUtils)
         sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
 
     int32_t depth = GetScreenDepth();
     if (depth == 16) {
-        sOffscreenFormat = gfxImageFormat::RGB16_565;
+        sOffscreenFormat = SurfaceFormat::R5G6B5_UINT16;
     }
     uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
     uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
     InitBackendPrefs(canvasMask, BackendType::CAIRO,
                      contentMask, BackendType::CAIRO);
 }
 
 gfxQtPlatform::~gfxQtPlatform()
--- a/gfx/thebes/gfxQuartzSurface.cpp
+++ b/gfx/thebes/gfxQuartzSurface.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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 "gfxQuartzSurface.h"
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
+#include "mozilla/gfx/HelpersCairo.h"
 
 #include "cairo-quartz.h"
 
 void
 gfxQuartzSurface::MakeInvalid()
 {
     mSize = mozilla::gfx::IntSize(-1, -1);
 }
@@ -21,17 +22,17 @@ gfxQuartzSurface::gfxQuartzSurface(const
     mozilla::gfx::IntSize size((unsigned int) floor(desiredSize.width),
                     (unsigned int) floor(desiredSize.height));
     if (!CheckSurfaceSize(size))
         MakeInvalid();
 
     unsigned int width = static_cast<unsigned int>(mSize.width);
     unsigned int height = static_cast<unsigned int>(mSize.height);
 
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
+    cairo_format_t cformat = GfxFormatToCairoFormat(format);
     cairo_surface_t *surf = cairo_quartz_surface_create(cformat, width, height);
 
     mCGContext = cairo_quartz_surface_get_cg_context (surf);
 
     CGContextRetain(mCGContext);
 
     Init(surf);
     if (mSurfaceValid) {
@@ -104,17 +105,17 @@ gfxQuartzSurface::gfxQuartzSurface(unsig
     mozilla::gfx::IntSize size((unsigned int) floor(desiredSize.width),
                     (unsigned int) floor(desiredSize.height));
     if (!CheckSurfaceSize(size))
         MakeInvalid();
 
     unsigned int width = static_cast<unsigned int>(mSize.width);
     unsigned int height = static_cast<unsigned int>(mSize.height);
 
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
+    cairo_format_t cformat = GfxFormatToCairoFormat(format);
     cairo_surface_t *surf = cairo_quartz_surface_create_for_data
         (data, cformat, width, height, stride);
 
     mCGContext = cairo_quartz_surface_get_cg_context (surf);
 
     CGContextRetain(mCGContext);
 
     Init(surf);
@@ -127,17 +128,17 @@ gfxQuartzSurface::gfxQuartzSurface(unsig
                                    const mozilla::gfx::IntSize& aSize,
                                    long stride,
                                    gfxImageFormat format)
     : mCGContext(nullptr), mSize(aSize.width, aSize.height)
 {
     if (!CheckSurfaceSize(aSize))
         MakeInvalid();
 
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
+    cairo_format_t cformat = GfxFormatToCairoFormat(format);
     cairo_surface_t *surf = cairo_quartz_surface_create_for_data
         (data, cformat, aSize.width, aSize.height, stride);
 
     mCGContext = cairo_quartz_surface_get_cg_context (surf);
 
     CGContextRetain(mCGContext);
 
     Init(surf);
--- a/gfx/thebes/gfxTypes.h
+++ b/gfx/thebes/gfxTypes.h
@@ -39,44 +39,16 @@ typedef double gfxFloat;
  * @see nsLineLayout::NotifyOptionalBreakPosition
  */
 enum class gfxBreakPriority {
   eNoBreak       = 0,
   eWordWrapBreak,
   eNormalBreak
 };
 
-/**
-  * The format for an image surface. For all formats with alpha data, 0
-  * means transparent, 1 or 255 means fully opaque.
-  *
-  * XXX: it's vital that the values here match the values in cairo_format_t,
-  * otherwise gfxCairoFormatToImageFormat() and gfxImageFormatToCairoFormat()
-  * won't work.
-  */
-enum class gfxImageFormat {
-  ARGB32    = 0, ///< ARGB data in native endianness, using premultiplied alpha
-  RGB24     = 1, ///< xRGB data in native endianness
-  A8        = 2, ///< Only an alpha channel
-  RGB16_565 = 4, ///< RGB_565 data in native endianness
-  Unknown
-};
-
-// XXX: temporary
-// This works because the gfxImageFormat enum is defined so as to match the
-// cairo_format_t enum.
-#define gfxCairoFormatToImageFormat(aFormat) \
-    ((gfxImageFormat)aFormat)
-
-// XXX: temporary
-// This works because the gfxImageFormat enum is defined so as to match the
-// cairo_format_t enum.
-#define gfxImageFormatToCairoFormat(aFormat) \
-    ((cairo_format_t)aFormat)
-
 enum class gfxSurfaceType {
   Image,
   PDF,
   PS,
   Xlib,
   Xcb,
   Glitz,           // unused, but needed for cairo parity
   Quartz,
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -784,21 +784,21 @@ gfxUtils::DrawPixelSnapped(gfxContext*  
 
     drawable->Draw(aContext, aRegion.Rect(), extendMode, aFilter, aOpacity, gfxMatrix());
 }
 
 /* static */ int
 gfxUtils::ImageFormatToDepth(gfxImageFormat aFormat)
 {
     switch (aFormat) {
-        case gfxImageFormat::ARGB32:
+        case SurfaceFormat::A8R8G8B8_UINT32:
             return 32;
-        case gfxImageFormat::RGB24:
+        case SurfaceFormat::X8R8G8B8_UINT32:
             return 24;
-        case gfxImageFormat::RGB16_565:
+        case SurfaceFormat::R5G6B5_UINT16:
             return 16;
         default:
             break;
     }
     return 0;
 }
 
 static void
@@ -980,17 +980,17 @@ gfxUtils::GetYCbCrToRGBDestFormatAndSize
                       aData.mCbCrSize.width,
                       aData.mCbCrSize.height);
 
   // 'prescale' is true if the scaling is to be done as part of the
   // YCbCr to RGB conversion rather than on the RGB data when rendered.
   bool prescale = aSuggestedSize.width > 0 && aSuggestedSize.height > 0 &&
                     aSuggestedSize != aData.mPicSize;
 
-  if (aSuggestedFormat == gfxImageFormat::RGB16_565) {
+  if (aSuggestedFormat == SurfaceFormat::R5G6B5_UINT16) {
 #if defined(HAVE_YCBCR_TO_RGB565)
     if (prescale &&
         !IsScaleYCbCrToRGB565Fast(aData.mPicX,
                                        aData.mPicY,
                                        aData.mPicSize.width,
                                        aData.mPicSize.height,
                                        aSuggestedSize.width,
                                        aSuggestedSize.height,
@@ -1000,24 +1000,24 @@ gfxUtils::GetYCbCrToRGBDestFormatAndSize
                                         aData.mPicY,
                                         aData.mPicSize.width,
                                         aData.mPicSize.height,
                                         yuvtype)) {
       prescale = false;
     }
 #else
     // yuv2rgb16 function not available
-    aSuggestedFormat = gfxImageFormat::RGB24;
+    aSuggestedFormat = SurfaceFormat::X8R8G8B8_UINT32;
 #endif
   }
-  else if (aSuggestedFormat != gfxImageFormat::RGB24) {
+  else if (aSuggestedFormat != SurfaceFormat::X8R8G8B8_UINT32) {
     // No other formats are currently supported.
-    aSuggestedFormat = gfxImageFormat::RGB24;
+    aSuggestedFormat = SurfaceFormat::X8R8G8B8_UINT32;
   }
-  if (aSuggestedFormat == gfxImageFormat::RGB24) {
+  if (aSuggestedFormat == SurfaceFormat::X8R8G8B8_UINT32) {
     /* ScaleYCbCrToRGB32 does not support a picture offset, nor 4:4:4 data.
        See bugs 639415 and 640073. */
     if (aData.mPicX != 0 || aData.mPicY != 0 || yuvtype == YV24)
       prescale = false;
   }
   if (!prescale) {
     aSuggestedSize = aData.mPicSize;
   }
@@ -1040,17 +1040,17 @@ gfxUtils::ConvertYCbCrToRGB(const Planar
     TypeFromSize(aData.mYSize.width,
                       aData.mYSize.height,
                       aData.mCbCrSize.width,
                       aData.mCbCrSize.height);
 
   // Convert from YCbCr to RGB now, scaling the image if needed.
   if (aDestSize != aData.mPicSize) {
 #if defined(HAVE_YCBCR_TO_RGB565)
-    if (aDestFormat == gfxImageFormat::RGB16_565) {
+    if (aDestFormat == SurfaceFormat::R5G6B5_UINT16) {
       ScaleYCbCrToRGB565(aData.mYChannel,
                               aData.mCbChannel,
                               aData.mCrChannel,
                               aDestBuffer,
                               aData.mPicX,
                               aData.mPicY,
                               aData.mPicSize.width,
                               aData.mPicSize.height,
@@ -1074,30 +1074,30 @@ gfxUtils::ConvertYCbCrToRGB(const Planar
                              aData.mYStride,
                              aData.mCbCrStride,
                              aStride,
                              yuvtype,
                              ROTATE_0,
                              FILTER_BILINEAR);
   } else { // no prescale
 #if defined(HAVE_YCBCR_TO_RGB565)
-    if (aDestFormat == gfxImageFormat::RGB16_565) {
+    if (aDestFormat == SurfaceFormat::R5G6B5_UINT16) {
       ConvertYCbCrToRGB565(aData.mYChannel,
                                 aData.mCbChannel,
                                 aData.mCrChannel,
                                 aDestBuffer,
                                 aData.mPicX,
                                 aData.mPicY,
                                 aData.mPicSize.width,
                                 aData.mPicSize.height,
                                 aData.mYStride,
                                 aData.mCbCrStride,
                                 aStride,
                                 yuvtype);
-    } else // aDestFormat != gfxImageFormat::RGB16_565
+    } else // aDestFormat != SurfaceFormat::R5G6B5_UINT16
 #endif
       ConvertYCbCrToRGB32(aData.mYChannel,
                                aData.mCbChannel,
                                aData.mCrChannel,
                                aDestBuffer,
                                aData.mPicX,
                                aData.mPicY,
                                aData.mPicSize.width,
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -44,17 +44,17 @@ public:
 
     /*
      * Premultiply or Unpremultiply aSourceSurface, writing the result
      * to aDestSurface or back into aSourceSurface if aDestSurface is null.
      *
      * If aDestSurface is given, it must have identical format, dimensions, and
      * stride as the source.
      *
-     * If the source is not gfxImageFormat::ARGB32, no operation is performed.  If
+     * If the source is not SurfaceFormat::A8R8G8B8_UINT32, no operation is performed.  If
      * aDestSurface is given, the data is copied over.
      */
     static bool PremultiplyDataSurface(DataSourceSurface* srcSurf,
                                        DataSourceSurface* destSurf);
     static bool UnpremultiplyDataSurface(DataSourceSurface* srcSurf,
                                          DataSourceSurface* destSurf);
 
     static already_AddRefed<DataSourceSurface>
@@ -132,17 +132,17 @@ public:
      * Return the smallest power of kScaleResolution (2) greater than or equal to
      * aVal.
      */
     static gfxFloat ClampToScaleFactor(gfxFloat aVal);
 
     /**
      * Helper function for ConvertYCbCrToRGB that finds the
      * RGB buffer size and format for given YCbCrImage.
-     * @param aSuggestedFormat will be set to gfxImageFormat::RGB24
+     * @param aSuggestedFormat will be set to SurfaceFormat::X8R8G8B8_UINT32
      *   if the desired format is not supported.
      * @param aSuggestedSize will be set to the picture size from aData
      *   if either the suggested size was {0,0}
      *   or simultaneous scaling and conversion is not supported.
      */
     static void
     GetYCbCrToRGBDestFormatAndSize(const mozilla::layers::PlanarYCbCrData& aData,
                                    gfxImageFormat& aSuggestedFormat,
--- a/gfx/thebes/gfxWindowsSurface.cpp
+++ b/gfx/thebes/gfxWindowsSurface.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * 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 "gfxWindowsSurface.h"
 #include "gfxContext.h"
 #include "gfxPlatform.h"
+#include "mozilla/gfx/HelpersCairo.h"
 #include "mozilla/gfx/Logging.h"
 
 #include "cairo.h"
 #include "cairo-win32.h"
 
 #include "nsString.h"
 
 gfxWindowsSurface::gfxWindowsSurface(HWND wnd, uint32_t flags) :
@@ -54,17 +55,17 @@ gfxWindowsSurface::MakeInvalid(mozilla::
 
 gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) :
     mOwnsDC(false), mForPrinting(false), mWnd(nullptr)
 {
     mozilla::gfx::IntSize size(realSize);
     if (!CheckSurfaceSize(size))
         MakeInvalid(size);
 
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat);
+    cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat);
     cairo_surface_t *surf =
         cairo_win32_surface_create_with_dib(cformat, size.width, size.height);
 
     Init(surf);
 
     if (CairoStatus() == CAIRO_STATUS_SUCCESS) {
         mDC = cairo_win32_surface_get_dc(CairoSurface());
         RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface));
@@ -75,26 +76,27 @@ gfxWindowsSurface::gfxWindowsSurface(con
 
 gfxWindowsSurface::gfxWindowsSurface(HDC dc, const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) :
     mOwnsDC(false), mForPrinting(false), mWnd(nullptr)
 {
     mozilla::gfx::IntSize size(realSize);
     if (!CheckSurfaceSize(size))
         MakeInvalid(size);
 
-    cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat);
+    cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat);
     cairo_surface_t *surf =
         cairo_win32_surface_create_with_ddb(dc, cformat,
                                             size.width, size.height);
 
     Init(surf);
 
     if (mSurfaceValid) {
         // DDBs will generally only use 3 bytes per pixel when RGB24
-        int bytesPerPixel = ((imageFormat == gfxImageFormat::RGB24) ? 3 : 4);
+        int bytesPerPixel =
+            ((imageFormat == mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) ? 3 : 4);
         RecordMemoryUsed(size.width * size.height * bytesPerPixel + sizeof(gfxWindowsSurface));
     }
 
     if (CairoStatus() == 0)
         mDC = cairo_win32_surface_get_dc(CairoSurface());
     else
         mDC = nullptr;
 }
@@ -138,17 +140,17 @@ gfxWindowsSurface::CreateSimilarSurface(
         // use  a DIB for a gfxContentType::COLOR surface if this surface doesn't
         // have a DIB (e.g. if we're a transparent window surface). But
         // we need a DIB to perform well if the new surface is composited into
         // a surface that's the result of create_similar(gfxContentType::COLOR_ALPHA)
         // (e.g. a backbuffer for the window) --- that new surface *would*
         // have a DIB.
         gfxImageFormat gformat =
             gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
-        cairo_format_t cformat = gfxImageFormatToCairoFormat(gformat);
+        cairo_format_t cformat = GfxFormatToCairoFormat(gformat);
         surface = cairo_win32_surface_create_with_dib(cformat, aSize.width,
                                                       aSize.height);
     } else {
         surface =
           cairo_surface_create_similar(mSurface, (cairo_content_t)(int)aContent,
                                        aSize.width, aSize.height);
     }
 
--- a/gfx/thebes/gfxWindowsSurface.h
+++ b/gfx/thebes/gfxWindowsSurface.h
@@ -30,22 +30,22 @@ public:
     gfxWindowsSurface(HWND wnd, uint32_t flags = 0);
     gfxWindowsSurface(HDC dc, uint32_t flags = 0);
 
     // Create from a shared d3d9surface
     gfxWindowsSurface(IDirect3DSurface9 *surface, uint32_t flags = 0);
 
     // Create a DIB surface
     gfxWindowsSurface(const mozilla::gfx::IntSize& size,
-                      gfxImageFormat imageFormat = gfxImageFormat::RGB24);
+                      gfxImageFormat imageFormat = mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32);
 
     // Create a DDB surface; dc may be nullptr to use the screen DC
     gfxWindowsSurface(HDC dc,
                       const mozilla::gfx::IntSize& size,
-                      gfxImageFormat imageFormat = gfxImageFormat::RGB24);
+                      gfxImageFormat imageFormat = mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32);
 
     gfxWindowsSurface(cairo_surface_t *csurf);
 
     virtual already_AddRefed<gfxASurface> CreateSimilarSurface(gfxContentType aType,
                                                                const mozilla::gfx::IntSize& aSize);
 
     void InitWithDC(uint32_t flags);
 
--- a/gfx/thebes/gfxXlibNativeRenderer.cpp
+++ b/gfx/thebes/gfxXlibNativeRenderer.cpp
@@ -8,16 +8,17 @@
 #include "gfxXlibSurface.h"
 #include "gfxImageSurface.h"
 #include "gfxContext.h"
 #include "gfxPlatform.h"
 #include "gfxAlphaRecovery.h"
 #include "cairo-xlib.h"
 #include "cairo-xlib-xrender.h"
 #include "mozilla/gfx/BorrowedContext.h"
+#include "mozilla/gfx/HelpersCairo.h"
 #include "gfx2DGlue.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 #if 0
 #include <stdio.h>
 #define NATIVE_DRAWING_NOTE(m) fprintf(stderr, m)
@@ -347,17 +348,17 @@ CreateTempXlibSurface (cairo_surface_t* 
         Visual *target_visual = nullptr;
         XRenderPictFormat *target_format = nullptr;
         if (cairoTargetType == CAIRO_SURFACE_TYPE_XLIB) {
             target_visual = cairo_xlib_surface_get_visual (cairoTarget);
             target_format = cairo_xlib_surface_get_xrender_format (cairoTarget);
         } else if (cairoTargetType == CAIRO_SURFACE_TYPE_IMAGE || drawTarget) {
             gfxImageFormat imageFormat =
                 drawTarget ? SurfaceFormatToImageFormat(drawTarget->GetFormat()) :
-                    gfxCairoFormatToImageFormat(cairo_image_surface_get_format(cairoTarget));
+                    CairoFormatToGfxFormat(cairo_image_surface_get_format(cairoTarget));
             target_visual = gfxXlibSurface::FindVisual(screen, imageFormat);
             Display *dpy = DisplayOfScreen(screen);
             if (target_visual) {
                 target_format = XRenderFindVisualFormat(dpy, target_visual);
             } else {
                 target_format =
                     gfxXlibSurface::FindRenderFormat(dpy, imageFormat);
             }
@@ -384,27 +385,27 @@ CreateTempXlibSurface (cairo_surface_t* 
     if (supportsAlternateVisual && !drawIsOpaque &&
         (screen != target_screen ||
          !(doCopyBackground || VisualHasAlpha(screen, visual)))) {
         // Try to find a visual with an alpha channel.
         Screen *visualScreen =
             supportsAlternateScreen ? target_screen : screen;
         Visual *argbVisual =
             gfxXlibSurface::FindVisual(visualScreen,
-                                       gfxImageFormat::ARGB32);
+                                       SurfaceFormat::A8R8G8B8_UINT32);
         if (argbVisual) {
             visual = argbVisual;
             screen = visualScreen;
         } else if (!doCopyBackground &&
                    gfxXlibSurface::DepthOfVisual(screen, visual) != 24) {
             // Will need to do alpha extraction; prefer a 24-bit visual.
             // No advantage in using the target screen.
             Visual *rgb24Visual =
                 gfxXlibSurface::FindVisual(screen,
-                                           gfxImageFormat::RGB24);
+                                           SurfaceFormat::X8R8G8B8_UINT32);
             if (rgb24Visual) {
                 visual = rgb24Visual;
             }
         }
     }
 
     Drawable drawable =
         (screen == target_screen && cairoTargetType == CAIRO_SURFACE_TYPE_XLIB) ?
@@ -591,26 +592,26 @@ gfxXlibNativeRenderer::Draw(gfxContext* 
             ctx->SetSource(tmpSurf, offset);
             ctx->Paint();
         }
         cairo_surface_destroy(tempXlibSurface);
         return;
     }
     
     RefPtr<gfxImageSurface> blackImage =
-        CopyXlibSurfaceToImage(tempXlibSurface, size, gfxImageFormat::ARGB32);
+        CopyXlibSurfaceToImage(tempXlibSurface, size, SurfaceFormat::A8R8G8B8_UINT32);
     
     cairo_t* tmpCtx = cairo_create(tempXlibSurface);
     cairo_set_source_rgba(tmpCtx, 1.0, 1.0, 1.0, 1.0);
     cairo_set_operator(tmpCtx, CAIRO_OPERATOR_SOURCE);
     cairo_paint(tmpCtx);
     cairo_destroy(tmpCtx);
     DrawOntoTempSurface(tempXlibSurface, -drawingRect.TopLeft());
     RefPtr<gfxImageSurface> whiteImage =
-        CopyXlibSurfaceToImage(tempXlibSurface, size, gfxImageFormat::RGB24);
+        CopyXlibSurfaceToImage(tempXlibSurface, size, SurfaceFormat::X8R8G8B8_UINT32);
   
     if (blackImage->CairoStatus() == CAIRO_STATUS_SUCCESS &&
         whiteImage->CairoStatus() == CAIRO_STATUS_SUCCESS) {
         if (!gfxAlphaRecovery::RecoverAlpha(blackImage, whiteImage)) {
             cairo_surface_destroy(tempXlibSurface);
             return;
         }
 
--- a/gfx/thebes/gfxXlibSurface.cpp
+++ b/gfx/thebes/gfxXlibSurface.cpp
@@ -499,35 +499,35 @@ gfxXlibSurface::DepthOfVisual(const Scre
     
 /* static */
 Visual*
 gfxXlibSurface::FindVisual(Screen *screen, gfxImageFormat format)
 {
     int depth;
     unsigned long red_mask, green_mask, blue_mask;
     switch (format) {
-        case gfxImageFormat::ARGB32:
+        case gfx::SurfaceFormat::A8R8G8B8_UINT32:
             depth = 32;
             red_mask = 0xff0000;
             green_mask = 0xff00;
             blue_mask = 0xff;
             break;
-        case gfxImageFormat::RGB24:
+        case gfx::SurfaceFormat::X8R8G8B8_UINT32:
             depth = 24;
             red_mask = 0xff0000;
             green_mask = 0xff00;
             blue_mask = 0xff;
             break;
-        case gfxImageFormat::RGB16_565:
+        case gfx::SurfaceFormat::R5G6B5_UINT16:
             depth = 16;
             red_mask = 0xf800;
             green_mask = 0x7e0;
             blue_mask = 0x1f;
             break;
-        case gfxImageFormat::A8:
+        case gfx::SurfaceFormat::A8:
         default:
             return nullptr;
     }
 
     for (int d = 0; d < screen->ndepths; d++) {
         const Depth& d_info = screen->depths[d];
         if (d_info.depth != depth)
             continue;
@@ -546,30 +546,30 @@ gfxXlibSurface::FindVisual(Screen *scree
     return nullptr;
 }
 
 /* static */
 XRenderPictFormat*
 gfxXlibSurface::FindRenderFormat(Display *dpy, gfxImageFormat format)
 {
     switch (format) {
-        case gfxImageFormat::ARGB32:
+        case gfx::SurfaceFormat::A8R8G8B8_UINT32:
             return XRenderFindStandardFormat (dpy, PictStandardARGB32);
-        case gfxImageFormat::RGB24:
+        case gfx::SurfaceFormat::X8R8G8B8_UINT32:
             return XRenderFindStandardFormat (dpy, PictStandardRGB24);
-        case gfxImageFormat::RGB16_565: {
+        case gfx::SurfaceFormat::R5G6B5_UINT16: {
             // PictStandardRGB16_565 is not standard Xrender format
             // we should try to find related visual
             // and find xrender format by visual
             Visual *visual = FindVisual(DefaultScreenOfDisplay(dpy), format);
             if (!visual)
                 return nullptr;
             return XRenderFindVisualFormat(dpy, visual);
         }
-        case gfxImageFormat::A8:
+        case gfx::SurfaceFormat::A8:
             return XRenderFindStandardFormat (dpy, PictStandardA8);
         default:
             break;
     }
 
     return nullptr;
 }
 
--- a/gfx/ycbcr/YCbCrUtils.cpp
+++ b/gfx/ycbcr/YCbCrUtils.cpp
@@ -130,17 +130,17 @@ ConvertYCbCrToRGB(const layers::PlanarYC
                            aData.mPicX,
                            aData.mPicY,
                            aData.mPicSize.width,
                            aData.mPicSize.height,
                            aData.mYStride,
                            aData.mCbCrStride,
                            aStride,
                            yuvtype);
-    } else // aDestFormat != gfxImageFormat::RGB16_565
+    } else // aDestFormat != SurfaceFormat::R5G6B5_UINT16
 #endif
       ConvertYCbCrToRGB32(aData.mYChannel, //
                           aData.mCbChannel,
                           aData.mCrChannel,
                           aDestBuffer,
                           aData.mPicX,
                           aData.mPicY,
                           aData.mPicSize.width,
--- a/widget/android/AndroidGraphicBuffer.cpp
+++ b/widget/android/AndroidGraphicBuffer.cpp
@@ -386,19 +386,19 @@ AndroidGraphicBuffer::GetAndroidUsage(ui
 
   return flags;
 }
 
 uint32_t
 AndroidGraphicBuffer::GetAndroidFormat(gfxImageFormat aFormat)
 {
   switch (aFormat) {
-    case gfxImageFormat::RGB24:
+    case SurfaceFormat::X8R8G8B8_UINT32:
       return HAL_PIXEL_FORMAT_RGBX_8888;
-    case gfxImageFormat::RGB16_565:
+    case SurfaceFormat::R5G6B5_UINT16:
       return HAL_PIXEL_FORMAT_RGB_565;
     default:
       return 0;
   }
 }
 
 bool
 AndroidGraphicBuffer::EnsureEGLImage()
--- a/widget/cocoa/nsDeviceContextSpecX.mm
+++ b/widget/cocoa/nsDeviceContextSpecX.mm
@@ -152,17 +152,17 @@ NS_IMETHODIMP nsDeviceContextSpecX::GetS
 
     if (context) {
         // Initially, origin is at bottom-left corner of the paper.
         // Here, we translate it to top-left corner of the paper.
         CGContextTranslateCTM(context, 0, height);
         CGContextScaleCTM(context, 1.0, -1.0);
         newSurface = new gfxQuartzSurface(context, gfxSize(width, height));
     } else {
-        newSurface = new gfxQuartzSurface(gfxSize((int32_t)width, (int32_t)height), gfxImageFormat::ARGB32);
+        newSurface = new gfxQuartzSurface(gfxSize((int32_t)width, (int32_t)height), SurfaceFormat::A8R8G8B8_UINT32);
     }
 
     if (!newSurface)
         return NS_ERROR_FAILURE;
 
     *surface = newSurface;
     NS_ADDREF(*surface);
 
--- a/widget/nsDeviceContextSpecProxy.cpp
+++ b/widget/nsDeviceContextSpecProxy.cpp
@@ -81,17 +81,17 @@ nsDeviceContextSpecProxy::GetSurfaceForP
   }
 
   // convert twips to points
   width /= TWIPS_PER_POINT_FLOAT;
   height /= TWIPS_PER_POINT_FLOAT;
 
   RefPtr<gfxASurface> surface = gfxPlatform::GetPlatform()->
     CreateOffscreenSurface(mozilla::gfx::IntSize(width, height),
-                           gfxImageFormat::ARGB32);
+                           SurfaceFormat::A8R8G8B8_UINT32);
 
   surface.forget(aSurface);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDeviceContextSpecProxy::GetDrawEventRecorder(mozilla::gfx::DrawEventRecorder** aDrawEventRecorder)
 {
--- a/widget/windows/TaskbarPreview.cpp
+++ b/widget/windows/TaskbarPreview.cpp
@@ -352,17 +352,17 @@ TaskbarPreview::UpdateTooltip() {
   if (FAILED(mTaskbar->SetThumbnailTooltip(PreviewWindow(), mTooltip.get())))
     return NS_ERROR_FAILURE;
   return NS_OK;
 }
 
 void
 TaskbarPreview::DrawBitmap(uint32_t width, uint32_t height, bool isPreview) {
   nsresult rv;
-  RefPtr<gfxWindowsSurface> surface = new gfxWindowsSurface(gfx::IntSize(width, height), gfxImageFormat::ARGB32);
+  RefPtr<gfxWindowsSurface> surface = new gfxWindowsSurface(gfx::IntSize(width, height), gfx::SurfaceFormat::A8R8G8B8_UINT32);
 
   nsCOMPtr<nsIDocShell> shell = do_QueryReferent(mDocShell);
 
   if (!shell)
     return;
 
   rv = GetRenderingContext(shell, surface, width, height);
   if (NS_FAILED(rv))
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -6934,17 +6934,17 @@ nsWindow::GetAccessible()
 #ifdef MOZ_XUL
 
 void nsWindow::ResizeTranslucentWindow(int32_t aNewWidth, int32_t aNewHeight, bool force)
 {
   if (!force && aNewWidth == mBounds.width && aNewHeight == mBounds.height)
     return;
 
   RefPtr<gfxWindowsSurface> newSurface =
-    new gfxWindowsSurface(IntSize(aNewWidth, aNewHeight), gfxImageFormat::ARGB32);
+    new gfxWindowsSurface(IntSize(aNewWidth, aNewHeight), SurfaceFormat::A8R8G8B8_UINT32);
   mTransparentSurface = newSurface;
   mMemoryDC = newSurface->GetDC();
 }
 
 void nsWindow::SetWindowTranslucencyInner(nsTransparencyMode aMode)
 {
   if (aMode == mTransparencyMode)
     return;
--- a/widget/windows/nsWindowGfx.cpp
+++ b/widget/windows/nsWindowGfx.cpp
@@ -349,17 +349,17 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t
               return false;
             }
 
             // don't use the shared surface directly; instead, create a new one
             // that just reuses its buffer.
             targetSurfaceImage = new gfxImageSurface(sSharedSurfaceData.get(),
                                                      surfaceSize,
                                                      surfaceSize.width * 4,
-                                                     gfxImageFormat::RGB24);
+                                                     SurfaceFormat::X8R8G8B8_UINT32);
 
             if (targetSurfaceImage && !targetSurfaceImage->CairoStatus()) {
               targetSurfaceImage->SetDeviceOffset(gfxPoint(-ps.rcPaint.left, -ps.rcPaint.top));
               targetSurface = targetSurfaceImage;
             }
           }
 
           if (!targetSurface) {