2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Release a pen previously allocated.
8 #include <aros/debug.h>
10 #include "graphics_intern.h"
11 #include <graphics/view.h>
13 /*****************************************************************************
16 #include <proto/graphics.h>
18 AROS_LH2(void, ReleasePen
,
21 AROS_LHA(struct ColorMap
*, cm
, A0
),
22 AROS_LHA(ULONG
, n
, D0
),
25 struct GfxBase
*, GfxBase
, 158, Graphics
)
28 Release a pen that was previously allocated as an exclusive
29 or shared pen by the application. Any other application can
30 then obtain this pen and make changes to the color register
35 cm - ColorMap structure where the pen was allocated
36 n - The number of the pen
39 An exclusive pen is deallocated for other applications to use.
40 A shared pen is only completely deallocated if no other
41 application is using it anymore.
55 *****************************************************************************/
59 if (NULL
!= cm
&& n
< cm
->Count
)
61 struct PaletteExtra
* pe
= cm
->PalExtra
;
62 PalExtra_AllocList_Type index
;
64 ObtainSemaphore(&pe
->pe_Semaphore
);
65 /* First I check whether this pen is somewhere in the
69 index
= pe
->pe_FirstFree
;
70 while ((PalExtra_AllocList_Type
)-1 != index
)
72 if (index
== (PalExtra_AllocList_Type
)n
)
75 index
= PALEXTRA_ALLOCLIST(pe
, index
);
79 ** It is not in the free list.
80 ** If it is a shared pen, then I can recognize this
81 ** by its value in the RefCnt
84 if (0 != PALEXTRA_REFCNT(pe
,n
))
89 PALEXTRA_REFCNT(pe
, n
)--;
90 if (0 == PALEXTRA_REFCNT(pe
, n
))
92 D(BOOL found
= FALSE
);
94 ** I can take this out if the list of shared pens
95 ** since this was the last application that used
98 index
= pe
->pe_FirstShared
;
99 if ((PalExtra_AllocList_Type
)n
== index
)
103 ** it's the very first one.
106 ** Take it out of the list of entries in
107 ** the shared list...
109 if ((PalExtra_AllocList_Type
)-1 == PALEXTRA_ALLOCLIST(pe
,n
))
110 pe
->pe_FirstShared
= (WORD
)-1;
112 pe
->pe_FirstShared
= (WORD
)PALEXTRA_ALLOCLIST(pe
,n
);
117 ** ... and make it available in the list of free
120 PALEXTRA_ALLOCLIST(pe
,n
) = (PalExtra_AllocList_Type
)pe
->pe_FirstFree
;
121 pe
->pe_FirstFree
= n
;
128 if ((PalExtra_AllocList_Type
)n
== PALEXTRA_ALLOCLIST(pe
, index
))
133 ** Take it out of the list of shared entries
135 PALEXTRA_ALLOCLIST(pe
, index
) = PALEXTRA_ALLOCLIST(pe
, n
);
139 ** ... and make it available in the list of free
142 PALEXTRA_ALLOCLIST(pe
, n
) = (PalExtra_AllocList_Type
)pe
->pe_FirstFree
;
143 pe
->pe_FirstFree
= n
;
148 index
= PALEXTRA_ALLOCLIST(pe
, index
);
150 while ((PalExtra_AllocList_Type
)-1 != index
);
155 D(bug("Error in ReleasePen() pen = %d!\n",n
));
158 } /* if (no further app needs this pen) */
160 } /* if (0 != PALEXTRA_REFCNT(pe,n)) */
163 /* releasing an EXCLUSIVE pen */
164 D(bug("Releasing (exclusive) pen %d\n"));
166 PALEXTRA_ALLOCLIST(pe
, n
) = pe
->pe_FirstFree
;
167 pe
->pe_FirstFree
= n
;
171 ReleaseSemaphore(&pe
->pe_Semaphore
);
173 } /* if (NULL != cm && n < cm->Count) */