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.33 2003/09/21 00:17:34 mvojkovi Exp $ */
42 #include "nv_include.h"
47 static const int NVCopyROP[16] =
51 0x44, /* GXandReverse */
53 0x22, /* GXandInverted */
60 0xDD, /* GXorReverse */
61 0x33, /* GXcopyInverted */
62 0xBB, /* GXorInverted */
67 static const int NVCopyROP_PM[16] =
71 0x4A, /* GXandReverse */
73 0x2A, /* GXandInverted */
80 0xDA, /* GXorReverse */
81 0x3A, /* GXcopyInverted */
82 0xBA, /* GXorInverted */
87 static const int NVPatternROP[16] =
108 NVDmaKickoff(NVPtr pNv)
110 if(pNv->dmaCurrent != pNv->dmaPut) {
111 pNv->dmaPut = pNv->dmaCurrent;
112 WRITE_PUT(pNv, pNv->dmaPut);
117 /* There is a HW race condition with videoram command buffers.
118 You can't jump to the location of your put offset. We write put
119 at the jump offset + SKIPS dwords with noop padding in between
120 to solve this problem */
132 while(pNv->dmaFree < size) {
133 dmaGet = READ_GET(pNv);
135 if(pNv->dmaPut >= dmaGet) {
136 pNv->dmaFree = pNv->dmaMax - pNv->dmaCurrent;
137 if(pNv->dmaFree < size) {
138 NVDmaNext(pNv, 0x20000000);
139 if(dmaGet <= SKIPS) {
140 if(pNv->dmaPut <= SKIPS) /* corner case - will be idle */
141 WRITE_PUT(pNv, SKIPS + 1);
142 do { dmaGet = READ_GET(pNv); }
143 while(dmaGet <= SKIPS);
145 WRITE_PUT(pNv, SKIPS);
146 pNv->dmaCurrent = pNv->dmaPut = SKIPS;
147 pNv->dmaFree = dmaGet - (SKIPS + 1);
150 pNv->dmaFree = dmaGet - pNv->dmaCurrent - 1;
155 currentRop = 0-15 solid fill
156 16-31 8x8 pattern fill
157 32-47 solid fill with planemask
169 NVPtr pNv = NVPTR(pScrn);
171 NVDmaStart(pNv, PATTERN_COLOR_0, 4);
172 NVDmaNext (pNv, clr0);
173 NVDmaNext (pNv, clr1);
174 NVDmaNext (pNv, pat0);
175 NVDmaNext (pNv, pat1);
179 NVSetRopSolid(ScrnInfoPtr pScrn, CARD32 rop, CARD32 planemask)
181 NVPtr pNv = NVPTR(pScrn);
183 if(planemask != ~0) {
184 NVSetPattern(pScrn, 0, planemask, ~0, ~0);
185 if(pNv->currentRop != (rop + 32)) {
186 NVDmaStart(pNv, ROP_SET, 1);
187 NVDmaNext (pNv, NVCopyROP_PM[rop]);
188 pNv->currentRop = rop + 32;
191 if (pNv->currentRop != rop) {
192 if(pNv->currentRop >= 16)
193 NVSetPattern(pScrn, ~0, ~0, ~0, ~0);
194 NVDmaStart(pNv, ROP_SET, 1);
195 NVDmaNext (pNv, NVCopyROP[rop]);
196 pNv->currentRop = rop;
200 void NVResetGraphics(ScrnInfoPtr pScrn)
202 NVPtr pNv = NVPTR(pScrn);
203 CARD32 surfaceFormat, patternFormat, rectFormat, lineFormat;
206 if(pNv->NoAccel) return;
208 pitch = pNv->CurrentLayout.displayWidth *
209 (pNv->CurrentLayout.bitsPerPixel >> 3);
211 pNv->dmaBase = (CARD32*)(&pNv->FbStart[pNv->FbUsableSize]);
213 for(i = 0; i < SKIPS; i++)
214 pNv->dmaBase[i] = 0x00000000;
216 pNv->dmaBase[0x0 + SKIPS] = 0x00040000;
217 pNv->dmaBase[0x1 + SKIPS] = 0x80000010;
218 pNv->dmaBase[0x2 + SKIPS] = 0x00042000;
219 pNv->dmaBase[0x3 + SKIPS] = 0x80000011;
220 pNv->dmaBase[0x4 + SKIPS] = 0x00044000;
221 pNv->dmaBase[0x5 + SKIPS] = 0x80000012;
222 pNv->dmaBase[0x6 + SKIPS] = 0x00046000;
223 pNv->dmaBase[0x7 + SKIPS] = 0x80000013;
224 pNv->dmaBase[0x8 + SKIPS] = 0x00048000;
225 pNv->dmaBase[0x9 + SKIPS] = 0x80000014;
226 pNv->dmaBase[0xA + SKIPS] = 0x0004A000;
227 pNv->dmaBase[0xB + SKIPS] = 0x80000015;
228 pNv->dmaBase[0xC + SKIPS] = 0x0004C000;
229 pNv->dmaBase[0xD + SKIPS] = 0x80000016;
230 pNv->dmaBase[0xE + SKIPS] = 0x0004E000;
231 pNv->dmaBase[0xF + SKIPS] = 0x80000017;
234 pNv->dmaCurrent = 16 + SKIPS;
236 pNv->dmaFree = pNv->dmaMax - pNv->dmaCurrent;
238 switch(pNv->CurrentLayout.depth) {
240 surfaceFormat = SURFACE_FORMAT_DEPTH24;
241 patternFormat = PATTERN_FORMAT_DEPTH24;
242 rectFormat = RECT_FORMAT_DEPTH24;
243 lineFormat = LINE_FORMAT_DEPTH24;
247 surfaceFormat = SURFACE_FORMAT_DEPTH16;
248 patternFormat = PATTERN_FORMAT_DEPTH16;
249 rectFormat = RECT_FORMAT_DEPTH16;
250 lineFormat = LINE_FORMAT_DEPTH16;
253 surfaceFormat = SURFACE_FORMAT_DEPTH8;
254 patternFormat = PATTERN_FORMAT_DEPTH8;
255 rectFormat = RECT_FORMAT_DEPTH8;
256 lineFormat = LINE_FORMAT_DEPTH8;
260 NVDmaStart(pNv, SURFACE_FORMAT, 4);
261 NVDmaNext (pNv, surfaceFormat);
262 NVDmaNext (pNv, pitch | (pitch << 16));
266 NVDmaStart(pNv, PATTERN_FORMAT, 1);
267 NVDmaNext (pNv, patternFormat);
269 NVDmaStart(pNv, RECT_FORMAT, 1);
270 NVDmaNext (pNv, rectFormat);
272 NVDmaStart(pNv, LINE_FORMAT, 1);
273 NVDmaNext (pNv, lineFormat);
275 pNv->currentRop = ~0; /* set to something invalid */
276 NVSetRopSolid(pScrn, GXcopy, ~0);
281 void NVSync(ScrnInfoPtr pScrn)
283 NVPtr pNv = NVPTR(pScrn);
285 if(pNv->DMAKickoffCallback)
286 (*pNv->DMAKickoffCallback)(pScrn);
288 while(READ_GET(pNv) != pNv->dmaPut);
290 while(pNv->PGRAPH[0x0700/4]);
294 NVDMAKickoffCallback (ScrnInfoPtr pScrn)
296 NVPtr pNv = NVPTR(pScrn);
299 pNv->DMAKickoffCallback = NULL;
304 NVSetupForScreenToScreenCopy(
309 int transparency_color
312 NVPtr pNv = NVPTR(pScrn);
314 planemask |= ~0 << pNv->CurrentLayout.depth;
316 NVSetRopSolid(pScrn, rop, planemask);
318 pNv->DMAKickoffCallback = NVDMAKickoffCallback;
322 NVSubsequentScreenToScreenCopy(
329 NVPtr pNv = NVPTR(pScrn);
331 NVDmaStart(pNv, BLIT_POINT_SRC, 3);
332 NVDmaNext (pNv, (y1 << 16) | x1);
333 NVDmaNext (pNv, (y2 << 16) | x2);
334 NVDmaNext (pNv, (h << 16) | w);
348 NVPtr pNv = NVPTR(pScrn);
350 planemask |= ~0 << pNv->CurrentLayout.depth;
352 NVSetRopSolid(pScrn, rop, planemask);
353 NVDmaStart(pNv, RECT_SOLID_COLOR, 1);
354 NVDmaNext (pNv, color);
356 pNv->DMAKickoffCallback = NVDMAKickoffCallback;
360 NVSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
362 NVPtr pNv = NVPTR(pScrn);
364 NVDmaStart(pNv, RECT_SOLID_RECTS(0), 2);
365 NVDmaNext (pNv, (x << 16) | y);
366 NVDmaNext (pNv, (w << 16) | h);
373 NVSetupForMono8x8PatternFill (
375 int patternx, int patterny,
381 NVPtr pNv = NVPTR(pScrn);
383 planemask = ~0 << pNv->CurrentLayout.depth;
387 else bg |= planemask;
389 if (pNv->currentRop != (rop + 16)) {
390 NVDmaStart(pNv, ROP_SET, 1);
391 NVDmaNext (pNv, NVPatternROP[rop]);
392 pNv->currentRop = rop + 16;
395 NVSetPattern(pScrn, bg, fg, patternx, patterny);
396 NVDmaStart(pNv, RECT_SOLID_COLOR, 1);
399 pNv->DMAKickoffCallback = NVDMAKickoffCallback;
403 NVSubsequentMono8x8PatternFillRect(
405 int patternx, int patterny,
410 NVPtr pNv = NVPTR(pScrn);
412 NVDmaStart(pNv, RECT_SOLID_RECTS(0), 2);
413 NVDmaNext (pNv, (x << 16) | y);
414 NVDmaNext (pNv, (w << 16) | h);
420 static CARD32 _bg_pixel;
421 static CARD32 _fg_pixel;
422 static Bool _transparent;
423 static CARD32 _color_expand_dwords;
424 static CARD32 _color_expand_offset;
425 static int _remaining;
426 static unsigned char *_storage_buffer[1];
429 NVSetupForScanlineCPUToScreenColorExpandFill (
433 unsigned int planemask
436 NVPtr pNv = NVPTR(pScrn);
438 CARD32 mask = ~0 << pNv->CurrentLayout.depth;
441 _fg_pixel = fg | mask;
446 _transparent = FALSE;
447 _bg_pixel = bg | mask;
450 NVSetRopSolid (pScrn, rop, planemask);
454 NVSubsequentScanlineCPUToScreenColorExpandFill (
461 NVPtr pNv = NVPTR(pScrn);
462 int bw = (w + 31) & ~31;
464 _color_expand_dwords = bw >> 5;
468 NVDmaStart(pNv, RECT_EXPAND_ONE_COLOR_CLIP, 5);
469 NVDmaNext (pNv, (y << 16) | ((x + skipleft) & 0xFFFF));
470 NVDmaNext (pNv, ((y + h) << 16) | ((x + w) & 0xFFFF));
471 NVDmaNext (pNv, _fg_pixel);
472 NVDmaNext (pNv, (h << 16) | bw);
473 NVDmaNext (pNv, (y << 16) | (x & 0xFFFF));
474 _color_expand_offset = RECT_EXPAND_ONE_COLOR_DATA(0);
476 NVDmaStart(pNv, RECT_EXPAND_TWO_COLOR_CLIP, 7);
477 NVDmaNext (pNv, (y << 16) | ((x + skipleft) & 0xFFFF));
478 NVDmaNext (pNv, ((y + h) << 16) | ((x + w) & 0xFFFF));
479 NVDmaNext (pNv, _bg_pixel);
480 NVDmaNext (pNv, _fg_pixel);
481 NVDmaNext (pNv, (h << 16) | bw);
482 NVDmaNext (pNv, (h << 16) | bw);
483 NVDmaNext (pNv, (y << 16) | (x & 0xFFFF));
484 _color_expand_offset = RECT_EXPAND_TWO_COLOR_DATA(0);
487 NVDmaStart(pNv, _color_expand_offset, _color_expand_dwords);
488 _storage_buffer[0] = (unsigned char*)&pNv->dmaBase[pNv->dmaCurrent];
492 NVSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
494 NVPtr pNv = NVPTR(pScrn);
496 pNv->dmaCurrent += _color_expand_dwords;
499 NVDmaStart(pNv, _color_expand_offset, _color_expand_dwords);
500 _storage_buffer[0] = (unsigned char*)&pNv->dmaBase[pNv->dmaCurrent];
502 /* hardware bug workaround */
503 NVDmaStart(pNv, BLIT_POINT_SRC, 1);
510 NVSetupForScanlineImageWrite(
511 ScrnInfoPtr pScrn, int rop,
512 unsigned int planemask,
517 NVPtr pNv = NVPTR(pScrn);
519 planemask |= ~0 << pNv->CurrentLayout.depth;
521 NVSetRopSolid (pScrn, rop, planemask);
524 static CARD32 _image_size;
525 static CARD32 _image_srcpoint;
526 static CARD32 _image_dstpoint;
527 static CARD32 _image_dstpitch;
530 NVSubsequentScanlineImageWriteRect(
537 NVPtr pNv = NVPTR(pScrn);
538 int Bpp = pNv->CurrentLayout.bitsPerPixel >> 3;
541 _image_size = (1 << 16) | (w - skipleft);
542 _image_srcpoint = skipleft;
543 _image_dstpoint = (y << 16) | (x + skipleft);
545 _image_dstpitch = pNv->CurrentLayout.displayWidth * Bpp;
546 image_srcpitch = ((w * Bpp) + 63) & ~63;
547 _storage_buffer[0] = pNv->FbStart + pNv->ScratchBufferStart;
551 NVDmaStart(pNv, SURFACE_PITCH, 2);
552 NVDmaNext (pNv, (_image_dstpitch << 16) | image_srcpitch);
553 NVDmaNext (pNv, pNv->ScratchBufferStart);
556 static void NVSubsequentImageWriteScanline(ScrnInfoPtr pScrn, int bufno)
558 NVPtr pNv = NVPTR(pScrn);
560 NVDmaStart(pNv, BLIT_POINT_SRC, 3);
561 NVDmaNext (pNv, _image_srcpoint);
562 NVDmaNext (pNv, _image_dstpoint);
563 NVDmaNext (pNv, _image_size);
567 _image_dstpoint += (1 << 16);
570 NVDmaStart(pNv, SURFACE_PITCH, 2);
571 NVDmaNext (pNv, _image_dstpitch | (_image_dstpitch << 16));
577 NVSetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop, unsigned planemask)
579 NVPtr pNv = NVPTR(pScrn);
581 planemask |= ~0 << pNv->CurrentLayout.depth;
583 NVSetRopSolid(pScrn, rop, planemask);
587 pNv->DMAKickoffCallback = NVDMAKickoffCallback;
591 NVSubsequentSolidHorVertLine(ScrnInfoPtr pScrn, int x, int y, int len, int dir)
593 NVPtr pNv = NVPTR(pScrn);
595 NVDmaStart(pNv, LINE_COLOR, 1);
596 NVDmaNext (pNv, _fg_pixel);
597 NVDmaStart(pNv, LINE_LINES(0), 2);
598 NVDmaNext (pNv, (y << 16) | ( x & 0xffff));
599 if(dir == DEGREES_0) {
600 NVDmaNext (pNv, (y << 16) | ((x + len) & 0xffff));
602 NVDmaNext (pNv, ((y + len) << 16) | (x & 0xffff));
607 NVSubsequentSolidTwoPointLine(
614 NVPtr pNv = NVPTR(pScrn);
615 Bool drawLast = !(flags & OMIT_LAST);
617 NVDmaStart(pNv, LINE_COLOR, 1);
618 NVDmaNext (pNv, _fg_pixel);
619 NVDmaStart(pNv, LINE_LINES(0), drawLast ? 4 : 2);
620 NVDmaNext (pNv, (y1 << 16) | (x1 & 0xffff));
621 NVDmaNext (pNv, (y2 << 16) | (x2 & 0xffff));
623 NVDmaNext (pNv, (y2 << 16) | (x2 & 0xffff));
624 NVDmaNext (pNv, ((y2 + 1) << 16) | (x2 & 0xffff));
629 NVSetClippingRectangle(ScrnInfoPtr pScrn, int x1, int y1, int x2, int y2)
631 NVPtr pNv = NVPTR(pScrn);
635 NVDmaStart(pNv, CLIP_POINT, 2);
636 NVDmaNext (pNv, (y1 << 16) | x1);
637 NVDmaNext (pNv, (h << 16) | w);
641 NVDisableClipping(ScrnInfoPtr pScrn)
643 NVPtr pNv = NVPTR(pScrn);
645 NVDmaStart(pNv, CLIP_POINT, 2);
647 NVDmaNext (pNv, 0x7FFF7FFF);
651 /* Initialize XAA acceleration info */
653 NVAccelInit(ScreenPtr pScreen)
655 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
656 NVPtr pNv = NVPTR(pScrn);
659 accel = pNv->AccelInfoRec = XAACreateInfoRec();
660 if(!accel) return FALSE;
662 accel->Flags = LINEAR_FRAMEBUFFER | PIXMAP_CACHE | OFFSCREEN_PIXMAPS;
663 accel->Sync = NVSync;
665 accel->ScreenToScreenCopyFlags = NO_TRANSPARENCY;
666 accel->SetupForScreenToScreenCopy = NVSetupForScreenToScreenCopy;
667 accel->SubsequentScreenToScreenCopy = NVSubsequentScreenToScreenCopy;
669 accel->SolidFillFlags = 0;
670 accel->SetupForSolidFill = NVSetupForSolidFill;
671 accel->SubsequentSolidFillRect = NVSubsequentSolidFillRect;
673 accel->Mono8x8PatternFillFlags = HARDWARE_PATTERN_SCREEN_ORIGIN |
674 HARDWARE_PATTERN_PROGRAMMED_BITS |
676 accel->SetupForMono8x8PatternFill = NVSetupForMono8x8PatternFill;
677 accel->SubsequentMono8x8PatternFillRect = NVSubsequentMono8x8PatternFillRect;
679 accel->ScanlineCPUToScreenColorExpandFillFlags =
680 BIT_ORDER_IN_BYTE_LSBFIRST |
681 CPU_TRANSFER_PAD_DWORD |
683 LEFT_EDGE_CLIPPING_NEGATIVE_X;
684 accel->NumScanlineColorExpandBuffers = 1;
685 accel->SetupForScanlineCPUToScreenColorExpandFill =
686 NVSetupForScanlineCPUToScreenColorExpandFill;
687 accel->SubsequentScanlineCPUToScreenColorExpandFill =
688 NVSubsequentScanlineCPUToScreenColorExpandFill;
689 accel->SubsequentColorExpandScanline =
690 NVSubsequentColorExpandScanline;
691 accel->ScanlineColorExpandBuffers = _storage_buffer;
693 accel->ScanlineImageWriteFlags = NO_GXCOPY |
696 LEFT_EDGE_CLIPPING_NEGATIVE_X;
697 accel->NumScanlineImageWriteBuffers = 1;
698 accel->SetupForScanlineImageWrite = NVSetupForScanlineImageWrite;
699 accel->SubsequentScanlineImageWriteRect = NVSubsequentScanlineImageWriteRect;
700 accel->SubsequentImageWriteScanline = NVSubsequentImageWriteScanline;
701 accel->ScanlineImageWriteBuffers = _storage_buffer;
703 accel->SolidLineFlags = 0;
704 accel->SetupForSolidLine = NVSetupForSolidLine;
705 accel->SubsequentSolidHorVertLine = NVSubsequentSolidHorVertLine;
706 accel->SubsequentSolidTwoPointLine = NVSubsequentSolidTwoPointLine;
707 accel->SetClippingRectangle = NVSetClippingRectangle;
708 accel->DisableClipping = NVDisableClipping;
709 accel->ClippingFlags = HARDWARE_CLIP_SOLID_LINE;
711 miSetZeroLineBias(pScreen, OCTANT1 | OCTANT3 | OCTANT4 | OCTANT6);
713 return (XAAInit(pScreen, accel));