2 * sdl.hidd - SDL graphics/sound/keyboard for AROS hosted
3 * Copyright (c) 2007 Robert Norris. All rights reserved.
4 * Copyright (c) 2010 The AROS Development Team. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
10 #include <hidd/hidd.h>
11 #include <hidd/graphics.h>
12 #include <utility/tagitem.h>
15 #include <proto/exec.h>
16 #include <proto/oop.h>
17 #include <proto/utility.h>
26 #include "sdl_intern.h"
29 #include <aros/debug.h>
37 if (SDL_MUSTLOCK(s)) \
38 SV(SDL_LockSurface, s); \
43 if (SDL_MUSTLOCK(s)) \
44 SV(SDL_UnlockSurface, s); \
47 #define LIBBASE (&xsd)
50 static void load_icon(LIBBASETYPEPTR SDLGfxBase
) {
51 unsigned char *data
, *pixel
;
58 if ((SDLGfxBase
->icon
= SP(SDL_CreateRGBSurface
, SDL_SWSURFACE
, icon_width
, icon_height
, 24, icon_red_mask
, icon_green_mask
, icon_blue_mask
, 0)) != NULL
)
60 LOCK(SDLGfxBase
->icon
);
62 data
= icon_header_data
;
63 pixel
= SDLGfxBase
->icon
->pixels
;
65 for (i
= 0; i
< icon_width
* icon_height
; i
++) {
66 ICON_HEADER_PIXEL(data
, pixel
);
70 UNLOCK(SDLGfxBase
->icon
);
74 #define SDLGfxBase ((LIBBASETYPEPTR) cl->UserData)
76 OOP_Object
*SDLBitMap__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
) {
77 struct bmdata
*bmdata
;
79 IPTR width
, height
, depth
;
82 IPTR red_mask
, green_mask
, blue_mask
, alpha_mask
;
84 D(bug("[sdl] SDLBitMap::New\n"));
86 o
= (OOP_Object
*) OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
88 D(bug("[sdl] supermethod failed, bailing out\n"));
92 bmdata
= OOP_INST_DATA(cl
, o
);
94 OOP_GetAttr(o
, aHidd_BitMap_Width
, &width
);
95 OOP_GetAttr(o
, aHidd_BitMap_Height
, &height
);
96 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (IPTR
*)&pixfmt
);
98 OOP_GetAttr(pixfmt
, aHidd_PixFmt_Depth
, &depth
);
100 D(bug("[sdl] width %d height %d depth %d\n", width
, height
, depth
));
102 framebuffer
= GetTagData(aHidd_BitMap_FrameBuffer
, FALSE
, msg
->attrList
);
104 D(bug("[sdl] creating new framebuffer\n"));
106 /* XXX we should free any existing onscreen surface. the problem is
107 * that we can't dispose the existing framebuffer object because the
108 * caller may still have a handle on it. we could fiddle at its
109 * innards well enough (store the current onscreen bitmap in class
110 * static data, and now grab it and free its surface), but then we
111 * have a bitmap with no associated surface, so we need checks for
114 * I expect that if the caller wants to make a new framebuffer, it
115 * should have to free the old one
118 if (!LIBBASE
->use_hwsurface
)
119 D(bug("[sdl] hardware surface not available, using software surface instead\n"));
121 if (LIBBASE
->icon
== NULL
) {
122 D(bug("[sdl] loading window icon\n"));
123 load_icon((LIBBASETYPEPTR
) cl
->UserData
);
127 SV(SDL_WM_SetIcon
, LIBBASE
->icon
, NULL
);
129 s
= SP(SDL_SetVideoMode
, width
, height
, depth
,
130 (LIBBASE
->use_hwsurface
? SDL_HWSURFACE
| SDL_HWPALETTE
: SDL_SWSURFACE
) |
131 (LIBBASE
->use_fullscreen
? SDL_FULLSCREEN
: 0) |
134 SV(SDL_WM_SetCaption
, "AROS Research Operating System", "AROS");
138 OOP_GetAttr(pixfmt
, aHidd_PixFmt_RedMask
, &red_mask
);
139 OOP_GetAttr(pixfmt
, aHidd_PixFmt_GreenMask
, &green_mask
);
140 OOP_GetAttr(pixfmt
, aHidd_PixFmt_BlueMask
, &blue_mask
);
141 OOP_GetAttr(pixfmt
, aHidd_PixFmt_AlphaMask
, &alpha_mask
);
143 D(bug("[sdl] creating new offscreen surface; masks: red 0x%08x green 0x%08x blue 0x%08x alpha 0x%08x\n", red_mask
, green_mask
, blue_mask
, alpha_mask
));
145 s
= SP(SDL_CreateRGBSurface
, SDL_SWSURFACE
, width
, height
, depth
, red_mask
, green_mask
, blue_mask
, alpha_mask
);
149 OOP_MethodID dispose
;
151 D(bug("[sdl] failed to create surface: %s\n", S(SDL_GetError
, )));
153 dispose
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
154 OOP_CoerceMethod(cl
, o
, (OOP_Msg
) &dispose
);
162 bmdata
->is_onscreen
= TRUE
;
164 D(bug("[sdl] created surface: 0x%08x\n", s
));
169 VOID
SDLBitMap__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
) {
170 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
172 D(bug("[sdl] SDLBitMap::Dispose\n"));
174 if (bmdata
->surface
!= NULL
) {
175 D(bug("[sdl] destroying surface 0x%08x\n", bmdata
->surface
));
177 SV(SDL_FreeSurface
, bmdata
->surface
);
178 bmdata
->surface
= NULL
;
181 OOP_DoSuperMethod(cl
, o
, msg
);
186 VOID
SDLBitMap__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
) {
187 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
189 // D(bug("[sdl] SDLBitMap::Get\n"));
191 switch (SDLBM_ATTR(msg
->attrID
)) {
192 case aoHidd_SDLBitMap_Surface
:
193 *msg
->storage
= (IPTR
) bmdata
->surface
;
197 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
202 VOID
SDLBitMap__Root__Set(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Set
*msg
)
204 struct bmdata
*data
= OOP_INST_DATA(cl
, o
);
205 struct TagItem
*tag
, *tstate
;
208 tstate
= msg
->attrList
;
209 while((tag
= NextTagItem(&tstate
))) {
210 idx
= SDLBM_ATTR(tag
->ti_Tag
);
211 if (idx
< num_Hidd_SDLBitMap_Attrs
) {
213 case aoHidd_SDLBitMap_Surface
:
214 data
->surface
= (SDL_Surface
*)tag
->ti_Data
;
220 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
223 BOOL
SDLBitMap__Hidd_BitMap__SetColors(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_SetColors
*msg
) {
224 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
225 HIDDT_PixelFormat
*pixfmt
;
229 //D(bug("[sdl] SDLBitMap::SetColors\n"));
231 pixfmt
= BM_PIXFMT(o
);
232 if (HIDD_PF_COLMODEL(pixfmt
) == vHidd_ColorModel_StaticPalette
||
233 HIDD_PF_COLMODEL(pixfmt
) == vHidd_ColorModel_TrueColor
) {
235 return OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
238 if (!OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
))
241 colors
= AllocVec(sizeof(SDL_Color
) * msg
->numColors
, MEMF_CLEAR
);
243 for (i
= 0; i
< msg
->numColors
; i
++) {
244 colors
[i
].r
= msg
->colors
[i
].red
;
245 colors
[i
].g
= msg
->colors
[i
].green
;
246 colors
[i
].b
= msg
->colors
[i
].blue
;
249 S(SDL_SetColors
, bmdata
->surface
, colors
, msg
->firstColor
, msg
->numColors
);
251 D(bug("[sdl] set %d colours for surface 0x%08x\n", msg
->numColors
, bmdata
->surface
));
256 #define PUTPIXEL8(p,c) (* (Uint8 *) (p) = (c))
257 #define GETPIXEL8(p) (* (Uint8 *) (p))
259 #define PUTPIXEL16(p,c) (* (Uint16 *) (p)) = (c)
260 #define GETPIXEL16(p) (* (Uint16 *) (p))
262 #define PUTPIXEL32(p,c) (* (Uint32 *) (p)) = (c)
263 #define GETPIXEL32(p) (* (Uint32 *) (p))
265 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
266 #define PUTPIXEL24(p,c) \
268 ((Uint8 *) p)[0] = ((c) >> 16) & 0xff; \
269 ((Uint8 *) p)[1] = ((c) >> 8) & 0xff; \
270 ((Uint8 *) p)[2] = (c) & 0xff; \
272 #define GETPIXEL24(p) (((Uint8 *) p)[0] << 16 | ((Uint8 *) p)[1] << 8 | ((Uint8 *)p)[2])
274 #define PUTPIXEL24(p,c) \
276 ((Uint8 *) p)[0] = (c) & 0xff; \
277 ((Uint8 *) p)[1] = ((c) >> 8) & 0xff; \
278 ((Uint8 *) p)[2] = ((c) >> 16) & 0xff; \
280 #define GETPIXEL24(p) (((Uint8 *) p)[0] | ((Uint8 *) p)[1] << 8 | ((Uint8 *) p)[2] << 16)
283 VOID
SDLBitMap__Hidd_BitMap__PutPixel(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutPixel
*msg
) {
284 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
285 int bytesperpixel
= bmdata
->surface
->format
->BytesPerPixel
;
286 Uint8
*p
= (Uint8
*) bmdata
->surface
->pixels
+ msg
->y
* bmdata
->surface
->pitch
+ msg
->x
* bytesperpixel
;
287 Uint32 c
= msg
->pixel
;
289 //D(bug("[sdl] SDLBitMap::PutPixel\n"));
290 //D(bug("[sdl] x %d y %d colour 0x%08x bytesperpixel %d\n", msg->x, msg->y, c, bytesperpixel));
292 LOCK(bmdata
->surface
);
294 switch (bytesperpixel
) {
312 UNLOCK(bmdata
->surface
);
315 HIDDT_Pixel
SDLBitMap__Hidd_BitMap__GetPixel(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetPixel
*msg
) {
316 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
317 int bytesperpixel
= bmdata
->surface
->format
->BytesPerPixel
;
318 Uint8
*p
= (Uint8
*) bmdata
->surface
->pixels
+ msg
->y
* bmdata
->surface
->pitch
+ msg
->x
* bytesperpixel
;
321 //D(bug("[sdl] SDLBitMap::GetPixel\n"));
322 //D(bug("[sdl] x %d y %d bytesperpixel %d\n", msg->x, msg->y, bytesperpixel));
324 LOCK(bmdata
->surface
);
326 switch(bytesperpixel
) {
345 UNLOCK(bmdata
->surface
);
347 //D(bug("[sdl] returning pixel 0x%08x\n", c));
349 return (HIDDT_Pixel
) c
;
352 VOID
SDLBitMap__Hidd_BitMap__UpdateRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_UpdateRect
*msg
) {
353 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
355 D(bug("[sdl] SDLBitMap::UpdateRect\n"));
356 D(bug("[sdl] Updating region (%d,%d) [%d,%d]\n", msg
->x
, msg
->y
, msg
->width
, msg
->height
));
358 if (bmdata
->is_onscreen
)
359 SV(SDL_UpdateRect
, bmdata
->surface
, msg
->x
, msg
->y
, msg
->width
, msg
->height
);
362 VOID
SDLBitMap__Hidd_BitMap__PutImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImage
*msg
) {
363 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
365 IPTR red_mask
, green_mask
, blue_mask
, alpha_mask
;
366 BOOL native32
= FALSE
;
368 SDL_Rect srect
, drect
;
370 DPUTIMAGE(bug("[sdl] SDLBitMap::PutImage\n"));
372 switch (msg
->pixFmt
) {
373 case vHidd_StdPixFmt_Native32
:
374 DPUTIMAGE(bug("[sdl] native32 format, making a note to ensure 4-byte pixels later\n"));
377 case vHidd_StdPixFmt_Native
:
378 DPUTIMAGE(bug("[sdl] native format, using our attributes\n"));
380 depth
= bmdata
->surface
->format
->BitsPerPixel
;
381 red_mask
= bmdata
->surface
->format
->Rmask
;
382 green_mask
= bmdata
->surface
->format
->Gmask
;
383 blue_mask
= bmdata
->surface
->format
->Bmask
;
384 alpha_mask
= bmdata
->surface
->format
->Amask
;
389 DPUTIMAGE(bug("[sdl] pixel format %d, asking the gfxhidd for attributes\n", msg
->pixFmt
));
392 OOP_GetAttr(o
, aHidd_BitMap_GfxHidd
, (IPTR
*)&gfxhidd
);
394 OOP_Object
*pixfmt
= HIDD_Gfx_GetPixFmt(gfxhidd
, msg
->pixFmt
);
396 OOP_GetAttr(pixfmt
, aHidd_PixFmt_Depth
, &depth
);
397 OOP_GetAttr(pixfmt
, aHidd_PixFmt_RedMask
, &red_mask
);
398 OOP_GetAttr(pixfmt
, aHidd_PixFmt_GreenMask
, &green_mask
);
399 OOP_GetAttr(pixfmt
, aHidd_PixFmt_BlueMask
, &blue_mask
);
400 /* Alpha blitting is done using PutAlphaImage(). This method
401 should ignore alpha channel data. Otherwise data without
402 alpha channel (with alpha == 0) is assumed to contain valid
403 alpha values and we see nothing as a result.
404 This is known to affect TrueType fonts. */
410 DPUTIMAGE(bug("[sdl] source format: depth %d red 0x%08x green 0x%08x blue 0x%08x alpha 0x%08x\n", depth
, red_mask
, green_mask
, blue_mask
, alpha_mask
));
412 s
= SP(SDL_CreateRGBSurfaceFrom
, msg
->pixels
, msg
->width
, msg
->height
, depth
, msg
->modulo
, red_mask
, green_mask
, blue_mask
, alpha_mask
);
414 DPUTIMAGE(bug("[sdl] native32 format, setting pixel width to 4 bytes\n"));
415 s
->format
->BytesPerPixel
= 4;
420 srect
.w
= msg
->width
;
421 srect
.h
= msg
->height
;
426 DPUTIMAGE(bug("[sdl] blitting %dx%d image to surface 0x%08x at [%d,%d]\n", srect
.w
, srect
.h
, bmdata
->surface
, drect
.x
, drect
.y
));
428 S(SDL_BlitSurface
, s
, &srect
, bmdata
->surface
, &drect
);
430 SV(SDL_FreeSurface
, s
);
433 VOID
SDLBitMap__Hidd_BitMap__GetImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetImage
*msg
) {
434 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
436 IPTR red_mask
, green_mask
, blue_mask
, alpha_mask
;
437 BOOL native32
= FALSE
;
441 D(bug("[sdl] SDLBitMap::GetImage\n"));
443 switch (msg
->pixFmt
) {
444 case vHidd_StdPixFmt_Native32
:
445 D(bug("[sdl] native32 format, making a note to ensure 4-byte pixels later\n"));
448 case vHidd_StdPixFmt_Native
:
449 D(bug("[sdl] native format, using our attributes\n"));
451 depth
= bmdata
->surface
->format
->BitsPerPixel
;
452 red_mask
= bmdata
->surface
->format
->Rmask
;
453 green_mask
= bmdata
->surface
->format
->Gmask
;
454 blue_mask
= bmdata
->surface
->format
->Bmask
;
455 alpha_mask
= bmdata
->surface
->format
->Amask
;
460 D(bug("[sdl] pixel format %d, asking the gfxhidd for attributes\n", msg
->pixFmt
));
463 OOP_GetAttr(o
, aHidd_BitMap_GfxHidd
, (IPTR
*)&gfxhidd
);
465 OOP_Object
*pixfmt
= HIDD_Gfx_GetPixFmt(gfxhidd
, msg
->pixFmt
);
467 OOP_GetAttr(pixfmt
, aHidd_PixFmt_Depth
, &depth
);
468 OOP_GetAttr(pixfmt
, aHidd_PixFmt_RedMask
, &red_mask
);
469 OOP_GetAttr(pixfmt
, aHidd_PixFmt_GreenMask
, &green_mask
);
470 OOP_GetAttr(pixfmt
, aHidd_PixFmt_BlueMask
, &blue_mask
);
471 OOP_GetAttr(pixfmt
, aHidd_PixFmt_AlphaMask
, &alpha_mask
);
476 D(bug("[sdl] target format: depth %d red 0x%08x green 0x%08x blue 0x%08x alpha 0x%08x\n", depth
, red_mask
, green_mask
, blue_mask
, alpha_mask
));
478 s
= SP(SDL_CreateRGBSurfaceFrom
, msg
->pixels
, msg
->width
, msg
->height
, depth
, msg
->modulo
, red_mask
, green_mask
, blue_mask
, alpha_mask
);
480 D(bug("[sdl] native32 format, setting pixel width to 4 bytes\n"));
481 s
->format
->BytesPerPixel
= 4;
486 srect
.w
= msg
->width
;
487 srect
.h
= msg
->height
;
489 D(bug("[sdl] blitting %dx%d image at [%d,%d] to surface 0x%08x\n", srect
.w
, srect
.h
, srect
.x
, srect
.y
, bmdata
->surface
));
491 S(SDL_BlitSurface
, bmdata
->surface
, &srect
, s
, NULL
);
493 SV(SDL_FreeSurface
, s
);
496 VOID
SDLBitMap__Hidd_BitMap__FillRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawRect
*msg
) {
497 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
498 struct SDL_Rect rect
;
499 int bytesperpixel
= bmdata
->surface
->format
->BytesPerPixel
;
500 HIDDT_Pixel fg
= GC_FG(msg
->gc
);
501 HIDDT_DrawMode mode
= GC_DRMD(msg
->gc
);
503 D(bug("[sdl] SDLBitMap::FillRect\n"));
507 rect
.w
= msg
->maxX
- msg
->minX
+ 1;
508 rect
.h
= msg
->maxY
- msg
->minY
+ 1;
510 D(bug("[sdl] target surface 0x%08x, width %d, height %d, depth %d\n", bmdata
->surface
, bmdata
->surface
->w
, bmdata
->surface
->h
, bmdata
->surface
->format
->BitsPerPixel
));
511 D(bug("[sdl] target rect x %d y %d w %d h %d\n", rect
.x
, rect
.y
, rect
.h
, rect
.y
));
512 D(bug("[sdl] colour 0x%08x, mode %d\n", fg
, mode
));
515 case vHidd_GC_DrawMode_Copy
:
516 SV(SDL_FillRect
, bmdata
->surface
, &rect
, fg
);
520 case vHidd_GC_DrawMode_Invert
:
521 LOCK(bmdata
->surface
);
523 HIDD_BM_InvertMemRect(o
,
524 bmdata
->surface
->pixels
,
525 msg
->minX
* bytesperpixel
,
527 msg
->maxX
* bytesperpixel
+ bytesperpixel
- 1,
529 bmdata
->surface
->pitch
);
531 UNLOCK(bmdata
->surface
);
536 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
542 VOID
SDLBitMap__Hidd_BitMap__Clear(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_Clear
*msg
) {
543 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
546 D(bug("[sdl] SDLBitMap::Clear\n"));
550 D(bug("[sdl] filling surface 0x%08x with colour 0x%08x\n", bmdata
->surface
, c
));
552 S(SDL_FillRect
, bmdata
->surface
, NULL
, c
);
555 VOID
SDLBitMap__Hidd_BitMap__BlitColorExpansion(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_BlitColorExpansion
*msg
) {
556 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
557 int bytesperpixel
= bmdata
->surface
->format
->BytesPerPixel
;
558 Uint8
*p
= (Uint8
*) bmdata
->surface
->pixels
+ msg
->destY
* bmdata
->surface
->pitch
+ msg
->destX
* bytesperpixel
;
564 D(bug("[sdl] SDLBitMap::BlitColorExpansion\n"));
566 D(bug("[sdl] target surface 0x%08x rect x %d y %d w %d h %d\n", bmdata
->surface
, msg
->destX
, msg
->destY
, msg
->width
, msg
->height
));
570 ce
= GC_COLEXP(msg
->gc
);
572 srcline
= AllocMem(msg
->width
* sizeof(ULONG
), 0);
574 LOCK(bmdata
->surface
);
578 case vHidd_GC_ColExp_Transparent
:
579 D(bug("[sdl] transparent colour expansion, fg 0x%08x\n", fg
));
581 switch (bytesperpixel
) {
584 for (y
= 0; y
< msg
->height
; y
++) {
585 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcX
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
586 for (x
= 0; x
< msg
->width
; x
++) {
588 PUTPIXEL8(&p
[x
], fg
);
590 p
+= bmdata
->surface
->pitch
;
595 for (y
= 0; y
< msg
->height
; y
++) {
596 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcX
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
597 for (x
= 0; x
< msg
->width
; x
++) {
599 PUTPIXEL16(&(((Uint16
*) p
)[x
]), fg
);
601 p
+= bmdata
->surface
->pitch
;
606 for (y
= 0; y
< msg
->height
; y
++) {
607 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcX
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
608 for (x
= 0; x
< msg
->width
; x
++) {
610 PUTPIXEL24(&(((Uint32
*) p
)[x
]), fg
);
612 p
+= bmdata
->surface
->pitch
;
617 for (y
= 0; y
< msg
->height
; y
++) {
618 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcX
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
619 for (x
= 0; x
< msg
->width
; x
++) {
621 PUTPIXEL32(&(((Uint32
*) p
)[x
]), fg
);
623 p
+= bmdata
->surface
->pitch
;
631 case vHidd_GC_ColExp_Opaque
:
632 D(bug("[sdl] opaque colour expansion, fg 0x%08x bg %08x\n", fg
, bg
));
634 switch (bytesperpixel
) {
637 for (y
= 0; y
< msg
->height
; y
++) {
638 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcX
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
639 for (x
= 0; x
< msg
->width
; x
++)
640 PUTPIXEL8(&p
[x
], srcline
[x
] != 0 ? fg
: bg
);
641 p
+= bmdata
->surface
->pitch
;
646 for (y
= 0; y
< msg
->height
; y
++) {
647 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcY
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
648 for (x
= 0; x
< msg
->width
; x
++)
649 PUTPIXEL16(&(((Uint16
*) p
)[x
]), srcline
[x
] != 0 ? fg
: bg
);
650 p
+= bmdata
->surface
->pitch
;
655 for (y
= 0; y
< msg
->height
; y
++) {
656 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcX
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
657 for (x
= 0; x
< msg
->width
; x
++)
658 PUTPIXEL24(&(((Uint32
*) p
)[x
]), srcline
[x
] != 0 ? fg
: bg
);
659 p
+= bmdata
->surface
->pitch
;
664 for (y
= 0; y
< msg
->height
; y
++) {
665 HIDD_BM_GetImage(msg
->srcBitMap
, (UBYTE
*)srcline
, msg
->width
* sizeof(ULONG
), msg
->srcX
, msg
->srcY
+ y
, msg
->width
, 1, vHidd_StdPixFmt_Native32
);
666 for (x
= 0; x
< msg
->width
; x
++)
667 PUTPIXEL32(&(((Uint32
*) p
)[x
]), srcline
[x
] != 0 ? fg
: bg
);
668 p
+= bmdata
->surface
->pitch
;
676 UNLOCK(bmdata
->surface
);
678 FreeMem(srcline
, msg
->width
* sizeof(ULONG
));
681 VOID
SDLBitMap__Hidd_BitMap__PutAlphaImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutAlphaImage
*msg
) {
682 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
684 SDL_Rect srect
, drect
;
686 D(bug("[sdl] SDLBitMap::PutAlphaImage\n"));
688 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
689 s
= SP(SDL_CreateRGBSurfaceFrom
, msg
->pixels
, msg
->width
, msg
->height
, 32, msg
->modulo
, 0xff0000, 0xff00, 0xff, 0xff000000);
691 s
= SP(SDL_CreateRGBSurfaceFrom
, msg
->pixels
, msg
->width
, msg
->height
, 32, msg
->modulo
, 0xff00, 0xff0000, 0xff000000, 0xff);
696 srect
.w
= msg
->width
;
697 srect
.h
= msg
->height
;
702 D(bug("[sdl] blitting %dx%d alpha image to surface 0x%08x at [%d,%d]\n", srect
.w
, srect
.h
, bmdata
->surface
, drect
.x
, drect
.y
));
704 S(SDL_BlitSurface
, s
, &srect
, bmdata
->surface
, &drect
);
706 SV(SDL_FreeSurface
, s
);
709 VOID
SDLBitMap__Hidd_BitMap__PutTemplate(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutTemplate
*msg
) {
710 struct bmdata
*bmdata
= OOP_INST_DATA(cl
, o
);
712 D(bug("[sdl] SDLBitMap::PutTemplate\n"));
714 LOCK(bmdata
->surface
);
716 switch (bmdata
->surface
->format
->BytesPerPixel
) {
718 HIDD_BM_PutMemTemplate8(o
, msg
->gc
, msg
->masktemplate
, msg
->modulo
, msg
->srcx
, bmdata
->surface
->pixels
, bmdata
->surface
->pitch
, msg
->x
, msg
->y
, msg
->width
, msg
->height
, msg
->inverttemplate
);
722 HIDD_BM_PutMemTemplate16(o
, msg
->gc
, msg
->masktemplate
, msg
->modulo
, msg
->srcx
, bmdata
->surface
->pixels
, bmdata
->surface
->pitch
, msg
->x
, msg
->y
, msg
->width
, msg
->height
, msg
->inverttemplate
);
726 HIDD_BM_PutMemTemplate24(o
, msg
->gc
, msg
->masktemplate
, msg
->modulo
, msg
->srcx
, bmdata
->surface
->pixels
, bmdata
->surface
->pitch
, msg
->x
, msg
->y
, msg
->width
, msg
->height
, msg
->inverttemplate
);
730 HIDD_BM_PutMemTemplate32(o
, msg
->gc
, msg
->masktemplate
, msg
->modulo
, msg
->srcx
, bmdata
->surface
->pixels
, bmdata
->surface
->pitch
, msg
->x
, msg
->y
, msg
->width
, msg
->height
, msg
->inverttemplate
);
734 UNLOCK(bmdata
->surface
);
737 static struct OOP_MethodDescr SDLBitMap_Root_descr
[] = {
738 {(OOP_MethodFunc
)SDLBitMap__Root__New
, moRoot_New
},
739 {(OOP_MethodFunc
)SDLBitMap__Root__Dispose
, moRoot_Dispose
},
740 {(OOP_MethodFunc
)SDLBitMap__Root__Get
, moRoot_Get
},
741 {(OOP_MethodFunc
)SDLBitMap__Root__Set
, moRoot_Set
},
744 #define NUM_SDLBitMap_Root_METHODS 4
746 static struct OOP_MethodDescr SDLBitMap_Hidd_BitMap_descr
[] = {
747 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__SetColors
, moHidd_BitMap_SetColors
},
748 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__PutPixel
, moHidd_BitMap_PutPixel
},
749 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__GetPixel
, moHidd_BitMap_GetPixel
},
750 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__UpdateRect
, moHidd_BitMap_UpdateRect
},
751 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__PutImage
, moHidd_BitMap_PutImage
},
752 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__GetImage
, moHidd_BitMap_GetImage
},
753 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__FillRect
, moHidd_BitMap_FillRect
},
754 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__Clear
, moHidd_BitMap_Clear
},
755 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__BlitColorExpansion
, moHidd_BitMap_BlitColorExpansion
},
756 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__PutAlphaImage
, moHidd_BitMap_PutAlphaImage
},
757 {(OOP_MethodFunc
)SDLBitMap__Hidd_BitMap__PutTemplate
, moHidd_BitMap_PutTemplate
},
760 #define NUM_SDLBitMap_Hidd_BitMap_METHODS 11
762 struct OOP_InterfaceDescr SDLBitMap_ifdescr
[] = {
763 {SDLBitMap_Root_descr
, IID_Root
, NUM_SDLBitMap_Root_METHODS
},
764 {SDLBitMap_Hidd_BitMap_descr
, IID_Hidd_BitMap
, NUM_SDLBitMap_Hidd_BitMap_METHODS
},