vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / ati / rage128_cursor.cpp
blobd7d6b9ecf5f245b83004dde0a206f2ac23534588
1 /*
2 Haiku ATI video driver adapted from the X.org ATI driver.
4 Copyright 1999, 2000 ATI Technologies Inc., Markham, Ontario,
5 Precision Insight, Inc., Cedar Park, Texas, and
6 VA Linux Systems Inc., Fremont, California.
8 Copyright 2009 Haiku, Inc. All rights reserved.
9 Distributed under the terms of the MIT license.
11 Authors:
12 Gerald Zajac 2009
16 #include "accelerant.h"
17 #include "rage128.h"
21 void
22 Rage128_ShowCursor(bool bShow)
24 // Turn cursor on/off.
26 OUTREGM(R128_CRTC_GEN_CNTL, bShow ? R128_CRTC_CUR_EN : 0, R128_CRTC_CUR_EN);
30 void
31 Rage128_SetCursorPosition(int x, int y)
33 SharedInfo& si = *gInfo.sharedInfo;
35 // xOffset & yOffset are used for displaying partial cursors on screen edges.
37 uint8 xOffset = 0;
38 uint8 yOffset = 0;
40 if (x < 0) {
41 xOffset = (( -x) & 0xFE);
42 x = 0;
45 if (y < 0) {
46 yOffset = (( -y) & 0xFE);
47 y = 0;
50 OUTREG(R128_CUR_HORZ_VERT_OFF, R128_CUR_LOCK | (xOffset << 16) | yOffset);
51 OUTREG(R128_CUR_HORZ_VERT_POSN, R128_CUR_LOCK | (x << 16) | y);
52 OUTREG(R128_CUR_OFFSET, si.cursorOffset + yOffset * 16);
56 bool
57 Rage128_LoadCursorImage(int width, int height, uint8* andMask, uint8* xorMask)
59 SharedInfo& si = *gInfo.sharedInfo;
61 if (andMask == NULL || xorMask == NULL)
62 return false;
64 // Initialize the hardware cursor as completely transparent.
66 uint32* fbCursor32 = (uint32*)((addr_t)si.videoMemAddr + si.cursorOffset);
68 for (int i = 0; i < CURSOR_BYTES; i += 16) {
69 *fbCursor32++ = ~0; // and bits
70 *fbCursor32++ = ~0;
71 *fbCursor32++ = 0; // xor bits
72 *fbCursor32++ = 0;
75 // Now load the AND & XOR masks for the cursor image into the cursor
76 // buffer. Note that a particular bit in these masks will have the
77 // following effect upon the corresponding cursor pixel:
78 // AND XOR Result
79 // 0 0 White pixel
80 // 0 1 Black pixel
81 // 1 0 Screen color (for transparency)
82 // 1 1 Reverse screen color to black or white
84 uint8* fbCursor = (uint8*)((addr_t)si.videoMemAddr + si.cursorOffset);
86 for (int row = 0; row < height; row++) {
87 for (int colByte = 0; colByte < width / 8; colByte++) {
88 fbCursor[row * 16 + colByte] = *andMask++;
89 fbCursor[row * 16 + colByte + 8] = *xorMask++;
93 // Set the cursor colors which are white background and black foreground.
95 OUTREG(R128_CUR_CLR0, ~0);
96 OUTREG(R128_CUR_CLR1, 0);
98 return true;