update copyright date
[gnash.git] / libdevice / x11 / X11Device.h
blob5f143df1541fc5e03be648216c300abfef42d95a
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
20 #ifndef __X11_DEVICE_H__
21 #define __X11_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>
30 #ifdef HAVE_X11_X_H
31 # include <X11/X.h>
32 # include <X11/Xlib.h>
33 # include <X11/Xutil.h>
34 #else
35 # error "This file needs X11"
36 #endif
38 #include "GnashDevice.h"
40 namespace gnash {
42 namespace renderer {
44 namespace x11 {
46 class X11Device : public GnashDevice
48 public:
50 X11Device();
51 X11Device(int);
52 X11Device(int argc, char *argv[]);
54 // virtual classes should have virtual destructors
55 virtual ~X11Device();
57 dtype_t getType() { return X11; };
59 size_t getStride() { return 0; };
61 // Initialize X11 Device layer
62 bool initDevice(int argc, char *argv[]);
64 // Initialize X11 Window layer
65 bool attachWindow(GnashDevice::native_window_t window);
67 // Utility methods not in the base class
69 // Return a string with the error code as text, instead of a numeric value
70 const char *getErrorString(int error);
72 int getDepth() { return DefaultDepth(_display, _screennum); }
74 // Accessors for the settings needed by higher level code.
75 // Surface accessors
76 size_t getWidth() { if (_screen) { return XWidthOfScreen(_screen); } return 0; }
77 size_t getHeight() { if (_screen) { return XWidthOfScreen(_screen); } return 0; }
79 bool isSingleBuffered() { return true; }
81 bool supportsRenderer(GnashDevice::rtype_t /* rtype */) { return false; }
83 bool isBufferDestroyed() { return false; }
84 // bool isBufferDestroyed(IX11Surface surface) {
85 // return false;
86 // }
87 int getID() { return static_cast<int>(_window); }
89 // Get the size of the pixels, for X11 it's always 8 as far as I can tell
90 int getRedSize() { return (_vinfo) ? _vinfo[0].bits_per_rgb : 0; };
91 int getGreenSize() { return getRedSize(); };
92 int getBlueSize() { return getRedSize(); };
94 // Using X11 always means a native renderer
95 bool isNativeRender() { return true; }
97 int getHandle() { return _window; };
100 // Testing Support
103 // Create an X11 window to render in. This is only used by testing
104 void createWindow(const char *name, int x, int y, int width, int height);
106 /// Start an X11 event loop. This is only used by testing. Note that
107 /// calling this function blocks until the specified number of events
108 /// have been handled. The first 5 are used up by creating the window.
110 /// @param passes the number of events to process before returning.
111 /// @return nothing
112 void eventLoop(size_t passes);
114 protected:
115 Display *_display;
116 int _screennum;
117 Window _root;
118 Window _window;
119 Colormap _colormap;
120 Visual *_visual;
121 Screen *_screen;
122 int _depth;
123 XVisualInfo *_vinfo;
124 int _vid;
127 typedef void (*init_func)();
128 typedef void (*reshape_func)(int, int);
129 typedef void (*draw_func)();
130 typedef int (*key_func)(unsigned key);
132 } // namespace x11
133 } // namespace renderer
134 } // namespace gnash
136 #endif // end of __X11_DEVICE_H__
138 // local Variables:
139 // mode: C++
140 // indent-tabs-mode: nil
141 // End: