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 extern Atom xvBrightness, xvColorKey, xvAutopaintColorKey, xvSetDefaults;
40 NV04PutOverlayImage(ScrnInfoPtr pScrn, struct nouveau_bo *src, int offset,
41 int id, int dstPitch, BoxPtr dstBox, int x1, int y1,
42 int x2, int y2, short width, short height,
43 short src_w, short src_h, short drw_w, short drw_h,
46 NVPtr pNv = NVPTR(pScrn);
47 NVPortPrivPtr pPriv = GET_OVERLAY_PRIVATE(pNv);
49 /*This may not work with NV04 overlay according to rivatv source*/
50 if (!pNv->randr12_enable) {
51 if (pScrn->currentMode->Flags & V_DBLSCAN) {
57 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
58 xf86CrtcPtr crtc = xf86_config->crtc[pPriv->overlayCRTC];
59 if (crtc->mode.Flags & V_DBLSCAN) {
66 /* paint the color key */
67 if(pPriv->autopaintColorKey && (pPriv->grabbedByV4L ||
68 !REGION_EQUAL(pScrn->pScreen, &pPriv->clip, clipBoxes))) {
69 /* we always paint V4L's color key */
70 if (!pPriv->grabbedByV4L)
71 REGION_COPY(pScrn->pScreen, &pPriv->clip, clipBoxes);
73 xf86XVFillKeyHelper(pScrn->pScreen, pPriv->colorKey, clipBoxes);
77 nvWriteVIDEO(pNv, NV_PVIDEO_OE_STATE, 0);
78 nvWriteVIDEO(pNv, NV_PVIDEO_SU_STATE, 0);
79 nvWriteVIDEO(pNv, NV_PVIDEO_RM_STATE, 0);
81 nvWriteVIDEO(pNv, NV_PVIDEO_BUFF0_START_ADDRESS,
82 src->offset + offset);
83 nvWriteVIDEO(pNv, NV_PVIDEO_BUFF0_START_ADDRESS + 4,
84 src->offset + offset);
85 nvWriteVIDEO(pNv, NV_PVIDEO_BUFF0_PITCH_LENGTH, dstPitch);
86 nvWriteVIDEO(pNv, NV_PVIDEO_BUFF0_PITCH_LENGTH + 4, dstPitch);
87 nvWriteVIDEO(pNv, NV_PVIDEO_BUFF0_OFFSET, 0);
88 nvWriteVIDEO(pNv, NV_PVIDEO_BUFF0_OFFSET + 4, 0);
90 nvWriteVIDEO(pNv, NV_PVIDEO_WINDOW_START, (dstBox->y1 << 16) | dstBox->x1);
91 nvWriteVIDEO(pNv, NV_PVIDEO_WINDOW_SIZE, ((dstBox->y2 - dstBox->y1) << 16) |
92 (dstBox->x2 - dstBox->x1));
93 nvWriteVIDEO(pNv, NV_PVIDEO_STEP_SIZE, (uint32_t)(((src_h - 1) << 11) / (drw_h - 1)) << 16 | (uint32_t)(((src_w - 1) << 11) / (drw_w - 1)));
95 nvWriteVIDEO(pNv, NV_PVIDEO_RED_CSC_OFFSET, (0x69 - (pPriv->brightness * 62 / 512)));
96 nvWriteVIDEO(pNv, NV_PVIDEO_GREEN_CSC_OFFSET, (0x3e + (pPriv->brightness * 62 / 512)));
97 nvWriteVIDEO(pNv, NV_PVIDEO_BLUE_CSC_OFFSET, (0x89 - (pPriv->brightness * 62 / 512)));
98 nvWriteVIDEO(pNv, NV_PVIDEO_CSC_ADJUST, 0x0);
100 nvWriteVIDEO(pNv, NV_PVIDEO_CONTROL_Y, 0x001); /* (BLUR_ON, LINE_HALF) */
101 nvWriteVIDEO(pNv, NV_PVIDEO_CONTROL_X, 0x111); /* (WEIGHT_HEAVY, SHARPENING_ON, SMOOTHING_ON) */
103 nvWriteVIDEO(pNv, NV_PVIDEO_FIFO_BURST_LENGTH, 0x03);
104 nvWriteVIDEO(pNv, NV_PVIDEO_FIFO_THRES_SIZE, 0x38);
106 nvWriteVIDEO(pNv, NV_PVIDEO_KEY, pPriv->colorKey);
111 nvWriteVIDEO(pNv, NV_PVIDEO_OVERLAY, 0x111);
113 nvWriteVIDEO(pNv, NV_PVIDEO_SU_STATE, (nvReadVIDEO(pNv, NV_PVIDEO_SU_STATE) ^ (1 << 16)));
115 pPriv->videoStatus = CLIENT_VIDEO_ON;
119 * NV04SetOverlayPortAttribute
120 * sets the attribute "attribute" of port "data" to value "value"
121 * calls NVResetVideo(pScrn) to apply changes to hardware
124 * @param attribute attribute to set
125 * @param value value to which attribute is to be set
126 * @param data port from which the attribute is to be set
128 * @return Success, if setting is successful
129 * BadValue/BadMatch, if value/attribute are invalid
130 * @see NVResetVideo(ScrnInfoPtr pScrn)
133 NV04SetOverlayPortAttribute(ScrnInfoPtr pScrn, Atom attribute,
134 INT32 value, pointer data)
136 NVPortPrivPtr pPriv = (NVPortPrivPtr)data;
138 if (attribute == xvBrightness) {
139 if ((value < -512) || (value > 512))
141 pPriv->brightness = value;
143 if (attribute == xvColorKey) {
144 pPriv->colorKey = value;
145 REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
147 if (attribute == xvAutopaintColorKey) {
148 if ((value < 0) || (value > 1))
150 pPriv->autopaintColorKey = value;
152 if (attribute == xvSetDefaults) {
153 NVSetPortDefaults(pScrn, pPriv);
161 * NV04GetOverlayPortAttribute
163 * @param pScrn unused
164 * @param attribute attribute to be read
165 * @param value value of attribute will be stored in this pointer
166 * @param data port from which attribute will be read
167 * @return Success, if queried attribute exists
170 NV04GetOverlayPortAttribute(ScrnInfoPtr pScrn, Atom attribute,
171 INT32 *value, pointer data)
173 NVPortPrivPtr pPriv = (NVPortPrivPtr)data;
175 if (attribute == xvBrightness)
176 *value = pPriv->brightness;
177 else if (attribute == xvColorKey)
178 *value = pPriv->colorKey;
179 else if (attribute == xvAutopaintColorKey)
180 *value = (pPriv->autopaintColorKey) ? 1 : 0;
189 * Tell the hardware to stop the overlay
192 NV04StopOverlay (ScrnInfoPtr pScrn)
194 NVPtr pNv = NVPTR(pScrn);
196 nvWriteVIDEO(pNv, NV_PVIDEO_OVERLAY, nvReadVIDEO(pNv, NV_PVIDEO_OVERLAY) &~ 0x1);
197 nvWriteVIDEO(pNv, NV_PVIDEO_OE_STATE, 0);
198 nvWriteVIDEO(pNv, NV_PVIDEO_SU_STATE, 0);
199 nvWriteVIDEO(pNv, NV_PVIDEO_RM_STATE, 0);