try to make sure compiler/include/mmakefile is always refreshed correctly.
[AROS.git] / rom / intuition / allocscreenbuffer.c
blobe316a2494fc3992d8a7c42676c4ad71d399ecd4a
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
6 Desc: Intuition function AllocScreenBuffer()
7 Lang: english
8 */
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 /*****************************************************************************
17 NAME */
18 #include <intuition/screens.h>
19 #include <proto/intuition.h>
21 AROS_LH3(struct ScreenBuffer *, AllocScreenBuffer,
23 /* SYNOPSIS */
24 AROS_LHA(struct Screen *, screen, A0),
25 AROS_LHA(struct BitMap *, bitmap, A1),
26 AROS_LHA(ULONG , flags, D0),
28 /* LOCATION */
29 struct IntuitionBase *, IntuitionBase, 128, Intuition)
31 /* FUNCTION
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.
43 INPUTS
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
59 initial BitMap.
61 RESULT
62 Pointer to the allocated ScreenBuffer or NULL if function failed.
64 NOTES
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.
71 EXAMPLE
73 BUGS
75 SEE ALSO
76 FreeScreenBuffer(), ChangeScreenBuffer()
78 INTERNALS
80 *****************************************************************************/
82 AROS_LIBFUNC_INIT
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));
90 if (screen)
92 if ((ScreenBuffer = AllocMem(sizeof (struct IntScreenBuffer),
93 MEMF_CLEAR)))
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;
106 UnlockIBase(ilock);
108 if (gotrestore &&
109 (ScreenBuffer->sb.sb_DBufInfo = AllocDBufInfo(&screen->ViewPort)))
111 if (!bitmap)
113 /* Get a bitmap */
114 if (flags & SB_SCREEN_BITMAP)
116 bitmap = IS(screen)->AllocatedBitMap;
118 else
120 ULONG allocflags = BMF_MINPLANES|BMF_DISPLAYABLE;
121 ScreenBuffer->free_bitmap = TRUE;
123 if (!(flags & SB_COPY_BITMAP)) allocflags |= BMF_CLEAR;
124 #ifdef __MORPHOS__
125 if (IS(screen)->Support3D) allocflags |= BMF_3DTARGET;
126 #endif
127 bitmap = AllocBitMap(GetBitMapAttr(screen->RastPort.BitMap,BMA_WIDTH),
128 GetBitMapAttr(screen->RastPort.BitMap,BMA_HEIGHT),
129 GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH),
130 allocflags,
131 screen->RastPort.BitMap);
133 if (NULL == bitmap)
135 FreeDBufInfo(ScreenBuffer->sb.sb_DBufInfo);
136 FreeMem(ScreenBuffer, sizeof(struct IntScreenBuffer));
137 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: failed\n"));
138 return NULL;
143 ScreenBuffer->sb.sb_BitMap = bitmap;
145 if (flags & SB_COPY_BITMAP)
147 BltBitMap(screen->RastPort.BitMap,
150 bitmap,
153 GetBitMapAttr(screen->RastPort.BitMap,BMA_WIDTH),
154 GetBitMapAttr(screen->RastPort.BitMap,BMA_HEIGHT),
155 0xc0, /* vanilla copy */
157 NULL);
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"));
172 return NULL;
174 AROS_LIBFUNC_EXIT
175 } /* AllocScreenBuffer */