Gnash  0.8.11dev
X11Device.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 __X11_DEVICE_H__
21 #define __X11_DEVICE_H__ 1
22 
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
26 
27 #include <memory>
28 
29 #ifdef HAVE_X11_X_H
30 # include <X11/X.h>
31 # include <X11/Xlib.h>
32 # include <X11/Xutil.h>
33 #else
34 # error "This file needs X11"
35 #endif
36 
37 #include "GnashDevice.h"
38 
39 namespace gnash {
40 
41 namespace renderer {
42 
43 namespace x11 {
44 
45 class X11Device : public GnashDevice
46 {
47  public:
48 
49  X11Device();
50  X11Device(int);
51  X11Device(int argc, char *argv[]);
52 
53  // virtual classes should have virtual destructors
54  virtual ~X11Device();
55 
56  dtype_t getType() { return X11; };
57 
58  size_t getStride() { return 0; };
59 
60  // Initialize X11 Device layer
61  bool initDevice(int argc, char *argv[]);
62 
63  // Initialize X11 Window layer
65 
66  // Utility methods not in the base class
67 
68  // Return a string with the error code as text, instead of a numeric value
69  const char *getErrorString(int error);
70 
71  int getDepth() { return DefaultDepth(_display, _screennum); }
72 
73  // Accessors for the settings needed by higher level code.
74  // Surface accessors
75  size_t getWidth() { if (_screen) { return XWidthOfScreen(_screen); } return 0; }
76  size_t getHeight() { if (_screen) { return XWidthOfScreen(_screen); } return 0; }
77 
78  bool isSingleBuffered() { return true; }
79 
80  bool supportsRenderer(GnashDevice::rtype_t /* rtype */) { return false; }
81 
82  bool isBufferDestroyed() { return false; }
83  // bool isBufferDestroyed(IX11Surface surface) {
84  // return false;
85  // }
86  int getID() { return static_cast<int>(_window); }
87 
88  // Get the size of the pixels, for X11 it's always 8 as far as I can tell
89  int getRedSize() { return (_vinfo) ? _vinfo[0].bits_per_rgb : 0; };
90  int getGreenSize() { return getRedSize(); };
91  int getBlueSize() { return getRedSize(); };
92 
93  // Using X11 always means a native renderer
94  bool isNativeRender() { return true; }
95 
96  int getHandle() { return _window; };
97 
98  //
99  // Testing Support
100  //
101 
102  // Create an X11 window to render in. This is only used by testing
103  void createWindow(const char *name, int x, int y, int width, int height);
104 
111  void eventLoop(size_t passes);
112 
113 protected:
114  Display *_display;
116  Window _root;
117  Window _window;
118  Colormap _colormap;
119  Visual *_visual;
120  Screen *_screen;
121  int _depth;
122  XVisualInfo *_vinfo;
123  int _vid;
124 };
125 
126 typedef void (*init_func)();
127 typedef void (*reshape_func)(int, int);
128 typedef void (*draw_func)();
129 typedef int (*key_func)(unsigned key);
130 
131 } // namespace x11
132 } // namespace renderer
133 } // namespace gnash
134 
135 #endif // end of __X11_DEVICE_H__
136 
137 // local Variables:
138 // mode: C++
139 // indent-tabs-mode: nil
140 // End:
int getRedSize()
Get the size of the Red pixel.
Definition: X11Device.h:89
int _screennum
Definition: X11Device.h:115
void(* reshape_func)(int, int)
Definition: X11Device.h:127
void createWindow(const char *name, int x, int y, int width, int height)
Definition: X11Device.cpp:207
int getDepth()
Get the depth of the device.
Definition: X11Device.h:71
Visual * _visual
Definition: X11Device.h:119
Window _root
Definition: X11Device.h:116
size_t getHeight()
Get the Height of the device.
Definition: X11Device.h:76
bool initDevice(int argc, char *argv[])
Definition: X11Device.cpp:126
long native_window_t
Definition: GnashDevice.h:43
Display * _display
Definition: X11Device.h:114
Definition: GnashDevice.h:48
Definition: GnashDevice.h:39
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
void(* init_func)()
Definition: X11Device.h:126
int getID()
Get the window ID handle.
Definition: X11Device.h:86
int _depth
Definition: X11Device.h:121
Definition: klash_part.cpp:329
int getBlueSize()
Get the size of the Blue pixel.
Definition: X11Device.h:91
Definition: X11Device.h:45
XVisualInfo * _vinfo
Definition: X11Device.h:122
int _vid
Definition: X11Device.h:123
const char * getErrorString(int error)
Return a string with the error code as text, instead of a numeric value.
Definition: X11Device.cpp:192
virtual ~X11Device()
Definition: X11Device.cpp:110
Definition: klash_part.cpp:329
size_t getStride()
Query the system for all supported configs.
Definition: X11Device.h:58
rtype_t
The list of supported renders that use devices.
Definition: GnashDevice.h:46
void eventLoop(size_t passes)
Definition: X11Device.cpp:253
Window _window
Definition: X11Device.h:117
int getGreenSize()
Get the size of the Green pixel.
Definition: X11Device.h:90
std::int32_t x
Definition: BitmapData_as.cpp:434
bool supportsRenderer(GnashDevice::rtype_t)
Is the specified renderer supported by this hardware ?
Definition: X11Device.h:80
bool isSingleBuffered()
Is this device single buffered.
Definition: X11Device.h:78
int getHandle()
Definition: X11Device.h:96
Screen * _screen
Definition: X11Device.h:120
Colormap _colormap
Definition: X11Device.h:118
std::int32_t y
Definition: BitmapData_as.cpp:435
bool attachWindow(GnashDevice::native_window_t window)
Definition: X11Device.cpp:180
dtype_t getType()
Definition: X11Device.h:56
void(* draw_func)()
Definition: X11Device.h:128
size_t getWidth()
Get the width of the device.
Definition: X11Device.h:75
bool isBufferDestroyed()
Are buffers destroyed ?
Definition: X11Device.h:82
int(* key_func)(unsigned key)
Definition: X11Device.h:129
bool isNativeRender()
Is this renderering natively.
Definition: X11Device.h:94
std::string name
Definition: LocalConnection_as.cpp:149
X11Device()
Definition: X11Device.cpp:59