2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Graphics function MakeVPort()
9 #include <aros/debug.h>
10 #include <graphics/view.h>
12 #include "graphics_intern.h"
13 #include "gfxfuncsupport.h"
15 /*****************************************************************************
18 #include <proto/graphics.h>
20 AROS_LH2(ULONG
, MakeVPort
,
23 AROS_LHA(struct View
*, view
, A0
),
24 AROS_LHA(struct ViewPort
*, viewport
, A1
),
27 struct GfxBase
*, GfxBase
, 36, Graphics
)
30 Prepare a ViewPort to be displayed. Calculate all necessary internal data.
31 For Amiga(tm) chipset bitmaps this includes calculating preliminary copperlists.
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
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).
61 ******************************************************************************/
65 struct ViewPortExtra
*vpe
;
66 struct HIDD_ViewPortData
*vpd
;
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
));
77 vpe
= (struct ViewPortExtra
*)GfxNew(VIEWPORT_EXTRA_TYPE
);
81 vpe
->Flags
= VPXF_FREE_ME
;
82 GfxAssociate(viewport
, &vpe
->n
);
86 /* Now make sure that ViewPortData is created */
88 vpe
->DriverData
[0] = AllocMem(sizeof(struct HIDD_ViewPortData
), MEMF_PUBLIC
|MEMF_CLEAR
);
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.
104 vpd
->Bitmap
= OBTAIN_HIDD_BM(viewport
->RasInfo
->BitMap
);
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
;
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
;
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.
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
);
176 /* Use ScrollVPort() in order to validate offsets */
177 ScrollVPort(viewport
);
181 RELEASE_HIDD_BM(vpd
->Bitmap
, viewport
->RasInfo
->BitMap
);