memdraw.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /* Portions of this file are Copyright (C) 9front's team.
  10. * See /doc/license/9front-mit for details about the licensing.
  11. * See http://code.9front.org/hg/plan9front/ for a list of authors.
  12. */
  13. #pragma src "/sys/src/lib/memdraw"
  14. #pragma lib "libmemdraw.a"
  15. typedef struct Memimage Memimage;
  16. typedef struct Memdata Memdata;
  17. typedef struct Memsubfont Memsubfont;
  18. typedef struct Memlayer Memlayer;
  19. typedef struct Memcmap Memcmap;
  20. typedef struct Memdrawparam Memdrawparam;
  21. #pragma incomplete Memlayer
  22. /*
  23. * Memdata is allocated from main pool, but .data from the image pool.
  24. * Memdata is allocated separately to permit patching its pointer after
  25. * compaction when windows share the image data.
  26. * The first word of data is a back pointer to the Memdata, to find
  27. * The word to patch.
  28. */
  29. struct Memdata
  30. {
  31. uint32_t *base; /* allocated data pointer */
  32. uint8_t *bdata; /* pointer to first byte of actual data; word-aligned */
  33. int ref; /* number of Memimages using this data */
  34. void* imref;
  35. int allocd; /* is this malloc'd? */
  36. };
  37. enum {
  38. Frepl = 1<<0, /* is replicated */
  39. Fsimple = 1<<1, /* is 1x1 */
  40. Fgrey = 1<<2, /* is grey */
  41. Falpha = 1<<3, /* has explicit alpha */
  42. Fcmap = 1<<4, /* has cmap channel */
  43. Fbytes = 1<<5, /* has only 8-bit channels */
  44. };
  45. struct Memimage
  46. {
  47. Rectangle r; /* rectangle in data area, local coords */
  48. Rectangle clipr; /* clipping region */
  49. int depth; /* number of bits of storage per pixel */
  50. int nchan; /* number of channels */
  51. uint32_t chan; /* channel descriptions */
  52. Memcmap *cmap;
  53. Memdata *data; /* pointer to data; shared by windows in this image */
  54. int zero; /* data->bdata+zero==&byte containing (0,0) */
  55. uint32_t width; /* width in words of a single scan line */
  56. Memlayer *layer; /* nil if not a layer*/
  57. uint32_t flags;
  58. int shift[NChan];
  59. int mask[NChan];
  60. int nbits[NChan];
  61. };
  62. struct Memcmap
  63. {
  64. uint8_t cmap2rgb[3*256];
  65. uint8_t rgb2cmap[16*16*16];
  66. };
  67. /*
  68. * Subfonts
  69. *
  70. * given char c, Subfont *f, Fontchar *i, and Point p, one says
  71. * i = f->info+c;
  72. * draw(b, Rect(p.x+i->left, p.y+i->top,
  73. * p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
  74. * color, f->bits, Pt(i->x, i->top));
  75. * p.x += i->width;
  76. * to draw characters in the specified color (itself a Memimage) in Memimage b.
  77. */
  78. struct Memsubfont
  79. {
  80. char *name;
  81. int16_t n; /* number of chars in font */
  82. uint8_t height; /* height of bitmap */
  83. char ascent; /* top of bitmap to baseline */
  84. Fontchar *info; /* n+1 character descriptors */
  85. Memimage *bits; /* of font */
  86. };
  87. /*
  88. * Encapsulated parameters and information for sub-draw routines.
  89. */
  90. enum {
  91. Simplesrc=1<<0,
  92. Simplemask=1<<1,
  93. Replsrc=1<<2,
  94. Replmask=1<<3,
  95. Fullmask=1<<4,
  96. };
  97. struct Memdrawparam
  98. {
  99. Memimage *dst;
  100. Rectangle r;
  101. Memimage *src;
  102. Rectangle sr;
  103. Memimage *mask;
  104. Rectangle mr;
  105. int op;
  106. uint32_t state;
  107. uint32_t mval; /* if Simplemask, the mask pixel in mask format */
  108. uint32_t mrgba; /* mval in rgba */
  109. uint32_t sval; /* if Simplesrc, the source pixel in src format */
  110. uint32_t srgba; /* sval in rgba */
  111. uint32_t sdval; /* sval in dst format */
  112. };
  113. /*
  114. * Memimage management
  115. */
  116. extern Memimage* allocmemimage(Rectangle, uint32_t);
  117. extern Memimage* allocmemimaged(Rectangle, uint32_t, Memdata*);
  118. extern Memimage* readmemimage(int);
  119. extern Memimage* creadmemimage(int);
  120. extern int writememimage(int, Memimage*);
  121. extern void freememimage(Memimage*);
  122. extern int loadmemimage(Memimage*, Rectangle, uint8_t*, int);
  123. extern int cloadmemimage(Memimage*, Rectangle, uint8_t*, int);
  124. extern int unloadmemimage(Memimage*, Rectangle, uint8_t*, int);
  125. extern uint32_t* wordaddr(Memimage*, Point);
  126. extern uint8_t* byteaddr(Memimage*, Point);
  127. extern int drawclip(Memimage*, Rectangle*, Memimage*, Point*, Memimage*, Point*, Rectangle*, Rectangle*);
  128. extern void memfillcolor(Memimage*, uint32_t);
  129. extern int memsetchan(Memimage*, uint32_t);
  130. /*
  131. * Graphics
  132. */
  133. extern void memdraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
  134. extern void memline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
  135. extern void mempoly(Memimage*, Point*, int, int, int, int, Memimage*, Point, int);
  136. extern void memfillpoly(Memimage*, Point*, int, int, Memimage*, Point, int);
  137. extern void _memfillpolysc(Memimage*, Point*, int, int, Memimage*, Point, int, int, int, int);
  138. extern void memimagedraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
  139. extern int hwdraw(Memdrawparam*);
  140. extern void memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
  141. extern void _memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, Rectangle, int);
  142. extern Point memimagestring(Memimage*, Point, Memimage*, Point, Memsubfont*,
  143. char*);
  144. extern void memellipse(Memimage*, Point, int, int, int, Memimage*, Point, int);
  145. extern void memarc(Memimage*, Point, int, int, int, Memimage*, Point, int, int, int);
  146. extern Rectangle memlinebbox(Point, Point, int, int, int);
  147. extern int memlineendsize(int);
  148. extern void _memmkcmap(void);
  149. extern int memimageinit(void);
  150. /*
  151. * Subfont management
  152. */
  153. extern Memsubfont* allocmemsubfont(char*, int, int, int,
  154. Fontchar*, Memimage*);
  155. extern Memsubfont* openmemsubfont(char*);
  156. extern void freememsubfont(Memsubfont*);
  157. extern Point memsubfontwidth(Memsubfont*, char*);
  158. extern Memsubfont* getmemdefont(void);
  159. /*
  160. * Predefined
  161. */
  162. extern Memimage* memwhite;
  163. extern Memimage* memblack;
  164. extern Memimage* memopaque;
  165. extern Memimage* memtransparent;
  166. extern Memcmap *memdefcmap;
  167. /*
  168. * Kernel interface
  169. */
  170. void memimagemove(void*, void*);
  171. /*
  172. * Kernel cruft
  173. */
  174. extern void rdb(void);
  175. extern int iprint(char*, ...);
  176. #pragma varargck argpos iprint 1
  177. extern int drawdebug;
  178. /*
  179. * doprint interface: numbconv bit strings
  180. */
  181. #pragma varargck type "llb" vlong
  182. #pragma varargck type "llb" uvlong
  183. #pragma varargck type "lb" long
  184. #pragma varargck type "lb" ulong
  185. #pragma varargck type "b" int
  186. #pragma varargck type "b" uint32_t