Bug 1006198 - Remove a bunch of dead Thebes code. r=jgilbert
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 13 May 2014 14:20:27 +1200
changeset 182942 bbbe64df866efd71af223d4d082a57255315afdb
parent 182941 66efc0d84a37ec286149dd742beabfdaa1dcd220
child 182943 0ff7d00bb9fbdeb79d05663f349f742fa4faad15
push id26774
push userryanvm@gmail.com
push dateTue, 13 May 2014 20:27:07 +0000
treeherdermozilla-central@e5f321740d10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1006198
milestone32.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 1006198 - Remove a bunch of dead Thebes code. r=jgilbert
gfx/gl/GLReadTexImageHelper.cpp
gfx/gl/GLReadTexImageHelper.h
gfx/layers/LayerUtils.cpp
gfx/layers/LayerUtils.h
gfx/layers/moz.build
gfx/thebes/gfxUtils.cpp
gfx/thebes/gfxUtils.h
--- a/gfx/gl/GLReadTexImageHelper.cpp
+++ b/gfx/gl/GLReadTexImageHelper.cpp
@@ -323,198 +323,16 @@ GuessAlignment(int width, int pixelSize,
             NS_WARNING("Bad alignment for GLES. Will use temp surf for readback.");
             return 0;
         }
     }
     return alignment;
 }
 
 void
