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; }
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)); } }
gfxOS2Surface::gfxOS2Surface(HDC aDC, const gfxIntSize& aSize, int aPreview) : mWnd(0), mDC(aDC), mPS(0), mSize(aSize), mSurfType(os2Print) { // Create a PS using the same page size as the device. SIZEL sizel = { 0, 0 }; mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIA_ASSOC | (aPreview ? GPIT_MICRO : GPIT_NORMAL)); NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on print DC!"); printf("gfxOS2Surface for print - DC= %lx PS= %lx w= %d h= %d preview= %d\n", mDC, mPS, mSize.width, mSize.height, aPreview); // Create a cairo surface for the PS associated with the printer DC. // For print preview, create a null surface that can be queried but // generates no output. Otherwise, create a printing surface that // uses GPI functions to render the output. cairo_surface_t* surf; if (aPreview) surf = cairo_os2_surface_create_null_surface(mPS, mSize.width, mSize.height); else surf = cairo_os2_printing_surface_create(mPS, mSize.width, mSize.height); Init(surf); // Cairo allocates temporary buffers when it converts images from // BGR4 to BGR3 but there's no way to determine their size. RecordMemoryUsed(OS2_OVERHEAD); }
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); }
int gfxOS2Surface::Resize(const gfxIntSize& aSize) { if (mSurfType != os2Window) return 0; int status = cairo_os2_surface_set_size((cairo_os2_surface_t*)CairoSurface(), aSize.width, aSize.height, FALSE); if (status == CAIRO_STATUS_SUCCESS) { RecordMemoryUsed((aSize.width * aSize.height * 4) - (mSize.width * mSize.height * 4)); mSize = aSize; } return status; }
gfxWindowsSurface::gfxWindowsSurface(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_dib((cairo_format_t)imageFormat, size.width, size.height); Init(surf); RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface)); if (CairoStatus() == 0) mDC = cairo_win32_surface_get_dc(CairoSurface()); else mDC = nsnull; }
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; } }
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; }
gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) : mOwnsDC(false), mWnd(nullptr) { mozilla::gfx::IntSize size(realSize); if (!mozilla::gfx::Factory::CheckSurfaceSize(size)) MakeInvalid(size); cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat); cairo_surface_t *surf = cairo_win32_surface_create_with_dib(cformat, 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 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)); } }
gfxOS2Surface::gfxOS2Surface(HWND aWnd) : mWnd(aWnd), mDC(0), mPS(0), mSize(0,0), mSurfType(os2Window) { RECTL rectl; WinQueryWindowRect(aWnd, &rectl); mSize.width = rectl.xRight - rectl.xLeft; mSize.height = rectl.yTop - rectl.yBottom; // If necessary fake a minimal surface area to let // cairo_os2_surface_create() return something. if (mSize.width == 0) mSize.width = 1; if (mSize.height == 0) mSize.height = 1; cairo_surface_t *surf = cairo_os2_surface_create_for_window(mWnd, mSize.width, mSize.height); Init(surf); RecordMemoryUsed(mSize.width * mSize.height * 4 + OS2_OVERHEAD); }
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)); } }