1 /***************************************************************************\
3 |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
5 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
6 |* international laws. Users and possessors of this source code are *|
7 |* hereby granted a nonexclusive, royalty-free copyright license to *|
8 |* use this code in individual and commercial software. *|
10 |* Any use of this source code must include, in the user documenta- *|
11 |* tion and internal comments to the code, notices to the end user *|
14 |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
16 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
17 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
18 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
19 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
20 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
21 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
22 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
23 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
24 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
25 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
26 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
28 |* U.S. Government End Users. This source code is a "commercial *|
29 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
30 |* consisting of "commercial computer software" and "commercial *|
31 |* computer software documentation," as such terms are used in *|
32 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
33 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
34 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
35 |* all U.S. Government End Users acquire the source code with only *|
36 |* those rights set forth herein. *|
38 \***************************************************************************/
40 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_xaa.c,v 1.35 2004/03/20 16:25:18 mvojkovi Exp $ */
42 #include "nv_include.h"
48 static const int NVCopyROP[16] =
52 0x44, /* GXandReverse */
54 0x22, /* GXandInverted */
61 0xDD, /* GXorReverse */
62 0x33, /* GXcopyInverted */
63 0xBB, /* GXorInverted */
68 static const int NVCopyROP_PM[16] =
72 0x4A, /* GXandReverse */
74 0x2A, /* GXandInverted */
81 0xDA, /* GXorReverse */
82 0x3A, /* GXcopyInverted */
83 0xBA, /* GXorInverted */
88 static const int NVPatternROP[16] =
109 NVWaitVSync(ScrnInfoPtr pScrn)
111 NVPtr pNv = NVPTR(pScrn);
113 NVDmaStart(pNv, 5, 0x0000012C, 1);
115 NVDmaStart(pNv, 5, 0x00000134, 1);
116 NVDmaNext (pNv, pNv->CRTCnumber);
117 NVDmaStart(pNv, 5, 0x00000100, 1);
119 NVDmaStart(pNv, 5, 0x00000130, 1);
124 currentRop = 0-15 solid fill
125 16-31 8x8 pattern fill
126 32-47 solid fill with planemask
138 NVPtr pNv = NVPTR(pScrn);
140 NVDmaStart(pNv, NvSubImagePattern, PATTERN_COLOR_0, 4);
141 NVDmaNext (pNv, clr0);
142 NVDmaNext (pNv, clr1);
143 NVDmaNext (pNv, pat0);
144 NVDmaNext (pNv, pat1);
148 NVSetRopSolid(ScrnInfoPtr pScrn, CARD32 rop, CARD32 planemask)
150 NVPtr pNv = NVPTR(pScrn);
152 if(planemask != ~0) {
153 NVSetPattern(pScrn, 0, planemask, ~0, ~0);
154 if(pNv->currentRop != (rop + 32)) {
155 NVDmaStart(pNv, NvSubRop, ROP_SET, 1);
156 NVDmaNext (pNv, NVCopyROP_PM[rop]);
157 pNv->currentRop = rop + 32;
160 if (pNv->currentRop != rop) {
161 if(pNv->currentRop >= 16)
162 NVSetPattern(pScrn, ~0, ~0, ~0, ~0);
163 NVDmaStart(pNv, NvSubRop, ROP_SET, 1);
164 NVDmaNext (pNv, NVCopyROP[rop]);
165 pNv->currentRop = rop;
170 NVSetupForScreenToScreenCopy(
175 int transparency_color
178 NVPtr pNv = NVPTR(pScrn);
180 planemask |= ~0 << pNv->CurrentLayout.depth;
182 NVSetRopSolid(pScrn, rop, planemask);
184 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
188 NVSubsequentScreenToScreenCopy(
195 NVPtr pNv = NVPTR(pScrn);
197 NVDmaStart(pNv, NvSubImageBlit, BLIT_POINT_SRC, 3);
198 NVDmaNext (pNv, (y1 << 16) | x1);
199 NVDmaNext (pNv, (y2 << 16) | x2);
200 NVDmaNext (pNv, (h << 16) | w);
214 NVPtr pNv = NVPTR(pScrn);
216 planemask |= ~0 << pNv->CurrentLayout.depth;
218 NVSetRopSolid(pScrn, rop, planemask);
219 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_COLOR, 1);
220 NVDmaNext (pNv, color);
222 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
226 NVSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
228 NVPtr pNv = NVPTR(pScrn);
230 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_RECTS(0), 2);
231 NVDmaNext (pNv, (x << 16) | y);
232 NVDmaNext (pNv, (w << 16) | h);
239 NVSetupForMono8x8PatternFill (
241 int patternx, int patterny,
247 NVPtr pNv = NVPTR(pScrn);
249 planemask = ~0 << pNv->CurrentLayout.depth;
253 else bg |= planemask;
255 if (pNv->currentRop != (rop + 16)) {
256 NVDmaStart(pNv, NvSubRop, ROP_SET, 1);
257 NVDmaNext (pNv, NVPatternROP[rop]);
258 pNv->currentRop = rop + 16;
261 NVSetPattern(pScrn, bg, fg, patternx, patterny);
262 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_COLOR, 1);
265 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
269 NVSubsequentMono8x8PatternFillRect(
271 int patternx, int patterny,
276 NVPtr pNv = NVPTR(pScrn);
278 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_RECTS(0), 2);
279 NVDmaNext (pNv, (x << 16) | y);
280 NVDmaNext (pNv, (w << 16) | h);
286 static CARD32 _bg_pixel;
287 static CARD32 _fg_pixel;
288 static Bool _transparent;
289 static CARD32 _color_expand_dwords;
290 static CARD32 _color_expand_offset;
291 static int _remaining;
292 static unsigned char *_storage_buffer[1];
295 NVSetupForScanlineCPUToScreenColorExpandFill (
299 unsigned int planemask
302 NVPtr pNv = NVPTR(pScrn);
304 CARD32 mask = ~0 << pNv->CurrentLayout.depth;
307 _fg_pixel = fg | mask;
312 _transparent = FALSE;
313 _bg_pixel = bg | mask;
316 NVSetRopSolid (pScrn, rop, planemask);
320 NVSubsequentScanlineCPUToScreenColorExpandFill (
327 NVPtr pNv = NVPTR(pScrn);
328 int bw = (w + 31) & ~31;
330 _color_expand_dwords = bw >> 5;
334 NVDmaStart(pNv, NvSubRectangle, RECT_EXPAND_ONE_COLOR_CLIP, 5);
335 NVDmaNext (pNv, (y << 16) | ((x + skipleft) & 0xFFFF));
336 NVDmaNext (pNv, ((y + h) << 16) | ((x + w) & 0xFFFF));
337 NVDmaNext (pNv, _fg_pixel);
338 NVDmaNext (pNv, (h << 16) | bw);
339 NVDmaNext (pNv, (y << 16) | (x & 0xFFFF));
340 _color_expand_offset = RECT_EXPAND_ONE_COLOR_DATA(0);
342 NVDmaStart(pNv, NvSubRectangle, RECT_EXPAND_TWO_COLOR_CLIP, 7);
343 NVDmaNext (pNv, (y << 16) | ((x + skipleft) & 0xFFFF));
344 NVDmaNext (pNv, ((y + h) << 16) | ((x + w) & 0xFFFF));
345 NVDmaNext (pNv, _bg_pixel);
346 NVDmaNext (pNv, _fg_pixel);
347 NVDmaNext (pNv, (h << 16) | bw);
348 NVDmaNext (pNv, (h << 16) | bw);
349 NVDmaNext (pNv, (y << 16) | (x & 0xFFFF));
350 _color_expand_offset = RECT_EXPAND_TWO_COLOR_DATA(0);
353 NVDmaStart(pNv, NvSubRectangle, _color_expand_offset, _color_expand_dwords);
354 _storage_buffer[0] = (unsigned char*)&pNv->dmaBase[pNv->dmaCurrent];
358 NVSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
360 NVPtr pNv = NVPTR(pScrn);
362 pNv->dmaCurrent += _color_expand_dwords;
365 NVDmaStart(pNv, NvSubRectangle, _color_expand_offset, _color_expand_dwords);
366 _storage_buffer[0] = (unsigned char*)&pNv->dmaBase[pNv->dmaCurrent];
368 /* hardware bug workaround */
369 NVDmaStart(pNv, NvSubImageBlit, BLIT_POINT_SRC, 1);
376 NVSetupForScanlineImageWrite(
377 ScrnInfoPtr pScrn, int rop,
378 unsigned int planemask,
383 NVPtr pNv = NVPTR(pScrn);
385 planemask |= ~0 << pNv->CurrentLayout.depth;
387 NVSetRopSolid (pScrn, rop, planemask);
390 static CARD32 _image_size;
391 static CARD32 _image_srcpoint;
392 static CARD32 _image_dstpoint;
393 static CARD32 _image_dstpitch;
396 NVSubsequentScanlineImageWriteRect(
403 NVPtr pNv = NVPTR(pScrn);
404 int Bpp = pNv->CurrentLayout.bitsPerPixel >> 3;
407 _image_size = (1 << 16) | (w - skipleft);
408 _image_srcpoint = skipleft;
409 _image_dstpoint = (y << 16) | (x + skipleft);
411 _image_dstpitch = pNv->CurrentLayout.displayWidth * Bpp;
412 image_srcpitch = ((w * Bpp) + 63) & ~63;
413 _storage_buffer[0] = pNv->ScratchBuffer->map;
417 NVDmaStart(pNv, NvSubContextSurfaces, SURFACE_PITCH, 2);
418 NVDmaNext (pNv, (_image_dstpitch << 16) | image_srcpitch);
419 NVDmaNext (pNv, pNv->ScratchBuffer->offset);
422 static void NVSubsequentImageWriteScanline(ScrnInfoPtr pScrn, int bufno)
424 NVPtr pNv = NVPTR(pScrn);
426 NVDmaStart(pNv, NvSubImageBlit, BLIT_POINT_SRC, 3);
427 NVDmaNext (pNv, _image_srcpoint);
428 NVDmaNext (pNv, _image_dstpoint);
429 NVDmaNext (pNv, _image_size);
433 _image_dstpoint += (1 << 16);
436 NVDmaStart(pNv, NvSubContextSurfaces, SURFACE_PITCH, 2);
437 NVDmaNext (pNv, _image_dstpitch | (_image_dstpitch << 16));
438 NVDmaNext (pNv, pNv->FB->offset);
443 NVSetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop, unsigned planemask)
445 NVPtr pNv = NVPTR(pScrn);
447 planemask |= ~0 << pNv->CurrentLayout.depth;
449 NVSetRopSolid(pScrn, rop, planemask);
453 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
457 NVSubsequentSolidHorVertLine(ScrnInfoPtr pScrn, int x, int y, int len, int dir)
459 NVPtr pNv = NVPTR(pScrn);
461 NVDmaStart(pNv, NvSubSolidLine, LINE_COLOR, 1);
462 NVDmaNext (pNv, _fg_pixel);
463 NVDmaStart(pNv, NvSubSolidLine, LINE_LINES(0), 2);
464 NVDmaNext (pNv, (y << 16) | ( x & 0xffff));
465 if(dir == DEGREES_0) {
466 NVDmaNext (pNv, (y << 16) | ((x + len) & 0xffff));
468 NVDmaNext (pNv, ((y + len) << 16) | (x & 0xffff));
473 NVSubsequentSolidTwoPointLine(
480 NVPtr pNv = NVPTR(pScrn);
481 Bool drawLast = !(flags & OMIT_LAST);
483 NVDmaStart(pNv, NvSubSolidLine, LINE_COLOR, 1);
484 NVDmaNext (pNv, _fg_pixel);
485 NVDmaStart(pNv, NvSubSolidLine, LINE_LINES(0), drawLast ? 4 : 2);
486 NVDmaNext (pNv, (y1 << 16) | (x1 & 0xffff));
487 NVDmaNext (pNv, (y2 << 16) | (x2 & 0xffff));
489 NVDmaNext (pNv, (y2 << 16) | (x2 & 0xffff));
490 NVDmaNext (pNv, ((y2 + 1) << 16) | (x2 & 0xffff));
495 NVSetClippingRectangle(ScrnInfoPtr pScrn, int x1, int y1, int x2, int y2)
497 NVPtr pNv = NVPTR(pScrn);
501 NVDmaStart(pNv, NvSubClipRectangle, CLIP_POINT, 2);
502 NVDmaNext (pNv, (y1 << 16) | x1);
503 NVDmaNext (pNv, (h << 16) | w);
507 NVDisableClipping(ScrnInfoPtr pScrn)
509 NVPtr pNv = NVPTR(pScrn);
511 NVDmaStart(pNv, NvSubClipRectangle, CLIP_POINT, 2);
513 NVDmaNext (pNv, 0x7FFF7FFF);
517 /* Initialize XAA acceleration info */
519 NVXaaInit(ScreenPtr pScreen)
521 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
522 NVPtr pNv = NVPTR(pScrn);
525 accel = pNv->AccelInfoRec = XAACreateInfoRec();
526 if(!accel) return FALSE;
528 accel->Flags = LINEAR_FRAMEBUFFER | PIXMAP_CACHE | OFFSCREEN_PIXMAPS;
529 accel->Sync = NVSync;
531 accel->ScreenToScreenCopyFlags = NO_TRANSPARENCY;
532 accel->SetupForScreenToScreenCopy = NVSetupForScreenToScreenCopy;
533 accel->SubsequentScreenToScreenCopy = NVSubsequentScreenToScreenCopy;
535 accel->SolidFillFlags = 0;
536 accel->SetupForSolidFill = NVSetupForSolidFill;
537 accel->SubsequentSolidFillRect = NVSubsequentSolidFillRect;
539 accel->Mono8x8PatternFillFlags = HARDWARE_PATTERN_SCREEN_ORIGIN |
540 HARDWARE_PATTERN_PROGRAMMED_BITS |
542 accel->SetupForMono8x8PatternFill = NVSetupForMono8x8PatternFill;
543 accel->SubsequentMono8x8PatternFillRect = NVSubsequentMono8x8PatternFillRect;
545 accel->ScanlineCPUToScreenColorExpandFillFlags =
546 BIT_ORDER_IN_BYTE_LSBFIRST |
547 CPU_TRANSFER_PAD_DWORD |
549 LEFT_EDGE_CLIPPING_NEGATIVE_X;
550 accel->NumScanlineColorExpandBuffers = 1;
551 accel->SetupForScanlineCPUToScreenColorExpandFill =
552 NVSetupForScanlineCPUToScreenColorExpandFill;
553 accel->SubsequentScanlineCPUToScreenColorExpandFill =
554 NVSubsequentScanlineCPUToScreenColorExpandFill;
555 accel->SubsequentColorExpandScanline =
556 NVSubsequentColorExpandScanline;
557 accel->ScanlineColorExpandBuffers = _storage_buffer;
559 accel->ScanlineImageWriteFlags = NO_GXCOPY |
562 LEFT_EDGE_CLIPPING_NEGATIVE_X;
563 accel->NumScanlineImageWriteBuffers = 1;
564 accel->SetupForScanlineImageWrite = NVSetupForScanlineImageWrite;
565 accel->SubsequentScanlineImageWriteRect = NVSubsequentScanlineImageWriteRect;
566 accel->SubsequentImageWriteScanline = NVSubsequentImageWriteScanline;
567 accel->ScanlineImageWriteBuffers = _storage_buffer;
569 accel->SolidLineFlags = 0;
570 accel->SetupForSolidLine = NVSetupForSolidLine;
571 accel->SubsequentSolidHorVertLine = NVSubsequentSolidHorVertLine;
572 accel->SubsequentSolidTwoPointLine = NVSubsequentSolidTwoPointLine;
573 accel->SetClippingRectangle = NVSetClippingRectangle;
574 accel->DisableClipping = NVDisableClipping;
575 accel->ClippingFlags = HARDWARE_CLIP_SOLID_LINE;
577 miSetZeroLineBias(pScreen, OCTANT1 | OCTANT3 | OCTANT4 | OCTANT6);
579 return (XAAInit(pScreen, accel));