blob: 032e24a8200c8f9db7ee6bda51a89de80b89d21c [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
46 virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0);
47 virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0);
48
49 // Pointer to corresponding XImage, made public for efficiency.
50 // NOTE: if this field is NULL, then no methods other than Init()
51 // may be called.
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000052 XImage* xim;
53
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000054protected:
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000055
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000056 void Init(int width, int height);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000057
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000058 Display *dpy;
59 bool trueColor;
60
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000061};
62
Constantin Kaplinskyd31fd312005-09-08 19:29:02 +000063//
64// ShmImage uses MIT-SHM extension of an X server to get image data.
65//
66
67#ifdef HAVE_MITSHM
68
69#include <X11/extensions/XShm.h>
70
71class ShmImage : public Image {
72
73public:
74
75 ShmImage(Display *d);
76 ShmImage(Display *d, int width, int height);
77 virtual ~ShmImage();
78
79 virtual void get(Window wnd, int x = 0, int y = 0);
80 virtual void get(Window wnd, int x, int y, int w, int h);
81
82protected:
83
84 void Init(int width, int height, const XVisualInfo *vinfo = NULL);
85
86 XShmSegmentInfo *shminfo;
87
88};
89
90//
91// IrixOverlayShmImage uses ReadDisplay extension of an X server to
92// get truecolor image data, regardless of the default X visual type.
93// This method is available on Irix only.
94//
95
96#ifdef HAVE_READDISPLAY
97
98#include <X11/extensions/readdisplay.h>
99
100class IrixOverlayShmImage : public ShmImage {
101
102public:
103
104 IrixOverlayShmImage(Display *d);
105 IrixOverlayShmImage(Display *d, int width, int height);
106 virtual ~IrixOverlayShmImage();
107
108 virtual void get(Window wnd, int x = 0, int y = 0);
109 virtual void get(Window wnd, int x, int y, int w, int h);
110
111protected:
112
113 void Init(int width, int height);
114
115 // This method searches available X visuals for one that matches
116 // actual pixel format returned by XReadDisplay(). Returns true on
117 // success, false if there is no matching visual. On success, visual
118 // information is placed into the structure pointed by vinfo_ret.
119 bool getOverlayVisualInfo(XVisualInfo *vinfo_ret);
120
121 ShmReadDisplayBuf *readDisplayBuf;
122
123};
124
125#endif // HAVE_READDISPLAY
126#endif // HAVE_MITSHM
127
128//
129// SolarisOverlayImage uses SUN_OVL extension of an X server to get
130// truecolor image data, regardless of the default X visual type. This
131// method is available on Solaris only.
132//
133
134#ifdef HAVE_SUN_OVL
135
136#include <X11/extensions/transovl.h>
137
138class SolarisOverlayImage : public Image {
139
140public:
141
142 SolarisOverlayImage(Display *d);
143 SolarisOverlayImage(Display *d, int width, int height);
144 virtual ~SolarisOverlayImage();
145
146 virtual void get(Window wnd, int x = 0, int y = 0);
147 virtual void get(Window wnd, int x, int y, int w, int h);
148
149protected:
150
151 void Init(int width, int height);
152
153};
154
155#endif // HAVE_SUN_OVL
156
157//
158// ImageFactory class is used to produce instances of Image-derived
159// objects that are most appropriate for current X server and user
160// settings.
161//
162
163class ImageFactory {
164
165public:
166
167 ImageFactory(bool allowShm, bool allowOverlay);
168 virtual ~ImageFactory();
169
170 bool isShmAllowed() { return mayUseShm; }
171 bool isOverlayAllowed() { return mayUseOverlay; }
172
173 virtual Image *newImage(Display *d, int width, int height);
174
175protected:
176
177 bool mayUseShm;
178 bool mayUseOverlay;
179
180};
181
182#endif // __IMAGE_H__