summaryrefslogtreecommitdiffstats
path: root/krfb/krfb/xupdatescanner.h
blob: fdd02e3064d3f7c657fbd60fcc7afaa2bb38deb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 *  Copyright (C) 2000 heXoNet Support GmbH, D-66424 Homburg.
 *  All Rights Reserved.
 *
 *  This is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This software is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this software; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 *  USA.
 */

#ifndef _hexonet_rfb_XUpdateScanner_h_
#define _hexonet_rfb_XUpdateScanner_h_

#include <tqptrlist.h>
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>


class Hint {
 public:
	int x, y, w, h;

	Hint() :
		x(0),
		y(0),
		w(0),
		h(0)
	{}
	Hint(Hint &h) :
		x(h.x),
		y(h.y),
		w(h.w),
		h(h.h)
	{
	}
	int left() {
		return x;
	}
	int right() {
		return x+w;
	}
	int top() {
		return y;
	}
	int bottom() {
		return y+h;
	}
};

struct TileChangeRegion {
  short firstLine, lastLine;
};


class XUpdateScanner
{
 public:
	XUpdateScanner( Display *_dpy,
			Window _window,
			unsigned char *_fb,
			int _width, int _height,
			int _bitsPerPixel, int _bytesPerLine,
			bool useXShm);

	~XUpdateScanner();

	// hitList: returns list of changes
	// ptrY: ptrY: position of the cursor
	void searchUpdates( TQPtrList<Hint> &hintList, int ptrY);

 private:
	void testScanline(int y, bool rememberHits);
	bool copyTile(int x, int y, int tx, int ty);
	void copyAllTiles();
	void flushHint(int x, int y, int &x0, Hint &hint,
		       TQPtrList<Hint> &hintList);
	void createHints(TQPtrList<Hint> &hintList);
	void addTileToHint(int x, int y, int th, Hint &hint);
	void createHintFromTile(int x, int y, int th, Hint &hint);

	Display *dpy;
	Window window;
	unsigned char *fb;
	int width, height;
	int bitsPerPixel, bytesPerLine;
	unsigned int tileWidth, tileHeight;
	unsigned int count;
	bool useShm;

	XImage *scanline;
	XShmSegmentInfo shminfo_scanline;

	XImage *tile;
	XShmSegmentInfo shminfo_tile;

	unsigned int tilesX, tilesY;
	bool *tileMap;
	struct TileChangeRegion *tileRegionMap;
};


#endif // _hexonet_rfb_XUpdateScanner_h_