summaryrefslogtreecommitdiff
path: root/src/smi_crtc.c
blob: d061ad5efefb9ffe3b57b1d7789d64a545d4f06a (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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
Copyright (C) 2008 Francisco Jerez.  All Rights Reserved.

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, FIT-
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
XFREE86 PROJECT 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 "smi.h"
#include "smi_crtc.h"
#include "smilynx.h"
#include "smi_501.h"

static void
SMI_CrtcDPMS(xf86CrtcPtr		crtc,
	     int		    	mode)
{
    ENTER();

    /* Nothing */

    LEAVE();
}

static Bool
SMI_CrtcLock (xf86CrtcPtr crtc)
{
    ScrnInfoPtr pScrn = crtc->scrn;
    SMIPtr pSmi = SMIPTR(pScrn);

    ENTER();

    WaitIdle();

    RETURN(FALSE);
}

static void
SMI_CrtcUnlock (xf86CrtcPtr crtc)
{
    ENTER();

    /* Nothing */

    LEAVE();
}

static Bool
SMI_CrtcModeFixup(xf86CrtcPtr crtc,
		  DisplayModePtr mode,
		  DisplayModePtr adjusted_mode)
{
    ENTER();

    /* Nothing */

    RETURN(TRUE);
}

static void
SMI_CrtcPrepare(xf86CrtcPtr crtc)
{
    ScrnInfoPtr pScrn = crtc->scrn;
    SMIPtr pSmi = SMIPTR(pScrn);

    ENTER();

    if (pSmi->HwCursor)
	crtc->funcs->hide_cursor(crtc);

    LEAVE();
}

static void
SMI_CrtcCommit(xf86CrtcPtr crtc)
{
    ScrnInfoPtr pScrn = crtc->scrn;
    SMIPtr pSmi = SMIPTR(pScrn);

    ENTER();

    /* Problem:
     *	When starting in Dualhead mode, both hw cursors will be shown,
     *	and at the same position, as both are at the same address.
     *	When reconfiguring with something like:
     *	$ xrandr --output VGA --right-of LVDS
     *	what will happen is basically:
     *	hide_cursor(panel)
     *	hide_cursor(crt)
     *	<set-crt-mode-and-modify-mapped-address>
     *	show_cursor(panel)	<- besides a sw argb cursor is being used...
     *
     *	It should not be a problem if argb cursors were supported,
     *	or only one output is available...
     */
    if (pSmi->HwCursor)
	xf86_reload_cursors(pScrn->pScreen);

    LEAVE();
}

static void
SMI_CrtcGammaSet(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
	     int size)
{
    SMICrtcPrivatePtr crtcPriv = SMICRTC(crtc);
    int i;

    ENTER();

    for(i=0; i<256; i++){
	crtcPriv->lut_r[i] = red[i * size >> 8];
	crtcPriv->lut_g[i] = green[i * size >> 8];
	crtcPriv->lut_b[i] = blue[i * size >> 8];
    }

    crtcPriv->load_lut(crtc);

    LEAVE();
}

static void *
SMI_CrtcShadowAllocate (xf86CrtcPtr crtc, int width, int height)
{
    ScrnInfoPtr pScrn = crtc->scrn;
    SMIPtr pSmi = SMIPTR(pScrn);
    SMICrtcPrivatePtr crtcPriv = SMICRTC(crtc);

    ENTER();

    if(!pSmi->NoAccel && pSmi->useEXA){
	int aligned_pitch = (width * pSmi->Bpp + 15) & ~15;

	crtcPriv->shadowArea = exaOffscreenAlloc(pScrn->pScreen, aligned_pitch * height, 16, TRUE, NULL, NULL);

	if(crtcPriv->shadowArea)
	    RETURN(pSmi->FBBase + crtcPriv->shadowArea->offset);
    }

    RETURN(NULL);
}

static PixmapPtr
SMI_CrtcShadowCreate (xf86CrtcPtr crtc, void *data, int width, int height)
{
    ScrnInfoPtr pScrn = crtc->scrn;
    SMIPtr pSmi = SMIPTR(pScrn);
    int aligned_pitch;

    ENTER();

    aligned_pitch = (width * pSmi->Bpp + 15) & ~15;

    RETURN(GetScratchPixmapHeader(pScrn->pScreen,width,height,pScrn->depth,
				  pScrn->bitsPerPixel,aligned_pitch,data));
}

static void
SMI_CrtcShadowDestroy (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data)
{
    ScrnInfoPtr pScrn = crtc->scrn;
    SMICrtcPrivatePtr crtcPriv = SMICRTC(crtc);

    ENTER();

    if(pPixmap)
	FreeScratchPixmapHeader(pPixmap);

    if(crtcPriv->shadowArea){
	exaOffscreenFree(pScrn->pScreen, crtcPriv->shadowArea);
	crtcPriv->shadowArea = NULL;
    }

    LEAVE();
}

static void
SMI_CrtcDestroy (xf86CrtcPtr	crtc)
{
    ENTER();

    /* Nothing */

    LEAVE();
}

static Bool
SMI_CrtcConfigResize(ScrnInfoPtr       pScrn,
		     int               width,
		     int               height)
{
    SMIPtr pSmi = SMIPTR(pScrn);
    xf86CrtcConfigPtr crtcConf = XF86_CRTC_CONFIG_PTR(pScrn);
    int i;
    xf86CrtcPtr crtc;

    ENTER();

    /* Allocate another offscreen area and use it as screen, if it really has to be resized */
    if(!pSmi->NoAccel && pSmi->useEXA &&
       ( !pSmi->fbArea || width != pScrn->virtualX || height != pScrn->virtualY )){
	int aligned_pitch = (width*pSmi->Bpp + 15) & ~15;

	ExaOffscreenArea* fbArea = exaOffscreenAlloc(pScrn->pScreen, aligned_pitch*height, 16, TRUE, NULL, NULL);
	if(!fbArea){
	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
		   "SMI_CrtcConfigResize: Not enough memory to resize the framebuffer\n");
	    RETURN(FALSE);
	}

	if(pSmi->fbArea)
	    exaOffscreenFree(pScrn->pScreen, pSmi->fbArea);

	pSmi->fbArea = fbArea;
	pSmi->FBOffset = fbArea->offset;
	pScrn->fbOffset = pSmi->FBOffset + pSmi->fbMapOffset;

	if(pScrn->pixmapPrivate.ptr)
	    /* Framebuffer access is disabled */
	    pScrn->pixmapPrivate.ptr = pSmi->FBBase + pSmi->FBOffset;
	else
	    pScrn->pScreen->ModifyPixmapHeader(pScrn->pScreen->GetScreenPixmap(pScrn->pScreen),
					       -1,-1,-1,-1,-1, pSmi->FBBase + pSmi->FBOffset);

	/* Modify the screen pitch */
	pScrn->displayWidth = aligned_pitch / pSmi->Bpp;
	pScrn->pScreen->ModifyPixmapHeader(pScrn->pScreen->GetScreenPixmap(pScrn->pScreen),
					   -1, -1, -1, -1, aligned_pitch, NULL);

	/* Modify the screen dimensions */
	pScrn->virtualX = width;
	pScrn->virtualY = height;
	pScrn->pScreen->ModifyPixmapHeader(pScrn->pScreen->GetScreenPixmap(pScrn->pScreen),
					   width, height, -1, -1, 0, NULL);
    }

    /* Setup each crtc video processor */
    for(i=0;i<crtcConf->num_crtc;i++){
	crtc = crtcConf->crtc[i];
	SMICRTC(crtc)->video_init(crtc);
	SMICRTC(crtc)->adjust_frame(crtc,crtc->x,crtc->y);
    }

    RETURN(TRUE);
}

