blob: 43c0b0b5f52ae9324c6ae8c65e2752f46f6462f3 [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.
67 XImage* xim;
68
69protected:
70
71 void Init(int width, int height);
72
73 // Like updateRect(), but does not check arguments.
74 void copyPixels(XImage *src,
75 int dst_x, int dst_y,
76 int src_x, int src_y,
77 int w, int h);
78
79 Display *dpy;
80 bool trueColor;
81
82};
83
84//
85// ShmImage uses MIT-SHM extension of an X server to get image data.
86//
87
88#ifdef HAVE_MITSHM
89
90#include <X11/extensions/XShm.h>
91
92class ShmImage : public Image {
93
94public:
95
96 ShmImage(Display *d);
97 ShmImage(Display *d, int width, int height);
98 virtual ~ShmImage();
99
100 virtual const char *className() const {
101 return "ShmImage";
102 }
103 virtual const char *classDesc() const {
104 return "shared memory image";
105 }
106
107 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000108 virtual void get(Window wnd, int x, int y, int w, int h,
109 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000110
111protected:
112
113 void Init(int width, int height, const XVisualInfo *vinfo = NULL);
114
115 XShmSegmentInfo *shminfo;
116
117};
118
119//
120// IrixOverlayShmImage uses ReadDisplay extension of an X server to
121// get truecolor image data, regardless of the default X visual type.
122// This method is available on Irix only.
123//
124
125#ifdef HAVE_READDISPLAY
126
127#include <X11/extensions/readdisplay.h>
128
129class IrixOverlayShmImage : public ShmImage {
130
131public:
132
133 IrixOverlayShmImage(Display *d);
134 IrixOverlayShmImage(Display *d, int width, int height);
135 virtual ~IrixOverlayShmImage();
136
137 virtual const char *className() const {
138 return "IrixOverlayShmImage";
139 }
140 virtual const char *classDesc() const {
141 return "IRIX-specific SHM-aware overlay image";
142 }
143
144 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000145 virtual void get(Window wnd, int x, int y, int w, int h,
146 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000147
148protected:
149
150 void Init(int width, int height);
151
152 // This method searches available X visuals for one that matches
153 // actual pixel format returned by XReadDisplay(). Returns true on
154 // success, false if there is no matching visual. On success, visual
155 // information is placed into the structure pointed by vinfo_ret.
156 bool getOverlayVisualInfo(XVisualInfo *vinfo_ret);
157
158 ShmReadDisplayBuf *readDisplayBuf;
159
160};
161
162#endif // HAVE_READDISPLAY
163#endif // HAVE_MITSHM
164
165//
166// SolarisOverlayImage uses SUN_OVL extension of an X server to get
167// truecolor image data, regardless of the default X visual type. This
168// method is available on Solaris only.
169//
170
171#ifdef HAVE_SUN_OVL
172
173#include <X11/extensions/transovl.h>
174
175class SolarisOverlayImage : public Image {
176
177public:
178
179 SolarisOverlayImage(Display *d);
180 SolarisOverlayImage(Display *d, int width, int height);
181 virtual ~SolarisOverlayImage();
182
183 virtual const char *className() const {
184 return "SolarisOverlayImage";
185 }
186 virtual const char *classDesc() const {
187 return "Solaris-specific non-SHM overlay image";
188 }
189
190 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000191 virtual void get(Window wnd, int x, int y, int w, int h,
192 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000193
194protected:
195
196 void Init(int width, int height);
197
198};
199
200#endif // HAVE_SUN_OVL
201
202//
203// ImageFactory class is used to produce instances of Image-derived
204// objects that are most appropriate for current X server and user
205// settings.
206//
207
208class ImageFactory {
209
210public:
211
212 ImageFactory(bool allowShm, bool allowOverlay);
213 virtual ~ImageFactory();
214
215 bool isShmAllowed() { return mayUseShm; }
216 bool isOverlayAllowed() { return mayUseOverlay; }
217
218 virtual Image *newImage(Display *d, int width, int height);
219
220protected:
221
222 bool mayUseShm;
223 bool mayUseOverlay;
224
225};
226
227#endif // __IMAGE_H__