gfxImageSurface::gfxImageSurface(const gfxIntSize& size, gfxImageFormat format) : mSize(size), mFormat(format) { mStride = ComputeStride(); if (!CheckSurfaceSize(size)) return; // if we have a zero-sized surface, just set mData to nsnull if (mSize.height * mStride > 0) { mData = (unsigned char *) malloc(mSize.height * mStride); if (!mData) return; } else { mData = nsnull; } mOwnsData = PR_TRUE; cairo_surface_t *surface = cairo_image_surface_create_for_data((unsigned char*)mData, (cairo_format_t)format, mSize.width, mSize.height, mStride); Init(surface); }
gfxQuartzSurface::gfxQuartzSurface(unsigned char *data, const gfxSize& desiredSize, long stride, gfxImageFormat format, bool aForPrinting) : mCGContext(nullptr), mSize(desiredSize), mForPrinting(aForPrinting) { gfxIntSize size((unsigned int) floor(desiredSize.width), (unsigned int) floor(desiredSize.height)); if (!CheckSurfaceSize(size)) MakeInvalid(); 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_for_data (data, (cairo_format_t) format, width, height, stride); mCGContext = cairo_quartz_surface_get_cg_context (surf); CGContextRetain(mCGContext); Init(surf); if (mSurfaceValid) { RecordMemoryUsed(mSize.height * stride + sizeof(gfxQuartzSurface)); } }
gfxWindowsSurface::gfxWindowsSurface(HDC dc, const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) : mOwnsDC(false), mForPrinting(false), mWnd(nullptr) { mozilla::gfx::IntSize size(realSize); if (!CheckSurfaceSize(size)) MakeInvalid(size); cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat); cairo_surface_t *surf = cairo_win32_surface_create_with_ddb(dc, cformat, size.width, size.height); Init(surf); if (mSurfaceValid) { // DDBs will generally only use 3 bytes per pixel when RGB24 int bytesPerPixel = ((imageFormat == gfxImageFormat::RGB24) ? 3 : 4); RecordMemoryUsed(size.width * size.height * bytesPerPixel + sizeof(gfxWindowsSurface)); } if (CairoStatus() == 0) mDC = cairo_win32_surface_get_dc(CairoSurface()); else mDC = nullptr; }
gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfxIntSize& size) : mPixmapTaken(PR_FALSE), mDisplay(dpy), mDrawable(drawable), mSize(size) { NS_ASSERTION(CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT), "Bad size"); cairo_surface_t *surf = cairo_xlib_surface_create(dpy, drawable, visual, mSize.width, mSize.height); Init(surf); }
gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, XRenderPictFormat *format, const gfxIntSize& size) : mPixmapTaken(PR_FALSE), mDisplay(dpy), mDrawable(drawable), mSize(size) { if (!CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT)) return; cairo_surface_t *surf = cairo_xlib_surface_create_with_xrender_format(dpy, drawable, ScreenOfDisplay(dpy,DefaultScreen(dpy)), format, mSize.width, mSize.height); Init(surf); }
gfxDirectFBSurface::gfxDirectFBSurface(const gfxIntSize& size, gfxImageFormat format) : mDFB(nsnull), mDFBSurface(nsnull) { DFBResult ret; DFBSurfaceDescription desc; if (!CheckSurfaceSize(size) || size.width <= 0 || size.height <= 0) return; /* Lightweight, getting singleton */ ret = DirectFBCreate( &mDFB ); if (ret) { D_DERROR( (DirectResult) ret, "gfxDirectFBSurface: DirectFBCreate() failed!\n" ); return; } desc.flags = (DFBSurfaceDescriptionFlags)( DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT ); desc.width = size.width; desc.height = size.height; switch (format) { case gfxASurface::ImageFormatARGB32: desc.pixelformat = DSPF_ARGB; break; case gfxASurface::ImageFormatRGB24: desc.pixelformat = DSPF_RGB32; break; case gfxASurface::ImageFormatA8: desc.pixelformat = DSPF_A8; break; case gfxASurface::ImageFormatA1: desc.pixelformat = DSPF_A1; break; default: D_BUG( "unknown format" ); return; } ret = mDFB->CreateSurface( mDFB, &desc, &mDFBSurface ); if (ret) { D_DERROR( (DirectResult) ret, "gfxDirectFBSurface: " "IDirectFB::CreateSurface( %dx%d ) failed!\n", desc.width, desc.height ); return; } cairo_surface_t *surface = cairo_directfb_surface_create(mDFB, mDFBSurface); Init(surface); }
gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize, gfxASurface::gfxImageFormat aFormat) : mWnd(0), mDC(0), mPS(0), mSize(aSize), mSurfType(os2Image) { if (!CheckSurfaceSize(aSize)) return; cairo_surface_t *surf = cairo_os2_surface_create((cairo_format_t)aFormat, mSize.width, mSize.height); Init(surf); RecordMemoryUsed(mSize.width * mSize.height * 4 + OS2_OVERHEAD); }
gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFormat *format, const gfxIntSize& size) : mPixmapTaken(PR_FALSE), mDisplay(DisplayOfScreen(screen)), mDrawable(drawable), mSize(size) { NS_ASSERTION(CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT), "Bad Size"); cairo_surface_t *surf = cairo_xlib_surface_create_with_xrender_format(mDisplay, drawable, screen, format, mSize.width, mSize.height); Init(surf); }
gfxWindowsSurface::gfxWindowsSurface(HDC dc, const gfxIntSize& size, gfxImageFormat imageFormat) : mOwnsDC(PR_FALSE), mForPrinting(PR_FALSE), mWnd(nsnull) { if (!CheckSurfaceSize(size)) return; cairo_surface_t *surf = cairo_win32_surface_create_with_ddb(dc, (cairo_format_t)imageFormat, size.width, size.height); Init(surf); if (CairoStatus() == 0) mDC = cairo_win32_surface_get_dc(CairoSurface()); else mDC = nsnull; }
gfxXlibSurface::gfxXlibSurface(Display *dpy, Visual *visual, const gfxIntSize& size) : mPixmapTaken(PR_FALSE), mDisplay(dpy), mSize(size) { if (!CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT)) return; mDrawable = (Drawable)XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), mSize.width, mSize.height, DefaultDepth(dpy, DefaultScreen(dpy))); cairo_surface_t *surf = cairo_xlib_surface_create(dpy, mDrawable, visual, mSize.width, mSize.height); Init(surf); TakePixmap(); }
gfxWindowsSurface::gfxWindowsSurface(const gfxIntSize& realSize, gfxImageFormat imageFormat) : mOwnsDC(false), mForPrinting(false), mWnd(nullptr) { gfxIntSize size(realSize); if (!CheckSurfaceSize(size)) MakeInvalid(size); cairo_surface_t *surf = cairo_win32_surface_create_with_dib((cairo_format_t)(int)imageFormat, size.width, size.height); Init(surf); if (CairoStatus() == CAIRO_STATUS_SUCCESS) { mDC = cairo_win32_surface_get_dc(CairoSurface()); RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface)); } else { mDC = nullptr; } }
gfxQuartzSurface::gfxQuartzSurface(CGContextRef context, const gfxIntSize& size, bool aForPrinting) : mCGContext(context), mSize(size), mForPrinting(aForPrinting) { if (!CheckSurfaceSize(size)) MakeInvalid(); 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_for_cg_context(context, width, height); CGContextRetain(mCGContext); Init(surf); }
gfxWindowsSurface::gfxWindowsSurface(HDC dc, const gfxIntSize& size, gfxImageFormat imageFormat) : mOwnsDC(PR_FALSE), mForPrinting(PR_FALSE), mWnd(nsnull) { if (!CheckSurfaceSize(size)) return; cairo_surface_t *surf = cairo_win32_surface_create_with_ddb(dc, (cairo_format_t)imageFormat, size.width, size.height); Init(surf); // DDBs will generally only use 3 bytes per pixel when RGB24 int bytesPerPixel = ((imageFormat == gfxASurface::ImageFormatRGB24) ? 3 : 4); RecordMemoryUsed(size.width * size.height * bytesPerPixel + sizeof(gfxWindowsSurface)); if (CairoStatus() == 0) mDC = cairo_win32_surface_get_dc(CairoSurface()); else mDC = nsnull; }
gfxQuartzSurface::gfxQuartzSurface(const gfxSize& desiredSize, gfxImageFormat format, bool aForPrinting) : mCGContext(NULL), mSize(desiredSize), mForPrinting(aForPrinting) { gfxIntSize size((unsigned int) floor(desiredSize.width), (unsigned int) floor(desiredSize.height)); if (!CheckSurfaceSize(size)) MakeInvalid(); 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); mCGContext = cairo_quartz_surface_get_cg_context (surf); CGContextRetain(mCGContext); Init(surf); }
gfxQuartzSurface::gfxQuartzSurface(CGContextRef context, const mozilla::gfx::IntSize& size) : mCGContext(context), mSize(size) { if (!CheckSurfaceSize(size)) MakeInvalid(); 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_for_cg_context(context, width, height); CGContextRetain(mCGContext); Init(surf); if (mSurfaceValid) { RecordMemoryUsed(mSize.height * 4 + sizeof(gfxQuartzSurface)); } }
gfxQuartzSurface::gfxQuartzSurface(unsigned char *data, const gfxIntSize& aSize, long stride, gfxImageFormat format, bool aForPrinting) : mCGContext(nullptr), mSize(aSize.width, aSize.height), mForPrinting(aForPrinting) { if (!CheckSurfaceSize(aSize)) MakeInvalid(); cairo_surface_t *surf = cairo_quartz_surface_create_for_data (data, (cairo_format_t) format, aSize.width, aSize.height, stride); mCGContext = cairo_quartz_surface_get_cg_context (surf); CGContextRetain(mCGContext); Init(surf); if (mSurfaceValid) { RecordMemoryUsed(mSize.height * stride + sizeof(gfxQuartzSurface)); } }
gfxQuartzSurface::gfxQuartzSurface(unsigned char *data, const mozilla::gfx::IntSize& aSize, long stride, gfxImageFormat format) : mCGContext(nullptr), mSize(aSize.width, aSize.height) { if (!CheckSurfaceSize(aSize)) MakeInvalid(); cairo_format_t cformat = GfxFormatToCairoFormat(format); cairo_surface_t *surf = cairo_quartz_surface_create_for_data (data, cformat, aSize.width, aSize.height, stride); mCGContext = cairo_quartz_surface_get_cg_context (surf); CGContextRetain(mCGContext); Init(surf); if (mSurfaceValid) { RecordMemoryUsed(mSize.height * stride + sizeof(gfxQuartzSurface)); } }
gfxQuartzSurface::gfxQuartzSurface(const gfxSize& desiredSize, gfxImageFormat format) : mCGContext(nullptr), mSize(desiredSize) { mozilla::gfx::IntSize size((unsigned int) floor(desiredSize.width), (unsigned int) floor(desiredSize.height)); if (!CheckSurfaceSize(size)) MakeInvalid(); 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(cformat, width, height); mCGContext = cairo_quartz_surface_get_cg_context (surf); CGContextRetain(mCGContext); Init(surf); if (mSurfaceValid) { RecordMemoryUsed(mSize.height * 4 + sizeof(gfxQuartzSurface)); } }
gfxQuartzSurface::gfxQuartzSurface(CGContextRef context, const gfxSize& desiredSize, bool aForPrinting) : mCGContext(context), mSize(desiredSize), mForPrinting(aForPrinting) { gfxIntSize size((unsigned int) floor(desiredSize.width), (unsigned int) floor(desiredSize.height)); if (!CheckSurfaceSize(size)) MakeInvalid(); 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_for_cg_context(context, width, height); CGContextRetain(mCGContext); Init(surf); if (mSurfaceValid) { RecordMemoryUsed(mSize.height * 4 + sizeof(gfxQuartzSurface)); } }