blob: e3de17d0b5eff9972f971001589b59d025624661 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +00002 * Copyright (C) 2004-2005 Constantin Kaplinsky. All Rights Reserved.
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 *
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 Kaplinskyd31fd312005-09-08 19:29:02 +000027#include <X11/Xutil.h>
28
29//
30// Image class is an Xlib-based implementation of screen image storage.
31//
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000032
33class Image {
34
35public:
36
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000037 Image(Display *d);
38 Image(Display *d, int width, int height);
39 virtual ~Image();
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000040
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000041 bool isTrueColor() { return trueColor; }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000042
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000043 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
Constantin Kaplinskyce676c62006-02-08 13:36:58 +000046// Copying pixels from one image to another.
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000047 virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyce676c62006-02-08 13:36:58 +000048 virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0);
49 virtual void updateRect(XImage *src, int dst_x, int dst_y, int w, int h);
50 virtual void updateRect(Image *src, int dst_x, int dst_y, int w, int h);
51 virtual void updateRect(XImage *src, int dst_x, int dst_y,
52 int src_x, int src_y, int w, int h);
53 virtual void updateRect(Image *src, int dst_x, int dst_y,
54 int src_x, int src_y, int w, int h);
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000055
56 // Pointer to corresponding XImage, made public for efficiency.
57 // NOTE: if this field is NULL, then no methods other than Init()
58 // may be called.
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000059 XImage* xim;
60
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000061protected:
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000062
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000063 void Init(int width, int height);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000064
Constantin Kaplinskyce676c62006-02-08 13:36:58 +000065 // Like updateRect(), but does not check arguments.
66 void copyPixels(XImage *src,
67 int dst_x, int dst_y,
68 int src_x, int src_y,
69 int w, int h);
70
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000071 Display *dpy;
72 bool trueColor;
73
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000074};
75
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000076//
77// ShmImage uses MIT-SHM extension of an X server to get image data.
78//
79
80#ifdef HAVE_MITSHM
81
82#include <X11/extensions/XShm.h>
83
84class ShmImage : public Image {
85
86public:
87
88 ShmImage(Display *d);
89 ShmImage(Display *d, int width, int height);
90 virtual ~ShmImage();
91
92 virtual void get(Window wnd, int x = 0, int y = 0);
93 virtual void get(Window wnd, int x, int y, int w, int h);
94
95protected:
96
97 void Init(int width, int height, const XVisualInfo *vinfo = NULL);
98
99 XShmSegmentInfo *shminfo;
100
101};
102
103//
104// IrixOverlayShmImage uses ReadDisplay extension of an X server to
105// get truecolor image data, regardless of the default X visual type.
106// This method is available on Irix only.
107//
108
109#ifdef HAVE_READDISPLAY
110
111#include <X11/extensions/readdisplay.h>
112
113class IrixOverlayShmImage : public ShmImage {
114
115public:
116
117 IrixOverlayShmImage(Display *d);
118 IrixOverlayShmImage(Display *d, int width, int height);
119 virtual ~IrixOverlayShmImage();
120
121 virtual void get(Window wnd, int x = 0, int y = 0);
122 virtual void get(Window wnd, int x, int y, int w, int h);
123
124protected:
125
126 void Init(int width, int height);
127
128 // This method searches available X visuals for one that matches
129 // actual pixel format returned by XReadDisplay(). Returns true on
130 // success, false if there is no matching visual. On success, visual
131 // information is placed into the structure pointed by vinfo_ret.
132 bool getOverlayVisualInfo(XVisualInfo *vinfo_ret);
133
134 ShmReadDisplayBuf *readDisplayBuf;
135
136};
137
138#endif // HAVE_READDISPLAY
139#endif // HAVE_MITSHM
140
141//
142// SolarisOverlayImage uses SUN_OVL extension of an X server to get
143// truecolor image data, regardless of the default X visual type. This
144// method is available on Solaris only.
145//
146
147#ifdef HAVE_SUN_OVL
148
149#include <X11/extensions/transovl.h>
150
151class SolarisOverlayImage : public Image {
152
153public:
154
155 SolarisOverlayImage(Display *d);
156 SolarisOverlayImage(Display *d, int width, int height);
157 virtual ~SolarisOverlayImage();
158
159 virtual void get(Window wnd, int x = 0, int y = 0);
160 virtual void get(Window wnd, int x, int y, int w, int h);
161
162protected:
163
164 void Init(int width, int height);
165
166};
167
168#endif // HAVE_SUN_OVL
169
170//
171// ImageFactory class is used to produce instances of Image-derived
172// objects that are most appropriate for current X server and user
173// settings.
174//
175
176class ImageFactory {
177
178public:
179
180 ImageFactory(bool allowShm, bool allowOverlay);
181 virtual ~ImageFactory();
182
183 bool isShmAllowed() { return mayUseShm; }
184 bool isOverlayAllowed() { return mayUseOverlay; }
185
186 virtual Image *newImage(Display *d, int width, int height);
187
188protected:
189
190 bool mayUseShm;
191 bool mayUseOverlay;
192
193};
194
195#endif // __IMAGE_H__