add accessors for framebuffer and ofscreen buffer
[gnash.git] / libdevice / rawfb / RawFBDevice.h
blobfb24839f1a86b9707dddb5bc05c09ca67d054cfa
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // 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
20 #ifndef __RAWFB_DEVICE_H__
21 #define __RAWFB_DEVICE_H__ 1
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
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>
36 #include "GnashDevice.h"
38 namespace gnash {
40 namespace renderer {
42 namespace rawfb {
44 #define CMAP_SIZE (256*2)
46 class RawFBDevice : public GnashDevice
48 public:
50 RawFBDevice();
51 RawFBDevice(int);
52 RawFBDevice(int argc, char *argv[]);
54 // virtual classes should have virtual destructors
55 virtual ~RawFBDevice();
57 dtype_t getType() { return RAWFB; };
59 // Initialize RAWFB Device layer
60 bool initDevice(int argc, char *argv[]);
62 // Initialize RAWFB Window layer
63 bool attachWindow(GnashDevice::native_window_t window);
65 // Utility methods not in the base class
67 // Return a string with the error code as text, instead of a numeric value
68 const char *getErrorString(int error);
70 int getDepth() { return _varinfo.bits_per_pixel; };
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; };
77 bool isSingleBuffered() { return true; }
79 bool supportsRenderer(GnashDevice::rtype_t /* rtype */) { return false; }
81 bool isBufferDestroyed() { return false; }
82 // bool isBufferDestroyed(IRAWFBSurface surface) {
83 // return false;
84 // }
85 int getID() { return 0; };
87 // Get the size of the pixels
88 int getRedSize() { return _varinfo.red.length; };
89 int getGreenSize() { return _varinfo.green.length; };
90 int getBlueSize() { return _varinfo.blue.length; };
92 #ifdef RENDERER_AGG
93 /// These methods are only needed by AGG, which uses these
94 /// to calculate the pixel format.
95 int getRedOffset() { return _varinfo.red.offset; };
96 int getGreenOffset() { return _varinfo.green.offset; };
97 int getBlueOffset() { return _varinfo.blue.offset; };
98 #endif
100 // Using RAWFB always means a native renderer
101 bool isNativeRender() { return true; }
103 native_window_t getDrawableWindow() { return 0; };
106 // Testing Support
109 // Create an RAWFB window to render in. This is only used by testing
110 void createWindow(const char *name, int x, int y, int width, int height);
112 // Get the memory from the real framebuffer
113 boost::uint8_t *getFBMemory() { return _fbmem.get(); };
115 // Get the memory from an offscreen buffer to support Double Buffering
116 boost::uint8_t *getOffscreenBuffer() { return _offscreen_buffer.get(); };
118 size_t getFBMemSize() { return _fixinfo.smem_len; };
119 int getHandle() { return _fd; };
121 /// Start an RAWFB event loop. This is only used by testing. Note that
122 /// calling this function blocks until the specified number of events
123 /// have been handled. The first 5 are used up by creating the window.
125 /// @param passes the number of events to process before returning.
126 /// @return nothing
127 void eventLoop(size_t passes);
129 /// For 8 bit (palette / LUT) modes, sets a grayscale palette.
130 /// This GUI currently does not support palette modes.
131 bool setGrayscaleLUT8();
133 protected:
134 /// Clear the framebuffer memory
135 void clear();
137 int _fd;
138 std::string _filespec;
139 struct fb_fix_screeninfo _fixinfo;
140 struct fb_var_screeninfo _varinfo;
141 boost::scoped_ptr<boost::uint8_t> _fbmem;
143 boost::scoped_ptr<boost::uint8_t> _offscreen_buffer;
144 struct fb_cmap _cmap; // the colormap
147 #ifdef ENABLE_FAKE_FRAMEBUFFER
148 /// Simulate the ioctls used to get information from the framebuffer driver.
150 /// Since this is an emulator, we have to set these fields to a reasonable default.
151 int fakefb_ioctl(int fd, int request, void *data);
152 #endif
154 typedef void (*init_func)();
155 typedef void (*reshape_func)(int, int);
156 typedef void (*draw_func)();
157 typedef int (*key_func)(unsigned key);
159 } // namespace rawFB
160 } // namespace renderer
161 } // namespace gnash
163 #endif // end of __RAWFB_DEVICE_H__
165 // local Variables:
166 // mode: C++
167 // indent-tabs-mode: nil
168 // End: