2 Copyright � 1995-2006, The AROS Development Team. All rights reserved.
10 #include <aros/debug.h>
12 #include <exec/alerts.h>
13 #include <string.h> // memset() prototype
15 #include "vmwaresvgahardware.h"
16 #include "vmwaresvgaclass.h"
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
);
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
);
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"));
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"));
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
;
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
))
78 if ((msg
->firstColor
+ msg
->numColors
) > (1<<data
->bpp
))
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);
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
);
91 msg
->colors
[col_i
].pixval
= xc_i
;
96 /********* BitMap::PutPixel() ***************************/
98 STATIC VOID
putpixel(struct BitmapData
*data
, LONG x
, LONG y
, HIDDT_Pixel pixel
)
103 offset
= (x
*data
->bytesperpix
)+(y
*data
->data
->bytesperline
);
105 offset
= (x
+ (y
*data
->width
))*data
->bytesperpix
;
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
);
122 putpixel(data
, msg
->x
, msg
->y
, msg
->pixel
);
124 box
.x1
= box
.x2
= msg
->x
;
125 box
.y1
= box
.y2
= msg
->y
;
126 refreshAreaVMWareSVGA(data
->data
, &box
);
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
);
139 offset
= (msg
->x
*data
->bytesperpix
)+(msg
->y
*data
->data
->bytesperline
);
141 offset
= (msg
->x
+ (msg
->y
*data
->width
))*data
->bytesperpix
;
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
));
154 /********* BitMap::DrawPixel() ***************************/
156 VOID
MNAME_BM(DrawPixel
)(OOP_Class
*cl
,OOP_ Object
*o
, struct pHidd_BitMap_DrawPixel
*msg
)
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
);
176 UBYTE
*src
=(UBYTE
*)msg
->pixels
;
178 if (msg
->pixFmt
== vHidd_StdPixFmt_Native32
)
181 offset
= (msg
->x
*data
->bytesperpix
)+(msg
->y
*data
->data
->bytesperline
);
182 restadd
= (data
->data
->bytesperline
- (msg
->width
*data
->bytesperpix
));
184 offset
= (msg
->x
+ (msg
->y
*data
->width
))*data
->bytesperpix
;
185 restadd
= (data
->width
-msg
->width
)*data
->bytesperpix
;
187 buffer
= data
->VideoData
+offset
;
191 HIDDT_Pixel
*p
= (HIDDT_Pixel
*)src
;
194 CopyMem(p
, buffer
, xcnt
* data
->bytesperpix
);
196 buffer
+= (xcnt
* data
->bytesperpix
);
204 box
.x2
= box
.x1
+msg
->width
-1;
205 box
.y2
= box
.y1
+msg
->height
-1;
206 VMWareSVGA_Damage_DeltaAdd(data
->data
, box
);
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
);
225 UBYTE
*src
=msg
->pixels
;
227 if (msg
->pixFmt
== vHidd_StdPixFmt_Native32
)
230 offset
= (msg
->x
*data
->bytesperpix
)+(msg
->y
*data
->data
->bytesperline
);
231 restadd
= (data
->data
->bytesperline
- (msg
->width
*data
->bytesperpix
));
233 offset
= (msg
->x
+ (msg
->y
*data
->width
))*data
->bytesperpix
;
234 restadd
= (data
->width
-msg
->width
)*data
->bytesperpix
;
236 buffer
= data
->VideoData
+offset
;
240 HIDDT_Pixel
*p
= (HIDDT_Pixel
*)src
;
243 CopyMem(buffer
, p
, xcnt
* data
->bytesperpix
);
245 buffer
+= (xcnt
* data
->bytesperpix
);
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
);
270 UBYTE
*src
=msg
->pixels
;
273 offset
= (msg
->x
*data
->bytesperpix
)+(msg
->y
*data
->data
->bytesperline
);
274 restadd
= (data
->data
->bytesperline
- (msg
->width
*data
->bytesperpix
));
276 offset
= (msg
->x
+ (msg
->y
*data
->width
))*data
->bytesperpix
;
277 restadd
= (data
->width
-msg
->width
)*data
->bytesperpix
;
279 buffer
= data
->VideoData
+offset
;
286 if (data
->bytesperpix
== 1)
288 *((UBYTE
*)buffer
) = (UBYTE
)msg
->pixlut
->pixels
[*src
++];
291 else if (data
->bytesperpix
== 2)
293 *((UWORD
*)buffer
) = (UWORD
)msg
->pixlut
->pixels
[*src
++];
296 else if (data
->bytesperpix
== 4)
298 *((ULONG
*)buffer
) = (ULONG
)msg
->pixlut
->pixels
[*src
++];
304 src
+= (msg
->modulo
- msg
->width
);
310 box
.x2
= box
.x1
+msg
->width
-1;
311 box
.y2
= box
.y1
+msg
->height
-1;
312 refreshAreaVMWareSVGA(data
->data
, &box
);
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
)
329 struct BitmapData
*data
=OOP_INST_DATA(cl
, o
);
334 pixel
= GC_FG(msg
->gc
);
335 mode
= GC_DRMD(msg
->gc
);
337 if (hw
->capabilities
& SVGA_CAP_RASTER_OP
)
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
390 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
396 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
399 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
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
);
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
++)
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
);
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
);
445 box
.x2
= msg
->destX
+msg
->width
-1;
446 box
.y2
= msg
->destY
+msg
->height
-1;
447 refreshAreaVMWareSVGA(data
->data
, &box
);
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
);
458 if (IS_VMWareSVGABM_ATTR(msg
->attrID
, idx
))
462 case aoHidd_VMWareSVGABitMap_Drawable
:
463 *msg
->storage
= (IPTR
)data
->VideoData
;
466 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
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
);