2 #ifdef HAVE_XORG_CONFIG_H
3 #include <xorg-config.h>
8 #include "xf86_OSproc.h"
12 #include "scrnintstr.h"
14 #include "pixmapstr.h"
19 void XAAMoveDWORDS_FixedBase(
20 register CARD32
* dest
,
24 while(dwords
& ~0x03) {
35 if(dwords
== 1) return;
37 if(dwords
== 2) return;
42 register CARD32
* dest
,
46 while(dwords
& ~0x03) {
48 *(dest
+ 1) = *(src
+ 1);
49 *(dest
+ 2) = *(src
+ 2);
50 *(dest
+ 3) = *(src
+ 3);
57 if(dwords
== 1) return;
58 *(dest
+ 1) = *(src
+ 1);
59 if(dwords
== 2) return;
60 *(dest
+ 2) = *(src
+ 2);
63 void XAAMoveDWORDS_FixedSrc(
64 register CARD32
* dest
,
68 while(dwords
& ~0x03) {
78 if(dwords
== 1) return;
80 if(dwords
== 2) return;
87 int x
, int y
, int w
, int h
,
88 unsigned char *srcInit
,
89 int srcwidth
, /* bytes */
91 unsigned int planemask
,
94 XAAInfoRecPtr infoRec
= GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn
);
95 int count
, dwords
= ((w
* 3) + 3) >> 2;
99 if((infoRec
->ImageWriteFlags
& CPU_TRANSFER_PAD_QWORD
) &&
100 ((dwords
* h
) & 0x01)) {
104 (*infoRec
->SetupForImageWrite
)(pScrn
, rop
, planemask
, trans
, 24, 24);
105 (*infoRec
->SubsequentImageWriteRect
)(pScrn
, x
, y
, w
, h
, 0);
107 if(dwords
> infoRec
->ImageWriteRange
) {
108 dst
= (CARD32
*)infoRec
->ImageWriteBase
;
110 src
= (CARD32
*)srcInit
;
114 *dst
= (src
[0] & 0x00ffffff) | (src
[1] << 24);
115 *dst
= ((src
[1] >> 8) & 0x0000ffff) | (src
[2] << 16);
116 *dst
= ((src
[2] >> 16) & 0x000000ff) | (src
[3] << 8);
122 case 1: *dst
= src
[0];
124 case 2: *dst
= (src
[0] & 0x00ffffff) | (src
[1] << 24);
127 default: *dst
= (src
[0] & 0x00ffffff) | (src
[1] << 24);
128 *dst
= ((src
[1] >> 8) & 0x0000ffff) | (src
[2] << 16);
136 dst
= (CARD32
*)infoRec
->ImageWriteBase
;
137 src
= (CARD32
*)srcInit
;
141 dst
[0] = (src
[0] & 0x00ffffff) | (src
[1] << 24);
142 dst
[1] = ((src
[1] >> 8) & 0x0000ffff) | (src
[2] << 16);
143 dst
[2] = ((src
[2] >> 16) & 0x000000ff) | (src
[3] << 8);
150 case 1: dst
[0] = src
[0];
152 case 2: dst
[0] = (src
[0] & 0x00ffffff) | (src
[1] << 24);
153 dst
[1] = src
[1] >> 8;
155 default: dst
[0] = (src
[0] & 0x00ffffff) | (src
[1] << 24);
156 dst
[1] = ((src
[1] >> 8) & 0x0000ffff) | (src
[2] << 16);
157 dst
[2] = src
[2] >> 16;
165 CARD32
* base
= (CARD32
*)infoRec
->ImageWriteBase
;
169 if(infoRec
->ImageWriteFlags
& SYNC_AFTER_IMAGE_WRITE
)
170 (*infoRec
->Sync
)(pScrn
);
171 else SET_SYNC_FLAG(infoRec
);
178 int x
, int y
, int w
, int h
,
180 int srcwidth
, /* bytes */
182 unsigned int planemask
,
186 XAAInfoRecPtr infoRec
;
187 int dwords
, skipleft
, Bpp
;
188 Bool beCareful
, PlusOne
;
190 if((bpp
== 32) && (pScrn
->bitsPerPixel
== 24)) {
191 XAAWritePixmap32To24(pScrn
, x
, y
, w
, h
, src
, srcwidth
,
192 rop
, planemask
, trans
);
196 infoRec
= GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn
);
197 beCareful
= PlusOne
= FALSE
;
200 if((skipleft
= (long)src
& 0x03L
)) {
201 if(!(infoRec
->ImageWriteFlags
& LEFT_EDGE_CLIPPING
)) {
208 skipleft
= 4 - skipleft
;
212 if((x
< skipleft
) && !(infoRec
->ImageWriteFlags
&
213 LEFT_EDGE_CLIPPING_NEGATIVE_X
)) {
224 else /* is this Alpha friendly ? */
225 src
= (unsigned char*)((long)src
& ~0x03L
);
230 dwords
= ((w
* Bpp
) + 3) >> 2;
232 if((infoRec
->ImageWriteFlags
& CPU_TRANSFER_PAD_QWORD
) &&
233 ((dwords
* h
) & 0x01)) {
238 (*infoRec
->SetupForImageWrite
)(pScrn
, rop
, planemask
, trans
, bpp
, depth
);
239 (*infoRec
->SubsequentImageWriteRect
)(pScrn
, x
, y
, w
, h
, skipleft
);
242 /* in cases with bad alignment we have to be careful not
243 to read beyond the end of the source */
244 if(((x
* Bpp
) + (dwords
<< 2)) > srcwidth
) h
--;
245 else beCareful
= FALSE
;
248 if(dwords
> infoRec
->ImageWriteRange
) {
250 XAAMoveDWORDS_FixedBase((CARD32
*)infoRec
->ImageWriteBase
,
251 (CARD32
*)src
, dwords
);
255 int shift
= ((long)src
& 0x03L
) << 3;
257 XAAMoveDWORDS_FixedBase((CARD32
*)infoRec
->ImageWriteBase
,
258 (CARD32
*)src
, dwords
);
259 src
= (unsigned char*)((long)(src
+ (dwords
<< 2)) & ~0x03L
);
260 *((CARD32
*)infoRec
->ImageWriteBase
) = *((CARD32
*)src
) >> shift
;
263 if(srcwidth
== (dwords
<< 2)) {
264 int decrement
= infoRec
->ImageWriteRange
/dwords
;
266 while(h
> decrement
) {
267 XAAMoveDWORDS((CARD32
*)infoRec
->ImageWriteBase
,
268 (CARD32
*)src
, dwords
* decrement
);
269 src
+= (srcwidth
* decrement
);
273 XAAMoveDWORDS((CARD32
*)infoRec
->ImageWriteBase
,
274 (CARD32
*)src
, dwords
* h
);
275 if(beCareful
) src
+= (srcwidth
* h
);
279 XAAMoveDWORDS((CARD32
*)infoRec
->ImageWriteBase
,
280 (CARD32
*)src
, dwords
);
286 int shift
= ((long)src
& 0x03L
) << 3;
288 XAAMoveDWORDS((CARD32
*)infoRec
->ImageWriteBase
,
289 (CARD32
*)src
, dwords
);
290 src
= (unsigned char*)((long)(src
+ (dwords
<< 2)) & ~0x03L
);
292 ((CARD32
*)infoRec
->ImageWriteBase
)[dwords
] =
293 *((CARD32
*)src
) >> shift
;
298 CARD32
* base
= (CARD32
*)infoRec
->ImageWriteBase
;
302 if(infoRec
->ImageWriteFlags
& SYNC_AFTER_IMAGE_WRITE
)
303 (*infoRec
->Sync
)(pScrn
);
304 else SET_SYNC_FLAG(infoRec
);
309 XAAWritePixmapScanline (
311 int x
, int y
, int w
, int h
,
313 int srcwidth
, /* bytes */
315 unsigned int planemask
,
319 XAAInfoRecPtr infoRec
= GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn
);
320 int dwords
, skipleft
, bufferNo
= 0, Bpp
= bpp
>> 3;
321 Bool beCareful
= FALSE
;
324 if((skipleft
= (long)src
& 0x03L
)) {
325 if(!(infoRec
->ScanlineImageWriteFlags
& LEFT_EDGE_CLIPPING
)) {
332 skipleft
= 4 - skipleft
;
336 if((x
< skipleft
) && !(infoRec
->ScanlineImageWriteFlags
&
337 LEFT_EDGE_CLIPPING_NEGATIVE_X
)) {
349 src
= (unsigned char*)((long)src
& ~0x03L
);
354 dwords
= ((w
* Bpp
) + 3) >> 2;
356 (*infoRec
->SetupForScanlineImageWrite
)(
357 pScrn
, rop
, planemask
, trans
, bpp
, depth
);
358 (*infoRec
->SubsequentScanlineImageWriteRect
)(pScrn
, x
, y
, w
, h
, skipleft
);
361 /* in cases with bad alignment we have to be careful not
362 to read beyond the end of the source */
363 if(((x
* Bpp
) + (dwords
<< 2)) > srcwidth
) h
--;
364 else beCareful
= FALSE
;
368 base
= (CARD32
*)infoRec
->ScanlineImageWriteBuffers
[bufferNo
];
369 XAAMoveDWORDS(base
, (CARD32
*)src
, dwords
);
370 (*infoRec
->SubsequentImageWriteScanline
)(pScrn
, bufferNo
++);
372 if(bufferNo
>= infoRec
->NumScanlineImageWriteBuffers
)
377 int shift
= ((long)src
& 0x03L
) << 3;
378 base
= (CARD32
*)infoRec
->ScanlineImageWriteBuffers
[bufferNo
];
380 XAAMoveDWORDS(base
,(CARD32
*)src
, dwords
);
381 src
= (unsigned char*)((long)(src
+ (dwords
<< 2)) & ~0x03L
);
383 base
[dwords
] = *((CARD32
*)src
) >> shift
;
384 (*infoRec
->SubsequentImageWriteScanline
)(pScrn
, bufferNo
);
387 SET_SYNC_FLAG(infoRec
);
404 XAAInfoRecPtr infoRec
= GET_XAAINFORECPTR_FROM_GC(pGC
);
405 int bpp
= BitsPerPixel(depth
);
406 Bool depthBug
= FALSE
;
409 if(!REGION_NUM_RECTS(pGC
->pCompositeClip
))
412 depthBug
= XAA_DEPTH_BUG(pGC
);
414 if(((format
== ZPixmap
) && infoRec
->WritePixmap
&&
415 ((pDraw
->bitsPerPixel
== bpp
) ||
416 ((pDraw
->bitsPerPixel
== 24) && (bpp
== 32) &&
417 (infoRec
->WritePixmapFlags
& CONVERT_32BPP_TO_24BPP
))) &&
418 CHECK_ROP(pGC
,infoRec
->WritePixmapFlags
) &&
419 CHECK_ROPSRC(pGC
,infoRec
->WritePixmapFlags
) &&
420 CHECK_PLANEMASK(pGC
,infoRec
->WritePixmapFlags
) &&
421 CHECK_NO_GXCOPY(pGC
,infoRec
->WritePixmapFlags
)) ||
422 ((format
== XYBitmap
) && !depthBug
&& infoRec
->WriteBitmap
&&
423 CHECK_ROP(pGC
,infoRec
->WriteBitmapFlags
) &&
424 CHECK_ROPSRC(pGC
,infoRec
->WriteBitmapFlags
) &&
425 CHECK_PLANEMASK(pGC
,infoRec
->WriteBitmapFlags
) &&
426 CHECK_COLORS(pGC
,infoRec
->WriteBitmapFlags
) &&
427 !(infoRec
->WriteBitmapFlags
& TRANSPARENCY_ONLY
)) ||
428 ((format
== XYPixmap
) && !depthBug
&& infoRec
->WriteBitmap
&&
429 CHECK_ROP(pGC
,infoRec
->WriteBitmapFlags
) &&
430 CHECK_ROPSRC(pGC
,infoRec
->WriteBitmapFlags
) &&
431 !(infoRec
->WriteBitmapFlags
& NO_PLANEMASK
) &&
432 !(infoRec
->WriteBitmapFlags
& TRANSPARENCY_ONLY
))){
434 int MaxBoxes
= REGION_NUM_RECTS(pGC
->pCompositeClip
);
435 BoxPtr pbox
, pClipBoxes
;
436 int nboxes
, srcx
, srcy
, srcwidth
;
439 TheRect
.x
= pDraw
->x
+ x
;
440 TheRect
.y
= pDraw
->y
+ y
;
444 if(MaxBoxes
> (infoRec
->PreAllocSize
/sizeof(BoxRec
))) {
445 pClipBoxes
= xalloc(MaxBoxes
* sizeof(BoxRec
));
446 if(!pClipBoxes
) return;
447 } else pClipBoxes
= (BoxPtr
)infoRec
->PreAllocMem
;
449 nboxes
= XAAGetRectClipBoxes(pGC
, pClipBoxes
, 1, &TheRect
);
452 if(format
== XYBitmap
) {
453 srcwidth
= BitmapBytePad(leftPad
+ w
);
455 srcx
= pbox
->x1
- TheRect
.x
+ leftPad
;
456 srcy
= pbox
->y1
- TheRect
.y
;
457 (*infoRec
->WriteBitmap
)(infoRec
->pScrn
, pbox
->x1
, pbox
->y1
,
458 pbox
->x2
- pbox
->x1
, pbox
->y2
- pbox
->y1
,
459 (unsigned char*)pImage
+
460 (srcwidth
* srcy
) + ((srcx
>> 5) << 2),
461 srcwidth
, srcx
& 31, pGC
->fgPixel
, pGC
->bgPixel
,
462 pGC
->alu
, pGC
->planemask
);
465 } else if(format
== ZPixmap
) {
467 srcwidth
= PixmapBytePad(leftPad
+ w
, depth
);
469 srcx
= pbox
->x1
- TheRect
.x
+ leftPad
;
470 srcy
= pbox
->y1
- TheRect
.y
;
471 (*infoRec
->WritePixmap
)(infoRec
->pScrn
, pbox
->x1
, pbox
->y1
,
472 pbox
->x2
- pbox
->x1
, pbox
->y2
- pbox
->y1
,
473 (unsigned char*)pImage
+
474 (srcwidth
* srcy
) + (srcx
* Bpp
),
475 srcwidth
, pGC
->alu
, pGC
->planemask
, -1,
479 } else { /* XYPixmap */
480 int depth
= pGC
->depth
;
481 int numBox
, increment
;
482 unsigned long i
, mask
;
485 srcwidth
= BitmapBytePad(w
+ leftPad
);
486 increment
= h
* srcwidth
;
487 i
= 1 << (depth
- 1);
490 if((infoRec
->pScrn
->overlayFlags
& OVERLAY_8_32_PLANAR
) &&
492 i
= 0x80000000; mask
= 0xff000000;
495 for(; i
& mask
; i
>>= 1, pImage
+= increment
) {
496 if(i
& pGC
->planemask
) {
500 srcx
= pntBox
->x1
- TheRect
.x
+ leftPad
;
501 srcy
= pntBox
->y1
- TheRect
.y
;
502 (*infoRec
->WriteBitmap
)(infoRec
->pScrn
,
503 pntBox
->x1
, pntBox
->y1
,
504 pntBox
->x2
- pntBox
->x1
,
505 pntBox
->y2
- pntBox
->y1
,
506 (unsigned char*)pImage
+
507 (srcwidth
* srcy
) + ((srcx
>> 5) << 2),
508 srcwidth
, srcx
& 31, ~0, 0, pGC
->alu
, i
);
516 if(pClipBoxes
!= (BoxPtr
)infoRec
->PreAllocMem
)
519 XAAFallbackOps
.PutImage(pDraw
, pGC
, depth
, x
, y
, w
, h
, leftPad
,