plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

devdraw.h (5270B)


      1 
      2 #define NHASH (1<<5)
      3 #define HASHMASK (NHASH-1)
      4 
      5 typedef struct Kbdbuf Kbdbuf;
      6 typedef struct Mousebuf Mousebuf;
      7 typedef struct Tagbuf Tagbuf;
      8 
      9 typedef struct Client Client;
     10 typedef struct ClientImpl ClientImpl;
     11 typedef struct DImage DImage;
     12 typedef struct DScreen DScreen;
     13 typedef struct CScreen CScreen;
     14 typedef struct FChar FChar;
     15 typedef struct Refresh Refresh;
     16 typedef struct Refx Refx;
     17 typedef struct DName DName;
     18 
     19 struct Kbdbuf
     20 {
     21 	Rune r[256];
     22 	int ri;
     23 	int wi;
     24 	int stall;
     25 	int alting;
     26 	Rune k[10];
     27 	int nk;
     28 };
     29 
     30 struct Mousebuf
     31 {
     32 	Mouse m[256];
     33 	Mouse last;
     34 	int ri;
     35 	int wi;
     36 	int stall;
     37 	int resized;
     38 };
     39 
     40 struct Tagbuf
     41 {
     42 	int t[256];
     43 	int ri;
     44 	int wi;
     45 };
     46 
     47 struct ClientImpl
     48 {
     49 	void (*rpc_resizeimg)(Client*);
     50 	void (*rpc_resizewindow)(Client*, Rectangle);
     51 	void (*rpc_setcursor)(Client*, Cursor*, Cursor2*);
     52 	void (*rpc_setlabel)(Client*, char*);
     53 	void (*rpc_setmouse)(Client*, Point);
     54 	void (*rpc_topwin)(Client*);
     55 	void (*rpc_bouncemouse)(Client*, Mouse);
     56 	void (*rpc_flush)(Client*, Rectangle);
     57 };
     58 
     59 extern QLock drawlk;
     60 
     61 struct Client
     62 {
     63 	int		rfd;
     64 
     65 	// wfdlk protects writes to wfd, which can be issued from either
     66 	// the RPC thread or the graphics thread.
     67 	QLock	wfdlk;
     68 	int		wfd;
     69 	uchar*	mbuf;
     70 	int		nmbuf;
     71 
     72 	char*	wsysid;
     73 
     74 	// drawlk protects the draw data structures for all clients.
     75 	// It can be acquired by an RPC thread or a graphics thread
     76 	// but must not be held on one thread while waiting for the other.
     77 	/*Ref		r;*/
     78 	DImage*		dimage[NHASH];
     79 	CScreen*	cscreen;
     80 	Refresh*	refresh;
     81 	Rendez		refrend;
     82 	uchar*		readdata;
     83 	int		nreaddata;
     84 	int		busy;
     85 	int		clientid;
     86 	int		slot;
     87 	int		refreshme;
     88 	int		infoid;
     89 	int		op;
     90 	int		displaydpi;
     91 	int		forcedpi;
     92 	int		waste;
     93 	Rectangle	flushrect;
     94 	Memimage	*screenimage;
     95 	DScreen*	dscreen;
     96 	int		nname;
     97 	DName*		name;
     98 	int		namevers;
     99 	ClientImpl*	impl;
    100 
    101 	// Only accessed/modified by the graphics thread.
    102 	const void*		view;
    103 
    104 	// eventlk protects the keyboard and mouse events.
    105 	QLock eventlk;
    106 	Kbdbuf kbd;
    107 	Mousebuf mouse;
    108 	Tagbuf kbdtags;
    109 	Tagbuf mousetags;
    110 	Rectangle mouserect;
    111 };
    112 
    113 struct Refresh
    114 {
    115 	DImage*		dimage;
    116 	Rectangle	r;
    117 	Refresh*	next;
    118 };
    119 
    120 struct Refx
    121 {
    122 	Client*		client;
    123 	DImage*		dimage;
    124 };
    125 
    126 struct DName
    127 {
    128 	char			*name;
    129 	Client	*client;
    130 	DImage*		dimage;
    131 	int			vers;
    132 };
    133 
    134 struct FChar
    135 {
    136 	int		minx;	/* left edge of bits */
    137 	int		maxx;	/* right edge of bits */
    138 	uchar		miny;	/* first non-zero scan-line */
    139 	uchar		maxy;	/* last non-zero scan-line + 1 */
    140 	schar		left;	/* offset of baseline */
    141 	uchar		width;	/* width of baseline */
    142 };
    143 
    144 /*
    145  * Reference counts in DImages:
    146  *	one per open by original client
    147  *	one per screen image or fill
    148  * 	one per image derived from this one by name
    149  */
    150 struct DImage
    151 {
    152 	int		id;
    153 	int		ref;
    154 	char		*name;
    155 	int		vers;
    156 	Memimage*	image;
    157 	int		ascent;
    158 	int		nfchar;
    159 	FChar*		fchar;
    160 	DScreen*	dscreen;	/* 0 if not a window */
    161 	DImage*	fromname;	/* image this one is derived from, by name */
    162 	DImage*		next;
    163 };
    164 
    165 struct CScreen
    166 {
    167 	DScreen*	dscreen;
    168 	CScreen*	next;
    169 };
    170 
    171 struct DScreen
    172 {
    173 	int		id;
    174 	int		public;
    175 	int		ref;
    176 	DImage	*dimage;
    177 	DImage	*dfill;
    178 	Memscreen*	screen;
    179 	Client*		owner;
    180 	DScreen*	next;
    181 };
    182 
    183 // For the most part, the graphics driver-specific code in files
    184 // like mac-screen.m runs in the graphics library's main thread,
    185 // while the RPC service code in srv.c runs on the RPC service thread.
    186 // The exceptions in each file, which are called by the other,
    187 // are marked with special prefixes: gfx_* indicates code that
    188 // is in srv.c but nonetheless runs on the main graphics thread,
    189 // while rpc_* indicates code that is in, say, mac-screen.m but
    190 // nonetheless runs on the RPC service thread.
    191 //
    192 // The gfx_* and rpc_* calls typically synchronize with the other
    193 // code in the file by acquiring a lock (or running a callback on the
    194 // target thread, which amounts to the same thing).
    195 // To avoid deadlock, callers of those routines must not hold any locks.
    196 
    197 // gfx_* routines are called on the graphics thread,
    198 // invoked from graphics driver callbacks to do RPC work.
    199 // No locks are held on entry.
    200 void	gfx_abortcompose(Client*);
    201 void	gfx_keystroke(Client*, int);
    202 void	gfx_main(void);
    203 void	gfx_mousetrack(Client*, int, int, int, uint);
    204 void	gfx_replacescreenimage(Client*, Memimage*);
    205 void	gfx_mouseresized(Client*);
    206 void	gfx_started(void);
    207 
    208 // rpc_* routines are called on the RPC thread,
    209 // invoked by the RPC server code to do graphics work.
    210 // No locks are held on entry.
    211 Memimage *rpc_attach(Client*, char*, char*);
    212 char*	rpc_getsnarf(void);
    213 void	rpc_putsnarf(char*);
    214 void	rpc_shutdown(void);
    215 void	rpc_main(void);
    216 
    217 // rpc_gfxdrawlock and rpc_gfxdrawunlock
    218 // are called around drawing operations to lock and unlock
    219 // access to the graphics display, for systems where the
    220 // individual memdraw operations use the graphics display (X11, not macOS).
    221 void rpc_gfxdrawlock(void);
    222 void rpc_gfxdrawunlock(void);
    223 
    224 // draw* routines are called on the RPC thread,
    225 // invoked by the RPC server to do pixel pushing.
    226 // No locks are held on entry.
    227 int draw_dataread(Client*, void*, int);
    228 int draw_datawrite(Client*, void*, int);
    229 void draw_initdisplaymemimage(Client*, Memimage*);
    230 
    231 // utility routines
    232 int latin1(Rune*, int);
    233 int mouseswap(int);
    234 int parsewinsize(char*, Rectangle*, int*);
    235 
    236 extern Client *client0; // set in single-client mode