Bug 576437 - CreateOffscreenSurface should not silently translate ImageFormat24 into ImageFormat16_565. r=joe a=blocking2.0

This commit is contained in:
Tom Brinkman 2010-09-16 14:34:53 -07:00
parent edaafea0fe
commit e23595f3c1
31 changed files with 66 additions and 51 deletions

View File

@ -1109,7 +1109,7 @@ nsCanvasRenderingContext2D::SetDimensions(PRInt32 width, PRInt32 height)
surface = layerManager->CreateOptimalSurface(gfxIntSize(width, height), format);
} else {
surface = gfxPlatform::GetPlatform()->
CreateOffscreenSurface(gfxIntSize(width, height), format);
CreateOffscreenSurface(gfxIntSize(width, height), gfxASurface::ContentFromFormat(format));
}
}
@ -1121,7 +1121,7 @@ nsCanvasRenderingContext2D::SetDimensions(PRInt32 width, PRInt32 height)
#ifdef MOZ_X11
if (surface->GetType() == gfxASurface::SurfaceTypeXlib) {
mBackSurface =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, format);
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxASurface::ContentFromFormat(format));
NS_ABORT_IF_FALSE(mBackSurface->GetType() ==
gfxASurface::SurfaceTypeXlib, "need xlib surface");
mIsBackSurfaceReadable = PR_TRUE;

View File

@ -278,7 +278,7 @@ protected:
CreateUpdateSurface(const gfxIntSize& aSize, ImageFormat aFmt)
{
mUpdateFormat = aFmt;
return gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, aFmt);
return gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, gfxASurface::ContentFromFormat(aFmt));
}
virtual already_AddRefed<gfxImageSurface>

View File

@ -964,7 +964,7 @@ GLContextEGL::CreateTextureImage(const nsIntSize& aSize,
nsRefPtr<gfxASurface> pixmap =
gfxPlatform::GetPlatform()->
CreateOffscreenSurface(gfxIntSize(aSize.width, aSize.height),
imageFormat);
gfxASurface::ContentFromFormat(imageFormat));
impl = GLContextProviderEGL::CreateForNativePixmapSurface(pixmap);
if (impl) {

View File

@ -343,7 +343,7 @@ protected:
CreateUpdateSurface(const gfxIntSize& aSize, ImageFormat aFmt)
{
mUpdateFormat = aFmt;
return gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, aFmt);
return gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, gfxASurface::ContentFromFormat(aFmt));
}
virtual already_AddRefed<gfxImageSurface>

View File

@ -454,7 +454,7 @@ protected:
mUpdateSize = aSize;
mUpdateFormat = aFmt;
return gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, aFmt);
return gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, gfxASurface::ContentFromFormat(aFmt));
}
virtual already_AddRefed<gfxImageSurface>

View File

