cg14_cursor.c revision 0a3f7816
1/* $NetBSD: cg14_cursor.c,v 1.2 2013/06/19 13:20:05 macallan Exp $ */ 2/* 3 * Copyright (c) 2005 Michael Lorenz 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * - Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * - Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials provided 15 * with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 21 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 * 30 */ 31 32#include <sys/types.h> 33 34/* all driver need this */ 35#include "xf86.h" 36#include "xf86_OSproc.h" 37 38#include "cg14.h" 39 40static void CG14LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 41static void CG14SetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 42static void CG14SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg); 43 44static void 45CG14LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 46{ 47 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 48 uint32_t buf[64]; 49 uint32_t *img = buf; 50 int i; 51 52 memcpy(buf, src, 256); /* to make sure it's aligned */ 53 for (i = 0; i < 32; i++) { 54 pCG14->curs->curs_plane0[i] = *img; 55 img++; 56 } 57 for (i = 0; i < 32; i++) { 58 pCG14->curs->curs_plane1[i] = *img; 59 img++; 60 } 61} 62 63void 64CG14ShowCursor(ScrnInfoPtr pScrn) 65{ 66 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 67 68 pCG14->curs->curs_ctl = CG14_CURS_ENABLE; 69} 70 71void 72CG14HideCursor(ScrnInfoPtr pScrn) 73{ 74 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 75 76 pCG14->curs->curs_ctl = 0; 77} 78 79static void 80CG14SetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 81{ 82 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 83 84 pCG14->curs->curs_x = x; 85 pCG14->curs->curs_y = y; 86} 87 88static void 89CG14SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 90{ 91 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 92#define RGB2BGR(x) (((x & 0xff0000) >> 16) | (x & 0xff00) | ((x & 0xff) << 16)) 93 pCG14->curs->curs_color1 = RGB2BGR(bg); 94 pCG14->curs->curs_color2 = RGB2BGR(fg); 95} 96 97Bool 98CG14SetupCursor(ScreenPtr pScreen) 99{ 100 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 101 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 102 xf86CursorInfoPtr infoPtr; 103 104 pCG14->curs->curs_ctl = 0; 105 106 infoPtr = xf86CreateCursorInfoRec(); 107 if(!infoPtr) return FALSE; 108 109 pCG14->CursorInfoRec = infoPtr; 110 111 xf86Msg(X_INFO, "HW cursor enabled\n"); 112 113 infoPtr->MaxWidth = 32; 114 infoPtr->MaxHeight = 32; 115 116 infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 117 HARDWARE_CURSOR_TRUECOLOR_AT_8BPP | 118 HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK; 119 infoPtr->SetCursorColors = CG14SetCursorColors; 120 infoPtr->SetCursorPosition = CG14SetCursorPosition; 121 infoPtr->LoadCursorImage = CG14LoadCursorImage; 122 infoPtr->HideCursor = CG14HideCursor; 123 infoPtr->ShowCursor = CG14ShowCursor; 124 infoPtr->UseHWCursor = NULL; 125 126 return xf86InitCursor(pScreen, infoPtr); 127} 128