2008-04-19 08:43:23 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07: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 08:43:23 -07:00
|
|
|
|
2008-05-04 11:51:37 -07:00
|
|
|
#include <assert.h>
|
|
|
|
|
2011-03-10 11:52:15 -08:00
|
|
|
#include "cairo-features.h"
|
2010-10-04 23:15:57 -07:00
|
|
|
#ifdef CAIRO_HAS_QT_SURFACE
|
2010-04-29 03:25:02 -07:00
|
|
|
#include "cairo-qt.h"
|
2011-03-10 11:52:15 -08:00
|
|
|
#include "gfxQPainterSurface.h"
|
2008-04-19 08:43:23 -07:00
|
|
|
|
|
|
|
gfxQPainterSurface::gfxQPainterSurface(QPainter *painter)
|
|
|
|
{
|
2010-04-29 03:25:02 -07:00
|
|
|
cairo_surface_t *csurf = cairo_qt_surface_create (painter);
|
2008-04-19 08:43:23 -07:00
|
|
|
|
|
|
|
mPainter = painter;
|
|
|
|
|
|
|
|
Init (csurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxImageFormat format)
|
|
|
|
{
|
2010-04-29 03:25:02 -07:00
|
|
|
cairo_surface_t *csurf = cairo_qt_surface_create_with_qimage ((cairo_format_t) format,
|
2008-04-19 08:43:23 -07:00
|
|
|
size.width,
|
|
|
|
size.height);
|
2010-04-29 03:25:02 -07:00
|
|
|
mPainter = cairo_qt_surface_get_qpainter (csurf);
|
2008-04-19 08:43:23 -07:00
|
|
|
|
|
|
|
Init (csurf);
|
|
|
|
}
|
|
|
|
|
2008-04-28 18:15:30 -07:00
|
|
|
gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxContentType content)
|
2008-04-19 08:43:23 -07:00
|
|
|
{
|
2010-04-29 03:25:02 -07:00
|
|
|
cairo_surface_t *csurf = cairo_qt_surface_create_with_qpixmap ((cairo_content_t) content,
|
2008-04-28 18:15:30 -07:00
|
|
|
size.width,
|
2008-04-19 08:43:23 -07:00
|
|
|
size.height);
|
2010-04-29 03:25:02 -07:00
|
|
|
mPainter = cairo_qt_surface_get_qpainter (csurf);
|
2008-04-19 08:43:23 -07:00
|
|
|
|
|
|
|
Init (csurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxQPainterSurface::gfxQPainterSurface(cairo_surface_t *csurf)
|
|
|
|
{
|
2010-04-29 03:25:02 -07:00
|
|
|
mPainter = cairo_qt_surface_get_qpainter (csurf);
|
2008-04-19 08:43:23 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
Init(csurf, true);
|
2008-04-19 08:43:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxQPainterSurface::~gfxQPainterSurface()
|
|
|
|
{
|
|
|
|
}
|
2008-04-20 01:40:10 -07:00
|
|
|
|
|
|
|
QImage *
|
|
|
|
gfxQPainterSurface::GetQImage()
|
|
|
|
{
|
|
|
|
if (!mSurfaceValid)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-20 01:40:10 -07:00
|
|
|
|
2010-04-29 03:25:02 -07:00
|
|
|
return cairo_qt_surface_get_qimage(CairoSurface());
|
2008-04-20 01:40:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxImageSurface>
|
2010-11-11 12:31:22 -08:00
|
|
|
gfxQPainterSurface::GetAsImageSurface()
|
2008-04-20 01:40:10 -07:00
|
|
|
{
|
|
|
|
if (!mSurfaceValid)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-20 01:40:10 -07:00
|
|
|
|
2010-04-29 03:25:02 -07:00
|
|
|
cairo_surface_t *isurf = cairo_qt_surface_get_image(CairoSurface());
|
2008-04-20 01:40:10 -07:00
|
|
|
if (!isurf)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-04-20 01:40:10 -07:00
|
|
|
|
2008-05-04 11:51:37 -07:00
|
|
|
assert(cairo_surface_get_type(isurf) == CAIRO_SURFACE_TYPE_IMAGE);
|
2008-04-20 01:40:10 -07:00
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> asurf = new gfxImageSurface(isurf);
|
2013-09-20 02:50:05 -07:00
|
|
|
asurf->SetOpaqueRect(GetOpaqueRect());
|
2008-04-20 01:40:10 -07:00
|
|
|
return asurf.forget();
|
|
|
|
}
|
2010-10-04 23:15:57 -07:00
|
|
|
#endif
|