blob: 4cac8b417d7991261ac9f913ac24a0bb48e9a61a [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
95#ifdef HAVE_MITSHM
96
97#include <X11/extensions/XShm.h>
98
99class ShmImage : public Image {
100
101public:
102
103 ShmImage(Display *d);
104 ShmImage(Display *d, int width, int height);
105 virtual ~ShmImage();
106
107 virtual const char *className() const {
108 return "ShmImage";
109 }
110 virtual const char *classDesc() const {
111 return "shared memory image";
112 }
113
114 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000115 virtual void get(Window wnd, int x, int y, int w, int h,
116 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000117
118protected:
119
120 void Init(int width, int height, const XVisualInfo *vinfo = NULL);
121
122 XShmSegmentInfo *shminfo;
123
124};
125
126//
127// IrixOverlayShmImage uses ReadDisplay extension of an X server to
128// get truecolor image data, regardless of the default X visual type.
129// This method is available on Irix only.
130//
131
132#ifdef HAVE_READDISPLAY
133
134#include <X11/extensions/readdisplay.h>
135
136class IrixOverlayShmImage : public ShmImage {
137
138public:
139
140 IrixOverlayShmImage(Display *d);
141 IrixOverlayShmImage(Display *d, int width, int height);
142 virtual ~IrixOverlayShmImage();
143
144 virtual const char *className() const {
145 return "IrixOverlayShmImage";
146 }
147 virtual const char *classDesc() const {
148 return "IRIX-specific SHM-aware overlay image";
149 }
150
151 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000152 virtual void get(Window wnd, int x, int y, int w, int h,
153 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000154
155protected:
156
157 void Init(int width, int height);
158
159 // This method searches available X visuals for one that matches
160 // actual pixel format returned by XReadDisplay(). Returns true on
161 // success, false if there is no matching visual. On success, visual
162 // information is placed into the structure pointed by vinfo_ret.
163 bool getOverlayVisualInfo(XVisualInfo *vinfo_ret);
164
165 ShmReadDisplayBuf *readDisplayBuf;
166
167};
168
169#endif // HAVE_READDISPLAY
170#endif // HAVE_MITSHM
171
172//
173// SolarisOverlayImage uses SUN_OVL extension of an X server to get
174// truecolor image data, regardless of the default X visual type. This
175// method is available on Solaris only.
176//
177
178#ifdef HAVE_SUN_OVL
179
180#include <X11/extensions/transovl.h>
181
182class SolarisOverlayImage : public Image {
183
184public:
185
186 SolarisOverlayImage(Display *d);
187 SolarisOverlayImage(Display *d, int width, int height);
188 virtual ~SolarisOverlayImage();
189
190 virtual const char *className() const {
191 return "SolarisOverlayImage";
192 }
193 virtual const char *classDesc() const {
194 return "Solaris-specific non-SHM overlay image";
195 }
196
197 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000198 virtual void get(Window wnd, int x, int y, int w, int h,
199 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000200
201protected:
202
203 void Init(int width, int height);
204
205};
206
207#endif // HAVE_SUN_OVL
208
209//
210// ImageFactory class is used to produce instances of Image-derived
211// objects that are most appropriate for current X server and user
212// settings.
213//
214
215class ImageFactory {
216
217public:
218
219 ImageFactory(bool allowShm, bool allowOverlay);
220 virtual ~ImageFactory();
221
222 bool isShmAllowed() { return mayUseShm; }
223 bool isOverlayAllowed() { return mayUseOverlay; }
224
225 virtual Image *newImage(Display *d, int width, int height);
226
227protected:
228
229 bool mayUseShm;
230 bool mayUseOverlay;
231
232};
233
234#endif // __IMAGE_H__