Plug more leaks (in the test, not the core)
[gnash.git] / gui / kde / kde_glue_agg.cpp
blob5a50a60001ee63b74200397da4c07772ba268881
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
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.
9 //
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.
14 //
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
20 #ifdef HAVE_CONFIG_H
21 #include "gnashconfig.h"
22 #endif
24 #if GNASH_QT_VERSION == 4
25 #include <Qt/qpixmap.h>
26 #include <Qt/qcolor.h>
27 #include <Qt/qicon.h>
28 #include <Qt/Qt3Support>
29 #else
30 #include <qpixmap.h>
31 #include <qcolor.h>
32 #endif
33 #include "kde_glue_agg.h"
34 #include "Renderer.h"
35 #include "Renderer_agg.h"
36 #include "GnashException.h"
38 namespace gnash
41 KdeAggGlue::KdeAggGlue()
43 _width(0),
44 _height(0),
45 _renderer(0)
49 KdeAggGlue::~KdeAggGlue()
53 bool
54 KdeAggGlue::init(int /* argc */, char *** /* argv */)
56 // GNASH_REPORT_FUNCTION;
58 return true;
62 void
63 KdeAggGlue::prepDrawingArea(QWidget *drawing_area)
65 // GNASH_REPORT_FUNCTION;
66 _drawing_area = drawing_area;
70 void
71 KdeAggGlue::initBuffer(int width, int height)
73 if (!_renderer) return;
75 int _bpp = 32;
76 int depth_bytes = _bpp / 8; // TODO: <Udo> is this correct? Gives 1 for 15 bit modes!
78 assert(_bpp % 8 == 0);
80 #define CHUNK_SIZE (100 * 100 * depth_bytes)
82 int bufsize = (width * height * depth_bytes / CHUNK_SIZE + 1) * CHUNK_SIZE;
84 _offscreenbuf.reset(new unsigned char[bufsize]);
86 // Only the AGG renderer has the function init_buffer, which is *not* part of
87 // the renderer api. It allows us to change the renderers movie size (and buffer
88 // address) during run-time.
89 Renderer_agg_base * renderer =
90 static_cast<Renderer_agg_base *>(_renderer);
91 renderer->init_buffer(_offscreenbuf.get(), bufsize, width, height,
92 width*((_bpp+7)/8));
94 _width = width;
95 _height = height;
97 _validbounds.setTo(0, 0, _width, _height);
98 _drawbounds.push_back(_validbounds);
100 _qimage.reset(new QImage(_offscreenbuf.get(), _width, _height, 32 /* bits per pixel */,
101 0 , 0, QImage::IgnoreEndian));
104 void
105 KdeAggGlue::render()
107 // In order to use our buffer in QT, we must copy it into a pixmap. This is
108 // an expensive operation, but, as far as I can see, the only way to do it.
109 QPixmap qpixmap(*_qimage);
111 for (unsigned bno=0; bno < _drawbounds.size(); bno++) {
112 geometry::Range2d<int>& bounds = _drawbounds[bno];
114 assert ( bounds.isFinite() );
116 QPoint dest_point(bounds.getMinX(), bounds.getMinY()) ;
117 QRect src_rect(bounds.getMinX(), bounds.getMinY(), bounds.width(),
118 bounds.height());
120 bitBlt (_drawing_area, dest_point, &qpixmap, src_rect, Qt::CopyROP,
121 true /* ignore mask */ );
125 void
126 KdeAggGlue::setInvalidatedRegions(const InvalidatedRanges& ranges)
128 _renderer->set_invalidated_regions(ranges);
130 _drawbounds.clear();
132 for (size_t rno=0; rno<ranges.size(); rno++) {
134 geometry::Range2d<int> bounds = Intersection(
135 _renderer->world_to_pixel(ranges.getRange(rno)),
136 _validbounds);
138 // it may happen that a particular range is out of the screen, which
139 // will lead to bounds==null.
140 if (bounds.isNull()) continue;
142 assert(bounds.isFinite());
144 _drawbounds.push_back(bounds);
150 Renderer*
151 KdeAggGlue::createRenderHandler()
153 // QT requires the use of this pixel format...
154 _renderer = create_Renderer_agg("BGRA32");
155 if (! _renderer) {
156 throw GnashException(_("Could not create AGG renderer with pixelformat BGRA32"));
158 return _renderer;
161 void
162 KdeAggGlue::resize(int width, int height)
164 initBuffer(width, height);
167 // end of namespace gnash