tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / rom / graphics / releasepen.c
blob8ca7dd4cc26a125da0ecf097da51312e0311ea4e
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Release a pen previously allocated.
6 Lang: english
7 */
8 #include <aros/debug.h>
10 #include "graphics_intern.h"
11 #include <graphics/view.h>
13 /*****************************************************************************
15 NAME */
16 #include <proto/graphics.h>
18 AROS_LH2(void, ReleasePen,
20 /* SYNOPSIS */
21 AROS_LHA(struct ColorMap *, cm, A0),
22 AROS_LHA(ULONG , n , D0),
24 /* LOCATION */
25 struct GfxBase *, GfxBase, 158, Graphics)
27 /* FUNCTION
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
31 entries.
34 INPUTS
35 cm - ColorMap structure where the pen was allocated
36 n - The number of the pen
38 RESULT
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.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
51 INTERNALS
53 HISTORY
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
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
66 free list already...
69 index = pe->pe_FirstFree;
70 while ((PalExtra_AllocList_Type)-1 != index)
72 if (index == (PalExtra_AllocList_Type)n)
73 goto exit;
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))
86 /*
87 ** A SHARED pen
89 PALEXTRA_REFCNT(pe, n)--;
90 if (0 == PALEXTRA_REFCNT(pe, n))
92 D(BOOL found = FALSE);
93 /*
94 ** I can take this out if the list of shared pens
95 ** since this was the last application that used
96 ** this pen.
98 index = pe->pe_FirstShared;
99 if ((PalExtra_AllocList_Type)n == index)
101 D(found = TRUE);
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;
111 else
112 pe->pe_FirstShared = (WORD)PALEXTRA_ALLOCLIST(pe,n);
114 pe->pe_NShared--;
117 ** ... and make it available in the list of free
118 ** entries.
120 PALEXTRA_ALLOCLIST(pe,n) = (PalExtra_AllocList_Type)pe->pe_FirstFree;
121 pe->pe_FirstFree = n;
122 pe->pe_NFree++;
124 else
128 if ((PalExtra_AllocList_Type)n == PALEXTRA_ALLOCLIST(pe, index))
130 D(found = TRUE);
133 ** Take it out of the list of shared entries
135 PALEXTRA_ALLOCLIST(pe, index) = PALEXTRA_ALLOCLIST(pe, n);
136 pe->pe_NShared--;
139 ** ... and make it available in the list of free
140 ** entries.
142 PALEXTRA_ALLOCLIST(pe, n) = (PalExtra_AllocList_Type)pe->pe_FirstFree;
143 pe->pe_FirstFree = n;
144 pe->pe_NFree++;
145 break;
147 else
148 index = PALEXTRA_ALLOCLIST(pe, index);
150 while ((PalExtra_AllocList_Type)-1 != index);
153 #if DEBUG
154 if (!found)
155 D(bug("Error in ReleasePen() pen = %d!\n",n));
156 #endif
158 } /* if (no further app needs this pen) */
160 } /* if (0 != PALEXTRA_REFCNT(pe,n)) */
161 else
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;
168 pe->pe_NFree++;
170 exit:
171 ReleaseSemaphore(&pe->pe_Semaphore);
173 } /* if (NULL != cm && n < cm->Count) */
175 AROS_LIBFUNC_EXIT
177 } /* ReleasePen */