fbpict.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. /*
  2. *
  3. * 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 SuSE not be used in advertising or
  10. * publicity pertaining to distribution of the software without specific,
  11. * written prior permission. SuSE 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. * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
  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. * Author: Keith Packard, SuSE, Inc.
  23. */
  24. #ifdef HAVE_DIX_CONFIG_H
  25. #include <dix-config.h>
  26. #endif
  27. #include <string.h>
  28. #include "fb.h"
  29. #include "picturestr.h"
  30. #include "mipict.h"
  31. #include "fbpict.h"
  32. typedef void (*CompositeFunc) (CARD8 op,
  33. PicturePtr pSrc,
  34. PicturePtr pMask,
  35. PicturePtr pDst,
  36. INT16 xSrc,
  37. INT16 ySrc,
  38. INT16 xMask,
  39. INT16 yMask,
  40. INT16 xDst,
  41. INT16 yDst, CARD16 width, CARD16 height);
  42. CARD32
  43. fbOver(CARD32 x, CARD32 y)
  44. {
  45. CARD16 a = ~x >> 24;
  46. CARD16 t;
  47. CARD32 m, n, o, p;
  48. m = FbOverU(x, y, 0, a, t);
  49. n = FbOverU(x, y, 8, a, t);
  50. o = FbOverU(x, y, 16, a, t);
  51. p = FbOverU(x, y, 24, a, t);
  52. return m | n | o | p;
  53. }
  54. CARD32
  55. fbOver24(CARD32 x, CARD32 y)
  56. {
  57. CARD16 a = ~x >> 24;
  58. CARD16 t;
  59. CARD32 m, n, o;
  60. m = FbOverU(x, y, 0, a, t);
  61. n = FbOverU(x, y, 8, a, t);
  62. o = FbOverU(x, y, 16, a, t);
  63. return m | n | o;
  64. }
  65. CARD32
  66. fbIn(CARD32 x, CARD8 y)
  67. {
  68. CARD16 a = y;
  69. CARD16 t;
  70. CARD32 m, n, o, p;
  71. m = FbInU(x, 0, a, t);
  72. n = FbInU(x, 8, a, t);
  73. o = FbInU(x, 16, a, t);
  74. p = FbInU(x, 24, a, t);
  75. return m | n | o | p;
  76. }
  77. /*
  78. * Naming convention:
  79. *
  80. * opSRCxMASKxDST
  81. */
  82. void
  83. fbCompositeSolidMask_nx8x8888(CARD8 op,
  84. PicturePtr pSrc,
  85. PicturePtr pMask,
  86. PicturePtr pDst,
  87. INT16 xSrc,
  88. INT16 ySrc,
  89. INT16 xMask,
  90. INT16 yMask,
  91. INT16 xDst,
  92. INT16 yDst, CARD16 width, CARD16 height)
  93. {
  94. CARD32 src, srca;
  95. CARD32 *dstLine, *dst, d, dstMask;
  96. CARD8 *maskLine, *mask, m;
  97. FbStride dstStride, maskStride;
  98. CARD16 w;
  99. fbComposeGetSolid(pSrc, src, pDst->format);
  100. dstMask = FbFullMask(pDst->pDrawable->depth);
  101. srca = src >> 24;
  102. if (src == 0)
  103. return;
  104. fbComposeGetStart(pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);
  105. fbComposeGetStart(pMask, xMask, yMask, CARD8, maskStride, maskLine, 1);
  106. while (height--) {
  107. dst = dstLine;
  108. dstLine += dstStride;
  109. mask = maskLine;
  110. maskLine += maskStride;
  111. w = width;
  112. while (w--) {
  113. m = *mask++;
  114. if (m == 0xff) {
  115. if (srca == 0xff)
  116. *dst = src & dstMask;
  117. else
  118. *dst = fbOver(src, *dst) & dstMask;
  119. }
  120. else if (m) {
  121. d = fbIn(src, m);
  122. *dst = fbOver(d, *dst) & dstMask;
  123. }
  124. dst++;
  125. }
  126. }
  127. }
  128. void
  129. fbCompositeSolidMask_nx8888x8888C(CARD8 op,
  130. PicturePtr pSrc,
  131. PicturePtr pMask,
  132. PicturePtr pDst,
  133. INT16 xSrc,
  134. INT16 ySrc,
  135. INT16 xMask,
  136. INT16 yMask,
  137. INT16 xDst,
  138. INT16 yDst, CARD16 width, CARD16 height)
  139. {
  140. CARD32 src, srca;
  141. CARD32 *dstLine, *dst, d, dstMask;
  142. CARD32 *maskLine, *mask, ma;
  143. FbStride dstStride, maskStride;
  144. CARD16 w;
  145. CARD32 m, n, o, p;
  146. fbComposeGetSolid(pSrc, src, pDst->format);
  147. dstMask = FbFullMask(pDst->pDrawable->depth);
  148. srca = src >> 24;
  149. if (src == 0)
  150. return;
  151. fbComposeGetStart(pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);
  152. fbComposeGetStart(pMask, xMask, yMask, CARD32, maskStride, maskLine, 1);
  153. while (height--) {
  154. dst = dstLine;
  155. dstLine += dstStride;
  156. mask = maskLine;
  157. maskLine += maskStride;
  158. w = width;
  159. while (w--) {
  160. ma = *mask++;
  161. if (ma == 0xffffffff) {
  162. if (srca == 0xff)
  163. *dst = src & dstMask;
  164. else
  165. *dst = fbOver(src, *dst) & dstMask;
  166. }
  167. else if (ma) {
  168. d = *dst;
  169. #define FbInOverC(src,srca,msk,dst,i,result) { \
  170. CARD16 __a = FbGet8(msk,i); \
  171. CARD32 __t, __ta; \
  172. CARD32 __i; \
  173. __t = FbIntMult (FbGet8(src,i), __a,__i); \
  174. __ta = (CARD8) ~FbIntMult (srca, __a,__i); \
  175. __t = __t + FbIntMult(FbGet8(dst,i),__ta,__i); \
  176. __t = (CARD32) (CARD8) (__t | (-(__t >> 8))); \
  177. result = __t << (i); \
  178. }
  179. FbInOverC(src, srca, ma, d, 0, m);
  180. FbInOverC(src, srca, ma, d, 8, n);
  181. FbInOverC(src, srca, ma, d, 16, o);
  182. FbInOverC(src, srca, ma, d, 24, p);
  183. *dst = m | n | o | p;
  184. }
  185. dst++;
  186. }
  187. }
  188. }
  189. void
  190. fbCompositeSolidMask_nx8x0888(CARD8 op,
  191. PicturePtr pSrc,
  192. PicturePtr pMask,
  193. PicturePtr pDst,
  194. INT16 xSrc,
  195. INT16 ySrc,
  196. INT16 xMask,
  197. INT16 yMask,
  198. INT16 xDst,
  199. INT16 yDst, CARD16 width, CARD16 height)
  200. {
  201. CARD32 src, srca;
  202. CARD8 *dstLine, *dst;
  203. CARD32 d;
  204. CARD8 *maskLine, *mask, m;
  205. FbStride dstStride, maskStride;
  206. CARD16 w;
  207. fbComposeGetSolid(pSrc, src, pDst->format);
  208. srca = src >> 24;
  209. if (src == 0)
  210. return;
  211. fbComposeGetStart(pDst, xDst, yDst, CARD8, dstStride, dstLine, 3);
  212. fbComposeGetStart(pMask, xMask, yMask, CARD8, maskStride, maskLine, 1);
  213. while (height--) {
  214. dst = dstLine;
  215. dstLine += dstStride;
  216. mask = maskLine;
  217. maskLine += maskStride;
  218. w = width;
  219. while (w--) {
  220. m = *mask++;
  221. if (m == 0xff) {
  222. if (srca == 0xff)
  223. d = src;
  224. else {
  225. d = Fetch24(dst);
  226. d = fbOver24(src, d);
  227. }
  228. Store24(dst, d);
  229. }
  230. else if (m) {
  231. d = fbOver24(fbIn(src, m), Fetch24(dst));
  232. Store24(dst, d);
  233. }
  234. dst += 3;
  235. }
  236. }
  237. }
  238. void
  239. fbCompositeSolidMask_nx8x0565(CARD8 op,
  240. PicturePtr pSrc,
  241. PicturePtr pMask,
  242. PicturePtr pDst,
  243. INT16 xSrc,
  244. INT16 ySrc,
  245. INT16 xMask,
  246. INT16 yMask,
  247. INT16 xDst,
  248. INT16 yDst, CARD16 width, CARD16 height)
  249. {
  250. CARD32 src, srca;
  251. CARD16 *dstLine, *dst;
  252. CARD32 d;
  253. CARD8 *maskLine, *mask, m;
  254. FbStride dstStride, maskStride;
  255. CARD16 w;
  256. fbComposeGetSolid(pSrc, src, pDst->format);
  257. srca = src >> 24;
  258. if (src == 0)
  259. return;
  260. fbComposeGetStart(pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);
  261. fbComposeGetStart(pMask, xMask, yMask, CARD8, maskStride, maskLine, 1);
  262. while (height--) {
  263. dst = dstLine;
  264. dstLine += dstStride;
  265. mask = maskLine;
  266. maskLine += maskStride;
  267. w = width;
  268. while (w--) {
  269. m = *mask++;
  270. if (m == 0xff) {
  271. if (srca == 0xff)
  272. d = src;
  273. else {
  274. d = *dst;
  275. d = fbOver24(src, cvt0565to8888(d));
  276. }
  277. *dst = cvt8888to0565(d);
  278. }
  279. else if (m) {
  280. d = *dst;
  281. d = fbOver24(fbIn(src, m), cvt0565to8888(d));
  282. *dst = cvt8888to0565(d);
  283. }
  284. dst++;
  285. }
  286. }
  287. }
  288. void
  289. fbCompositeSolidMask_nx8888x0565C(CARD8 op,
  290. PicturePtr pSrc,
  291. PicturePtr pMask,
  292. PicturePtr pDst,
  293. INT16 xSrc,
  294. INT16 ySrc,
  295. INT16 xMask,
  296. INT16 yMask,
  297. INT16 xDst,
  298. INT16 yDst, CARD16 width, CARD16 height)
  299. {
  300. CARD32 src, srca;
  301. CARD16 src16;
  302. CARD16 *dstLine, *dst;
  303. CARD32 d;
  304. CARD32 *maskLine, *mask, ma;
  305. FbStride dstStride, maskStride;
  306. CARD16 w;
  307. CARD32 m, n, o;
  308. fbComposeGetSolid(pSrc, src, pDst->format);
  309. srca = src >> 24;
  310. if (src == 0)
  311. return;
  312. src16 = cvt8888to0565(src);
  313. fbComposeGetStart(pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);
  314. fbComposeGetStart(pMask, xMask, yMask, CARD32, maskStride, maskLine, 1);
  315. while (height--) {
  316. dst = dstLine;
  317. dstLine += dstStride;
  318. mask = maskLine;
  319. maskLine += maskStride;
  320. w = width;
  321. while (w--) {
  322. ma = *mask++;
  323. if (ma == 0xffffffff) {
  324. if (srca == 0xff) {
  325. *dst = src16;
  326. }
  327. else {
  328. d = *dst;
  329. d = fbOver24(src, cvt0565to8888(d));
  330. *dst = cvt8888to0565(d);
  331. }
  332. }
  333. else if (ma) {
  334. d = *dst;
  335. d = cvt0565to8888(d);
  336. FbInOverC(src, srca, ma, d, 0, m);
  337. FbInOverC(src, srca, ma, d, 8, n);
  338. FbInOverC(src, srca, ma, d, 16, o);
  339. d = m | n | o;
  340. *dst = cvt8888to0565(d);
  341. }
  342. dst++;
  343. }
  344. }
  345. }
  346. void
  347. fbCompositeSrc_8888x8888(CARD8 op,
  348. PicturePtr pSrc,
  349. PicturePtr pMask,
  350. PicturePtr pDst,
  351. INT16 xSrc,
  352. INT16 ySrc,
  353. INT16 xMask,
  354. INT16 yMask,
  355. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  356. {
  357. CARD32 *dstLine, *dst, dstMask;
  358. CARD32 *srcLine, *src, s;
  359. FbStride dstStride, srcStride;
  360. CARD8 a;
  361. CARD16 w;
  362. fbComposeGetStart(pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);
  363. fbComposeGetStart(pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
  364. dstMask = FbFullMask(pDst->pDrawable->depth);
  365. while (height--) {
  366. dst = dstLine;
  367. dstLine += dstStride;
  368. src = srcLine;
  369. srcLine += srcStride;
  370. w = width;
  371. while (w--) {
  372. s = *src++;
  373. a = s >> 24;
  374. if (a == 0xff)
  375. *dst = s & dstMask;
  376. else if (a)
  377. *dst = fbOver(s, *dst) & dstMask;
  378. dst++;
  379. }
  380. }
  381. }
  382. void
  383. fbCompositeSrc_8888x0888(CARD8 op,
  384. PicturePtr pSrc,
  385. PicturePtr pMask,
  386. PicturePtr pDst,
  387. INT16 xSrc,
  388. INT16 ySrc,
  389. INT16 xMask,
  390. INT16 yMask,
  391. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  392. {
  393. CARD8 *dstLine, *dst;
  394. CARD32 d;
  395. CARD32 *srcLine, *src, s;
  396. CARD8 a;
  397. FbStride dstStride, srcStride;
  398. CARD16 w;
  399. fbComposeGetStart(pDst, xDst, yDst, CARD8, dstStride, dstLine, 3);
  400. fbComposeGetStart(pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
  401. while (height--) {
  402. dst = dstLine;
  403. dstLine += dstStride;
  404. src = srcLine;
  405. srcLine += srcStride;
  406. w = width;
  407. while (w--) {
  408. s = *src++;
  409. a = s >> 24;
  410. if (a) {
  411. if (a == 0xff)
  412. d = s;
  413. else
  414. d = fbOver24(s, Fetch24(dst));
  415. Store24(dst, d);
  416. }
  417. dst += 3;
  418. }
  419. }
  420. }
  421. void
  422. fbCompositeSrc_8888x0565(CARD8 op,
  423. PicturePtr pSrc,
  424. PicturePtr pMask,
  425. PicturePtr pDst,
  426. INT16 xSrc,
  427. INT16 ySrc,
  428. INT16 xMask,
  429. INT16 yMask,
  430. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  431. {
  432. CARD16 *dstLine, *dst;
  433. CARD32 d;
  434. CARD32 *srcLine, *src, s;
  435. CARD8 a;
  436. FbStride dstStride, srcStride;
  437. CARD16 w;
  438. fbComposeGetStart(pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
  439. fbComposeGetStart(pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);
  440. while (height--) {
  441. dst = dstLine;
  442. dstLine += dstStride;
  443. src = srcLine;
  444. srcLine += srcStride;
  445. w = width;
  446. while (w--) {
  447. s = *src++;
  448. a = s >> 24;
  449. if (a) {
  450. if (a == 0xff)
  451. d = s;
  452. else {
  453. d = *dst;
  454. d = fbOver24(s, cvt0565to8888(d));
  455. }
  456. *dst = cvt8888to0565(d);
  457. }
  458. dst++;
  459. }
  460. }
  461. }
  462. void
  463. fbCompositeSrc_0565x0565(CARD8 op,
  464. PicturePtr pSrc,
  465. PicturePtr pMask,
  466. PicturePtr pDst,
  467. INT16 xSrc,
  468. INT16 ySrc,
  469. INT16 xMask,
  470. INT16 yMask,
  471. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  472. {
  473. CARD16 *dstLine, *dst;
  474. CARD16 *srcLine, *src;
  475. FbStride dstStride, srcStride;
  476. CARD16 w;
  477. fbComposeGetStart(pSrc, xSrc, ySrc, CARD16, srcStride, srcLine, 1);
  478. fbComposeGetStart(pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);
  479. while (height--) {
  480. dst = dstLine;
  481. dstLine += dstStride;
  482. src = srcLine;
  483. srcLine += srcStride;
  484. w = width;
  485. while (w--)
  486. *dst++ = *src++;
  487. }
  488. }
  489. void
  490. fbCompositeSrcAdd_8000x8000(CARD8 op,
  491. PicturePtr pSrc,
  492. PicturePtr pMask,
  493. PicturePtr pDst,
  494. INT16 xSrc,
  495. INT16 ySrc,
  496. INT16 xMask,
  497. INT16 yMask,
  498. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  499. {
  500. CARD8 *dstLine, *dst;
  501. CARD8 *srcLine, *src;
  502. FbStride dstStride, srcStride;
  503. CARD16 w;
  504. CARD8 s, d;
  505. CARD16 t;
  506. fbComposeGetStart(pSrc, xSrc, ySrc, CARD8, srcStride, srcLine, 1);
  507. fbComposeGetStart(pDst, xDst, yDst, CARD8, dstStride, dstLine, 1);
  508. while (height--) {
  509. dst = dstLine;
  510. dstLine += dstStride;
  511. src = srcLine;
  512. srcLine += srcStride;
  513. w = width;
  514. while (w--) {
  515. s = *src++;
  516. if (s) {
  517. if (s != 0xff) {
  518. d = *dst;
  519. t = d + s;
  520. s = t | (0 - (t >> 8));
  521. }
  522. *dst = s;
  523. }
  524. dst++;
  525. }
  526. }
  527. }
  528. void
  529. fbCompositeSrcAdd_8888x8888(CARD8 op,
  530. PicturePtr pSrc,
  531. PicturePtr pMask,
  532. PicturePtr pDst,
  533. INT16 xSrc,
  534. INT16 ySrc,
  535. INT16 xMask,
  536. INT16 yMask,
  537. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  538. {
  539. CARD32 *dstLine, *dst;
  540. CARD32 *srcLine, *src;
  541. FbStride dstStride, srcStride;
  542. CARD16 w;
  543. CARD32 s, d;
  544. CARD16 t;
  545. CARD32 m, n, o, p;
  546. fbComposeGetStart(pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
  547. fbComposeGetStart(pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);
  548. while (height--) {
  549. dst = dstLine;
  550. dstLine += dstStride;
  551. src = srcLine;
  552. srcLine += srcStride;
  553. w = width;
  554. while (w--) {
  555. s = *src++;
  556. if (s) {
  557. if (s != 0xffffffff) {
  558. d = *dst;
  559. if (d) {
  560. m = FbAdd(s, d, 0, t);
  561. n = FbAdd(s, d, 8, t);
  562. o = FbAdd(s, d, 16, t);
  563. p = FbAdd(s, d, 24, t);
  564. s = m | n | o | p;
  565. }
  566. }
  567. *dst = s;
  568. }
  569. dst++;
  570. }
  571. }
  572. }
  573. void
  574. fbCompositeSrcAdd_1000x1000(CARD8 op,
  575. PicturePtr pSrc,
  576. PicturePtr pMask,
  577. PicturePtr pDst,
  578. INT16 xSrc,
  579. INT16 ySrc,
  580. INT16 xMask,
  581. INT16 yMask,
  582. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  583. {
  584. FbBits *dstBits, *srcBits;
  585. FbStride dstStride, srcStride;
  586. int dstBpp, srcBpp;
  587. int dstXoff, dstYoff;
  588. int srcXoff, srcYoff;
  589. fbGetDrawable(pSrc->pDrawable, srcBits, srcStride, srcBpp, srcXoff,
  590. srcYoff);
  591. fbGetDrawable(pDst->pDrawable, dstBits, dstStride, dstBpp, dstXoff,
  592. dstYoff);
  593. fbBlt(srcBits + srcStride * (ySrc + srcYoff),
  594. srcStride,
  595. xSrc + srcXoff,
  596. dstBits + dstStride * (yDst + dstYoff),
  597. dstStride,
  598. xDst + dstXoff,
  599. width, height, GXor, FB_ALLONES, srcBpp, FALSE, FALSE);
  600. }
  601. void
  602. fbCompositeSolidMask_nx1xn(CARD8 op,
  603. PicturePtr pSrc,
  604. PicturePtr pMask,
  605. PicturePtr pDst,
  606. INT16 xSrc,
  607. INT16 ySrc,
  608. INT16 xMask,
  609. INT16 yMask,
  610. INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  611. {
  612. FbBits *dstBits;
  613. FbStip *maskBits;
  614. FbStride dstStride, maskStride;
  615. int dstBpp, maskBpp;
  616. int dstXoff, dstYoff;
  617. int maskXoff, maskYoff;
  618. FbBits src;
  619. fbComposeGetSolid(pSrc, src, pDst->format);
  620. if ((src & 0xff000000) != 0xff000000) {
  621. fbCompositeGeneral(op, pSrc, pMask, pDst,
  622. xSrc, ySrc, xMask, yMask, xDst, yDst, width, height);
  623. return;
  624. }
  625. fbGetStipDrawable(pMask->pDrawable, maskBits, maskStride, maskBpp, maskXoff,
  626. maskYoff);
  627. fbGetDrawable(pDst->pDrawable, dstBits, dstStride, dstBpp, dstXoff,
  628. dstYoff);
  629. switch (dstBpp) {
  630. case 32:
  631. break;
  632. case 24:
  633. break;
  634. case 16:
  635. src = cvt8888to0565(src);
  636. break;
  637. }
  638. src = fbReplicatePixel(src, dstBpp);
  639. fbBltOne(maskBits + maskStride * (yMask + maskYoff),
  640. maskStride,
  641. xMask + maskXoff,
  642. dstBits + dstStride * (yDst + dstYoff),
  643. dstStride,
  644. (xDst + dstXoff) * dstBpp,
  645. dstBpp, width * dstBpp, height, 0x0, src, FB_ALLONES, 0x0);
  646. }
  647. # define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
  648. void
  649. fbComposite(CARD8 op,
  650. PicturePtr pSrc,
  651. PicturePtr pMask,
  652. PicturePtr pDst,
  653. INT16 xSrc,
  654. INT16 ySrc,
  655. INT16 xMask,
  656. INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
  657. {
  658. RegionRec region;
  659. int n;
  660. BoxPtr pbox;
  661. CompositeFunc func = NULL;
  662. Bool srcRepeat = pSrc->pDrawable && pSrc->repeat;
  663. Bool maskRepeat = FALSE;
  664. Bool srcAlphaMap = pSrc->alphaMap != 0;
  665. Bool maskAlphaMap = FALSE;
  666. Bool dstAlphaMap = pDst->alphaMap != 0;
  667. int x_msk, y_msk, x_src, y_src, x_dst, y_dst;
  668. int w, h, w_this, h_this;
  669. xDst += pDst->pDrawable->x;
  670. yDst += pDst->pDrawable->y;
  671. if (pSrc->pDrawable) {
  672. xSrc += pSrc->pDrawable->x;
  673. ySrc += pSrc->pDrawable->y;
  674. }
  675. if (pMask && pMask->pDrawable) {
  676. xMask += pMask->pDrawable->x;
  677. yMask += pMask->pDrawable->y;
  678. maskRepeat = pMask->repeat == RepeatNormal;
  679. maskAlphaMap = pMask->alphaMap != 0;
  680. }
  681. if (pSrc->pDrawable && (!pMask || pMask->pDrawable)
  682. && !pSrc->transform && !(pMask && pMask->transform)
  683. && !maskAlphaMap && !srcAlphaMap && !dstAlphaMap
  684. && (pSrc->filter != PictFilterConvolution)
  685. && (!pMask || pMask->filter != PictFilterConvolution))
  686. switch (op) {
  687. case PictOpSrc:
  688. break;
  689. case PictOpOver:
  690. if (pMask) {
  691. if (fbCanGetSolid(pSrc) && !maskRepeat) {
  692. srcRepeat = FALSE;
  693. if (PICT_FORMAT_COLOR(pSrc->format)) {
  694. switch (pMask->format) {
  695. case PICT_a8:
  696. switch (pDst->format) {
  697. case PICT_r5g6b5:
  698. case PICT_b5g6r5:
  699. func = fbCompositeSolidMask_nx8x0565;
  700. break;
  701. case PICT_r8g8b8:
  702. case PICT_b8g8r8:
  703. func = fbCompositeSolidMask_nx8x0888;
  704. break;
  705. case PICT_a8r8g8b8:
  706. case PICT_x8r8g8b8:
  707. case PICT_a8b8g8r8:
  708. case PICT_x8b8g8r8:
  709. func = fbCompositeSolidMask_nx8x8888;
  710. break;
  711. default:
  712. break;
  713. }
  714. break;
  715. case PICT_a8r8g8b8:
  716. if (pMask->componentAlpha) {
  717. switch (pDst->format) {
  718. case PICT_a8r8g8b8:
  719. case PICT_x8r8g8b8:
  720. func =
  721. fbCompositeSolidMask_nx8888x8888C;
  722. break;
  723. case PICT_r5g6b5:
  724. func =
  725. fbCompositeSolidMask_nx8888x0565C;
  726. break;
  727. default:
  728. break;
  729. }
  730. }
  731. break;
  732. case PICT_a8b8g8r8:
  733. if (pMask->componentAlpha) {
  734. switch (pDst->format) {
  735. case PICT_a8b8g8r8:
  736. case PICT_x8b8g8r8:
  737. func =
  738. fbCompositeSolidMask_nx8888x8888C;
  739. break;
  740. case PICT_b5g6r5:
  741. func =
  742. fbCompositeSolidMask_nx8888x0565C;
  743. break;
  744. default:
  745. break;
  746. }
  747. }
  748. break;
  749. case PICT_a1:
  750. switch (pDst->format) {
  751. case PICT_r5g6b5:
  752. case PICT_b5g6r5:
  753. case PICT_r8g8b8:
  754. case PICT_b8g8r8:
  755. case PICT_a8r8g8b8:
  756. case PICT_x8r8g8b8:
  757. case PICT_a8b8g8r8:
  758. case PICT_x8b8g8r8:
  759. func = fbCompositeSolidMask_nx1xn;
  760. break;
  761. default:
  762. break;
  763. }
  764. break;
  765. default:
  766. break;
  767. }
  768. default:
  769. break;
  770. }
  771. }
  772. else if (!srcRepeat) { /* has mask and non-repeating source */
  773. if (pSrc->pDrawable == pMask->pDrawable &&
  774. xSrc == xMask && ySrc == yMask &&
  775. !pMask->componentAlpha && !maskRepeat) {
  776. /* source == mask: non-premultiplied data */
  777. switch (pSrc->format) {
  778. case PICT_x8b8g8r8:
  779. switch (pMask->format) {
  780. case PICT_a8r8g8b8:
  781. case PICT_a8b8g8r8:
  782. switch (pDst->format) {
  783. case PICT_a8r8g8b8:
  784. case PICT_x8r8g8b8:
  785. break;
  786. case PICT_r5g6b5:
  787. break;
  788. default:
  789. break;
  790. }
  791. break;
  792. default:
  793. break;
  794. }
  795. break;
  796. case PICT_x8r8g8b8:
  797. switch (pMask->format) {
  798. case PICT_a8r8g8b8:
  799. case PICT_a8b8g8r8:
  800. switch (pDst->format) {
  801. case PICT_a8b8g8r8:
  802. case PICT_x8b8g8r8:
  803. break;
  804. case PICT_r5g6b5:
  805. break;
  806. default:
  807. break;
  808. }
  809. break;
  810. default:
  811. break;
  812. }
  813. break;
  814. default:
  815. break;
  816. }
  817. break;
  818. }
  819. else {
  820. /* non-repeating source, repeating mask => translucent window */
  821. if (fbCanGetSolid(pMask)) {
  822. if (pSrc->format == PICT_x8r8g8b8 &&
  823. pDst->format == PICT_x8r8g8b8 &&
  824. pMask->format == PICT_a8) {
  825. }
  826. }
  827. }
  828. }
  829. }
  830. else { /* no mask */
  831. if (fbCanGetSolid(pSrc)) {
  832. /* no mask and repeating source */
  833. switch (pSrc->format) {
  834. case PICT_a8r8g8b8:
  835. switch (pDst->format) {
  836. case PICT_a8r8g8b8:
  837. case PICT_x8r8g8b8:
  838. break;
  839. case PICT_r5g6b5:
  840. break;
  841. default:
  842. break;
  843. }
  844. break;
  845. default:
  846. break;
  847. }
  848. }
  849. else if (!srcRepeat) {
  850. switch (pSrc->format) {
  851. case PICT_a8r8g8b8:
  852. switch (pDst->format) {
  853. case PICT_a8r8g8b8:
  854. case PICT_x8r8g8b8:
  855. func = fbCompositeSrc_8888x8888;
  856. break;
  857. case PICT_r8g8b8:
  858. func = fbCompositeSrc_8888x0888;
  859. break;
  860. case PICT_r5g6b5:
  861. func = fbCompositeSrc_8888x0565;
  862. break;
  863. default:
  864. break;
  865. }
  866. break;
  867. case PICT_x8r8g8b8:
  868. switch (pDst->format) {
  869. case PICT_a8r8g8b8:
  870. case PICT_x8r8g8b8:
  871. break;
  872. default:
  873. break;
  874. }
  875. case PICT_x8b8g8r8:
  876. switch (pDst->format) {
  877. case PICT_a8b8g8r8:
  878. case PICT_x8b8g8r8:
  879. break;
  880. default:
  881. break;
  882. }
  883. break;
  884. case PICT_a8b8g8r8:
  885. switch (pDst->format) {
  886. case PICT_a8b8g8r8:
  887. case PICT_x8b8g8r8:
  888. func = fbCompositeSrc_8888x8888;
  889. break;
  890. case PICT_b8g8r8:
  891. func = fbCompositeSrc_8888x0888;
  892. break;
  893. case PICT_b5g6r5:
  894. func = fbCompositeSrc_8888x0565;
  895. break;
  896. default:
  897. break;
  898. }
  899. break;
  900. case PICT_r5g6b5:
  901. switch (pDst->format) {
  902. case PICT_r5g6b5:
  903. func = fbCompositeSrc_0565x0565;
  904. break;
  905. default:
  906. break;
  907. }
  908. break;
  909. case PICT_b5g6r5:
  910. switch (pDst->format) {
  911. case PICT_b5g6r5:
  912. func = fbCompositeSrc_0565x0565;
  913. break;
  914. default:
  915. break;
  916. }
  917. break;
  918. default:
  919. break;
  920. }
  921. }
  922. }
  923. break;
  924. case PictOpAdd:
  925. if (pMask == 0) {
  926. switch (pSrc->format) {
  927. case PICT_a8r8g8b8:
  928. switch (pDst->format) {
  929. case PICT_a8r8g8b8:
  930. func = fbCompositeSrcAdd_8888x8888;
  931. break;
  932. default:
  933. break;
  934. }
  935. break;
  936. case PICT_a8b8g8r8:
  937. switch (pDst->format) {
  938. case PICT_a8b8g8r8:
  939. func = fbCompositeSrcAdd_8888x8888;
  940. break;
  941. default:
  942. break;
  943. }
  944. break;
  945. case PICT_a8:
  946. switch (pDst->format) {
  947. case PICT_a8:
  948. func = fbCompositeSrcAdd_8000x8000;
  949. break;
  950. default:
  951. break;
  952. }
  953. break;
  954. case PICT_a1:
  955. switch (pDst->format) {
  956. case PICT_a1:
  957. func = fbCompositeSrcAdd_1000x1000;
  958. break;
  959. default:
  960. break;
  961. }
  962. break;
  963. default:
  964. break;
  965. }
  966. }
  967. break;
  968. }
  969. if (!func) {
  970. /* no fast path, use the general code */
  971. fbCompositeGeneral(op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask,
  972. xDst, yDst, width, height);
  973. return;
  974. }
  975. if (!miComputeCompositeRegion(&region,
  976. pSrc,
  977. pMask,
  978. pDst,
  979. xSrc,
  980. ySrc,
  981. xMask, yMask, xDst, yDst, width, height))
  982. return;
  983. n = REGION_NUM_RECTS(&region);
  984. pbox = REGION_RECTS(&region);
  985. while (n--) {
  986. h = pbox->y2 - pbox->y1;
  987. y_src = pbox->y1 - yDst + ySrc;
  988. y_msk = pbox->y1 - yDst + yMask;
  989. y_dst = pbox->y1;
  990. while (h) {
  991. h_this = h;
  992. w = pbox->x2 - pbox->x1;
  993. x_src = pbox->x1 - xDst + xSrc;
  994. x_msk = pbox->x1 - xDst + xMask;
  995. x_dst = pbox->x1;
  996. if (maskRepeat) {
  997. y_msk =
  998. mod(y_msk - pMask->pDrawable->y, pMask->pDrawable->height);
  999. if (h_this > pMask->pDrawable->height - y_msk)
  1000. h_this = pMask->pDrawable->height - y_msk;
  1001. y_msk += pMask->pDrawable->y;
  1002. }
  1003. if (srcRepeat) {
  1004. y_src =
  1005. mod(y_src - pSrc->pDrawable->y, pSrc->pDrawable->height);
  1006. if (h_this > pSrc->pDrawable->height - y_src)
  1007. h_this = pSrc->pDrawable->height - y_src;
  1008. y_src += pSrc->pDrawable->y;
  1009. }
  1010. while (w) {
  1011. w_this = w;
  1012. if (maskRepeat) {
  1013. x_msk =
  1014. mod(x_msk - pMask->pDrawable->x,
  1015. pMask->pDrawable->width);
  1016. if (w_this > pMask->pDrawable->width - x_msk)
  1017. w_this = pMask->pDrawable->width - x_msk;
  1018. x_msk += pMask->pDrawable->x;
  1019. }
  1020. if (srcRepeat) {
  1021. x_src =
  1022. mod(x_src - pSrc->pDrawable->x, pSrc->pDrawable->width);
  1023. if (w_this > pSrc->pDrawable->width - x_src)
  1024. w_this = pSrc->pDrawable->width - x_src;
  1025. x_src += pSrc->pDrawable->x;
  1026. }
  1027. (*func) (op, pSrc, pMask, pDst,
  1028. x_src, y_src, x_msk, y_msk, x_dst, y_dst,
  1029. w_this, h_this);
  1030. w -= w_this;
  1031. x_src += w_this;
  1032. x_msk += w_this;
  1033. x_dst += w_this;
  1034. }
  1035. h -= h_this;
  1036. y_src += h_this;
  1037. y_msk += h_this;
  1038. y_dst += h_this;
  1039. }
  1040. pbox++;
  1041. }
  1042. REGION_UNINIT(&region);
  1043. }
  1044. Bool
  1045. fbPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
  1046. {
  1047. PictureScreenPtr ps;
  1048. if (!miPictureInit(pScreen, formats, nformats))
  1049. return FALSE;
  1050. ps = GetPictureScreen(pScreen);
  1051. ps->Composite = fbComposite;
  1052. ps->Glyphs = miGlyphs;
  1053. ps->CompositeRects = miCompositeRects;
  1054. ps->RasterizeTrapezoid = fbRasterizeTrapezoid;
  1055. ps->AddTraps = fbAddTraps;
  1056. ps->AddTriangles = fbAddTriangles;
  1057. return TRUE;
  1058. }