gfx/thebes/gfxQPainterSurface.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxQPainterSurface.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <assert.h>
    1.10 +
    1.11 +#include "cairo-features.h"
    1.12 +#ifdef CAIRO_HAS_QT_SURFACE
    1.13 +#include "cairo-qt.h"
    1.14 +#include "gfxQPainterSurface.h"
    1.15 +
    1.16 +gfxQPainterSurface::gfxQPainterSurface(QPainter *painter)
    1.17 +{
    1.18 +    cairo_surface_t *csurf = cairo_qt_surface_create (painter);
    1.19 +
    1.20 +    mPainter = painter;
    1.21 +
    1.22 +    Init (csurf);
    1.23 +}
    1.24 +
    1.25 +gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxImageFormat format)
    1.26 +{
    1.27 +    cairo_surface_t *csurf = cairo_qt_surface_create_with_qimage ((cairo_format_t) format,
    1.28 +                                                                        size.width,
    1.29 +                                                                        size.height);
    1.30 +    mPainter = cairo_qt_surface_get_qpainter (csurf);
    1.31 +
    1.32 +    Init (csurf);
    1.33 +}
    1.34 +
    1.35 +gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxContentType content)
    1.36 +{
    1.37 +    cairo_surface_t *csurf = cairo_qt_surface_create_with_qpixmap ((cairo_content_t) content,
    1.38 +                                                                         size.width,
    1.39 +                                                                         size.height);
    1.40 +    mPainter = cairo_qt_surface_get_qpainter (csurf);
    1.41 +
    1.42 +    Init (csurf);
    1.43 +}
    1.44 +
    1.45 +gfxQPainterSurface::gfxQPainterSurface(cairo_surface_t *csurf)
    1.46 +{
    1.47 +    mPainter = cairo_qt_surface_get_qpainter (csurf);
    1.48 +
    1.49 +    Init(csurf, true);
    1.50 +}
    1.51 +
    1.52 +gfxQPainterSurface::~gfxQPainterSurface()
    1.53 +{
    1.54 +}
    1.55 +
    1.56 +QImage *
    1.57 +gfxQPainterSurface::GetQImage()
    1.58 +{
    1.59 +    if (!mSurfaceValid)
    1.60 +        return nullptr;
    1.61 +
    1.62 +    return cairo_qt_surface_get_qimage(CairoSurface());
    1.63 +}
    1.64 +
    1.65 +already_AddRefed<gfxImageSurface>
    1.66 +gfxQPainterSurface::GetAsImageSurface()
    1.67 +{
    1.68 +    if (!mSurfaceValid)
    1.69 +        return nullptr;
    1.70 +
    1.71 +    cairo_surface_t *isurf = cairo_qt_surface_get_image(CairoSurface());
    1.72 +    if (!isurf)
    1.73 +        return nullptr;
    1.74 +
    1.75 +    assert(cairo_surface_get_type(isurf) == CAIRO_SURFACE_TYPE_IMAGE);
    1.76 +
    1.77 +    nsRefPtr<gfxImageSurface> asurf = new gfxImageSurface(isurf);
    1.78 +    asurf->SetOpaqueRect(GetOpaqueRect());
    1.79 +    return asurf.forget();
    1.80 +}
    1.81 +#endif

mercurial