Bug 867460: remove notion of ShaderProgramTypes from gfx/gl. Carry r=bas. r=bgirard for the changes.
authorAndreas Gal <gal@uci.edu>, Milan Sreckovic <milan@mozilla.com>
Thu, 04 Jul 2013 13:25:50 -0400
changeset 137836 55258de26ac37c5ec3eb3bb948d8739cb8e465b9
parent 137835 60307abd5f7f271462e62d5e5615bc1e46416560
child 137837 3b63ac78d593abe5b0f705a07022e44d96b46df1
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbas, bgirard
bugs867460
milestone25.0a1
Bug 867460: remove notion of ShaderProgramTypes from gfx/gl. Carry r=bas. r=bgirard for the changes.
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GLContextTypes.h
gfx/gl/GLTextureImage.cpp
gfx/gl/GLTextureImage.h
gfx/layers/opengl/CanvasLayerOGL.cpp
gfx/layers/opengl/CanvasLayerOGL.h
gfx/layers/opengl/ColorLayerOGL.cpp
gfx/layers/opengl/CompositingRenderTargetOGL.h
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/CompositorOGL.h
gfx/layers/opengl/ContainerLayerOGL.cpp
gfx/layers/opengl/GLManager.cpp
gfx/layers/opengl/GLManager.h
gfx/layers/opengl/ImageLayerOGL.cpp
gfx/layers/opengl/ImageLayerOGL.h
gfx/layers/opengl/LayerManagerOGL.cpp
gfx/layers/opengl/LayerManagerOGL.h
gfx/layers/opengl/LayerManagerOGLProgram.cpp
gfx/layers/opengl/LayerManagerOGLProgram.h
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
gfx/layers/opengl/ThebesLayerOGL.cpp
widget/cocoa/nsChildView.mm
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1476,17 +1476,17 @@ static already_AddRefed<gfxImageSurface>
   ctx->Scale(1.0, -1.0);
   ctx->Translate(-gfxPoint(0.0, size.height));
   ctx->SetSource(aSurf);
   ctx->Paint();
   return temp.forget();
 }
 
 already_AddRefed<gfxImageSurface>
-GLContext::GetTexImage(GLuint aTexture, bool aYInvert, ShaderProgramType aShader)
+GLContext::GetTexImage(GLuint aTexture, bool aYInvert, SurfaceFormat aFormat)
 {
     MakeCurrent();
     GuaranteeResolve();
     fActiveTexture(LOCAL_GL_TEXTURE0);
     fBindTexture(LOCAL_GL_TEXTURE_2D, aTexture);
 
     gfxIntSize size;
     fGetTexLevelParameteriv(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_TEXTURE_WIDTH, &size.width);
@@ -1502,17 +1502,17 @@ GLContext::GetTexImage(GLuint aTexture, 
     if (currentPackAlignment != 4) {
         fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 4);
     }
     fGetTexImage(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, surf->Data());
     if (currentPackAlignment != 4) {
         fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, currentPackAlignment);
     }
 
-    if (aShader == RGBALayerProgramType || aShader == RGBXLayerProgramType) {
+    if (aFormat == FORMAT_R8G8B8A8 || aFormat == FORMAT_R8G8B8X8) {
       SwapRAndBComponents(surf);
     }
 
     if (aYInvert) {
       surf = YInvertImageSurface(surf);
     }
     return surf.forget();
 }
