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