already_AddRefed<gfxImageSurface> gfxWindowsSurface::GetImageSurface() { if (!mSurfaceValid) { NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?"); return nsnull; } NS_ASSERTION(CairoSurface() != nsnull, "CairoSurface() shouldn't be nsnull when mSurfaceValid is TRUE!"); if (mForPrinting) return nsnull; cairo_surface_t *isurf = cairo_win32_surface_get_image(CairoSurface()); if (!isurf) return nsnull; nsRefPtr<gfxASurface> asurf = gfxASurface::Wrap(isurf); gfxImageSurface *imgsurf = (gfxImageSurface*) asurf.get(); NS_ADDREF(imgsurf); return imgsurf; }
already_AddRefed<gfxImageSurface> gfxWindowsSurface::GetAsImageSurface() { if (!mSurfaceValid) { NS_WARNING ("GetImageSurface on an invalid (null) surface; who's calling this without checking for surface errors?"); return nullptr; } NS_ASSERTION(CairoSurface() != nullptr, "CairoSurface() shouldn't be nullptr when mSurfaceValid is TRUE!"); if (mForPrinting) return nullptr; cairo_surface_t *isurf = cairo_win32_surface_get_image(CairoSurface()); if (!isurf) return nullptr; nsRefPtr<gfxImageSurface> result = gfxASurface::Wrap(isurf).downcast<gfxImageSurface>(); result->SetOpaqueRect(GetOpaqueRect()); return result.forget(); }
already_AddRefed<gfxImageSurface> gfxQuartzImageSurface::GetAsImageSurface() { if (!mSurfaceValid) return nullptr; cairo_surface_t *isurf = cairo_quartz_image_surface_get_image (CairoSurface()); if (!isurf) { NS_WARNING ("Couldn't obtain an image surface from a QuartzImageSurface?!"); return nullptr; } return gfxASurface::Wrap(isurf).downcast<gfxImageSurface>(); }
nsresult gfxWindowsSurface::EndPage() { #ifdef NS_PRINTING if (mForPrinting) cairo_surface_show_page(CairoSurface()); int result = ::EndPage(mDC); if (result <= 0) return NS_ERROR_FAILURE; return NS_OK; #else return NS_ERROR_FAILURE; #endif }
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(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; }
already_AddRefed<gfxImageSurface> gfxQPainterSurface::GetAsImageSurface() { if (!mSurfaceValid) return nsnull; cairo_surface_t *isurf = cairo_qt_surface_get_image(CairoSurface()); if (!isurf) return nsnull; assert(cairo_surface_get_type(isurf) == CAIRO_SURFACE_TYPE_IMAGE); nsRefPtr<gfxImageSurface> asurf = new gfxImageSurface(isurf); return asurf.forget(); }
already_AddRefed<gfxASurface> gfxXlibSurface::CreateSimilarSurface(gfxContentType aContent, const gfxIntSize& aSize) { if (!mSurface || !mSurfaceValid) { return nsnull; } if (aContent == CONTENT_COLOR) { // cairo_surface_create_similar will use a matching visual if it can. // However, systems with 16-bit or indexed default visuals may benefit // from rendering with 24-bit formats. static PRBool force24bpp = GetForce24bppPref(); if (force24bpp && cairo_xlib_surface_get_depth(CairoSurface()) != 24) { XRenderPictFormat* format = XRenderFindStandardFormat(mDisplay, PictStandardRGB24); if (format) { // Cairo only performs simple self-copies as desired if it // knows that this is a Pixmap surface. It only knows that // surfaces are pixmap surfaces if it creates the Pixmap // itself, so we use cairo_surface_create_similar with a // temporary reference surface to indicate the format. Screen* screen = cairo_xlib_surface_get_screen(CairoSurface()); nsRefPtr<gfxXlibSurface> depth24reference = gfxXlibSurface::Create(screen, format, gfxIntSize(1, 1), mDrawable); if (depth24reference) return depth24reference-> gfxASurface::CreateSimilarSurface(aContent, aSize); } } } return gfxASurface::CreateSimilarSurface(aContent, aSize); }
already_AddRefed<gfxImageSurface> gfxQuartzImageSurface::GetImageSurface() { if (!mSurfaceValid) return nsnull; cairo_surface_t *isurf = cairo_quartz_image_surface_get_image (CairoSurface()); if (!isurf) { NS_WARNING ("Couldn't obtain an image surface from a QuartzImageSurface?!"); return nsnull; } nsRefPtr<gfxASurface> asurf = gfxASurface::Wrap(isurf); gfxImageSurface *imgsurf = (gfxImageSurface*) asurf.get(); NS_ADDREF(imgsurf); return imgsurf; }
void gfxXlibSurface::TakePixmap() { if (mPixmapTaken) return; pixmap_free_struct *pfs = new pixmap_free_struct; pfs->dpy = mDisplay; pfs->pixmap = mDrawable; cairo_surface_set_user_data (CairoSurface(), &pixmap_free_key, pfs, pixmap_free_func); mPixmapTaken = PR_TRUE; }
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; } }
gfxWindowsSurface::gfxWindowsSurface(HDC dc, 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_ddb(dc, (cairo_format_t)(int)imageFormat, 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; }
ID3D10Texture2D* gfxD2DSurface::GetTexture() { return cairo_d2d_surface_get_texture(CairoSurface()); }
XRenderPictFormat* gfxXlibSurface::XRenderFormat() { return cairo_xlib_surface_get_xrender_format(CairoSurface()); }
void gfxOS2Surface::Refresh(RECTL *aRect, int aCount, HPS aPS) { if (mSurfType == os2Window) cairo_os2_surface_paint_window((cairo_os2_surface_t*)CairoSurface(), (aPS ? aPS : mPS), aRect, aCount); }
HDC gfxD2DSurface::GetDC(bool aRetainContents) { return cairo_d2d_get_dc(CairoSurface(), aRetainContents); }
void gfxD2DSurface::Present() { cairo_d2d_present_backbuffer(CairoSurface()); }
HDC gfxWindowsSurface::GetDC() { return cairo_win32_surface_get_dc (CairoSurface()); }
Screen* gfxXlibSurface::XScreen() { return cairo_xlib_surface_get_screen(CairoSurface()); }
nsresult gfxPDFSurface::EndPage() { cairo_surface_show_page(CairoSurface()); return NS_OK; }