2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Release a pen previously allocated.
8 #include "graphics_intern.h"
9 #include <graphics/view.h>
14 #include <aros/debug.h>
16 /*****************************************************************************
19 #include <clib/graphics_protos.h>
21 AROS_LH2(void, ReleasePen
,
24 AROS_LHA(struct ColorMap
*, cm
, A0
),
25 AROS_LHA(ULONG
, n
, D0
),
28 struct GfxBase
*, GfxBase
, 158, Graphics
)
31 Release a pen that was previously allocated as an exclusive
32 or shared pen by the application. Any other application can
33 then obtain this pen and make changes to the color register
38 cm - ColorMap structure where the pen was allocated
39 n - The number of the pen
42 An exclusive pen is deallocated for other applications to use.
43 A shared pen is only completely deallocated if no other
44 application is using it anymore.
58 *****************************************************************************/
61 AROS_LIBBASE_EXT_DECL(struct GfxBase
*,GfxBase
)
63 if (NULL
!= cm
&& n
< cm
->Count
)
65 struct PaletteExtra
* pe
= cm
->PalExtra
;
66 PalExtra_AllocList_Type index
;
68 ObtainSemaphore(&pe
->pe_Semaphore
);
69 /* First I check whether this pen is somewhere in the
73 index
= pe
->pe_FirstFree
;
74 while ((PalExtra_AllocList_Type
)-1 != index
)
76 if (index
== (PalExtra_AllocList_Type
)n
)
79 index
= PALEXTRA_ALLOCLIST(pe
, index
);
83 ** It is not in the free list.
84 ** If it is a shared pen, then I can recognize this
85 ** by its value in the RefCnt
88 if (0 != PALEXTRA_REFCNT(pe
,n
))
93 PALEXTRA_REFCNT(pe
, n
)--;
94 if (0 == PALEXTRA_REFCNT(pe
, n
))
98 ** I can take this out if the list of shared pens
99 ** since this was the last application that used
102 index
= pe
->pe_FirstShared
;
103 if ((PalExtra_AllocList_Type
)n
== index
)
107 ** it's the very first one.
110 ** Take it out of the list of entries in
111 ** the shared list...
113 if ((PalExtra_AllocList_Type
)-1 == PALEXTRA_ALLOCLIST(pe
,n
))
114 pe
->pe_FirstShared
= (WORD
)-1;
116 pe
->pe_FirstShared
= (WORD
)PALEXTRA_ALLOCLIST(pe
,n
);
121 ** ... and make it available in the list of free
124 PALEXTRA_ALLOCLIST(pe
,n
) = (PalExtra_AllocList_Type
)pe
->pe_FirstFree
;
125 pe
->pe_FirstFree
= n
;
132 if ((PalExtra_AllocList_Type
)n
== PALEXTRA_ALLOCLIST(pe
, index
))
137 ** Take it out of the list of shared entries
139 PALEXTRA_ALLOCLIST(pe
, index
) = PALEXTRA_ALLOCLIST(pe
, n
);
143 ** ... and make it available in the list of free
146 PALEXTRA_ALLOCLIST(pe
, n
) = (PalExtra_AllocList_Type
)pe
->pe_FirstFree
;
147 pe
->pe_FirstFree
= n
;
152 index
= PALEXTRA_ALLOCLIST(pe
, index
);
154 while ((PalExtra_AllocList_Type
)-1 != index
);
159 D(bug("Error in RealsePen() pen = %d!\n",n
));
162 } /* if (no further app needs this pen) */
164 } /* if (0 != PALEXTRA_REFCNT(pe,n)) */
167 /* releasing an EXCLUSIVE pen */
168 D(bug("Releasing (exclusive) pen %d\n"));
170 PALEXTRA_ALLOCLIST(pe
, n
) = pe
->pe_FirstFree
;
171 pe
->pe_FirstFree
= n
;
175 ReleaseSemaphore(&pe
->pe_Semaphore
);
177 } /* if (NULL != cm && n < cm->Count) */