2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "gnashconfig.h"
25 #include "Qt4GlueCairo.h"
27 #include "Renderer_cairo.h"
34 Qt4CairoGlue::Qt4CairoGlue()
39 _cairo_handle(nullptr),
40 _cairo_surface(nullptr)
44 Qt4CairoGlue::~Qt4CairoGlue()
47 cairo_surface_destroy(_cairo_surface
);
51 Qt4CairoGlue::init(int /* argc */, char *** /* argv */)
57 Qt4CairoGlue::initBuffer(int width
, int height
)
65 cairo_format_t cairoFormat
= CAIRO_FORMAT_ARGB32
;
66 QImage::Format qtFormat
= QImage::Format_ARGB32
;
67 switch (_drawing_area
->depth()) {
69 cairoFormat
= CAIRO_FORMAT_RGB24
;
70 qtFormat
= QImage::Format_RGB32
;
73 cairoFormat
= CAIRO_FORMAT_ARGB32
;
74 qtFormat
= QImage::Format_ARGB32
;
78 // Cairo uses 4 bits per pixel even for 24 bit color depth
79 int bufsize
= _width
* _height
* 4;
80 _offscreenbuf
.reset(new unsigned char[bufsize
]);
81 _image
.reset(new QImage(_offscreenbuf
.get(),
82 _width
, _height
, qtFormat
));
85 cairo_surface_destroy(_cairo_surface
);
87 cairo_destroy(_cairo_handle
);
89 _cairo_surface
= cairo_image_surface_create_for_data(
90 _offscreenbuf
.get(), cairoFormat
, _width
, _height
,
91 cairo_format_stride_for_width(cairoFormat
, _width
));
93 _cairo_handle
= cairo_create(_cairo_surface
);
94 cairo_set_source_surface(_cairo_handle
,
95 cairo_get_target(_cairo_handle
), 0, 0);
96 renderer::cairo::set_context(_renderer
, _cairo_handle
);
100 Qt4CairoGlue::prepDrawingArea(DrawingWidget
*drawing_area
)
102 assert(drawing_area
);
103 _drawing_area
= drawing_area
;
108 Qt4CairoGlue::render()
110 QRect
r(0, 0, _width
, _height
);
116 Qt4CairoGlue::render(const QRect
& updateRect
)
118 assert(_drawing_area
);
122 cairo_paint(_cairo_handle
);
124 QPainter
p(_drawing_area
);
126 p
.drawImage(updateRect
, *_image
, updateRect
);
132 Qt4CairoGlue::resize(int width
, int height
)
134 initBuffer(width
, height
);
140 Qt4CairoGlue::createRenderHandler()
142 _renderer
= renderer::cairo::create_handler();
147 // end of namespace gnash