-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathraw.cc
270 lines (233 loc) · 9.35 KB
/
raw.cc
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#if __ORCAC__
#pragma lint -1
#pragma noroot
segment "VNCview GS";
#endif
#include <window.h>
#include <quickdraw.h>
#include <qdaux.h>
#include <desk.h>
#include <memory.h>
#include <resources.h>
#include <tcpip.h>
#include <menu.h>
#include <control.h>
#include <misctool.h>
#include <scrap.h>
#include <stdio.h>
#include <stdlib.h>
#include <event.h>
#include <limits.h>
#include "vncsession.h"
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "readtcp.h"
#include "raw.h"
#define EVENT_CHECK_INVERVAL 10 /* tick count between event checks */
/* Data on state of raw rectangle drawing routines */
static unsigned int lineBytes; /* Number of bytes in a line of GS pixels */
static unsigned long pixels;
static unsigned int drawingLine; /* Line to be drawn while displaying */
static BOOLEAN extraByteAdvance;
static unsigned linesAvailable;
/* Bytes to skip before or after doing raw drawing */
static unsigned long preSkip, postSkip;
/* Buffer to hold all SHR pixel data from one update (defined in tables.asm).
* Must be big enough: at least (WIN_WIDTH_640/4 + 1) * WIN_HEIGHT. */
#define DESTBUF_SIZE 0x8001
extern unsigned char destBuf[];
static unsigned char *destPtr;
unsigned char * rawDecode640(unsigned startOffset, unsigned endOffset,
unsigned char *lineDataPtr);
unsigned char * rawDecode320(unsigned startOffset, unsigned endOffset,
unsigned char *lineDataPtr);
/* Ends drawing of a raw rectangle when it is complete or aborted
* because the rectangle is not visible.
*/
static void StopRawDrawing (void) {
NextRect(); /* Prepare for next rect */
}
#pragma optimize 95 /* To work around an ORCA/C optimizer bug */
/* Draw one or more lines from a raw rectangle
*/
void RawDraw (void) {
static unsigned char *lineDataPtr;
unsigned int i; /* Loop indices */
unsigned char *initialLineDataPtr;
unsigned char *finalDestPtr;
static EventRecord eventRec;
unsigned long eventCheckTime;
/* For use with GetContentOrigin() */
Origin contentOrigin;
eventCheckTime = TickCount() + EVENT_CHECK_INVERVAL;
SetPort(vncWindow); /* Drawing in VNC window */
#if 0
/* Check if what we're drawing is visible, and skip any invisible part
* by skipping some lines or completely aborting drawing the rectangle.
*/
if (checkBounds) {
Rect drawingRect;
contentOrigin.l = GetContentOrigin(vncWindow);
drawingRect.h1 = rectX - contentOrigin.pt.h;
drawingRect.h2 = rectX - contentOrigin.pt.h + rectWidth;
drawingRect.v1 = rectY - contentOrigin.pt.v + drawingLine;
drawingRect.v2 = rectY - contentOrigin.pt.v + rectHeight;
if (!RectInRgn(&drawingRect, GetVisHandle())) {
StopRawDrawing();
return;
}
else if (rectY + drawingLine < contentOrigin.pt.v) {
unsigned linesToSkip = contentOrigin.pt.v - rectY - drawingLine;
preSkip = linesToSkip * rectWidth;
destPtr += (unsigned long)lineBytes * linesToSkip;
drawingLine = contentOrigin.pt.v - rectY;
if (drawingLine >= rectHeight) { /* Sanity check */
StopRawDrawing();
return;
}
}
else if (rectY + rectHeight - 1 > contentOrigin.pt.v + winHeight)
rectHeight = contentOrigin.pt.v + winHeight - rectY + 1;
checkBounds = FALSE;
}
#endif
do { /* We short-circuit back to here if there are no events pending */
unsigned inPixelsA, inPixelsB, outPixels;
if (linesAvailable == 0) {
linesAvailable = DoReadMultipleTCP(rectWidth, rectHeight - drawingLine);
if (linesAvailable) {
lineDataPtr = readBufferPtr;
} else {
return;
}
}
finalDestPtr = destPtr + lineBytes - 1;
if (hRez == 640) {
initialLineDataPtr = lineDataPtr;
lineDataPtr = rawDecode640(destPtr-destBuf, finalDestPtr-destBuf, lineDataPtr);
destPtr = finalDestPtr;
*destPtr = pixTransTbl[*(lineDataPtr++)] & 0xC0;
for (i = lineDataPtr - initialLineDataPtr; i < rectWidth; i++)
switch (i & 0x03) {
case 0x01: /* pixels 1, 5, 9, ... */
*destPtr += pixTransTbl[*(lineDataPtr++)] & 0x30;
break;
case 0x02: /* pixels 2, 6, 10, ... */
*destPtr += pixTransTbl[*(lineDataPtr++)] & 0x0C;
break;
case 0x03: /* pixels 3, 7, 11, ... */
*destPtr += pixTransTbl[*(lineDataPtr++)] & 0x03;
}
destPtr++;
}
else { /* 320 mode */
lineDataPtr = rawDecode320(destPtr-destBuf, finalDestPtr-destBuf, lineDataPtr);
destPtr = finalDestPtr;
/* Final byte to produce */
*destPtr = pixTransTbl[*(lineDataPtr++)] & 0xF0;
if (extraByteAdvance)
destPtr++; /* Not ending on byte boundary - update index */
else
*(destPtr++) += pixTransTbl[*(lineDataPtr++)] & 0x0F;
}
drawingLine++;
if (pixels > 613 && !(drawingLine & 0x03)) { /* Draw every 4th line */
srcRect.v2 = drawingLine;
contentOrigin.l = GetContentOrigin(vncWindow);
PPToPort(&srcLocInfo, &srcRect, rectX - contentOrigin.pt.h,
rectY + srcRect.v1 - contentOrigin.pt.v, modeCopy);
srcRect.v1 = drawingLine;
}
/* Check whether we're done with this rectangle */
if (drawingLine >= rectHeight) {
/* Draw final rect, if necessary */
if (drawingLine > srcRect.v1) {
srcRect.v2 = drawingLine;
contentOrigin.l = GetContentOrigin(vncWindow);
PPToPort(&srcLocInfo, &srcRect, rectX - contentOrigin.pt.h,
rectY + srcRect.v1 - contentOrigin.pt.v, modeCopy);
}
StopRawDrawing();
return;
}
linesAvailable--;
/* Check if there are actually any events that need to be processed.
* If not, save time by not going through the whole event loop, but
* instead processing the minimum necessary periodic tasks and then
* going straight to the next line of data.
*/
if (TickCount() >= eventCheckTime) {
if (EventAvail(0xFFFF, &eventRec))
return;
SystemTask(); /* Let periodic Desk Accesories do their things */
eventCheckTime = eventRec.when + EVENT_CHECK_INVERVAL;
}
TCPIPPoll(); /* Let Marinetti keep processing data */
} while (1);
}
#pragma optimize -1
/* Process rectangle data in raw encoding and write it to screen.
*/
void DoRawRect (void) {
pixels = (unsigned long) rectWidth * rectHeight;
if (hRez == 640) {
if (rectWidth & 0x03) { /* Width not an exact multiple of 4 */
lineBytes = rectWidth/4 + 1;
}
else { /* Width is a multiple of 4 */
lineBytes = rectWidth/4;
}
}
else { /* 320 mode */
if (rectWidth & 0x01) { /* Width not an exact multiple of 2 */
lineBytes = rectWidth/2 + 1;
extraByteAdvance = TRUE;
}
else { /* Width is a multiple of 2 */
lineBytes = rectWidth/2;
extraByteAdvance = FALSE;
}
}
/* If we get an oversized update, ignore it and ask for another one.
* Shouldn't normally happen, except possibly if there are outstanding
* update requests for multiple screen regions due to scrolling.
*/
if (lineBytes * rectHeight >= DESTBUF_SIZE) {
Origin contentOrigin;
contentOrigin.l = GetContentOrigin(vncWindow);
SendFBUpdateRequest(FALSE, contentOrigin.pt.h, contentOrigin.pt.v,
winWidth, winHeight);
skipBytes = pixels;
StopRawDrawing();
return;
}
destPtr = destBuf;
srcLocInfo.ptrToPixImage = destPtr;
srcLocInfo.width = lineBytes;
srcLocInfo.boundsRect.v2 = rectHeight;
/* Since the lines are rounded up to integral numbers of bytes, this
* padding must be accounted for here.
*/
if (hRez == 640) {
switch (rectWidth & 0x03) {
case 0x00: srcLocInfo.boundsRect.h2 = rectWidth; break;
case 0x01: srcLocInfo.boundsRect.h2 = rectWidth+3; break;
case 0x02: srcLocInfo.boundsRect.h2 = rectWidth+2; break;
case 0x03: srcLocInfo.boundsRect.h2 = rectWidth+1;
}
}
else {
switch (rectWidth & 0x01) {
case 0x00: srcLocInfo.boundsRect.h2 = rectWidth; break;
case 0x01: srcLocInfo.boundsRect.h2 = rectWidth+1;
}
}
/* Don't include padding in the area we will actually copy over */
srcRect.h2 = rectWidth;
srcRect.v1 = 0;
displayInProgress = TRUE;
drawingLine = 0; /* Drawing first line of rect */
linesAvailable = 0; /* No line data read yet */
checkBounds = TRUE; /* Flag to check bounds when drawing 1st line */
}