@ -424,6 +424,20 @@ gfxASurface::ContentFromFormat(gfxImageFormat format)
}
}
gfxASurface::gfxImageFormat
gfxASurface::FormatFromContent(gfxASurface::gfxContentType type)
{
switch (type) {
case CONTENT_COLOR_ALPHA:
return ImageFormatARGB32;
case CONTENT_ALPHA:
return ImageFormatA8;
case CONTENT_COLOR:
default:
return ImageFormatRGB24;
}
}
PRInt32
gfxASurface::BytePerPixelFromFormat(gfxImageFormat format)
{

View File

@ -212,6 +212,7 @@ public:
virtual PRInt32 GetDefaultContextFlags() const { return 0; }
static gfxContentType ContentFromFormat(gfxImageFormat format);
static gfxImageFormat FormatFromContent(gfxContentType format);
/**
* Record number of bytes for given surface type. Use positive bytes

View File

@ -87,13 +87,13 @@ gfxAndroidPlatform::~gfxAndroidPlatform()
already_AddRefed<gfxASurface>
gfxAndroidPlatform::CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat)
gfxASurface::gfxContentType contentType)
{
nsRefPtr<gfxASurface> newSurface;
if (imageFormat == gfxImageSurface::ImageFormatRGB24)
if (contentType == gfxImageSurface::CONTENT_COLOR)
newSurface = new gfxImageSurface (size, gfxASurface::ImageFormatRGB16_565);
else
newSurface = new gfxImageSurface (size, imageFormat);
newSurface = new gfxImageSurface (size, gfxASurface::FormatFromContent(contentType));
return newSurface.forget();
}

View File

@ -60,7 +60,7 @@ public:
}
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
gfxASurface::gfxContentType contentType);
virtual PRBool IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags);
virtual gfxPlatformFontList* CreatePlatformFontList();

View File

@ -71,16 +71,15 @@ gfxBeOSPlatform::~gfxBeOSPlatform()
already_AddRefed<gfxASurface>
gfxBeOSPlatform::CreateOffscreenSurface (PRUint32 width,
PRUint32 height,
gfxASurface::gfxImageFormat imageFormat)
gfxASurface::gfxContentType contentType)
{
gfxASurface *newSurface = nsnull;
if (imageFormat == gfxASurface::ImageFormatA1 ||
imageFormat == gfxASurface::ImageFormatA8) {
if (contentType == gfxASurface::CONTENT_ALPHA) {
newSurface = new gfxImageSurface(imageFormat, width, height);
} else {
newSurface = new gfxBeOSSurface(width, height,
imageFormat == gfxASurface::ImageFormatARGB32 ? B_RGBA32 : B_RGB32);
contentType == gfxASurface::CONTENT_COLOR_ALPHA ? B_RGBA32 : B_RGB32);
}
NS_ADDREF(newSurface);

View File

@ -56,7 +56,7 @@ public:
already_AddRefed<gfxASurface>
CreateOffscreenSurface(PRUint32 width,
PRUint32 height,
gfxASurface::gfxImageFormat imageFormat);
gfxASurface::gfxContentType contentType);
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,

View File

@ -185,7 +185,7 @@ already_AddRefed<gfxSurfaceDrawable>
gfxCallbackDrawable::MakeSurfaceDrawable(const gfxPattern::GraphicsFilter aFilter)
{
nsRefPtr<gfxASurface> surface =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(mSize, gfxASurface::ImageFormatARGB32);
gfxPlatform::GetPlatform()->CreateOffscreenSurface(mSize, gfxASurface::CONTENT_COLOR_ALPHA);
if (!surface || surface->CairoStatus() != 0)
return nsnull;

View File

@ -84,7 +84,7 @@ gfxOS2Platform::~gfxOS2Platform()
already_AddRefed<gfxASurface>
gfxOS2Platform::CreateOffscreenSurface(const gfxIntSize& aSize,
gfxASurface::gfxImageFormat aImageFormat)
gfxASurface::gfxContentType contentType)
{
#ifdef DEBUG_thebes_2
printf("gfxOS2Platform::CreateOffscreenSurface(%d/%d, %d)\n",
@ -94,13 +94,12 @@ gfxOS2Platform::CreateOffscreenSurface(const gfxIntSize& aSize,
// we only ever seem to get aImageFormat=0 or ImageFormatARGB32 but
// I don't really know if we need to differ between ARGB32 and RGB24 here
if (aImageFormat == gfxASurface::ImageFormatARGB32 ||
aImageFormat == gfxASurface::ImageFormatRGB24)
if (contentType == gfxASurface::CONTENT_COLOR_ALPHA ||
contentType == gfxASurface::CONTENT_COLOR)
{
newSurface = new gfxOS2Surface(aSize, aImageFormat);
} else if (aImageFormat == gfxASurface::ImageFormatA8 ||
aImageFormat == gfxASurface::ImageFormatA1) {
newSurface = new gfxImageSurface(aSize, aImageFormat);
newSurface = new gfxOS2Surface(aSize, gfxASurface::FormatFromContent(contentType));
} else if (contentType == gfxASurface::CONTENT_ALPHA) {
newSurface = new gfxImageSurface(aSize, gfxASurface::FormatFromContent(contentType));
} else {
return nsnull;
}

View File

@ -60,7 +60,7 @@ public:
already_AddRefed<gfxASurface>
CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
gfxASurface::gfxContentType contentType);
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,

View File

@ -253,7 +253,7 @@ gfxPlatform::Init()
gPlatform->mScreenReferenceSurface =
gPlatform->CreateOffscreenSurface(gfxIntSize(1,1),
gfxASurface::ImageFormatARGB32);
gfxASurface::CONTENT_COLOR_ALPHA);
if (!gPlatform->mScreenReferenceSurface) {
NS_ERROR("Could not initialize mScreenReferenceSurface");
Shutdown();
@ -369,7 +369,7 @@ gfxPlatform::OptimizeImage(gfxImageSurface *aSurface,
return nsnull;
}
#endif
nsRefPtr<gfxASurface> optSurface = CreateOffscreenSurface(surfaceSize, format);
nsRefPtr<gfxASurface> optSurface = CreateOffscreenSurface(surfaceSize, gfxASurface::ContentFromFormat(format));
if (!optSurface || optSurface->CairoStatus() != 0)
return nsnull;

View File

@ -147,7 +147,7 @@ public:
* and image format.
*/
virtual already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat) = 0;
gfxASurface::gfxContentType contentType) = 0;
virtual already_AddRefed<gfxASurface> OptimizeImage(gfxImageSurface *aSurface,

View File

@ -161,9 +161,10 @@ gfxPlatformGtk::~gfxPlatformGtk()
already_AddRefed<gfxASurface>
gfxPlatformGtk::CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat)
gfxASurface::gfxContentType contentType)
{
nsRefPtr<gfxASurface> newSurface = nsnull;
gfxASurface::gfxImageFormat imageFormat = gfxASurface::FormatFromContent(contentType);
#ifdef MOZ_X11
// XXX we really need a different interface here, something that passes
// in more context, including the display and/or target surface type that
@ -172,7 +173,7 @@ gfxPlatformGtk::CreateOffscreenSurface(const gfxIntSize& size,
if (gdkScreen) {
// try to optimize it for 16bpp default screen
if (gfxASurface::ImageFormatRGB24 == imageFormat
if (gfxASurface::CONTENT_COLOR == contentType
&& 16 == gdk_visual_get_system()->depth)
imageFormat = gfxASurface::ImageFormatRGB16_565;

View File

@ -64,7 +64,7 @@ public:
}
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
gfxASurface::gfxContentType contentType);
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,

View File

@ -76,11 +76,11 @@ gfxPlatformMac::CreatePlatformFontList()
already_AddRefed<gfxASurface>
gfxPlatformMac::CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat)
gfxASurface::gfxContentType contentType)
{
gfxASurface *newSurface = nsnull;
newSurface = new gfxQuartzSurface(size, imageFormat);
newSurface = new gfxQuartzSurface(size, gfxASurface::FormatFromContent(contentType));
NS_IF_ADDREF(newSurface);
return newSurface;

View File

@ -60,7 +60,7 @@ public:
}
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
gfxASurface::gfxContentType contentType);
already_AddRefed<gfxASurface> OptimizeImage(gfxImageSurface *aSurface,
gfxASurface::gfxImageFormat format);

