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