blob: 675b1fa6f9a6fad8fb89bafd5feb586ea44ab51c [file] [log] [blame]
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
2 * Copyright (C) 2004-2005 Constantin Kaplinsky. All Rights Reserved.
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>
27#include <X11/Xutil.h>
28
29//
30// Image class is an Xlib-based implementation of screen image storage.
31//
32
33class Image {
34
35public:
36
37 Image(Display *d);
38 Image(Display *d, int width, int height);
39 virtual ~Image();
40
41 bool isTrueColor() const { return trueColor; }
42
43 virtual const char *className() const {
44 return "Image";
45 }
46 virtual const char *classDesc() const {
47 return "basic Xlib image";
48 }
49
50 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +000051 virtual void get(Window wnd, int x, int y, int w, int h,
52 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000053
Constantin Kaplinskycffb6912007-09-03 10:17:19 +000054 // Copying pixels from one image to another.
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000055 virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0);
56 virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0);
57 virtual void updateRect(XImage *src, int dst_x, int dst_y, int w, int h);
58 virtual void updateRect(Image *src, int dst_x, int dst_y, int w, int h);
59 virtual void updateRect(XImage *src, int dst_x, int dst_y,
60 int src_x, int src_y, int w, int h);
61 virtual void updateRect(Image *src, int dst_x, int dst_y,
62 int src_x, int src_y, int w, int h);
63
64 // Pointer to corresponding XImage, made public for efficiency.
65 // NOTE: if this field is NULL, then no methods other than Init()
66 // may be called.
Constantin Kaplinsky801123d2008-01-18 15:23:11 +000067 XImage *xim;
68
69 // Get a pointer to the data corresponding to the given coordinates.
70 inline char *locatePixel(int x, int y) const {
71 return (xim->data +
72 y * xim->bytes_per_line +
73 x * (xim->bits_per_pixel / 8));
74 }
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000075
76protected:
77
78 void Init(int width, int height);
79
80 // Like updateRect(), but does not check arguments.
81 void copyPixels(XImage *src,
82 int dst_x, int dst_y,
83 int src_x, int src_y,
84 int w, int h);
85
86 Display *dpy;
87 bool trueColor;
88
89};
90
91//
92// ShmImage uses MIT-SHM extension of an X server to get image data.
93//
94
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000095#include <X11/extensions/XShm.h>
96
97class ShmImage : public Image {
98
99public:
100
101 ShmImage(Display *d);
102 ShmImage(Display *d, int width, int height);
103 virtual ~ShmImage();
104
105 virtual const char *className() const {
106 return "ShmImage";
107 }
108 virtual const char *classDesc() const {
109 return "shared memory image";
110 }
111
112 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000113 virtual void get(Window wnd, int x, int y, int w, int h,
114 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000115
116protected:
117
118 void Init(int width, int height, const XVisualInfo *vinfo = NULL);
119
120 XShmSegmentInfo *shminfo;
121
122};
123
124//
125// IrixOverlayShmImage uses ReadDisplay extension of an X server to
126// get truecolor image data, regardless of the default X visual type.
127// This method is available on Irix only.
128//
129
130#ifdef HAVE_READDISPLAY
131
132#include <X11/extensions/readdisplay.h>
133
134class IrixOverlayShmImage : public ShmImage {
135
136public:
137
138 IrixOverlayShmImage(Display *d);
139 IrixOverlayShmImage(Display *d, int width, int height);
140 virtual ~IrixOverlayShmImage();
141
142 virtual const char *className() const {
143 return "IrixOverlayShmImage";
144 }
145 virtual const char *classDesc() const {
146 return "IRIX-specific SHM-aware overlay image";
147 }
148
149 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000150 virtual void get(Window wnd, int x, int y, int w, int h,
151 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000152
153protected:
154
155 void Init(int width, int height);
156
157 // This method searches available X visuals for one that matches
158 // actual pixel format returned by XReadDisplay(). Returns true on
159 // success, false if there is no matching visual. On success, visual
160 // information is placed into the structure pointed by vinfo_ret.
161 bool getOverlayVisualInfo(XVisualInfo *vinfo_ret);
162
163 ShmReadDisplayBuf *readDisplayBuf;
164
165};
166
167#endif // HAVE_READDISPLAY
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000168
169//
170// SolarisOverlayImage uses SUN_OVL extension of an X server to get
171// truecolor image data, regardless of the default X visual type. This
172// method is available on Solaris only.
173//
174
175#ifdef HAVE_SUN_OVL
176
177#include <X11/extensions/transovl.h>
178
179class SolarisOverlayImage : public Image {
180
181public:
182
183 SolarisOverlayImage(Display *d);
184 SolarisOverlayImage(Display *d, int width, int height);
185 virtual ~SolarisOverlayImage();
186
187 virtual const char *className() const {
188 return "SolarisOverlayImage";
189 }
190 virtual const char *classDesc() const {
191 return "Solaris-specific non-SHM overlay image";
192 }
193
194 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000195 virtual void get(Window wnd, int x, int y, int w, int h,
196 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000197
198protected:
199
200 void Init(int width, int height);
201
202};
203
204#endif // HAVE_SUN_OVL
205
206//
207// ImageFactory class is used to produce instances of Image-derived
208// objects that are most appropriate for current X server and user
209// settings.
210//
211
212class ImageFactory {
213
214public:
215
216 ImageFactory(bool allowShm, bool allowOverlay);
217 virtual ~ImageFactory();
218
219 bool isShmAllowed() { return mayUseShm; }
220 bool isOverlayAllowed() { return mayUseOverlay; }
221
222 virtual Image *newImage(Display *d, int width, int height);
223
224protected:
225
226 bool mayUseShm;
227 bool mayUseOverlay;
228
229};
230
231#endif // __IMAGE_H__