add comments about swapBuffers() beyhaviour
[gnash.git] / libdevice / rawfb / test_rawfb.cpp
blob513a09cb8ec63421b6e08a918dc4869ee2f5d043
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 <iostream>
24 #include <string>
25 #include <cstdlib>
26 #include <vector>
27 #include <map>
28 #include <cassert>
29 #include <regex.h>
30 #include <boost/assign/list_of.hpp>
32 #include "log.h"
33 #include "dejagnu.h"
34 #include "GnashDevice.h"
35 #include "RawFBDevice.h"
37 TestState runtest;
39 using namespace gnash;
40 using namespace std;
41 using namespace renderer;
43 // The debug log used by all the gnash libraries.
44 static LogFile& dbglogfile = LogFile::getDefaultInstance();
47 unsigned short red[256], green[256], blue[256];
48 struct fb_cmap map332 = {0, 256, red, green, blue, NULL};
49 unsigned short red_b[256], green_b[256], blue_b[256];
50 struct fb_cmap map_back = {0, 256, red_b, green_b, blue_b, NULL};
52 int
53 main(int argc, char *argv[])
55 // FIXME: for now, always run verbose till this supports command line args
56 dbglogfile.setVerbosity();
58 rawfb::RawFBDevice rfb;
60 if (!rfb.initDevice(argc, argv)) {
61 runtest.fail("RawFBDevice:InitDevice()");
62 } else {
63 runtest.pass("RawFBDevice:InitDevice()");
66 bool ret = rfb.attachWindow(rfb.getHandle());
67 if (rfb.getFBMemory()) {
68 runtest.pass("RawFBDevice::attachWindow()");
69 } else {
70 runtest.fail("RawFBDevice::attachWindow()");
73 #ifdef ENABLE_DOUBLE_BUFFERING
74 if (rfb.getOffscreenBuffer()) {
75 runtest.pass("RawFBDevice::getOffscreenBuffer()");
76 } else {
77 runtest.fail("RawFBDevice::getOffscreenBuffer()");
79 #endif
81 if (ret && rfb.getStride()) {
82 runtest.pass("RawFBDevice::getStride()");
83 } else {
84 runtest.fail("RawFBDevice::getStride()");
87 if (ret && rfb.getWidth()) {
88 runtest.pass("RawFBDevice::getWidth()");
89 } else {
90 runtest.fail("RawFBDevice::getWidth()");
93 if (ret && rfb.getHeight()) {
94 runtest.pass("RawFBDevice::getHeight()");
95 } else {
96 runtest.fail("DirecTFBDevice::getHeight()");
99 if (ret && rfb.isSingleBuffered()) {
100 runtest.pass("RawFBDevice::is*Buffered()");
101 } else {
102 runtest.fail("RawFBDevice::is*Buffered()");
105 if (ret && rfb.getDepth()) {
106 runtest.pass("RawFBDevice::getDepth()");
107 } else {
108 runtest.fail("RawFBDevice::getDepth()");
111 if (ret && rfb.getRedSize() > 0) {
112 runtest.pass("RawFBDevice::getRedSize()");
113 } else {
114 runtest.fail("RawFBDevice::getRedSize()");
117 if (ret && rfb.getGreenSize() > 0) {
118 runtest.pass("RawFBDevice::getGreenSize()");
119 } else {
120 runtest.fail("RawFBDevice::getGreenSize()");
123 if (ret && rfb.getBlueSize() > 0) {
124 runtest.pass("RawFBDevice::getBlueSize()");
125 } else {
126 runtest.fail("RawFBDevice::getBlueSize()");
129 #if 0
130 if (rfb.setGrayscaleLUT8()) {
131 runtest.pass("RawFBDevice::setGrayscaleLUT8()");
132 } else {
133 runtest.fail("RawFBDevice::setGrayscaleLUT8()");
135 #endif
137 // AGG uses these to calculate the poixel format
138 #ifdef RENDERER_AGG
139 if (ret && rfb.getRedOffset() > 0) {
140 runtest.pass("RawFBDevice::getRedOffset()");
141 } else {
142 runtest.fail("RawFBDevice::getRedOffset()");
145 if (ret && rfb.getGreenOffset() > 0) {
146 runtest.pass("RawFBDevice::getGreenOffset()");
147 } else {
148 runtest.fail("RawFBDevice::getGreenOffset()");
151 if (ret && rfb.getBlueOffset() == 0) {
152 runtest.pass("RawFBDevice::getBlueOffset()");
153 } else {
154 runtest.fail("RawFBDevice::getBlueOffset()");
156 #endif
158 // This is a manual test to see if we can draw a line on the
159 // raw framebuffer to make sure it got initialized correctly.
160 int x = 0, y = 0;
161 long location = 0;
162 int line_length = rfb.getWidth() * ((rfb.getDepth()+7)/8);
164 boost::uint8_t *fbp = rfb.getFBMemory();
166 for(y=100; y<102; y++); /* Where we are going to put the pixel */
168 for(x=0; x<200; x++) {
169 /* Figure out where in memory to put the pixel */
170 location = x * (rfb.getDepth()/8) + y * line_length;
172 *(fbp + location) = 89; /* Some blue */
173 *(fbp + location + 1) = 40; /* A little green */
174 *(fbp + location + 2) = 200; /* A lot of red */
175 *(fbp + location + 3) = 0; /* No transparency */
180 // Local Variables:
181 // mode: C++
182 // indent-tabs-mode: nil
183 // End: