Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved. |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 2 | * Copyright (C) 2004-2005 Constantin Kaplinsky. All Rights Reserved. |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 3 | * |
| 4 | * This is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This software is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this software; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 17 | * USA. |
| 18 | */ |
| 19 | // |
| 20 | // Image.h |
| 21 | // |
| 22 | |
| 23 | #ifndef __IMAGE_H__ |
| 24 | #define __IMAGE_H__ |
| 25 | |
| 26 | #include <X11/Xlib.h> |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 27 | #include <X11/Xutil.h> |
| 28 | |
| 29 | // |
| 30 | // Image class is an Xlib-based implementation of screen image storage. |
| 31 | // |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 32 | |
| 33 | class Image { |
| 34 | |
| 35 | public: |
| 36 | |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 37 | Image(Display *d); |
| 38 | Image(Display *d, int width, int height); |
| 39 | virtual ~Image(); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 40 | |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 41 | bool isTrueColor() { return trueColor; } |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 42 | |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 43 | virtual void get(Window wnd, int x = 0, int y = 0); |
| 44 | virtual void get(Window wnd, int x, int y, int w, int h); |
| 45 | |
| 46 | virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0); |
| 47 | virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0); |
| 48 | |
| 49 | // Pointer to corresponding XImage, made public for efficiency. |
| 50 | // NOTE: if this field is NULL, then no methods other than Init() |
| 51 | // may be called. |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 52 | XImage* xim; |
| 53 | |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 54 | protected: |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 55 | |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 56 | void Init(int width, int height); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 57 | |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 58 | Display *dpy; |
| 59 | bool trueColor; |
| 60 | |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Constantin Kaplinsky | d31fd31 | 2005-09-08 19:29:02 +0000 | [diff] [blame^] | 63 | // |
| 64 | // ShmImage uses MIT-SHM extension of an X server to get image data. |
| 65 | // |
| 66 | |
| 67 | #ifdef HAVE_MITSHM |
| 68 | |
| 69 | #include <X11/extensions/XShm.h> |
| 70 | |
| 71 | class ShmImage : public Image { |
| 72 | |
| 73 | public: |
| 74 | |
| 75 | ShmImage(Display *d); |
| 76 | ShmImage(Display *d, int width, int height); |
| 77 | virtual ~ShmImage(); |
| 78 | |
| 79 | virtual void get(Window wnd, int x = 0, int y = 0); |
| 80 | virtual void get(Window wnd, int x, int y, int w, int h); |
| 81 | |
| 82 | protected: |
| 83 | |
| 84 | void Init(int width, int height, const XVisualInfo *vinfo = NULL); |
| 85 | |
| 86 | XShmSegmentInfo *shminfo; |
| 87 | |
| 88 | }; |
| 89 | |
| 90 | // |
| 91 | // IrixOverlayShmImage uses ReadDisplay extension of an X server to |
| 92 | // get truecolor image data, regardless of the default X visual type. |
| 93 | // This method is available on Irix only. |
| 94 | // |
| 95 | |
| 96 | #ifdef HAVE_READDISPLAY |
| 97 | |
| 98 | #include <X11/extensions/readdisplay.h> |
| 99 | |
| 100 | class IrixOverlayShmImage : public ShmImage { |
| 101 | |
| 102 | public: |
| 103 | |
| 104 | IrixOverlayShmImage(Display *d); |
| 105 | IrixOverlayShmImage(Display *d, int width, int height); |
| 106 | virtual ~IrixOverlayShmImage(); |
| 107 | |
| 108 | virtual void get(Window wnd, int x = 0, int y = 0); |
| 109 | virtual void get(Window wnd, int x, int y, int w, int h); |
| 110 | |
| 111 | protected: |
| 112 | |
| 113 | void Init(int width, int height); |
| 114 | |
| 115 | // This method searches available X visuals for one that matches |
| 116 | // actual pixel format returned by XReadDisplay(). Returns true on |
| 117 | // success, false if there is no matching visual. On success, visual |
| 118 | // information is placed into the structure pointed by vinfo_ret. |
| 119 | bool getOverlayVisualInfo(XVisualInfo *vinfo_ret); |
| 120 | |
| 121 | ShmReadDisplayBuf *readDisplayBuf; |
| 122 | |
| 123 | }; |
| 124 | |
| 125 | #endif // HAVE_READDISPLAY |
| 126 | #endif // HAVE_MITSHM |
| 127 | |
| 128 | // |
| 129 | // SolarisOverlayImage uses SUN_OVL extension of an X server to get |
| 130 | // truecolor image data, regardless of the default X visual type. This |
| 131 | // method is available on Solaris only. |
| 132 | // |
| 133 | |
| 134 | #ifdef HAVE_SUN_OVL |
| 135 | |
| 136 | #include <X11/extensions/transovl.h> |
| 137 | |
| 138 | class SolarisOverlayImage : public Image { |
| 139 | |
| 140 | public: |
| 141 | |
| 142 | SolarisOverlayImage(Display *d); |
| 143 | SolarisOverlayImage(Display *d, int width, int height); |
| 144 | virtual ~SolarisOverlayImage(); |
| 145 | |
| 146 | virtual void get(Window wnd, int x = 0, int y = 0); |
| 147 | virtual void get(Window wnd, int x, int y, int w, int h); |
| 148 | |
| 149 | protected: |
| 150 | |
| 151 | void Init(int width, int height); |
| 152 | |
| 153 | }; |
| 154 | |
| 155 | #endif // HAVE_SUN_OVL |
| 156 | |
| 157 | // |
| 158 | // ImageFactory class is used to produce instances of Image-derived |
| 159 | // objects that are most appropriate for current X server and user |
| 160 | // settings. |
| 161 | // |
| 162 | |
| 163 | class ImageFactory { |
| 164 | |
| 165 | public: |
| 166 | |
| 167 | ImageFactory(bool allowShm, bool allowOverlay); |
| 168 | virtual ~ImageFactory(); |
| 169 | |
| 170 | bool isShmAllowed() { return mayUseShm; } |
| 171 | bool isOverlayAllowed() { return mayUseOverlay; } |
| 172 | |
| 173 | virtual Image *newImage(Display *d, int width, int height); |
| 174 | |
| 175 | protected: |
| 176 | |
| 177 | bool mayUseShm; |
| 178 | bool mayUseOverlay; |
| 179 | |
| 180 | }; |
| 181 | |
| 182 | #endif // __IMAGE_H__ |