]> git.lizzy.rs Git - plan9front.git/blob - sys/man/3/draw
vac(1), ec(2), usb(3), hjfs(8): fix source reference
[plan9front.git] / sys / man / 3 / draw
1 .TH DRAW 3 
2 .SH NAME
3 draw \- screen graphics
4 .SH SYNOPSIS
5 .nf
6 .B bind -a #i /dev
7
8 .B /dev/draw/new
9
10 .BI /dev/draw/ n /ctl
11 .BI /dev/draw/ n /data
12 .BI /dev/draw/ n /colormap
13 .BI /dev/draw/ n /refresh
14
15 .ft L
16 #include <u.h>
17 #include <draw.h>
18
19 .ta \w'ushort 'u
20 ushort  BGSHORT(uchar *p)
21 ulong   BGLONG(uchar *p)
22 void    BPSHORT(uchar *p, ushort v)
23 void    BPLONG(uchar *p, ulong v)
24 .ft P
25 .fi
26 .SH DESCRIPTION
27 The
28 .I draw
29 device serves a three-level file system 
30 providing an interface to the graphics facilities of the system.
31 Each client of the device connects by opening
32 .B /dev/draw/new
33 and reading 12 strings, each 11 characters wide followed by a blank:
34 the connection number
35 .RI ( n ),
36 the image id
37 .RI ( q.v. )
38 of the display image (always zero),
39 the
40 channel format
41 of the image,
42 the
43 .BR min.x ,
44 .BR min.y ,
45 .BR max.x ,
46 and
47 .B max.y
48 of the display image,
49 and the
50 .BR min.x ,
51 .BR min.y ,
52 .BR max.x ,
53 and
54 .B max.y 
55 of the clipping rectangle. 
56 The channel format string is described in 
57 .IR image (6),
58 and the other fields are decimal numbers.
59 .PP
60 The client can then open the directory
61 .BI /dev/draw/ n /
62 to access the
63 .BR ctl ,
64 .BR data ,
65 .BR colormap ,
66 and
67 .B refresh
68 files associated with the connection.
69 .PP
70 Via the 
71 .B ctl
72 and
73 .B draw 
74 files, the
75 .I draw
76 device provides access to 
77 images and font caches
78 in its private storage,
79 as described in 
80 .IR graphics (2).
81 Each image is identified by a 4-byte integer, its
82 .IR id .
83 .PP
84 Reading the
85 .B ctl 
86 file yields 12 strings formatted as in
87 .BR /dev/draw/new ,
88 but for the current image rather
89 than the display image.
90 The current image may be set by writing a
91 binary image id to the
92 .B ctl
93 file.
94 .PP
95 A process can write messages to 
96 .B data
97 to allocate and free images, fonts, and subfonts;
98 read or write portions of the images;
99 and draw line segments and character
100 strings in the images.
101 All graphics requests are clipped to their images.
102 Some messages return a response to be recovered by 
103 reading the
104 .B data 
105 file.
106 .PP
107 The format of messages written to
108 .B data
109 is a single letter
110 followed by binary parameters;
111 multibyte integers are transmitted with the low order byte first.
112 The
113 .B BPSHORT
114 and
115 .B BPLONG
116 macros place correctly formatted two- and four-byte integers into a character
117 buffer.
118 .B BGSHORT
119 and
120 .B BGLONG
121 retrieve values from a character buffer.
122 Points are two four-byte numbers:
123 .IR x ,
124 .IR y .
125 Rectangles are four four-byte numbers: min 
126 .IR x ,
127 min
128 .IR y ,
129 max
130 .IR x ,
131 and max
132 .IR y .
133 Images, screens, and fonts have 32-bit identifiers.
134 In the discussion of the protocol below,
135 the distinction between identifier and actual image, screen, or font
136 is not made, so that
137 ``the object
138 .IR id ''
139 should be interpreted as 
140 ``the object with identifier
141 .IR id ''.
142 The definitions of constants used in the description below can be found in
143 .BR draw.h .
144 .PP
145 The following requests are accepted by the
146 .B data
147 file.
148 The numbers in brackets give the length in bytes of the parameters.
149 .HP .5i
150 .B A
151 .IR id [4]
152 .IR imageid [4]
153 .IR fillid [4]
154 .IR public [1]
155 .br
156 Allocate a new
157 .B Screen
158 (see
159 .IR window (2))
160 with
161 screen identifier
162 .I id
163 using
164 backing store image
165 .IR imageid ,
166 filling it initially
167 with data from image
168 .IR fillid .
169 If the
170 .I public
171 byte is non-zero, the screen can 
172 be accessed from other processes
173 using the
174 .B publicscreen
175 interface.
176 .HP
177 .B b 
178 .IR id [4]
179 .IR screenid [4]
180 .IR refresh [1]
181 .IR chan [4]
182 .IR repl [1]
183 .IR r [4*4]
184 .IR clipr [4*4]
185 .IR color [4]
186 .br
187 Allocate an image with a given 
188 .I id 
189 on the
190 screen named by
191 .IR screenid .
192 The image will have rectangle
193 .I r 
194 and clipping rectangle
195 .IR clipr .
196 If 
197 .I repl
198 is non-zero, the image's replicate 
199 bit will be set (see
200 .IR draw (2)).
201 .IP
202 .I Refresh
203 specifies the method to be used to draw the window
204 when it is uncovered.
205 .B Refbackup
206 causes the server to maintain a backing store,
207 .B Refnone 
208 does not refresh the image,
209 and
210 .B Refmesg
211 causes a message to be sent via
212 the
213 .B refresh 
214 file
215 .RI ( q.v. ).
216 .IP
217 The image format is described by
218 .IR chan ,
219 a binary version of the channel format string.
220 Specifically, the image format is the catenation of up to four
221 8-bit numbers, each describing a particular image channel.
222 Each of these 8-bit numbers contains a channel type in its
223 high nibble and a bit count in its low nibble.
224 The channel type is one of
225 .BR CRed ,
226 .BR CGreen ,
227 .BR CBlue ,
228 .BR CGrey ,
229 .BR CAlpha ,
230 .BR CMap ,
231 and
232 .BR CIgnore .
233 See
234 .IR image (6).
235 .IP
236 .I Color
237 is the catenation of four 8-bit numbers
238 specifying the red, green, blue, and alpha
239 channels of the color that the new image should
240 be initially filled with.
241 The red channel is in the highest 8 bits, and
242 the alpha in the lowest.
243 Note that color is always in this format, independent of 
244 the image format.
245 .HP
246 .B c
247 .IR dstid [4]
248 .IR repl [1]
249 .IR clipr [4*4]
250 .br
251 Change the replicate bit and clipping rectangle of the 
252 image
253 .IR dstid .
254 This overrides whatever settings were specified in
255 the allocate message.
256 .HP
257 .B d
258 .IR dstid [4]
259 .IR srcid [4]
260 .IR maskid [4]
261 .IR dstr [4*4]
262 .IR srcp [2*4]
263 .IR maskp [2*4]
264 .br
265 Use the 
266 .B draw
267 operator to combine the rectangle 
268 .I dstr
269 of 
270 image
271 .I dstid 
272 with a 
273 rectangle of image
274 .IR srcid ,
275 using a rectangle of image
276 .IR maskid
277 as an alpha mask to further control blending.
278 The three rectangles are congruent and aligned such that
279 the upper left corner
280 .I dstr
281 in image
282 .I dstid
283 corresponds to
284 the point 
285 .I srcp
286 in image
287 .I srcid
288 and
289 the point
290 .I maskp
291 in image
292 .IR maskid .
293 See
294 .IR draw (2).
295 .HP
296 .B D
297 .IR debugon [1]
298 .br
299 If
300 .I debugon
301 is non-zero, enable debugging output.
302 If zero, disable it.
303 The meaning of ``debugging output'' is implementation dependent.
304 .HP
305 .B e
306 .IR dstid [4]
307 .IR srcid [4]
308 .IR c [2*4]
309 .IR a [4]
310 .IR b [4]
311 .IR thick [4]
312 .IR sp [2*4]
313 .IR alpha [4]
314 .IR phi [4]
315 .br
316 Draw an ellipse in image
317 .I dst
318 centered on the point
319 .I c
320 with horizontal and vertical semiaxes
321 .I a
322 and
323 .IR b .
324 The ellipse is drawn using the image
325 .IR src ,
326 with
327 the point
328 .I sp
329 in 
330 .I src
331 aligned with
332 .I c
333 in
334 .IR dst .
335 The ellipse is drawn with thickness
336 .RI 1+2× thick .
337 .IP
338 If the high bit of
339 .I alpha
340 is set, 
341 only the arc of the ellipse from degree angles
342 .I alpha
343 to
344 .I phi 
345 is drawn.
346 For the purposes of drawing the arc,
347 .I alpha
348 is treated as a signed 31-bit number
349 by ignoring its high bit.
350 .HP
351 .B E
352 .IR dstid [4]
353 .IR srcid [4]
354 .IR center [2*4]
355 .IR a [4]
356 .IR b [4]
357 .IR thick [4]
358 .IR sp [2*4]
359 .IR alpha [4]
360 .IR phi [4]
361 .br
362 Draws an ellipse or arc as the
363 .B e
364 message, but rather than outlining it, fills
365 the corresponding sector using the image
366 .IR srcid .
367 The 
368 .I thick 
369 field is ignored, but must be non-negative.
370 .HP
371 .B f
372 .IR id [4]
373 .br
374 Free the resources associated with the image
375 .IR id .
376 .HP
377 .B F
378 .IR id [4]
379 .br
380 Free the the screen with the specified
381 .IR id .
382 Windows on the screen must be freed separately.
383 .HP
384 .B i
385 .IR id [4]
386 .IR n [4]
387 .IR ascent [1]
388 .br
389 Treat the image
390 .I id
391 as a font cache of 
392 .I n
393 character cells, each with
394 ascent
395 .IR ascent .
396 .HP
397 .B l
398 .IR cacheid [4]
399 .IR srcid [4]
400 .IR index [2]
401 .IR r [4*4]
402 .IR sp [2*4]
403 .IR left [1]
404 .IR width [1]
405 .br
406 Load a character into the font cache associated with image
407 .I cacheid
408 at cache position
409 .IR index .
410 The character data is drawn in rectangle
411 .I r
412 of the font cache image
413 and is fetched from
414 the congruent rectangle in image
415 .I srcid
416 with upper left corner
417 .IR sp .
418 .I Width
419 specifies the width of the character\(emthe spacing from this character to the next\(emwhile
420 .I left
421 specifies
422 the horizontal distance from the left side
423 of the character to the left side of the cache image.
424 The dimensions of the image of the character are defined by
425 .IR r .
426 .HP
427 .B L
428 .IR dstid [4]
429 .IR p0 [2*4]
430 .IR p1 [2*4]
431 .IR end0 [4]
432 .IR end1 [4]
433 .IR thick [4]
434 .IR srcid [4]
435 .IR sp [2*4]
436 .br
437 Draw a line of thickness
438 .RI 1+2× thick
439 in image
440 .I dstid
441 from point
442 .I p0
443 to
444 .IR p1 .
445 The line is drawn using the image
446 .IR srcid ,
447 translated so that point
448 .I sp
449 in
450 .I srcid
451 aligns with
452 .I p0
453 in 
454 .IR dstid .
455 The 
456 .I end0
457 and
458 .I end1
459 fields specify whether the corresponding
460 line end should be a square, a disc,
461 or an arrow head.
462 See 
463 .I line
464 in
465 .IR draw (2)
466 for more details.
467 .HP
468 .B N
469 .IR id [4]
470 .IR in [1]
471 .IR j [1]
472 .IR name [ j ]
473 .br
474 If 
475 .I in
476 is non-zero, associate the image
477 .I id
478 with the string
479 .IR name .
480 If 
481 .I in
482 is zero and 
483 .I name
484 already corresponds to the
485 image
486 .IR id ,
487 the association is deleted.
488 .HP
489 .B n
490 .IR id [4]
491 .IR j [1]
492 .IR name [ j ]
493 .br
494 Introduce the identifier 
495 .I id
496 to correspond to the image named
497 by the string
498 .IR name .
499 .HP
500 .B o
501 .IR id [4]
502 .IR r.min [2*4]
503 .IR scr [2*4]
504 .br
505 Position the window 
506 .I id
507 so that its upper left corner is at the
508 point
509 .I scr
510 on its screen.
511 Simultaneously change its internal (logical) coordinate system
512 so that the point
513 .I log
514 corresponds to the upper left corner of the window.
515 .HP
516 .B O
517 .IR op [1]
518 .br
519 Set the compositing operator to
520 .I op
521 for the next draw operation.
522 (The default is
523 .BR SoverD ).
524 .HP
525 .B p
526 .IR dstid [4]
527 .IR n [2]
528 .IR end0 [4]
529 .IR end1 [4]
530 .IR thick [4]
531 .IR srcid [4]
532 .IR sp [2*4]
533 .IR dp [2*2*(n+1)]
534 .br
535 Draw a polygon of thickness
536 .RI 1+2× thick .
537 It is conceptually equivalent to a series of
538 .I n
539 line-drawing messages (see
540 .B L
541 above)
542 joining adjacent points in the list of points
543 .IR dp .
544 The source image
545 .I srcid
546 is translated so that the point
547 .I sp
548 in
549 .I srcid
550 aligns with the first point
551 in the list
552 .IR dp .
553 The polygon need not be closed: 
554 .I end0
555 and
556 .I end1
557 specify the line endings for the first and
558 last point on the polygon.
559 All interior lines have rounded ends
560 to make smooth joins.
561 .HP
562 .B P
563 .IR dstid [4]
564 .IR n [2]
565 .IR wind [4]
566 .IR ignore [2*4]
567 .IR srcid [4]
568 .IR sp [2*4]
569 .IR dp [2*2*(n+1)]
570 .br
571 Draw a polygon as the
572 .B p
573 message, but
574 fill it rather than outlining it.
575 The winding rule parameter
576 .I wind
577 resolves ambiguities about what to fill if the polygon is self-intersecting.
578 If
579 .I wind
580 is
581 .BR ~0 ,
582 a pixel is inside the polygon if the polygon's winding number about the point
583 is non-zero.
584 If
585 .I wind
586 is
587 .BR 1 ,
588 a pixel is inside if the winding number is odd.
589 Complementary values (0 or ~1) cause outside pixels to be filled.
590 The meaning of other values is undefined.
591 The polygon is closed with a line if necessary.
592 .HP
593 .B r
594 .IR id [4]
595 .IR r [4*4]
596 .br
597 Cause the next read of the
598 .B data
599 file to return the image pixel data corresponding to the
600 rectangle
601 .I r
602 in image
603 .IR id .
604 .HP
605 .B s
606 .IR dstid [4]
607 .IR srcid [4]
608 .IR fontid [4]
609 .IR p [2*4]
610 .IR clipr [4*4]
611 .IR sp [2*4]
612 .IR n [2]
613 .IR n*(index [2])
614 .br
615 Draw in the image
616 .I dstid
617 the text string specified by the 
618 .I n 
619 cache
620 .I indices
621 into font
622 .IR fontid ,
623 starting with the upper left corner at point
624 .I p
625 in image
626 .IR dstid .
627 The image drawn is taken from image
628 .IR srcid ,
629 translated to align
630 .I sp
631 in
632 .I srcid
633 with
634 .I dp
635 in
636 .IR dstid.
637 All drawing is confined to the clipping rectangle
638 .I clipr 
639 in
640 .IR dstid .
641 .HP
642 .B x
643 .IR dstid [4]
644 .IR srcid [4]
645 .IR fontid [4]
646 .IR dp [2*4]
647 .IR clipr [4*4]
648 .IR sp [2*4]
649 .IR n [2]
650 .IR bgid [4]
651 .IR bp [2*4]
652 .IR n*(index [2])
653 .br
654 Like the string drawing 
655 .B s
656 command, but fill the background of each character
657 with pixels from image
658 .IR bgid .
659 The image
660 .I bgid
661 is translated so that the point
662 .I bp
663 aligns with the
664 point 
665 .I dp
666 in 
667 .IR dstid .
668 .HP
669 .B S
670 .IR id [4]
671 .IR chan [4]
672 Attach to the public screen with the specified
673 .IR id .
674 It is an error if the screen does not exist, is not public, or does not
675 have the channel descriptor
676 .I chan
677 for its associated image.
678 .HP
679 .B t
680 .IR top [1]
681 .IR n [2]
682 .IR n*id [4]
683 .br
684 Send 
685 .I n
686 windows to the top (if
687 .I t
688 is non-zero) or bottom (if
689 .I t
690 is zero) of the window stack.
691 The window is specified by the list of
692 .I n
693 image
694 .IR id s
695 are moved as a group, maintaining their own order within the stack.
696 .HP
697 .B v
698 .br
699 Flush changes from a soft screen, if any, to the display buffer.
700 .HP
701 .B y
702 .IR id [4]
703 .IR r [4*4]
704 .IR buf [x*1]
705 .br
706 .ti -0.5i
707 .B Y
708 .IR id [4]
709 .IR r [4*4]
710 .IR buf [x*1]
711 .br
712 Replace the rectangle 
713 .I r
714 of pixels in image
715 .I id
716 with the pixel data in 
717 .IR buf .
718 The pixel data must be in the format dictated by
719 .IR id 's
720 image channel descriptor (see
721 .IR image (6)).
722 The 
723 .B y
724 message uses uncompressed data,
725 while the
726 .B Y
727 message uses compressed data. 
728 In either case, 
729 it is an error to include more data than necessary.
730 .PP
731 Reading the
732 .B colormap
733 returns the system color map used on 8-bit displays.
734 Each color map entry consists of a single line containing
735 four space-separated decimal strings.
736 The first is an index into the map, and the remaining three are
737 the red, green, and blue values associated with that index.
738 The color map can be changed by writing entries in the
739 above format to
740 the 
741 .B colormap
742 file.
743 Note that changing the system color map 
744 does not change the color map used for
745 calculations involving
746 .B m8
747 images, which is immutable.
748 .PP
749 The
750 .B refresh
751 file is read-only.
752 As windows owned by the client are uncovered,
753 if they cannot be refreshed by the server (such as when they have
754 refresh functions associated with them), a message is made available
755 on the
756 .B refresh
757 file reporting what needs to be repainted by the client.
758 The message has five decimal integers formatted as in the
759 .B ctl
760 message: the image id of the window and the coordinates of the rectangle
761 that should be refreshed.
762 .SH SOURCE
763 .B /sys/src/9/port/devdraw.c
764 .br
765 .B /sys/src/libmemdraw
766 .SH DIAGNOSTICS
767 Most messages to
768 .B draw
769 can return errors;
770 these can be detected by a system call error
771 on the
772 .IR write (see
773 .IR read (2))
774 of the data containing the erroneous message.
775 The most common error is a failure to allocate
776 because of insufficient free resources.  Most other errors occur
777 only when the protocol is mishandled by the application.
778 .IR Errstr (2)
779 will report details.
780 .SH BUGS
781 The 
782 .B Refmesg
783 refresh method is not fully implemented.
784 .br
785 The
786 .B colormap
787 files only reference the system color map, and as 
788 such should be called
789 .B /dev/colormap
790 rather than
791 .BI /dev/draw/ n /colormap\f1.