glamor_glyphs.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  1. /*
  2. * Copyright © 2008 Red Hat, Inc.
  3. * Partly based on code Copyright © 2000 SuSE, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of Red Hat not be used in advertising or
  10. * publicity pertaining to distribution of the software without specific,
  11. * written prior permission. Red Hat makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as is"
  13. * without express or implied warranty.
  14. *
  15. * Red Hat DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL Red Hat
  17. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  18. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  19. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  20. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21. *
  22. * Permission to use, copy, modify, distribute, and sell this software and its
  23. * documentation for any purpose is hereby granted without fee, provided that
  24. * the above copyright notice appear in all copies and that both that
  25. * copyright notice and this permission notice appear in supporting
  26. * documentation, and that the name of SuSE not be used in advertising or
  27. * publicity pertaining to distribution of the software without specific,
  28. * written prior permission. SuSE makes no representations about the
  29. * suitability of this software for any purpose. It is provided "as is"
  30. * without express or implied warranty.
  31. *
  32. * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  33. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
  34. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  35. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  36. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  37. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  38. *
  39. * Author: Owen Taylor <otaylor@fishsoup.net>
  40. * Based on code by: Keith Packard
  41. */
  42. #include <stdlib.h>
  43. #include "glamor_priv.h"
  44. #include <mipict.h>
  45. #if DEBUG_GLYPH_CACHE
  46. #define DBG_GLYPH_CACHE(a) ErrorF a
  47. #else
  48. #define DBG_GLYPH_CACHE(a)
  49. #endif
  50. /* Width of the pixmaps we use for the caches; this should be less than
  51. * max texture size of the driver; this may need to actually come from
  52. * the driver.
  53. */
  54. /* Maximum number of glyphs we buffer on the stack before flushing
  55. * rendering to the mask or destination surface.
  56. */
  57. #define GLYPH_BUFFER_SIZE 1024
  58. #define CACHE_PICTURE_SIZE 1024
  59. #define GLYPH_MIN_SIZE 8
  60. #define GLYPH_MAX_SIZE 64
  61. #define GLYPH_CACHE_SIZE ((CACHE_PICTURE_SIZE) * CACHE_PICTURE_SIZE / (GLYPH_MIN_SIZE * GLYPH_MIN_SIZE))
  62. #define MASK_CACHE_MAX_SIZE 32
  63. #define MASK_CACHE_WIDTH (CACHE_PICTURE_SIZE / MASK_CACHE_MAX_SIZE)
  64. #define MASK_CACHE_MASK ((1LL << (MASK_CACHE_WIDTH)) - 1)
  65. typedef struct {
  66. PicturePtr source;
  67. glamor_composite_rect_t rects[GLYPH_BUFFER_SIZE + 4];
  68. int count;
  69. } glamor_glyph_buffer_t;
  70. struct glamor_glyph {
  71. glamor_glyph_cache_t *cache;
  72. uint16_t x, y;
  73. uint16_t size, pos;
  74. unsigned long long left_x1_map, left_x2_map;
  75. unsigned long long right_x1_map, right_x2_map; /* Use to check real intersect or not. */
  76. Bool has_edge_map;
  77. Bool cached;
  78. };
  79. typedef enum {
  80. GLAMOR_GLYPH_SUCCESS, /* Glyph added to render buffer */
  81. GLAMOR_GLYPH_FAIL, /* out of memory, etc */
  82. GLAMOR_GLYPH_NEED_FLUSH, /* would evict a glyph already in the buffer */
  83. } glamor_glyph_cache_result_t;
  84. #define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0)
  85. static DevPrivateKeyRec glamor_glyph_key;
  86. static inline struct glamor_glyph *
  87. glamor_glyph_get_private(GlyphPtr glyph)
  88. {
  89. return (struct glamor_glyph *) glyph->devPrivates;
  90. }
  91. /*
  92. * Mask cache is located at the corresponding cache picture's last row.
  93. * and is deadicated for the mask picture when do the glyphs_via_mask.
  94. *
  95. * As we split the glyphs list according to its overlapped or non-overlapped,
  96. * we can reduce the length of glyphs to do the glyphs_via_mask to 2 or 3
  97. * glyphs one time for most cases. Thus it give us a case to allocate a
  98. * small portion of the corresponding cache directly as the mask picture.
  99. * Then we can rendering the glyphs to this mask picture, and latter we
  100. * can accumulate the second steps, composite the mask to the dest with
  101. * the other non-overlapped glyphs's rendering process.
  102. * Another major benefit is we now only need to clear a relatively small mask
  103. * region then before. It also make us implement a bunch mask picture clearing
  104. * algorithm to avoid too frequently small region clearing.
  105. *
  106. * If there is no any overlapping, this method will not get performance gain.
  107. * If there is some overlapping, then this algorithm can get about 15% performance
  108. * gain.
  109. */
  110. struct glamor_glyph_mask_cache_entry {
  111. int idx;
  112. int width;
  113. int height;
  114. int x;
  115. int y;
  116. };
  117. static struct glamor_glyph_mask_cache {
  118. PixmapPtr pixmap;
  119. struct glamor_glyph_mask_cache_entry mcache[MASK_CACHE_WIDTH];
  120. unsigned int free_bitmap;
  121. unsigned int cleared_bitmap;
  122. } *mask_cache[GLAMOR_NUM_GLYPH_CACHE_FORMATS] = {
  123. NULL};
  124. static void
  125. clear_mask_cache_bitmap(struct glamor_glyph_mask_cache *maskcache,
  126. unsigned int clear_mask_bits)
  127. {
  128. unsigned int i = 0;
  129. BoxRec box[MASK_CACHE_WIDTH];
  130. int box_cnt = 0;
  131. assert((clear_mask_bits & ~MASK_CACHE_MASK) == 0);
  132. for (i = 0; i < MASK_CACHE_WIDTH; i++) {
  133. if (clear_mask_bits & (1 << i)) {
  134. box[box_cnt].x1 = maskcache->mcache[i].x;
  135. box[box_cnt].x2 = maskcache->mcache[i].x + MASK_CACHE_MAX_SIZE;
  136. box[box_cnt].y1 = maskcache->mcache[i].y;
  137. box[box_cnt].y2 = maskcache->mcache[i].y + MASK_CACHE_MAX_SIZE;
  138. box_cnt++;
  139. }
  140. }
  141. glamor_solid_boxes(maskcache->pixmap, box, box_cnt, 0);
  142. maskcache->cleared_bitmap |= clear_mask_bits;
  143. }
  144. static void
  145. clear_mask_cache(struct glamor_glyph_mask_cache *maskcache)
  146. {
  147. int x = 0;
  148. int cnt = MASK_CACHE_WIDTH;
  149. unsigned int i = 0;
  150. struct glamor_glyph_mask_cache_entry *mce;
  151. glamor_solid(maskcache->pixmap, 0, CACHE_PICTURE_SIZE, CACHE_PICTURE_SIZE,
  152. MASK_CACHE_MAX_SIZE, GXcopy, 0xFFFFFFFF, 0);
  153. mce = &maskcache->mcache[0];
  154. while (cnt--) {
  155. mce->width = 0;
  156. mce->height = 0;
  157. mce->x = x;
  158. mce->y = CACHE_PICTURE_SIZE;
  159. mce->idx = i++;
  160. x += MASK_CACHE_MAX_SIZE;
  161. mce++;
  162. }
  163. maskcache->free_bitmap = MASK_CACHE_MASK;
  164. maskcache->cleared_bitmap = MASK_CACHE_MASK;
  165. }
  166. static int
  167. find_continuous_bits(unsigned int bits, int bits_cnt, unsigned int *pbits_mask)
  168. {
  169. int idx = 0;
  170. unsigned int bits_mask;
  171. bits_mask = ((1LL << bits_cnt) - 1);
  172. if (_X_UNLIKELY(bits_cnt > 56)) {
  173. while (bits) {
  174. if ((bits & bits_mask) == bits_mask) {
  175. *pbits_mask = bits_mask << idx;
  176. return idx;
  177. }
  178. bits >>= 1;
  179. idx++;
  180. }
  181. }
  182. else {
  183. idx = __fls(bits);
  184. while (bits) {
  185. unsigned int temp_bits;
  186. temp_bits = bits_mask << (idx - bits_cnt + 1);
  187. if ((bits & temp_bits) == temp_bits) {
  188. *pbits_mask = temp_bits;
  189. return (idx - bits_cnt + 1);
  190. }
  191. /* Find first zero. And clear the tested bit. */
  192. bits &= ~(1LL << idx);
  193. idx = __fls(~bits);
  194. bits &= ~((1LL << idx) - 1);
  195. idx--;
  196. }
  197. }
  198. return -1;
  199. }
  200. static struct glamor_glyph_mask_cache_entry *
  201. get_mask_cache(struct glamor_glyph_mask_cache *maskcache, int blocks)
  202. {
  203. int free_cleared_bit, idx = -1;
  204. int retry_cnt = 0;
  205. unsigned int bits_mask = 0;
  206. if (maskcache->free_bitmap == 0)
  207. return NULL;
  208. retry:
  209. free_cleared_bit = maskcache->free_bitmap & maskcache->cleared_bitmap;
  210. if (free_cleared_bit && blocks == 1) {
  211. idx = __fls(free_cleared_bit);
  212. bits_mask = 1 << idx;
  213. }
  214. else if (free_cleared_bit && blocks > 1) {
  215. idx = find_continuous_bits(free_cleared_bit, blocks, &bits_mask);
  216. }
  217. if (idx < 0) {
  218. clear_mask_cache_bitmap(maskcache, maskcache->free_bitmap);
  219. if (retry_cnt++ > 2)
  220. return NULL;
  221. goto retry;
  222. }
  223. maskcache->cleared_bitmap &= ~bits_mask;
  224. maskcache->free_bitmap &= ~bits_mask;
  225. DEBUGF("get idx %d free %x clear %x \n",
  226. idx, maskcache->free_bitmap, maskcache->cleared_bitmap);
  227. return &maskcache->mcache[idx];
  228. }
  229. static void
  230. put_mask_cache_bitmap(struct glamor_glyph_mask_cache *maskcache,
  231. unsigned int bitmap)
  232. {
  233. maskcache->free_bitmap |= bitmap;
  234. DEBUGF("put bitmap %x free %x clear %x \n",
  235. bitmap, maskcache->free_bitmap, maskcache->cleared_bitmap);
  236. }
  237. static void
  238. glamor_unrealize_glyph_caches(ScreenPtr pScreen)
  239. {
  240. glamor_screen_private *glamor = glamor_get_screen_private(pScreen);
  241. int i;
  242. if (!glamor->glyph_cache_initialized)
  243. return;
  244. for (i = 0; i < GLAMOR_NUM_GLYPH_CACHE_FORMATS; i++) {
  245. glamor_glyph_cache_t *cache = &glamor->glyphCaches[i];
  246. if (cache->picture)
  247. FreePicture(cache->picture, 0);
  248. if (cache->glyphs)
  249. free(cache->glyphs);
  250. if (mask_cache[i])
  251. free(mask_cache[i]);
  252. }
  253. glamor->glyph_cache_initialized = FALSE;
  254. }
  255. void
  256. glamor_glyphs_fini(ScreenPtr pScreen)
  257. {
  258. glamor_unrealize_glyph_caches(pScreen);
  259. }
  260. /* All caches for a single format share a single pixmap for glyph storage,
  261. * allowing mixing glyphs of different sizes without paying a penalty
  262. * for switching between source pixmaps. (Note that for a size of font
  263. * right at the border between two sizes, we might be switching for almost
  264. * every glyph.)
  265. *
  266. * This function allocates the storage pixmap, and then fills in the
  267. * rest of the allocated structures for all caches with the given format.
  268. */
  269. Bool
  270. glamor_realize_glyph_caches(ScreenPtr pScreen)
  271. {
  272. glamor_screen_private *glamor = glamor_get_screen_private(pScreen);
  273. unsigned int formats[] = {
  274. PIXMAN_a8,
  275. PIXMAN_a8r8g8b8,
  276. };
  277. int i;
  278. memset(glamor->glyphCaches, 0, sizeof(glamor->glyphCaches));
  279. for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++) {
  280. glamor_glyph_cache_t *cache = &glamor->glyphCaches[i];
  281. PixmapPtr pixmap;
  282. PicturePtr picture;
  283. XID component_alpha;
  284. int depth = PIXMAN_FORMAT_DEPTH(formats[i]);
  285. int error;
  286. PictFormatPtr pPictFormat =
  287. PictureMatchFormat(pScreen, depth, formats[i]);
  288. if (!pPictFormat)
  289. goto bail;
  290. /* Now allocate the pixmap and picture */
  291. pixmap = pScreen->CreatePixmap(pScreen,
  292. CACHE_PICTURE_SIZE,
  293. CACHE_PICTURE_SIZE + MASK_CACHE_MAX_SIZE,
  294. depth, GLAMOR_CREATE_NO_LARGE);
  295. if (!pixmap)
  296. goto bail;
  297. component_alpha = NeedsComponent(pPictFormat->format);
  298. picture = CreatePicture(0, &pixmap->drawable, pPictFormat,
  299. CPComponentAlpha, &component_alpha,
  300. serverClient, &error);
  301. pScreen->DestroyPixmap(pixmap);
  302. if (!picture)
  303. goto bail;
  304. ValidatePicture(picture);
  305. cache->picture = picture;
  306. cache->glyphs = calloc(sizeof(GlyphPtr), GLYPH_CACHE_SIZE);
  307. if (!cache->glyphs)
  308. goto bail;
  309. cache->evict = rand() % GLYPH_CACHE_SIZE;
  310. mask_cache[i] = calloc(1, sizeof(*mask_cache[i]));
  311. mask_cache[i]->pixmap = pixmap;
  312. clear_mask_cache(mask_cache[i]);
  313. }
  314. assert(i == GLAMOR_NUM_GLYPH_CACHE_FORMATS);
  315. return TRUE;
  316. bail:
  317. glamor_unrealize_glyph_caches(pScreen);
  318. return FALSE;
  319. }
  320. /**
  321. * Called by glamor_create_screen_resources() to set up the glyph cache.
  322. *
  323. * This was previously required to be called by the drivers, but not
  324. * as of the xserver 1.16 ABI.
  325. */
  326. Bool
  327. glamor_glyphs_init(ScreenPtr pScreen)
  328. {
  329. glamor_screen_private *glamor = glamor_get_screen_private(pScreen);
  330. if (glamor->glyph_cache_initialized)
  331. return TRUE;
  332. if (!dixRegisterPrivateKey(&glamor_glyph_key,
  333. PRIVATE_GLYPH, sizeof(struct glamor_glyph)))
  334. return FALSE;
  335. glamor->glyph_cache_initialized = TRUE;
  336. return TRUE;
  337. }
  338. /* The most efficient thing to way to upload the glyph to the screen
  339. * is to use CopyArea; glamor pixmaps are always offscreen.
  340. */
  341. static void
  342. glamor_glyph_cache_upload_glyph(ScreenPtr screen,
  343. glamor_glyph_cache_t *cache,
  344. GlyphPtr glyph, int x, int y)
  345. {
  346. PicturePtr pGlyphPicture = GlyphPicture(glyph)[screen->myNum];
  347. PixmapPtr pGlyphPixmap = (PixmapPtr) pGlyphPicture->pDrawable;
  348. PixmapPtr pCachePixmap = (PixmapPtr) cache->picture->pDrawable;
  349. PixmapPtr scratch;
  350. BoxRec box;
  351. GCPtr gc;
  352. gc = GetScratchGC(pCachePixmap->drawable.depth, screen);
  353. if (!gc)
  354. return;
  355. ValidateGC(&pCachePixmap->drawable, gc);
  356. scratch = pGlyphPixmap;
  357. if (pGlyphPixmap->drawable.depth != pCachePixmap->drawable.depth) {
  358. scratch = glamor_create_pixmap(screen,
  359. glyph->info.width,
  360. glyph->info.height,
  361. pCachePixmap->drawable.depth, 0);
  362. if (scratch) {
  363. PicturePtr picture;
  364. int error;
  365. picture =
  366. CreatePicture(0,
  367. &scratch->drawable,
  368. PictureMatchFormat
  369. (screen,
  370. pCachePixmap->drawable.depth,
  371. cache->picture->format),
  372. 0, NULL, serverClient, &error);
  373. if (picture) {
  374. ValidatePicture(picture);
  375. glamor_composite(PictOpSrc,
  376. pGlyphPicture,
  377. NULL, picture,
  378. 0, 0, 0, 0, 0,
  379. 0, glyph->info.width, glyph->info.height);
  380. FreePicture(picture, 0);
  381. }
  382. }
  383. else {
  384. scratch = pGlyphPixmap;
  385. }
  386. }
  387. box.x1 = x;
  388. box.y1 = y;
  389. box.x2 = x + glyph->info.width;
  390. box.y2 = y + glyph->info.height;
  391. glamor_copy_n_to_n_nf(&scratch->drawable,
  392. &pCachePixmap->drawable, NULL,
  393. &box, 1, -x, -y, FALSE, FALSE, 0, NULL);
  394. if (scratch != pGlyphPixmap)
  395. screen->DestroyPixmap(scratch);
  396. FreeScratchGC(gc);
  397. }
  398. void
  399. glamor_glyph_unrealize(ScreenPtr screen, GlyphPtr glyph)
  400. {
  401. struct glamor_glyph *priv;
  402. /* Use Lookup in case we have not attached to this glyph. */
  403. priv = glamor_glyph_get_private(glyph);
  404. if (priv->cached)
  405. priv->cache->glyphs[priv->pos] = NULL;
  406. }
  407. /* Cut and paste from render/glyph.c - probably should export it instead */
  408. static void
  409. glamor_glyph_extents(int nlist,
  410. GlyphListPtr list, GlyphPtr *glyphs, BoxPtr extents)
  411. {
  412. int x1, x2, y1, y2;
  413. int x, y, n;
  414. x1 = y1 = MAXSHORT;
  415. x2 = y2 = MINSHORT;
  416. x = y = 0;
  417. while (nlist--) {
  418. x += list->xOff;
  419. y += list->yOff;
  420. n = list->len;
  421. list++;
  422. while (n--) {
  423. GlyphPtr glyph = *glyphs++;
  424. int v;
  425. v = x - glyph->info.x;
  426. if (v < x1)
  427. x1 = v;
  428. v += glyph->info.width;
  429. if (v > x2)
  430. x2 = v;
  431. v = y - glyph->info.y;
  432. if (v < y1)
  433. y1 = v;
  434. v += glyph->info.height;
  435. if (v > y2)
  436. y2 = v;
  437. x += glyph->info.xOff;
  438. y += glyph->info.yOff;
  439. }
  440. }
  441. extents->x1 = x1 < MINSHORT ? MINSHORT : x1;
  442. extents->x2 = x2 > MAXSHORT ? MAXSHORT : x2;
  443. extents->y1 = y1 < MINSHORT ? MINSHORT : y1;
  444. extents->y2 = y2 > MAXSHORT ? MAXSHORT : y2;
  445. }
  446. static void
  447. glamor_glyph_priv_get_edge_map(GlyphPtr glyph, struct glamor_glyph *priv,
  448. PicturePtr glyph_picture)
  449. {
  450. PixmapPtr glyph_pixmap = (PixmapPtr) glyph_picture->pDrawable;
  451. int j;
  452. unsigned long long left_x1_map = 0, left_x2_map = 0;
  453. unsigned long long right_x1_map = 0, right_x2_map = 0;
  454. int bitsPerPixel;
  455. int stride;
  456. void *bits;
  457. int width;
  458. unsigned int left_x1_data = 0, left_x2_data = 0;
  459. unsigned int right_x1_data = 0, right_x2_data = 0;
  460. bitsPerPixel = glyph_pixmap->drawable.bitsPerPixel;
  461. stride = glyph_pixmap->devKind;
  462. bits = glyph_pixmap->devPrivate.ptr;
  463. width = glyph->info.width;
  464. if (glyph_pixmap->drawable.width < 2
  465. || !(glyph_pixmap->drawable.depth == 8
  466. || glyph_pixmap->drawable.depth == 1
  467. || glyph_pixmap->drawable.depth == 32)) {
  468. priv->has_edge_map = FALSE;
  469. return;
  470. }
  471. left_x1_map = left_x2_map = 0;
  472. right_x1_map = right_x2_map = 0;
  473. for (j = 0; j < glyph_pixmap->drawable.height; j++) {
  474. if (bitsPerPixel == 8) {
  475. unsigned char *data;
  476. data = (unsigned char *) ((unsigned char *) bits + stride * j);
  477. left_x1_data = *data++;
  478. left_x2_data = *data;
  479. data =
  480. (unsigned char *) ((unsigned char *) bits + stride * j + width -
  481. 2);
  482. right_x1_data = *data++;
  483. right_x2_data = *data;
  484. }
  485. else if (bitsPerPixel == 32) {
  486. left_x1_data = *((unsigned int *) bits + stride / 4 * j);
  487. left_x2_data = *((unsigned int *) bits + stride / 4 * j + 1);
  488. right_x1_data =
  489. *((unsigned int *) bits + stride / 4 * j + width - 2);
  490. right_x2_data =
  491. *((unsigned int *) bits + stride / 4 * j + width - 1);
  492. }
  493. else if (bitsPerPixel == 1) {
  494. unsigned char temp;
  495. temp = *((unsigned char *) glyph_pixmap->devPrivate.ptr
  496. + glyph_pixmap->devKind * j) & 0x3;
  497. left_x1_data = temp & 0x1;
  498. left_x2_data = temp & 0x2;
  499. temp = *((unsigned char *) glyph_pixmap->devPrivate.ptr
  500. + glyph_pixmap->devKind * j
  501. + (glyph_pixmap->drawable.width - 2) / 8);
  502. right_x1_data = temp
  503. & (1 << ((glyph_pixmap->drawable.width - 2) % 8));
  504. temp = *((unsigned char *) glyph_pixmap->devPrivate.ptr
  505. + glyph_pixmap->devKind * j
  506. + (glyph_pixmap->drawable.width - 1) / 8);
  507. right_x2_data = temp
  508. & (1 << ((glyph_pixmap->drawable.width - 1) % 8));
  509. }
  510. left_x1_map |= (left_x1_data != 0) << j;
  511. left_x2_map |= (left_x2_data != 0) << j;
  512. right_x1_map |= (right_x1_data != 0) << j;
  513. right_x2_map |= (right_x2_data != 0) << j;
  514. }
  515. priv->left_x1_map = left_x1_map;
  516. priv->left_x2_map = left_x2_map;
  517. priv->right_x1_map = right_x1_map;
  518. priv->right_x2_map = right_x2_map;
  519. priv->has_edge_map = TRUE;
  520. return;
  521. }
  522. /**
  523. * Returns TRUE if the glyphs in the lists intersect. Only checks based on
  524. * bounding box, which appears to be good enough to catch most cases at least.
  525. */
  526. #define INTERSECTED_TYPE_MASK 1
  527. #define NON_INTERSECTED 0
  528. #define INTERSECTED 1
  529. struct glamor_glyph_list {
  530. int nlist;
  531. GlyphListPtr list;
  532. GlyphPtr *glyphs;
  533. int type;
  534. };
  535. static Bool
  536. glyph_new_fixed_list(struct glamor_glyph_list *fixed_list,
  537. GlyphPtr *cur_glyphs,
  538. GlyphPtr ** head_glyphs,
  539. GlyphListPtr cur_list,
  540. int cur_pos, int cur_x, int cur_y,
  541. int x1, int y1, int x2, int y2,
  542. GlyphListPtr *head_list,
  543. int *head_pos,
  544. int *head_x,
  545. int *head_y, int *fixed_cnt, int type, BoxPtr prev_extents)
  546. {
  547. int x_off = 0;
  548. int y_off = 0;
  549. int n_off = 0;
  550. int list_cnt;
  551. if (type == NON_INTERSECTED) {
  552. if (x1 < prev_extents->x2 && x2 > prev_extents->x1
  553. && y1 < prev_extents->y2 && y2 > prev_extents->y1)
  554. return FALSE;
  555. x_off = (*(cur_glyphs - 1))->info.xOff;
  556. y_off = (*(cur_glyphs - 1))->info.yOff;
  557. n_off = 1;
  558. }
  559. list_cnt = cur_list - *head_list + 1;
  560. if (cur_pos <= n_off) {
  561. DEBUGF("break at %d n_off %d\n", cur_pos, n_off);
  562. list_cnt--;
  563. if (cur_pos < n_off) {
  564. /* we overlap with previous list's last glyph. */
  565. x_off += cur_list->xOff;
  566. y_off += cur_list->yOff;
  567. cur_list--;
  568. cur_pos = cur_list->len;
  569. if (cur_pos <= n_off) {
  570. list_cnt--;
  571. }
  572. }
  573. }
  574. DEBUGF("got %d lists\n", list_cnt);
  575. if (list_cnt != 0) {
  576. fixed_list->list = malloc(list_cnt * sizeof(*cur_list));
  577. memcpy(fixed_list->list, *head_list, list_cnt * sizeof(*cur_list));
  578. fixed_list->list[0].xOff = *head_x;
  579. fixed_list->list[0].yOff = *head_y;
  580. fixed_list->glyphs = *head_glyphs;
  581. fixed_list->type = type & INTERSECTED_TYPE_MASK;
  582. fixed_list->nlist = list_cnt;
  583. if (cur_list != *head_list) {
  584. fixed_list->list[0].len = (*head_list)->len - *head_pos;
  585. if (cur_pos != n_off)
  586. fixed_list->list[list_cnt - 1].len = cur_pos - n_off;
  587. }
  588. else
  589. fixed_list->list[0].len = cur_pos - *head_pos - n_off;
  590. (*fixed_cnt)++;
  591. }
  592. if (type <= INTERSECTED) {
  593. *head_list = cur_list;
  594. *head_pos = cur_pos - n_off;
  595. *head_x = cur_x - x_off;
  596. *head_y = cur_y - y_off;
  597. *head_glyphs = cur_glyphs - n_off;
  598. }
  599. return TRUE;
  600. }
  601. /*
  602. * This function detects glyph lists's overlapping.
  603. *
  604. * If check_fake_overlap is set, then it will check the glyph's left
  605. * and right small boxes's real overlapping pixels. And if there is
  606. * no real pixel overlapping, then it will not be treated as overlapped
  607. * case. And we also can configured it to ignore less than 2 pixels
  608. * overlappig.
  609. *
  610. * This function analyzes all the lists and split the list to multiple
  611. * lists which are pure overlapped glyph lists or pure non-overlapped
  612. * list if the overlapping only ocurr on the two adjacent glyphs.
  613. * Otherwise, it return -1.
  614. *
  615. **/
  616. static int
  617. glamor_glyphs_intersect(int nlist, GlyphListPtr list, GlyphPtr *glyphs,
  618. PictFormatShort mask_format,
  619. ScreenPtr screen, Bool check_fake_overlap,
  620. struct glamor_glyph_list *fixed_list, int fixed_size)
  621. {
  622. int x1, x2, y1, y2;
  623. int n;
  624. int x, y;
  625. BoxPtr extents;
  626. BoxRec prev_extents;
  627. Bool first = TRUE, first_list = TRUE;
  628. Bool need_free_list_region = FALSE;
  629. Bool need_free_fixed_list = FALSE;
  630. struct glamor_glyph *priv = NULL;
  631. Bool in_non_intersected_list = -1;
  632. GlyphListPtr head_list;
  633. int head_x, head_y, head_pos;
  634. int fixed_cnt = 0;
  635. GlyphPtr *head_glyphs;
  636. GlyphListPtr cur_list = list;
  637. RegionRec list_region;
  638. RegionRec current_region;
  639. BoxRec current_box;
  640. if (nlist > 1) {
  641. pixman_region_init(&list_region);
  642. need_free_list_region = TRUE;
  643. }
  644. pixman_region_init(&current_region);
  645. extents = pixman_region_extents(&current_region);
  646. x = 0;
  647. y = 0;
  648. x1 = x2 = y1 = y2 = 0;
  649. n = 0;
  650. extents->x1 = 0;
  651. extents->y1 = 0;
  652. extents->x2 = 0;
  653. extents->y2 = 0;
  654. head_list = list;
  655. DEBUGF("has %d lists.\n", nlist);
  656. while (nlist--) {
  657. BoxRec left_box, right_box = { 0 };
  658. Bool has_left_edge_box = FALSE, has_right_edge_box = FALSE;
  659. Bool left_to_right;
  660. struct glamor_glyph *left_priv = NULL, *right_priv = NULL;
  661. x += list->xOff;
  662. y += list->yOff;
  663. n = list->len;
  664. left_to_right = TRUE;
  665. cur_list = list++;
  666. if (_X_UNLIKELY(!first_list)) {
  667. pixman_region_init_with_extents(&current_region, extents);
  668. pixman_region_union(&list_region, &list_region, &current_region);
  669. first = TRUE;
  670. }
  671. else {
  672. head_list = cur_list;
  673. head_pos = cur_list->len - n;
  674. head_x = x;
  675. head_y = y;
  676. head_glyphs = glyphs;
  677. }
  678. DEBUGF("current list %p has %d glyphs\n", cur_list, n);
  679. while (n--) {
  680. GlyphPtr glyph = *glyphs++;
  681. DEBUGF("the %dth glyph\n", cur_list->len - n - 1);
  682. if (glyph->info.width == 0 || glyph->info.height == 0) {
  683. x += glyph->info.xOff;
  684. y += glyph->info.yOff;
  685. continue;
  686. }
  687. if (mask_format
  688. && mask_format != GlyphPicture(glyph)[screen->myNum]->format) {
  689. need_free_fixed_list = TRUE;
  690. goto done;
  691. }
  692. x1 = x - glyph->info.x;
  693. if (x1 < MINSHORT)
  694. x1 = MINSHORT;
  695. y1 = y - glyph->info.y;
  696. if (y1 < MINSHORT)
  697. y1 = MINSHORT;
  698. if (check_fake_overlap)
  699. priv = glamor_glyph_get_private(glyph);
  700. x2 = x1 + glyph->info.width;
  701. y2 = y1 + glyph->info.height;
  702. if (x2 > MAXSHORT)
  703. x2 = MAXSHORT;
  704. if (y2 > MAXSHORT)
  705. y2 = MAXSHORT;
  706. if (first) {
  707. extents->x1 = x1;
  708. extents->y1 = y1;
  709. extents->x2 = x2;
  710. extents->y2 = y2;
  711. prev_extents = *extents;
  712. first = FALSE;
  713. if (check_fake_overlap && priv
  714. && priv->has_edge_map && glyph->info.yOff == 0) {
  715. left_box.x1 = x1;
  716. left_box.x2 = x1 + 1;
  717. left_box.y1 = y1;
  718. right_box.x1 = x2 - 2;
  719. right_box.x2 = x2 - 1;
  720. right_box.y1 = y1;
  721. left_priv = right_priv = priv;
  722. has_left_edge_box = TRUE;
  723. has_right_edge_box = TRUE;
  724. }
  725. }
  726. else {
  727. if (_X_UNLIKELY(!first_list)) {
  728. current_box.x1 = x1;
  729. current_box.y1 = y1;
  730. current_box.x2 = x2;
  731. current_box.y2 = y2;
  732. if (pixman_region_contains_rectangle
  733. (&list_region, &current_box) != PIXMAN_REGION_OUT) {
  734. need_free_fixed_list = TRUE;
  735. goto done;
  736. }
  737. }
  738. if (x1 < extents->x2 && x2 > extents->x1
  739. && y1 < extents->y2 && y2 > extents->y1) {
  740. if (check_fake_overlap &&
  741. (has_left_edge_box || has_right_edge_box)
  742. && priv->has_edge_map && glyph->info.yOff == 0) {
  743. int left_dx, right_dx;
  744. unsigned long long intersected;
  745. left_dx = has_left_edge_box ? 1 : 0;
  746. right_dx = has_right_edge_box ? 1 : 0;
  747. if (x1 + 1 < extents->x2 - right_dx &&
  748. x2 - 1 > extents->x1 + left_dx)
  749. goto real_intersected;
  750. if (left_to_right && has_right_edge_box) {
  751. if (x1 == right_box.x1) {
  752. intersected =
  753. ((priv->left_x1_map & right_priv->
  754. right_x1_map)
  755. | (priv->left_x2_map & right_priv->
  756. right_x2_map));
  757. if (intersected)
  758. goto real_intersected;
  759. }
  760. else if (x1 == right_box.x2) {
  761. intersected =
  762. (priv->left_x1_map & right_priv->
  763. right_x2_map);
  764. if (intersected) {
  765. #ifdef GLYPHS_EDEGE_OVERLAP_LOOSE_CHECK
  766. /* tolerate with two pixels overlap. */
  767. intersected &= ~(1 << __fls(intersected));
  768. if ((intersected & (intersected - 1)))
  769. #endif
  770. goto real_intersected;
  771. }
  772. }
  773. }
  774. else if (!left_to_right && has_left_edge_box) {
  775. if (x2 - 1 == left_box.x1) {
  776. intersected =
  777. (priv->right_x2_map & left_priv->
  778. left_x1_map);
  779. if (intersected) {
  780. #ifdef GLYPHS_EDEGE_OVERLAP_LOOSE_CHECK
  781. /* tolerate with two pixels overlap. */
  782. intersected &= ~(1 << __fls(intersected));
  783. if ((intersected & (intersected - 1)))
  784. #endif
  785. goto real_intersected;
  786. }
  787. }
  788. else if (x2 - 1 == right_box.x2) {
  789. if ((priv->right_x1_map & left_priv->
  790. left_x1_map)
  791. || (priv->right_x2_map & left_priv->
  792. left_x2_map))
  793. goto real_intersected;
  794. }
  795. }
  796. else {
  797. if (x1 < extents->x2 && x1 + 2 > extents->x1)
  798. goto real_intersected;
  799. }
  800. goto non_intersected;
  801. }
  802. else {
  803. real_intersected:
  804. DEBUGF("overlap with previous glyph.\n");
  805. if (in_non_intersected_list == 1) {
  806. if (fixed_cnt >= fixed_size) {
  807. need_free_fixed_list = TRUE;
  808. goto done;
  809. }
  810. if (!glyph_new_fixed_list(&fixed_list[fixed_cnt],
  811. glyphs - 1,
  812. &head_glyphs,
  813. cur_list,
  814. cur_list->len - (n + 1),
  815. x, y, x1, y1, x2, y2,
  816. &head_list, &head_pos,
  817. &head_x, &head_y,
  818. &fixed_cnt,
  819. NON_INTERSECTED,
  820. &prev_extents)) {
  821. need_free_fixed_list = TRUE;
  822. goto done;
  823. }
  824. }
  825. in_non_intersected_list = 0;
  826. }
  827. }
  828. else {
  829. non_intersected:
  830. DEBUGF("doesn't overlap with previous glyph.\n");
  831. if (in_non_intersected_list == 0) {
  832. if (fixed_cnt >= fixed_size) {
  833. need_free_fixed_list = TRUE;
  834. goto done;
  835. }
  836. if (!glyph_new_fixed_list(&fixed_list[fixed_cnt],
  837. glyphs - 1,
  838. &head_glyphs,
  839. cur_list,
  840. cur_list->len - (n + 1), x, y,
  841. x1, y1, x2, y2,
  842. &head_list,
  843. &head_pos,
  844. &head_x,
  845. &head_y, &fixed_cnt,
  846. INTERSECTED, &prev_extents)) {
  847. need_free_fixed_list = TRUE;
  848. goto done;
  849. }
  850. }
  851. in_non_intersected_list = 1;
  852. }
  853. prev_extents = *extents;
  854. }
  855. if (check_fake_overlap && priv
  856. && priv->has_edge_map && glyph->info.yOff == 0) {
  857. if (!has_left_edge_box || x1 < extents->x1) {
  858. left_box.x1 = x1;
  859. left_box.x2 = x1 + 1;
  860. left_box.y1 = y1;
  861. has_left_edge_box = TRUE;
  862. left_priv = priv;
  863. }
  864. if (!has_right_edge_box || x2 > extents->x2) {
  865. right_box.x1 = x2 - 2;
  866. right_box.x2 = x2 - 1;
  867. right_box.y1 = y1;
  868. has_right_edge_box = TRUE;
  869. right_priv = priv;
  870. }
  871. }
  872. if (x1 < extents->x1)
  873. extents->x1 = x1;
  874. if (x2 > extents->x2)
  875. extents->x2 = x2;
  876. if (y1 < extents->y1)
  877. extents->y1 = y1;
  878. if (y2 > extents->y2)
  879. extents->y2 = y2;
  880. x += glyph->info.xOff;
  881. y += glyph->info.yOff;
  882. }
  883. first_list = FALSE;
  884. }
  885. if (in_non_intersected_list == 0 && fixed_cnt == 0) {
  886. fixed_cnt = -1;
  887. goto done;
  888. }
  889. if ((in_non_intersected_list != -1 || head_pos != n) && (fixed_cnt > 0)) {
  890. if (fixed_cnt >= fixed_size) {
  891. need_free_fixed_list = TRUE;
  892. goto done;
  893. }
  894. if (!glyph_new_fixed_list(&fixed_list[fixed_cnt],
  895. glyphs - 1,
  896. &head_glyphs,
  897. cur_list,
  898. cur_list->len - (n + 1), x, y,
  899. x1, y1, x2, y2,
  900. &head_list,
  901. &head_pos,
  902. &head_x,
  903. &head_y, &fixed_cnt,
  904. (!in_non_intersected_list) | 0x80,
  905. &prev_extents)) {
  906. need_free_fixed_list = TRUE;
  907. goto done;
  908. }
  909. }
  910. done:
  911. if (need_free_list_region)
  912. pixman_region_fini(&list_region);
  913. pixman_region_fini(&current_region);
  914. if (need_free_fixed_list && fixed_cnt >= 0) {
  915. while (fixed_cnt--) {
  916. free(fixed_list[fixed_cnt].list);
  917. }
  918. }
  919. DEBUGF("Got %d fixed list \n", fixed_cnt);
  920. return fixed_cnt;
  921. }
  922. static inline unsigned int
  923. glamor_glyph_size_to_count(int size)
  924. {
  925. size /= GLYPH_MIN_SIZE;
  926. return size * size;
  927. }
  928. static inline unsigned int
  929. glamor_glyph_count_to_mask(int count)
  930. {
  931. return ~(count - 1);
  932. }
  933. static inline unsigned int
  934. glamor_glyph_size_to_mask(int size)
  935. {
  936. return glamor_glyph_count_to_mask(glamor_glyph_size_to_count(size));
  937. }
  938. static PicturePtr
  939. glamor_glyph_cache(glamor_screen_private *glamor, GlyphPtr glyph, int *out_x,
  940. int *out_y)
  941. {
  942. ScreenPtr screen = glamor->screen;
  943. PicturePtr glyph_picture = GlyphPicture(glyph)[screen->myNum];
  944. glamor_glyph_cache_t *cache =
  945. &glamor->glyphCaches[PICT_FORMAT_RGB(glyph_picture->format) != 0];
  946. struct glamor_glyph *priv = NULL, *evicted_priv = NULL;
  947. int size, mask, pos, s;
  948. if (glyph->info.width > GLYPH_MAX_SIZE
  949. || glyph->info.height > GLYPH_MAX_SIZE)
  950. return NULL;
  951. for (size = GLYPH_MIN_SIZE; size <= GLYPH_MAX_SIZE; size *= 2)
  952. if (glyph->info.width <= size && glyph->info.height <= size)
  953. break;
  954. s = glamor_glyph_size_to_count(size);
  955. mask = glamor_glyph_count_to_mask(s);
  956. pos = (cache->count + s - 1) & mask;
  957. priv = glamor_glyph_get_private(glyph);
  958. if (pos < GLYPH_CACHE_SIZE) {
  959. cache->count = pos + s;
  960. }
  961. else {
  962. for (s = size; s <= GLYPH_MAX_SIZE; s *= 2) {
  963. int i = cache->evict & glamor_glyph_size_to_mask(s);
  964. GlyphPtr evicted = cache->glyphs[i];
  965. if (evicted == NULL)
  966. continue;
  967. evicted_priv = glamor_glyph_get_private(evicted);
  968. assert(evicted_priv->pos == i);
  969. if (evicted_priv->size >= s) {
  970. cache->glyphs[i] = NULL;
  971. evicted_priv->cached = FALSE;
  972. pos = cache->evict & glamor_glyph_size_to_mask(size);
  973. }
  974. else
  975. evicted_priv = NULL;
  976. break;
  977. }
  978. if (evicted_priv == NULL) {
  979. int count = glamor_glyph_size_to_count(size);
  980. mask = glamor_glyph_count_to_mask(count);
  981. pos = cache->evict & mask;
  982. for (s = 0; s < count; s++) {
  983. GlyphPtr evicted = cache->glyphs[pos + s];
  984. if (evicted != NULL) {
  985. evicted_priv = glamor_glyph_get_private(evicted);
  986. assert(evicted_priv->pos == pos + s);
  987. evicted_priv->cached = FALSE;
  988. cache->glyphs[pos + s] = NULL;
  989. }
  990. }
  991. }
  992. /* And pick a new eviction position */
  993. cache->evict = rand() % GLYPH_CACHE_SIZE;
  994. }
  995. cache->glyphs[pos] = glyph;
  996. priv->cache = cache;
  997. priv->size = size;
  998. priv->pos = pos;
  999. s = pos / ((GLYPH_MAX_SIZE / GLYPH_MIN_SIZE) *
  1000. (GLYPH_MAX_SIZE / GLYPH_MIN_SIZE));
  1001. priv->x = s % (CACHE_PICTURE_SIZE / GLYPH_MAX_SIZE) * GLYPH_MAX_SIZE;
  1002. priv->y = (s / (CACHE_PICTURE_SIZE / GLYPH_MAX_SIZE)) * GLYPH_MAX_SIZE;
  1003. for (s = GLYPH_MIN_SIZE; s < GLYPH_MAX_SIZE; s *= 2) {
  1004. if (pos & 1)
  1005. priv->x += s;
  1006. if (pos & 2)
  1007. priv->y += s;
  1008. pos >>= 2;
  1009. }
  1010. glamor_glyph_cache_upload_glyph(screen, cache, glyph, priv->x, priv->y);
  1011. #ifndef GLYPHS_NO_EDEGEMAP_OVERLAP_CHECK
  1012. if (priv->has_edge_map == FALSE && glyph->info.width >= 2)
  1013. glamor_glyph_priv_get_edge_map(glyph, priv, glyph_picture);
  1014. #endif
  1015. priv->cached = TRUE;
  1016. *out_x = priv->x;
  1017. *out_y = priv->y;
  1018. return cache->picture;
  1019. }
  1020. typedef void (*glyphs_flush_func) (void *arg);
  1021. struct glyphs_flush_dst_arg {
  1022. CARD8 op;
  1023. PicturePtr src;
  1024. PicturePtr dst;
  1025. glamor_glyph_buffer_t *buffer;
  1026. int x_src, y_src;
  1027. int x_dst, y_dst;
  1028. };
  1029. static struct glyphs_flush_dst_arg dst_arg;
  1030. static struct glyphs_flush_mask_arg mask_arg;
  1031. static glamor_glyph_buffer_t dst_buffer;
  1032. static glamor_glyph_buffer_t mask_buffer;
  1033. unsigned long long mask_glyphs_cnt = 0;
  1034. unsigned long long dst_glyphs_cnt = 0;
  1035. #define GLYPHS_DST_MODE_VIA_MASK 0
  1036. #define GLYPHS_DST_MODE_VIA_MASK_CACHE 1
  1037. #define GLYPHS_DST_MODE_TO_DST 2
  1038. #define GLYPHS_DST_MODE_MASK_TO_DST 3
  1039. struct glyphs_flush_mask_arg {
  1040. PicturePtr mask;
  1041. glamor_glyph_buffer_t *buffer;
  1042. struct glamor_glyph_mask_cache *maskcache;
  1043. unsigned int used_bitmap;
  1044. };
  1045. static void
  1046. glamor_glyphs_flush_mask(struct glyphs_flush_mask_arg *arg)
  1047. {
  1048. if (arg->buffer->count > 0) {
  1049. #ifdef RENDER
  1050. glamor_composite_glyph_rects(PictOpAdd, arg->buffer->source,
  1051. NULL, arg->mask,
  1052. arg->buffer->count, arg->buffer->rects);
  1053. #endif
  1054. }
  1055. arg->buffer->count = 0;
  1056. arg->buffer->source = NULL;
  1057. }
  1058. static void
  1059. glamor_glyphs_flush_dst(struct glyphs_flush_dst_arg *arg)
  1060. {
  1061. if (!arg->buffer)
  1062. return;
  1063. if (mask_buffer.count > 0) {
  1064. glamor_glyphs_flush_mask(&mask_arg);
  1065. }
  1066. if (mask_arg.used_bitmap) {
  1067. put_mask_cache_bitmap(mask_arg.maskcache, mask_arg.used_bitmap);
  1068. mask_arg.used_bitmap = 0;
  1069. }
  1070. if (arg->buffer->count > 0) {
  1071. glamor_composite_glyph_rects(arg->op, arg->src,
  1072. arg->buffer->source, arg->dst,
  1073. arg->buffer->count,
  1074. &arg->buffer->rects[0]);
  1075. arg->buffer->count = 0;
  1076. arg->buffer->source = NULL;
  1077. }
  1078. }
  1079. static glamor_glyph_cache_result_t
  1080. glamor_buffer_glyph(glamor_screen_private *glamor_priv,
  1081. glamor_glyph_buffer_t *buffer,
  1082. PictFormatShort format,
  1083. GlyphPtr glyph, struct glamor_glyph *priv,
  1084. int x_glyph, int y_glyph,
  1085. int dx, int dy, int w, int h,
  1086. int glyphs_dst_mode,
  1087. glyphs_flush_func glyphs_flush, void *flush_arg)
  1088. {
  1089. ScreenPtr screen = glamor_priv->screen;
  1090. glamor_composite_rect_t *rect;
  1091. PicturePtr source;
  1092. int x, y;
  1093. glamor_glyph_cache_t *cache;
  1094. if (glyphs_dst_mode != GLYPHS_DST_MODE_MASK_TO_DST)
  1095. priv = glamor_glyph_get_private(glyph);
  1096. if (PICT_FORMAT_BPP(format) == 1)
  1097. format = PICT_a8;
  1098. cache = &glamor_priv->glyphCaches[PICT_FORMAT_RGB(format) != 0];
  1099. if (buffer->source && buffer->source != cache->picture && glyphs_flush) {
  1100. (*glyphs_flush) (flush_arg);
  1101. glyphs_flush = NULL;
  1102. }
  1103. if (buffer->count == GLYPH_BUFFER_SIZE && glyphs_flush) {
  1104. (*glyphs_flush) (flush_arg);
  1105. glyphs_flush = NULL;
  1106. }
  1107. if (priv && priv->cached) {
  1108. rect = &buffer->rects[buffer->count++];
  1109. rect->x_src = priv->x + dx;
  1110. rect->y_src = priv->y + dy;
  1111. if (buffer->source == NULL)
  1112. buffer->source = priv->cache->picture;
  1113. if (glyphs_dst_mode <= GLYPHS_DST_MODE_VIA_MASK_CACHE)
  1114. assert(priv->cache->glyphs[priv->pos] == glyph);
  1115. }
  1116. else {
  1117. assert(glyphs_dst_mode != GLYPHS_DST_MODE_MASK_TO_DST);
  1118. if (glyphs_flush)
  1119. (*glyphs_flush) (flush_arg);
  1120. source = glamor_glyph_cache(glamor_priv, glyph, &x, &y);
  1121. if (source != NULL) {
  1122. rect = &buffer->rects[buffer->count++];
  1123. rect->x_src = x + dx;
  1124. rect->y_src = y + dy;
  1125. if (buffer->source == NULL)
  1126. buffer->source = source;
  1127. if (glyphs_dst_mode == GLYPHS_DST_MODE_VIA_MASK_CACHE) {
  1128. /* mode 1 means we are using global mask cache,
  1129. * thus we have to composite from the cache picture
  1130. * to the cache picture, we need a flush here to make
  1131. * sure latter we get the corret glyphs data.*/
  1132. glamor_make_current(glamor_priv);
  1133. glFlush();
  1134. }
  1135. }
  1136. else {
  1137. /* Couldn't find the glyph in the cache, use the glyph picture directly */
  1138. source = GlyphPicture(glyph)[screen->myNum];
  1139. if (buffer->source && buffer->source != source && glyphs_flush)
  1140. (*glyphs_flush) (flush_arg);
  1141. buffer->source = source;
  1142. rect = &buffer->rects[buffer->count++];
  1143. rect->x_src = 0 + dx;
  1144. rect->y_src = 0 + dy;
  1145. }
  1146. priv = glamor_glyph_get_private(glyph);
  1147. }
  1148. rect->x_dst = x_glyph;
  1149. rect->y_dst = y_glyph;
  1150. if (glyphs_dst_mode != GLYPHS_DST_MODE_MASK_TO_DST) {
  1151. rect->x_dst -= glyph->info.x;
  1152. rect->y_dst -= glyph->info.y;
  1153. }
  1154. rect->width = w;
  1155. rect->height = h;
  1156. if (glyphs_dst_mode > GLYPHS_DST_MODE_VIA_MASK_CACHE) {
  1157. rect->x_mask = rect->x_src;
  1158. rect->y_mask = rect->y_src;
  1159. rect->x_src = dst_arg.x_src + rect->x_dst - dst_arg.x_dst;
  1160. rect->y_src = dst_arg.y_src + rect->y_dst - dst_arg.y_dst;
  1161. }
  1162. return GLAMOR_GLYPH_SUCCESS;
  1163. }
  1164. static void
  1165. glamor_buffer_glyph_clip(glamor_screen_private *glamor_priv,
  1166. BoxPtr rects,
  1167. int nrect, PictFormatShort format,
  1168. GlyphPtr glyph, struct glamor_glyph *priv,
  1169. int glyph_x, int glyph_y,
  1170. int glyph_dx, int glyph_dy,
  1171. int width, int height,
  1172. int glyphs_mode,
  1173. glyphs_flush_func flush_func, void *arg)
  1174. {
  1175. int i;
  1176. for (i = 0; i < nrect; i++) {
  1177. int dst_x, dst_y;
  1178. int dx, dy;
  1179. int x2, y2;
  1180. dst_x = glyph_x - glyph_dx;
  1181. dst_y = glyph_y - glyph_dy;
  1182. x2 = dst_x + width;
  1183. y2 = dst_y + height;
  1184. dx = dy = 0;
  1185. if (rects[i].y1 >= y2)
  1186. break;
  1187. if (dst_x < rects[i].x1)
  1188. dx = rects[i].x1 - dst_x, dst_x = rects[i].x1;
  1189. if (x2 > rects[i].x2)
  1190. x2 = rects[i].x2;
  1191. if (dst_y < rects[i].y1)
  1192. dy = rects[i].y1 - dst_y, dst_y = rects[i].y1;
  1193. if (y2 > rects[i].y2)
  1194. y2 = rects[i].y2;
  1195. if (dst_x < x2 && dst_y < y2) {
  1196. glamor_buffer_glyph(glamor_priv,
  1197. &dst_buffer,
  1198. format,
  1199. glyph, priv,
  1200. dst_x + glyph_dx,
  1201. dst_y + glyph_dy,
  1202. dx, dy,
  1203. x2 - dst_x, y2 - dst_y,
  1204. glyphs_mode, flush_func, arg);
  1205. }
  1206. }
  1207. }
  1208. static void
  1209. glamor_glyphs_via_mask(CARD8 op,
  1210. PicturePtr src,
  1211. PicturePtr dst,
  1212. PictFormatPtr mask_format,
  1213. INT16 x_src,
  1214. INT16 y_src,
  1215. int nlist, GlyphListPtr list, GlyphPtr *glyphs,
  1216. Bool use_mask_cache)
  1217. {
  1218. PixmapPtr mask_pixmap = 0;
  1219. PicturePtr mask;
  1220. ScreenPtr screen = dst->pDrawable->pScreen;
  1221. int width = 0, height = 0;
  1222. int x, y;
  1223. int x_dst = list->xOff, y_dst = list->yOff;
  1224. int n;
  1225. GlyphPtr glyph;
  1226. int error;
  1227. BoxRec extents = { 0, 0, 0, 0 };
  1228. XID component_alpha;
  1229. glamor_screen_private *glamor_priv;
  1230. int need_free_mask = FALSE;
  1231. glamor_glyph_buffer_t buffer;
  1232. struct glyphs_flush_mask_arg arg;
  1233. glamor_glyph_buffer_t *pmask_buffer;
  1234. struct glyphs_flush_mask_arg *pmask_arg;
  1235. struct glamor_glyph_mask_cache_entry *mce = NULL;
  1236. struct glamor_glyph_mask_cache *maskcache;
  1237. glamor_glyph_cache_t *cache;
  1238. int glyphs_dst_mode;
  1239. glamor_glyph_extents(nlist, list, glyphs, &extents);
  1240. if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1)
  1241. return;
  1242. glamor_priv = glamor_get_screen_private(screen);
  1243. width = extents.x2 - extents.x1;
  1244. height = extents.y2 - extents.y1;
  1245. if (mask_format->depth == 1) {
  1246. PictFormatPtr a8Format = PictureMatchFormat(screen, 8, PICT_a8);
  1247. if (a8Format)
  1248. mask_format = a8Format;
  1249. }
  1250. cache = &glamor_priv->glyphCaches
  1251. [PICT_FORMAT_RGB(mask_format->format) != 0];
  1252. maskcache = mask_cache[PICT_FORMAT_RGB(mask_format->format) != 0];
  1253. x = -extents.x1;
  1254. y = -extents.y1;
  1255. if (!use_mask_cache || width > (CACHE_PICTURE_SIZE / 4)
  1256. || height > MASK_CACHE_MAX_SIZE) {
  1257. new_mask_pixmap:
  1258. mask_pixmap = glamor_create_pixmap(screen, width, height,
  1259. mask_format->depth,
  1260. CREATE_PIXMAP_USAGE_SCRATCH);
  1261. if (!mask_pixmap) {
  1262. glamor_destroy_pixmap(mask_pixmap);
  1263. return;
  1264. }
  1265. glamor_solid(mask_pixmap, 0, 0, width, height, GXcopy, 0xFFFFFFFF, 0);
  1266. component_alpha = NeedsComponent(mask_format->format);
  1267. mask = CreatePicture(0, &mask_pixmap->drawable,
  1268. mask_format, CPComponentAlpha,
  1269. &component_alpha, serverClient, &error);
  1270. if (!mask)
  1271. return;
  1272. need_free_mask = TRUE;
  1273. pmask_arg = &arg;
  1274. pmask_buffer = &buffer;
  1275. pmask_buffer->count = 0;
  1276. pmask_buffer->source = NULL;
  1277. pmask_arg->used_bitmap = 0;
  1278. glyphs_dst_mode = GLYPHS_DST_MODE_VIA_MASK;
  1279. }
  1280. else {
  1281. int retry_cnt = 0;
  1282. retry:
  1283. mce = get_mask_cache(maskcache,
  1284. (width + MASK_CACHE_MAX_SIZE -
  1285. 1) / MASK_CACHE_MAX_SIZE);
  1286. if (mce == NULL) {
  1287. glamor_glyphs_flush_dst(&dst_arg);
  1288. retry_cnt++;
  1289. if (retry_cnt > 2) {
  1290. assert(0);
  1291. goto new_mask_pixmap;
  1292. }
  1293. goto retry;
  1294. }
  1295. mask = cache->picture;
  1296. x += mce->x;
  1297. y += mce->y;
  1298. mce->width = (width + MASK_CACHE_MAX_SIZE - 1) / MASK_CACHE_MAX_SIZE;
  1299. mce->height = 1;
  1300. if (mask_arg.mask && mask_arg.mask != mask && mask_buffer.count != 0)
  1301. glamor_glyphs_flush_dst(&dst_arg);
  1302. pmask_arg = &mask_arg;
  1303. pmask_buffer = &mask_buffer;
  1304. pmask_arg->maskcache = maskcache;
  1305. glyphs_dst_mode = GLYPHS_DST_MODE_VIA_MASK_CACHE;
  1306. }
  1307. pmask_arg->mask = mask;
  1308. pmask_arg->buffer = pmask_buffer;
  1309. while (nlist--) {
  1310. x += list->xOff;
  1311. y += list->yOff;
  1312. n = list->len;
  1313. mask_glyphs_cnt += n;
  1314. while (n--) {
  1315. glyph = *glyphs++;
  1316. if (glyph->info.width > 0 && glyph->info.height > 0) {
  1317. glyphs_flush_func flush_func;
  1318. void *temp_arg;
  1319. if (need_free_mask) {
  1320. if (pmask_buffer->count)
  1321. flush_func =
  1322. (glyphs_flush_func) glamor_glyphs_flush_mask;
  1323. else
  1324. flush_func = NULL;
  1325. temp_arg = pmask_arg;
  1326. }
  1327. else {
  1328. /* If we are using global mask cache, then we need to
  1329. * flush dst instead of mask. As some dst depends on the
  1330. * previous mask result. Just flush mask can't get all previous's
  1331. * overlapped glyphs.*/
  1332. if (dst_buffer.count || mask_buffer.count)
  1333. flush_func =
  1334. (glyphs_flush_func) glamor_glyphs_flush_dst;
  1335. else
  1336. flush_func = NULL;
  1337. temp_arg = &dst_arg;
  1338. }
  1339. glamor_buffer_glyph(glamor_priv, pmask_buffer,
  1340. mask_format->format,
  1341. glyph, NULL, x, y,
  1342. 0, 0,
  1343. glyph->info.width, glyph->info.height,
  1344. glyphs_dst_mode,
  1345. flush_func, (void *) temp_arg);
  1346. }
  1347. x += glyph->info.xOff;
  1348. y += glyph->info.yOff;
  1349. }
  1350. list++;
  1351. }
  1352. x = extents.x1;
  1353. y = extents.y1;
  1354. if (need_free_mask) {
  1355. glamor_glyphs_flush_mask(pmask_arg);
  1356. CompositePicture(op,
  1357. src,
  1358. mask,
  1359. dst,
  1360. x_src + x - x_dst,
  1361. y_src + y - y_dst, 0, 0, x, y, width, height);
  1362. FreePicture(mask, 0);
  1363. glamor_destroy_pixmap(mask_pixmap);
  1364. }
  1365. else {
  1366. struct glamor_glyph priv;
  1367. glyphs_flush_func flush_func;
  1368. BoxPtr rects;
  1369. int nrect;
  1370. priv.cache = cache;
  1371. priv.x = mce->x;
  1372. priv.y = mce->y;
  1373. priv.cached = TRUE;
  1374. rects = REGION_RECTS(dst->pCompositeClip);
  1375. nrect = REGION_NUM_RECTS(dst->pCompositeClip);
  1376. pmask_arg->used_bitmap |= ((1 << mce->width) - 1) << mce->idx;
  1377. dst_arg.op = op;
  1378. dst_arg.src = src;
  1379. dst_arg.dst = dst;
  1380. dst_arg.buffer = &dst_buffer;
  1381. dst_arg.x_src = x_src;
  1382. dst_arg.y_src = y_src;
  1383. dst_arg.x_dst = x_dst;
  1384. dst_arg.y_dst = y_dst;
  1385. if (dst_buffer.source == NULL) {
  1386. dst_buffer.source = cache->picture;
  1387. }
  1388. else if (dst_buffer.source != cache->picture) {
  1389. glamor_glyphs_flush_dst(&dst_arg);
  1390. dst_buffer.source = cache->picture;
  1391. }
  1392. x += dst->pDrawable->x;
  1393. y += dst->pDrawable->y;
  1394. if (dst_buffer.count || mask_buffer.count)
  1395. flush_func = (glyphs_flush_func) glamor_glyphs_flush_dst;
  1396. else
  1397. flush_func = NULL;
  1398. glamor_buffer_glyph_clip(glamor_priv,
  1399. rects, nrect,
  1400. mask_format->format,
  1401. NULL, &priv,
  1402. x, y,
  1403. 0, 0,
  1404. width, height,
  1405. GLYPHS_DST_MODE_MASK_TO_DST,
  1406. flush_func, (void *) &dst_arg);
  1407. }
  1408. }
  1409. static void
  1410. glamor_glyphs_to_dst(CARD8 op,
  1411. PicturePtr src,
  1412. PicturePtr dst,
  1413. INT16 x_src,
  1414. INT16 y_src,
  1415. int nlist, GlyphListPtr list, GlyphPtr *glyphs)
  1416. {
  1417. ScreenPtr screen = dst->pDrawable->pScreen;
  1418. int x = 0, y = 0;
  1419. int x_dst = list->xOff, y_dst = list->yOff;
  1420. int n;
  1421. GlyphPtr glyph;
  1422. BoxPtr rects;
  1423. int nrect;
  1424. glamor_screen_private *glamor_priv;
  1425. rects = REGION_RECTS(dst->pCompositeClip);
  1426. nrect = REGION_NUM_RECTS(dst->pCompositeClip);
  1427. glamor_priv = glamor_get_screen_private(screen);
  1428. dst_arg.op = op;
  1429. dst_arg.src = src;
  1430. dst_arg.dst = dst;
  1431. dst_arg.buffer = &dst_buffer;
  1432. dst_arg.x_src = x_src;
  1433. dst_arg.y_src = y_src;
  1434. dst_arg.x_dst = x_dst;
  1435. dst_arg.y_dst = y_dst;
  1436. x = dst->pDrawable->x;
  1437. y = dst->pDrawable->y;
  1438. while (nlist--) {
  1439. x += list->xOff;
  1440. y += list->yOff;
  1441. n = list->len;
  1442. dst_glyphs_cnt += n;
  1443. while (n--) {
  1444. glyph = *glyphs++;
  1445. if (glyph->info.width > 0 && glyph->info.height > 0) {
  1446. glyphs_flush_func flush_func;
  1447. if (dst_buffer.count || mask_buffer.count)
  1448. flush_func = (glyphs_flush_func) glamor_glyphs_flush_dst;
  1449. else
  1450. flush_func = NULL;
  1451. glamor_buffer_glyph_clip(glamor_priv,
  1452. rects, nrect,
  1453. (GlyphPicture(glyph)[screen->myNum])->
  1454. format, glyph, NULL, x, y,
  1455. glyph->info.x, glyph->info.y,
  1456. glyph->info.width, glyph->info.height,
  1457. GLYPHS_DST_MODE_TO_DST, flush_func,
  1458. (void *) &dst_arg);
  1459. }
  1460. x += glyph->info.xOff;
  1461. y += glyph->info.yOff;
  1462. }
  1463. list++;
  1464. }
  1465. }
  1466. #define MAX_FIXED_SIZE
  1467. static void
  1468. glamor_glyphs_reset_buffer(glamor_glyph_buffer_t *buffer)
  1469. {
  1470. buffer->count = 0;
  1471. buffer->source = NULL;
  1472. }
  1473. static Bool
  1474. _glamor_glyphs(CARD8 op,
  1475. PicturePtr src,
  1476. PicturePtr dst,
  1477. PictFormatPtr mask_format,
  1478. INT16 x_src,
  1479. INT16 y_src, int nlist, GlyphListPtr list,
  1480. GlyphPtr *glyphs, Bool fallback)
  1481. {
  1482. PictFormatShort format;
  1483. int fixed_size, fixed_cnt = 0;
  1484. struct glamor_glyph_list *fixed_list = NULL;
  1485. Bool need_free_list = FALSE;
  1486. #ifndef GLYPHS_NO_EDEGEMAP_OVERLAP_CHECK
  1487. Bool check_fake_overlap = TRUE;
  1488. if (!(op == PictOpOver || op == PictOpAdd || op == PictOpXor)) {
  1489. /* C = (0,0,0,0) D = glyphs , SRC = A, DEST = B (faked overlapped glyphs, overlapped with (0,0,0,0)).
  1490. * For those op, (A IN (C ADD D)) OP B != (A IN D) OP ((A IN C) OP B)
  1491. * or (A IN (D ADD C)) OP B != (A IN C) OP ((A IN D) OP B)
  1492. * We need to split the faked regions to three or two, and composite the disoverlapped small
  1493. * boxes one by one. For other Ops, it's safe to composite the whole box. */
  1494. check_fake_overlap = FALSE;
  1495. }
  1496. #else
  1497. Bool check_fake_overlap = FALSE;
  1498. #endif
  1499. if (mask_format)
  1500. format = mask_format->depth << 24 | mask_format->format;
  1501. else
  1502. format = 0;
  1503. fixed_size = 32;
  1504. glamor_glyphs_reset_buffer(&dst_buffer);
  1505. if (!mask_format || (((nlist == 1 && list->len == 1) || op == PictOpAdd)
  1506. && (dst->format ==
  1507. ((mask_format->depth << 24) | mask_format->
  1508. format)))) {
  1509. glamor_glyphs_to_dst(op, src, dst, x_src, y_src, nlist, list, glyphs);
  1510. goto last_flush;
  1511. }
  1512. glamor_glyphs_reset_buffer(&mask_buffer);
  1513. /* We have mask_format. Need to check the real overlap or not. */
  1514. format = mask_format->depth << 24 | mask_format->format;
  1515. fixed_list = calloc(fixed_size, sizeof(*fixed_list));
  1516. if (_X_UNLIKELY(fixed_list == NULL))
  1517. fixed_size = 0;
  1518. fixed_cnt = glamor_glyphs_intersect(nlist, list, glyphs,
  1519. format, dst->pDrawable->pScreen,
  1520. check_fake_overlap,
  1521. fixed_list, fixed_size);
  1522. if (fixed_cnt == 0)
  1523. mask_format = NULL;
  1524. need_free_list = TRUE;
  1525. if (fixed_cnt <= 0) {
  1526. if (mask_format == NULL) {
  1527. glamor_glyphs_to_dst(op, src, dst, x_src, y_src, nlist,
  1528. list, glyphs);
  1529. goto last_flush;
  1530. }
  1531. else {
  1532. glamor_glyphs_via_mask(op, src, dst, mask_format,
  1533. x_src, y_src, nlist, list, glyphs, FALSE);
  1534. goto free_fixed_list;
  1535. }
  1536. }
  1537. else {
  1538. /* We have splitted the original list to serval list, some are overlapped
  1539. * and some are non-overlapped. For the non-overlapped, we render it to
  1540. * dst directly. For the overlapped, we render it to mask picture firstly,
  1541. * then render the mask to dst. If we can use mask cache which is in the
  1542. * glyphs cache's last row, we can accumulate the rendering of mask to dst
  1543. * with the other dst_buffer's rendering operations thus can reduce the call
  1544. * of glDrawElements.
  1545. *
  1546. * */
  1547. struct glamor_glyph_list *saved_list;
  1548. saved_list = fixed_list;
  1549. mask_arg.used_bitmap = 0;
  1550. while (fixed_cnt--) {
  1551. if (fixed_list->type == NON_INTERSECTED) {
  1552. glamor_glyphs_to_dst(op, src, dst,
  1553. x_src, y_src,
  1554. fixed_list->nlist,
  1555. fixed_list->list, fixed_list->glyphs);
  1556. }
  1557. else
  1558. glamor_glyphs_via_mask(op, src, dst,
  1559. mask_format, x_src, y_src,
  1560. fixed_list->nlist,
  1561. fixed_list->list,
  1562. fixed_list->glyphs, TRUE);
  1563. free(fixed_list->list);
  1564. fixed_list++;
  1565. }
  1566. free(saved_list);
  1567. need_free_list = FALSE;
  1568. }
  1569. last_flush:
  1570. if (dst_buffer.count || mask_buffer.count)
  1571. glamor_glyphs_flush_dst(&dst_arg);
  1572. free_fixed_list:
  1573. if (need_free_list) {
  1574. assert(fixed_cnt <= 0);
  1575. free(fixed_list);
  1576. }
  1577. return TRUE;
  1578. }
  1579. void
  1580. glamor_glyphs(CARD8 op,
  1581. PicturePtr src,
  1582. PicturePtr dst,
  1583. PictFormatPtr mask_format,
  1584. INT16 x_src,
  1585. INT16 y_src, int nlist, GlyphListPtr list, GlyphPtr *glyphs)
  1586. {
  1587. _glamor_glyphs(op, src, dst, mask_format, x_src,
  1588. y_src, nlist, list, glyphs, TRUE);
  1589. }
  1590. Bool
  1591. glamor_glyphs_nf(CARD8 op,
  1592. PicturePtr src,
  1593. PicturePtr dst,
  1594. PictFormatPtr mask_format,
  1595. INT16 x_src,
  1596. INT16 y_src, int nlist, GlyphListPtr list, GlyphPtr *glyphs)
  1597. {
  1598. return _glamor_glyphs(op, src, dst, mask_format, x_src,
  1599. y_src, nlist, list, glyphs, FALSE);
  1600. }