2
* Copyright 2007 NVIDIA, Corporation
3
* Copyright 2008 Ben Skeggs
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice shall be included in
13
* all copies or substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
#include "nv_include.h"
26
#define NV50EXA_LOCALS(p) \
27
ScrnInfoPtr pScrn = xf86Screens[(p)->drawable.pScreen->myNum]; \
28
NVPtr pNv = NVPTR(pScrn); \
32
NV50EXA2DSurfaceFormat(PixmapPtr pPix, uint32_t *fmt)
36
switch (pPix->drawable.depth) {
37
case 8 : *fmt = NV50_2D_SRC_FORMAT_8BPP; break;
38
case 15: *fmt = NV50_2D_SRC_FORMAT_15BPP; break;
39
case 16: *fmt = NV50_2D_SRC_FORMAT_16BPP; break;
40
case 24: *fmt = NV50_2D_SRC_FORMAT_24BPP; break;
41
case 32: *fmt = NV50_2D_SRC_FORMAT_32BPP; break;
43
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
44
"Unknown surface format for bpp=%d\n",
45
pPix->drawable.depth);
53
NV50EXAAcquireSurface2D(PixmapPtr pPix, int is_src)
56
int mthd = is_src ? NV50_2D_SRC_FORMAT : NV50_2D_DST_FORMAT;
57
uint32_t fmt, bo_flags;
59
if (!NV50EXA2DSurfaceFormat(pPix, &fmt))
62
bo_flags = NOUVEAU_BO_VRAM;
63
bo_flags |= is_src ? NOUVEAU_BO_RD : NOUVEAU_BO_WR;
65
BEGIN_RING(Nv2D, mthd, 2);
69
BEGIN_RING(Nv2D, mthd + 0x14, 5);
70
OUT_RING ((uint32_t)exaGetPixmapPitch(pPix));
71
OUT_RING (pPix->drawable.width);
72
OUT_RING (pPix->drawable.height);
73
OUT_PIXMAPh(pPix, 0, bo_flags);
74
OUT_PIXMAPl(pPix, 0, bo_flags);
77
BEGIN_RING(Nv2D, NV50_2D_CLIP_X, 4);
80
OUT_RING (pPix->drawable.width);
81
OUT_RING (pPix->drawable.height);
88
NV50EXAAcquireSurfaces(PixmapPtr pdPix)
90
NV50EXA_LOCALS(pdPix);
96
NV50EXAReleaseSurfaces(PixmapPtr pdPix)
98
NV50EXA_LOCALS(pdPix);
100
BEGIN_RING(Nv2D, NV50_2D_NOP, 1);
106
NV50EXASetPattern(PixmapPtr pdPix, int col0, int col1, int pat0, int pat1)
108
NV50EXA_LOCALS(pdPix);
110
BEGIN_RING(Nv2D, NV50_2D_PATTERN_COLOR(0), 4);
117
extern const int NVCopyROP[16];
119
NV50EXASetROP(PixmapPtr pdPix, int alu, Pixel planemask)
121
NV50EXA_LOCALS(pdPix);
122
int rop = NVCopyROP[alu];
124
BEGIN_RING(Nv2D, NV50_2D_OPERATION, 1);
125
if(alu == GXcopy && planemask == ~0) {
126
OUT_RING (NV50_2D_OPERATION_SRCCOPY);
129
OUT_RING (NV50_2D_OPERATION_ROP_AND);
132
BEGIN_RING(Nv2D, NV50_2D_PATTERN_FORMAT, 2);
133
switch (pdPix->drawable.depth) {
134
case 8: OUT_RING (3); break;
135
case 15: OUT_RING (1); break;
136
case 16: OUT_RING (0); break;
145
if(planemask != ~0) {
146
NV50EXASetPattern(pdPix, 0, planemask, ~0, ~0);
147
rop = (rop & 0xf0) | 0x0a;
149
if((pNv->currentRop & 0x0f) == 0x0a) {
150
NV50EXASetPattern(pdPix, ~0, ~0, ~0, ~0);
153
if (pNv->currentRop != rop) {
154
BEGIN_RING(Nv2D, NV50_2D_ROP, 1);
156
pNv->currentRop = rop;
161
NV50EXAPrepareSolid(PixmapPtr pdPix, int alu, Pixel planemask, Pixel fg)
163
NV50EXA_LOCALS(pdPix);
166
if(pdPix->drawable.depth > 24)
168
if (!NV50EXA2DSurfaceFormat(pdPix, &fmt))
171
if (!NV50EXAAcquireSurface2D(pdPix, 0))
173
if (!NV50EXAAcquireSurfaces(pdPix))
175
NV50EXASetROP(pdPix, alu, planemask);
177
BEGIN_RING(Nv2D, 0x580, 3);
186
NV50EXASolid(PixmapPtr pdPix, int x1, int y1, int x2, int y2)
188
NV50EXA_LOCALS(pdPix);
190
BEGIN_RING(Nv2D, NV50_2D_RECT_X1, 4);
196
if((x2 - x1) * (y2 - y1) >= 512)
201
NV50EXADoneSolid(PixmapPtr pdPix)
203
NV50EXA_LOCALS(pdPix);
205
NV50EXAReleaseSurfaces(pdPix);
209
NV50EXAPrepareCopy(PixmapPtr psPix, PixmapPtr pdPix, int dx, int dy,
210
int alu, Pixel planemask)
212
NV50EXA_LOCALS(pdPix);
214
if (!NV50EXAAcquireSurface2D(psPix, 1))
216
if (!NV50EXAAcquireSurface2D(pdPix, 0))
218
if (!NV50EXAAcquireSurfaces(pdPix))
220
NV50EXASetROP(pdPix, alu, planemask);
226
NV50EXACopy(PixmapPtr pdPix, int srcX , int srcY,
228
int width, int height)
230
NV50EXA_LOCALS(pdPix);
232
BEGIN_RING(Nv2D, 0x0110, 1);
234
BEGIN_RING(Nv2D, NV50_2D_BLIT_DST_X, 12);
248
if(width * height >= 512)
253
NV50EXADoneCopy(PixmapPtr pdPix)
255
NV50EXA_LOCALS(pdPix);
257
NV50EXAReleaseSurfaces(pdPix);
261
NV50EXAUploadSIFC(ScrnInfoPtr pScrn, const char *src, int src_pitch,
262
PixmapPtr pdPix, int x, int y, int w, int h, int cpp)
264
NVPtr pNv = NVPTR(pScrn);
265
int line_dwords = (w * cpp + 3) / 4;
268
if (!NV50EXA2DSurfaceFormat(pdPix, &sifc_fmt))
270
if (!NV50EXAAcquireSurface2D(pdPix, 0))
273
BEGIN_RING(Nv2D, NV50_2D_OPERATION, 1);
274
OUT_RING (NV50_2D_OPERATION_SRCCOPY);
275
BEGIN_RING(Nv2D, NV50_2D_SIFC_UNK0800, 2);
278
BEGIN_RING(Nv2D, NV50_2D_SIFC_WIDTH, 10);
279
OUT_RING ((line_dwords * 4) / cpp);
291
int count = line_dwords;
295
int size = count > 1792 ? 1792 : count;
297
BEGIN_RING(Nv2D, NV50_2D_SIFC_DATA | 0x40000000, size);