View File

@ -190,17 +190,18 @@ gfxQtPlatform::~gfxQtPlatform()
already_AddRefed<gfxASurface>
gfxQtPlatform::CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat)
gfxASurface::gfxContentType contentType)
{
nsRefPtr<gfxASurface> newSurface = nsnull;
// try to optimize it for 16bpp screen
if (gfxASurface::ImageFormatRGB24 == imageFormat
gfxASurface::gfxImageFormat imageFormat = gfxASurface::FormatFromContent(contentType);
if (gfxASurface::CONTENT_COLOR == contentType
&& 16 == QX11Info().depth())
imageFormat = gfxASurface::ImageFormatRGB16_565;
if (mRenderMode == RENDER_QPAINTER) {
newSurface = new gfxQPainterSurface(size, gfxASurface::ContentFromFormat(imageFormat));
newSurface = new gfxQPainterSurface(size, imageFormat);
return newSurface.forget();
}

View File

@ -72,7 +72,7 @@ public:
}
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
gfxASurface::gfxContentType contentType);
nsresult GetFontList(nsIAtom *aLangGroup,
const nsACString& aGenericFamily,

View File

@ -245,7 +245,7 @@ CreateSamplingRestrictedDrawable(gfxDrawable* aDrawable,
gfxIntSize size(PRInt32(needed.Width()), PRInt32(needed.Height()));
nsRefPtr<gfxASurface> temp =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, aFormat);
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxASurface::ContentFromFormat(aFormat));
if (!temp || temp->CairoStatus())
return nsnull;

View File

