2 // Copyright (C) 2010 Free Software Foundation, Inc
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.
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
20 #include "gnashconfig.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>
40 #include "SWFMatrix.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"
49 # ifdef BUILD_RAWFB_DEVICE
50 # include "fb/fb_glue_agg.h"
52 # ifdef BUILD_X11_DEVICE
53 # include "gtk/gtk_glue_agg.h"
56 #ifdef RENDERER_OPENVG
57 # include "fb/fb_glue_ovg.h"
61 # include "fb/fb_glue_gles1.h"
64 # include "fb/fb_glue_gles2.h"
66 #ifdef RENDERER_OPENGL
67 # ifdef BUILD_X11_DEVICE
68 # include "gtk/gtk_glue_gtkglext.h"
72 # include "gtk/gtk_glue_cairo.h"
78 using namespace gnash
;
79 using namespace renderer
;
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
94 Timer(const std::string
&name
, bool flag
)
100 Timer(const std::string
&name
) : _print(false) { _name
= name
; start(); }
101 Timer() : _print(false) { start(); }
106 cerr
<< "Total time for " << _name
<< " was: " << elapsed() << endl
;
111 _starttime
= boost::posix_time::microsec_clock::local_time();
115 _stoptime
= boost::posix_time::microsec_clock::local_time();
118 std::string
elapsed() {
120 time_duration td
= _stoptime
- _starttime
;
121 ss
<< td
.total_nanoseconds() << "ns elapsed";
124 void setName(const std::string
&name
) { _name
= name
; };
125 std::string
&getName() { return _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
142 struct fb_var_screeninfo varinfo
;
143 memset(&varinfo
, 0, sizeof(struct fb_var_screeninfo
));
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
= {
161 0, // replaced later by drawing_area
162 5242880, // the memory size
170 524288, // the framebuffer memory size
174 test_render("FB", "OpenVG");
178 test_render(const std::string
&gui
, const std::string
&render
)
180 cout
<< "*** Testing the glue layer for " << gui
181 << " and " << render
<< "*** " << endl
;
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.
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)");
196 runtest
.fail("FBOvgGlue::width(0)");
199 if (fbvg
.height() == 0) {
200 runtest
.pass("FBOvgGlue::height(0)");
202 runtest
.fail("FBOvgGlue::height(0)");
205 Renderer
*renderer
= fbvg
.createRenderHandler();
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
213 fbvg
.setInvalidatedRegion(bounds
);
214 if (fbvg
.getBounds() == 0) {
215 runtest
.pass("FBOvgGlue::setInvalidatedRegion(0)");
217 runtest
.fail("FBOvgGlue::setInvalidatedRegion(0)");
221 InvalidatedRanges ranges
;
222 fbvg
.setInvalidatedRegions(ranges
);
223 if (fbvg
.getBounds() == 0) {
224 runtest
.pass("FBOvgGlue::setInvalidatedRegions(0)");
226 runtest
.fail("FBOvgGlue::setInvalidatedRegions(0)");
230 fbvg
.prepDrawingArea(reinterpret_cast<void *>(fixinfo
.smem_start
));
231 if (fbvg
.getBounds() == 0) {
232 runtest
.pass("FBOvgGlue::setInvalidatedRegions(0)");
234 runtest
.fail("FBOvgGlue::setInvalidatedRegions(0)");
238 // This initlizes the device and glue
239 if (fbvg
.init(0, 0)) {
240 runtest
.pass("FBOvgGlue::init()");
242 runtest
.fail("FBOvgGlue::init()");
245 if (fbvg
.width() > 0) {
246 runtest
.pass("FBOvgGlue::width()");
248 runtest
.fail("FBOvgGlue::width()");
251 if (fbvg
.height() > 0) {
252 runtest
.pass("FBOvgGlue::height()");
254 runtest
.fail("FBOvgGlue::height()");
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;
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;
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;
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
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
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
328 std::string str
= FAKEFB
;
329 if (str
== "/tmp/fbe_buffer") {
330 int fd
= open("/tmp/fbe_cmap", O_WRONLY
);
332 write(fd
, data
, sizeof(struct fb_cmap
));
335 gnash::log_error("Couldn't write to the fake cmap!");
339 gnash::log_error("Couldn't write to the fake cmap, unknown type!");
342 // If we send a SIGUSR1 signal to fbe, it'll reload the
344 int fd
= open("/tmp/fbe.pid", O_RDONLY
);
347 if (read(fd
, buf
, 10) == 0) {
351 pid_t pid
= strtol(buf
, 0, NULL
);
353 gnash::log_debug("Signaled fbe to reload it's colormap.");
360 gnash::log_unimpl("fakefb_ioctl(%d)", request
);
366 #endif // ENABLE_FAKE_FRAMEBUFFER
370 // indent-tabs-mode: nil