From a8c0a30f5455fc2fc12bc5d2fba65e85853dc113 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Thu, 23 Jan 2014 13:34:56 +0100 Subject: [PATCH] Backed out changeset a5c71a784e33 (bug 950647) for Linux Build Bustage on a CLOSED TREE --- widget/gtk/nsImageToPixbuf.cpp | 96 +++++++++++++--------------------- widget/gtk/nsImageToPixbuf.h | 14 +---- 2 files changed, 38 insertions(+), 72 deletions(-) diff --git a/widget/gtk/nsImageToPixbuf.cpp b/widget/gtk/nsImageToPixbuf.cpp index dc2a218e9ee..0acb7f787dc 100644 --- a/widget/gtk/nsImageToPixbuf.cpp +++ b/widget/gtk/nsImageToPixbuf.cpp @@ -8,8 +8,6 @@ #include "gfxASurface.h" #include "gfxImageSurface.h" #include "gfxContext.h" -#include "gfxPlatform.h" -#include "mozilla/gfx/2D.h" #include "imgIContainer.h" @@ -17,9 +15,6 @@ #include "nsImageToPixbuf.h" -using mozilla::gfx::DataSourceSurface; -using mozilla::gfx::SurfaceFormat; - NS_IMPL_ISUPPORTS1(nsImageToPixbuf, nsIImageToPixbuf) inline unsigned char @@ -41,7 +36,7 @@ nsImageToPixbuf::ConvertImageToPixbuf(imgIContainer* aImage) GdkPixbuf* nsImageToPixbuf::ImageToPixbuf(imgIContainer* aImage) { - nsRefPtr thebesSurface = + nsRefPtr surface = aImage->GetFrame(imgIContainer::FRAME_CURRENT, imgIContainer::FLAG_SYNC_DECODE); @@ -49,81 +44,66 @@ nsImageToPixbuf::ImageToPixbuf(imgIContainer* aImage) // in an imgINotificationObserver event, meaning that we're not allowed request // a sync decode. Presumably the originating event is something sensible like // OnStopFrame(), so we can just retry the call without a sync decode. - if (!thebesSurface) - thebesSurface = aImage->GetFrame(imgIContainer::FRAME_CURRENT, - imgIContainer::FLAG_NONE); + if (!surface) + surface = aImage->GetFrame(imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_NONE); - NS_ENSURE_TRUE(thebesSurface, nullptr); - - RefPtr surface = - gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr, - thebesSurface); NS_ENSURE_TRUE(surface, nullptr); - return SourceSurfaceToPixbuf(surface, - surface->GetSize().width, - surface->GetSize().height); + nsRefPtr frame(surface->GetAsReadableARGB32ImageSurface()); + NS_ENSURE_TRUE(frame, nullptr); + + return ImgSurfaceToPixbuf(frame, frame->Width(), frame->Height()); } GdkPixbuf* -nsImageToPixbuf::SourceSurfaceToPixbuf(SourceSurface* aSurface, - int32_t aWidth, - int32_t aHeight) +nsImageToPixbuf::ImgSurfaceToPixbuf(gfxImageSurface* aImgSurface, int32_t aWidth, int32_t aHeight) { - MOZ_ASSERT(aWidth <= aSurface->GetSize().width && - aHeight <= aSurface->GetSize().height, - "Requested rect is bigger than the supplied surface"); - GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, aWidth, aHeight); if (!pixbuf) return nullptr; - uint32_t destStride = gdk_pixbuf_get_rowstride (pixbuf); - guchar* destPixels = gdk_pixbuf_get_pixels (pixbuf); + uint32_t rowstride = gdk_pixbuf_get_rowstride (pixbuf); + guchar* pixels = gdk_pixbuf_get_pixels (pixbuf); - RefPtr dataSurface = aSurface->GetDataSurface(); - DataSourceSurface::MappedSurface map; - dataSurface->Map(DataSourceSurface::MapType::READ, &map); - uint8_t* srcData = map.mData; - int32_t srcStride = map.mStride; + long cairoStride = aImgSurface->Stride(); + unsigned char* cairoData = aImgSurface->Data(); - SurfaceFormat format = dataSurface->GetFormat(); + gfxImageFormat format = aImgSurface->Format(); for (int32_t row = 0; row < aHeight; ++row) { for (int32_t col = 0; col < aWidth; ++col) { - guchar* destPixel = destPixels + row * destStride + 4 * col; + guchar* pixel = pixels + row * rowstride + 4 * col; - uint32_t* srcPixel = - reinterpret_cast((srcData + row * srcStride + 4 * col)); + uint32_t* cairoPixel = reinterpret_cast + ((cairoData + row * cairoStride + 4 * col)); - if (format == SurfaceFormat::B8G8R8A8) { - const uint8_t a = (*srcPixel >> 24) & 0xFF; - const uint8_t r = unpremultiply((*srcPixel >> 16) & 0xFF, a); - const uint8_t g = unpremultiply((*srcPixel >> 8) & 0xFF, a); - const uint8_t b = unpremultiply((*srcPixel >> 0) & 0xFF, a); + if (format == gfxImageFormatARGB32) { + const uint8_t a = (*cairoPixel >> 24) & 0xFF; + const uint8_t r = unpremultiply((*cairoPixel >> 16) & 0xFF, a); + const uint8_t g = unpremultiply((*cairoPixel >> 8) & 0xFF, a); + const uint8_t b = unpremultiply((*cairoPixel >> 0) & 0xFF, a); - *destPixel++ = r; - *destPixel++ = g; - *destPixel++ = b; - *destPixel++ = a; + *pixel++ = r; + *pixel++ = g; + *pixel++ = b; + *pixel++ = a; } else { - MOZ_ASSERT(format == SurfaceFormat::B8G8R8X8); + NS_ASSERTION(format == gfxImageFormatRGB24, + "unexpected format"); + const uint8_t r = (*cairoPixel >> 16) & 0xFF; + const uint8_t g = (*cairoPixel >> 8) & 0xFF; + const uint8_t b = (*cairoPixel >> 0) & 0xFF; - const uint8_t r = (*srcPixel >> 16) & 0xFF; - const uint8_t g = (*srcPixel >> 8) & 0xFF; - const uint8_t b = (*srcPixel >> 0) & 0xFF; - - *destPixel++ = r; - *destPixel++ = g; - *destPixel++ = b; - *destPixel++ = 0xFF; // A + *pixel++ = r; + *pixel++ = g; + *pixel++ = b; + *pixel++ = 0xFF; // A } } } - dataSurface->Unmap(); - return pixbuf; } @@ -155,9 +135,5 @@ nsImageToPixbuf::SurfaceToPixbuf(gfxASurface* aSurface, int32_t aWidth, int32_t context->Paint(); } - RefPtr surface = - gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(nullptr, - imgSurface); - - return SourceSurfaceToPixbuf(surface, aWidth, aHeight); + return ImgSurfaceToPixbuf(imgSurface, aWidth, aHeight); } diff --git a/widget/gtk/nsImageToPixbuf.h b/widget/gtk/nsImageToPixbuf.h index 2146dd67093..ff374fed5f8 100644 --- a/widget/gtk/nsImageToPixbuf.h +++ b/widget/gtk/nsImageToPixbuf.h @@ -13,15 +13,7 @@ class gfxASurface; class gfxPattern; class gfxImageSurface; -namespace mozilla { -namespace gfx { -class SourceSurface; -} -} - class nsImageToPixbuf MOZ_FINAL : public nsIImageToPixbuf { - typedef mozilla::gfx::SourceSurface SourceSurface; - public: NS_DECL_ISUPPORTS NS_IMETHOD_(GdkPixbuf*) ConvertImageToPixbuf(imgIContainer* aImage); @@ -35,11 +27,9 @@ class nsImageToPixbuf MOZ_FINAL : public nsIImageToPixbuf { static GdkPixbuf* ImageToPixbuf(imgIContainer * aImage); static GdkPixbuf* SurfaceToPixbuf(gfxASurface* aSurface, int32_t aWidth, int32_t aHeight); - static GdkPixbuf* SourceSurfaceToPixbuf(SourceSurface* aSurface, - int32_t aWidth, - int32_t aHeight); - private: + static GdkPixbuf* ImgSurfaceToPixbuf(gfxImageSurface* aImgSurface, + int32_t aWidth, int32_t aHeight); ~nsImageToPixbuf() {} };