2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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"
24 #if GNASH_QT_VERSION == 4
25 #include <Qt/qpixmap.h>
26 #include <Qt/qcolor.h>
28 #include <Qt/Qt3Support>
33 #include "kde_glue_agg.h"
35 #include "Renderer_agg.h"
36 #include "GnashException.h"
41 KdeAggGlue::KdeAggGlue()
49 KdeAggGlue::~KdeAggGlue()
54 KdeAggGlue::init(int /* argc */, char *** /* argv */)
56 // GNASH_REPORT_FUNCTION;
63 KdeAggGlue::prepDrawingArea(QWidget
*drawing_area
)
65 // GNASH_REPORT_FUNCTION;
66 _drawing_area
= drawing_area
;
71 KdeAggGlue::initBuffer(int width
, int height
)
73 if (!_renderer
) return;
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
,
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
));
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(),
120 bitBlt (_drawing_area
, dest_point
, &qpixmap
, src_rect
, Qt::CopyROP
,
121 true /* ignore mask */ );
126 KdeAggGlue::setInvalidatedRegions(const InvalidatedRanges
& ranges
)
128 _renderer
->set_invalidated_regions(ranges
);
132 for (size_t rno
=0; rno
<ranges
.size(); rno
++) {
134 geometry::Range2d
<int> bounds
= Intersection(
135 _renderer
->world_to_pixel(ranges
.getRange(rno
)),
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
);
151 KdeAggGlue::createRenderHandler()
153 // QT requires the use of this pixel format...
154 _renderer
= create_Renderer_agg("BGRA32");
156 throw GnashException(_("Could not create AGG renderer with pixelformat BGRA32"));
162 KdeAggGlue::resize(int width
, int height
)
164 initBuffer(width
, height
);
167 // end of namespace gnash