revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / hidds / vmwaresvga / vmwaresvgabitmap_common.c
blobbbdccd91642b910b84750e0151e22f561efcea5c
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"
16 #include "vmwaresvgaclass.h"
18 #ifdef OnBitmap
19 /********* BitMap::Clear() *************************************/
20 VOID MNAME_BM(Clear)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_Clear *msg)
22 struct BitmapData *data = OOP_INST_DATA(cl, o);
23 IPTR width, height;
25 D(bug("[VMWareSVGA] Clear()\n"));
27 /* Get width & height from bitmap */
29 OOP_GetAttr(o, aHidd_BitMap_Width, &width);
30 OOP_GetAttr(o, aHidd_BitMap_Height, &height);
32 writeVMWareSVGAFIFO(data->data, SVGA_CMD_RECT_FILL);
33 writeVMWareSVGAFIFO(data->data, GC_FG(msg->gc));
34 writeVMWareSVGAFIFO(data->data, 0);
35 writeVMWareSVGAFIFO(data->data, 0);
36 writeVMWareSVGAFIFO(data->data, width);
37 writeVMWareSVGAFIFO(data->data, height);
38 syncVMWareSVGAFIFO(data->data);
40 #endif
42 #if 0
43 /* this function does not really make sense for LUT bitmaps */
45 HIDDT_Pixel MNAME_BM(MapColor)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_MapColor *msg)
47 D(bug("[VMWareSVGA] MapColor()\n"));
48 return i;
51 /* this function does not really make sense for LUT bitmaps */
53 VOID MNAME_BM(UnMapPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_UnmapPixel *msg)
55 D(bug("[VMWareSVGA] UnMapPixel()\n"));
58 #endif
60 BOOL MNAME_BM(SetColors)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg)
62 struct BitmapData *data = OOP_INST_DATA(cl, o);
63 HIDDT_PixelFormat *pf;
64 HIDDT_Pixel red;
65 HIDDT_Pixel green;
66 HIDDT_Pixel blue;
67 ULONG xc_i;
68 ULONG col_i;
70 pf = BM_PIXFMT(o);
71 if (
72 (vHidd_ColorModel_StaticPalette == HIDD_PF_COLMODEL(pf)) ||
73 (vHidd_ColorModel_TrueColor == HIDD_PF_COLMODEL(pf))
75 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
76 if (!OOP_DoSuperMethod(cl, o, (OOP_Msg)msg))
77 return FALSE;
78 if ((msg->firstColor + msg->numColors) > (1<<data->bpp))
79 return FALSE;
80 for (xc_i = msg->firstColor, col_i = 0; col_i < msg->numColors; xc_i++, col_i++)
82 red = msg->colors[col_i].red >> 8;
83 green = msg->colors[col_i].green >> 8;
84 blue = msg->colors[col_i].blue >> 8;
85 data->cmap[xc_i] = 0x01000000 | red | (green << 8) | (blue << 16);
86 #ifdef OnBitmap
87 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+0, msg->colors[col_i].red);
88 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+1, msg->colors[col_i].green);
89 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+2, msg->colors[col_i].blue);
90 #endif
91 msg->colors[col_i].pixval = xc_i;
93 return TRUE;
96 /********* BitMap::PutPixel() ***************************/
98 STATIC VOID putpixel(struct BitmapData *data, LONG x, LONG y, HIDDT_Pixel pixel)
100 ULONG offset;
102 #ifdef OnBitmap
103 offset = (x*data->bytesperpix)+(y*data->data->bytesperline);
104 #else
105 offset = (x + (y*data->width))*data->bytesperpix;
106 #endif
107 if (data->bytesperpix == 1)
108 *((UBYTE*)(data->VideoData + offset)) = pixel;
109 else if (data->bytesperpix == 2)
110 *((UWORD*)(data->VideoData + offset)) = pixel;
111 else if (data->bytesperpix == 4)
112 *((ULONG*)(data->VideoData + offset)) = pixel;
115 VOID MNAME_BM(PutPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg)
117 struct BitmapData *data = OOP_INST_DATA(cl, o);
118 #ifdef OnBitmap
119 struct Box box;
120 #endif
122 putpixel(data, msg->x, msg->y, msg->pixel);
123 #ifdef OnBitmap
124 box.x1 = box.x2 = msg->x;
125 box.y1 = box.y2 = msg->y;
126 refreshAreaVMWareSVGA(data->data, &box);
127 #endif
128 return;
131 /********* BitMap::GetPixel() *********************************/
132 HIDDT_Pixel MNAME_BM(GetPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetPixel *msg)
134 HIDDT_Pixel pixel = 0;
135 struct BitmapData *data = OOP_INST_DATA(cl, o);
136 ULONG offset;
138 #ifdef OnBitmap
139 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
140 #else
141 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
142 #endif
143 if (data->bytesperpix == 1)
144 pixel = *((UBYTE*)(data->VideoData + offset));
145 else if (data->bytesperpix == 2)
146 pixel = *((UWORD*)(data->VideoData + offset));
147 else if (data->bytesperpix == 4)
148 pixel = *((ULONG*)(data->VideoData + offset));
149 return pixel;
152 #if 0
154 /********* BitMap::DrawPixel() ***************************/
156 VOID MNAME_BM(DrawPixel)(OOP_Class *cl,OOP_ Object *o, struct pHidd_BitMap_DrawPixel *msg)
158 return;
161 #endif
163 /********* BitMap::PutImage() ***************************/
165 VOID MNAME_BM(PutImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImage *msg)
167 struct BitmapData *data = OOP_INST_DATA(cl, o);
168 #ifdef OnBitmap
169 struct Box box;
170 #endif
171 ULONG offset;
172 ULONG restadd;
173 UBYTE *buffer;
174 ULONG ycnt;
175 LONG xcnt;
176 UBYTE *src=(UBYTE *)msg->pixels;
178 if (msg->pixFmt == vHidd_StdPixFmt_Native32)
180 #ifdef OnBitmap
181 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
182 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
183 #else
184 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
185 restadd = (data->width-msg->width)*data->bytesperpix;
186 #endif
187 buffer = data->VideoData+offset;
188 ycnt = msg->height;
189 while (ycnt>0)
191 HIDDT_Pixel *p = (HIDDT_Pixel *)src;
192 xcnt = msg->width;
194 CopyMem(p, buffer, xcnt * data->bytesperpix);
196 buffer += (xcnt * data->bytesperpix);
197 buffer += restadd;
198 src += msg->modulo;
199 ycnt--;
201 #ifdef OnBitmap
202 box.x1 = msg->x;
203 box.y1 = msg->y;
204 box.x2 = box.x1+msg->width-1;
205 box.y2 = box.y1+msg->height-1;
206 VMWareSVGA_Damage_DeltaAdd(data->data, box);
207 #endif
209 else
211 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
215 /********* BitMap::GetImage() ***************************/
217 VOID MNAME_BM(GetImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImage *msg)
219 struct BitmapData *data = OOP_INST_DATA(cl, o);
220 ULONG offset;
221 ULONG restadd;
222 UBYTE *buffer;
223 ULONG ycnt;
224 LONG xcnt;
225 UBYTE *src=msg->pixels;
227 if (msg->pixFmt == vHidd_StdPixFmt_Native32)
229 #ifdef OnBitmap
230 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
231 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
232 #else
233 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
234 restadd = (data->width-msg->width)*data->bytesperpix;
235 #endif
236 buffer = data->VideoData+offset;
237 ycnt = msg->height;
238 while (ycnt>0)
240 HIDDT_Pixel *p = (HIDDT_Pixel *)src;
241 xcnt = msg->width;
243 CopyMem(buffer, p, xcnt * data->bytesperpix);
245 buffer += (xcnt * data->bytesperpix);
246 buffer += restadd;
247 src += msg->modulo;
248 ycnt--;
251 else
253 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
257 /********* BitMap::PutImageLUT() ***************************/
259 VOID MNAME_BM(PutImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImageLUT *msg)
261 struct BitmapData *data = OOP_INST_DATA(cl, o);
262 #ifdef OnBitmap
263 struct Box box;
264 #endif
265 ULONG offset;
266 ULONG restadd;
267 UBYTE *buffer;
268 ULONG ycnt;
269 LONG xcnt;
270 UBYTE *src=msg->pixels;
272 #ifdef OnBitmap
273 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
274 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
275 #else
276 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
277 restadd = (data->width-msg->width)*data->bytesperpix;
278 #endif
279 buffer = data->VideoData+offset;
280 ycnt = msg->height;
281 while (ycnt>0)
283 xcnt = msg->width;
284 while (xcnt)
286 if (data->bytesperpix == 1)
288 *((UBYTE *)buffer) = (UBYTE)msg->pixlut->pixels[*src++];
289 buffer++;
291 else if (data->bytesperpix == 2)
293 *((UWORD *)buffer) = (UWORD)msg->pixlut->pixels[*src++];
294 buffer += 2;
296 else if (data->bytesperpix == 4)
298 *((ULONG *)buffer) = (ULONG)msg->pixlut->pixels[*src++];
299 buffer += 4;
301 xcnt--;
303 buffer += restadd;
304 src += (msg->modulo - msg->width);
305 ycnt--;
307 #ifdef OnBitmap
308 box.x1 = msg->x;
309 box.y1 = msg->y;
310 box.x2 = box.x1+msg->width-1;
311 box.y2 = box.y1+msg->height-1;
312 refreshAreaVMWareSVGA(data->data, &box);
313 #endif
316 /********* BitMap::GetImageLUT() ***************************/
318 VOID MNAME_BM(GetImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImageLUT *msg)
320 D(bug("[VMWareSVGA] GetImageLUT()\n"));
321 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
324 /********* BitMap::FillRect() ***************************/
326 VOID MNAME_BM(FillRect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_DrawRect *msg)
328 #ifdef OnBitmap
329 struct BitmapData *data =OOP_INST_DATA(cl, o);
330 struct HWData *hw;
331 HIDDT_Pixel pixel;
332 HIDDT_DrawMode mode;
334 pixel = GC_FG(msg->gc);
335 mode = GC_DRMD(msg->gc);
336 hw = data->data;
337 if (hw->capabilities & SVGA_CAP_RASTER_OP)
339 switch (mode)
341 case vHidd_GC_DrawMode_Clear:
342 clearFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
343 break;
344 case vHidd_GC_DrawMode_And:
345 andFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
346 break;
347 case vHidd_GC_DrawMode_AndReverse:
348 andReverseFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
349 break;
350 case vHidd_GC_DrawMode_Copy:
351 copyFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
352 break;
353 case vHidd_GC_DrawMode_AndInverted:
354 andInvertedFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
355 break;
356 case vHidd_GC_DrawMode_NoOp:
357 noOpFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
358 break;
359 case vHidd_GC_DrawMode_Xor:
360 xorFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
361 break;
362 case vHidd_GC_DrawMode_Or:
363 orFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
364 break;
365 case vHidd_GC_DrawMode_Nor:
366 norFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
367 break;
368 case vHidd_GC_DrawMode_Equiv:
369 equivFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
370 break;
371 case vHidd_GC_DrawMode_Invert:
372 invertFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
373 break;
374 case vHidd_GC_DrawMode_OrReverse:
375 orReverseFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
376 break;
377 case vHidd_GC_DrawMode_CopyInverted:
378 copyInvertedFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
379 break;
380 case vHidd_GC_DrawMode_OrInverted:
381 orInvertedFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
382 break;
383 case vHidd_GC_DrawMode_Nand:
384 nandFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
385 break;
386 case vHidd_GC_DrawMode_Set:
387 setFillVMWareSVGA(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
388 break;
389 default:
390 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
391 break;
394 else
396 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
398 #else
399 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
400 #endif
403 /*** BitMap::BlitColorExpansion() **********************************************/
404 VOID MNAME_BM(BlitColorExpansion)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_BlitColorExpansion *msg)
406 struct BitmapData *data = OOP_INST_DATA(cl, o);
407 #ifdef OnBitmap
408 struct Box box;
409 #endif
410 ULONG cemd;
411 HIDDT_Pixel fg;
412 HIDDT_Pixel bg;
413 LONG x;
414 LONG y;
416 fg = GC_FG(msg->gc);
417 bg = GC_BG(msg->gc);
418 cemd = GC_COLEXP(msg->gc);
419 if (cemd & vHidd_GC_ColExp_Opaque)
421 for (y=0; y<msg->height; y++)
423 for (x=0;x<msg->width;x++)
425 ULONG is_set;
426 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x+msg->srcX, y+msg->srcY);
427 putpixel(data, x+msg->destX, y+msg->destY, is_set ? fg : bg);
431 else
433 for (y=0; y<msg->height; y++)
435 for (x=0;x<msg->width; x++)
437 if (HIDD_BM_GetPixel(msg->srcBitMap, x+msg->srcX, y+msg->srcY))
438 putpixel(data, x+msg->destX, y+msg->destY, fg);
442 #ifdef OnBitmap
443 box.x1 = msg->destX;
444 box.y1 = msg->destY;
445 box.x2 = msg->destX+msg->width-1;
446 box.y2 = msg->destY+msg->height-1;
447 refreshAreaVMWareSVGA(data->data, &box);
448 #endif
451 /*** BitMap::Get() *******************************************/
453 VOID MNAME_ROOT(Get)(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
455 struct BitmapData *data = OOP_INST_DATA(cl, o);
456 ULONG idx;
458 if (IS_VMWareSVGABM_ATTR(msg->attrID, idx))
460 switch (idx)
462 case aoHidd_VMWareSVGABitMap_Drawable:
463 *msg->storage = (IPTR)data->VideoData;
464 break;
465 default:
466 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
469 else
471 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
475 VOID MNAME_BM(UpdateRect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_UpdateRect *msg)
477 struct HWData *pData = &XSD(cl)->data;
478 struct Box box = { msg->x, msg->y, msg->x + msg->width + 1, msg->y + msg->height + 1};
480 VMWareSVGA_Damage_DeltaAdd(pData, box);