|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include <assert.h> |
|
7 |
|
8 #include "cairo-features.h" |
|
9 #ifdef CAIRO_HAS_QT_SURFACE |
|
10 #include "cairo-qt.h" |
|
11 #include "gfxQPainterSurface.h" |
|
12 |
|
13 gfxQPainterSurface::gfxQPainterSurface(QPainter *painter) |
|
14 { |
|
15 cairo_surface_t *csurf = cairo_qt_surface_create (painter); |
|
16 |
|
17 mPainter = painter; |
|
18 |
|
19 Init (csurf); |
|
20 } |
|
21 |
|
22 gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxImageFormat format) |
|
23 { |
|
24 cairo_surface_t *csurf = cairo_qt_surface_create_with_qimage ((cairo_format_t) format, |
|
25 size.width, |
|
26 size.height); |
|
27 mPainter = cairo_qt_surface_get_qpainter (csurf); |
|
28 |
|
29 Init (csurf); |
|
30 } |
|
31 |
|
32 gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxContentType content) |
|
33 { |
|
34 cairo_surface_t *csurf = cairo_qt_surface_create_with_qpixmap ((cairo_content_t) content, |
|
35 size.width, |
|
36 size.height); |
|
37 mPainter = cairo_qt_surface_get_qpainter (csurf); |
|
38 |
|
39 Init (csurf); |
|
40 } |
|
41 |
|
42 gfxQPainterSurface::gfxQPainterSurface(cairo_surface_t *csurf) |
|
43 { |
|
44 mPainter = cairo_qt_surface_get_qpainter (csurf); |
|
45 |
|
46 Init(csurf, true); |
|
47 } |
|
48 |
|
49 gfxQPainterSurface::~gfxQPainterSurface() |
|
50 { |
|
51 } |
|
52 |
|
53 QImage * |
|
54 gfxQPainterSurface::GetQImage() |
|
55 { |
|
56 if (!mSurfaceValid) |
|
57 return nullptr; |
|
58 |
|
59 return cairo_qt_surface_get_qimage(CairoSurface()); |
|
60 } |
|
61 |
|
62 already_AddRefed<gfxImageSurface> |
|
63 gfxQPainterSurface::GetAsImageSurface() |
|
64 { |
|
65 if (!mSurfaceValid) |
|
66 return nullptr; |
|
67 |
|
68 cairo_surface_t *isurf = cairo_qt_surface_get_image(CairoSurface()); |
|
69 if (!isurf) |
|
70 return nullptr; |
|
71 |
|
72 assert(cairo_surface_get_type(isurf) == CAIRO_SURFACE_TYPE_IMAGE); |
|
73 |
|
74 nsRefPtr<gfxImageSurface> asurf = new gfxImageSurface(isurf); |
|
75 asurf->SetOpaqueRect(GetOpaqueRect()); |
|
76 return asurf.forget(); |
|
77 } |
|
78 #endif |