Gnash  0.8.10
X11Device.h
Go to the documentation of this file.
00001 //
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 //
00019 
00020 #ifndef __X11_DEVICE_H__
00021 #define __X11_DEVICE_H__ 1
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "gnashconfig.h"
00025 #endif
00026 
00027 #include <boost/scoped_array.hpp>
00028 #include <boost/scoped_ptr.hpp>
00029 
00030 #ifdef HAVE_X11_X_H
00031 # include <X11/X.h>
00032 # include <X11/Xlib.h>
00033 # include <X11/Xutil.h>
00034 #else
00035 # error "This file needs X11"
00036 #endif
00037 
00038 #include "GnashDevice.h"
00039 
00040 namespace gnash {
00041 
00042 namespace renderer {
00043 
00044 namespace x11 {
00045 
00046 class X11Device : public GnashDevice
00047 {
00048   public:
00049     
00050     X11Device();
00051     X11Device(int);
00052     X11Device(int argc, char *argv[]);
00053     
00054     // virtual classes should have virtual destructors
00055     virtual ~X11Device();
00056 
00057     dtype_t getType() { return X11; };
00058 
00059     size_t getStride() { return 0; };
00060     
00061     // Initialize X11 Device layer
00062     bool initDevice(int argc, char *argv[]);
00063 
00064     // Initialize X11 Window layer
00065     bool attachWindow(GnashDevice::native_window_t window);
00066     
00067     // Utility methods not in the base class
00068 
00069     // Return a string with the error code as text, instead of a numeric value
00070     const char *getErrorString(int error);
00071     
00072     int getDepth() { return DefaultDepth(_display, _screennum); }
00073 
00074     // Accessors for the settings needed by higher level code.
00075     // Surface accessors
00076     size_t getWidth()  { if (_screen) { return XWidthOfScreen(_screen); } return 0; }
00077     size_t getHeight() { if (_screen) { return XWidthOfScreen(_screen); } return 0; }
00078     
00079     bool isSingleBuffered() { return true; }
00080     
00081     bool supportsRenderer(GnashDevice::rtype_t /* rtype */) { return false; }
00082     
00083     bool isBufferDestroyed() { return false; }
00084     // bool isBufferDestroyed(IX11Surface surface) {
00085     //     return false;
00086     // }
00087     int getID() { return static_cast<int>(_window); }
00088 
00089     // Get the size of the pixels, for X11 it's always 8 as far as I can tell
00090     int getRedSize() { return (_vinfo) ? _vinfo[0].bits_per_rgb : 0; };
00091     int getGreenSize() { return getRedSize(); };
00092     int getBlueSize() { return getRedSize(); };
00093     
00094     // Using X11 always means a native renderer
00095     bool isNativeRender() { return true; }
00096 
00097     int getHandle() { return _window; };
00098     
00099     //
00100     // Testing Support
00101     //
00102     
00103     // Create an X11 window to render in. This is only used by testing
00104     void createWindow(const char *name, int x, int y, int width, int height);
00105 
00112     void eventLoop(size_t passes);
00113 
00114 protected:
00115     Display    *_display;
00116     int         _screennum;
00117     Window      _root;
00118     Window      _window;
00119     Colormap    _colormap;
00120     Visual     *_visual;
00121     Screen     *_screen;
00122     int         _depth;
00123     XVisualInfo *_vinfo;
00124     int         _vid;
00125 };
00126 
00127 typedef void (*init_func)();
00128 typedef void (*reshape_func)(int, int);
00129 typedef void (*draw_func)();
00130 typedef int  (*key_func)(unsigned key);
00131 
00132 } // namespace x11
00133 } // namespace renderer
00134 } // namespace gnash
00135 
00136 #endif  // end of __X11_DEVICE_H__
00137 
00138 // local Variables:
00139 // mode: C++
00140 // indent-tabs-mode: nil
00141 // End: