Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / common / hidd.vmwaresvga / vmwaresvgabitmap_common.c
blobcf0df04863f38c0164f1a1f28771b9e1f293c4cb
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English.
7 */
9 #define DEBUG 0
10 #include <aros/debug.h>
12 #include <exec/alerts.h>
13 #include <string.h> // memset() prototype
14 #include "svga_reg.h"
15 #include "vmwaresvgahardware.h"
17 #ifdef OnBitmap
18 /********* BitMap::Clear() *************************************/
19 VOID MNAME_BM(Clear)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_Clear *msg)
21 struct BitmapData *data = OOP_INST_DATA(cl, o);
22 ULONG width, height;
24 D(bug("[VMWareSVGA] Clear()\n"));
26 /* Get width & height from bitmap */
28 OOP_GetAttr(o, aHidd_BitMap_Width, &width);
29 OOP_GetAttr(o, aHidd_BitMap_Height, &height);
31 writeVMWareSVGAFIFO(data->data, SVGA_CMD_RECT_FILL);
32 writeVMWareSVGAFIFO(data->data, GC_FG(msg->gc));
33 writeVMWareSVGAFIFO(data->data, 0);
34 writeVMWareSVGAFIFO(data->data, 0);
35 writeVMWareSVGAFIFO(data->data, width);
36 writeVMWareSVGAFIFO(data->data, height);
37 syncVMWareSVGAFIFO(data);
39 #endif
41 #if 0
42 /* this function does not really make sense for LUT bitmaps */
44 HIDDT_Pixel MNAME_BM(MapColor)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_MapColor *msg)
46 D(bug("[VMWareSVGA] MapColor()\n"));
47 return i;
50 /* this function does not really make sense for LUT bitmaps */
52 VOID MNAME_BM(UnMapPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_UnmapPixel *msg)
54 D(bug("[VMWareSVGA] UnMapPixel()\n"));
57 #endif
59 BOOL MNAME_BM(SetColors)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg)
61 struct BitmapData *data = OOP_INST_DATA(cl, o);
62 HIDDT_PixelFormat *pf;
63 HIDDT_Pixel red;
64 HIDDT_Pixel green;
65 HIDDT_Pixel blue;
66 ULONG xc_i;
67 ULONG col_i;
69 pf = BM_PIXFMT(o);
70 if (
71 (vHidd_ColorModel_StaticPalette == HIDD_PF_COLMODEL(pf)) ||
72 (vHidd_ColorModel_TrueColor == HIDD_PF_COLMODEL(pf))
74 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
75 if (!OOP_DoSuperMethod(cl, o, (OOP_Msg)msg))
76 return FALSE;
77 if ((msg->firstColor + msg->numColors) > (1<<data->bpp))
78 return FALSE;
79 for (xc_i = msg->firstColor, col_i = 0; col_i < msg->numColors; xc_i++, col_i++)
81 red = msg->colors[col_i].red >> 8;
82 green = msg->colors[col_i].green >> 8;
83 blue = msg->colors[col_i].blue >> 8;
84 data->cmap[xc_i] = 0x01000000 | red | (green << 8) | (blue << 16);
85 #ifdef OnBitmap
86 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+0, msg->colors[col_i].red);
87 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+1, msg->colors[col_i].green);
88 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+2, msg->colors[col_i].blue);
89 #endif
90 msg->colors[col_i].pixval = xc_i;
92 return TRUE;
95 /********* BitMap::PutPixel() ***************************/
97 STATIC VOID putpixel(struct BitmapData *data, LONG x, LONG y, HIDDT_Pixel pixel)
99 ULONG offset;
101 #ifdef OnBitmap
102 offset = (x*data->bytesperpix)+(y*data->data->bytesperline);
103 if (
104 (x>=data->mouse->x) && (x<(data->mouse->x+data->mouse->width)) &&
105 (y>=data->mouse->y) && (y<(data->mouse->y+data->mouse->height))
108 displayCursorVMWareSVGA(data->data, 0);
109 data->mouse->visible = 0;
111 #else
112 offset = (x + (y*data->width))*data->bytesperpix;
113 #endif
114 if (data->bytesperpix == 1)
115 *((UBYTE*)(data->VideoData + offset)) = pixel;
116 else if (data->bytesperpix == 2)
117 *((UWORD*)(data->VideoData + offset)) = pixel;
118 else if (data->bytesperpix == 4)
119 *((ULONG*)(data->VideoData + offset)) = pixel;
120 #ifdef OnBitmap
121 if (data->mouse->visible == 0)
123 displayCursorVMWareSVGA(data->data, 1);
124 data->mouse->visible = 1;
126 #endif
129 VOID MNAME_BM(PutPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg)
131 struct BitmapData *data = OOP_INST_DATA(cl, o);
132 struct Box box;
134 putpixel(data, msg->x, msg->y, msg->pixel);
135 #ifdef OnBitmap
136 box.x1 = box.x2 = msg->x;
137 box.y1 = box.y2 = msg->y;
138 refreshAreaVMWareSVGA(data->data, &box);
139 #endif
140 return;
143 /********* BitMap::GetPixel() *********************************/
144 HIDDT_Pixel MNAME_BM(GetPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetPixel *msg)
146 HIDDT_Pixel pixel;
147 struct BitmapData *data = OOP_INST_DATA(cl, o);
148 ULONG offset;
150 #ifdef OnBitmap
151 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
152 #else
153 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
154 #endif
155 if (data->bytesperpix == 1)
156 pixel = *((UBYTE*)(data->VideoData + offset));
157 else if (data->bytesperpix == 2)
158 pixel = *((UWORD*)(data->VideoData + offset));
159 else if (data->bytesperpix == 4)
160 pixel = *((ULONG*)(data->VideoData + offset));
161 return pixel;
164 #if 0
166 /********* BitMap::DrawPixel() ***************************/
168 VOID MNAME_BM(DrawPixel)(OOP_Class *cl,OOP_ Object *o, struct pHidd_BitMap_DrawPixel *msg)
170 return;
173 #endif
175 /********* BitMap::PutImage() ***************************/
177 VOID MNAME_BM(PutImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImage *msg)
179 struct BitmapData *data = OOP_INST_DATA(cl, o);
180 struct Box box;
181 ULONG offset;
182 ULONG restadd;
183 UBYTE *buffer;
184 ULONG ycnt;
185 LONG xcnt;
186 UBYTE *src=(UBYTE *)msg->pixels;
188 if (msg->pixFmt == vHidd_StdPixFmt_Native32)
190 #ifdef OnBitmap
191 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
192 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
193 #else
194 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
195 restadd = (data->width-msg->width)*data->bytesperpix;
196 #endif
197 buffer = data->VideoData+offset;
198 ycnt = msg->height;
199 while (ycnt>0)
201 HIDDT_Pixel *p = (HIDDT_Pixel *)src;
202 xcnt = msg->width;
203 while (xcnt)
205 if (data->bytesperpix == 1)
207 *((UBYTE *)buffer) = (UBYTE)*p++;
208 buffer++;
210 else if (data->bytesperpix == 2)
212 *((UWORD *)buffer) = (UWORD)*p++;
213 buffer += 2;
215 else if (data->bytesperpix == 4)
217 *((ULONG *)buffer) = (ULONG)*p++;
218 buffer += 4;
220 xcnt--;
222 buffer += restadd;
223 src += msg->modulo;
224 ycnt--;
226 #ifdef OnBitmap
227 box.x1 = msg->x;
228 box.y1 = msg->y;
229 box.x2 = box.x1+msg->width-1;
230 box.y2 = box.y1+msg->height-1;
231 refreshAreaVMWareSVGA(data->data, &box);
232 #endif
234 else
236 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
240 /********* BitMap::GetImage() ***************************/
242 VOID MNAME_BM(GetImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImage *msg)
244 struct BitmapData *data = OOP_INST_DATA(cl, o);
245 ULONG offset;
246 ULONG restadd;
247 UBYTE *buffer;
248 ULONG ycnt;
249 LONG xcnt;
250 UBYTE *src=msg->pixels;
252 if (msg->pixFmt == vHidd_StdPixFmt_Native32)
254 #ifdef OnBitmap
255 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
256 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
257 #else
258 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
259 restadd = (data->width-msg->width)*data->bytesperpix;
260 #endif
261 buffer = data->VideoData+offset;
262 ycnt = msg->height;
263 while (ycnt>0)
265 HIDDT_Pixel *p = (HIDDT_Pixel *)src;
266 xcnt = msg->width;
267 while (xcnt)
269 if (data->bytesperpix == 1)
271 *p++ = (HIDDT_Pixel)*((UBYTE *)buffer);
272 buffer++;
274 else if (data->bytesperpix == 2)
276 *p++ = (HIDDT_Pixel)*((UWORD *)buffer);
277 buffer += 2;
279 else if (data->bytesperpix == 4)
281 *p++ = (HIDDT_Pixel)*((ULONG *)buffer);
282 buffer += 4;
284 xcnt--;
286 buffer += restadd;
287 src += msg->modulo;
288 ycnt--;
291 else
293 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
297 /********* BitMap::PutImageLUT() ***************************/
299 VOID MNAME_BM(PutImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImageLUT *msg)
301 struct BitmapData *data = OOP_INST_DATA(cl, o);
302 struct Box box;
303 ULONG offset;
304 ULONG restadd;
305 UBYTE *buffer;
306 ULONG ycnt;
307 LONG xcnt;
308 UBYTE *src=msg->pixels;
310 #ifdef OnBitmap
311 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
312 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
313 #else
314 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
315 restadd = (data->width-msg->width)*data->bytesperpix;
316 #endif
317 buffer = data->VideoData+offset;
318 ycnt = msg->height;
319 while (ycnt>0)
321 xcnt = msg->width;
322 while (xcnt)
324 if (data->bytesperpix == 1)
326 *((UBYTE *)buffer) = (UBYTE)msg->pixlut->pixels[*src++];
327 buffer++;
329 else if (data->bytesperpix == 2)
331 *((UWORD *)buffer) = (UWORD)msg->pixlut->pixels[*src++];
332 buffer += 2;
334 else if (data->bytesperpix == 4)
336 *((ULONG *)buffer) = (ULONG)msg->pixlut->pixels[*src++];
337 buffer += 4;
339 xcnt--;
341 buffer += restadd;
342 src += (msg->modulo - msg->width);
343 ycnt--;
345 #ifdef OnBitmap
346 box.x1 = msg->x;
347 box.y1 = msg->y;
348 box.x2 = box.x1+msg->width-1;
349 box.y2 = box.y1+msg->height-1;
350 refreshAreaVMWareSVGA(data->data, &box);
351 #endif
354 /********* BitMap::GetImageLUT() ***************************/
356 VOID MNAME_BM(GetImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImageLUT *msg)
358 D(bug("[VMWareSVGA] GetImageLUT()\n"));
359 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
362 /********* BitMap::FillRect() ***************************/
364 VOID MNAME_BM(FillRect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_DrawRect *msg)
366 struct BitmapData *data =OOP_INST_DATA(cl, o);
367 struct HWData *hw;
368 HIDDT_Pixel pixel;
369 HIDDT_DrawMode mode;
371 #ifdef OnBitmap
372 pixel = GC_FG(msg->gc);
373 mode = GC_DRMD(msg->gc);
374 hw = data->data;
375 if (hw->capabilities & SVGA_CAP_RASTER_OP)
377 switch (mode)
379 case vHidd_GC_DrawMode_Clear:
380 clearFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
381 break;
382 case vHidd_GC_DrawMode_And:
383 andFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
384 break;
385 case vHidd_GC_DrawMode_AndReverse:
386 andReverseFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
387 break;
388 case vHidd_GC_DrawMode_Copy:
389 copyFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
390 break;
391 case vHidd_GC_DrawMode_AndInverted:
392 andInvertedFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
393 break;
394 case vHidd_GC_DrawMode_NoOp:
395 noOpFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
396 break;
397 case vHidd_GC_DrawMode_Xor:
398 xorFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
399 break;
400 case vHidd_GC_DrawMode_Or:
401 orFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
402 break;
403 case vHidd_GC_DrawMode_Nor:
404 norFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
405 break;
406 case vHidd_GC_DrawMode_Equiv:
407 equivFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
408 break;
409 case vHidd_GC_DrawMode_Invert:
410 invertFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
411 break;
412 case vHidd_GC_DrawMode_OrReverse:
413 orReverseFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
414 break;
415 case vHidd_GC_DrawMode_CopyInverted:
416 copyInvertedFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
417 break;
418 case vHidd_GC_DrawMode_OrInverted:
419 orInvertedFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
420 break;
421 case vHidd_GC_DrawMode_Nand:
422 nandFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
423 break;
424 case vHidd_GC_DrawMode_Set:
425 setFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
426 break;
427 default:
428 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
429 break;
432 else
434 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
436 #else
437 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
438 #endif
441 /*** BitMap::BlitColorExpansion() **********************************************/
442 VOID MNAME_BM(BlitColorExpansion)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_BlitColorExpansion *msg)
444 struct BitmapData *data = OOP_INST_DATA(cl, o);
445 struct Box box;
446 ULONG cemd;
447 HIDDT_Pixel fg;
448 HIDDT_Pixel bg;
449 LONG x;
450 LONG y;
452 fg = GC_FG(msg->gc);
453 bg = GC_BG(msg->gc);
454 cemd = GC_COLEXP(msg->gc);
455 if (cemd & vHidd_GC_ColExp_Opaque)
457 for (y=0; y<msg->height; y++)
459 for (x=0;x<msg->width;x++)
461 ULONG is_set;
462 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x+msg->srcX, y+msg->srcY);
463 putpixel(data, x+msg->destX, y+msg->destY, is_set ? fg : bg);
467 else
469 for (y=0; y<msg->height; y++)
471 for (x=0;x<msg->width; x++)
473 if (HIDD_BM_GetPixel(msg->srcBitMap, x+msg->srcX, y+msg->srcY))
474 putpixel(data, x+msg->destX, y+msg->destY, fg);
478 #ifdef OnBitmap
479 box.x1 = msg->destX;
480 box.y1 = msg->destY;
481 box.x2 = msg->destX+msg->width-1;
482 box.y2 = msg->destY+msg->height-1;
483 refreshAreaVMWareSVGA(data->data, &box);
484 #endif
487 /*** BitMap::Get() *******************************************/
489 VOID MNAME_ROOT(Get)(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
491 struct BitmapData *data = OOP_INST_DATA(cl, o);
492 ULONG idx;
494 if (IS_VMWareSVGABM_ATTR(msg->attrID, idx))
496 switch (idx)
498 case aoHidd_VMWareSVGABitMap_Drawable:
499 *msg->storage = (ULONG)data->VideoData;
500 break;
501 default:
502 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
505 else
507 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);