Added missing properties.
[AROS.git] / rom / graphics / makevport.c
blob2b169d93e88f7c2ee45e29c425ba6043a1bf11c3
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function MakeVPort()
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <graphics/view.h>
12 #include "graphics_intern.h"
13 #include "gfxfuncsupport.h"
15 /*****************************************************************************
17 NAME */
18 #include <proto/graphics.h>
20 AROS_LH2(ULONG, MakeVPort,
22 /* SYNOPSIS */
23 AROS_LHA(struct View *, view, A0),
24 AROS_LHA(struct ViewPort *, viewport, A1),
26 /* LOCATION */
27 struct GfxBase *, GfxBase, 36, Graphics)
29 /* FUNCTION
30 Prepare a ViewPort to be displayed. Calculate all necessary internal data.
31 For Amiga(tm) chipset bitmaps this includes calculating preliminary copperlists.
33 INPUTS
34 view - pointer to a View structure
35 viewport - pointer to a ViewPort structure
36 the viewport must have a valid pointer to a RasInfo
38 RESULT
39 error - Result of the operation:
40 MVP_OK - Everything is OK, ViewPort is ready
41 MVP_NO_MEM - There was not enough memory for internal data
42 MVP_NO_VPE - There was no ViewPortExtra for this ViewPort and no memory to
43 allocate a temporary one.
44 MVP_NO_DSPINS - There was not enough memory for Amiga(tm) copperlist.
45 MVP_NO_DISPLAY - The BitMap can't be displayed using specified mode (for example,
46 misaligned or wrong depth).
48 NOTES
50 EXAMPLE
52 BUGS
54 SEE ALSO
56 INTERNALS
58 HISTORY
61 ******************************************************************************/
63 AROS_LIBFUNC_INIT
65 struct ViewPortExtra *vpe;
66 struct HIDD_ViewPortData *vpd;
67 ULONG ret = MVP_OK;
68 BOOL own_vpe = FALSE;
69 BOOL release_bm = FALSE;
71 /* Attach a temporary ViewPortExtra if needed */
72 vpe = (struct ViewPortExtra *)GfxLookUp(viewport);
73 D(bug("[MakeVPort] ViewPort 0x%p, ViewPortExtra 0x%p\n", viewport, vpe));
75 if (!vpe)
77 vpe = (struct ViewPortExtra *)GfxNew(VIEWPORT_EXTRA_TYPE);
78 if (!vpe)
79 return MVP_NO_VPE;
81 vpe->Flags = VPXF_FREE_ME;
82 GfxAssociate(viewport, &vpe->n);
83 own_vpe = TRUE;
86 /* Now make sure that ViewPortData is created */
87 if (!VPE_DATA(vpe))
88 vpe->DriverData[0] = AllocMem(sizeof(struct HIDD_ViewPortData), MEMF_PUBLIC|MEMF_CLEAR);
90 vpd = VPE_DATA(vpe);
91 if (vpd)
93 vpd->vpe = vpe;
96 * MakeVPort() can be called repeatedly on the same ViewPort.
97 * In order to handle this correctly we obtain the bitmap only if
98 * the pointer is not set yet.
99 * Otherwise we will allocate a new planar bitmap object from the
100 * cache every time if our ViewPort contains plain Amiga bitmap.
102 if (!vpd->Bitmap)
104 vpd->Bitmap = OBTAIN_HIDD_BM(viewport->RasInfo->BitMap);
105 release_bm = TRUE;
108 D(bug("[MakeVPort] Bitmap object: 0x%p\n", vpd->Bitmap));
110 if (IS_HIDD_BM(viewport->RasInfo->BitMap))
113 * VPXF_RELEASE_BITMAP is our private flag, so we ensure that it's not
114 * ocassionally set by caller. Just in case.
116 vpe->Flags &= ~VPXF_RELEASE_BITMAP;
119 * If we have a colormap attached to a HIDD bitmap, we can verify
120 * that bitmap and colormap modes do not differ.
122 if (viewport->ColorMap)
124 struct DisplayInfoHandle *dih = viewport->ColorMap->NormalDisplayInfo;
126 if (dih)
128 if ((HIDD_BM_DRVDATA(viewport->RasInfo->BitMap) != dih->drv) ||
129 (HIDD_BM_HIDDMODE(viewport->RasInfo->BitMap) != dih->id))
132 D(bug("[MakeVPort] Bad NormalDisplayInfo\n"));
133 D(bug("[MakeVPort] Driverdata: ViewPort 0x%p, BitMap 0x%p\n", dih->drv, HIDD_BM_DRVDATA(viewport->RasInfo->BitMap)));
134 D(bug("[MakeVPort] HIDD ModeID: ViewPort 0x%p, BitMap 0x%p\n", dih->id, HIDD_BM_HIDDMODE(viewport->RasInfo->BitMap)));
135 ret = MVP_NO_DISPLAY;
139 if (viewport->ColorMap->VPModeID != INVALID_ID)
141 if (GET_BM_MODEID(viewport->RasInfo->BitMap) != viewport->ColorMap->VPModeID)
143 D(bug("[MakeVPort] Bad ModeID, ViewPort 0x%08lX, BitMap 0x%08lX\n", viewport->ColorMap->VPModeID, GET_BM_MODEID(viewport->RasInfo->BitMap)));
144 ret = MVP_NO_DISPLAY;
149 else
150 vpe->Flags |= VPXF_RELEASE_BITMAP;
153 * Ensure that we have a bitmap object.
154 * OBTAIN_HIDD_BM() may fail on planar bitmap in low memory situation.
156 if (vpd->Bitmap)
158 struct monitor_driverdata *mdd = GET_VP_DRIVERDATA(viewport);
161 * Store driverdata pointer in private ViewPortExtra field.
162 * It is needed because the caller can first free BitMap, then
163 * its ViewPort. In this case we won't be able to retrieve
164 * driver pointer from the bitmap in FreeVPortCopLists().
166 vpe->DriverData[1] = mdd;
167 ret = HIDD_Gfx_MakeViewPort(mdd->gfxhidd, vpd);
169 else
170 ret = MVP_NO_MEM;
172 else
173 ret = MVP_NO_MEM;
175 if (ret == MVP_OK)
176 /* Use ScrollVPort() in order to validate offsets */
177 ScrollVPort(viewport);
178 else
180 if (release_bm)
181 RELEASE_HIDD_BM(vpd->Bitmap, viewport->RasInfo->BitMap);
183 if (own_vpe)
184 GfxFree(&vpe->n);
187 return ret;
189 AROS_LIBFUNC_EXIT
190 } /* MakeVPort */