9fans.net/go@v0.0.7/cmd/devdraw/devdraw.h.go (about) 1 package main 2 3 import ( 4 "os" 5 "sync" 6 7 "9fans.net/go/draw" 8 "9fans.net/go/draw/memdraw" 9 ) 10 11 const ( 12 NHASH = 1 << 5 13 HASHMASK = NHASH - 1 14 ) 15 16 type Kbdbuf struct { 17 r [256]rune 18 ri int 19 wi int 20 stall int 21 alting bool 22 k [10]rune 23 nk int 24 } 25 26 type Mousebuf struct { 27 m [256]draw.Mouse 28 last draw.Mouse 29 ri int 30 wi int 31 stall int 32 resized bool 33 } 34 35 type Tagbuf struct { 36 t [256]int 37 ri int 38 wi int 39 } 40 41 type ClientImpl interface { 42 rpc_resizeimg(*Client) 43 rpc_resizewindow(*Client, draw.Rectangle) 44 rpc_setcursor(*Client, *draw.Cursor, *draw.Cursor2) 45 rpc_setlabel(*Client, string) 46 rpc_setmouse(*Client, draw.Point) 47 rpc_topwin(*Client) 48 rpc_bouncemouse(*Client, draw.Mouse) 49 rpc_flush(*Client, draw.Rectangle) 50 } 51 52 /* extern var drawlk QLock */ 53 54 type Client struct { 55 rfd *os.File 56 wfdlk sync.Mutex 57 wfd *os.File 58 mbuf *uint8 59 nmbuf int 60 wsysid string 61 dimage [NHASH]*DImage 62 cscreen *CScreen 63 refresh *Refresh 64 // refrend Rendez 65 readdata []uint8 66 busy int 67 clientid int 68 slot int 69 refreshme int 70 infoid int 71 op draw.Op 72 displaydpi int 73 forcedpi int 74 waste int 75 flushrect draw.Rectangle 76 screenimage *memdraw.Image 77 dscreen *DScreen 78 name []DName 79 namevers int 80 impl ClientImpl 81 view *[0]byte 82 eventlk sync.Mutex 83 kbd Kbdbuf 84 mouse Mousebuf 85 kbdtags Tagbuf 86 mousetags Tagbuf 87 mouserect draw.Rectangle 88 } 89 90 type Refresh struct { 91 dimage *DImage 92 r draw.Rectangle 93 next *Refresh 94 } 95 96 type Refx struct { 97 client *Client 98 dimage *DImage 99 } 100 101 type DName struct { 102 name string 103 client *Client 104 dimage *DImage 105 vers int 106 } 107 108 type FChar struct { 109 minx int 110 maxx int 111 miny uint8 112 maxy uint8 113 left int8 114 width uint8 115 } 116 117 /* 118 * Reference counts in DImages: 119 * one per open by original client 120 * one per screen image or fill 121 * one per image derived from this one by name 122 */ 123 type DImage struct { 124 id int 125 ref int 126 name string 127 vers int 128 image *memdraw.Image 129 ascent int 130 fchar []FChar 131 dscreen *DScreen 132 fromname *DImage 133 next *DImage 134 } 135 136 type CScreen struct { 137 dscreen *DScreen 138 next *CScreen 139 } 140 141 type DScreen struct { 142 id int 143 public int 144 ref int 145 dimage *DImage 146 dfill *DImage 147 screen *memdraw.Screen 148 owner *Client 149 next *DScreen 150 } 151 152 // For the most part, the graphics driver-specific code in files 153 // like mac-screen.m runs in the graphics library's main thread, 154 // while the RPC service code in srv.c runs on the RPC service thread. 155 // The exceptions in each file, which are called by the other, 156 // are marked with special prefixes: gfx_* indicates code that 157 // is in srv.c but nonetheless runs on the main graphics thread, 158 // while rpc_* indicates code that is in, say, mac-screen.m but 159 // nonetheless runs on the RPC service thread. 160 // 161 // The gfx_* and rpc_* calls typically synchronize with the other 162 // code in the file by acquiring a lock (or running a callback on the 163 // target thread, which amounts to the same thing). 164 // To avoid deadlock, callers of those routines must not hold any locks. 165 166 // gfx_* routines are called on the graphics thread, 167 // invoked from graphics driver callbacks to do RPC work. 168 // No locks are held on entry. 169 170 // rpc_* routines are called on the RPC thread, 171 // invoked by the RPC server code to do graphics work. 172 // No locks are held on entry. 173 174 // rpc_gfxdrawlock and rpc_gfxdrawunlock 175 // are called around drawing operations to lock and unlock 176 // access to the graphics display, for systems where the 177 // individual memdraw operations use the graphics display (X11, not macOS). 178 179 // draw* routines are called on the RPC thread, 180 // invoked by the RPC server to do pixel pushing. 181 // No locks are held on entry. 182 183 // utility routines 184 185 /* extern var client0 *Client */ // set in single-client mode