@ -426,27 +426,27 @@ gfxWindowsPlatform::CreatePlatformFontList()
already_AddRefed<gfxASurface>
gfxWindowsPlatform::CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat)
gfxASurface::gfxContentType contentType)
{
gfxASurface *surf = nsnull;
#ifdef CAIRO_HAS_DDRAW_SURFACE
if (mRenderMode == RENDER_DDRAW || mRenderMode == RENDER_DDRAW_GL)
surf = new gfxDDrawSurface(NULL, size, imageFormat);
surf = new gfxDDrawSurface(NULL, size, gfxASurface::FormatFromContent(contentType));
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
if (mRenderMode == RENDER_GDI)
surf = new gfxWindowsSurface(size, imageFormat);
surf = new gfxWindowsSurface(size, gfxASurface::FormatFromContent(contentType));
#endif
#ifdef CAIRO_HAS_D2D_SURFACE
if (mRenderMode == RENDER_DIRECT2D)
surf = new gfxD2DSurface(size, imageFormat);
surf = new gfxD2DSurface(size, gfxASurface::FormatFromContent(contentType));
#endif
if (surf == nsnull)
surf = new gfxImageSurface(size, imageFormat);
surf = new gfxImageSurface(size, gfxASurface::FormatFromContent(contentType));
NS_IF_ADDREF(surf);

View File

@ -118,7 +118,7 @@ public:
virtual gfxPlatformFontList* CreatePlatformFontList();
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat);
gfxASurface::gfxContentType contentType);
enum RenderMode {
/* Use GDI and windows surfaces */

View File

@ -3549,7 +3549,7 @@ nsLayoutUtils::SurfaceFromElement(nsIDOMElement *aElement,
if (wantImageSurface) {
surf = new gfxImageSurface(size, gfxASurface::ImageFormatARGB32);
} else {
surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxASurface::ImageFormatARGB32);
surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxASurface::CONTENT_COLOR_ALPHA);
}
nsRefPtr<gfxContext> ctx = new gfxContext(surf);
@ -3695,7 +3695,7 @@ nsLayoutUtils::SurfaceFromElement(nsIDOMElement *aElement,
gfxsurf = new gfxImageSurface (gfxIntSize(imgWidth, imgHeight), gfxASurface::ImageFormatARGB32);
} else {
gfxsurf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(imgWidth, imgHeight),
gfxASurface::ImageFormatARGB32);
gfxASurface::CONTENT_COLOR_ALPHA);
}
nsRefPtr<gfxContext> ctx = new gfxContext(gfxsurf);

View File

@ -342,7 +342,7 @@ nsSVGFilterInstance::BuildSourceImages()
nsRefPtr<gfxASurface> offscreen =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(
gfxIntSize(mSurfaceRect.width, mSurfaceRect.height),
gfxASurface::ImageFormatARGB32);
gfxASurface::CONTENT_COLOR_ALPHA);
if (!offscreen || offscreen->CairoStatus())
return NS_ERROR_OUT_OF_MEMORY;
offscreen->SetDeviceOffset(gfxPoint(-mSurfaceRect.x, -mSurfaceRect.y));

View File

@ -261,7 +261,7 @@ nsSVGPatternFrame::PaintPattern(gfxASurface** surface,
nsRefPtr<gfxASurface> tmpSurface =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(surfaceSize,
gfxASurface::ImageFormatARGB32);
gfxASurface::CONTENT_COLOR_ALPHA);
if (!tmpSurface || tmpSurface->CairoStatus())
return NS_ERROR_FAILURE;

View File

@ -413,7 +413,7 @@ imgFrame::SurfaceForDrawing(PRBool aDoPadding,
// transparent pixels in the padding or undecoded area
gfxImageSurface::gfxImageFormat format = gfxASurface::ImageFormatARGB32;
nsRefPtr<gfxASurface> surface =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, format);
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxImageSurface::ContentFromFormat(format));
if (!surface || surface->CairoStatus())
return SurfaceWithFormat();

View File

@ -278,7 +278,7 @@ UpdateOffScreenBuffers(int aDepth, QSize aSize)
format = gfxASurface::ImageFormatRGB24;
gBufferSurface = gfxPlatform::GetPlatform()->
CreateOffscreenSurface(gBufferMaxSize, format);
CreateOffscreenSurface(gBufferMaxSize, gfxASurface::ContentFromFormat(format));
return true;
}

View File

@ -611,7 +611,7 @@ nsBaseDragService::DrawDragForImage(nsPresContext* aPresContext,
nsRefPtr<gfxASurface> surface =
gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(destSize.width, destSize.height),
gfxASurface::ImageFormatARGB32);
gfxASurface::CONTENT_COLOR_ALPHA);
if (!surface)
return NS_ERROR_FAILURE;