2008-04-19 15:43:23 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-04-19 15:43:23 +00:00
|
|
|
|
2008-05-04 18:51:37 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2011-03-10 19:52:15 +00:00
|
|
|
#include "cairo-features.h"
|
2010-10-05 06:15:57 +00:00
|
|
|
#ifdef CAIRO_HAS_QT_SURFACE
|
2010-04-29 10:25:02 +00:00
|
|
|
#include "cairo-qt.h"
|
2011-03-10 19:52:15 +00:00
|
|
|
#include "gfxQPainterSurface.h"
|
2008-04-19 15:43:23 +00:00
|
|
|
|
|
|
|
gfxQPainterSurface::gfxQPainterSurface(QPainter *painter)
|
|
|
|
{
|
2010-04-29 10:25:02 +00:00
|
|
|
cairo_surface_t *csurf = cairo_qt_surface_create (painter);
|
2008-04-19 15:43:23 +00:00
|
|
|
|
|
|
|
mPainter = painter;
|
|
|
|
|
|
|
|
Init (csurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxImageFormat format)
|
|
|
|
{
|
2010-04-29 10:25:02 +00:00
|
|
|
cairo_surface_t *csurf = cairo_qt_surface_create_with_qimage ((cairo_format_t) format,
|
2008-04-19 15:43:23 +00:00
|
|
|
size.width,
|
|
|
|
size.height);
|
2010-04-29 10:25:02 +00:00
|
|
|
mPainter = cairo_qt_surface_get_qpainter (csurf);
|
2008-04-19 15:43:23 +00:00
|
|
|
|
|
|
|
Init (csurf);
|
|
|
|
}
|
|
|
|
|
2008-04-29 01:15:30 +00:00
|
|
|
gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxContentType content)
|
2008-04-19 15:43:23 +00:00
|
|
|
{
|
2010-04-29 10:25:02 +00:00
|
|
|
cairo_surface_t *csurf = cairo_qt_surface_create_with_qpixmap ((cairo_content_t) content,
|
2008-04-29 01:15:30 +00:00
|
|
|
size.width,
|
2008-04-19 15:43:23 +00:00
|
|
|
size.height);
|
2010-04-29 10:25:02 +00:00
|
|
|
mPainter = cairo_qt_surface_get_qpainter (csurf);
|
2008-04-19 15:43:23 +00:00
|
|
|
|
|
|
|
Init (csurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxQPainterSurface::gfxQPainterSurface(cairo_surface_t *csurf)
|
|
|
|
{
|
2010-04-29 10:25:02 +00:00
|
|
|
mPainter = cairo_qt_surface_get_qpainter (csurf);
|
2008-04-19 15:43:23 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
Init(csurf, true);
|
2008-04-19 15:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxQPainterSurface::~gfxQPainterSurface()
|
|
|
|
{
|
|
|
|
}
|
2008-04-20 08:40:10 +00:00
|
|
|
|
|
|
|
QImage *
|
|
|
|
gfxQPainterSurface::GetQImage()
|
|
|
|
{
|
|
|
|
if (!mSurfaceValid)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-04-20 08:40:10 +00:00
|
|
|
|
2010-04-29 10:25:02 +00:00
|
|
|
return cairo_qt_surface_get_qimage(CairoSurface());
|
2008-04-20 08:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxImageSurface>
|
2010-11-11 20:31:22 +00:00
|
|
|
gfxQPainterSurface::GetAsImageSurface()
|
2008-04-20 08:40:10 +00:00
|
|
|
{
|
|
|
|
if (!mSurfaceValid)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-04-20 08:40:10 +00:00
|
|
|
|
2010-04-29 10:25:02 +00:00
|
|
|
cairo_surface_t *isurf = cairo_qt_surface_get_image(CairoSurface());
|
2008-04-20 08:40:10 +00:00
|
|
|
if (!isurf)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-04-20 08:40:10 +00:00
|
|
|
|
2008-05-04 18:51:37 +00:00
|
|
|
assert(cairo_surface_get_type(isurf) == CAIRO_SURFACE_TYPE_IMAGE);
|
2008-04-20 08:40:10 +00:00
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> asurf = new gfxImageSurface(isurf);
|
2013-09-20 09:50:05 +00:00
|
|
|
asurf->SetOpaqueRect(GetOpaqueRect());
|
2008-04-20 08:40:10 +00:00
|
|
|
return asurf.forget();
|
|
|
|
}
|
2010-10-05 06:15:57 +00:00
|
|
|
#endif
|