1/* $NetBSD: cg14_cursor.c,v 1.3 2016/09/16 21:16:37 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#ifdef HAVE_CONFIG_H 33#include "config.h" 34#endif 35 36#include <sys/types.h> 37 38/* all driver need this */ 39#include "xf86.h" 40#include "xf86_OSproc.h" 41 42#include "cg14.h" 43 44static void CG14LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 45static void CG14SetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 46static void CG14SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg); 47 48static void 49CG14LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 50{ 51 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 52 uint32_t buf[64]; 53 uint32_t *img = buf; 54 int i; 55 56 memcpy(buf, src, 256); /* to make sure it's aligned */ 57 for (i = 0; i < 32; i++) { 58 pCG14->curs->curs_plane0[i] = *img; 59 img++; 60 } 61 for (i = 0; i < 32; i++) { 62 pCG14->curs->curs_plane1[i] = *img; 63 img++; 64 } 65} 66 67void 68CG14ShowCursor(ScrnInfoPtr pScrn) 69{ 70 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 71 72 pCG14->curs->curs_ctl = CG14_CURS_ENABLE; 73} 74 75void 76CG14HideCursor(ScrnInfoPtr pScrn) 77{ 78 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 79 80 pCG14->curs->curs_ctl = 0; 81} 82 83static void 84CG14SetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 85{ 86 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 87 88 pCG14->curs->curs_x = x; 89 pCG14->curs->curs_y = y; 90} 91 92static void 93CG14SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 94{ 95 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 96#define RGB2BGR(x) (((x & 0xff0000) >> 16) | (x & 0xff00) | ((x & 0xff) << 16)) 97 pCG14->curs->curs_color1 = RGB2BGR(bg); 98 pCG14->curs->curs_color2 = RGB2BGR(fg); 99} 100 101Bool 102CG14SetupCursor(ScreenPtr pScreen) 103{ 104 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 105 Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn); 106 xf86CursorInfoPtr infoPtr; 107 108 pCG14->curs->curs_ctl = 0; 109 110 infoPtr = xf86CreateCursorInfoRec(); 111 if(!infoPtr) return FALSE; 112 113 pCG14->CursorInfoRec = infoPtr; 114 115 xf86Msg(X_INFO, "HW cursor enabled\n"); 116 117 infoPtr->MaxWidth = 32; 118 infoPtr->MaxHeight = 32; 119 120 infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 121 HARDWARE_CURSOR_TRUECOLOR_AT_8BPP | 122 HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK; 123 infoPtr->SetCursorColors = CG14SetCursorColors; 124 infoPtr->SetCursorPosition = CG14SetCursorPosition; 125 infoPtr->LoadCursorImage = CG14LoadCursorImage; 126 infoPtr->HideCursor = CG14HideCursor; 127 infoPtr->ShowCursor = CG14ShowCursor; 128 infoPtr->UseHWCursor = NULL; 129 130 return xf86InitCursor(pScreen, infoPtr); 131} 132