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
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

View File

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

View File

@ -32,7 +32,7 @@ gfxImageSurface::InitFromSurface(cairo_surface_t *csurf)
mSize.width = cairo_image_surface_get_width(csurf);
mSize.height = cairo_image_surface_get_height(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;
mStride = cairo_image_surface_get_stride(csurf);
@ -66,9 +66,10 @@ gfxImageSurface::InitWithData(unsigned char *aData, const IntSize& aSize,
if (!CheckSurfaceSize(aSize))
MakeInvalid();
cairo_format_t cformat = gfxImageFormatToCairoFormat(mFormat);
cairo_surface_t *surface =
cairo_image_surface_create_for_data((unsigned char*)mData,
(cairo_format_t)(int)mFormat,
cformat,
mSize.width,
mSize.height,
mStride);
@ -135,9 +136,10 @@ gfxImageSurface::AllocateAndInit(long aStride, int32_t aMinimalAllocation,
mOwnsData = true;
cairo_format_t cformat = gfxImageFormatToCairoFormat(mFormat);
cairo_surface_t *surface =
cairo_image_surface_create_for_data((unsigned char*)mData,
(cairo_format_t)(int)mFormat,
cformat,
mSize.width,
mSize.height,
mStride);
@ -162,7 +164,7 @@ gfxImageSurface::gfxImageSurface(cairo_surface_t *csurf)
mSize.width = cairo_image_surface_get_width(csurf);
mSize.height = cairo_image_surface_get_height(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;
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)
{
cairo_surface_t *csurf = cairo_qt_surface_create_with_qimage ((cairo_format_t) format,
size.width,
size.height);
cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
cairo_surface_t *csurf =
cairo_qt_surface_create_with_qimage(cformat, size.width, size.height);
mPainter = cairo_qt_surface_get_qpainter (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 height = static_cast<unsigned int>(mSize.height);
cairo_surface_t *surf = cairo_quartz_surface_create
((cairo_format_t) format, width, height);
cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
cairo_surface_t *surf = cairo_quartz_surface_create(cformat, width, height);
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 height = static_cast<unsigned int>(mSize.height);
cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
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);
@ -131,8 +132,9 @@ gfxQuartzSurface::gfxQuartzSurface(unsigned char *data,
if (!CheckSurfaceSize(aSize))
MakeInvalid();
cairo_format_t cformat = gfxImageFormatToCairoFormat(format);
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);

View File

@ -57,6 +57,18 @@ enum class gfxImageFormat {
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 {
Image,
PDF,

View File

@ -59,8 +59,9 @@ gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize, gfxI
if (!CheckSurfaceSize(size))
MakeInvalid(size);
cairo_surface_t *surf = cairo_win32_surface_create_with_dib((cairo_format_t)(int)imageFormat,
size.width, size.height);
cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat);
cairo_surface_t *surf =
cairo_win32_surface_create_with_dib(cformat, size.width, size.height);
Init(surf);
@ -79,8 +80,10 @@ gfxWindowsSurface::gfxWindowsSurface(HDC dc, const mozilla::gfx::IntSize& realSi
if (!CheckSurfaceSize(size))
MakeInvalid(size);
cairo_surface_t *surf = cairo_win32_surface_create_with_ddb(dc, (cairo_format_t)(int)imageFormat,
size.width, size.height);
cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat);
cairo_surface_t *surf =
cairo_win32_surface_create_with_ddb(dc, cformat,
size.width, size.height);
Init(surf);
@ -138,9 +141,11 @@ gfxWindowsSurface::CreateSimilarSurface(gfxContentType aContent,
// a surface that's the result of create_similar(gfxContentType::COLOR_ALPHA)
// (e.g. a backbuffer for the window) --- that new surface *would*
// have a DIB.
surface =
cairo_win32_surface_create_with_dib((cairo_format_t)(int)gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent),
aSize.width, aSize.height);
gfxImageFormat gformat =
gfxPlatform::GetPlatform()->OptimalFormatForContent(aContent);
cairo_format_t cformat = gfxImageFormatToCairoFormat(gformat);
surface = cairo_win32_surface_create_with_dib(cformat, aSize.width,
aSize.height);
} else {
surface =
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) {
gfxImageFormat imageFormat =
drawTarget ? SurfaceFormatToImageFormat(drawTarget->GetFormat()) :
(gfxImageFormat)cairo_image_surface_get_format(cairoTarget);
gfxCairoFormatToImageFormat(cairo_image_surface_get_format(cairoTarget));
target_visual = gfxXlibSurface::FindVisual(screen, imageFormat);
Display *dpy = DisplayOfScreen(screen);
if (target_visual) {