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