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(NVPtr pNv)
111 NVDmaStart(pNv, 5, 0x0000012C, 1);
113 NVDmaStart(pNv, 5, 0x00000134, 1);
114 NVDmaNext (pNv, pNv->CRTCnumber);
115 NVDmaStart(pNv, 5, 0x00000100, 1);
117 NVDmaStart(pNv, 5, 0x00000130, 1);
122 currentRop = 0-15 solid fill
123 16-31 8x8 pattern fill
124 32-47 solid fill with planemask
136 NVPtr pNv = NVPTR(pScrn);
138 NVDmaStart(pNv, NvSubImagePattern, PATTERN_COLOR_0, 4);
139 NVDmaNext (pNv, clr0);
140 NVDmaNext (pNv, clr1);
141 NVDmaNext (pNv, pat0);
142 NVDmaNext (pNv, pat1);
146 NVSetRopSolid(ScrnInfoPtr pScrn, CARD32 rop, CARD32 planemask)
148 NVPtr pNv = NVPTR(pScrn);
150 if(planemask != ~0) {
151 NVSetPattern(pScrn, 0, planemask, ~0, ~0);
152 if(pNv->currentRop != (rop + 32)) {
153 NVDmaStart(pNv, NvSubRop, ROP_SET, 1);
154 NVDmaNext (pNv, NVCopyROP_PM[rop]);
155 pNv->currentRop = rop + 32;
158 if (pNv->currentRop != rop) {
159 if(pNv->currentRop >= 16)
160 NVSetPattern(pScrn, ~0, ~0, ~0, ~0);
161 NVDmaStart(pNv, NvSubRop, ROP_SET, 1);
162 NVDmaNext (pNv, NVCopyROP[rop]);
163 pNv->currentRop = rop;
168 NVSetupForScreenToScreenCopy(
173 int transparency_color
176 NVPtr pNv = NVPTR(pScrn);
178 planemask |= ~0 << pNv->CurrentLayout.depth;
180 NVSetRopSolid(pScrn, rop, planemask);
182 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
186 NVSubsequentScreenToScreenCopy(
193 NVPtr pNv = NVPTR(pScrn);
195 NVDmaStart(pNv, NvSubImageBlit, BLIT_POINT_SRC, 3);
196 NVDmaNext (pNv, (y1 << 16) | x1);
197 NVDmaNext (pNv, (y2 << 16) | x2);
198 NVDmaNext (pNv, (h << 16) | w);
212 NVPtr pNv = NVPTR(pScrn);
214 planemask |= ~0 << pNv->CurrentLayout.depth;
216 NVSetRopSolid(pScrn, rop, planemask);
217 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_COLOR, 1);
218 NVDmaNext (pNv, color);
220 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
224 NVSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
226 NVPtr pNv = NVPTR(pScrn);
228 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_RECTS(0), 2);
229 NVDmaNext (pNv, (x << 16) | y);
230 NVDmaNext (pNv, (w << 16) | h);
237 NVSetupForMono8x8PatternFill (
239 int patternx, int patterny,
245 NVPtr pNv = NVPTR(pScrn);
247 planemask = ~0 << pNv->CurrentLayout.depth;
251 else bg |= planemask;
253 if (pNv->currentRop != (rop + 16)) {
254 NVDmaStart(pNv, NvSubRop, ROP_SET, 1);
255 NVDmaNext (pNv, NVPatternROP[rop]);
256 pNv->currentRop = rop + 16;
259 NVSetPattern(pScrn, bg, fg, patternx, patterny);
260 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_COLOR, 1);
263 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
267 NVSubsequentMono8x8PatternFillRect(
269 int patternx, int patterny,
274 NVPtr pNv = NVPTR(pScrn);
276 NVDmaStart(pNv, NvSubRectangle, RECT_SOLID_RECTS(0), 2);
277 NVDmaNext (pNv, (x << 16) | y);
278 NVDmaNext (pNv, (w << 16) | h);
284 static CARD32 _bg_pixel;
285 static CARD32 _fg_pixel;
286 static Bool _transparent;
287 static CARD32 _color_expand_dwords;
288 static CARD32 _color_expand_offset;
289 static int _remaining;
290 static unsigned char *_storage_buffer[1];
293 NVSetupForScanlineCPUToScreenColorExpandFill (
297 unsigned int planemask
300 NVPtr pNv = NVPTR(pScrn);
302 CARD32 mask = ~0 << pNv->CurrentLayout.depth;
305 _fg_pixel = fg | mask;
310 _transparent = FALSE;
311 _bg_pixel = bg | mask;
314 NVSetRopSolid (pScrn, rop, planemask);
318 NVSubsequentScanlineCPUToScreenColorExpandFill (
325 NVPtr pNv = NVPTR(pScrn);
326 int bw = (w + 31) & ~31;
328 _color_expand_dwords = bw >> 5;
332 NVDmaStart(pNv, NvSubRectangle, RECT_EXPAND_ONE_COLOR_CLIP, 5);
333 NVDmaNext (pNv, (y << 16) | ((x + skipleft) & 0xFFFF));
334 NVDmaNext (pNv, ((y + h) << 16) | ((x + w) & 0xFFFF));
335 NVDmaNext (pNv, _fg_pixel);
336 NVDmaNext (pNv, (h << 16) | bw);
337 NVDmaNext (pNv, (y << 16) | (x & 0xFFFF));
338 _color_expand_offset = RECT_EXPAND_ONE_COLOR_DATA(0);
340 NVDmaStart(pNv, NvSubRectangle, RECT_EXPAND_TWO_COLOR_CLIP, 7);
341 NVDmaNext (pNv, (y << 16) | ((x + skipleft) & 0xFFFF));
342 NVDmaNext (pNv, ((y + h) << 16) | ((x + w) & 0xFFFF));
343 NVDmaNext (pNv, _bg_pixel);
344 NVDmaNext (pNv, _fg_pixel);
345 NVDmaNext (pNv, (h << 16) | bw);
346 NVDmaNext (pNv, (h << 16) | bw);
347 NVDmaNext (pNv, (y << 16) | (x & 0xFFFF));
348 _color_expand_offset = RECT_EXPAND_TWO_COLOR_DATA(0);
351 NVDmaStart(pNv, NvSubRectangle, _color_expand_offset, _color_expand_dwords);
352 _storage_buffer[0] = (unsigned char*)&pNv->dmaBase[pNv->dmaCurrent];
356 NVSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
358 NVPtr pNv = NVPTR(pScrn);
360 pNv->dmaCurrent += _color_expand_dwords;
363 NVDmaStart(pNv, NvSubRectangle, _color_expand_offset, _color_expand_dwords);
364 _storage_buffer[0] = (unsigned char*)&pNv->dmaBase[pNv->dmaCurrent];
366 /* hardware bug workaround */
367 NVDmaStart(pNv, NvSubImageBlit, BLIT_POINT_SRC, 1);
374 NVSetupForScanlineImageWrite(
375 ScrnInfoPtr pScrn, int rop,
376 unsigned int planemask,
381 NVPtr pNv = NVPTR(pScrn);
383 planemask |= ~0 << pNv->CurrentLayout.depth;
385 NVSetRopSolid (pScrn, rop, planemask);
388 static CARD32 _image_size;
389 static CARD32 _image_srcpoint;
390 static CARD32 _image_dstpoint;
391 static CARD32 _image_dstpitch;
394 NVSubsequentScanlineImageWriteRect(
401 NVPtr pNv = NVPTR(pScrn);
402 int Bpp = pNv->CurrentLayout.bitsPerPixel >> 3;
405 _image_size = (1 << 16) | (w - skipleft);
406 _image_srcpoint = skipleft;
407 _image_dstpoint = (y << 16) | (x + skipleft);
409 _image_dstpitch = pNv->CurrentLayout.displayWidth * Bpp;
410 image_srcpitch = ((w * Bpp) + 63) & ~63;
411 _storage_buffer[0] = pNv->ScratchBuffer->map;
415 NVDmaStart(pNv, NvSubContextSurfaces, SURFACE_PITCH, 2);
416 NVDmaNext (pNv, (_image_dstpitch << 16) | image_srcpitch);
417 NVDmaNext (pNv, pNv->ScratchBuffer->offset);
420 static void NVSubsequentImageWriteScanline(ScrnInfoPtr pScrn, int bufno)
422 NVPtr pNv = NVPTR(pScrn);
424 NVDmaStart(pNv, NvSubImageBlit, BLIT_POINT_SRC, 3);
425 NVDmaNext (pNv, _image_srcpoint);
426 NVDmaNext (pNv, _image_dstpoint);
427 NVDmaNext (pNv, _image_size);
431 _image_dstpoint += (1 << 16);
434 NVDmaStart(pNv, NvSubContextSurfaces, SURFACE_PITCH, 2);
435 NVDmaNext (pNv, _image_dstpitch | (_image_dstpitch << 16));
436 NVDmaNext (pNv, pNv->FB->offset);
441 NVSetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop, unsigned planemask)
443 NVPtr pNv = NVPTR(pScrn);
445 planemask |= ~0 << pNv->CurrentLayout.depth;
447 NVSetRopSolid(pScrn, rop, planemask);
451 pNv->DMAKickoffCallback = NVDmaKickoffCallback;
455 NVSubsequentSolidHorVertLine(ScrnInfoPtr pScrn, int x, int y, int len, int dir)
457 NVPtr pNv = NVPTR(pScrn);
459 NVDmaStart(pNv, NvSubSolidLine, LINE_COLOR, 1);
460 NVDmaNext (pNv, _fg_pixel);
461 NVDmaStart(pNv, NvSubSolidLine, LINE_LINES(0), 2);
462 NVDmaNext (pNv, (y << 16) | ( x & 0xffff));
463 if(dir == DEGREES_0) {
464 NVDmaNext (pNv, (y << 16) | ((x + len) & 0xffff));
466 NVDmaNext (pNv, ((y + len) << 16) | (x & 0xffff));
471 NVSubsequentSolidTwoPointLine(
478 NVPtr pNv = NVPTR(pScrn);
479 Bool drawLast = !(flags & OMIT_LAST);
481 NVDmaStart(pNv, NvSubSolidLine, LINE_COLOR, 1);
482 NVDmaNext (pNv, _fg_pixel);
483 NVDmaStart(pNv, NvSubSolidLine, LINE_LINES(0), drawLast ? 4 : 2);
484 NVDmaNext (pNv, (y1 << 16) | (x1 & 0xffff));
485 NVDmaNext (pNv, (y2 << 16) | (x2 & 0xffff));
487 NVDmaNext (pNv, (y2 << 16) | (x2 & 0xffff));
488 NVDmaNext (pNv, ((y2 + 1) << 16) | (x2 & 0xffff));
493 NVSetClippingRectangle(ScrnInfoPtr pScrn, int x1, int y1, int x2, int y2)
495 NVPtr pNv = NVPTR(pScrn);
499 NVDmaStart(pNv, NvSubClipRectangle, CLIP_POINT, 2);
500 NVDmaNext (pNv, (y1 << 16) | x1);
501 NVDmaNext (pNv, (h << 16) | w);
505 NVDisableClipping(ScrnInfoPtr pScrn)
507 NVPtr pNv = NVPTR(pScrn);
509 NVDmaStart(pNv, NvSubClipRectangle, CLIP_POINT, 2);
511 NVDmaNext (pNv, 0x7FFF7FFF);
515 /* Initialize XAA acceleration info */
517 NVXaaInit(ScreenPtr pScreen)
519 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
520 NVPtr pNv = NVPTR(pScrn);
523 accel = pNv->AccelInfoRec = XAACreateInfoRec();
524 if(!accel) return FALSE;
526 accel->Flags = LINEAR_FRAMEBUFFER | PIXMAP_CACHE | OFFSCREEN_PIXMAPS;
527 accel->Sync = NVSync;
529 accel->ScreenToScreenCopyFlags = NO_TRANSPARENCY;
530 accel->SetupForScreenToScreenCopy = NVSetupForScreenToScreenCopy;
531 accel->SubsequentScreenToScreenCopy = NVSubsequentScreenToScreenCopy;
533 accel->SolidFillFlags = 0;
534 accel->SetupForSolidFill = NVSetupForSolidFill;
535 accel->SubsequentSolidFillRect = NVSubsequentSolidFillRect;
537 accel->Mono8x8PatternFillFlags = HARDWARE_PATTERN_SCREEN_ORIGIN |
538 HARDWARE_PATTERN_PROGRAMMED_BITS |
540 accel->SetupForMono8x8PatternFill = NVSetupForMono8x8PatternFill;
541 accel->SubsequentMono8x8PatternFillRect = NVSubsequentMono8x8PatternFillRect;
543 accel->ScanlineCPUToScreenColorExpandFillFlags =
544 BIT_ORDER_IN_BYTE_LSBFIRST |
545 CPU_TRANSFER_PAD_DWORD |
547 LEFT_EDGE_CLIPPING_NEGATIVE_X;
548 accel->NumScanlineColorExpandBuffers = 1;
549 accel->SetupForScanlineCPUToScreenColorExpandFill =
550 NVSetupForScanlineCPUToScreenColorExpandFill;
551 accel->SubsequentScanlineCPUToScreenColorExpandFill =
552 NVSubsequentScanlineCPUToScreenColorExpandFill;
553 accel->SubsequentColorExpandScanline =
554 NVSubsequentColorExpandScanline;
555 accel->ScanlineColorExpandBuffers = _storage_buffer;
557 accel->ScanlineImageWriteFlags = NO_GXCOPY |
560 LEFT_EDGE_CLIPPING_NEGATIVE_X;
561 accel->NumScanlineImageWriteBuffers = 1;
562 accel->SetupForScanlineImageWrite = NVSetupForScanlineImageWrite;
563 accel->SubsequentScanlineImageWriteRect = NVSubsequentScanlineImageWriteRect;
564 accel->SubsequentImageWriteScanline = NVSubsequentImageWriteScanline;
565 accel->ScanlineImageWriteBuffers = _storage_buffer;
567 accel->SolidLineFlags = 0;
568 accel->SetupForSolidLine = NVSetupForSolidLine;
569 accel->SubsequentSolidHorVertLine = NVSubsequentSolidHorVertLine;
570 accel->SubsequentSolidTwoPointLine = NVSubsequentSolidTwoPointLine;
571 accel->SetClippingRectangle = NVSetClippingRectangle;
572 accel->DisableClipping = NVDisableClipping;
573 accel->ClippingFlags = HARDWARE_CLIP_SOLID_LINE;
575 miSetZeroLineBias(pScreen, OCTANT1 | OCTANT3 | OCTANT4 | OCTANT6);
577 return (XAAInit(pScreen, accel));