blob: bf62e7d0b775307d32bb43c5931b299bec2dc126 [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
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000041 virtual const char *className() const {
42 return "Image";
43 }
44 virtual const char *classDesc() const {
45 return "basic Xlib image";
46 }
47
48 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +000049 virtual void get(Window wnd, int x, int y, int w, int h,
50 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000051
Constantin Kaplinskycffb6912007-09-03 10:17:19 +000052 // Copying pixels from one image to another.
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000053 virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0);
54 virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0);
55 virtual void updateRect(XImage *src, int dst_x, int dst_y, int w, int h);
56 virtual void updateRect(Image *src, int dst_x, int dst_y, int w, int h);
57 virtual void updateRect(XImage *src, int dst_x, int dst_y,
58 int src_x, int src_y, int w, int h);
59 virtual void updateRect(Image *src, int dst_x, int dst_y,
60 int src_x, int src_y, int w, int h);
61
62 // Pointer to corresponding XImage, made public for efficiency.
63 // NOTE: if this field is NULL, then no methods other than Init()
64 // may be called.
Constantin Kaplinsky801123d2008-01-18 15:23:11 +000065 XImage *xim;
66
67 // Get a pointer to the data corresponding to the given coordinates.
68 inline char *locatePixel(int x, int y) const {
69 return (xim->data +
70 y * xim->bytes_per_line +
71 x * (xim->bits_per_pixel / 8));
72 }
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000073
74protected:
75
76 void Init(int width, int height);
77
78 // Like updateRect(), but does not check arguments.
79 void copyPixels(XImage *src,
80 int dst_x, int dst_y,
81 int src_x, int src_y,
82 int w, int h);
83
84 Display *dpy;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000085};
86
87//
88// ShmImage uses MIT-SHM extension of an X server to get image data.
89//
90
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +000091#include <X11/extensions/XShm.h>
92
93class ShmImage : public Image {
94
95public:
96
97 ShmImage(Display *d);
98 ShmImage(Display *d, int width, int height);
99 virtual ~ShmImage();
100
101 virtual const char *className() const {
102 return "ShmImage";
103 }
104 virtual const char *classDesc() const {
105 return "shared memory image";
106 }
107
108 virtual void get(Window wnd, int x = 0, int y = 0);
Constantin Kaplinskycffb6912007-09-03 10:17:19 +0000109 virtual void get(Window wnd, int x, int y, int w, int h,
110 int dst_x = 0, int dst_y = 0);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000111
112protected:
113
114 void Init(int width, int height, const XVisualInfo *vinfo = NULL);
115
116 XShmSegmentInfo *shminfo;
117
118};
119
120//
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000121// ImageFactory class is used to produce instances of Image-derived
122// objects that are most appropriate for current X server and user
123// settings.
124//
125
126class ImageFactory {
127
128public:
129
Peter Åstrand (astrand)dcd0b132017-10-16 15:18:00 +0200130 ImageFactory(bool allowShm);
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000131 virtual ~ImageFactory();
132
133 bool isShmAllowed() { return mayUseShm; }
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000134
135 virtual Image *newImage(Display *d, int width, int height);
136
137protected:
138
139 bool mayUseShm;
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +0000140
141};
142
143#endif // __IMAGE_H__