i810_cursor.c revision fa225cbc
1 2/************************************************************************** 3 4Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. 5All Rights Reserved. 6 7Permission is hereby granted, free of charge, to any person obtaining a 8copy of this software and associated documentation files (the 9"Software"), to deal in the Software without restriction, including 10without limitation the rights to use, copy, modify, merge, publish, 11distribute, sub license, and/or sell copies of the Software, and to 12permit persons to whom the Software is furnished to do so, subject to 13the following conditions: 14 15The above copyright notice and this permission notice (including the 16next paragraph) shall be included in all copies or substantial portions 17of the Software. 18 19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 23ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 27**************************************************************************/ 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33/* 34 * Authors: 35 * Keith Whitwell <keith@tungstengraphics.com> 36 * 37 * Add ARGB HW cursor support: 38 * Alan Hourihane <alanh@tungstengraphics.com> 39 * 40 */ 41 42#include "xf86.h" 43#include "xf86_OSproc.h" 44#include "compiler.h" 45 46#include "xf86fbman.h" 47 48#include "i810.h" 49 50static Bool I810UseHWCursorARGB(ScreenPtr pScreen, CursorPtr pCurs); 51static void I810LoadCursorARGB(ScrnInfoPtr pScrn, CursorPtr pCurs); 52static void I810LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 53static void I810ShowCursor(ScrnInfoPtr pScrn); 54static void I810HideCursor(ScrnInfoPtr pScrn); 55static void I810SetCursorColors(ScrnInfoPtr pScrn, int bg, int fb); 56static void I810SetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 57static Bool I810UseHWCursor(ScreenPtr pScrn, CursorPtr pCurs); 58 59Bool 60I810CursorInit(ScreenPtr pScreen) 61{ 62 ScrnInfoPtr pScrn; 63 I810Ptr pI810; 64 xf86CursorInfoPtr infoPtr; 65 66 pScrn = xf86Screens[pScreen->myNum]; 67 pI810 = I810PTR(pScrn); 68 pI810->CursorInfoRec = infoPtr = xf86CreateCursorInfoRec(); 69 if (!infoPtr) 70 return FALSE; 71 72 infoPtr->MaxWidth = 64; 73 infoPtr->MaxHeight = 64; 74 infoPtr->Flags = (HARDWARE_CURSOR_TRUECOLOR_AT_8BPP | 75 HARDWARE_CURSOR_BIT_ORDER_MSBFIRST | 76 HARDWARE_CURSOR_INVERT_MASK | 77 HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK | 78 HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 79 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | 0); 80 81 infoPtr->SetCursorColors = I810SetCursorColors; 82 infoPtr->SetCursorPosition = I810SetCursorPosition; 83 infoPtr->LoadCursorImage = I810LoadCursorImage; 84 infoPtr->HideCursor = I810HideCursor; 85 infoPtr->ShowCursor = I810ShowCursor; 86 infoPtr->UseHWCursor = I810UseHWCursor; 87#ifdef ARGB_CURSOR 88 pI810->CursorIsARGB = FALSE; 89 90 if (!pI810->CursorARGBPhysical) { 91 infoPtr->UseHWCursorARGB = I810UseHWCursorARGB; 92 infoPtr->LoadCursorARGB = I810LoadCursorARGB; 93 } 94#endif 95 96 return xf86InitCursor(pScreen, infoPtr); 97} 98 99#ifdef ARGB_CURSOR 100#include "cursorstr.h" 101 102static Bool I810UseHWCursorARGB (ScreenPtr pScreen, CursorPtr pCurs) 103{ 104 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 105 I810Ptr pI810 = I810PTR(pScrn); 106 107 if (!pI810->CursorARGBPhysical) 108 return FALSE; 109 110 if (pCurs->bits->height <= 64 && pCurs->bits->width <= 64) 111 return TRUE; 112 113 return FALSE; 114} 115 116static void I810LoadCursorARGB (ScrnInfoPtr pScrn, CursorPtr pCurs) 117{ 118 I810Ptr pI810 = I810PTR(pScrn); 119 uint32_t *pcurs = (uint32_t *) (pI810->FbBase + pI810->CursorStart); 120 uint32_t *image = (uint32_t *) pCurs->bits->argb; 121 int x, y, w, h; 122 123#ifdef ARGB_CURSOR 124 pI810->CursorIsARGB = TRUE; 125#endif 126 127 w = pCurs->bits->width; 128 h = pCurs->bits->height; 129 130 for (y = 0; y < h; y++) 131 { 132 for (x = 0; x < w; x++) 133 *pcurs++ = *image++; 134 for (; x < 64; x++) 135 *pcurs++ = 0; 136 } 137 138 for (; y < 64; y++) 139 for (x = 0; x < 64; x++) 140 *pcurs++ = 0; 141} 142#endif 143 144static Bool 145I810UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs) 146{ 147 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 148 I810Ptr pI810 = I810PTR(pScrn); 149 150 if (!pI810->CursorPhysical) 151 return FALSE; 152 else 153 return TRUE; 154} 155 156static void 157I810LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 158{ 159 I810Ptr pI810 = I810PTR(pScrn); 160 uint8_t *pcurs = (uint8_t *) (pI810->FbBase + pI810->CursorStart); 161 int x, y; 162 163#ifdef ARGB_CURSOR 164 pI810->CursorIsARGB = FALSE; 165#endif 166 167 for (y = 0; y < 64; y++) { 168 for (x = 0; x < 64 / 4; x++) { 169 *pcurs++ = *src++; 170 } 171 } 172} 173 174static void 175I810SetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 176{ 177 I810Ptr pI810 = I810PTR(pScrn); 178 int flag; 179 180 x += pI810->CursorOffset; 181 182 if (x >= 0) 183 flag = CURSOR_X_POS; 184 else { 185 flag = CURSOR_X_NEG; 186 x = -x; 187 } 188 189 OUTREG8(CURSOR_X_LO, x & 0xFF); 190 OUTREG8(CURSOR_X_HI, (((x >> 8) & 0x07) | flag)); 191 192 if (y >= 0) 193 flag = CURSOR_Y_POS; 194 else { 195 flag = CURSOR_Y_NEG; 196 y = -y; 197 } 198 OUTREG8(CURSOR_Y_LO, y & 0xFF); 199 OUTREG8(CURSOR_Y_HI, (((y >> 8) & 0x07) | flag)); 200 201 if (pI810->CursorIsARGB) 202 OUTREG(CURSOR_BASEADDR, pI810->CursorARGBPhysical); 203 else 204 OUTREG(CURSOR_BASEADDR, pI810->CursorPhysical); 205} 206 207static void 208I810ShowCursor(ScrnInfoPtr pScrn) 209{ 210 I810Ptr pI810 = I810PTR(pScrn); 211 unsigned char tmp; 212 213 if (pI810->CursorIsARGB) { 214 OUTREG(CURSOR_BASEADDR, pI810->CursorARGBPhysical); 215 OUTREG8(CURSOR_CONTROL, CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_ARGB_AX); 216 } else { 217 OUTREG(CURSOR_BASEADDR, pI810->CursorPhysical); 218 OUTREG8(CURSOR_CONTROL, CURSOR_ORIGIN_DISPLAY | CURSOR_MODE_64_3C); 219 } 220 221 tmp = INREG8(PIXPIPE_CONFIG_0); 222 tmp |= HW_CURSOR_ENABLE; 223 OUTREG8(PIXPIPE_CONFIG_0, tmp); 224} 225 226static void 227I810HideCursor(ScrnInfoPtr pScrn) 228{ 229 unsigned char tmp; 230 I810Ptr pI810 = I810PTR(pScrn); 231 232 tmp = INREG8(PIXPIPE_CONFIG_0); 233 tmp &= ~HW_CURSOR_ENABLE; 234 OUTREG8(PIXPIPE_CONFIG_0, tmp); 235} 236 237static void 238I810SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 239{ 240 int tmp; 241 I810Ptr pI810 = I810PTR(pScrn); 242 243#ifdef ARGB_CURSOR 244 if (pI810->CursorIsARGB) 245 return; 246#endif 247 248 tmp = INREG8(PIXPIPE_CONFIG_0); 249 tmp |= EXTENDED_PALETTE; 250 OUTREG8(PIXPIPE_CONFIG_0, tmp); 251 252 pI810->writeStandard(pI810, DACMASK, 0xFF); 253 pI810->writeStandard(pI810, DACWX, 0x04); 254 255 pI810->writeStandard(pI810, DACDATA, (bg & 0x00FF0000) >> 16); 256 pI810->writeStandard(pI810, DACDATA, (bg & 0x0000FF00) >> 8); 257 pI810->writeStandard(pI810, DACDATA, (bg & 0x000000FF)); 258 259 pI810->writeStandard(pI810, DACDATA, (fg & 0x00FF0000) >> 16); 260 pI810->writeStandard(pI810, DACDATA, (fg & 0x0000FF00) >> 8); 261 pI810->writeStandard(pI810, DACDATA, (fg & 0x000000FF)); 262 263 tmp = INREG8(PIXPIPE_CONFIG_0); 264 tmp &= ~EXTENDED_PALETTE; 265 OUTREG8(PIXPIPE_CONFIG_0, tmp); 266} 267