1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software 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
18
19
20 #ifdef HAVE_CONFIG_H
21 #include "gnashconfig.h"
22 #endif
23
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"
37
38 namespace gnash
39 {
40
KdeAggGlue()41 KdeAggGlue::KdeAggGlue()
42 :
43 _width(0),
44 _height(0),
45 _renderer(0)
46 {
47 }
48
~KdeAggGlue()49 KdeAggGlue::~KdeAggGlue()
50 {
51 }
52
53 bool
init(int,char ***)54 KdeAggGlue::init(int /* argc */, char *** /* argv */)
55 {
56 // GNASH_REPORT_FUNCTION;
57
58 return true;
59 }
60
61
62 void
prepDrawingArea(QWidget * drawing_area)63 KdeAggGlue::prepDrawingArea(QWidget *drawing_area)
64 {
65 // GNASH_REPORT_FUNCTION;
66 _drawing_area = drawing_area;
67 }
68
69
70 void
initBuffer(int width,int height)71 KdeAggGlue::initBuffer(int width, int height)
72 {
73 if (!_renderer) return;
74
75 int _bpp = 32;
76 int depth_bytes = _bpp / 8; // TODO: <Udo> is this correct? Gives 1 for 15 bit modes!
77
78 assert(_bpp % 8 == 0);
79
80 #define CHUNK_SIZE (100 * 100 * depth_bytes)
81
82 int bufsize = (width * height * depth_bytes / CHUNK_SIZE + 1) * CHUNK_SIZE;
83
84 _offscreenbuf.reset(new unsigned char[bufsize]);
85
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));
93
94 _width = width;
95 _height = height;
96
97 _validbounds.setTo(0, 0, _width, _height);
98 _drawbounds.push_back(_validbounds);
99
100 _qimage.reset(new QImage(_offscreenbuf.get(), _width, _height, 32 /* bits per pixel */,
101 0 , 0, QImage::IgnoreEndian));
102 }
103
104 void
render()105 KdeAggGlue::render()
106 {
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);
110
111 for (unsigned bno=0; bno < _drawbounds.size(); bno++) {
112 geometry::Range2d<int>& bounds = _drawbounds[bno];
113
114 assert ( bounds.isFinite() );
115
116 QPoint dest_point(bounds.getMinX(), bounds.getMinY()) ;
117 QRect src_rect(bounds.getMinX(), bounds.getMinY(), bounds.width(),
118 bounds.height());
119
120 bitBlt (_drawing_area, dest_point, &qpixmap, src_rect, Qt::CopyROP,
121 true /* ignore mask */ );
122 }
123 }
124
125 void
setInvalidatedRegions(const InvalidatedRanges & ranges)126 KdeAggGlue::setInvalidatedRegions(const InvalidatedRanges& ranges)
127 {
128 _renderer->set_invalidated_regions(ranges);
129
130 _drawbounds.clear();
131
132 for (size_t rno=0; rno<ranges.size(); rno++) {
133
134 geometry::Range2d<int> bounds = Intersection(
135 _renderer->world_to_pixel(ranges.getRange(rno)),
136 _validbounds);
137
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;
141
142 assert(bounds.isFinite());
143
144 _drawbounds.push_back(bounds);
145
146 }
147 }
148
149
150 Renderer*
createRenderHandler()151 KdeAggGlue::createRenderHandler()
152 {
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"));
157 }
158 return _renderer;
159 }
160
161 void
resize(int width,int height)162 KdeAggGlue::resize(int width, int height)
163 {
164 initBuffer(width, height);
165 }
166
167 // end of namespace gnash
168 }
169