2016-05-14 00:35:41 +00:00
|
|
|
#if __ORCAC__
|
|
|
|
#pragma lint -1
|
2015-09-24 00:40:17 +00:00
|
|
|
#pragma noroot
|
2016-05-14 02:44:12 +00:00
|
|
|
segment "VNCview GS";
|
2016-05-14 00:35:41 +00:00
|
|
|
#endif
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
#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 "menus.h"
|
|
|
|
#include "clipboard.h"
|
|
|
|
#include "desktopsize.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "copyrect.h"
|
|
|
|
#include "raw.h"
|
|
|
|
#include "hextile.h"
|
|
|
|
|
|
|
|
/* Data on state of raw rectangle drawing routines */
|
2016-05-14 00:35:41 +00:00
|
|
|
static unsigned int lineBytes; /* Number of bytes in a line of GS pixels */
|
|
|
|
static unsigned long pixels;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-05-14 00:35:41 +00:00
|
|
|
static unsigned int drawingLine; /* Line to be drawn while displaying */
|
2015-09-24 00:40:17 +00:00
|
|
|
static BOOLEAN extraByteAdvance;
|
|
|
|
|
2016-09-05 21:48:38 +00:00
|
|
|
static unsigned linesAvailable;
|
|
|
|
|
|
|
|
/* Bytes to skip before or after doing raw drawing */
|
|
|
|
static unsigned long preSkip, postSkip;
|
|
|
|
|
2016-05-14 02:44:12 +00:00
|
|
|
/* 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[];
|
|
|
|
|
2016-05-14 00:35:41 +00:00
|
|
|
static unsigned char *destPtr;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-05-14 22:30:44 +00:00
|
|
|
unsigned char * rawDecode640(unsigned startOffset, unsigned endOffset,
|
|
|
|
unsigned char *lineDataPtr);
|
2016-05-21 03:08:05 +00:00
|
|
|
unsigned char * rawDecode320(unsigned startOffset, unsigned endOffset,
|
|
|
|
unsigned char *lineDataPtr);
|
|
|
|
|
2016-05-14 22:30:44 +00:00
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
/* Ends drawing of a raw rectangle when it is complete or aborted
|
|
|
|
* because the rectangle is not visible.
|
|
|
|
*/
|
2016-05-14 00:35:41 +00:00
|
|
|
static void StopRawDrawing (void) {
|
2015-09-24 01:26:03 +00:00
|
|
|
NextRect(); /* Prepare for next rect */
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
#pragma optimize 95 /* To work around an ORCA/C optimizer bug */
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
/* Draw one or more lines from a raw rectangle
|
|
|
|
*/
|
2016-09-05 21:48:38 +00:00
|
|
|
void RawDraw (void) {
|
|
|
|
static unsigned char *lineDataPtr;
|
2015-09-24 01:26:03 +00:00
|
|
|
unsigned int i; /* Loop indices */
|
2016-09-05 21:48:38 +00:00
|
|
|
unsigned char *initialLineDataPtr;
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned char *finalDestPtr;
|
|
|
|
static EventRecord unusedEventRec;
|
|
|
|
|
|
|
|
/* For use with GetContentOrigin() */
|
2016-05-29 04:58:04 +00:00
|
|
|
Origin contentOrigin;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
SetPort(vncWindow); /* Drawing in VNC window */
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-09-05 21:48:38 +00:00
|
|
|
#if 0
|
2015-09-24 00:40:17 +00:00
|
|
|
/* 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) {
|
2015-09-24 01:26:03 +00:00
|
|
|
Rect drawingRect;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-05-29 04:58:04 +00:00
|
|
|
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;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
if (!RectInRgn(&drawingRect, GetVisHandle())) {
|
2015-09-24 01:26:03 +00:00
|
|
|
StopRawDrawing();
|
2015-09-24 00:40:17 +00:00
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2016-05-29 04:58:04 +00:00
|
|
|
else if (rectY + drawingLine < contentOrigin.pt.v) {
|
2016-09-05 21:48:38 +00:00
|
|
|
unsigned linesToSkip = contentOrigin.pt.v - rectY - drawingLine;
|
|
|
|
preSkip = linesToSkip * rectWidth;
|
|
|
|
destPtr += (unsigned long)lineBytes * linesToSkip;
|
2016-05-29 04:58:04 +00:00
|
|
|
drawingLine = contentOrigin.pt.v - rectY;
|
2015-09-24 01:26:03 +00:00
|
|
|
|
|
|
|
if (drawingLine >= rectHeight) { /* Sanity check */
|
|
|
|
StopRawDrawing();
|
|
|
|
return;
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2016-05-29 04:58:04 +00:00
|
|
|
else if (rectY + rectHeight - 1 > contentOrigin.pt.v + winHeight)
|
|
|
|
rectHeight = contentOrigin.pt.v + winHeight - rectY + 1;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
checkBounds = FALSE;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2016-09-05 21:48:38 +00:00
|
|
|
#endif
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
do { /* We short-circuit back to here if there are no events pending */
|
2016-09-05 21:48:38 +00:00
|
|
|
unsigned inPixelsA, inPixelsB, outPixels;
|
|
|
|
|
|
|
|
if (linesAvailable == 0) {
|
|
|
|
linesAvailable = DoReadMultipleTCP(rectWidth, rectHeight - drawingLine);
|
|
|
|
if (linesAvailable) {
|
|
|
|
lineDataPtr = (unsigned char *) *readBufferHndl;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
finalDestPtr = destPtr + lineBytes - 1;
|
2015-09-24 00:40:17 +00:00
|
|
|
if (hRez == 640) {
|
2015-09-24 01:26:03 +00:00
|
|
|
initialLineDataPtr = lineDataPtr;
|
2016-05-14 22:30:44 +00:00
|
|
|
lineDataPtr = rawDecode640(destPtr-destBuf, finalDestPtr-destBuf, lineDataPtr);
|
|
|
|
destPtr = finalDestPtr;
|
2015-09-24 00:40:17 +00:00
|
|
|
*destPtr = pixTransTbl[*(lineDataPtr++)] & 0xC0;
|
2015-09-24 01:26:03 +00:00
|
|
|
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;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
destPtr++;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
else { /* 320 mode */
|
2016-05-21 03:08:05 +00:00
|
|
|
lineDataPtr = rawDecode320(destPtr-destBuf, finalDestPtr-destBuf, lineDataPtr);
|
|
|
|
destPtr = finalDestPtr;
|
2015-09-24 00:40:17 +00:00
|
|
|
/* Final byte to produce */
|
|
|
|
*destPtr = pixTransTbl[*(lineDataPtr++)] & 0xF0;
|
2015-09-24 01:26:03 +00:00
|
|
|
if (extraByteAdvance)
|
|
|
|
destPtr++; /* Not ending on byte boundary - update index */
|
2015-09-24 00:40:17 +00:00
|
|
|
else
|
2015-09-24 01:26:03 +00:00
|
|
|
*(destPtr++) += pixTransTbl[*(lineDataPtr++)] & 0x0F;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
|
|
|
|
drawingLine++;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
if (pixels > 613 && !(drawingLine & 0x03)) { /* Draw every 4th line */
|
2015-09-24 01:26:03 +00:00
|
|
|
srcRect.v2 = drawingLine;
|
2016-05-29 04:58:04 +00:00
|
|
|
contentOrigin.l = GetContentOrigin(vncWindow);
|
|
|
|
PPToPort(&srcLocInfo, &srcRect, rectX - contentOrigin.pt.h,
|
|
|
|
rectY + srcRect.v1 - contentOrigin.pt.v, modeCopy);
|
2015-09-24 01:26:03 +00:00
|
|
|
srcRect.v1 = drawingLine;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
/* Check whether we're done with this rectangle */
|
|
|
|
if (drawingLine >= rectHeight) {
|
2015-09-24 01:26:03 +00:00
|
|
|
/* Draw final rect, if necessary */
|
|
|
|
if (drawingLine > srcRect.v1) {
|
|
|
|
srcRect.v2 = drawingLine;
|
2016-05-29 04:58:04 +00:00
|
|
|
contentOrigin.l = GetContentOrigin(vncWindow);
|
|
|
|
PPToPort(&srcLocInfo, &srcRect, rectX - contentOrigin.pt.h,
|
|
|
|
rectY + srcRect.v1 - contentOrigin.pt.v, modeCopy);
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
StopRawDrawing();
|
2015-09-24 00:40:17 +00:00
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-09-05 21:48:38 +00:00
|
|
|
linesAvailable--;
|
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
2016-05-21 04:09:40 +00:00
|
|
|
if (!(drawingLine & 15)) {
|
|
|
|
if (EventAvail(0xFFFF, &unusedEventRec))
|
|
|
|
return;
|
|
|
|
SystemTask(); /* Let periodic Desk Accesories do their things */
|
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
TCPIPPoll(); /* Let Marinetti keep processing data */
|
2015-09-24 01:56:33 +00:00
|
|
|
} while (1);
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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) {
|
2015-09-24 01:26:03 +00:00
|
|
|
if (rectWidth & 0x03) { /* Width not an exact multiple of 4 */
|
|
|
|
lineBytes = rectWidth/4 + 1;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
else { /* Width is a multiple of 4 */
|
|
|
|
lineBytes = rectWidth/4;
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
else { /* 320 mode */
|
|
|
|
if (rectWidth & 0x01) { /* Width not an exact multiple of 2 */
|
|
|
|
lineBytes = rectWidth/2 + 1;
|
2015-09-24 00:40:17 +00:00
|
|
|
extraByteAdvance = TRUE;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
else { /* Width is a multiple of 2 */
|
|
|
|
lineBytes = rectWidth/2;
|
2015-09-24 00:40:17 +00:00
|
|
|
extraByteAdvance = FALSE;
|
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-05-14 02:44:12 +00:00
|
|
|
/* 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) {
|
2016-05-29 04:58:04 +00:00
|
|
|
Origin contentOrigin;
|
2016-05-14 02:44:12 +00:00
|
|
|
|
2016-05-29 04:58:04 +00:00
|
|
|
contentOrigin.l = GetContentOrigin(vncWindow);
|
|
|
|
SendFBUpdateRequest(FALSE, contentOrigin.pt.h, contentOrigin.pt.v,
|
2016-05-14 02:44:12 +00:00
|
|
|
winWidth, winHeight);
|
2016-09-05 21:48:38 +00:00
|
|
|
skipBytes = pixels;
|
2016-05-14 02:44:12 +00:00
|
|
|
StopRawDrawing();
|
2015-09-24 00:40:17 +00:00
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2016-05-14 02:44:12 +00:00
|
|
|
destPtr = destBuf;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
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) {
|
2015-09-24 01:26:03 +00:00
|
|
|
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;
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
else {
|
2015-09-24 01:26:03 +00:00
|
|
|
switch (rectWidth & 0x01) {
|
|
|
|
case 0x00: srcLocInfo.boundsRect.h2 = rectWidth; break;
|
|
|
|
case 0x01: srcLocInfo.boundsRect.h2 = rectWidth+1;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
/* Don't include padding in the area we will actually copy over */
|
|
|
|
srcRect.h2 = rectWidth;
|
|
|
|
srcRect.v1 = 0;
|
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
displayInProgress = TRUE;
|
|
|
|
drawingLine = 0; /* Drawing first line of rect */
|
2016-09-05 21:48:38 +00:00
|
|
|
linesAvailable = 0; /* No line data read yet */
|
2015-09-24 01:26:03 +00:00
|
|
|
checkBounds = TRUE; /* Flag to check bounds when drawing 1st line */
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|