2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
6 Desc: Intuition function AllocScreenBuffer()
9 #include <proto/graphics.h>
10 #include <proto/cybergraphics.h>
11 #include <exec/exec.h>
12 #include <cybergraphx/cybergraphics.h>
13 #include "intuition_intern.h"
15 /*****************************************************************************
18 #include <intuition/screens.h>
19 #include <proto/intuition.h>
21 AROS_LH3(struct ScreenBuffer
*, AllocScreenBuffer
,
24 AROS_LHA(struct Screen
*, screen
, A0
),
25 AROS_LHA(struct BitMap
*, bitmap
, A1
),
26 AROS_LHA(ULONG
, flags
, D0
),
29 struct IntuitionBase
*, IntuitionBase
, 128, Intuition
)
32 Allocate a ScreenBuffer (and BitMap) for double or multiple
33 buffering in Intuition screens. Use this function to obtain a
34 ScreenBuffer for the screen's initial BitMap and for all other
35 BitMaps you want to swap in.
37 This function also allocates a DBufInfo from graphics.library
38 The returned ScreenBuffer contains a pointer to that DBufInfo.
39 See graphics.library/AllocDBufInfo() for more information on
40 how to use this struct to obtain info when it is safe to render
41 into an old buffer and when to switch.
44 screen - Screen to double-buffer
45 bitmap - You may pre-allocate a BitMap for CUSTOMBITMAP screens,
46 and pass the pointer to get a ScreenBuffer referring to it.
47 If you specify NULL, intuition will allocate the BitMap for
48 you. For non-CUSTOMBITMAP screens this parameter must be NULL.
49 flags - A combination of these flags:
50 SB_SCREEN_BITMAP for non-CUSTOMBITMAP screens to get a
51 ScreenBuffer referring to the screen's actual BitMap
52 (For CUSTOMBITMAP screens just pass the BitMap you used for
53 OpenScreen() as the bitmap parameter)
54 SB_COPY_BITMAP to copy the screen's BitMap intto the
55 ScreenBuffer's BitMap. Use this to get intuition rendered
56 stuff into your bitmap (such as menu-bars or gadgets).
57 May be omitted if the screen has no intuition rendered stuff,
58 as well as for allocating a ScreenBuffer for the screen's
62 Pointer to the allocated ScreenBuffer or NULL if function failed.
65 You may render into the resulting BitMap.
66 Use the sb_DBufInfo field to access graphics.library's ViewPort
67 buffering features to e.g check if it is safe to reuse the previous
68 BitMap. Otherwise you risk to write into the on-screen BitMap and
69 damage menu or gadget rendering.
76 FreeScreenBuffer(), ChangeScreenBuffer()
80 *****************************************************************************/
84 struct GfxBase
*GfxBase
= GetPrivIBase(IntuitionBase
)->GfxBase
;
85 struct IntScreenBuffer
*ScreenBuffer
= NULL
;
87 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: Screen 0x%lx BitMap 0x%lx Flags 0x%lx\n",
88 screen
, bitmap
, flags
));
92 if ((ScreenBuffer
= AllocMem(sizeof (struct IntScreenBuffer
),
95 ULONG ilock
= LockIBase(0);
96 BOOL gotrestore
= TRUE
;
98 /* allocate a dbuf info to use in FreeScreenBuffer! */
99 if (!IS(screen
)->RestoreDBufInfo
)
101 IS(screen
)->RestoreDBufInfo
= AllocDBufInfo(&screen
->ViewPort
);
103 if (IS(screen
)->RestoreDBufInfo
== NULL
) gotrestore
= FALSE
;
109 (ScreenBuffer
->sb
.sb_DBufInfo
= AllocDBufInfo(&screen
->ViewPort
)))
114 if (flags
& SB_SCREEN_BITMAP
)
116 bitmap
= IS(screen
)->AllocatedBitMap
;
120 ULONG allocflags
= BMF_MINPLANES
|BMF_DISPLAYABLE
;
121 ScreenBuffer
->free_bitmap
= TRUE
;
123 if (!(flags
& SB_COPY_BITMAP
)) allocflags
|= BMF_CLEAR
;
125 if (IS(screen
)->Support3D
) allocflags
|= BMF_3DTARGET
;
127 bitmap
= AllocBitMap(GetBitMapAttr(screen
->RastPort
.BitMap
,BMA_WIDTH
),
128 GetBitMapAttr(screen
->RastPort
.BitMap
,BMA_HEIGHT
),
129 GetBitMapAttr(screen
->RastPort
.BitMap
,BMA_DEPTH
),
131 screen
->RastPort
.BitMap
);
135 FreeDBufInfo(ScreenBuffer
->sb
.sb_DBufInfo
);
136 FreeMem(ScreenBuffer
, sizeof(struct IntScreenBuffer
));
137 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: failed\n"));
143 ScreenBuffer
->sb
.sb_BitMap
= bitmap
;
145 if (flags
& SB_COPY_BITMAP
)
147 BltBitMap(screen
->RastPort
.BitMap
,
153 GetBitMapAttr(screen
->RastPort
.BitMap
,BMA_WIDTH
),
154 GetBitMapAttr(screen
->RastPort
.BitMap
,BMA_HEIGHT
),
155 0xc0, /* vanilla copy */
160 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: ScreenBuffer 0x%lx BitMap 0x%lx DBufInfo 0x%lx\n",
161 ScreenBuffer
, bitmap
, ScreenBuffer
->sb
.sb_DBufInfo
));
163 return &ScreenBuffer
->sb
;
166 FreeMem(ScreenBuffer
, sizeof(struct IntScreenBuffer
));
170 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: no mem\n"));
175 } /* AllocScreenBuffer */