Gnash  0.8.11dev
RawFBDevice.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // 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
18 //
19 
20 #ifndef __RAWFB_DEVICE_H__
21 #define __RAWFB_DEVICE_H__ 1
22 
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
26 
27 #include <boost/scoped_array.hpp>
28 #include <boost/scoped_ptr.hpp>
29 #include <fcntl.h>
30 #include <sys/ioctl.h>
31 #include <sys/mman.h>
32 #include <linux/fb.h>
33 #include <linux/kd.h>
34 #include <linux/vt.h>
35 
36 #include "GnashDevice.h"
37 
38 namespace gnash {
39 
40 namespace renderer {
41 
42 namespace rawfb {
43 
44 #define CMAP_SIZE (256*2)
45 
47 {
48  public:
49 
50  RawFBDevice();
51  RawFBDevice(int);
52  RawFBDevice(int argc, char *argv[]);
53 
54  // virtual classes should have virtual destructors
55  virtual ~RawFBDevice();
56 
57  dtype_t getType() { return RAWFB; };
58 
59  // Initialize RAWFB Device layer
60  bool initDevice(int argc, char *argv[]);
61 
62  // Initialize RAWFB Window layer
63  bool attachWindow(GnashDevice::native_window_t window);
64 
65  // Utility methods not in the base class
66 
67  // Return a string with the error code as text, instead of a numeric value
68  const char *getErrorString(int error);
69 
70  int getDepth() { return _varinfo.bits_per_pixel; };
71 
72  // Accessors for the settings needed by higher level code.
73  // Surface accessors
74  size_t getWidth() { return _varinfo.xres; };
75  size_t getHeight() { return _varinfo.yres; };
76 
77  bool supportsRenderer(GnashDevice::rtype_t /* rtype */) { return false; }
78 
79  bool isBufferDestroyed() { return false; }
80  // bool isBufferDestroyed(IRAWFBSurface surface) {
81  // return false;
82  // }
83  int getID() { return 0; };
84 
85  // Get the size of the pixels
86  int getRedSize() { return _varinfo.red.length; };
87  int getGreenSize() { return _varinfo.green.length; };
88  int getBlueSize() { return _varinfo.blue.length; };
89 
90 #ifdef RENDERER_AGG
91  int getRedOffset() { return _varinfo.red.offset; };
94  int getGreenOffset() { return _varinfo.green.offset; };
95  int getBlueOffset() { return _varinfo.blue.offset; };
96 #endif
97 
98  // Using RAWFB always means a native renderer
99  bool isNativeRender() { return true; }
100 
102 
103  //
104  // Testing Support
105  //
106 
107  // Create an RAWFB window to render in. This is only used by testing
108  void createWindow(const char *name, int x, int y, int width, int height);
109 
110  // Get the memory from the real framebuffer
111  boost::uint8_t *getFBMemory() { return _fbmem; };
112 
113  // // Get the memory from an offscreen buffer to support Double Buffering
114  boost::uint8_t *getOffscreenBuffer() { return _offscreen_buffer.get(); };
115 
116  size_t getStride() { return _fixinfo.line_length; };
117  size_t getFBMemSize() { return _fixinfo.smem_len; };
118  int getHandle() { return _fd; };
119 
126  void eventLoop(size_t passes);
127 
130  bool setGrayscaleLUT8();
131 
133 #ifdef ENABLE_DOUBLE_BUFFERING
134  return false;
135 #else
136  return true;
137 #endif
138  }
139 
140  bool swapBuffers();
141 
142  void dump();
143 protected:
145  void clear();
146 
147  int _fd;
148  std::string _filespec;
149  struct fb_fix_screeninfo _fixinfo;
150  struct fb_var_screeninfo _varinfo;
151  boost::uint8_t *_fbmem;
152 
153  boost::scoped_ptr<boost::uint8_t> _offscreen_buffer;
154  struct fb_cmap _cmap; // the colormap
155 };
156 
157 #ifdef ENABLE_FAKE_FRAMEBUFFER
158 int fakefb_ioctl(int fd, int request, void *data);
162 #endif
163 
164 typedef void (*init_func)();
165 typedef void (*reshape_func)(int, int);
166 typedef void (*draw_func)();
167 typedef int (*key_func)(unsigned key);
168 
169 } // namespace rawFB
170 } // namespace renderer
171 } // namespace gnash
172 
173 #endif // end of __RAWFB_DEVICE_H__
174 
175 // local Variables:
176 // mode: C++
177 // indent-tabs-mode: nil
178 // End:
void(* draw_func)()
Definition: RawFBDevice.h:166
native_window_t getDrawableWindow()
Definition: RawFBDevice.h:101
bool isBufferDestroyed()
Are buffers destroyed ?
Definition: RawFBDevice.h:79
bool isSingleBuffered()
Is this device single buffered.
Definition: RawFBDevice.h:132
int getRedSize()
Get the size of the Red pixel.
Definition: RawFBDevice.h:86
bool supportsRenderer(GnashDevice::rtype_t)
Is the specified renderer supported by this hardware ?
Definition: RawFBDevice.h:77
void clear()
Clean up the font library.
Definition: fontlib.cpp:36
long native_window_t
Definition: GnashDevice.h:43
Definition: GnashDevice.h:39
SimpleBuffer data
Definition: LocalConnection_as.cpp:153
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
dtype_t
The list of supported device types.
Definition: GnashDevice.h:48
int getDepth()
Get the depth of the device.
Definition: RawFBDevice.h:70
int(* key_func)(unsigned key)
Definition: RawFBDevice.h:167
boost::uint8_t * _fbmem
Definition: RawFBDevice.h:151
Definition: klash_part.cpp:329
size_t getWidth()
Get the width of the device.
Definition: RawFBDevice.h:74
int getGreenSize()
Get the size of the Green pixel.
Definition: RawFBDevice.h:87
void(* init_func)()
Definition: RawFBDevice.h:164
int getBlueSize()
Get the size of the Blue pixel.
Definition: RawFBDevice.h:88
size_t getHeight()
Get the Height of the device.
Definition: RawFBDevice.h:75
bool isNativeRender()
Is this renderering natively.
Definition: RawFBDevice.h:99
boost::uint8_t * getOffscreenBuffer()
Get the memory from an offscreen buffer to support Double Buffering.
Definition: RawFBDevice.h:114
Definition: klash_part.cpp:329
size_t getStride()
Query the system for all supported configs.
Definition: RawFBDevice.h:116
rtype_t
The list of supported renders that use devices.
Definition: GnashDevice.h:46
boost::uint8_t * getFBMemory()
Get the memory from the real framebuffer.
Definition: RawFBDevice.h:111
dtype_t getType()
Definition: RawFBDevice.h:57
size_t getFBMemSize()
Definition: RawFBDevice.h:117
boost::int32_t x
Definition: BitmapData_as.cpp:434
#define DSOEXPORT
Definition: dsodefs.h:55
void(* reshape_func)(int, int)
Definition: RawFBDevice.h:165
int getHandle()
Definition: RawFBDevice.h:118
boost::int32_t y
Definition: BitmapData_as.cpp:435
int _fd
Definition: RawFBDevice.h:147
int getID()
Get the window ID handle.
Definition: RawFBDevice.h:83
Definition: RawFBDevice.h:46
std::string name
Definition: LocalConnection_as.cpp:151
std::string _filespec
Definition: RawFBDevice.h:148
boost::scoped_ptr< boost::uint8_t > _offscreen_buffer
Definition: RawFBDevice.h:153