Update with current status
[gnash.git] / gui / qt / Qt4GlueAgg.cpp
blob54ecddf2a0661d333428e770fce43e993f202649
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
20 #ifdef HAVE_CONFIG_H
21 #include "gnashconfig.h"
22 #endif
24 #include "Qt4GlueAgg.h"
25 #include "Renderer.h"
26 #include "Renderer_agg.h"
27 #include "GnashException.h"
28 #include <QWidget>
29 #include <QImage>
30 #include <QRect>
32 namespace gnash
35 Qt4AggGlue::Qt4AggGlue()
37 _width(0),
38 _height(0),
39 _renderer(nullptr)
43 Qt4AggGlue::~Qt4AggGlue()
47 bool
48 Qt4AggGlue::init(int /* argc */, char *** /* argv */)
50 return true;
54 void
55 Qt4AggGlue::prepDrawingArea(DrawingWidget *drawing_area)
57 _drawing_area = drawing_area;
61 void
62 Qt4AggGlue::initBuffer(int width, int height)
64 if (!_renderer) return;
66 _width = width;
67 _height = height;
69 int _bpp = 32;
70 int depth_bytes = _bpp / 8;
72 assert(_bpp % 8 == 0);
74 #define CHUNK_SIZE (100 * 100 * depth_bytes)
76 int bufsize = (width * height * depth_bytes / CHUNK_SIZE + 1) * CHUNK_SIZE;
78 _offscreenbuf.reset(new unsigned char[bufsize]);
80 Renderer_agg_base * renderer =
81 static_cast<Renderer_agg_base *>(_renderer);
83 renderer->init_buffer(_offscreenbuf.get(), bufsize, _width, _height,
84 width*((_bpp+7)/8));
86 _image.reset(new QImage(_offscreenbuf.get(), _width, _height, QImage::Format_RGB32));
90 void
91 Qt4AggGlue::render()
93 QRect r(0, 0, _width, _height);
94 render(r);
98 void
99 Qt4AggGlue::render(const QRect& updateRect)
101 QPainter p(_drawing_area);
103 p.drawImage(updateRect, *_image, updateRect);
104 p.end();
108 Renderer*
109 Qt4AggGlue::createRenderHandler()
111 _renderer = create_Renderer_agg("BGRA32");
113 if ( ! _renderer )
115 throw GnashException(_("Could not create AGG renderer with pixelformat ABGR32"));
117 return _renderer;
120 void
121 Qt4AggGlue::resize(int width, int height)
123 initBuffer(width, height);
126 // end of namespace gnash