-ReadPixelsIntoImageSurface(GLContext* gl, gfxImageSurface* dest) {
-    gl->MakeCurrent();
-    MOZ_ASSERT(dest->GetSize() != gfxIntSize(0, 0));
-
-    /* gfxImageFormat::ARGB32:
-     * RGBA+UByte:   be[RGBA], le[ABGR]
-     * RGBA+UInt:    be[ABGR], le[RGBA]
-     * BGRA+UInt:    be[ARGB], le[BGRA]
-     * BGRA+UIntRev: be[BGRA], le[ARGB]
-     *
-     * gfxImageFormat::RGB16_565:
-     * RGB+UShort: le[rrrrrggg,gggbbbbb]
-     */
-    bool hasAlpha = dest->Format() == gfxImageFormat::ARGB32;
-
-    int destPixelSize;
-    GLenum destFormat;
-    GLenum destType;
-
-    switch (dest->Format()) {
-        case gfxImageFormat::RGB24: // XRGB
-        case gfxImageFormat::ARGB32:
-            destPixelSize = 4;
-            // Needs host (little) endian ARGB.
-            destFormat = LOCAL_GL_BGRA;
-            destType = LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV;
-            break;
-
-        case gfxImageFormat::RGB16_565:
-            destPixelSize = 2;
-            destFormat = LOCAL_GL_RGB;
-            destType = LOCAL_GL_UNSIGNED_SHORT_5_6_5_REV;
-            break;
-
-        default:
-            MOZ_CRASH("Bad format.");
-    }
-    MOZ_ASSERT(dest->Width() * destPixelSize <= dest->Stride());
-
-    GLenum readFormat = destFormat;
-    GLenum readType = destType;
-    bool needsTempSurf = !GetActualReadFormats(gl,
-                                               destFormat, destType,
-                                               readFormat, readType);
-
-    nsAutoPtr<gfxImageSurface> tempSurf;
-    gfxImageSurface* readSurf = nullptr;
-
-    // Figure out alignment. We don't need to know why, we just need it
-    // to be valid.
-    int readAlignment = GuessAlignment(dest->Width(),
-                                       destPixelSize,
-                                       dest->Stride());
-    if (!readAlignment) // Couldn't calculate a valid alignment.
-        needsTempSurf = true;
-
-    if (!needsTempSurf) {
-        readSurf = dest;
-    } else {
-        if (gl->DebugMode()) {
-            NS_WARNING("Needing intermediary surface for ReadPixels. This will be slow!");
-        }
-        SurfaceFormat readFormatGFX;
-
-        switch (readFormat) {
-            case LOCAL_GL_RGBA:
-            case LOCAL_GL_BGRA: {
-                readFormatGFX = hasAlpha ? SurfaceFormat::B8G8R8A8
-                                         : SurfaceFormat::B8G8R8X8;
-                break;
-            }
-            case LOCAL_GL_RGB: {
-                MOZ_ASSERT(destPixelSize == 2);
-                MOZ_ASSERT(readType == LOCAL_GL_UNSIGNED_SHORT_5_6_5_REV);
-                readFormatGFX = SurfaceFormat::R5G6B5;
-                break;
-            }
-            default: {
-                MOZ_CRASH("Bad read format.");
-            }
-        }
-
-        switch (readType) {
-            case LOCAL_GL_UNSIGNED_BYTE: {
-                MOZ_ASSERT(readFormat == LOCAL_GL_RGBA);
-                readAlignment = 1;
-                break;
-            }
-            case LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV: {
-                MOZ_ASSERT(readFormat == LOCAL_GL_BGRA);
-                readAlignment = 4;
-                break;
-            }
-            case LOCAL_GL_UNSIGNED_SHORT_5_6_5_REV: {
-                MOZ_ASSERT(readFormat == LOCAL_GL_RGB);
-                readAlignment = 2;
-                break;
-            }
-            default: {
-                MOZ_CRASH("Bad read type.");
-            }
-        }
-
-        tempSurf = new gfxImageSurface(dest->GetSize(),
-                                       SurfaceFormatToImageFormat(readFormatGFX),
-                                       false);
-        readSurf = tempSurf;
-    }
-    MOZ_ASSERT(readAlignment);
-
-    GLint currentPackAlignment = 0;
-    gl->fGetIntegerv(LOCAL_GL_PACK_ALIGNMENT, &currentPackAlignment);
-
-    if (currentPackAlignment != readAlignment)
-        gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, readAlignment);
-
-    GLsizei width = dest->Width();
-    GLsizei height = dest->Height();
-
-    readSurf->Flush();
-    gl->fReadPixels(0, 0,
-                    width, height,
-                    readFormat, readType,
-                    readSurf->Data());
-    readSurf->MarkDirty();
-
-    if (currentPackAlignment != readAlignment)
-        gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, currentPackAlignment);
-
-    if (readSurf != dest) {
-        MOZ_ASSERT(readFormat == LOCAL_GL_RGBA);
-        MOZ_ASSERT(readType == LOCAL_GL_UNSIGNED_BYTE);
-        // So we just copied in RGBA in big endian, or le: 0xAABBGGRR.
-        // We want 0xAARRGGBB, so swap R and B:
-        dest->Flush();
-        RefPtr<DataSourceSurface> readDSurf =
-            Factory::CreateWrappingDataSourceSurface(readSurf->Data(),
-                                                     readSurf->Stride(),
-                                                     ToIntSize(readSurf->GetSize()),
-                                                     ImageFormatToSurfaceFormat(readSurf->Format()));
-        SwapRAndBComponents(readDSurf);
-        dest->MarkDirty();
-
-        gfxContext ctx(dest);
-        ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
-        ctx.SetSource(readSurf);
-        ctx.Paint();
-    }
-
-    // Check if GL is giving back 1.0 alpha for
-    // RGBA reads to RGBA images from no-alpha buffers.
-#ifdef XP_MACOSX
-    if (gl->WorkAroundDriverBugs() &&
-        gl->Vendor() == gl::GLVendor::NVIDIA &&
-        dest->Format() == gfxImageFormat::ARGB32 &&
-        width && height)
-    {
-        GLint alphaBits = 0;
-        gl->fGetIntegerv(LOCAL_GL_ALPHA_BITS, &alphaBits);
-        if (!alphaBits) {
-            const uint32_t alphaMask = gfxPackedPixelNoPreMultiply(0xff,0,0,0);
-
-            MOZ_ASSERT(dest->Width() * destPixelSize == dest->Stride());
-
-            dest->Flush();
-            uint32_t* itr = (uint32_t*)dest->Data();
-            uint32_t testPixel = *itr;
-            if ((testPixel & alphaMask) != alphaMask) {
-                // We need to set the alpha channel to 1.0 manually.
-                uint32_t* itrEnd = itr + width*height;  // Stride is guaranteed to be width*4.
-
-                for (; itr != itrEnd; itr++) {
-                    *itr |= alphaMask;
-                }
-            }
-            dest->MarkDirty();
-        }
-    }
-#endif
-}
-
-void
 ReadPixelsIntoDataSurface(GLContext* gl, DataSourceSurface* dest) {
     gl->MakeCurrent();
     MOZ_ASSERT(dest->GetSize().width != 0);
     MOZ_ASSERT(dest->GetSize().height != 0);
 
     bool hasAlpha = dest->GetFormat() == SurfaceFormat::B8G8R8A8 ||
                     dest->GetFormat() == SurfaceFormat::R8G8B8A8;
 
@@ -730,24 +548,16 @@ ReadBackSurface(GLContext* gl, GLuint aT
 
     if (aYInvert) {
       surf = YInvertImageSurface(surf);
     }
 
     return surf.forget();
 }
 
-void
-ReadScreenIntoImageSurface(GLContext* gl, gfxImageSurface* dest)
-{
-    ScopedBindFramebuffer autoFB(gl, 0);
-    ReadPixelsIntoImageSurface(gl, dest);
-}
-
-
 #define CLEANUP_IF_GLERROR_OCCURRED(x)                                      \
     if (DidGLErrorOccur(x)) {                                               \
         isurf = nullptr;                                                    \
         break;                                                              \
     }
 
 TemporaryRef<DataSourceSurface>
 GLReadTexImageHelper::ReadTexImage(GLuint aTextureId,
--- a/gfx/gl/GLReadTexImageHelper.h
+++ b/gfx/gl/GLReadTexImageHelper.h
@@ -21,18 +21,16 @@ namespace mozilla {
 namespace gfx {
 class DataSourceSurface;
 }
 
 namespace gl {
 
 void ReadPixelsIntoDataSurface(GLContext* aGL,
                                gfx::DataSourceSurface* aSurface);
-void ReadPixelsIntoImageSurface(GLContext* aGL, gfxImageSurface* aSurface);
-void ReadScreenIntoImageSurface(GLContext* aGL, gfxImageSurface* aSurface);
 
 TemporaryRef<gfx::DataSourceSurface>
 ReadBackSurface(GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aFormat);
 
 class GLReadTexImageHelper MOZ_FINAL
 {
     // The GLContext is the sole owner of the GLBlitHelper.
     GLContext* mGL;
deleted file mode 100644
--- a/gfx/layers/LayerUtils.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/* -*- Mode: c++; tab-width: 2; 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 "LayerUtils.h"
-#include "PremultiplyTables.h"
-#include "mozilla/Endian.h"
-
-namespace mozilla {
-namespace layers {
-
-using namespace mozilla::gfx;
-
-static inline const uint8_t PremultiplyValue(uint8_t a, uint8_t v) {
-  return PremultiplyTable[a*256+v];
-}
-
-static inline const uint8_t UnpremultiplyValue(uint8_t a, uint8_t v) {
-  return UnpremultiplyTable[a*256+v];
-}
-
-#ifdef DEBUG
-static bool IsLittleEndian()
-{
-    // Violate strict aliasing, because violating strict aliasing is how
-    // we always pack and unpack between uint32_t and uint8_t[].
-    uint16_t testShort;
-    static const uint8_t testBytes[2] = { 0xAA, 0xBB };
-    memcpy(&testShort, testBytes, sizeof(testBytes));
-    return testShort == 0xBBAA;
-}
-#endif // DEBUG
-
-#ifdef MOZ_LITTLE_ENDIAN
-#define ASSERT_ENDIAN() MOZ_ASSERT(IsLittleEndian(), "Defined as little endian, but actually big!")
-#else
-#define ASSERT_ENDIAN() MOZ_ASSERT(!IsLittleEndian(), "Defined as big endian, but actually little!")
-#endif
-
-void
-PremultiplySurface(DataSourceSurface* srcSurface,
-                   DataSourceSurface* destSurface)
-{
-  if (!destSurface)
-    destSurface = srcSurface;
-
-  IntSize srcSize = srcSurface->GetSize();
-  MOZ_ASSERT(srcSurface->GetFormat() == destSurface->GetFormat() &&
-             srcSize.width  == destSurface->GetSize().width &&
-             srcSize.height  == destSurface->GetSize().height &&
-             srcSurface->Stride() == destSurface->Stride(),
-             "Source and destination surfaces don't have identical characteristics");
-
-  MOZ_ASSERT(srcSurface->Stride() == srcSize.width * 4,
-             "Source surface stride isn't tightly packed");
-
-  // Only premultiply ARGB32
-  if (srcSurface->GetFormat() != SurfaceFormat::B8G8R8A8) {
-    if (destSurface != srcSurface) {
-      memcpy(destSurface->GetData(), srcSurface->GetData(),
-             srcSurface->Stride() * srcSize.height);
-    }
-    return;
-  }
-
-  uint8_t *src = srcSurface->GetData();
-  uint8_t *dst = destSurface->GetData();
-
-  // Assert that our endian define is correct.
-  ASSERT_ENDIAN();
-
-  uint32_t dim = srcSize.width * srcSize.height;
-  for (uint32_t i = 0; i < dim; ++i) {
-#ifdef MOZ_LITTLE_ENDIAN
-    uint8_t b = *src++;
-    uint8_t g = *src++;
-    uint8_t r = *src++;
-    uint8_t a = *src++;
-
-    *dst++ = PremultiplyValue(a, b);
-    *dst++ = PremultiplyValue(a, g);
-    *dst++ = PremultiplyValue(a, r);
-    *dst++ = a;
-#else
-    uint8_t a = *src++;
-    uint8_t r = *src++;
-    uint8_t g = *src++;
-    uint8_t b = *src++;
-
-    *dst++ = a;
-    *dst++ = PremultiplyValue(a, r);
-    *dst++ = PremultiplyValue(a, g);
-    *dst++ = PremultiplyValue(a, b);
-#endif
-  }
-}
-
-
-}
-}
deleted file mode 100644
--- a/gfx/layers/LayerUtils.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef MOZILLA_LAYERS_LAYERUTILS_H_
-#define MOZILLA_LAYERS_LAYERUTILS_H_
-
-#include "mozilla/gfx/2D.h"
-
-namespace mozilla {
-namespace layers {
-
-void
-PremultiplySurface(gfx::DataSourceSurface* srcSurface,
-                   gfx::DataSourceSurface* destSurface = nullptr);
-
-}
-}
-
-#endif /* MOZILLA_LAYERS_LAYERUTILS_H_ */
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -289,17 +289,16 @@ UNIFIED_SOURCES += [
     'ipc/ShadowLayers.cpp',
     'ipc/SharedBufferManagerChild.cpp',
     'ipc/SharedBufferManagerParent.cpp',
     'ipc/SharedPlanarYCbCrImage.cpp',
     'ipc/SharedRGBImage.cpp',
     'LayerScope.cpp',
     'LayersLogging.cpp',
     'LayerSorter.cpp',
-    'LayerUtils.cpp',
     'opengl/CompositingRenderTargetOGL.cpp',
     'opengl/CompositorOGL.cpp',
     'opengl/OGLShaderProgram.cpp',
     'opengl/TextureClientOGL.cpp',
     'opengl/TextureHostOGL.cpp',
     'opengl/TexturePoolOGL.cpp',
     'ReadbackProcessor.cpp',
     'RenderTrace.cpp',
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -31,70 +31,16 @@ static const uint8_t PremultiplyValue(ui
     return gfxUtils::sPremultiplyTable[a*256+v];
 }
 
 static const uint8_t UnpremultiplyValue(uint8_t a, uint8_t v) {
     return gfxUtils::sUnpremultiplyTable[a*256+v];
 }
 
 void
-gfxUtils::PremultiplyImageSurface(gfxImageSurface *aSourceSurface,
-                                  gfxImageSurface *aDestSurface)
-{
-    if (!aDestSurface)
-        aDestSurface = aSourceSurface;
-
-    MOZ_ASSERT(aSourceSurface->Format() == aDestSurface->Format() &&
-               aSourceSurface->Width()  == aDestSurface->Width() &&
-               aSourceSurface->Height() == aDestSurface->Height() &&
-               aSourceSurface->Stride() == aDestSurface->Stride(),
-               "Source and destination surfaces don't have identical characteristics");
-
-    MOZ_ASSERT(aSourceSurface->Stride() == aSourceSurface->Width() * 4,
-               "Source surface stride isn't tightly packed");
-
-    // Only premultiply ARGB32
-    if (aSourceSurface->Format() != gfxImageFormat::ARGB32) {
-        if (aDestSurface != aSourceSurface) {
-            memcpy(aDestSurface->Data(), aSourceSurface->Data(),
-                   aSourceSurface->Stride() * aSourceSurface->Height());
-        }
-        return;
-    }
-
-    uint8_t *src = aSourceSurface->Data();
-    uint8_t *dst = aDestSurface->Data();
-
-    uint32_t dim = aSourceSurface->Width() * aSourceSurface->Height();
-    for (uint32_t i = 0; i < dim; ++i) {
-#ifdef IS_LITTLE_ENDIAN
-        uint8_t b = *src++;
-        uint8_t g = *src++;
-        uint8_t r = *src++;
-        uint8_t a = *src++;
-
-        *dst++ = PremultiplyValue(a, b);
-        *dst++ = PremultiplyValue(a, g);
-        *dst++ = PremultiplyValue(a, r);
-        *dst++ = a;
-#else
-        uint8_t a = *src++;
-        uint8_t r = *src++;
-        uint8_t g = *src++;
-        uint8_t b = *src++;
-
-        *dst++ = a;
-        *dst++ = PremultiplyValue(a, r);
-        *dst++ = PremultiplyValue(a, g);
-        *dst++ = PremultiplyValue(a, b);
-#endif
-    }
-}
-
-void
 gfxUtils::PremultiplyDataSurface(DataSourceSurface *aSurface)
 {
     // Only premultiply ARGB32
     if (aSurface->GetFormat() != SurfaceFormat::B8G8R8A8) {
         return;
     }
 
     DataSourceSurface::MappedSurface map;
@@ -130,69 +76,16 @@ gfxUtils::PremultiplyDataSurface(DataSou
         *dst++ = PremultiplyValue(a, g);
         *dst++ = PremultiplyValue(a, b);
 #endif
     }
 
     aSurface->Unmap();
 }
 
-void
-gfxUtils::UnpremultiplyImageSurface(gfxImageSurface *aSourceSurface,
-                                    gfxImageSurface *aDestSurface)
-{
-    if (!aDestSurface)
-        aDestSurface = aSourceSurface;
-
-    MOZ_ASSERT(aSourceSurface->Format() == aDestSurface->Format() &&
-               aSourceSurface->Width()  == aDestSurface->Width() &&
-               aSourceSurface->Height() == aDestSurface->Height(),
-               "Source and destination surfaces don't have identical characteristics");
-
-    // Only premultiply ARGB32
-    if (aSourceSurface->Format() != gfxImageFormat::ARGB32) {
-        if (aDestSurface != aSourceSurface) {
-            aDestSurface->CopyFrom(aSourceSurface);
-        }
-        return;
-    }
-
-    uint8_t *src = aSourceSurface->Data();
-    uint8_t *dst = aDestSurface->Data();
-
-    for (int32_t i = 0; i < aSourceSurface->Height(); ++i) {
-        uint8_t *srcRow = src + (i * aSourceSurface->Stride());
-        uint8_t *dstRow = dst + (i * aDestSurface->Stride());
-
-        for (int32_t j = 0; j < aSourceSurface->Width(); ++j) {
-#ifdef IS_LITTLE_ENDIAN
-          uint8_t b = *srcRow++;
-          uint8_t g = *srcRow++;
-          uint8_t r = *srcRow++;
-          uint8_t a = *srcRow++;
-
-          *dstRow++ = UnpremultiplyValue(a, b);
-          *dstRow++ = UnpremultiplyValue(a, g);
-          *dstRow++ = UnpremultiplyValue(a, r);
-          *dstRow++ = a;
-#else
-          uint8_t a = *srcRow++;
-          uint8_t r = *srcRow++;
-          uint8_t g = *srcRow++;
-          uint8_t b = *srcRow++;
-
-          *dstRow++ = a;
-          *dstRow++ = UnpremultiplyValue(a, r);
-          *dstRow++ = UnpremultiplyValue(a, g);
-          *dstRow++ = UnpremultiplyValue(a, b);
-#endif
-        }
-    }
-}
-
 TemporaryRef<DataSourceSurface>
 gfxUtils::UnpremultiplyDataSurface(DataSourceSurface* aSurface)
 {
     // Only premultiply ARGB32
     if (aSurface->GetFormat() != SurfaceFormat::B8G8R8A8) {
         return aSurface;
     }
 
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -35,21 +35,17 @@ public:
      * 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
      * aDestSurface is given, the data is copied over.
      */
-    static void PremultiplyImageSurface(gfxImageSurface *aSourceSurface,
-                                        gfxImageSurface *aDestSurface = nullptr);
     static void PremultiplyDataSurface(DataSourceSurface *aSurface);
-    static void UnpremultiplyImageSurface(gfxImageSurface *aSurface,
-                                          gfxImageSurface *aDestSurface = nullptr);
     static mozilla::TemporaryRef<DataSourceSurface> UnpremultiplyDataSurface(DataSourceSurface* aSurface);
 
     static void ConvertBGRAtoRGBA(gfxImageSurface *aSourceSurface,
                                   gfxImageSurface *aDestSurface = nullptr);
     static void ConvertBGRAtoRGBA(uint8_t* aData, uint32_t aLength);
 
     /**
      * Draw something drawable while working around limitations like bad support