summaryrefslogtreecommitdiff
path: root/src/nv04_xv_blit.c
blob: 990817c0bdc13c63e5aed44505f64125e9d759ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * Copyright 2007 Arthur Huillet
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "xf86xv.h"
#include <X11/extensions/Xv.h>
#include "exa.h"
#include "damage.h"
#include "dixstruct.h"
#include "fourcc.h"

#include "nv_include.h"
#include "nv_dma.h"

#define FOURCC_RGB 0x0000003

extern Atom xvSetDefaults, xvSyncToVBlank;

/**
 * NVPutBlitImage
 * 
 * @param pScrn screen
 * @param src_offset offset of image data in VRAM
 * @param id pixel format
 * @param src_pitch source pitch
 * @param dstBox 
 * @param x1
 * @param y1
 * @param x2
 * @param y2
 * @param width
 * @param height
 * @param src_w
 * @param src_h
 * @param drw_w
 * @param drw_h
 * @param clipBoxes
 * @param pDraw
 */
Bool
NVPutBlitImage(ScrnInfoPtr pScrn, struct nouveau_bo *src, int src_offset,
	       int id, int src_pitch, BoxPtr dstBox,
               int x1, int y1, int x2, int y2,
               short width, short height,
               short src_w, short src_h,
               short drw_w, short drw_h,
               RegionPtr clipBoxes, PixmapPtr ppix)
{
        NVPtr          pNv   = NVPTR(pScrn);
        NVPortPrivPtr  pPriv = GET_BLIT_PRIVATE(pNv);
        BoxPtr         pbox;
        int            nbox;
        CARD32         dsdx, dtdy;
        CARD32         dst_size, dst_point;
        CARD32         src_point, src_format;
	struct nouveau_channel *chan = pNv->chan;
	struct nouveau_grobj *surf2d = pNv->NvContextSurfaces;
	struct nouveau_grobj *rect = pNv->NvRectangle;
	struct nouveau_grobj *sifm = pNv->NvScaledImage;
	struct nouveau_bo *bo = nouveau_pixmap_bo(ppix);
	unsigned delta = nouveau_pixmap_offset(ppix);
        unsigned int crtcs;
        int dst_format;

        if (!NVAccelGetCtxSurf2DFormatFromPixmap(ppix, &dst_format))
		return BadImplementation;

	if (MARK_RING(chan, 64, 4))
		return BadImplementation;

        BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_FORMAT, 4);
        OUT_RING  (chan, dst_format);
        OUT_RING  (chan, (exaGetPixmapPitch(ppix) << 16) | exaGetPixmapPitch(ppix));
        if (OUT_RELOCl(chan, bo, delta, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR) ||
	    OUT_RELOCl(chan, bo, delta, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR)) {
		MARK_UNDO(chan);
		return BadImplementation;
	}

        pbox = REGION_RECTS(clipBoxes);
        nbox = REGION_NUM_RECTS(clipBoxes);

        dsdx = (src_w << 20) / drw_w;
        dtdy = (src_h << 20) / drw_h;

        dst_size  = ((dstBox->y2 - dstBox->y1) << 16) |
                     (dstBox->x2 - dstBox->x1);
        dst_point = (dstBox->y1 << 16) | dstBox->x1;

        src_pitch |= (NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER |
                      NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_BILINEAR);
        src_point = ((y1 << 4) & 0xffff0000) | (x1 >> 12);

        switch(id) {
        case FOURCC_RGB:
                src_format =
                        NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X8R8G8B8;
                break;
        case FOURCC_UYVY:
                src_format =
                        NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_YB8V8YA8U8;
                break;
        default:
                src_format =
                        NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_V8YB8U8YA8;
                break;
        }

        if(pPriv->SyncToVBlank) {
                crtcs = nv_window_belongs_to_crtc(pScrn, dstBox->x1, dstBox->y1,
                        dstBox->x2, dstBox->y2);

                FIRE_RING (chan);
                if (crtcs & 0x1)
                        NVWaitVSync(pScrn, 0);
                else if (crtcs & 0x2)
                        NVWaitVSync(pScrn, 1);
        }

        if(pNv->BlendingPossible) {
                BEGIN_RING(chan, sifm,
				 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT, 2);
                OUT_RING  (chan, src_format);
                OUT_RING  (chan, NV04_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY);
        } else {
                BEGIN_RING(chan, sifm,
				 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT, 1);
                OUT_RING  (chan, src_format);
        }


	BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE, 1);
	OUT_RELOCo(chan, src, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART |
			      NOUVEAU_BO_RD);
        while (nbox--) {
                BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR1_A, 1);
                OUT_RING  (chan, 0);

                BEGIN_RING(chan, sifm,
				 NV04_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT, 6);
                OUT_RING  (chan, (pbox->y1 << 16) | pbox->x1);
                OUT_RING  (chan, ((pbox->y2 - pbox->y1) << 16) |
                                 (pbox->x2 - pbox->x1));
                OUT_RING  (chan, dst_point);
                OUT_RING  (chan, dst_size);
                OUT_RING  (chan, dsdx);
                OUT_RING  (chan, dtdy);

                BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_SIZE, 4);
                OUT_RING  (chan, (height << 16) | width);
                OUT_RING  (chan, src_pitch);
		if (OUT_RELOCl(chan, src, src_offset, NOUVEAU_BO_VRAM |
			       NOUVEAU_BO_GART | NOUVEAU_BO_RD)) {
			MARK_UNDO(chan);
			return BadImplementation;
		}
                OUT_RING  (chan, src_point);
                pbox++;
        }

        FIRE_RING (chan);

        exaMarkSync(pScrn->pScreen);

        pPriv->videoStatus = FREE_TIMER;
        pPriv->videoTime = currentTime.milliseconds + FREE_DELAY;
        extern void NVVideoTimerCallback(ScrnInfoPtr, Time);
	pNv->VideoTimerCallback = NVVideoTimerCallback;
	return Success;
}


