2 * Copyright 2007 Arthur Huillet
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #include <X11/extensions/Xv.h>
31 #include "dixstruct.h"
34 #include "nv_include.h"
37 #define FOURCC_RGB 0x0000003
39 extern Atom xvSetDefaults, xvSyncToVBlank;
45 * @param src_offset offset of image data in VRAM
46 * @param id pixel format
47 * @param src_pitch source pitch
63 NVPutBlitImage(ScrnInfoPtr pScrn, struct nouveau_bo *src, int src_offset,
64 int id, int src_pitch, BoxPtr dstBox,
65 int x1, int y1, int x2, int y2,
66 short width, short height,
67 short src_w, short src_h,
68 short drw_w, short drw_h,
69 RegionPtr clipBoxes, PixmapPtr ppix)
71 NVPtr pNv = NVPTR(pScrn);
72 NVPortPrivPtr pPriv = GET_BLIT_PRIVATE(pNv);
76 CARD32 dst_size, dst_point;
77 CARD32 src_point, src_format;
78 struct nouveau_channel *chan = pNv->chan;
79 struct nouveau_grobj *surf2d = pNv->NvContextSurfaces;
80 struct nouveau_grobj *rect = pNv->NvRectangle;
81 struct nouveau_grobj *sifm = pNv->NvScaledImage;
85 NVAccelGetCtxSurf2DFormatFromPixmap(ppix, &dst_format);
86 BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_FORMAT, 4);
87 OUT_RING (chan, dst_format);
88 OUT_RING (chan, (exaGetPixmapPitch(ppix) << 16) | exaGetPixmapPitch(ppix));
89 OUT_PIXMAPl(chan, ppix, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
90 OUT_PIXMAPl(chan, ppix, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
92 pbox = REGION_RECTS(clipBoxes);
93 nbox = REGION_NUM_RECTS(clipBoxes);
95 dsdx = (src_w << 20) / drw_w;
96 dtdy = (src_h << 20) / drw_h;
98 dst_size = ((dstBox->y2 - dstBox->y1) << 16) |
99 (dstBox->x2 - dstBox->x1);
100 dst_point = (dstBox->y1 << 16) | dstBox->x1;
102 src_pitch |= (NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER |
103 NV04_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_BILINEAR);
104 src_point = ((y1 << 4) & 0xffff0000) | (x1 >> 12);
109 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X8R8G8B8;
113 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_YB8V8YA8U8;
117 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_V8YB8U8YA8;
121 if(pPriv->SyncToVBlank) {
122 crtcs = nv_window_belongs_to_crtc(pScrn, dstBox->x1, dstBox->y1,
123 dstBox->x2, dstBox->y2);
127 NVWaitVSync(pScrn, 0);
128 else if (crtcs & 0x2)
129 NVWaitVSync(pScrn, 1);
132 if(pNv->BlendingPossible) {
133 BEGIN_RING(chan, sifm,
134 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT, 2);
135 OUT_RING (chan, src_format);
136 OUT_RING (chan, NV04_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY);
138 BEGIN_RING(chan, sifm,
139 NV04_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT, 2);
140 OUT_RING (chan, src_format);
144 BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR1_A, 1);
147 BEGIN_RING(chan, sifm,
148 NV04_SCALED_IMAGE_FROM_MEMORY_CLIP_POINT, 6);
149 OUT_RING (chan, (pbox->y1 << 16) | pbox->x1);
150 OUT_RING (chan, ((pbox->y2 - pbox->y1) << 16) |
151 (pbox->x2 - pbox->x1));
152 OUT_RING (chan, dst_point);
153 OUT_RING (chan, dst_size);
154 OUT_RING (chan, dsdx);
155 OUT_RING (chan, dtdy);
157 BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_SIZE, 4);
158 OUT_RING (chan, (height << 16) | width);
159 OUT_RING (chan, src_pitch);
160 OUT_RELOCl(chan, src, src_offset,
161 NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
162 OUT_RING (chan, src_point);
168 exaMarkSync(pScrn->pScreen);
170 pPriv->videoStatus = FREE_TIMER;
171 pPriv->videoTime = currentTime.milliseconds + FREE_DELAY;
172 extern void NVVideoTimerCallback(ScrnInfoPtr, Time);
173 pNv->VideoTimerCallback = NVVideoTimerCallback;
178 * NVSetBlitPortAttribute
179 * sets the attribute "attribute" of port "data" to value "value"
180 * supported attributes:
181 * - xvSyncToVBlank (values: 0,1)
182 * - xvSetDefaults (values: NA; SyncToVBlank will be set, if hardware supports it)
185 * @param attribute attribute to set
186 * @param value value to which attribute is to be set
187 * @param data port from which the attribute is to be set
189 * @return Success, if setting is successful
190 * BadValue/BadMatch, if value/attribute are invalid
193 NVSetBlitPortAttribute(ScrnInfoPtr pScrn, Atom attribute,
194 INT32 value, pointer data)
196 NVPortPrivPtr pPriv = (NVPortPrivPtr)data;
197 NVPtr pNv = NVPTR(pScrn);
199 if ((attribute == xvSyncToVBlank) && pNv->WaitVSyncPossible) {
200 if ((value < 0) || (value > 1))
202 pPriv->SyncToVBlank = value;
204 if (attribute == xvSetDefaults) {
205 pPriv->SyncToVBlank = pNv->WaitVSyncPossible;
213 * NVGetBlitPortAttribute
214 * reads the value of attribute "attribute" from port "data" into INT32 "*value"
215 * currently only one attribute supported: xvSyncToVBlank
217 * @param pScrn unused
218 * @param attribute attribute to be read
219 * @param value value of attribute will be stored here
220 * @param data port from which attribute will be read
221 * @return Success, if queried attribute exists
224 NVGetBlitPortAttribute(ScrnInfoPtr pScrn, Atom attribute,
225 INT32 *value, pointer data)
227 NVPortPrivPtr pPriv = (NVPortPrivPtr)data;
229 if(attribute == xvSyncToVBlank)
230 *value = (pPriv->SyncToVBlank) ? 1 : 0;
241 NVStopBlitVideo(ScrnInfoPtr pScrn, pointer data, Bool Exit)