1 //
2 //   Copyright (C) 2010, 2011, 2012 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.
13 //
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
17 //
18 
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
22 
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>
31 
32 #include "log.h"
33 #include "dejagnu.h"
34 #include "GnashDevice.h"
35 #include "RawFBDevice.h"
36 
37 TestState runtest;
38 
39 using namespace gnash;
40 using namespace std;
41 using namespace renderer;
42 
43 // The debug log used by all the gnash libraries.
44 static LogFile& dbglogfile = LogFile::getDefaultInstance();
45 
46 
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};
51 
52 int
main(int argc,char * argv[])53 main(int argc, char *argv[])
54 {
55     // FIXME: for now, always run verbose till this supports command line args
56     dbglogfile.setVerbosity();
57 
58     rawfb::RawFBDevice rfb;
59 
60     if (!rfb.initDevice(argc, argv)) {
61         runtest.fail("RawFBDevice:InitDevice()");
62     } else {
63         runtest.pass("RawFBDevice:InitDevice()");
64     }
65 
66     bool ret = rfb.attachWindow(rfb.getHandle());
67     if (rfb.getFBMemory()) {
68         runtest.pass("RawFBDevice::attachWindow()");
69     } else {
70         runtest.fail("RawFBDevice::attachWindow()");
71     }
72 
73 #ifdef ENABLE_DOUBLE_BUFFERING
74     if (rfb.getOffscreenBuffer()) {
75         runtest.pass("RawFBDevice::getOffscreenBuffer()");
76     } else {
77         runtest.fail("RawFBDevice::getOffscreenBuffer()");
78     }
79 #else
80     runtest.untested("RawFBDevice::getOffscreenBuffer()");
81 #endif
82 
83     if (ret && rfb.getStride()) {
84         runtest.pass("RawFBDevice::getStride()");
85     } else {
86         runtest.fail("RawFBDevice::getStride()");
87     }
88 
89     if (ret && rfb.getWidth()) {
90         runtest.pass("RawFBDevice::getWidth()");
91     } else {
92         runtest.fail("RawFBDevice::getWidth()");
93     }
94 
95     if (ret && rfb.getHeight()) {
96         runtest.pass("RawFBDevice::getHeight()");
97     } else {
98         runtest.fail("DirecTFBDevice::getHeight()");
99     }
100 
101     if (ret && rfb.isSingleBuffered()) {
102         runtest.pass("RawFBDevice::is*Buffered()");
103     } else {
104         runtest.fail("RawFBDevice::is*Buffered()");
105     }
106 
107     if (ret && rfb.getDepth()) {
108         runtest.pass("RawFBDevice::getDepth()");
109     } else {
110         runtest.fail("RawFBDevice::getDepth()");
111     }
112 
113     if (ret && rfb.getRedSize() > 0) {
114         runtest.pass("RawFBDevice::getRedSize()");
115     } else {
116         runtest.fail("RawFBDevice::getRedSize()");
117     }
118 
119     if (ret && rfb.getGreenSize() > 0) {
120         runtest.pass("RawFBDevice::getGreenSize()");
121     } else {
122         runtest.fail("RawFBDevice::getGreenSize()");
123     }
124 
125     if (ret && rfb.getBlueSize() > 0) {
126         runtest.pass("RawFBDevice::getBlueSize()");
127     } else {
128         runtest.fail("RawFBDevice::getBlueSize()");
129     }
130 
131 #if 0
132     if (rfb.setGrayscaleLUT8()) {
133         runtest.pass("RawFBDevice::setGrayscaleLUT8()");
134     } else {
135         runtest.fail("RawFBDevice::setGrayscaleLUT8()");
136     }
137 #endif
138 
139     // AGG uses these to calculate the poixel format
140 #ifdef RENDERER_AGG
141     if (ret && rfb.getRedOffset() > 0) {
142         runtest.pass("RawFBDevice::getRedOffset()");
143     } else {
144         runtest.fail("RawFBDevice::getRedOffset()");
145     }
146 
147     if (ret && rfb.getGreenOffset() > 0) {
148         runtest.pass("RawFBDevice::getGreenOffset()");
149     } else {
150         runtest.fail("RawFBDevice::getGreenOffset()");
151     }
152 
153     if (ret && rfb.getBlueOffset() == 0) {
154         runtest.pass("RawFBDevice::getBlueOffset()");
155     } else {
156         runtest.fail("RawFBDevice::getBlueOffset()");
157     }
158 #endif
159 
160     // This is a manual test to see if we can draw a line on the
161     // raw framebuffer to make sure it got initialized correctly.
162     int x = 0, y = 0;
163     long location = 0;
164     int line_length = rfb.getStride();
165 
166     std::uint8_t *fbp = 0;
167     fbp = rfb.getFBMemory();
168 
169     if (fbp > 0) {
170         runtest.pass("RawFBDevice::getFBMemory()");
171     } else {
172         runtest.fail("RawFBDevice::getFBMemory()");
173         exit;
174     }
175 
176     for(y=100; y<102; y++);            /* Where we are going to put the pixel */
177 
178     for(x=0; x<200; x++) {
179         /* Figure out where in memory to put the pixel */
180         location = x * (rfb.getDepth()/8) + y * line_length;
181 
182         *(fbp + location) = 89;    /* Some blue */
183         *(fbp + location + 1) = 40; /* A little green */
184         *(fbp + location + 2) = 200; /* A lot of red */
185         *(fbp + location + 3) = 0; /* No transparency */
186     }
187     return 0;
188 }
189 
190 // Local Variables:
191 // mode: C++
192 // indent-tabs-mode: nil
193 // End:
194