ref: f85425aad78787d12eb6f0941686b9fb5e114e62
parent: 0ce5868c8a91cacf824cd4ed5393678e0bc394a5
author: Yaroslav Kolomiiets <yarikos@gmail.com>
date: Tue Aug 9 11:12:36 EDT 2016
drawing contained within draw.c
--- a/dat.h
+++ b/dat.h
@@ -228,7 +228,7 @@
void finalhandshake(Rdp*);
void drawimgupdate(Rdp*,Share*);
void loadcmap(Rdp*,Share*);
-void scanorders(Rdp*,Share*);
+void draworders(Rdp*,Share*);
enum /* Imgupd.type */
{
@@ -259,10 +259,7 @@
uchar* bytes;
};
int getimgupd(Imgupd*, uchar*, uint);
-int getscrblt(Imgupd*,uchar*,uint,int,int);
-int getmemblt(Imgupd*,uchar*,uint,int,int);
-int getimgcache2(Imgupd*,uchar*,uint,int,int);
-int getcmapcache(Imgupd*,uchar*,uint,int,int);
+int getfupd(Imgupd*, uchar*, uint);
void loadmemimg(Rdp*, Imgupd*);
void drawmemimg(Rdp*, Imgupd*);
--- a/draw.c
+++ b/draw.c
@@ -8,18 +8,19 @@
#include "dat.h"
#include "fns.h"
+static Image* pad;
static Image* icache[3][600];
+static void drawupd(Rdp*,Imgupd*);
+
/* 2.2.9.1.1.3.1.2.1 Bitmap Update Data (TS_UPDATE_BITMAP_DATA) */
void
drawimgupdate(Rdp *c, Share* s)
{
- int (*loadfn)(Image*,Rectangle,uchar*,int,uchar*);
uchar* p, *ep;
int n, nr;
- Rectangle r, rs;
+ Rectangle rs;
Imgupd u;
- static Image* pad;
assert(s->type == ShUimg);
p = s->data;
@@ -39,24 +40,35 @@
while(p<ep && nr>0){
if((n = getimgupd(&u, p, ep-p)) < 0)
sysfatal("getimgupd: %r");
- if(u.depth != pad->depth)
- sysfatal("bad image depth");
+ drawupd(c, &u);
+ p += n;
+ nr--;
+ }
+ flushimage(display, 1);
+ if(display->locking)
+ unlockdisplay(display);
+}
- loadfn = loadbmp;
- if(u.iscompr)
- loadfn = loadrle;
+/* 2.2.2.2 Fast-Path Orders Update (TS_FP_UPDATE_ORDERS) */
+void
+draworders(Rdp* c, Share* as)
+{
+ int n, count;
+ uchar *p, *ep;
+ Imgupd u;
- r = rectaddpt(Rect(u.x, u.y, u.x+u.xsz, u.y+u.ysz), screen->r.min);
- if(loadfn(pad, r, u.bytes, u.nbytes, c->cmap) < 0)
- sysfatal("drawimgupdate: %r");
+ count = as->nord;
+ p = as->data;
+ ep = as->data + as->ndata;
- r = rectaddpt(Rect(u.x, u.y, u.xm+1, u.ym+1), screen->r.min);
- draw(screen, r, pad, nil, r.min);
+ while(count> 0 && p<ep){
+ n = getfupd(&u, p, ep-p);
+ drawupd(c, &u);
p += n;
- nr--;
+ count--;
}
-// if(p != ep)
-// fprint(2, "drawimgupdate: out of sync: %d bytes left\n", (int)(ep-p));
+ if(display->locking)
+ lockdisplay(display);
flushimage(display, 1);
if(display->locking)
unlockdisplay(display);
@@ -125,4 +137,76 @@
r = rectaddpt(r, screen->r.min);
pt = Pt(iu->sx, iu->sy);
draw(screen, r, img, nil, pt);
+}
+
+
+static void
+imgupd(Rdp* c, Imgupd* up)
+{
+ Rectangle r;
+ int (*loadfn)(Image*,Rectangle,uchar*,int,uchar*);
+
+ if(up->depth != pad->depth)
+ sysfatal("bad image depth");
+
+ loadfn = loadbmp;
+ if(up->iscompr)
+ loadfn = loadrle;
+
+ r = rectaddpt(Rect(up->x, up->y, up->x+up->xsz, up->y+up->ysz), screen->r.min);
+ if(loadfn(pad, r, up->bytes, up->nbytes, c->cmap) < 0)
+ sysfatal("drawimgupdate: %r");
+
+ r = rectaddpt(Rect(up->x, up->y, up->xm+1, up->ym+1), screen->r.min);
+ draw(screen, r, pad, nil, r.min);
+}
+
+static void
+scrblt(Rdp*, Imgupd* up)
+{
+ Rectangle r, sr;
+
+ r = rectaddpt(Rect(up->x, up->y, up->x+up->xsz, up->y+up->ysz), screen->r.min);
+ sr = rectaddpt(Rpt(Pt(up->sx, up->sy), Pt(Dx(r), Dy(r))), screen->r.min);
+ scroll(display, r, sr);
+}
+
+static void
+memblt(Rdp* c, Imgupd* up)
+{
+ if(display->locking)
+ lockdisplay(display);
+ if(up->clipped)
+ replclipr(screen, screen->repl, rectaddpt(up->clipr, screen->r.min));
+ drawmemimg(c, up);
+ if(up->clipped)
+ replclipr(screen, screen->repl, screen->r);
+ if(display->locking)
+ unlockdisplay(display);
+}
+
+
+static void
+cacheimage2(Rdp* c, Imgupd* up)
+{
+ loadmemimg(c, up);
+}
+
+
+static void
+cachecmap(Rdp*, Imgupd*)
+{
+ /* BUG: who cares? */
+}
+
+static void
+drawupd(Rdp* c, Imgupd* up)
+{
+ switch(up->type){
+ case Ubitmap: imgupd(c, up); break;
+ case Uscrblt: scrblt(c, up); break;
+ case Umemblt: memblt(c, up); break;
+ case Uicache: cacheimage2(c, up); break;
+ case Umcache: cachecmap(c, up); break;
+ }
}
--- a/egdi.c
+++ b/egdi.c
@@ -83,31 +83,27 @@
CacheCompressed3,
};
+static int getscrblt(Imgupd*, uchar*, uint, int, int);
+static int getmemblt(Imgupd*, uchar*, uint, int, int);
+static int getimgcache2(Imgupd*, uchar*, uint, int, int);
+static int getcmapcache(Imgupd*, uchar*, uint, int, int);
+
typedef struct Order Order;
struct Order
{
int fsize;
- void (*fn)(Rdp*,Imgupd*);
int (*get)(Imgupd*,uchar*,uint,int,int);
};
-static void drawupd(Rdp*,Imgupd*);
-
-
-static void scrblt(Rdp*,Imgupd*);
-static void memblt(Rdp*,Imgupd*);
-static void cacheimage2(Rdp*,Imgupd*);
-static void cachecmap(Rdp*,Imgupd*);
-
Order ordtab[NumOrders] = {
- [ScrBlt]= { 1, drawupd, getscrblt },
- [MemBlt]= { 2, drawupd, getmemblt },
+ [ScrBlt]= { 1, getscrblt },
+ [MemBlt]= { 2, getmemblt },
};
Order auxtab[8] = {
- [CacheImage2]= { 0, drawupd, getimgcache2 },
- [CacheCompressed2]= { 0, drawupd, getimgcache2 },
- [CacheCmap]= { 0, drawupd, getcmapcache },
+ [CacheImage2]= { 0, getimgcache2 },
+ [CacheCompressed2]= { 0, getimgcache2 },
+ [CacheCmap]= { 0, getcmapcache },
};
uchar
@@ -126,8 +122,8 @@
static int cfclipr(Rectangle*,uchar*,int);
static int cfpt(Point*,uchar*,int,int,int);
-int getfupd(Imgupd*, uchar*, uint);
-int getfupd(Imgupd* up, uchar* a, uint nb)
+int
+getfupd(Imgupd* up, uchar* a, uint nb)
{
uchar *p, *ep;
int ctl, fset, fsize;
@@ -142,10 +138,10 @@
goto ErrNstd;
if(ctl&Secondary){
if(p+6>ep)
- sysfatal("scanorders: %s", Eshort);
+ sysfatal("draworders: %s", Eshort);
size = ((short)GSHORT(p+1))+13;
if(size < 0 || p+size > ep)
- sysfatal("scanorders: size: %s", Eshort);
+ sysfatal("draworders: size: %s", Eshort);
opt = GSHORT(p+3);
xorder = p[5];
if(xorder >= nelem(auxtab) || auxtab[xorder].get == nil){
@@ -200,30 +196,6 @@
return p-a;
}
-/* 2.2.2.2 Fast-Path Orders Update (TS_FP_UPDATE_ORDERS) */
-void
-scanorders(Rdp* c, Share* as)
-{
- int n, count;
- uchar *p, *ep;
- Imgupd u;
-
- count = as->nord;
- p = as->data;
- ep = as->data + as->ndata;
-
- while(count-- > 0 && p<ep){
- n = getfupd(&u, p, ep-p);
- drawupd(c, &u);
- p += n;
- }
- if(display->locking)
- lockdisplay(display);
- flushimage(display, 1);
- if(display->locking)
- unlockdisplay(display);
-}
-
static int
cfpt(Point* p, uchar* a, int nb, int isdelta, int fset)
{
@@ -311,7 +283,7 @@
}
/* 2.2.2.2.1.1.2.7 ScrBlt (SCRBLT_ORDER) */
-int
+static int
getscrblt(Imgupd* up, uchar* a, uint nb, int ctl, int fset)
{
int n;
@@ -353,7 +325,7 @@
return p-a;
}
-int
+static int
getmemblt(Imgupd* up, uchar* a, uint nb, int ctl, int fset)
{
static int cid; /* cacheId */
@@ -408,7 +380,7 @@
}
/* 2.2.2.2.1.2.3 Cache Bitmap - Revision 2 (CACHE_BITMAP_REV2_ORDER) */
-int
+static int
getimgcache2(Imgupd* up, uchar* a, uint nb, int xorder, int opt)
{
uchar *p, *ep;
@@ -477,7 +449,7 @@
}
/* 2.2.2.2.1.2.4 Cache Color Table (CACHE_COLOR_TABLE_ORDER) */
-int
+static int
getcmapcache(Imgupd* up, uchar* a, uint nb, int, int)
{
int cid, n;
@@ -496,56 +468,3 @@
return 9+4*256;
}
-static void
-drawupd(Rdp* c,Imgupd* up)
-{
- switch(up->type){
- case Uscrblt: scrblt(c, up); break;
- case Umemblt: memblt(c, up); break;
- case Uicache: cacheimage2(c, up); break;
- case Umcache: cachecmap(c, up); break;
- }
-}
-
-
-static void
-scrblt(Rdp*, Imgupd* up)
-{
- Rectangle r, sr;
-
-DBG fprint(2, "scrblt...");
- r = rectaddpt(Rect(up->x, up->y, up->x+up->xsz, up->y+up->ysz), screen->r.min);
- sr = rectaddpt(Rpt(Pt(up->sx, up->sy), Pt(Dx(r), Dy(r))), screen->r.min);
- scroll(display, r, sr);
-}
-
-static void
-memblt(Rdp* c, Imgupd* up)
-{
-DBG fprint(2, "memblt...");
- if(display->locking)
- lockdisplay(display);
- if(up->clipped)
- replclipr(screen, screen->repl, rectaddpt(up->clipr, screen->r.min));
- drawmemimg(c, up);
- if(up->clipped)
- replclipr(screen, screen->repl, screen->r);
- if(display->locking)
- unlockdisplay(display);
-}
-
-
-static void
-cacheimage2(Rdp* c, Imgupd* up)
-{
-DBG fprint(2, "cacheimage2...");
- loadmemimg(c, up);
-}
-
-
-static void
-cachecmap(Rdp*, Imgupd*)
-{
-DBG fprint(2, "cachecmap...");
- /* BUG: who cares? */
-}
--- a/rpc.c
+++ b/rpc.c
@@ -444,7 +444,7 @@
c->hupreason = u.err;
break;
case ShUorders:
- scanorders(c, &u);
+ draworders(c, &u);
break;
case ShUimg:
drawimgupdate(c, &u);