1 #include "nv_include.h"
3 #define NV50_2D_NOP 0x00000100
4 #define NV50_2D_UNK110 0x00000110
5 #define NV50_2D_DST_FORMAT 0x00000200
6 #define NV50_2D_SRC_FORMAT 0x00000230
7 #define NV50_2D_SRC_FORMAT_8BPP 0x000000f3
8 #define NV50_2D_SRC_FORMAT_15BPP 0x000000f8
9 #define NV50_2D_SRC_FORMAT_16BPP 0x000000e8
10 #define NV50_2D_SRC_FORMAT_24BPP 0x000000e6
11 #define NV50_2D_SRC_FORMAT_32BPP 0x000000cf
12 #define NV50_2D_CLIP_X 0x00000280
13 #define NV50_2D_SET_OPERATION 0x000002ac
14 #define NV50_2D_SET_OPERATION_ROP_AND 0x00000001
15 #define NV50_2D_SET_OPERATION_SRCCOPY 0x00000003
16 #define NV50_2D_RASTER_OP 0x000002a0
17 #define NV50_2D_PATTERN_FORMAT 0x000002e8
18 #define NV50_2D_PATTERN_COLOR_0 0x000002f0
19 #define NV50_2D_RECT_UNK580 0x00000580
20 #define NV50_2D_RECT_FORMAT 0x00000584
21 #define NV50_2D_RECT_X1 0x00000600
22 #define NV50_2D_BLIT_DST_X 0x000008b0
24 #define NV50EXA_LOCALS(p) \
25 ScrnInfoPtr pScrn = xf86Screens[(p)->drawable.pScreen->myNum]; \
26 NVPtr pNv = NVPTR(pScrn); \
30 NV50EXA2DSurfaceFormat(PixmapPtr pPix, uint32_t *fmt)
34 switch (pPix->drawable.depth) {
35 case 8 : *fmt = NV50_2D_SRC_FORMAT_8BPP; break;
36 case 15: *fmt = NV50_2D_SRC_FORMAT_15BPP; break;
37 case 16: *fmt = NV50_2D_SRC_FORMAT_16BPP; break;
38 case 24: *fmt = NV50_2D_SRC_FORMAT_24BPP; break;
39 case 32: *fmt = NV50_2D_SRC_FORMAT_32BPP; break;
41 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
42 "Unknown surface format for bpp=%d\n",
43 pPix->drawable.depth);
51 NV50EXAAcquireSurface2D(PixmapPtr pPix, int is_src)
54 int mthd = is_src ? NV50_2D_SRC_FORMAT : NV50_2D_DST_FORMAT;
57 if (!NV50EXA2DSurfaceFormat(pPix, &fmt))
60 NVDmaStart(pNv, Nv2D, mthd, 2);
64 NVDmaStart(pNv, Nv2D, mthd + 0x14, 5);
65 NVDmaNext (pNv, (uint32_t)exaGetPixmapPitch(pPix));
66 NVDmaNext (pNv, pPix->drawable.width);
67 NVDmaNext (pNv, pPix->drawable.height);
69 NVDmaNext (pNv, NVAccelGetPixmapOffset(pPix));
72 NVDmaStart(pNv, Nv2D, NV50_2D_CLIP_X, 4);
75 NVDmaNext (pNv, pPix->drawable.width);
76 NVDmaNext (pNv, pPix->drawable.height);
83 NV50EXAAcquireSurfaces(PixmapPtr pdPix)
85 NV50EXA_LOCALS(pdPix);
91 NV50EXAReleaseSurfaces(PixmapPtr pdPix)
93 NV50EXA_LOCALS(pdPix);
95 NVDmaStart(pNv, Nv2D, NV50_2D_NOP, 1);
101 NV50EXASetPattern(PixmapPtr pdPix, int col0, int col1, int pat0, int pat1)
103 NV50EXA_LOCALS(pdPix);
105 NVDmaStart(pNv, Nv2D, NV50_2D_PATTERN_COLOR_0, 4);
106 NVDmaNext (pNv, col0);
107 NVDmaNext (pNv, col1);
108 NVDmaNext (pNv, pat0);
109 NVDmaNext (pNv, pat1);
112 extern const int NVCopyROP[16];
114 NV50EXASetROP(PixmapPtr pdPix, int alu, Pixel planemask)
116 NV50EXA_LOCALS(pdPix);
117 int rop = NVCopyROP[alu];
119 NVDmaStart(pNv, Nv2D, NV50_2D_SET_OPERATION, 1);
120 if(alu == GXcopy && planemask == ~0) {
121 NVDmaNext (pNv, NV50_2D_SET_OPERATION_SRCCOPY);
124 NVDmaNext (pNv, NV50_2D_SET_OPERATION_ROP_AND);
127 NVDmaStart(pNv, Nv2D, NV50_2D_PATTERN_FORMAT, 1);
128 switch (pdPix->drawable.depth) {
129 case 8: NVDmaNext(pNv, 3); break;
130 case 15: NVDmaNext(pNv, 1); break;
131 case 16: NVDmaNext(pNv, 0); break;
139 if(planemask != ~0) {
140 NV50EXASetPattern(pdPix, 0, planemask, ~0, ~0);
141 rop = (rop & 0xf0) | 0x0a;
143 if((pNv->currentRop & 0x0f) == 0x0a) {
144 NV50EXASetPattern(pdPix, ~0, ~0, ~0, ~0);
147 if (pNv->currentRop != rop) {
148 NVDmaStart(pNv, Nv2D, NV50_2D_RASTER_OP, 1);
149 NVDmaNext (pNv, rop);
150 pNv->currentRop = rop;
155 NV50EXAPrepareSolid(PixmapPtr pdPix, int alu, Pixel planemask, Pixel fg)
157 NV50EXA_LOCALS(pdPix);
160 if(pdPix->drawable.depth > 24)
162 if (!NV50EXA2DSurfaceFormat(pdPix, &fmt))
165 if (!NV50EXAAcquireSurface2D(pdPix, 0))
167 if (!NV50EXAAcquireSurfaces(pdPix))
169 NV50EXASetROP(pdPix, alu, planemask);
171 NVDmaStart(pNv, Nv2D, NV50_2D_RECT_UNK580, 3);
173 NVDmaNext (pNv, fmt);
180 NV50EXASolid(PixmapPtr pdPix, int x1, int y1, int x2, int y2)
182 NV50EXA_LOCALS(pdPix);
184 NVDmaStart(pNv, Nv2D, NV50_2D_RECT_X1, 4);
190 if((x2 - x1) * (y2 - y1) >= 512)
195 NV50EXADoneSolid(PixmapPtr pdPix)
197 NV50EXA_LOCALS(pdPix);
199 NV50EXAReleaseSurfaces(pdPix);
203 NV50EXAPrepareCopy(PixmapPtr psPix, PixmapPtr pdPix, int dx, int dy,
204 int alu, Pixel planemask)
206 NV50EXA_LOCALS(pdPix);
208 if (!NV50EXAAcquireSurface2D(psPix, 1))
210 if (!NV50EXAAcquireSurface2D(pdPix, 0))
212 if (!NV50EXAAcquireSurfaces(pdPix))
214 NV50EXASetROP(pdPix, alu, planemask);
220 NV50EXACopy(PixmapPtr pdPix, int srcX , int srcY,
222 int width, int height)
224 NV50EXA_LOCALS(pdPix);
226 NVDmaStart(pNv, Nv2D, NV50_2D_UNK110, 1);
228 NVDmaStart(pNv, Nv2D, NV50_2D_BLIT_DST_X, 12);
229 NVDmaNext (pNv, dstX);
230 NVDmaNext (pNv, dstY);
231 NVDmaNext (pNv, width);
232 NVDmaNext (pNv, height);
238 NVDmaNext (pNv, srcX);
240 NVDmaNext (pNv, srcY);
242 if(width * height >= 512)
247 NV50EXADoneCopy(PixmapPtr pdPix)
249 NV50EXA_LOCALS(pdPix);
251 NV50EXAReleaseSurfaces(pdPix);