void
SMI_CrtcFuncsInit_base(xf86CrtcFuncsPtr crtcFuncs, SMICrtcPrivatePtr crtcPriv){
    memset(crtcFuncs,0,sizeof(xf86CrtcFuncsRec));
    memset(crtcPriv,0,sizeof(SMICrtcPrivatePtr));

    crtcFuncs->dpms = SMI_CrtcDPMS;
    crtcFuncs->lock = SMI_CrtcLock;
    crtcFuncs->unlock = SMI_CrtcUnlock;
    crtcFuncs->mode_fixup = SMI_CrtcModeFixup;
    crtcFuncs->prepare = SMI_CrtcPrepare;
    crtcFuncs->commit = SMI_CrtcCommit;
    crtcFuncs->gamma_set = SMI_CrtcGammaSet;
    crtcFuncs->shadow_allocate = SMI_CrtcShadowAllocate;
    crtcFuncs->shadow_create = SMI_CrtcShadowCreate;
    crtcFuncs->shadow_destroy = SMI_CrtcShadowDestroy;
    crtcFuncs->destroy = SMI_CrtcDestroy;
}

static xf86CrtcConfigFuncsRec SMI_CrtcConfigFuncs = {
    .resize = SMI_CrtcConfigResize
};

Bool
SMI_CrtcPreInit(ScrnInfoPtr pScrn)
{
    SMIPtr pSmi = SMIPTR(pScrn);

    ENTER();

    xf86CrtcConfigInit(pScrn,&SMI_CrtcConfigFuncs);

    xf86CrtcSetSizeRange(pScrn,128,128,4096,4096);

    if(SMI_MSOC_SERIES(pSmi->Chipset)){
	RETURN( SMI501_CrtcPreInit(pScrn) );
    }else{
	RETURN( SMILynx_CrtcPreInit(pScrn) );
    }
}