@@ -1763,17 +1763,17 @@ GLContext::ReadPixelsIntoImageSurface(gf
 
     nsAutoPtr<gfxImageSurface> tempSurf;
     gfxImageSurface* readSurf = nullptr;
     int readPixelSize = 0;
     if (needsTempSurf) {
         if (DebugMode()) {
             NS_WARNING("Needing intermediary surface for ReadPixels. This will be slow!");
         }
-        gfxASurface::gfxImageFormat readFormatGFX;
+        ImageFormat readFormatGFX;
 
         switch (readFormat) {
             case LOCAL_GL_RGBA:
             case LOCAL_GL_BGRA: {
                 readFormatGFX = hasAlpha ? gfxASurface::ImageFormatARGB32
                                          : gfxASurface::ImageFormatRGB24;
                 break;
             }
@@ -2028,17 +2028,17 @@ GLContext::BlitTextureImage(TextureImage
 static unsigned int
 DataOffset(gfxImageSurface *aSurf, const nsIntPoint &aPoint)
 {
   unsigned int data = aPoint.y * aSurf->Stride();
   data += aPoint.x * gfxASurface::BytePerPixelFromFormat(aSurf->Format());
   return data;
 }
 
-ShaderProgramType
+GLContext::SurfaceFormat
 GLContext::UploadSurfaceToTexture(gfxASurface *aSurface,
                                   const nsIntRegion& aDstRegion,
                                   GLuint& aTexture,
                                   bool aOverwrite,
                                   const nsIntPoint& aSrcPoint,
                                   bool aPixelBuffer,
                                   GLenum aTextureUnit)
 {
@@ -2105,47 +2105,46 @@ GLContext::UploadSurfaceToTexture(gfxASu
     }
 
     MOZ_ASSERT(imageSurface);
     imageSurface->Flush();
 
     GLenum format;
     GLenum type;
     int32_t pixelSize = gfxASurface::BytePerPixelFromFormat(imageSurface->Format());
-    ShaderProgramType shader;
+    SurfaceFormat surfaceFormat;
 
     switch (imageSurface->Format()) {
         case gfxASurface::ImageFormatARGB32:
             format = LOCAL_GL_RGBA;
             type = LOCAL_GL_UNSIGNED_BYTE;
-            shader = BGRALayerProgramType;
+            surfaceFormat = FORMAT_B8G8R8A8;
             break;
         case gfxASurface::ImageFormatRGB24:
             // Treat RGB24 surfaces as RGBA32 except for the shader
             // program used.
             format = LOCAL_GL_RGBA;
             type = LOCAL_GL_UNSIGNED_BYTE;
-            shader = BGRXLayerProgramType;
+            surfaceFormat = FORMAT_B8G8R8X8;
             break;
         case gfxASurface::ImageFormatRGB16_565:
             format = LOCAL_GL_RGB;
             type = LOCAL_GL_UNSIGNED_SHORT_5_6_5;
-            shader = RGBALayerProgramType;
+            surfaceFormat = FORMAT_R5G6B5;
             break;
         case gfxASurface::ImageFormatA8:
             format = LOCAL_GL_LUMINANCE;
             type = LOCAL_GL_UNSIGNED_BYTE;
-            // We don't have a specific luminance shader
-            shader = ShaderProgramType(0);
+            surfaceFormat = FORMAT_A8;
             break;
         default:
             NS_ASSERTION(false, "Unhandled image surface format!");
             format = 0;
             type = 0;
-            shader = ShaderProgramType(0);
+            surfaceFormat = FORMAT_UNKNOWN;
     }
 
     int32_t stride = imageSurface->Stride();
 
     nsIntRegionRectIterator iter(paintRegion);
     const nsIntRect *iterRect;
 
     // Top left point of the region's bounding rectangle.
@@ -2184,17 +2183,17 @@ GLContext::UploadSurfaceToTexture(gfxASu
                        0,
                        format,
                        type,
                        rectData);
         }
 
     }
 
-    return shader;
+    return surfaceFormat;
 }
 
 static GLint GetAddressAlignment(ptrdiff_t aAddress)
 {
     if (!(aAddress & 0x7)) {
        return 8;
     } else if (!(aAddress & 0x3)) {
         return 4;
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -84,16 +84,18 @@ typedef uintptr_t SharedTextureHandle;
 
 class GLContext
     : public GLLibraryLoader
     , public GenericAtomicRefCounted
 {
 protected:
     typedef class gfx::SharedSurface SharedSurface;
     typedef gfx::SharedSurfaceType SharedSurfaceType;
+    typedef gfxASurface::gfxImageFormat ImageFormat;
+    typedef gfx::SurfaceFormat SurfaceFormat;
 
 public:
     typedef struct gfx::SurfaceCaps SurfaceCaps;
 
     GLContext(const SurfaceCaps& caps,
               GLContext* sharedContext = nullptr,
               bool isOffscreen = false)
       : mTexBlit_Buffer(0),
@@ -484,17 +486,17 @@ public:
      */
     virtual void ReleaseSharedHandle(SharedTextureShareType shareType,
                                      SharedTextureHandle sharedHandle)
     { }
 
 
     typedef struct {
         GLenum mTarget;
-        ShaderProgramType mProgramType;
+        SurfaceFormat mTextureFormat;
         gfx3DMatrix mTextureTransform;
     } SharedHandleDetails;
 
     /**
      * Returns information necessary for rendering a shared handle.
      * These values change depending on what sharing mechanism is in use
      */
     virtual bool GetSharedHandleDetails(SharedTextureShareType shareType,
@@ -800,17 +802,17 @@ public:
      * if you absolutely positively must, and never in any performance
      * critical path.
      */
     already_AddRefed<gfxImageSurface> ReadTextureImage(GLuint aTexture,
                                                        const gfxIntSize& aSize,
                                                        GLenum aTextureFormat,
                                                        bool aYInvert = false);
 
-    already_AddRefed<gfxImageSurface> GetTexImage(GLuint aTexture, bool aYInvert, ShaderProgramType aShader);
+    already_AddRefed<gfxImageSurface> GetTexImage(GLuint aTexture, bool aYInvert, SurfaceFormat aFormat);
 
     /**
      * Call ReadPixels into an existing gfxImageSurface.
      * The image surface must be using image format RGBA32 or RGB24,
      * and must have stride == width*4.
      * Note that neither ReadPixelsIntoImageSurface nor
      * ReadScreenIntoImageSurface call dest->Flush/MarkDirty.
      */
@@ -872,25 +874,25 @@ public:
      *  TopLeft() sits.
      * \param aPixelBuffer Pass true to upload texture data with an
      *  offset from the base data (generally for pixel buffer objects),
      *  otherwise textures are upload with an absolute pointer to the data.
      * \param aTextureUnit, the texture unit used temporarily to upload the
      *  surface. This testure may be overridden, clients should not rely on
      *  the contents of this texture after this call or even on this
      *  texture unit being active.
-     * \return Shader program needed to render this texture.
+     * \return Surface format of this texture.
      */
-    ShaderProgramType UploadSurfaceToTexture(gfxASurface *aSurface,
-                                             const nsIntRegion& aDstRegion,
-                                             GLuint& aTexture,
-                                             bool aOverwrite = false,
-                                             const nsIntPoint& aSrcPoint = nsIntPoint(0, 0),
-                                             bool aPixelBuffer = false,
-                                             GLenum aTextureUnit = LOCAL_GL_TEXTURE0);
+    SurfaceFormat UploadSurfaceToTexture(gfxASurface *aSurface,
+                                         const nsIntRegion& aDstRegion,
+                                         GLuint& aTexture,
+                                         bool aOverwrite = false,
+                                         const nsIntPoint& aSrcPoint = nsIntPoint(0, 0),
+                                         bool aPixelBuffer = false,
+                                         GLenum aTextureUnit = LOCAL_GL_TEXTURE0);
 
 
     void TexImage2D(GLenum target, GLint level, GLint internalformat,
                     GLsizei width, GLsizei height, GLsizei stride,
                     GLint pixelsize, GLint border, GLenum format,
                     GLenum type, const GLvoid *pixels);
 
     void TexSubImage2D(GLenum target, GLint level,
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -196,17 +196,17 @@ public:
         }
     }
 
     virtual bool GetSharedHandleDetails(SharedTextureShareType shareType,
                                         SharedTextureHandle sharedHandle,
                                         SharedHandleDetails& details)
     {
         details.mTarget = LOCAL_GL_TEXTURE_RECTANGLE_ARB;
-        details.mProgramType = RGBARectLayerProgramType;
+        details.mTextureFormat = FORMAT_R8G8B8A8;
         return true;
     }
 
     virtual bool AttachSharedHandle(SharedTextureShareType shareType,
                                     SharedTextureHandle sharedHandle)
     {
         MacIOSurface* surf = reinterpret_cast<MacIOSurface*>(sharedHandle);
         surf->CGLTexImageIOSurface2D(mContext, LOCAL_GL_RGBA, LOCAL_GL_BGRA,
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -115,16 +115,17 @@ public:
 #include "GLLibraryEGL.h"
 #include "nsDebug.h"
 #include "nsThreadUtils.h"
 
 #include "nsIWidget.h"
 
 #include "gfxCrashReporterUtils.h"
 
+using namespace mozilla::gfx;
 
 #if defined(MOZ_PLATFORM_MAEMO) || defined(MOZ_WIDGET_GONK)
 static bool gUseBackingSurface = true;
 #else
 static bool gUseBackingSurface = false;
 #endif
 
 #ifdef MOZ_WIDGET_GONK
@@ -976,25 +977,25 @@ bool GLContextEGL::GetSharedHandleDetail
     SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
 
     switch (wrapper->Type()) {
 #ifdef MOZ_WIDGET_ANDROID
     case SharedHandleType::SurfaceTexture: {
         SurfaceTextureWrapper* surfaceWrapper = reinterpret_cast<SurfaceTextureWrapper*>(wrapper);
 
         details.mTarget = LOCAL_GL_TEXTURE_EXTERNAL;
-        details.mProgramType = RGBALayerExternalProgramType;
+        details.mTextureFormat = FORMAT_R8G8B8A8;
         surfaceWrapper->SurfaceTexture()->GetTransformMatrix(details.mTextureTransform);
         break;
     }
 #endif
 
     case SharedHandleType::Image:
         details.mTarget = LOCAL_GL_TEXTURE_2D;
-        details.mProgramType = RGBALayerProgramType;
+        details.mTextureFormat = FORMAT_R8G8B8A8;
         break;
 
     default:
         NS_ERROR("Unknown shared handle type");
         return false;
     }
 
     return true;
@@ -1112,31 +1113,31 @@ public:
         , mConfig(nullptr)
         , mTextureState(aTextureState)
         , mBound(false)
     {
         mUpdateFormat = gfxPlatform::GetPlatform()->OptimalFormatForContent(GetContentType());
 
         if (gUseBackingSurface) {
             if (mUpdateFormat != gfxASurface::ImageFormatARGB32) {
-                mShaderType = RGBXLayerProgramType;
+                mTextureFormat = FORMAT_R8G8B8X8;
             } else {
-                mShaderType = RGBALayerProgramType;
+                mTextureFormat = FORMAT_R8G8B8A8;
             }
             Resize(aSize);
         } else {
             if (mUpdateFormat == gfxASurface::ImageFormatRGB16_565) {
-                mShaderType = RGBXLayerProgramType;
+                mTextureFormat = FORMAT_R8G8B8X8;
             } else if (mUpdateFormat == gfxASurface::ImageFormatRGB24) {
                 // RGB24 means really RGBX for Thebes, which means we have to
                 // use the right shader and ignore the uninitialized alpha
                 // value.
-                mShaderType = BGRXLayerProgramType;
+                mTextureFormat = FORMAT_B8G8R8X8;
             } else {
-                mShaderType = BGRALayerProgramType;
+                mTextureFormat = FORMAT_B8G8R8A8;
             }
         }
     }
 
     virtual ~TextureImageEGL()
     {
         GLContext *ctx = mGLContext;
         if (ctx->IsDestroyed() || !ctx->IsOwningThreadCurrent()) {
@@ -1291,17 +1292,17 @@ public:
         nsIntRegion region;
         if (mTextureState != Valid) {
             bounds = nsIntRect(0, 0, mSize.width, mSize.height);
             region = nsIntRegion(bounds);
         } else {
             region = aRegion;
         }
 
-        mShaderType =
+        mTextureFormat =
           mGLContext->UploadSurfaceToTexture(aSurf,
                                               region,
                                               mTexture,
                                               mTextureState == Created,
                                               bounds.TopLeft() + aFrom,
                                               false);
 
         mTextureState = Valid;
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -1057,19 +1057,19 @@ private:
         , mGLContext(aContext)
         , mUpdateSurface(aSurface)
         , mPixmap(aPixmap)
         , mInUpdate(false)
         , mTexture(aTexture)
         , sGLXLib(sGLXLibrary[aLibType])
     {
         if (aSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
-            mShaderType = gl::RGBALayerProgramType;
+            mTextureFormat = FORMAT_R8G8B8A8;
         } else {
-            mShaderType = gl::RGBXLayerProgramType;
+            mTextureFormat = FORMAT_R8G8B8X8;
         }
     }
 
     nsRefPtr<GLContext> mGLContext;
     nsRefPtr<gfxASurface> mUpdateSurface;
     GLXPixmap mPixmap;
     bool mInUpdate;
     GLuint mTexture;
--- a/gfx/gl/GLContextTypes.h
+++ b/gfx/gl/GLContextTypes.h
@@ -10,33 +10,16 @@ typedef unsigned int GLenum;
 typedef unsigned int GLbitfield;
 typedef unsigned int GLuint;
 typedef int GLint;
 typedef int GLsizei;
 
 namespace mozilla {
 namespace gl {
 
-enum ShaderProgramType {
-    RGBALayerProgramType,
-    RGBALayerExternalProgramType,
-    BGRALayerProgramType,
-    RGBXLayerProgramType,
-    BGRXLayerProgramType,
-    RGBARectLayerProgramType,
-    RGBAExternalLayerProgramType,
-    ColorLayerProgramType,
-    YCbCrLayerProgramType,
-    ComponentAlphaPass1ProgramType,
-    ComponentAlphaPass2ProgramType,
-    Copy2DProgramType,
-    Copy2DRectProgramType,
-    NumProgramTypes
-};
-
 struct GLFormats
 {
     // Constructs a zeroed object:
     GLFormats();
 
     GLenum color_texInternalFormat;
     GLenum color_texFormat;
     GLenum color_texType;
--- a/gfx/gl/GLTextureImage.cpp
+++ b/gfx/gl/GLTextureImage.cpp
@@ -93,17 +93,17 @@ BasicTextureImage::EndUpdate()
     // FIXME: this is the slow boat.  Make me fast (with GLXPixmap?).
 
     // Undo the device offset that BeginUpdate set; doesn't much matter for us here,
     // but important if we ever do anything directly with the surface.
     mUpdateSurface->SetDeviceOffset(gfxPoint(0, 0));
 
     bool relative = FinishedSurfaceUpdate();
 
-    mShaderType =
+    mTextureFormat =
         mGLContext->UploadSurfaceToTexture(mUpdateSurface,
                                            mUpdateRegion,
                                            mTexture,
                                            mTextureState == Created,
                                            mUpdateOffset,
                                            relative);
     FinishedSurfaceUpload();
 
@@ -151,17 +151,17 @@ BasicTextureImage::DirectUpdate(gfxASurf
     nsIntRegion region;
     if (mTextureState != Valid) {
         bounds = nsIntRect(0, 0, mSize.width, mSize.height);
         region = nsIntRegion(bounds);
     } else {
         region = aRegion;
     }
 
-    mShaderType =
+    mTextureFormat =
         mGLContext->UploadSurfaceToTexture(aSurf,
                                            region,
                                            mTexture,
                                            mTextureState == Created,
                                            bounds.TopLeft() + aFrom,
                                            false);
     mTextureState = Valid;
     return true;
@@ -263,17 +263,17 @@ TiledTextureImage::DirectUpdate(gfxASurf
             break;
         }
         // Override a callback cancelling iteration if the texture wasn't valid.
         // We need to force the update in that situation, or we may end up
         // showing invalid/out-of-date texture data.
     } while (NextTile() || (mTextureState != Valid));
     mCurrentImage = oldCurrentImage;
 
-    mShaderType = mImages[0]->GetShaderProgramType();
+    mTextureFormat = mImages[0]->GetTextureFormat();
     mTextureState = Valid;
     return result;
 }
 
 void
 TiledTextureImage::GetUpdateRegion(nsIntRegion& aForRegion)
 {
     if (mTextureState != Valid) {
@@ -375,17 +375,17 @@ TiledTextureImage::BeginUpdate(nsIntRegi
 void
 TiledTextureImage::EndUpdate()
 {
     NS_ASSERTION(mInUpdate, "EndUpdate not in update");
     if (!mUpdateSurface) { // update was to a single TextureImage
         mImages[mCurrentImage]->EndUpdate();
         mInUpdate = false;
         mTextureState = Valid;
-        mShaderType = mImages[mCurrentImage]->GetShaderProgramType();
+        mTextureFormat = mImages[mCurrentImage]->GetTextureFormat();
         return;
     }
 
     // upload tiles from temp surface
     for (unsigned i = 0; i < mImages.Length(); i++) {
         int xPos = (i % mColumns) * mTileSize;
         int yPos = (i / mColumns) * mTileSize;
         nsIntRect imageRect = nsIntRect(nsIntPoint(xPos,yPos), mImages[i]->GetSize());
@@ -402,17 +402,17 @@ TiledTextureImage::EndUpdate()
         ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
         ctx->SetSource(mUpdateSurface, gfxPoint(-xPos, -yPos));
         ctx->Paint();
         mImages[i]->EndUpdate();
     }
 
     mUpdateSurface = nullptr;
     mInUpdate = false;
-    mShaderType = mImages[0]->GetShaderProgramType();
+    mTextureFormat = mImages[0]->GetTextureFormat();
     mTextureState = Valid;
 }
 
 void TiledTextureImage::BeginTileIteration()
 {
     mCurrentImage = 0;
 }
 
--- a/gfx/gl/GLTextureImage.h
+++ b/gfx/gl/GLTextureImage.h
@@ -31,16 +31,18 @@ class GLContext;
  *
  *  (2) efficient manager of texture memory; e.g. by having clients draw
  *      into a scratch buffer which is then uploaded with
  *      glTexSubImage2D().
  */
 class TextureImage
 {
     NS_INLINE_DECL_REFCOUNTING(TextureImage)
+protected:
+    typedef gfxASurface::gfxImageFormat ImageFormat;
 public:
     enum TextureState
     {
       Created, // Texture created, but has not had glTexImage called to initialize it.
       Allocated,  // Texture memory exists, but contents are invalid.
       Valid  // Texture fully ready to use.
     };
 
@@ -196,23 +198,21 @@ public:
         {
             if (mTexture) {
                 mTexture->ApplyFilter();
             }
         }
     };
 
     /**
-     * Returns the shader program type that should be used to render
-     * this texture. Only valid after a matching BeginUpdate/EndUpdate
-     * pair have been called.
+     * Returns the image format of the texture. Only valid after a matching
+     * BeginUpdate/EndUpdate pair have been called.
      */
-    virtual ShaderProgramType GetShaderProgramType()
-    {
-         return mShaderType;
+    virtual gfx::SurfaceFormat GetTextureFormat() {
+        return mTextureFormat;
     }
 
     /** Can be called safely at any time. */
 
     /**
      * If this TextureImage has a permanent gfxASurface backing,
      * return it.  Otherwise return nullptr.
      */
@@ -253,17 +253,17 @@ protected:
 
     virtual nsIntRect GetSrcTileRect() {
         return nsIntRect(nsIntPoint(0,0), mSize);
     }
 
     nsIntSize mSize;
     GLenum mWrapMode;
     ContentType mContentType;
-    ShaderProgramType mShaderType;
+    gfx::SurfaceFormat mTextureFormat;
     gfxPattern::GraphicsFilter mFilter;
     Flags mFlags;
 };
 
 /**
  * BasicTextureImage is the baseline TextureImage implementation ---
  * it updates its texture by allocating a scratch buffer for the
  * client to draw into, then using glTexSubImage2D() to upload the new
@@ -271,17 +271,16 @@ protected:
  * into which the updated pixels will be drawn, and the code to
  * convert the update surface's pixels into an image on which we can
  * glTexSubImage2D().
  */
 class BasicTextureImage
     : public TextureImage
 {
 public:
-    typedef gfxASurface::gfxImageFormat ImageFormat;
     virtual ~BasicTextureImage();
 
     BasicTextureImage(GLuint aTexture,
                       const nsIntSize& aSize,
                       GLenum aWrapMode,
                       ContentType aContentType,
                       GLContext* aContext,
                       TextureImage::Flags aFlags = TextureImage::NoFlags)
--- a/gfx/layers/opengl/CanvasLayerOGL.cpp
+++ b/gfx/layers/opengl/CanvasLayerOGL.cpp
@@ -126,21 +126,17 @@ CanvasLayerOGL::Initialize(const Data& a
   } else if (aData.mSurface) {
     mCanvasSurface = aData.mSurface;
     mNeedsYFlip = false;
 #if defined(GL_PROVIDER_GLX)
     if (aData.mSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
         gfxXlibSurface *xsurf = static_cast<gfxXlibSurface*>(aData.mSurface);
         mPixmap = xsurf->GetGLXPixmap();
         if (mPixmap) {
-            if (aData.mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
-                mLayerProgram = gl::RGBALayerProgramType;
-            } else {
-                mLayerProgram = gl::RGBXLayerProgramType;
-            }
+            mLayerProgram = ShaderProgramFromContentType(aData.mSurface->GetContentType());
             MakeTextureIfNeeded(gl(), mUploadTexture);
         }
     }
 #endif
   } else if (aData.mGLContext) {
     mGLContext = aData.mGLContext;
     NS_ASSERTION(mGLContext->IsOffscreen(), "Canvas GLContext must be offscreen.");
     mIsGLAlphaPremult = aData.mIsGLAlphaPremult;
@@ -231,34 +227,36 @@ CanvasLayerOGL::UpdateSurface()
   } else if (mCanvasSurface) {
 #ifdef XP_MACOSX
     if (mDrawTarget && mDrawTarget->GetNativeSurface(gfx::NATIVE_SURFACE_CGCONTEXT_ACCELERATED)) {
       if (!mTexture) {
         mTexture = MakeIOSurfaceTexture((CGContextRef)mDrawTarget->GetNativeSurface(
                                         gfx::NATIVE_SURFACE_CGCONTEXT_ACCELERATED),
                                         gl());
         mTextureTarget = LOCAL_GL_TEXTURE_RECTANGLE_ARB;
-        mLayerProgram = gl::RGBARectLayerProgramType;
+        mLayerProgram = RGBARectLayerProgramType;
       }
       mDrawTarget->Flush();
       return;
     }
 #endif
     updatedSurface = mCanvasSurface;
   } else {
     MOZ_CRASH("Unhandled canvas layer type.");
   }
 
   if (updatedSurface) {
     mOGLManager->MakeCurrent();
-    mLayerProgram = gl()->UploadSurfaceToTexture(updatedSurface,
-                                                 mBounds,
-                                                 mUploadTexture,
-                                                 true,//false,
-                                                 nsIntPoint(0, 0));
+    gfx::SurfaceFormat format =
+      gl()->UploadSurfaceToTexture(updatedSurface,
+                                   mBounds,
+                                   mUploadTexture,
+                                   true,//false,
+                                   nsIntPoint(0, 0));
+    mLayerProgram = ShaderProgramFromSurfaceFormat(format);
     mTexture = mUploadTexture;
 
     if (temporarySurface)
       delete temporarySurface;
   }
 
   MOZ_ASSERT(mTexture || nothingToShow);
 }
@@ -289,39 +287,40 @@ CanvasLayerOGL::RenderLayer(int aPreviou
   ShaderProgramOGL *program = nullptr;
 
   nsIntRect drawRect = mBounds;
   if (mDelayedUpdates) {
     NS_ABORT_IF_FALSE(mCanvasSurface || mDrawTarget, "WebGL canvases should always be using full texture upload");
     
     drawRect.IntersectRect(drawRect, GetEffectiveVisibleRegion().GetBounds());
 
-    mLayerProgram =
+    gfx::SurfaceFormat format =
       gl()->UploadSurfaceToTexture(mCanvasSurface,
                                    nsIntRect(0, 0, drawRect.width, drawRect.height),
                                    mUploadTexture,
                                    true,
                                    drawRect.TopLeft());
+    mLayerProgram = ShaderProgramFromSurfaceFormat(format);
     mTexture = mUploadTexture;
   }
 
   if (!program) {
     program = mOGLManager->GetProgram(mLayerProgram, GetMaskLayer());
   }
 
 #if defined(GL_PROVIDER_GLX)
   if (mPixmap && !mDelayedUpdates) {
     sDefGLXLib.BindTexImage(mPixmap);
   }
 #endif
 
   gl()->ApplyFilterToBoundTexture(mFilter);
 
   program->Activate();
-  if (mLayerProgram == gl::RGBARectLayerProgramType) {
+  if (mLayerProgram == RGBARectLayerProgramType) {
     // This is used by IOSurface that use 0,0...w,h coordinate rather then 0,0..1,1.
     program->SetTexCoordMultiplier(mDrawTarget->GetSize().width, mDrawTarget->GetSize().height);
   }
   program->SetLayerQuadRect(drawRect);
   program->SetLayerTransform(GetEffectiveTransform());
   program->SetLayerOpacity(GetEffectiveOpacity());
   program->SetRenderOffset(aOffset);
   program->SetTextureUnit(0);
--- a/gfx/layers/opengl/CanvasLayerOGL.h
+++ b/gfx/layers/opengl/CanvasLayerOGL.h
@@ -23,17 +23,17 @@ namespace layers {
 class CanvasLayerOGL :
   public CanvasLayer,
   public LayerOGL
 {
 public:
   CanvasLayerOGL(LayerManagerOGL *aManager)
     : CanvasLayer(aManager, NULL)
     , LayerOGL(aManager)
-    , mLayerProgram(gl::RGBALayerProgramType)
+    , mLayerProgram(RGBALayerProgramType)
     , mTexture(0)
     , mTextureTarget(LOCAL_GL_TEXTURE_2D)
     , mDelayedUpdates(false)
     , mIsGLAlphaPremult(false)
     , mUploadTexture(0)
 #if defined(GL_PROVIDER_GLX)
     , mPixmap(0)
 #endif
@@ -56,17 +56,17 @@ public:
                            const nsIntPoint& aOffset);
   virtual void CleanupResources();
 
 protected:
   void UpdateSurface();
 
   nsRefPtr<gfxASurface> mCanvasSurface;
   nsRefPtr<GLContext> mGLContext;
-  gl::ShaderProgramType mLayerProgram;
+  ShaderProgramType mLayerProgram;
   RefPtr<gfx::DrawTarget> mDrawTarget;
 
   GLuint mTexture;
   GLenum mTextureTarget;
 
   bool mDelayedUpdates;
   bool mIsGLAlphaPremult;
   bool mNeedsYFlip;
--- a/gfx/layers/opengl/ColorLayerOGL.cpp
+++ b/gfx/layers/opengl/ColorLayerOGL.cpp
@@ -29,17 +29,17 @@ RenderColorLayer(ColorLayer* aLayer, Lay
    */
   gfxRGBA color(aLayer->GetColor());
   float opacity = aLayer->GetEffectiveOpacity() * color.a;
   color.r *= opacity;
   color.g *= opacity;
   color.b *= opacity;
   color.a = opacity;
 
-  ShaderProgramOGL *program = aManager->GetProgram(gl::ColorLayerProgramType,
+  ShaderProgramOGL *program = aManager->GetProgram(ColorLayerProgramType,
                                                    aLayer->GetMaskLayer());
   program->Activate();
   program->SetLayerQuadRect(visibleRect);
   program->SetLayerTransform(aLayer->GetEffectiveTransform());
   program->SetRenderOffset(aOffset);
   program->SetRenderColor(color);
   program->LoadMask(aLayer->GetMaskLayer());
 
--- a/gfx/layers/opengl/CompositingRenderTargetOGL.h
+++ b/gfx/layers/opengl/CompositingRenderTargetOGL.h
@@ -155,17 +155,17 @@ public:
     return mTransform;
   }
 
 #ifdef MOZ_DUMP_PAINTING
   virtual already_AddRefed<gfxImageSurface> Dump(Compositor* aCompositor)
   {
     MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
     CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(aCompositor);
-    return mGL->GetTexImage(mTextureHandle, true, compositorOGL->GetFBOLayerProgramType());
+    return mGL->GetTexImage(mTextureHandle, true, compositorOGL->GetFBOFormat());
   }
 #endif
 
 private:
   /**
    * Actually do the initialisation. Note that we leave our FBO bound, and so
    * calling this method is only suitable when about to use this render target.
    */
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -379,17 +379,17 @@ CompositorOGL::Initialize()
   mGLContext->fEnable(LOCAL_GL_BLEND);
 
   mPrograms.AppendElements(NumProgramTypes);
   for (int type = 0; type < NumProgramTypes; ++type) {
     AddPrograms(static_cast<ShaderProgramType>(type));
   }
 
   // initialise a common shader to check that we can actually compile a shader
-  if (!mPrograms[gl::RGBALayerProgramType].mVariations[MaskNone]->Initialize()) {
+  if (!mPrograms[RGBALayerProgramType].mVariations[MaskNone]->Initialize()) {
     return false;
   }
 
   if (mGLContext->WorkAroundDriverBugs()) {
     /**
     * We'll test the ability here to bind NPOT textures to a framebuffer, if
     * this fails we'll try ARB_texture_rectangle.
     */
@@ -947,38 +947,40 @@ CompositorOGL::CreateFBOWithTexture(cons
   mGLContext->fBindTexture(mFBOTextureTarget, 0);
 
   mGLContext->fGenFramebuffers(1, &fbo);
 
   *aFBO = fbo;
   *aTexture = tex;
 }
 
-gl::ShaderProgramType
+ShaderProgramType
 CompositorOGL::GetProgramTypeForEffect(Effect *aEffect) const
 {
   switch(aEffect->mType) {
   case EFFECT_SOLID_COLOR:
-    return gl::ColorLayerProgramType;
+    return ColorLayerProgramType;
   case EFFECT_RGBA:
   case EFFECT_RGBX:
   case EFFECT_BGRA:
   case EFFECT_BGRX:
   {
     TexturedEffect* texturedEffect =
         static_cast<TexturedEffect*>(aEffect);
     TextureSourceOGL* source = texturedEffect->mTexture->AsSourceOGL();
-    return source->GetShaderProgram();
+
+    return ShaderProgramFromTargetAndFormat(source->GetTextureTarget(),
+                                            source->GetTextureFormat());
   }
   case EFFECT_YCBCR:
-    return gl::YCbCrLayerProgramType;
+    return YCbCrLayerProgramType;
   case EFFECT_RENDER_TARGET:
     return GetFBOLayerProgramType();
   default:
-    return gl::RGBALayerProgramType;
+    return RGBALayerProgramType;
   }
 }
 
 struct MOZ_STACK_CLASS AutoBindTexture
 {
   AutoBindTexture() : mTexture(nullptr) {}
   AutoBindTexture(TextureSourceOGL* aTexture, GLenum aTextureUnit)
    : mTexture(nullptr) { Bind(aTexture, aTextureUnit); }
@@ -1041,20 +1043,20 @@ CompositorOGL::DrawQuad(const Rect& aRec
 
     maskType = effectMask->mIs3D
                  ? Mask3d
                  : Mask2d;
   } else {
     maskType = MaskNone;
   }
 
-  gl::ShaderProgramType programType = GetProgramTypeForEffect(aEffectChain.mPrimaryEffect);
+  ShaderProgramType programType = GetProgramTypeForEffect(aEffectChain.mPrimaryEffect);
   ShaderProgramOGL *program = GetProgram(programType, maskType);
   program->Activate();
-  if (programType == gl::RGBARectLayerProgramType) {
+  if (programType == RGBARectLayerProgramType) {
     TexturedEffect* texturedEffect =
         static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get());
     TextureSourceOGL* source = texturedEffect->mTexture->AsSourceOGL();
     // This is used by IOSurface that use 0,0...w,h coordinate rather then 0,0..1,1.
     program->SetTexCoordMultiplier(source->GetSize().width, source->GetSize().height);
   }
   program->SetLayerQuadRect(aRect);
   program->SetLayerTransform(aTransform);
@@ -1100,17 +1102,17 @@ CompositorOGL::DrawQuad(const Rect& aRec
       TextureSource *source = texturedEffect->mTexture;
 
       if (!texturedEffect->mPremultiplied) {
         mGLContext->fBlendFuncSeparate(LOCAL_GL_SRC_ALPHA, LOCAL_GL_ONE_MINUS_SRC_ALPHA,
                                        LOCAL_GL_ONE, LOCAL_GL_ONE);
       }
 
       AutoBindTexture bindSource(source->AsSourceOGL(), LOCAL_GL_TEXTURE0);
-      if (programType == gl::RGBALayerExternalProgramType) {
+      if (programType == RGBALayerExternalProgramType) {
         program->SetTextureTransform(source->AsSourceOGL()->GetTextureTransform());
       }
 
       mGLContext->ApplyFilterToBoundTexture(source->AsSourceOGL()->GetTextureTarget(),
                                             ThebesFilter(texturedEffect->mFilter));
 
       program->SetTextureUnit(0);
       program->SetLayerOpacity(aOpacity);
@@ -1208,21 +1210,21 @@ CompositorOGL::DrawQuad(const Rect& aRec
           !sourceOnWhite->IsValid()) {
         NS_WARNING("Invalid layer texture for component alpha");
         return;
       }
 
       for (int32_t pass = 1; pass <=2; ++pass) {
         ShaderProgramOGL* program;
         if (pass == 1) {
-          program = GetProgram(gl::ComponentAlphaPass1ProgramType, maskType);
+          program = GetProgram(ComponentAlphaPass1ProgramType, maskType);
           gl()->fBlendFuncSeparate(LOCAL_GL_ZERO, LOCAL_GL_ONE_MINUS_SRC_COLOR,
                                    LOCAL_GL_ONE, LOCAL_GL_ONE);
         } else {
-          program = GetProgram(gl::ComponentAlphaPass2ProgramType, maskType);
+          program = GetProgram(ComponentAlphaPass2ProgramType, maskType);
           gl()->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE,
                                    LOCAL_GL_ONE, LOCAL_GL_ONE);
         }
 
         AutoBindTexture bindSourceOnBlack(sourceOnBlack, LOCAL_GL_TEXTURE0);
         AutoBindTexture bindSourceOnWhite(sourceOnWhite, LOCAL_GL_TEXTURE1);
 
         program->Activate();
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -19,17 +19,17 @@ namespace layers {
 
 struct FPSState;
 class CompositingRenderTargetOGL;
 class GLManagerCompositor;
 
 class CompositorOGL : public Compositor
 {
   typedef mozilla::gl::GLContext GLContext;
-  typedef mozilla::gl::ShaderProgramType ProgramType;
+  typedef ShaderProgramType ProgramType;
   
   friend class GLManagerCompositor;
 
 public:
   CompositorOGL(nsIWidget *aWidget, int aSurfaceWidth = -1, int aSurfaceHeight = -1,
                 bool aUseExternalSurfaceSize = false);
 
   virtual ~CompositorOGL();
@@ -125,19 +125,22 @@ public:
   virtual bool Resume() MOZ_OVERRIDE;
 
   virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; }
   virtual const nsIntSize& GetWidgetSize() MOZ_OVERRIDE {
     return mWidgetSize;
   }
 
   GLContext* gl() const { return mGLContext; }
-  gl::ShaderProgramType GetFBOLayerProgramType() const {
+  ShaderProgramType GetFBOLayerProgramType() const {
     return mFBOTextureTarget == LOCAL_GL_TEXTURE_RECTANGLE_ARB ?
-           gl::RGBARectLayerProgramType : gl::RGBALayerProgramType;
+           RGBARectLayerProgramType : RGBALayerProgramType;
+  }
+  gfx::SurfaceFormat GetFBOFormat() const {
+    return gfx::FORMAT_R8G8B8A8;
   }
 
   /**
    * The compositor provides with temporary textures for use with direct
    * textruing like gralloc texture.
    * Doing so lets us use gralloc the way it has been designed to be used
    * (see https://wiki.mozilla.org/Platform/GFX/Gralloc)
    */
@@ -211,30 +214,30 @@ private:
    * sets *aClipRectOut to the screen dimensions.
    */
   virtual void BeginFrame(const gfx::Rect *aClipRectIn,
                           const gfxMatrix& aTransform,
                           const gfx::Rect& aRenderBounds, 
                           gfx::Rect *aClipRectOut = nullptr,
                           gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE;
 
-  gl::ShaderProgramType GetProgramTypeForEffect(Effect* aEffect) const;
+  ShaderProgramType GetProgramTypeForEffect(Effect* aEffect) const;
 
   /**
    * Updates all layer programs with a new projection matrix.
    */
   void SetLayerProgramProjectionMatrix(const gfx3DMatrix& aMatrix);
 
   /**
    * Helper method for Initialize, creates all valid variations of a program
    * and adds them to mPrograms
    */
-  void AddPrograms(gl::ShaderProgramType aType);
+  void AddPrograms(ShaderProgramType aType);
 
-  ShaderProgramOGL* GetProgram(gl::ShaderProgramType aType,
+  ShaderProgramOGL* GetProgram(ShaderProgramType aType,
                                MaskType aMask = MaskNone) {
     MOZ_ASSERT(ProgramProfileOGL::ProgramExists(aType, aMask),
                "Invalid program type.");
     return mPrograms[aType].mVariations[aMask];
   }
 
   /**
    * Create a FBO backed by a texture.
--- a/gfx/layers/opengl/ContainerLayerOGL.cpp
+++ b/gfx/layers/opengl/ContainerLayerOGL.cpp
@@ -282,17 +282,17 @@ ContainerRender(Container* aContainer,
   }
 
 
   if (needsFramebuffer) {
     // Unbind the current framebuffer and rebind the previous one.
 #ifdef MOZ_DUMP_PAINTING
     if (gfxUtils::sDumpPainting) {
       nsRefPtr<gfxImageSurface> surf = 
-        aContainer->gl()->GetTexImage(containerSurface, true, aManager->GetFBOLayerProgramType());
+        aContainer->gl()->GetTexImage(containerSurface, true, aManager->GetFBOTextureFormat());
 
       WriteSnapshotToDumpFile(aContainer, surf);
     }
 #endif
     
     // Restore the viewport
     aContainer->gl()->PopViewportRect();
     nsIntRect viewport = aContainer->gl()->ViewportRect();
--- a/gfx/layers/opengl/GLManager.cpp
+++ b/gfx/layers/opengl/GLManager.cpp
@@ -42,17 +42,17 @@ public:
     : mImpl(aCompositor)
   {}
 
   virtual GLContext* gl() const MOZ_OVERRIDE
   {
     return mImpl->gl();
   }
 
-  virtual ShaderProgramOGL* GetProgram(gl::ShaderProgramType aType) MOZ_OVERRIDE
+  virtual ShaderProgramOGL* GetProgram(ShaderProgramType aType) MOZ_OVERRIDE
   {
     return mImpl->GetProgram(aType);
   }
 
   virtual void BindAndDrawQuad(ShaderProgramOGL *aProg) MOZ_OVERRIDE
   {
     mImpl->BindAndDrawQuad(aProg);
   }
--- a/gfx/layers/opengl/GLManager.h
+++ b/gfx/layers/opengl/GLManager.h
@@ -22,16 +22,19 @@ namespace layers {
 class GLManager
 {
 public:
   static GLManager* CreateGLManager(LayerManager* aManager);
 
   virtual ~GLManager() {}
 
   virtual gl::GLContext* gl() const = 0;
-  virtual ShaderProgramOGL* GetProgram(gl::ShaderProgramType aType) = 0;
+  virtual ShaderProgramOGL* GetProgram(ShaderProgramType aType) = 0;
   virtual void BindAndDrawQuad(ShaderProgramOGL *aProg) = 0;
 
+  ShaderProgramOGL* GetProgram(gfx::SurfaceFormat aFormat) {
+    return GetProgram(ShaderProgramFromSurfaceFormat(aFormat));
+  }
 };
 
 }
 }
 #endif
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -225,17 +225,17 @@ ImageLayerOGL::RenderLayer(int,
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, data->mTextures[2].GetTextureID());
     gl()->ApplyFilterToBoundTexture(mFilter);
     gl()->fActiveTexture(LOCAL_GL_TEXTURE1);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, data->mTextures[1].GetTextureID());
     gl()->ApplyFilterToBoundTexture(mFilter);
     gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, data->mTextures[0].GetTextureID());
     gl()->ApplyFilterToBoundTexture(mFilter);
-    
+
     ShaderProgramOGL *program = mOGLManager->GetProgram(YCbCrLayerProgramType,
                                                         GetMaskLayer());
 
     program->Activate();
     program->SetLayerQuadRect(nsIntRect(0, 0,
                                         yuvImage->GetSize().width,
                                         yuvImage->GetSize().height));
     program->SetLayerTransform(GetEffectiveTransform());
@@ -283,18 +283,17 @@ ImageLayerOGL::RenderLayer(int,
       return;
     }
 
     gl()->MakeCurrent();
 
     gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, data->mTexture.GetTextureID());
 
-    ShaderProgramOGL *program = 
-      mOGLManager->GetProgram(data->mLayerProgram, GetMaskLayer());
+    ShaderProgramOGL *program = mOGLManager->GetProgram(data->mLayerProgram, GetMaskLayer());
 
     gl()->ApplyFilterToBoundTexture(mFilter);
 
     program->Activate();
     program->SetLayerQuadRect(nsIntRect(0, 0, 
                                         cairoImage->GetSize().width, 
                                         cairoImage->GetSize().height));
     program->SetLayerTransform(GetEffectiveTransform());
@@ -309,20 +308,23 @@ ImageLayerOGL::RenderLayer(int,
       static_cast<SharedTextureImage*>(image);
     const SharedTextureImage::Data* data = texImage->GetData();
     GLContext::SharedHandleDetails handleDetails;
     if (!gl()->GetSharedHandleDetails(data->mShareType, data->mHandle, handleDetails)) {
       NS_ERROR("Failed to get shared handle details");
       return;
     }
 
-    ShaderProgramOGL* program = mOGLManager->GetProgram(handleDetails.mProgramType, GetMaskLayer());
+    ShaderProgramType programType =
+      ShaderProgramFromTargetAndFormat(handleDetails.mTarget,
+                                       handleDetails.mTextureFormat);
+    ShaderProgramOGL* program = mOGLManager->GetProgram(programType, GetMaskLayer());
 
     program->Activate();
-    if (handleDetails.mProgramType == gl::RGBARectLayerProgramType) {
+    if (programType == RGBARectLayerProgramType) {
       // 2DRect case, get the multiplier right for a sampler2DRect
       program->SetTexCoordMultiplier(data->mSize.width, data->mSize.height);
     }
     program->SetLayerTransform(GetEffectiveTransform());
     program->SetLayerOpacity(GetEffectiveOpacity());
     program->SetRenderOffset(aOffset);
     program->SetTextureUnit(0);
     program->SetTextureTransform(handleDetails.mTextureTransform);
@@ -454,35 +456,31 @@ ImageLayerOGL::AllocateTexturesCairo(Cai
   SetClamping(gl, tex);
 
 #if defined(GL_PROVIDER_GLX)
   if (aImage->mSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
     gfxXlibSurface *xsurf =
       static_cast<gfxXlibSurface*>(aImage->mSurface.get());
     GLXPixmap pixmap = xsurf->GetGLXPixmap();
     if (pixmap) {
-      if (aImage->mSurface->GetContentType()
-          == gfxASurface::CONTENT_COLOR_ALPHA) {
-        backendData->mLayerProgram = gl::RGBALayerProgramType;
-      } else {
-        backendData->mLayerProgram = gl::RGBXLayerProgramType;
-      }
+      backendData->mLayerProgram = ShaderProgramFromContentType(aImage->mSurface->GetContentType());
 
       aImage->SetBackendData(LAYERS_OPENGL, backendData.forget());
 
       sDefGLXLib.BindTexImage(pixmap);
 
       return;
     }
   }
 #endif
-  backendData->mLayerProgram =
+  gfx::SurfaceFormat format =
     gl->UploadSurfaceToTexture(aImage->mSurface,
                                nsIntRect(0,0, aImage->mSize.width, aImage->mSize.height),
                                tex, true);
+  backendData->mLayerProgram = ShaderProgramFromSurfaceFormat(format);
 
   aImage->SetBackendData(LAYERS_OPENGL, backendData.forget());
 }
 
 /*
  * Returns a size that is larger than and closest to aSize where both
  * width and height are powers of two.
  * If the OpenGL setup is capable of using non-POT textures, then it
@@ -542,23 +540,24 @@ ImageLayerOGL::LoadAsTexture(GLuint aTex
       return false;
     }
 
     mozilla::gl::GLContext *texGL = texture.GetGLContext();
     texGL->MakeCurrent();
 
     GLuint texID = texture.GetTextureID();
 
-    data->mLayerProgram =
+    gfx::SurfaceFormat format =
       texGL->UploadSurfaceToTexture(cairoImage->mSurface,
                                     nsIntRect(0,0,
                                               data->mTextureSize.width,
                                               data->mTextureSize.height),
                                     texID, true, nsIntPoint(0,0), false,
                                     aTextureUnit);
+    data->mLayerProgram = ShaderProgramFromSurfaceFormat(format);
 
     cairoImage->SetBackendData(LAYERS_OPENGL, data);
 
     gl()->MakeCurrent();
     gl()->fActiveTexture(aTextureUnit);
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, texID);
     gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER,
                          LOCAL_GL_LINEAR);
--- a/gfx/layers/opengl/ImageLayerOGL.h
+++ b/gfx/layers/opengl/ImageLayerOGL.h
@@ -142,17 +142,17 @@ struct PlanarYCbCrOGLBackendData : publi
   GLTexture mTextures[3];
   gfxIntSize mYSize, mCbCrSize;
   nsRefPtr<TextureRecycleBin> mTextureRecycleBin;
 };
 
 
 struct CairoOGLBackendData : public ImageBackendData
 {
-  CairoOGLBackendData() : mLayerProgram(gl::RGBALayerProgramType) {}
+  CairoOGLBackendData() : mLayerProgram(RGBALayerProgramType) {}
   GLTexture mTexture;
-  gl::ShaderProgramType mLayerProgram;
+  ShaderProgramType mLayerProgram;
   gfxIntSize mTextureSize;
 };
 
 } /* layers */
 } /* mozilla */
 #endif /* GFX_IMAGELAYEROGL_H */
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -287,17 +287,17 @@ LayerManagerOGL::Initialize(bool force)
   mGLContext->fEnable(LOCAL_GL_BLEND);
 
   mPrograms.AppendElements(NumProgramTypes);
   for (int type = 0; type < NumProgramTypes; ++type) {
     AddPrograms(static_cast<ShaderProgramType>(type));
   }
 
   // initialise a common shader to check that we can actually compile a shader
-  if (!mPrograms[gl::RGBALayerProgramType].mVariations[MaskNone]->Initialize()) {
+  if (!mPrograms[RGBALayerProgramType].mVariations[MaskNone]->Initialize()) {
 #ifdef MOZ_WIDGET_ANDROID
     NS_RUNTIMEABORT("Shader initialization failed");
 #endif
     return false;
   }
 
 
   mGLContext->fGenFramebuffers(1, &mBackBufferFBO);
--- a/gfx/layers/opengl/LayerManagerOGL.h
+++ b/gfx/layers/opengl/LayerManagerOGL.h
@@ -41,17 +41,16 @@ struct FPSState;
 
 /**
  * This is the LayerManager used for OpenGL 2.1 and OpenGL ES 2.0.
  * This should be used only on the main thread.
  */
 class LayerManagerOGL : public LayerManager
 {
   typedef mozilla::gl::GLContext GLContext;
-  typedef mozilla::gl::ShaderProgramType ProgramType;
 
 public:
   LayerManagerOGL(nsIWidget *aWidget, int aSurfaceWidth = -1, int aSurfaceHeight = -1,
                   bool aIsRenderingToEGLSurface = false);
   virtual ~LayerManagerOGL();
 
   void Destroy();
 
@@ -120,53 +119,57 @@ public:
   /**
    * Helper methods.
    */
   void MakeCurrent(bool aForce = false);
 
   ShaderProgramOGL* GetBasicLayerProgram(bool aOpaque, bool aIsRGB,
                                          MaskType aMask = MaskNone)
   {
-    gl::ShaderProgramType format = gl::BGRALayerProgramType;
+    ShaderProgramType format = BGRALayerProgramType;
     if (aIsRGB) {
       if (aOpaque) {
-        format = gl::RGBXLayerProgramType;
+        format = RGBXLayerProgramType;
       } else {
-        format = gl::RGBALayerProgramType;
+        format = RGBALayerProgramType;
       }
     } else {
       if (aOpaque) {
-        format = gl::BGRXLayerProgramType;
+        format = BGRXLayerProgramType;
       }
     }
     return GetProgram(format, aMask);
   }
 
-  ShaderProgramOGL* GetProgram(gl::ShaderProgramType aType,
+  ShaderProgramOGL* GetProgram(ShaderProgramType aType,
                                Layer* aMaskLayer) {
     if (aMaskLayer)
       return GetProgram(aType, Mask2d);
     return GetProgram(aType, MaskNone);
   }
 
-  ShaderProgramOGL* GetProgram(gl::ShaderProgramType aType,
+  ShaderProgramOGL* GetProgram(ShaderProgramType aType,
                                MaskType aMask = MaskNone) {
     NS_ASSERTION(ProgramProfileOGL::ProgramExists(aType, aMask),
                  "Invalid program type.");
     return mPrograms[aType].mVariations[aMask];
   }
 
   ShaderProgramOGL* GetFBOLayerProgram(MaskType aMask = MaskNone) {
     return GetProgram(GetFBOLayerProgramType(), aMask);
   }
 
-  gl::ShaderProgramType GetFBOLayerProgramType() {
+  ShaderProgramType GetFBOLayerProgramType() {
     if (mFBOTextureTarget == LOCAL_GL_TEXTURE_RECTANGLE_ARB)
-      return gl::RGBARectLayerProgramType;
-    return gl::RGBALayerProgramType;
+      return RGBARectLayerProgramType;
+    return RGBALayerProgramType;
+  }
+
+  gfx::SurfaceFormat GetFBOTextureFormat() {
+    return gfx::FORMAT_R8G8B8A8;
   }
 
   GLContext* gl() const { return mGLContext; }
 
   // |NSOpenGLContext*|:
   void* GetNSOpenGLContext() const;
 
   DrawThebesLayerCallback GetThebesLayerCallback() const
@@ -390,17 +393,17 @@ private:
    * Updates all layer programs with a new projection matrix.
    */
   void SetLayerProgramProjectionMatrix(const gfx3DMatrix& aMatrix);
 
   /**
    * Helper method for Initialize, creates all valid variations of a program
    * and adds them to mPrograms
    */
-  void AddPrograms(gl::ShaderProgramType aType);
+  void AddPrograms(ShaderProgramType aType);
 
   /**
    * Recursive helper method for use by ComputeRenderIntegrity. Subtracts
    * any incomplete rendering on aLayer from aScreenRegion. Any low-precision
    * rendering is included in aLowPrecisionScreenRegion. aTransform is the
    * accumulated transform of intermediate surfaces beneath aLayer.
    */
   static void ComputeRenderIntegrityInternal(Layer* aLayer,
--- a/gfx/layers/opengl/LayerManagerOGLProgram.cpp
+++ b/gfx/layers/opengl/LayerManagerOGLProgram.cpp
@@ -31,188 +31,188 @@ void
 AddCommonTextureArgs(ProgramProfileOGL& aProfile)
 {
   aProfile.mUniforms.AppendElement(Argument("uLayerOpacity"));
   aProfile.mUniforms.AppendElement(Argument("uTexture"));
   aProfile.mAttributes.AppendElement(Argument("aTexCoord"));
 }
 
 /* static */ ProgramProfileOGL
-ProgramProfileOGL::GetProfileFor(gl::ShaderProgramType aType,
+ProgramProfileOGL::GetProfileFor(ShaderProgramType aType,
                                  MaskType aMask)
 {
   NS_ASSERTION(ProgramExists(aType, aMask), "Invalid program type.");
   ProgramProfileOGL result;
 
   switch (aType) {
-  case gl::RGBALayerProgramType:
+  case RGBALayerProgramType:
     if (aMask == Mask3d) {
       result.mVertexShaderString = sLayerMask3DVS;
       result.mFragmentShaderString = sRGBATextureLayerMask3DFS;
     } else if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sRGBATextureLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sRGBATextureLayerFS;
     }
     AddCommonArgs(result);
     AddCommonTextureArgs(result);
     result.mTextureCount = 1;
     break;
-  case gl::RGBALayerExternalProgramType:
+  case RGBALayerExternalProgramType:
     if (aMask == Mask3d) {
       result.mVertexShaderString = sLayerMask3DVS;
       result.mFragmentShaderString = sRGBATextureLayerExternalMask3DFS;
     } else if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sRGBATextureLayerExternalMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sRGBATextureLayerExternalFS;
     }
     AddCommonArgs(result);
     AddCommonTextureArgs(result);
     result.mUniforms.AppendElement(Argument("uTextureTransform"));
     result.mHasTextureTransform = true;
     result.mTextureCount = 1;
     break;
-  case gl::BGRALayerProgramType:
+  case BGRALayerProgramType:
     if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sBGRATextureLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sBGRATextureLayerFS;
     }
     AddCommonArgs(result);
     AddCommonTextureArgs(result);
     result.mTextureCount = 1;
     break;
-  case gl::RGBXLayerProgramType:
+  case RGBXLayerProgramType:
     if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sRGBXTextureLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sRGBXTextureLayerFS;
     }
     AddCommonArgs(result);
     AddCommonTextureArgs(result);
     result.mTextureCount = 1;
     break;
-  case gl::BGRXLayerProgramType:
+  case BGRXLayerProgramType:
     if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sBGRXTextureLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sBGRXTextureLayerFS;
     }
     AddCommonArgs(result);
     AddCommonTextureArgs(result);
     result.mTextureCount = 1;
     break;
-  case gl::RGBARectLayerProgramType:
+  case RGBARectLayerProgramType:
     if (aMask == Mask3d) {
       result.mVertexShaderString = sLayerMask3DVS;
       result.mFragmentShaderString = sRGBARectTextureLayerMask3DFS;
     } else if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sRGBARectTextureLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sRGBARectTextureLayerFS;
     }
     AddCommonArgs(result);
     AddCommonTextureArgs(result);
     result.mTextureCount = 1;
     break;
-  case gl::RGBAExternalLayerProgramType:
+  case RGBAExternalLayerProgramType:
     if (aMask == Mask3d) {
       result.mVertexShaderString = sLayerMask3DVS;
       result.mFragmentShaderString = sRGBAExternalTextureLayerMask3DFS;
     } else if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sRGBAExternalTextureLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sRGBAExternalTextureLayerFS;
     }
     AddCommonArgs(result);
     AddCommonTextureArgs(result);
     result.mTextureCount = 1;
     break;
-  case gl::ColorLayerProgramType:
+  case ColorLayerProgramType:
     if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sSolidColorLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sSolidColorLayerFS;
     }
     AddCommonArgs(result);
     result.mUniforms.AppendElement(Argument("uRenderColor"));
     break;
-  case gl::YCbCrLayerProgramType:
+  case YCbCrLayerProgramType:
     if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sYCbCrTextureLayerMaskFS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sYCbCrTextureLayerFS;
     }
     AddCommonArgs(result);
     result.mUniforms.AppendElement(Argument("uLayerOpacity"));
     result.mUniforms.AppendElement(Argument("uYTexture"));
     result.mUniforms.AppendElement(Argument("uCbTexture"));
     result.mUniforms.AppendElement(Argument("uCrTexture"));
     result.mAttributes.AppendElement(Argument("aTexCoord"));
     result.mTextureCount = 3;
     break;
-  case gl::ComponentAlphaPass1ProgramType:
+  case ComponentAlphaPass1ProgramType:
     if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sComponentPassMask1FS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sComponentPass1FS;
     }
     AddCommonArgs(result);
     result.mUniforms.AppendElement(Argument("uLayerOpacity"));
     result.mUniforms.AppendElement(Argument("uBlackTexture"));
     result.mUniforms.AppendElement(Argument("uWhiteTexture"));
     result.mAttributes.AppendElement(Argument("aTexCoord"));
     result.mTextureCount = 2;
     break;
-  case gl::ComponentAlphaPass2ProgramType:
+  case ComponentAlphaPass2ProgramType:
     if (aMask == Mask2d) {
       result.mVertexShaderString = sLayerMaskVS;
       result.mFragmentShaderString = sComponentPassMask2FS;
     } else {
       result.mVertexShaderString = sLayerVS;
       result.mFragmentShaderString = sComponentPass2FS;
     }
     AddCommonArgs(result);
     result.mUniforms.AppendElement(Argument("uLayerOpacity"));
     result.mUniforms.AppendElement(Argument("uBlackTexture"));
     result.mUniforms.AppendElement(Argument("uWhiteTexture"));
     result.mAttributes.AppendElement(Argument("aTexCoord"));
     result.mTextureCount = 2;
     break;
-  case gl::Copy2DProgramType:
+  case Copy2DProgramType:
     NS_ASSERTION(!aMask, "Program does not have masked variant.");
     result.mVertexShaderString = sCopyVS;
     result.mFragmentShaderString = sCopy2DFS;
     result.mUniforms.AppendElement(Argument("uTexture"));
     result.mAttributes.AppendElement(Argument("aVertexCoord"));
     result.mAttributes.AppendElement(Argument("aTexCoord"));
     result.mTextureCount = 1;
     break;
-  case gl::Copy2DRectProgramType:
+  case Copy2DRectProgramType:
     NS_ASSERTION(!aMask, "Program does not have masked variant.");
     result.mVertexShaderString = sCopyVS;
     result.mFragmentShaderString = sCopy2DRectFS;
     result.mUniforms.AppendElement(Argument("uTexture"));
     result.mAttributes.AppendElement(Argument("aVertexCoord"));
     result.mAttributes.AppendElement(Argument("aTexCoord"));
     result.mTextureCount = 1;
     break;
--- a/gfx/layers/opengl/LayerManagerOGLProgram.h
+++ b/gfx/layers/opengl/LayerManagerOGLProgram.h
@@ -8,66 +8,129 @@
 
 #include <string.h>
 
 #include "prenv.h"
 
 #include "nsString.h"
 #include "nsTArray.h"
 #include "GLContextTypes.h"
+#include "GLDefs.h"
 #include "gfx3DMatrix.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "gfxColor.h"
 #include "mozilla/gfx/Matrix.h"
 #include "mozilla/RefPtr.h"
+#include "gfxASurface.h"
 
 namespace mozilla {
 namespace gl {
 class GLContext;
 }
 namespace layers {
 
 class Layer;
 
+enum ShaderProgramType {
+  RGBALayerProgramType,
+  RGBALayerExternalProgramType,
+  BGRALayerProgramType,
+  RGBXLayerProgramType,
+  BGRXLayerProgramType,
+  RGBARectLayerProgramType,
+  RGBAExternalLayerProgramType,
+  ColorLayerProgramType,
+  YCbCrLayerProgramType,
+  ComponentAlphaPass1ProgramType,
+  ComponentAlphaPass2ProgramType,
+  Copy2DProgramType,
+  Copy2DRectProgramType,
+  NumProgramTypes
+};
+
+static inline ShaderProgramType
+ShaderProgramFromSurfaceFormat(gfx::SurfaceFormat aFormat)
+{
+  switch (aFormat) {
+    case gfx::FORMAT_B8G8R8A8:
+      return BGRALayerProgramType;
+    case gfx::FORMAT_B8G8R8X8:
+      return BGRXLayerProgramType;
+    case gfx::FORMAT_R8G8B8A8:
+      return RGBALayerProgramType;
+    case gfx::FORMAT_R8G8B8X8:
+    case gfx::FORMAT_R5G6B5:
+      return RGBXLayerProgramType;
+    case gfx::FORMAT_A8:
+      // We don't have a specific luminance shader
+      break;
+    default:
+      NS_ASSERTION(false, "Unhandled surface format!");
+  }
+  return ShaderProgramType(0);
+}
+
+static inline ShaderProgramType
+ShaderProgramFromTargetAndFormat(GLenum aTarget,
+                                 gfx::SurfaceFormat aFormat)
+{
+  switch(aTarget) {
+    case LOCAL_GL_TEXTURE_EXTERNAL:
+      return RGBALayerExternalProgramType;
+    case LOCAL_GL_TEXTURE_RECTANGLE_ARB:
+      return RGBARectLayerProgramType;
+    default:
+      return ShaderProgramFromSurfaceFormat(aFormat);
+  }
+}
+
+static inline ShaderProgramType
+ShaderProgramFromContentType(gfxASurface::gfxContentType aContentType)
+{
+  if (aContentType == gfxASurface::CONTENT_COLOR_ALPHA)
+    return RGBALayerProgramType;
+  return RGBXLayerProgramType;
+}
+
 /**
  * This struct represents the shaders that make up a program and the uniform
  * and attribute parmeters that those shaders take.
  * It is used by ShaderProgramOGL.
  * Use the factory method GetProfileFor to create instances.
  */
 struct ProgramProfileOGL
 {
   /**
    * Factory method; creates an instance of this class for the given
    * ShaderProgramType
    */
-  static ProgramProfileOGL GetProfileFor(gl::ShaderProgramType aType,
+  static ProgramProfileOGL GetProfileFor(ShaderProgramType aType,
                                          MaskType aMask);
 
   /**
    * returns true if such a shader program exists
    */
-  static bool ProgramExists(gl::ShaderProgramType aType, MaskType aMask)
+  static bool ProgramExists(ShaderProgramType aType, MaskType aMask)
   {
     if (aType < 0 ||
-        aType >= gl::NumProgramTypes)
+        aType >= NumProgramTypes)
       return false;
 
     if (aMask < MaskNone ||
         aMask >= NumMaskTypes)
       return false;
 
     if (aMask == Mask2d &&
-        (aType == gl::Copy2DProgramType ||
-         aType == gl::Copy2DRectProgramType))
+        (aType == Copy2DProgramType ||
+         aType == Copy2DRectProgramType))
       return false;
 
     return aMask != Mask3d ||
-           aType == gl::RGBARectLayerProgramType ||
-           aType == gl::RGBALayerProgramType;
+           aType == RGBARectLayerProgramType ||
+           aType == RGBALayerProgramType;
   }
 
 
   /**
    * These two methods lookup the location of a uniform and attribute,
    * respectively. Returns -1 if the named uniform/attribute does not
    * have a location for the shaders represented by this profile.
    */
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -94,36 +94,16 @@ WrapMode(gl::GLContext *aGl, bool aAllow
   if (aAllowRepeat &&
       (aGl->IsExtensionSupported(GLContext::ARB_texture_non_power_of_two) ||
        aGl->IsExtensionSupported(GLContext::OES_texture_npot))) {
     return LOCAL_GL_REPEAT;
   }
   return LOCAL_GL_CLAMP_TO_EDGE;
 }
 
-gfx::SurfaceFormat
-FormatFromShaderType(ShaderProgramType aShaderType)
-{
-  switch (aShaderType) {
-    case RGBALayerProgramType:
-    case RGBALayerExternalProgramType:
-    case RGBARectLayerProgramType:
-    case RGBAExternalLayerProgramType:
-      return FORMAT_R8G8B8A8;
-    case RGBXLayerProgramType:
-      return FORMAT_R8G8B8X8;
-    case BGRALayerProgramType:
-      return FORMAT_B8G8R8A8;
-    case BGRXLayerProgramType:
-      return FORMAT_B8G8R8X8;
-    default:
-      MOZ_CRASH("Unsupported texture shader type");
-  }
-}
-
 TextureImageTextureHostOGL::~TextureImageTextureHostOGL()
 {
   MOZ_COUNT_DTOR(TextureImageTextureHostOGL);
   if (mTexture && mTexture->InUpdate()) {
     mTexture->EndUpdate();
   }
 }
 
@@ -216,17 +196,17 @@ TextureImageTextureHostOGL::UpdateImpl(c
   } else {
     updateRegion = *aRegion;
   }
   nsIntPoint offset;
   if (aOffset) {
     offset = *aOffset;
   }
   mTexture->DirectUpdate(surf.Get(), updateRegion, offset);
-  mFormat = FormatFromShaderType(mTexture->GetShaderProgramType());
+  mFormat = mTexture->GetTextureFormat();
 
   if (mTexture->InUpdate()) {
     mTexture->EndUpdate();
   }
 }
 
 bool
 TextureImageTextureHostOGL::Lock()
@@ -234,17 +214,17 @@ TextureImageTextureHostOGL::Lock()
   if (!mTexture) {
     NS_WARNING("TextureImageTextureHost to be composited without texture");
     return false;
   }
 
   NS_ASSERTION(mTexture->GetContentType() != gfxASurface::CONTENT_ALPHA,
                 "Image layer has alpha image");
 
-  mFormat = FormatFromShaderType(mTexture->GetShaderProgramType());
+  mFormat = mTexture->GetTextureFormat();
 
   return true;
 }
 
 void
 SharedTextureHostOGL::SetCompositor(Compositor* aCompositor)
 {
   CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
@@ -298,18 +278,17 @@ SharedTextureHostOGL::SwapTexturesImpl(c
   }
 
   mShareType = texture.shareType();
   mSharedHandle = newHandle;
 
   GLContext::SharedHandleDetails handleDetails;
   if (mSharedHandle && mGL->GetSharedHandleDetails(mShareType, mSharedHandle, handleDetails)) {
     mTextureTarget = handleDetails.mTarget;
-    mShaderProgram = handleDetails.mProgramType;
-    mFormat = FormatFromShaderType(mShaderProgram);
+    mFormat = handleDetails.mTextureFormat;
   }
 }
 
 bool
 SharedTextureHostOGL::Lock()
 {
   MakeTextureIfNeeded(mGL, mTextureTarget, mTextureHandle);
 
@@ -405,31 +384,31 @@ SurfaceStreamHostOGL::Lock()
 
   gfxImageSurface* toUpload = nullptr;
   switch (sharedSurf->Type()) {
     case SharedSurfaceType::GLTextureShare: {
       SharedSurface_GLTexture* glTexSurf = SharedSurface_GLTexture::Cast(sharedSurf);
       glTexSurf->SetConsumerGL(mGL);
       mTextureHandle = glTexSurf->Texture();
       MOZ_ASSERT(mTextureHandle);
-      mShaderProgram = sharedSurf->HasAlpha() ? RGBALayerProgramType
-                                              : RGBXLayerProgramType;
+      mFormat = sharedSurf->HasAlpha() ? FORMAT_R8G8B8A8
+                                       : FORMAT_R8G8B8X8;
       break;
     }
     case SharedSurfaceType::EGLImageShare: {
       SharedSurface_EGLImage* eglImageSurf =
           SharedSurface_EGLImage::Cast(sharedSurf);
 
       mTextureHandle = eglImageSurf->AcquireConsumerTexture(mGL);
       if (!mTextureHandle) {
         toUpload = eglImageSurf->GetPixels();
         MOZ_ASSERT(toUpload);
       } else {
-        mShaderProgram = sharedSurf->HasAlpha() ? RGBALayerProgramType
-                                                : RGBXLayerProgramType;
+        mFormat = sharedSurf->HasAlpha() ? FORMAT_R8G8B8A8
+                                         : FORMAT_R8G8B8X8;
       }
       break;
     }
     case SharedSurfaceType::Basic: {
       toUpload = SharedSurface_Basic::Cast(sharedSurf)->GetData();
       MOZ_ASSERT(toUpload);
       break;
     }
@@ -437,25 +416,23 @@ SurfaceStreamHostOGL::Lock()
       MOZ_CRASH("Invalid SharedSurface type.");
   }
 
   if (toUpload) {
     // mBounds seems to end up as (0,0,0,0) a lot, so don't use it?
     nsIntSize size(toUpload->GetSize());
     nsIntRect rect(nsIntPoint(0,0), size);
     nsIntRegion bounds(rect);
-    mShaderProgram = mGL->UploadSurfaceToTexture(toUpload,
-                                                 bounds,
-                                                 mUploadTexture,
-                                                 true);
+    mFormat = mGL->UploadSurfaceToTexture(toUpload,
+                                          bounds,
+                                          mUploadTexture,
+                                          true);
     mTextureHandle = mUploadTexture;
   }
 
-  mFormat = FormatFromShaderType(mShaderProgram);
-
   MOZ_ASSERT(mTextureHandle);
   mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle);
   mGL->fTexParameteri(LOCAL_GL_TEXTURE_2D,
                       LOCAL_GL_TEXTURE_WRAP_S,
                       LOCAL_GL_CLAMP_TO_EDGE);
   mGL->fTexParameteri(LOCAL_GL_TEXTURE_2D,
                       LOCAL_GL_TEXTURE_WRAP_T,
                       LOCAL_GL_CLAMP_TO_EDGE);
@@ -886,57 +863,57 @@ GrallocTextureHostOGL::GetRenderState()
 }
 #endif // MOZ_WIDGET_GONK
 
 already_AddRefed<gfxImageSurface>
 TextureImageTextureHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(mTexture->GetTextureID(),
                      false,
-                     mTexture->GetShaderProgramType())
+                     mTexture->GetTextureFormat())
     : nullptr;
   return surf.forget();
 }
 
 already_AddRefed<gfxImageSurface>
 YCbCrTextureHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(mYTexture->mTexImage->GetTextureID(),
                      false,
-                     mYTexture->mTexImage->GetShaderProgramType())
+                     mYTexture->mTexImage->GetTextureFormat())
     : nullptr;
   return surf.forget();
 }
 
 already_AddRefed<gfxImageSurface>
 SharedTextureHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(GetTextureHandle(),
                      false,
-                     GetShaderProgram())
+                     GetTextureFormat())
     : nullptr;
   return surf.forget();
 }
 
 already_AddRefed<gfxImageSurface>
 SurfaceStreamHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(mTextureHandle,
                      false,
-                     GetShaderProgram())
+                     GetTextureFormat())
     : nullptr;
   return surf.forget();
 }
 
 already_AddRefed<gfxImageSurface>
 TiledTextureHostOGL::GetAsSurface() {
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     mGL->GetTexImage(mTextureHandle,
                      false,
-                     GetShaderProgram())
+                     GetTextureFormat())
     : nullptr;
   return surf.forget();
 }
 
 #ifdef MOZ_WIDGET_GONK
 already_AddRefed<gfxImageSurface>
 GrallocTextureHostOGL::GetAsSurface() {
   gl()->MakeCurrent();
@@ -947,16 +924,16 @@ GrallocTextureHostOGL::GetAsSurface() {
   if (!mEGLImage) {
     mEGLImage = gl()->CreateEGLImageForNativeBuffer(mGraphicBuffer->getNativeBuffer());
   }
   gl()->fEGLImageTargetTexture2D(mTextureTarget, mEGLImage);
 
   nsRefPtr<gfxImageSurface> surf = IsValid() ?
     gl()->GetTexImage(tex,
                       false,
-                      GetShaderProgram())
+                      GetTextureFormat())
     : nullptr;
   return surf.forget();
 }
 #endif
 
 } // namespace
 } // namespace
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -1,12 +1,12 @@
 /* -*- 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/. */
+ * 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 MOZILLA_GFX_TEXTUREOGL_H
 #define MOZILLA_GFX_TEXTUREOGL_H
 
 #include "ImageLayerOGL.h"
 #include "GLContextTypes.h"
 #include "gfx2DGlue.h"
 #include "mozilla/layers/Effects.h"
@@ -44,39 +44,39 @@ class CompositorOGL;
  */
 class TextureSourceOGL
 {
 public:
   virtual bool IsValid() const = 0;
   virtual void BindTexture(GLenum aTextureUnit) = 0;
   virtual void ReleaseTexture() = 0;
   virtual gfx::IntSize GetSize() const = 0;
-  virtual gl::ShaderProgramType GetShaderProgram() const {
-    MOZ_CRASH("unhandled shader type");
+  virtual gfx::SurfaceFormat GetTextureFormat() const {
+    MOZ_CRASH("unhandled texture format");
   }
   // TODO: Noone's implementing this anymore, should see if we need this.
   virtual GLenum GetTextureTarget() const { return LOCAL_GL_TEXTURE_2D; }
   virtual GLenum GetWrapMode() const = 0;// { return LOCAL_GL_CLAMP_TO_EDGE; } // default
   virtual gfx3DMatrix GetTextureTransform() { return gfx3DMatrix(); }
 
   virtual TextureImageTextureHostOGL* AsTextureImageTextureHost() { return nullptr; }
 };
 
-inline gl::ShaderProgramType
+inline ShaderProgramType
 GetProgramTypeForTexture(const TextureHost *aTextureHost)
 {
   switch (aTextureHost->GetFormat()) {
   case gfx::FORMAT_B8G8R8A8:
-    return gl::BGRALayerProgramType;;
+    return BGRALayerProgramType;;
   case gfx::FORMAT_B8G8R8X8:
-    return gl::BGRXLayerProgramType;;
+    return BGRXLayerProgramType;;
   case gfx::FORMAT_R8G8B8X8:
-    return gl::RGBXLayerProgramType;;
+    return RGBXLayerProgramType;;
   case gfx::FORMAT_R8G8B8A8:
-    return gl::RGBALayerProgramType;;
+    return RGBALayerProgramType;;
   default:
     MOZ_CRASH("unhandled program type");
   }
 }
 
 /**
  * TextureHost implementation using a TextureImage as the underlying texture.
  */
@@ -143,19 +143,19 @@ public:
 
   void ReleaseTexture() MOZ_OVERRIDE
   {
     mTexture->ReleaseTexture();
   }
 
   gfx::IntSize GetSize() const MOZ_OVERRIDE;
 
-  gl::ShaderProgramType GetShaderProgram() const MOZ_OVERRIDE
+  gfx::SurfaceFormat GetTextureFormat() const MOZ_OVERRIDE
   {
-    return GetProgramTypeForTexture(this);
+    return GetFormat();
   }
 
   GLenum GetWrapMode() const MOZ_OVERRIDE
   {
     return mTexture->GetWrapMode();
   }
 
   gl::TextureImage* GetTextureImage()
@@ -363,19 +363,24 @@ public:
   virtual void SwapTexturesImpl(const SurfaceDescriptor& aImage,
                                 nsIntRegion* aRegion = nullptr) MOZ_OVERRIDE;
   virtual bool Lock() MOZ_OVERRIDE;
   virtual void Unlock() MOZ_OVERRIDE;
 
   virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return mWrapMode; }
   virtual void SetWrapMode(GLenum aMode) { mWrapMode = aMode; }
 
-  gl::ShaderProgramType GetShaderProgram() const MOZ_OVERRIDE
+  gfx::SurfaceFormat GetTextureFormat() const MOZ_OVERRIDE
   {
-    return mShaderProgram;
+    return mFormat;
+  }
+
+  virtual GLenum GetTextureTarget() const MOZ_OVERRIDE
+  {
+    return mTextureTarget;
   }
 
   gfx::IntSize GetSize() const MOZ_OVERRIDE {
     return mSize;
   }
 
   void BindTexture(GLenum activetex) MOZ_OVERRIDE
   {
@@ -404,17 +409,16 @@ protected:
   void DeleteTextures();
 
   gfx::IntSize mSize;
   nsRefPtr<gl::GLContext> mGL;
   GLuint mTextureHandle;
   GLenum mWrapMode;
   GLenum mTextureTarget;
   gl::SharedTextureHandle mSharedHandle;
-  gl::ShaderProgramType mShaderProgram;
   gl::GLContext::SharedTextureShareType mShareType;
 };
 
 class SurfaceStreamHostOGL : public TextureHost
                            , public TextureSourceOGL
 {
 public:
   typedef gfxASurface::gfxContentType ContentType;
@@ -446,19 +450,19 @@ public:
 
   virtual GLenum GetWrapMode() const MOZ_OVERRIDE {
     return mWrapMode;
   }
   virtual void SetWrapMode(GLenum aMode) {
     mWrapMode = aMode;
   }
 
-  gl::ShaderProgramType GetShaderProgram() const MOZ_OVERRIDE
+  gfx::SurfaceFormat GetTextureFormat() const MOZ_OVERRIDE
   {
-    return mShaderProgram;
+    return mFormat;
   }
 
   gfx::IntSize GetSize() const MOZ_OVERRIDE {
     return mSize;
   }
 
   virtual GLenum GetTextureTarget() const MOZ_OVERRIDE
   {
@@ -495,17 +499,16 @@ public:
 protected:
   void DeleteTextures();
 
   gfx::IntSize mSize;
   nsRefPtr<GLContext> mGL;
   GLuint mTextureHandle;
   GLuint mUploadTexture;
   GLenum mWrapMode;
-  gl::ShaderProgramType mShaderProgram;
 };
 
 class TiledTextureHostOGL : public TextureHost
                           , public TextureSourceOGL
 {
 public:
   TiledTextureHostOGL()
     : mTextureHandle(0)
@@ -529,19 +532,19 @@ public:
     mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle);
   }
   virtual void ReleaseTexture() MOZ_OVERRIDE {}
   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE
   {
     return mSize;
   }
 
-  gl::ShaderProgramType GetShaderProgram() const MOZ_OVERRIDE
+  gfx::SurfaceFormat GetTextureFormat() const MOZ_OVERRIDE
   {
-    return GetProgramTypeForTexture(this);
+    return GetFormat();
   }
 
   virtual void SwapTexturesImpl(const SurfaceDescriptor& aImage,
                                 nsIntRegion* aRegion = nullptr)
   { MOZ_ASSERT(false, "Tiles should not use this path"); }
 
   virtual already_AddRefed<gfxImageSurface> GetAsSurface() MOZ_OVERRIDE;
 
@@ -594,25 +597,23 @@ public:
   virtual bool Lock() MOZ_OVERRIDE;
   virtual void Unlock() MOZ_OVERRIDE;
 
   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE
   {
     return mGraphicBuffer.get() ? gfx::IntSize(mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight()) : gfx::IntSize(0, 0);
   }
 
-  gl::ShaderProgramType GetShaderProgram() const MOZ_OVERRIDE
+  gfx::SurfaceFormat GetTextureFormat() const MOZ_OVERRIDE
   {
     if (mTextureTarget == LOCAL_GL_TEXTURE_EXTERNAL) {
-      return gl::RGBAExternalLayerProgramType;
+      return gfx::FORMAT_R8G8B8A8;
     }
     MOZ_ASSERT(mTextureTarget == LOCAL_GL_TEXTURE_2D);
-    return mFormat == gfx::FORMAT_B8G8R8A8 || mFormat == gfx::FORMAT_B8G8R8X8
-           ? gl::BGRALayerProgramType
-           : gl::RGBALayerProgramType;
+    return mFormat;
   }
 
   GLenum GetWrapMode() const MOZ_OVERRIDE
   {
     return LOCAL_GL_CLAMP_TO_EDGE;
   }
 
   bool IsValid() const MOZ_OVERRIDE;
--- a/gfx/layers/opengl/ThebesLayerOGL.cpp
+++ b/gfx/layers/opengl/ThebesLayerOGL.cpp
@@ -129,49 +129,49 @@ ThebesLayerBufferOGL::RenderTo(const nsI
   if (!mTexImage || !Initialised())
     return;
 
   EndUpdate();
 
 #ifdef MOZ_DUMP_PAINTING
   if (gfxUtils::sDumpPainting) {
     nsRefPtr<gfxImageSurface> surf = 
-      gl()->GetTexImage(mTexImage->GetTextureID(), false, mTexImage->GetShaderProgramType());
+      gl()->GetTexImage(mTexImage->GetTextureID(), false, mTexImage->GetTextureFormat());
     
     WriteSnapshotToDumpFile(mLayer, surf);
   }
 #endif
 
   int32_t passes = mTexImageOnWhite ? 2 : 1;
   for (int32_t pass = 1; pass <= passes; ++pass) {
     ShaderProgramOGL *program;
 
     if (passes == 2) {
       ShaderProgramOGL* alphaProgram;
       if (pass == 1) {
-        alphaProgram = aManager->GetProgram(gl::ComponentAlphaPass1ProgramType,
+        alphaProgram = aManager->GetProgram(ComponentAlphaPass1ProgramType,
                                             mLayer->GetMaskLayer());
         gl()->fBlendFuncSeparate(LOCAL_GL_ZERO, LOCAL_GL_ONE_MINUS_SRC_COLOR,
                                  LOCAL_GL_ONE, LOCAL_GL_ONE);
       } else {
-        alphaProgram = aManager->GetProgram(gl::ComponentAlphaPass2ProgramType,
+        alphaProgram = aManager->GetProgram(ComponentAlphaPass2ProgramType,
                                             mLayer->GetMaskLayer());
         gl()->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE,
                                  LOCAL_GL_ONE, LOCAL_GL_ONE);
       }
 
       alphaProgram->Activate();
       alphaProgram->SetBlackTextureUnit(0);
       alphaProgram->SetWhiteTextureUnit(1);
       program = alphaProgram;
     } else {
       // Note BGR: Cairo's image surfaces are always in what
       // OpenGL and our shaders consider BGR format.
       ShaderProgramOGL* basicProgram =
-        aManager->GetProgram(mTexImage->GetShaderProgramType(),
+        aManager->GetProgram(ShaderProgramFromSurfaceFormat(mTexImage->GetTextureFormat()),
                              mLayer->GetMaskLayer());
 
       basicProgram->Activate();
       basicProgram->SetTextureUnit(0);
       program = basicProgram;
     }
 
     program->SetLayerOpacity(mLayer->GetEffectiveOpacity());
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2010,17 +2010,17 @@ nsChildView::MaybeDrawResizeIndicator(GL
   NS_ABORT_IF_FALSE(mResizerImage, "Must have a texture allocated by now!");
 
   float bottomX = aRect.XMost();
   float bottomY = aRect.YMost();
 
   TextureImage::ScopedBindTexture texBind(mResizerImage, LOCAL_GL_TEXTURE0);
 
   ShaderProgramOGL *program =
-    aManager->GetProgram(mResizerImage->GetShaderProgramType());
+    aManager->GetProgram(mResizerImage->GetTextureFormat());
   program->Activate();
   program->SetLayerQuadRect(nsIntRect(bottomX - resizeIndicatorWidth,
                                       bottomY - resizeIndicatorHeight,
                                       resizeIndicatorWidth,
                                       resizeIndicatorHeight));
   program->SetLayerTransform(gfx3DMatrix());
   program->SetLayerOpacity(1.0);
   program->SetRenderOffset(nsIntPoint(0,0));
@@ -2212,17 +2212,17 @@ nsChildView::MaybeDrawTitlebar(GLManager
 
   if (!mTitlebarImage) {
     return;
   }
 
   TextureImage::ScopedBindTexture texBind(mTitlebarImage, LOCAL_GL_TEXTURE0);
 
   ShaderProgramOGL *program =
-    aManager->GetProgram(mTitlebarImage->GetShaderProgramType());
+    aManager->GetProgram(mTitlebarImage->GetTextureFormat());
   program->Activate();
   program->SetLayerQuadRect(nsIntRect(nsIntPoint(0, 0),
                                       mTitlebarImage->GetSize()));
   program->SetLayerTransform(gfx3DMatrix());
   program->SetLayerOpacity(1.0);
   program->SetRenderOffset(nsIntPoint(0,0));
   program->SetTextureUnit(0);
 
@@ -2280,17 +2280,17 @@ nsChildView::MaybeDrawRoundedCorners(GLM
 
     mCornerMaskImage->EndUpdate();
   }
   
   NS_ABORT_IF_FALSE(mCornerMaskImage, "Must have a texture allocated by now!");
   
   TextureImage::ScopedBindTexture texBind(mCornerMaskImage, LOCAL_GL_TEXTURE0);
   
-  ShaderProgramOGL *program = aManager->GetProgram(mCornerMaskImage->GetShaderProgramType());
+  ShaderProgramOGL *program = aManager->GetProgram(mCornerMaskImage->GetTextureFormat());
   program->Activate();
   program->SetLayerQuadRect(nsIntRect(nsIntPoint(0, 0),
                                       mCornerMaskImage->GetSize()));
   program->SetLayerOpacity(1.0);
   program->SetRenderOffset(nsIntPoint(0,0));
   program->SetTextureUnit(0);
 
   // Use operator destination in: multiply all 4 channels with source alpha.