Bug 1209812 (part 1) - Remove casts between cairo_format_t and gfxImageFormat. r=nical.

cairo_format_t and gfxImageFormat have their equivalent constants in the same
order, so you can just cast between them, which is kind of nasty.

This patch replaces all such casts with explicit conversions via calls to new
conversion functions. These functions will be removed in a subsequent patch.
This commit is contained in:
Nicholas Nethercote 2015-09-28 21:11:52 -07:00
parent 82cff83b93
commit 93c78b58d8
8 changed files with 44 additions and 22 deletions

View File

@ -424,7 +424,8 @@ gfxASurface::CheckSurfaceSize(const IntSize& sz, int32_t limit)
int32_t int32_t
gfxASurface::FormatStrideForWidth(gfxImageFormat format, int32_t width) gfxASurface::FormatStrideForWidth(gfxImageFormat format, int32_t width)
{ {
return cairo_format_stride_for_width((cairo_format_t)(int)format, (int)width); cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
return cairo_format_stride_for_width(cformat, (int)width);
} }
nsresult nsresult

View File

@ -77,8 +77,8 @@ public:
mozilla::gfx::IntSize size(shmInfo->width, shmInfo->height); mozilla::gfx::IntSize size(shmInfo->width, shmInfo->height);
if (!gfxASurface::CheckSurfaceSize(size)) if (!gfxASurface::CheckSurfaceSize(size))
return nullptr; return nullptr;
gfxImageFormat format = (gfxImageFormat)shmInfo->format; gfxImageFormat format = shmInfo->format;
long stride = gfxImageSurface::ComputeStride(size, format); long stride = gfxImageSurface::ComputeStride(size, format);
RefPtr<Sub> s = RefPtr<Sub> s =

View File

