summaryrefslogtreecommitdiff
path: root/src/smi_shadow.c
blob: 5ef9ba586708ecf87e8bf6131235dfb6eadd2887 (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
/* Header:   //Mercury/Projects/archives/XFree86/4.0/smi_shadow.c-arc   1.10   30 Nov 2000 11:40:38   Frido  $ */

/*
Copyright (C) 1994-2000 The XFree86 Project, Inc.  All Rights Reserved.
Copyright (C) 2000 Silicon Motion, Inc.  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.

Except as contained in this notice, the names of the XFree86 Project and
Silicon Motion shall not be used in advertising or otherwise to promote the
sale, use or other dealings in this Software without prior written
authorization from the XFree86 Project and Silicon Motion.
*/
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/siliconmotion/smi_shadow.c,v 1.2 2000/12/05 21:18:37 dawes Exp $ */

#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86Resources.h"
#include "xf86_ansic.h"
#include "xf86PciInfo.h"
#include "xf86Pci.h"
#include "shadowfb.h"
#include "servermd.h"

#include "smi.h"

/******************************************************************************\
|* SMI_RefreshArea
|*=============================================================================
|*
|*  PARAMETERS:		pScrn	Pointer to ScrnInfo structure.
|*					num		Number of boxes to refresh.
|*					pbox	Pointer to an array of boxes to refresh.
|*
|*  DESCRIPTION:	Refresh a portion of the shadow buffer to the visual screen
|*					buffer.  This is mainly used for rotation purposes.
|*												y
|*  RETURNS:		Nothing.
|*
\******************************************************************************/
void SMI_RefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
{
	SMIPtr pSmi = SMIPTR(pScrn);
	int width, height, srcX, srcY, destX, destY;

	ENTER_PROC("SMI_RefreshArea");

	/* #671 */
	if (pSmi->polyLines)
	{
		pSmi->polyLines = FALSE;
		return;
	}

	if (pSmi->rotate)
	{
		/* IF we need to do rotation, setup the hardware here. */
		WaitIdleEmpty();
		WRITE_DPR(pSmi, 0x10, pSmi->ShadowPitch);
		WRITE_DPR(pSmi, 0x3C, pSmi->ShadowPitch);
		WRITE_DPR(pSmi, 0x44, pSmi->FBOffset >> 3);
	}

	/* #672 */
	if (pSmi->ClipTurnedOn)
	{
		WaitQueue(1);
		WRITE_DPR(pSmi, 0x2C, pSmi->ScissorsLeft);
		pSmi->ClipTurnedOn = FALSE;
	}

	while (num--)
	{
		/* Get coordinates of the box to refresh. */
		srcX   = pbox->x1;
		srcY   = pbox->y1;
		width  = pbox->x2 - srcX;
		height = pbox->y2 - srcY;

		DEBUG((VERBLEV, "x=%d y=%d w=%d h=%d\n", srcX, srcY, width, height));

		if ((width > 0) && (height > 0))
		{
			switch (pSmi->rotate)
			{
				case SMI_ROTATE_CW:
					/* 90 degrees CW rotation.  Calculate destination
					   coordinates:

						*---+
						|   |       +-----*
						|   |       |     |  destX = shadowHeight - srcY - 1
						|   |  -->  |     |  destY = srcX
						|   |       |     |
						|   |       +-----+
						+---+
					*/
					destX = pSmi->ShadowHeight - srcY - 1;
					destY = srcX;

					WaitQueue(4);
					WRITE_DPR(pSmi, 0x00, (srcX << 16)   + srcY);
					WRITE_DPR(pSmi, 0x04, (destX << 16)  + destY);
					WRITE_DPR(pSmi, 0x08, (width << 16)  + height);
					WRITE_DPR(pSmi, 0x0C, 0xCC | SMI_ROTATE_BLT |
							SMI_ROTATE_CW | SMI_START_ENGINE);
					break;

				case SMI_ROTATE_CCW:
					/* 90 degrees CCW rotatation.  Calculate destination
					   coordinates:

						*---+
						|   |       +-----+
						|   |       |     |  destX = srcY
						|   |  -->  |     |  destY = shadowWidth - srcX - 1
						|   |       |     |
						|   |       *-----+
						+---+
					*/
					destX = srcY;
					destY = pSmi->ShadowWidth - srcX - 1;

					WaitQueue(4);
					WRITE_DPR(pSmi, 0x00, (srcX << 16)   + srcY);
					WRITE_DPR(pSmi, 0x04, (destX << 16)  + destY);
					WRITE_DPR(pSmi, 0x08, (width << 16)  + height);
					WRITE_DPR(pSmi, 0x0C, 0xCC | SMI_ROTATE_BLT |
							SMI_ROTATE_CCW | SMI_START_ENGINE);
					break;

				default:
					/* No rotation, perform a normal copy. */
					if (pScrn->bitsPerPixel == 24)
					{
						srcX  *= 3;
						width *= 3;

						if (pSmi->Chipset == SMI_LYNX)
						{
							srcY *= 3;
						}
					}

					WaitQueue(4);
					WRITE_DPR(pSmi, 0x00, (srcX << 16)  + srcY);
					WRITE_DPR(pSmi, 0x04, (srcX << 16)  + srcY);
					WRITE_DPR(pSmi, 0x08, (width << 16) + height);
					WRITE_DPR(pSmi, 0x0C, SMI_BITBLT + SMI_START_ENGINE + 0xCC);
					break;
			}
		}

		pbox++;
	}

	if (pSmi->rotate)
	{
		/* If we did a rotation, we need to restore the hardware state here. */
		WaitIdleEmpty();
		WRITE_DPR(pSmi, 0x10, (pSmi->Stride << 16) | pSmi->Stride);
		WRITE_DPR(pSmi, 0x3C, (pSmi->Stride << 16) | pSmi->Stride);
		WRITE_DPR(pSmi, 0x44, 0);
	}

	LEAVE_PROC("SMI_RefreshArea");
}

/******************************************************************************\
|* SMI_PointerMoved
|*=============================================================================
|*
|*  PARAMETERS:		index	Index of current screen.
|*					x		X location of pointer.
|*					y		Y location of pointer.
|*
|*  DESCRIPTION:	Adjust the pointer location if we are in rotation mode.
|*
|*  RETURNS:		Nothing.
|*
\******************************************************************************/
void SMI_PointerMoved(int index, int x, int y)
{
    ScrnInfoPtr pScrn = xf86Screens[index];
    SMIPtr pSmi = SMIPTR(pScrn);
    int newX, newY;

	switch (pSmi->rotate)
	{
		case SMI_ROTATE_CW:
			/* 90 degrees CW rotation. */
			newX = pScrn->pScreen->height - y - 1;
			newY = x;
			break;

		case SMI_ROTATE_CCW:
			/* 90 degrees CCW rotation. */
			newX = y;
			newY = pScrn->pScreen->width - x - 1;
			break;

		default:
			/* No rotation. */
			newX = x;
			newY = y;
			break;
    }

	/* Pass adjusted pointer coordinates original PointerMoved function. */
    (*pSmi->PointerMoved)(index, newX, newY);
}