Minor fixes to comments.
[AROS.git] / rom / intuition / allocscreenbuffer.c
blobc562026e1b7f68193c27369339445c7b35d25397
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/graphics.h>
8 #include <proto/cybergraphics.h>
9 #include <exec/exec.h>
10 #include <cybergraphx/cybergraphics.h>
11 #include "intuition_intern.h"
12 /*****************************************************************************
14 NAME */
15 #include <intuition/screens.h>
16 #include <proto/intuition.h>
18 AROS_LH3(struct ScreenBuffer *, AllocScreenBuffer,
20 /* SYNOPSIS */
21 AROS_LHA(struct Screen *, screen, A0),
22 AROS_LHA(struct BitMap *, bitmap, A1),
23 AROS_LHA(ULONG , flags, D0),
25 /* LOCATION */
26 struct IntuitionBase *, IntuitionBase, 128, Intuition)
28 /* FUNCTION
29 Allocate a ScreenBuffer (and BitMap) for double or multiple
30 buffering in Intuition screens. Use this function to obtain a
31 ScreenBuffer for the screen's initial BitMap and for all other
32 BitMaps you want to swap in.
34 This function also allocates a DBufInfo from graphics.library
35 The returned ScreenBuffer contains a pointer to that DBufInfo.
36 See graphics.library/AllocDBufInfo() for more information on
37 how to use this struct to obtain info when it is safe to render
38 into an old buffer and when to switch.
40 INPUTS
41 screen - Screen to double-buffer
42 bitmap - You may pre-allocate a BitMap for CUSTOMBITMAP screens,
43 and pass the pointer to get a ScreenBuffer referring to it.
44 If you specify NULL, intuition will allocate the BitMap for
45 you. For non-CUSTOMBITMAP screens this parameter must be NULL.
46 flags - A combination of these flags:
47 SB_SCREEN_BITMAP for non-CUSTOMBITMAP screens to get a
48 ScreenBuffer referring to the screen's actual BitMap
49 (For CUSTOMBITMAP screens just pass the BitMap you used for
50 OpenScreen() as the bitmap parameter)
51 SB_COPY_BITMAP to copy the screen's BitMap intto the
52 ScreenBuffer's BitMap. Use this to get intuition rendered
53 stuff into your bitmap (such as menu-bars or gadgets).
54 May be omitted if the screen has no intuition rendered stuff,
55 as well as for allocating a ScreenBuffer for the screen's
56 initial BitMap.
59 RESULT
60 Pointer to the allocated ScreenBuffer or NULL if function failed.
62 NOTES
63 You may render into the resulting BitMap.
64 Use the sb_DBufInfo field to access graphics.library's ViewPort
65 buffering features to e.g check if it is safe to reuse the previous
66 BitMap. Otherwise you risk to write into the on-screen BitMap and
67 damage menu or gadget rendering.
69 EXAMPLE
71 BUGS
73 SEE ALSO
74 FreeScreenBuffer(), ChangeScreenBuffer()
76 INTERNALS
78 HISTORY
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 if ((ScreenBuffer->sb.sb_DBufInfo =
96 AllocDBufInfo(&screen->ViewPort)))
98 if (!bitmap)
100 /* Get a bitmap */
101 if (flags & SB_SCREEN_BITMAP)
103 bitmap = screen->RastPort.BitMap;
105 else
107 ScreenBuffer->free_bitmap = TRUE;
108 bitmap = AllocBitMap(GetBitMapAttr(screen->RastPort.BitMap,BMA_WIDTH),
109 GetBitMapAttr(screen->RastPort.BitMap,BMA_HEIGHT),
110 GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH),
111 BMF_MINPLANES|BMF_DISPLAYABLE|BMF_CLEAR,
112 screen->RastPort.BitMap);
113 if (NULL == bitmap)
115 FreeDBufInfo(ScreenBuffer->sb.sb_DBufInfo);
116 FreeMem(ScreenBuffer, sizeof(struct IntScreenBuffer));
117 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: failed\n"));
119 return NULL;
124 ScreenBuffer->sb.sb_BitMap = bitmap;
126 if (flags & SB_COPY_BITMAP)
128 BltBitMap(screen->RastPort.BitMap,
131 bitmap,
134 screen->Width,
135 screen->Height,
136 0x0c0, /* copy */
138 NULL);
141 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: ScreenBuffer 0x%lx BitMap 0x%lx DBufInfo 0x%lx\n",
142 ScreenBuffer, bitmap, ScreenBuffer->sb.sb_DBufInfo));
144 return &ScreenBuffer->sb;
147 FreeMem(ScreenBuffer, sizeof(struct IntScreenBuffer));
151 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: no mem\n"));
153 return NULL;
155 AROS_LIBFUNC_EXIT
156 } /* AllocScreenBuffer */