2 Copyright © 1995-2007, 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 *****************************************************************************/
62 if (NULL
!= cm
&& n
< cm
->Count
)
64 struct PaletteExtra
* pe
= cm
->PalExtra
;
65 PalExtra_AllocList_Type index
;
67 ObtainSemaphore(&pe
->pe_Semaphore
);
68 /* First I check whether this pen is somewhere in the
72 index
= pe
->pe_FirstFree
;
73 while ((PalExtra_AllocList_Type
)-1 != index
)
75 if (index
== (PalExtra_AllocList_Type
)n
)
78 index
= PALEXTRA_ALLOCLIST(pe
, index
);
82 ** It is not in the free list.
83 ** If it is a shared pen, then I can recognize this
84 ** by its value in the RefCnt
87 if (0 != PALEXTRA_REFCNT(pe
,n
))
92 PALEXTRA_REFCNT(pe
, n
)--;
93 if (0 == PALEXTRA_REFCNT(pe
, n
))
95 D(BOOL found
= FALSE
);
97 ** I can take this out if the list of shared pens
98 ** since this was the last application that used
101 index
= pe
->pe_FirstShared
;
102 if ((PalExtra_AllocList_Type
)n
== index
)
106 ** it's the very first one.
109 ** Take it out of the list of entries in
110 ** the shared list...
112 if ((PalExtra_AllocList_Type
)-1 == PALEXTRA_ALLOCLIST(pe
,n
))
113 pe
->pe_FirstShared
= (WORD
)-1;
115 pe
->pe_FirstShared
= (WORD
)PALEXTRA_ALLOCLIST(pe
,n
);
120 ** ... and make it available in the list of free
123 PALEXTRA_ALLOCLIST(pe
,n
) = (PalExtra_AllocList_Type
)pe
->pe_FirstFree
;
124 pe
->pe_FirstFree
= n
;
131 if ((PalExtra_AllocList_Type
)n
== PALEXTRA_ALLOCLIST(pe
, index
))
136 ** Take it out of the list of shared entries
138 PALEXTRA_ALLOCLIST(pe
, index
) = PALEXTRA_ALLOCLIST(pe
, n
);
142 ** ... and make it available in the list of free
145 PALEXTRA_ALLOCLIST(pe
, n
) = (PalExtra_AllocList_Type
)pe
->pe_FirstFree
;
146 pe
->pe_FirstFree
= n
;
151 index
= PALEXTRA_ALLOCLIST(pe
, index
);
153 while ((PalExtra_AllocList_Type
)-1 != index
);
158 D(bug("Error in ReleasePen() pen = %d!\n",n
));
161 } /* if (no further app needs this pen) */
163 } /* if (0 != PALEXTRA_REFCNT(pe,n)) */
166 /* releasing an EXCLUSIVE pen */
167 D(bug("Releasing (exclusive) pen %d\n"));
169 PALEXTRA_ALLOCLIST(pe
, n
) = pe
->pe_FirstFree
;
170 pe
->pe_FirstFree
= n
;
174 ReleaseSemaphore(&pe
->pe_Semaphore
);
176 } /* if (NULL != cm && n < cm->Count) */