ag10e_cursor.c revision 898e129c
1/* 2 * Hardware cursor support for Fujitsu AG-10e 3 * 4 * Copyright 2007 by Michael Lorenz 5 * 6 * Permission to use, copy, modify, distribute, and sell this software 7 * and its documentation for any purpose is hereby granted without 8 * fee, provided that the above copyright notice appear in all copies 9 * and that both that copyright notice and this permission notice 10 * appear in supporting documentation, and that the name of Jakub 11 * Jelinek not be used in advertising or publicity pertaining to 12 * distribution of the software without specific, written prior 13 * permission. Jakub Jelinek makes no representations about the 14 * suitability of this software for any purpose. It is provided "as 15 * is" without express or implied warranty. 16 * 17 * JAKUB JELINEK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 19 * FITNESS, IN NO EVENT SHALL JAKUB JELINEK BE LIABLE FOR ANY 20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 22 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 23 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 24 * SOFTWARE. 25 */ 26/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/suncg6/cg6_cursor.c,v 1.1 2000/06/30 19:30:46 dawes Exp $ */ 27 28#include <fcntl.h> 29#include <sys/time.h> 30#include <sys/types.h> 31#include <sys/ioctl.h> 32#include <dev/sun/fbio.h> 33#include <dev/wscons/wsconsio.h> 34 35#include "ag10e.h" 36 37static void AG10ELoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 38static void AG10EShowCursor(ScrnInfoPtr pScrn); 39static void AG10EHideCursor(ScrnInfoPtr pScrn); 40static void AG10ESetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 41static void AG10ESetCursorColors(ScrnInfoPtr pScrn, int bg, int fg); 42 43static void 44AG10ELoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 45{ 46 AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 47 48 pAG10E->Cursor.set = FB_CUR_SETSHAPE; 49 pAG10E->Cursor.image = src; 50 pAG10E->Cursor.mask = src + 0x200; 51 52 if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 53 xf86Msg(X_ERROR, "FB_CUR_SETSHAPE failed\n"); 54} 55 56void 57AG10EShowCursor(ScrnInfoPtr pScrn) 58{ 59 AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 60 61 if (pAG10E->Cursor.enable == 0) { 62 pAG10E->Cursor.enable = 1; 63 pAG10E->Cursor.set = FB_CUR_SETCUR; 64 if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 65 xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n"); 66 } 67} 68 69void 70AG10EHideCursor(ScrnInfoPtr pScrn) 71{ 72 AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 73 74 if (pAG10E->Cursor.enable == 1) { 75 pAG10E->Cursor.enable = 0; 76 pAG10E->Cursor.set = FB_CUR_SETCUR; 77 if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 78 xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n"); 79 } 80} 81 82static void 83AG10ESetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 84{ 85 AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 86 87 pAG10E->Cursor.pos.x = x; 88 pAG10E->Cursor.pos.y = y; 89 pAG10E->Cursor.set = FB_CUR_SETPOS; 90 if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 91 xf86Msg(X_ERROR, "FB_CUR_SETPOS failed\n"); 92} 93 94static void 95AG10ESetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 96{ 97 AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 98 99 pAG10E->Cursor.set = FB_CUR_SETCMAP; 100 pAG10E->Cursor.cmap.index = 0; 101 pAG10E->Cursor.cmap.count = 2; 102 pAG10E->Cursor.cmap.red[0] = (bg & 0xff0000) >> 16; 103 pAG10E->Cursor.cmap.green[0] = (bg & 0xff00) >> 8; 104 pAG10E->Cursor.cmap.blue[0] = bg & 0xff; 105 pAG10E->Cursor.cmap.red[1] = (fg & 0xff0000) >> 16; 106 pAG10E->Cursor.cmap.green[1] = (fg & 0xff00) >> 8; 107 pAG10E->Cursor.cmap.blue[1] = fg & 0xff; 108 if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 109 xf86Msg(X_ERROR, "FB_CUR_SETCMAP failed\n"); 110} 111 112Bool 113AG10EHWCursorInit(ScreenPtr pScreen) 114{ 115 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 116 AG10EPtr pAG10E; 117 xf86CursorInfoPtr infoPtr; 118 119 pAG10E = GET_AG10E_FROM_SCRN(pScrn); 120 121 pAG10E->Cursor.mask = NULL; 122 pAG10E->Cursor.image = NULL; 123 if (ioctl(pAG10E->psdp->fd, FBIOGCURSOR, &pAG10E->Cursor) == -1) { 124 xf86Msg(X_ERROR, "Hardware cursor isn't available\n"); 125 return FALSE; 126 } 127 128 infoPtr = xf86CreateCursorInfoRec(); 129 if(!infoPtr) return FALSE; 130 131 pAG10E->CursorInfoRec = infoPtr; 132 133 infoPtr->MaxWidth = 64; 134 infoPtr->MaxHeight = 64; 135 136 pAG10E->Cursor.hot.x = 0; 137 pAG10E->Cursor.hot.y = 0; 138 pAG10E->Cursor.set = FB_CUR_SETHOT; 139 ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor); 140 141 pAG10E->Cursor.cmap.red = pAG10E->pal; 142 pAG10E->Cursor.cmap.green = pAG10E->pal + 3; 143 pAG10E->Cursor.cmap.blue = pAG10E->pal + 6; 144 145 infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 146 HARDWARE_CURSOR_TRUECOLOR_AT_8BPP; 147 148 infoPtr->SetCursorColors = AG10ESetCursorColors; 149 infoPtr->SetCursorPosition = AG10ESetCursorPosition; 150 infoPtr->LoadCursorImage = AG10ELoadCursorImage; 151 infoPtr->HideCursor = AG10EHideCursor; 152 infoPtr->ShowCursor = AG10EShowCursor; 153 infoPtr->UseHWCursor = NULL; 154 155 return xf86InitCursor(pScreen, infoPtr); 156} 157