oops .. forgot to offset from objects bounds
[AROS.git] / rom / intuition / allocscreenbuffer.c
blob3487d65f15bc1c6b13e7fbf759aa775efcea5356
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.
62 RESULT
63 Pointer to the allocated ScreenBuffer or NULL if function failed.
65 NOTES
66 You may render into the resulting BitMap.
67 Use the sb_DBufInfo field to access graphics.library's ViewPort
68 buffering features to e.g check if it is safe to reuse the previous
69 BitMap. Otherwise you risk to write into the on-screen BitMap and
70 damage menu or gadget rendering.
72 EXAMPLE
74 BUGS
76 SEE ALSO
77 FreeScreenBuffer(), ChangeScreenBuffer()
79 INTERNALS
81 HISTORY
83 *****************************************************************************/
85 AROS_LIBFUNC_INIT
87 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
88 struct IntScreenBuffer *ScreenBuffer = NULL;
90 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: Screen 0x%lx BitMap 0x%lx Flags 0x%lx\n",
91 screen, bitmap, flags));
93 if (screen)
95 if ((ScreenBuffer = AllocMem(sizeof (struct IntScreenBuffer),
96 MEMF_CLEAR)))
98 ULONG ilock = LockIBase(0);
99 BOOL gotrestore = TRUE;
101 /* allocate a dbuf info to use in FreeScreenBuffer! */
102 if (!IS(screen)->RestoreDBufInfo)
104 IS(screen)->RestoreDBufInfo = AllocDBufInfo(&screen->ViewPort);
106 if (IS(screen)->RestoreDBufInfo == NULL) gotrestore = FALSE;
109 UnlockIBase(ilock);
111 if (gotrestore &&
112 (ScreenBuffer->sb.sb_DBufInfo = AllocDBufInfo(&screen->ViewPort)))
114 if (!bitmap)
116 /* Get a bitmap */
117 if (flags & SB_SCREEN_BITMAP)
119 bitmap = IS(screen)->AllocatedBitmap;
121 else
123 ULONG allocflags = BMF_MINPLANES|BMF_DISPLAYABLE;
124 ScreenBuffer->free_bitmap = TRUE;
126 if (!(flags & SB_COPY_BITMAP)) allocflags |= BMF_CLEAR;
127 #ifdef __MORPHOS__
128 if (IS(screen)->Support3D) allocflags |= BMF_3DTARGET;
129 #endif
130 bitmap = AllocBitMap(GetBitMapAttr(screen->RastPort.BitMap,BMA_WIDTH),
131 GetBitMapAttr(screen->RastPort.BitMap,BMA_HEIGHT),
132 GetBitMapAttr(screen->RastPort.BitMap,BMA_DEPTH),
133 allocflags,
134 screen->RastPort.BitMap);
136 if (NULL == bitmap)
138 FreeDBufInfo(ScreenBuffer->sb.sb_DBufInfo);
139 FreeMem(ScreenBuffer, sizeof(struct IntScreenBuffer));
140 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: failed\n"));
141 return NULL;
146 ScreenBuffer->sb.sb_BitMap = bitmap;
148 if (flags & SB_COPY_BITMAP)
150 BltBitMap(screen->RastPort.BitMap,
153 bitmap,
156 GetBitMapAttr(screen->RastPort.BitMap,BMA_WIDTH),
157 GetBitMapAttr(screen->RastPort.BitMap,BMA_HEIGHT),
158 0xc0, /* vanilla copy */
160 NULL);
163 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: ScreenBuffer 0x%lx BitMap 0x%lx DBufInfo 0x%lx\n",
164 ScreenBuffer, bitmap, ScreenBuffer->sb.sb_DBufInfo));
166 return &ScreenBuffer->sb;
169 FreeMem(ScreenBuffer, sizeof(struct IntScreenBuffer));
173 DEBUG_ALLOCSCREENBUFFER(dprintf("AllocScreenBuffer: no mem\n"));
175 return NULL;
177 AROS_LIBFUNC_EXIT
178 } /* AllocScreenBuffer */