/**
 * NVSetBlitPortAttribute
 * sets the attribute "attribute" of port "data" to value "value"
 * supported attributes:
 * - xvSyncToVBlank (values: 0,1)
 * - xvSetDefaults (values: NA; SyncToVBlank will be set, if hardware supports it)
 * 
 * @param pScrenInfo
 * @param attribute attribute to set
 * @param value value to which attribute is to be set
 * @param data port from which the attribute is to be set
 * 
 * @return Success, if setting is successful
 * BadValue/BadMatch, if value/attribute are invalid
 */
int
NVSetBlitPortAttribute(ScrnInfoPtr pScrn, Atom attribute,
                       INT32 value, pointer data)
{
        NVPortPrivPtr pPriv = (NVPortPrivPtr)data;
        NVPtr           pNv = NVPTR(pScrn);

        if ((attribute == xvSyncToVBlank) && pNv->WaitVSyncPossible) {
                if ((value < 0) || (value > 1))
                        return BadValue;
                pPriv->SyncToVBlank = value;
        } else
        if (attribute == xvSetDefaults) {
                pPriv->SyncToVBlank = pNv->WaitVSyncPossible;
        } else
                return BadMatch;

        return Success;
}

/**
 * NVGetBlitPortAttribute
 * reads the value of attribute "attribute" from port "data" into INT32 "*value"
 * currently only one attribute supported: xvSyncToVBlank
 * 
 * @param pScrn unused
 * @param attribute attribute to be read
 * @param value value of attribute will be stored here
 * @param data port from which attribute will be read
 * @return Success, if queried attribute exists
 */
int
NVGetBlitPortAttribute(ScrnInfoPtr pScrn, Atom attribute,
                       INT32 *value, pointer data)
{
        NVPortPrivPtr pPriv = (NVPortPrivPtr)data;

        if(attribute == xvSyncToVBlank)
                *value = (pPriv->SyncToVBlank) ? 1 : 0;
        else
                return BadMatch;

        return Success;
}

/**
 * NVStopBlitVideo
 */
void
NVStopBlitVideo(ScrnInfoPtr pScrn, pointer data, Bool Exit)
{
}