enable docbook, don't gzip man pages
[gnash.git] / gui / test_glue.cpp
blob759cd9c4d150809e9cb6a0c26e85904050b7eea9
1 //
2 // Copyright (C) 2010 Free Software Foundation, Inc
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
23 #include <fcntl.h>
24 #include <iostream>
25 #include <string>
26 #include <cstdlib>
27 #include <vector>
28 #include <sstream>
29 #include <map>
30 #include <signal.h>
31 #include <unistd.h>
32 #include <cassert>
33 #include <regex.h>
34 #include <boost/assign/list_of.hpp>
35 #include <boost/date_time/date.hpp>
36 #include <boost/date_time/posix_time/posix_time.hpp>
38 #include "log.h"
39 #include "dejagnu.h"
40 #include "SWFMatrix.h"
41 #include "Renderer.h"
42 #include "Transform.h"
43 #include "CachedBitmap.h"
44 #include "GnashVaapiImage.h"
45 #include "GnashVaapiImageProxy.h"
46 #include "boost/date_time/posix_time/posix_time.hpp"
48 #ifdef RENDERER_AGG
49 # ifdef BUILD_RAWFB_DEVICE
50 # include "fb/fb_glue_agg.h"
51 # endif
52 # ifdef BUILD_X11_DEVICE
53 # include "gtk/gtk_glue_agg.h"
54 # endif
55 #endif
56 #ifdef RENDERER_OPENVG
57 # include "fb/fb_glue_ovg.h"
58 #endif
59 #if 0
60 #ifdef RENDERER_GLES1
61 # include "fb/fb_glue_gles1.h"
62 #endif
63 #ifdef RENDERER_GLES2
64 # include "fb/fb_glue_gles2.h"
65 #endif
66 #ifdef RENDERER_OPENGL
67 # ifdef BUILD_X11_DEVICE
68 # include "gtk/gtk_glue_gtkglext.h"
69 # endif
70 #endif
71 #ifdef RENDERER_CAIRO
72 # include "gtk/gtk_glue_cairo.h"
73 #endif
74 #endif
76 TestState runtest;
78 using namespace gnash;
79 using namespace renderer;
80 using namespace gui;
81 using namespace std;
82 using namespace boost::posix_time;
84 static void test_render(const std::string &gui, const std::string &render);
86 // The debug log used by all the gnash libraries.
87 static LogFile& dbglogfile = LogFile::getDefaultInstance();
89 //------------------------------------------------------------
91 // Simple class to do nanosecond based timing for performance analysis
92 class Timer {
93 public:
94 Timer(const std::string &name, bool flag)
96 _print = flag;
97 _name = name;
98 start();
100 Timer(const std::string &name) : _print(false) { _name = name; start(); }
101 Timer() : _print(false) { start(); }
102 ~Timer()
104 stop();
105 if (_print) {
106 cerr << "Total time for " << _name << " was: " << elapsed() << endl;
110 void start() {
111 _starttime = boost::posix_time::microsec_clock::local_time();
114 void stop() {
115 _stoptime = boost::posix_time::microsec_clock::local_time();
118 std::string elapsed() {
119 stringstream ss;
120 time_duration td = _stoptime - _starttime;
121 ss << td.total_nanoseconds() << "ns elapsed";
122 return ss.str();
124 void setName(const std::string &name) { _name = name; };
125 std::string &getName() { return _name; };
127 private:
128 bool _print;
129 std::string _name;
130 boost::posix_time::ptime _starttime;
131 boost::posix_time::ptime _stoptime;
135 main(int argc, char *argv[])
137 // FIXME: for now, always run verbose till this supports command line args
138 dbglogfile.setVerbosity();
140 // Create fake data for the fake framebuffer, This was copied off a
141 // working PC.
142 struct fb_var_screeninfo varinfo;
143 memset(&varinfo, 0, sizeof(struct fb_var_screeninfo));
144 varinfo.xres = 1200;
145 varinfo.yres = 1024;
146 varinfo.xres_virtual = 1280;
147 varinfo.yres_virtual = 1024;
148 varinfo.bits_per_pixel = 32;
149 varinfo.red.offset = 16;
150 varinfo.red.length = 8;
151 varinfo.green.offset = 8;
152 varinfo.green.length = 8;
153 varinfo.blue.offset = 0;
154 varinfo.blue.length = 8;
155 varinfo.width = 4294967295;
156 varinfo.height = 4294967295;
158 size_t memsize = 5242880;
159 struct fb_fix_screeninfo fixinfo = {
160 "test_glue",
161 0, // replaced later by drawing_area
162 5242880, // the memory size
167 1, 0,
168 5120, // the rowsize
169 4289200128,
170 524288, // the framebuffer memory size
172 {0, 0, 0}};
174 test_render("FB", "OpenVG");
177 static void
178 test_render(const std::string &gui, const std::string &render)
180 cout << "*** Testing the glue layer for " << gui
181 << " and " << render << "*** " << endl;
183 FBOvgGlue fbvg(0);
185 // if ((gui == "FB") && (render = "OpenVG")) {
186 // // We're not testing the virtual terminals here, so we just pass 0 as
187 // // the file descriptor.
188 // glue = FBAggGlue;
189 // }
191 // Test the defaults. These need to properly handle an unitialized
192 // Glue without segfaulting.
193 if (fbvg.width() == 0) {
194 runtest.pass("FBOvgGlue::width(0)");
195 } else {
196 runtest.fail("FBOvgGlue::width(0)");
199 if (fbvg.height() == 0) {
200 runtest.pass("FBOvgGlue::height(0)");
201 } else {
202 runtest.fail("FBOvgGlue::height(0)");
205 Renderer *renderer = fbvg.createRenderHandler();
207 #if 0
208 // FIXME: this appears to be AGG specific
209 // These next two will display an error, because the glue isn't
210 // set but we know that, we want to test if nothiung crashes when
211 // unitilized.
212 SWFRect bounds;
213 fbvg.setInvalidatedRegion(bounds);
214 if (fbvg.getBounds() == 0) {
215 runtest.pass("FBOvgGlue::setInvalidatedRegion(0)");
216 } else {
217 runtest.fail("FBOvgGlue::setInvalidatedRegion(0)");
219 #endif
221 InvalidatedRanges ranges;
222 fbvg.setInvalidatedRegions(ranges);
223 if (fbvg.getBounds() == 0) {
224 runtest.pass("FBOvgGlue::setInvalidatedRegions(0)");
225 } else {
226 runtest.fail("FBOvgGlue::setInvalidatedRegions(0)");
229 #if 0
230 fbvg.prepDrawingArea(reinterpret_cast<void *>(fixinfo.smem_start));
231 if (fbvg.getBounds() == 0) {
232 runtest.pass("FBOvgGlue::setInvalidatedRegions(0)");
233 } else {
234 runtest.fail("FBOvgGlue::setInvalidatedRegions(0)");
236 #endif
238 // This initlizes the device and glue
239 if (fbvg.init(0, 0)) {
240 runtest.pass("FBOvgGlue::init()");
241 } else {
242 runtest.fail("FBOvgGlue::init()");
245 if (fbvg.width() > 0) {
246 runtest.pass("FBOvgGlue::width()");
247 } else {
248 runtest.fail("FBOvgGlue::width()");
251 if (fbvg.height() > 0) {
252 runtest.pass("FBOvgGlue::height()");
253 } else {
254 runtest.fail("FBOvgGlue::height()");
257 fbvg.render();
260 #ifdef ENABLE_FAKE_FRAMEBUFFER
261 // Simulate the ioctls used to get information from the framebuffer
262 // driver. Since this is an emulator, we have to set these fields
263 // to a reasonable default.
265 fakefb_ioctl(int /* fd */, int request, void *data)
267 // GNASH_REPORT_FUNCTION;
269 switch (request) {
270 case FBIOGET_VSCREENINFO:
272 struct fb_var_screeninfo *ptr =
273 reinterpret_cast<struct fb_var_screeninfo *>(data);
274 // If we are using a simulated framebuffer, the default for
275 // fbe us 640x480, 8bits. So use that as a sensible
276 // default. Note that the fake framebuffer is only used for
277 // debugging and development.
278 ptr->xres = 640; // visible resolution
279 ptr->xres_virtual = 640; // virtual resolution
280 ptr->yres = 480; // visible resolution
281 ptr->yres_virtual = 480; // virtual resolution
282 ptr->width = 640; // width of picture in mm
283 ptr->height = 480; // height of picture in mm
285 // Android and fbe use a 16bit 5/6/5 framebuffer
286 ptr->bits_per_pixel = 16;
287 ptr->red.length = 5;
288 ptr->red.offset = 11;
289 ptr->green.length = 6;
290 ptr->green.offset = 5;
291 ptr->blue.length = 5;
292 ptr->blue.offset = 0;
293 ptr->transp.offset = 0;
294 ptr->transp.length = 0;
295 // 8bit framebuffer
296 // ptr->bits_per_pixel = 8;
297 // ptr->red.length = 8;
298 // ptr->red.offset = 0;
299 // ptr->green.length = 8;
300 // ptr->green.offset = 0;
301 // ptr->blue.length = 8;
302 // ptr->blue.offset = 0;
303 // ptr->transp.offset = 0;
304 // ptr->transp.length = 0;
305 ptr->grayscale = 1; // != 0 Graylevels instead of color
307 break;
309 case FBIOGET_FSCREENINFO:
311 struct fb_fix_screeninfo *ptr =
312 reinterpret_cast<struct fb_fix_screeninfo *>(data);
313 ptr->smem_len = 307200; // Length of frame buffer mem
314 ptr->type = FB_TYPE_PACKED_PIXELS; // see FB_TYPE_*
315 ptr->visual = FB_VISUAL_PSEUDOCOLOR; // see FB_VISUAL_*
316 ptr->xpanstep = 0; // zero if no hardware panning
317 ptr->ypanstep = 0; // zero if no hardware panning
318 ptr->ywrapstep = 0; // zero if no hardware panning
319 ptr->accel = FB_ACCEL_NONE; // Indicate to driver which specific
320 // chip/card we have
321 break;
323 case FBIOPUTCMAP:
325 // Fbe uses this name for the fake framebuffer, so in this
326 // case assume we're using fbe, so write to the known fbe
327 // cmap file.
328 std::string str = FAKEFB;
329 if (str == "/tmp/fbe_buffer") {
330 int fd = open("/tmp/fbe_cmap", O_WRONLY);
331 if (fd) {
332 write(fd, data, sizeof(struct fb_cmap));
333 close(fd);
334 } else {
335 gnash::log_error("Couldn't write to the fake cmap!");
336 return -1;
338 } else {
339 gnash::log_error("Couldn't write to the fake cmap, unknown type!");
340 return -1;
342 // If we send a SIGUSR1 signal to fbe, it'll reload the
343 // color map.
344 int fd = open("/tmp/fbe.pid", O_RDONLY);
345 char buf[10];
346 if (fd) {
347 if (read(fd, buf, 10) == 0) {
348 close(fd);
349 return -1;
350 } else {
351 pid_t pid = strtol(buf, 0, NULL);
352 kill(pid, SIGUSR1);
353 gnash::log_debug("Signaled fbe to reload it's colormap.");
355 close(fd);
357 break;
359 default:
360 gnash::log_unimpl("fakefb_ioctl(%d)", request);
361 break;
364 return 0;
366 #endif // ENABLE_FAKE_FRAMEBUFFER
368 // Local Variables:
369 // mode: C++
370 // indent-tabs-mode: nil
371 // End: