[qpainter] Add getters for QImage; also make OptimizeImages a noop

The QPainter back end knows how to create a QImage from an image surface
while painting, so no need to copy the image.
This commit is contained in:
Vladimir Vukicevic 2008-04-20 01:40:10 -07:00
parent a8b0f696f7
commit ed0e67d29f
6 changed files with 88 additions and 0 deletions

View File

@ -1451,6 +1451,28 @@ cairo_qpainter_surface_get_qpainter (cairo_surface_t *surface)
return qs->p; return qs->p;
} }
QImage *
cairo_qpainter_surface_get_qimage (cairo_surface_t *surface)
{
cairo_qpainter_surface_t *qs = (cairo_qpainter_surface_t*) surface;
if (surface->type != CAIRO_SURFACE_TYPE_QPAINTER)
return NULL;
return qs->image;
}
cairo_surface_t *
cairo_qpainter_surface_get_image (cairo_surface_t *surface)
{
cairo_qpainter_surface_t *qs = (cairo_qpainter_surface_t*) surface;
if (surface->type != CAIRO_SURFACE_TYPE_QPAINTER)
return NULL;
return (cairo_surface_t*) qs->image_equiv;
}
/* /*
* TODO: * TODO:
* *

View File

@ -42,6 +42,7 @@
#if CAIRO_HAS_QPAINTER_SURFACE #if CAIRO_HAS_QPAINTER_SURFACE
class QPainter; class QPainter;
class QImage;
CAIRO_BEGIN_DECLS CAIRO_BEGIN_DECLS
@ -60,6 +61,12 @@ cairo_qpainter_surface_create_with_qpixmap (int width,
cairo_public QPainter * cairo_public QPainter *
cairo_qpainter_surface_get_qpainter (cairo_surface_t *surface); cairo_qpainter_surface_get_qpainter (cairo_surface_t *surface);
cairo_public cairo_surface_t *
cairo_qpainter_surface_get_image (cairo_surface_t *surface);
cairo_public QImage *
cairo_qpainter_surface_get_qimage (cairo_surface_t *surface);
CAIRO_END_DECLS CAIRO_END_DECLS
#else /* CAIRO_HAS_QPAINTER_SURFACE */ #else /* CAIRO_HAS_QPAINTER_SURFACE */

View File

@ -42,6 +42,7 @@
#include "gfxImageSurface.h" #include "gfxImageSurface.h"
class QPainter; class QPainter;
class QImage;
class THEBES_API gfxQPainterSurface : public gfxASurface { class THEBES_API gfxQPainterSurface : public gfxASurface {
public: public:
@ -55,6 +56,9 @@ public:
QPainter *GetQPainter() { return mPainter; } QPainter *GetQPainter() { return mPainter; }
QImage *GetQImage();
already_AddRefed<gfxImageSurface> GetImageSurface();
protected: protected:
QPainter *mPainter; QPainter *mPainter;
}; };

View File

@ -60,6 +60,9 @@ public:
already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size, already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,
gfxASurface::gfxImageFormat imageFormat); gfxASurface::gfxImageFormat imageFormat);
already_AddRefed<gfxASurface> OptimizeImage(gfxImageSurface *aSurface,
gfxASurface::gfxImageFormat format);
nsresult GetFontList(const nsACString& aLangGroup, nsresult GetFontList(const nsACString& aLangGroup,
const nsACString& aGenericFamily, const nsACString& aGenericFamily,
nsStringArray& aListOfFonts); nsStringArray& aListOfFonts);

View File

@ -36,6 +36,7 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "gfxQPainterSurface.h" #include "gfxQPainterSurface.h"
#include "gfxImageSurface.h"
#include "cairo-qpainter.h" #include "cairo-qpainter.h"
@ -77,3 +78,29 @@ gfxQPainterSurface::gfxQPainterSurface(cairo_surface_t *csurf)
gfxQPainterSurface::~gfxQPainterSurface() gfxQPainterSurface::~gfxQPainterSurface()
{ {
} }
QImage *
gfxQPainterSurface::GetQImage()
{
if (!mSurfaceValid)
return nsnull;
return cairo_qpainter_surface_get_qimage(CairoSurface());
}
already_AddRefed<gfxImageSurface>
gfxQPainterSurface::GetImageSurface()
{
if (!mSurfaceValid)
return nsnull;
cairo_surface_t *isurf = cairo_qpainter_surface_get_image(CairoSurface());
if (!isurf)
return nsnull;
if (cairo_surface_get_type(isurf) == CAIRO_SURFACE_TYPE_IMAGE)
return nsnull;
nsRefPtr<gfxImageSurface> asurf = new gfxImageSurface(isurf);
return asurf.forget();
}

View File

@ -126,6 +126,31 @@ gfxQtPlatform::CreateOffscreenSurface(const gfxIntSize& size,
return newSurface.forget(); return newSurface.forget();
} }
already_AddRefed<gfxASurface>
gfxQtPlatform::OptimizeImage(gfxImageSurface *aSurface,
gfxASurface::gfxImageFormat format)
{
NS_ADDREF(aSurface);
return aSurface;
#if 0
const gfxIntSize& surfaceSize = aSurface->GetSize();
nsRefPtr<gfxASurface> optSurface = CreateOffscreenSurface(surfaceSize, format);
if (!optSurface || optSurface->CairoStatus() != 0)
return nsnull;
gfxContext tmpCtx(optSurface);
tmpCtx.SetOperator(gfxContext::OPERATOR_SOURCE);
tmpCtx.SetSource(aSurface);
tmpCtx.Paint();
gfxASurface *ret = optSurface;
NS_ADDREF(ret);
return ret;
#endif
}
nsresult nsresult
gfxQtPlatform::GetFontList(const nsACString& aLangGroup, gfxQtPlatform::GetFontList(const nsACString& aLangGroup,
const nsACString& aGenericFamily, const nsACString& aGenericFamily,