@ -32,7 +32,7 @@ gfxImageSurface::InitFromSurface(cairo_surface_t *csurf)
mSize.width = cairo_image_surface_get_width(csurf); mSize.width = cairo_image_surface_get_width(csurf);
mSize.height = cairo_image_surface_get_height(csurf); mSize.height = cairo_image_surface_get_height(csurf);
mData = cairo_image_surface_get_data(csurf); mData = cairo_image_surface_get_data(csurf);
mFormat = (gfxImageFormat) cairo_image_surface_get_format(csurf); mFormat = gfxCairoFormatToImageFormat(cairo_image_surface_get_format(csurf));
mOwnsData = false; mOwnsData = false;
mStride = cairo_image_surface_get_stride(csurf); mStride = cairo_image_surface_get_stride(csurf);
@ -66,9 +66,10 @@ gfxImageSurface::InitWithData(unsigned char *aData, const IntSize& aSize,
if (!CheckSurfaceSize(aSize)) if (!CheckSurfaceSize(aSize))
MakeInvalid(); MakeInvalid();
cairo_format_t cformat = gfxImageFormatToCairoFormat(mFormat);
cairo_surface_t *surface = cairo_surface_t *surface =
cairo_image_surface_create_for_data((unsigned char*)mData, cairo_image_surface_create_for_data((unsigned char*)mData,
(cairo_format_t)(int)mFormat, cformat,
mSize.width, mSize.width,
mSize.height, mSize.height,
mStride); mStride);
@ -135,9 +136,10 @@ gfxImageSurface::AllocateAndInit(long aStride, int32_t aMinimalAllocation,
mOwnsData = true; mOwnsData = true;
cairo_format_t cformat = gfxImageFormatToCairoFormat(mFormat);
cairo_surface_t *surface = cairo_surface_t *surface =
cairo_image_surface_create_for_data((unsigned char*)mData, cairo_image_surface_create_for_data((unsigned char*)mData,
(cairo_format_t)(int)mFormat, cformat,
mSize.width, mSize.width,
mSize.height, mSize.height,
mStride); mStride);
@ -162,7 +164,7 @@ gfxImageSurface::gfxImageSurface(cairo_surface_t *csurf)
mSize.width = cairo_image_surface_get_width(csurf); mSize.width = cairo_image_surface_get_width(csurf);
mSize.height = cairo_image_surface_get_height(csurf); mSize.height = cairo_image_surface_get_height(csurf);
mData = cairo_image_surface_get_data(csurf); mData = cairo_image_surface_get_data(csurf);
mFormat = (gfxImageFormat) cairo_image_surface_get_format(csurf); mFormat = gfxCairoFormatToImageFormat(cairo_image_surface_get_format(csurf));
mOwnsData = false; mOwnsData = false;
mStride = cairo_image_surface_get_stride(csurf); mStride = cairo_image_surface_get_stride(csurf);

View File

@ -21,9 +21,9 @@ gfxQPainterSurface::gfxQPainterSurface(QPainter *painter)
gfxQPainterSurface::gfxQPainterSurface(const mozilla::gfx::IntSize& size, gfxImageFormat format) gfxQPainterSurface::gfxQPainterSurface(const mozilla::gfx::IntSize& size, gfxImageFormat format)
{ {
cairo_surface_t *csurf = cairo_qt_surface_create_with_qimage ((cairo_format_t) format, cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
size.width, cairo_surface_t *csurf =
size.height); cairo_qt_surface_create_with_qimage(cformat, size.width, size.height);
mPainter = cairo_qt_surface_get_qpainter (csurf); mPainter = cairo_qt_surface_get_qpainter (csurf);
Init (csurf); Init (csurf);

View File

@ -26,8 +26,8 @@ gfxQuartzSurface::gfxQuartzSurface(const gfxSize& desiredSize, gfxImageFormat fo
unsigned int width = static_cast<unsigned int>(mSize.width); unsigned int width = static_cast<unsigned int>(mSize.width);
unsigned int height = static_cast<unsigned int>(mSize.height); unsigned int height = static_cast<unsigned int>(mSize.height);
cairo_surface_t *surf = cairo_quartz_surface_create cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
((cairo_format_t) format, width, height); cairo_surface_t *surf = cairo_quartz_surface_create(cformat, width, height);
mCGContext = cairo_quartz_surface_get_cg_context (surf); mCGContext = cairo_quartz_surface_get_cg_context (surf);
@ -109,8 +109,9 @@ gfxQuartzSurface::gfxQuartzSurface(unsigned char *data,
unsigned int width = static_cast<unsigned int>(mSize.width); unsigned int width = static_cast<unsigned int>(mSize.width);
unsigned int height = static_cast<unsigned int>(mSize.height); unsigned int height = static_cast<unsigned int>(mSize.height);
cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
cairo_surface_t *surf = cairo_quartz_surface_create_for_data cairo_surface_t *surf = cairo_quartz_surface_create_for_data
(data, (cairo_format_t) format, width, height, stride); (data, cformat, width, height, stride);
mCGContext = cairo_quartz_surface_get_cg_context (surf); mCGContext = cairo_quartz_surface_get_cg_context (surf);
@ -131,8 +132,9 @@ gfxQuartzSurface::gfxQuartzSurface(unsigned char *data,
if (!CheckSurfaceSize(aSize)) if (!CheckSurfaceSize(aSize))
MakeInvalid(); MakeInvalid();
cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
cairo_surface_t *surf = cairo_quartz_surface_create_for_data cairo_surface_t *surf = cairo_quartz_surface_create_for_data
(data, (cairo_format_t) format, aSize.width, aSize.height, stride); (data, cformat, aSize.width, aSize.height, stride);
mCGContext = cairo_quartz_surface_get_cg_context (surf); mCGContext = cairo_quartz_surface_get_cg_context (surf);

View File

@ -57,6 +57,18 @@ enum class gfxImageFormat {
Unknown Unknown
}; };
// XXX: temporary
// This works because the gfxImageFormat enum is defined so as to match the
// _cairo_format enum.
#define gfxCairoFormatToImageFormat(aFormat) \
((gfxImageFormat)aFormat)
// XXX: temporary
// This works because the gfxImageFormat enum is defined so as to match the
// _cairo_format enum.
#define gfxImageFormatToCairoFormat(aFormat) \
((cairo_format_t)aFormat)
enum class gfxSurfaceType { enum class gfxSurfaceType {
Image, Image,
PDF, PDF,

View File

@ -59,8 +59,9 @@ gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize, gfxI
if (!CheckSurfaceSize(size)) if (!CheckSurfaceSize(size))
MakeInvalid(size); MakeInvalid(size);
cairo_surface_t *surf = cairo_win32_surface_create_with_dib((cairo_format_t)(int)imageFormat, cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat);
size.width, size.height); cairo_surface_t *surf =
cairo_win32_surface_create_with_dib(cformat, size.width, size.height);
Init(surf); Init(surf);
@ -79,8 +80,10 @@ gfxWindowsSurface::gfxWindowsSurface(HDC dc, const mozilla::gfx::IntSize& realSi
if (!CheckSurfaceSize(size)) if (!CheckSurfaceSize(size))
MakeInvalid(size); MakeInvalid(size);
cairo_surface_t *surf = cairo_win32_surface_create_with_ddb(dc, (cairo_format_t)(int)imageFormat, cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat);
size.width, size.height); cairo_surface_t *surf =
cairo_win32_surface_create_with_ddb(dc, cformat,
size.width, size.height);
Init(surf); Init(surf);
@ -138,9 +141,11 @@ gfxWindowsSurface::CreateSimilarSurface(gfxContentType aContent,
// a surface that's the result of create_similar(gfxContentType::COLOR_ALPHA) // a surface that's the result of create_similar(gfxContentType::COLOR_ALPHA)
// (e.g. a backbuffer for the window) --- that new surface *would* // (e.g. a backbuffer for the window) --- that new surface *would*
// have a DIB. // have a DIB.
surface = gfxImageFormat gformat =
cairo_win32_surface_create_with_dib((cairo_format_t)(int)gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent), gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
aSize.width, aSize.height); cairo_format_t cformat = gfxImageFormatToCairoFormat(gformat);
surface = cairo_win32_surface_create_with_dib(cformat, aSize.width,
aSize.height);
} else { } else {
surface = surface =
cairo_surface_create_similar(mSurface, (cairo_content_t)(int)aContent, cairo_surface_create_similar(mSurface, (cairo_content_t)(int)aContent,

View File

@ -352,7 +352,7 @@ CreateTempXlibSurface (cairo_surface_t* cairoTarget,
} else if (cairoTargetType == CAIRO_SURFACE_TYPE_IMAGE || drawTarget) { } else if (cairoTargetType == CAIRO_SURFACE_TYPE_IMAGE || drawTarget) {
gfxImageFormat imageFormat = gfxImageFormat imageFormat =
drawTarget ? SurfaceFormatToImageFormat(drawTarget->GetFormat()) : drawTarget ? SurfaceFormatToImageFormat(drawTarget->GetFormat()) :
(gfxImageFormat)cairo_image_surface_get_format(cairoTarget); gfxCairoFormatToImageFormat(cairo_image_surface_get_format(cairoTarget));
target_visual = gfxXlibSurface::FindVisual(screen, imageFormat); target_visual = gfxXlibSurface::FindVisual(screen, imageFormat);
Display *dpy = DisplayOfScreen(screen); Display *dpy = DisplayOfScreen(screen);
if (target_visual) { if (target_visual) {