lock xft, plugin index builder lock, clear clip thumbnails, clear vwin clock, setpoin...
[goodguy/history.git] / cinelerra-5.1 / guicast / workarounds.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "clip.h"
23 #include "mutex.h"
24 #include <math.h>
25 #include "workarounds.h"
26
27 void Workarounds::copy_int(int &a, int &b)
28 {
29         a = b;
30 }
31
32 double Workarounds::divide_double(double a, double b)
33 {
34         return a / b;
35 }
36
37 void Workarounds::copy_double(double *a, double b)
38 {
39         *a = b;
40 }
41
42
43 void Workarounds::clamp(int32_t &x, int32_t y, int32_t z)
44 {
45         if(x < y) x = y;
46         else
47         if(x > z) x = z;
48 }
49
50 void Workarounds::clamp(int64_t &x, int64_t y, int64_t z)
51 {
52         if(x < y) x = y;
53         else
54         if(x > z) x = z;
55 }
56
57 void Workarounds::clamp(float &x, float y, float z)
58 {
59         if(x < y) x = y;
60         else
61         if(x > z) x = z;
62 }
63
64 void Workarounds::clamp(double &x, double y, double z)
65 {
66         if(x < y) x = y;
67         else
68         if(x > z) x = z;
69 }
70
71 float Workarounds::pow(float x, float y)
72 {
73         return powf(x, y);
74 }
75
76 #ifdef HAVE_XFT
77 // not thread safe
78 static Mutex xft_lock("xft_lock");
79
80 FcBool xftInitFtLibrary(void)
81 {
82         xft_lock.lock("xftInitFtLibrary");
83         FcBool ret = XftInitFtLibrary();
84         xft_lock.unlock();
85         return ret;
86 }
87
88 Bool xftDefaultHasRender(Display *dpy)
89 {
90         xft_lock.lock("xftDefaultHasRender");
91         Bool ret = XftDefaultHasRender(dpy);
92         xft_lock.unlock();
93         return ret;
94 }
95
96 FcBool xftCharExists(Display *dpy, XftFont *pub, FcChar32 ucs4)
97 {
98         xft_lock.lock("xftCharExists");
99         FcBool ret = XftCharExists(dpy, pub, ucs4);
100         xft_lock.unlock();
101         return ret;
102 }
103
104 void xftTextExtents8(Display *dpy, XftFont *pub,
105                 _Xconst FcChar8 *string, int len, XGlyphInfo *extents)
106 {
107         xft_lock.lock("xftTextExtents8");
108         XftTextExtents8(dpy, pub, string, len, extents);
109         xft_lock.unlock();
110 }
111
112 void xftTextExtentsUtf8(Display *dpy, XftFont *pub,
113                 _Xconst FcChar8 *string, int len, XGlyphInfo *extents)
114 {
115         xft_lock.lock("xftTextExtentsUtf8");
116         XftTextExtentsUtf8(dpy, pub, string, len, extents);
117         xft_lock.unlock();
118 }
119
120 void xftTextExtents32(Display *dpy, XftFont *pub,
121                 _Xconst FcChar32 *string, int len, XGlyphInfo *extents)
122 {
123         xft_lock.lock("xftTextExtents32");
124         XftTextExtents32(dpy, pub, string, len, extents);
125         xft_lock.unlock();
126 }
127
128 XftDraw *xftDrawCreate(Display *dpy, Drawable drawable, Visual *visual, Colormap colormap)
129 {
130         xft_lock.lock("xftDrawCreate");
131         XftDraw *ret = XftDrawCreate(dpy, drawable, visual, colormap);
132         xft_lock.unlock();
133         return ret;
134 }
135
136 XftDraw *xftDrawCreateBitmap(Display  *dpy, Pixmap bitmap)
137 {
138         xft_lock.lock("xftDrawCreateBitmap");
139         XftDraw *ret = XftDrawCreateBitmap(dpy, bitmap);
140         xft_lock.unlock();
141         return ret;
142 }
143
144 void xftDrawDestroy(XftDraw *draw)
145 {
146         xft_lock.lock("xftDrawDestroy");
147         XftDrawDestroy(draw);
148         xft_lock.unlock();
149 }
150
151 void xftDrawString32(XftDraw *draw, _Xconst XftColor *color, XftFont *pub,
152                 int x, int y, _Xconst FcChar32 *string, int len)
153 {
154         xft_lock.lock("xftDrawString32");
155         XftDrawString32(draw, color, pub, x, y, string, len);
156         xft_lock.unlock();
157 }
158
159 Bool xftColorAllocValue(Display *dpy, Visual *visual,
160                 Colormap cmap, _Xconst XRenderColor *color, XftColor *result)
161 {
162         xft_lock.lock("xftColorAllocValue");
163         Bool ret = XftColorAllocValue(dpy, visual, cmap, color, result);
164         xft_lock.unlock();
165         return ret;
166 }
167
168 void xftColorFree(Display *dpy, Visual *visual, Colormap cmap, XftColor *color)
169 {
170         xft_lock.lock("xftColorFree");
171         XftColorFree(dpy, visual, cmap, color);
172         xft_lock.unlock();
173 }
174
175 XftFont *xftFontOpenName(Display *dpy, int screen, _Xconst char *name)
176 {
177         xft_lock.lock("xftFontOpenName");
178         XftFont *ret = XftFontOpenName(dpy, screen, name);
179         xft_lock.unlock();
180         return ret;
181 }
182
183 XftFont *xftFontOpenXlfd(Display *dpy, int screen, _Xconst char *xlfd)
184 {
185         xft_lock.lock("xftFontOpenXlfd");
186         XftFont *ret = XftFontOpenXlfd(dpy, screen, xlfd);
187         xft_lock.unlock();
188         return ret;
189 }
190
191 XftFont *xftFontOpenPattern(Display *dpy, FcPattern *pattern)
192 {
193         xft_lock.lock("xftFontOpenPattern");
194         XftFont *ret = XftFontOpenPattern(dpy, pattern);
195         xft_lock.unlock();
196         return ret;
197 }
198
199 void xftFontClose(Display *dpy, XftFont *pub)
200 {
201         xft_lock.lock("xftFontClose");
202         XftFontClose(dpy, pub);
203         xft_lock.unlock();
204 }
205
206
207 static Mutex &ft_lock = xft_lock;
208
209 FT_Error ft_Done_Face(FT_Face face)
210 {
211         ft_lock.lock("ft_Done_Face");
212         FT_Error ret = FT_Done_Face(face);
213         ft_lock.unlock();
214         return ret;
215 }
216
217 FT_Error ft_Done_FreeType(FT_Library library)
218 {
219         ft_lock.lock("ft_Done_FreeType");
220         FT_Error ret = FT_Done_FreeType(library);
221         ft_lock.unlock();
222         return ret;
223 }
224
225 void ft_Done_Glyph(FT_Glyph glyph)
226 {
227         ft_lock.lock("ft_Done_Glyph");
228         FT_Done_Glyph(glyph);
229         ft_lock.unlock();
230 }
231
232 FT_UInt ft_Get_Char_Index(FT_Face face, FT_ULong charcode)
233 {
234         ft_lock.lock("ft_Get_Char_Index");
235         FT_UInt ret = FT_Get_Char_Index(face, charcode);
236         ft_lock.unlock();
237         return ret;
238 }
239
240 FT_Error ft_Get_Glyph(FT_GlyphSlot  slot, FT_Glyph *aglyph)
241 {
242         ft_lock.lock("ft_Get_Glyph");
243         FT_Error ret = FT_Get_Glyph(slot, aglyph);
244         ft_lock.unlock();
245         return ret;
246 }
247
248 FT_Error ft_Get_Kerning(FT_Face face, FT_UInt left_glyph, FT_UInt right_glyph, FT_UInt kern_mode, FT_Vector *akerning)
249 {
250         ft_lock.lock("ft_Get_Kerning");
251         FT_Error ret = FT_Get_Kerning(face, left_glyph, right_glyph, kern_mode, akerning);
252         ft_lock.unlock();
253         return ret;
254 }
255
256 FT_Error ft_Init_FreeType(FT_Library *alibrary)
257 {
258         ft_lock.lock("ft_Init_FreeType");
259         FT_Error ret = FT_Init_FreeType(alibrary);
260         ft_lock.unlock();
261         return ret;
262 }
263
264 FT_Error ft_Load_Char(FT_Face face, FT_ULong char_code, FT_Int32 load_flags)
265 {
266         ft_lock.lock("ft_Load_Char");
267         FT_Error ret = FT_Load_Char(face, char_code, load_flags);
268         ft_lock.unlock();
269         return ret;
270 }
271
272 FT_Error ft_Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags)
273 {
274         ft_lock.lock("ft_Load_Glyph");
275         FT_Error ret = FT_Load_Glyph(face, glyph_index, load_flags);
276         ft_lock.unlock();
277         return ret;
278 }
279
280 FT_Error ft_New_Face(FT_Library library, const char *filepathname, FT_Long face_index, FT_Face *aface)
281 {
282         ft_lock.lock("ft_New_Face");
283         FT_Error ret = FT_New_Face(library, filepathname, face_index, aface);
284         ft_lock.unlock();
285         return ret;
286 }
287
288 FT_Error ft_Outline_Done(FT_Library library, FT_Outline *outline)
289 {
290         ft_lock.lock("ft_Outline_Done");
291         FT_Error ret = FT_Outline_Done(library, outline);
292         ft_lock.unlock();
293         return ret;
294 }
295
296 FT_Error ft_Outline_Get_BBox(FT_Outline *outline, FT_BBox *abbox)
297 {
298         ft_lock.lock("ft_Outline_Get_BBox");
299         FT_Error ret = FT_Outline_Get_BBox(outline, abbox);
300         ft_lock.unlock();
301         return ret;
302 }
303
304 FT_Error ft_Outline_Get_Bitmap(FT_Library library, FT_Outline *outline, const FT_Bitmap  *abitmap)
305 {
306         ft_lock.lock("ft_Outline_Get_Bitmap");
307         FT_Error ret = FT_Outline_Get_Bitmap(library, outline, abitmap);
308         ft_lock.unlock();
309         return ret;
310 }
311
312 FT_Error ft_Outline_New(FT_Library library, FT_UInt numPoints, FT_Int numContours, FT_Outline *anoutline)
313 {
314         ft_lock.lock("ft_Outline_New");
315         FT_Error ret = FT_Outline_New(library, numPoints, numContours, anoutline);
316         ft_lock.unlock();
317         return ret;
318 }
319
320 void ft_Outline_Translate(const FT_Outline *outline, FT_Pos xOffset, FT_Pos yOffset)
321 {
322         ft_lock.lock("ft_Outline_Translate");
323         FT_Outline_Translate(outline, xOffset, yOffset);
324         ft_lock.unlock();
325 }
326
327 FT_Error ft_Select_Charmap(FT_Face face, FT_Encoding encoding)
328 {
329         ft_lock.lock("ft_Select_Charmap");
330         FT_Error ret = FT_Select_Charmap(face, encoding);
331         ft_lock.unlock();
332         return ret;
333 }
334 FT_Error ft_Set_Pixel_Sizes(FT_Face face, FT_UInt pixel_width, FT_UInt pixel_height)
335 {
336         ft_lock.lock("ft_Set_Pixel_Sizes");
337         FT_Error ret = FT_Set_Pixel_Sizes(face, pixel_width, pixel_height);
338         ft_lock.unlock();
339         return ret;
340 }
341
342 void ft_Stroker_Done(FT_Stroker stroker)
343 {
344         ft_lock.lock("ft_Stroker_Done");
345         FT_Stroker_Done(stroker);
346         ft_lock.unlock();
347 }
348
349 void ft_Stroker_Export(FT_Stroker stroker, FT_Outline *outline)
350 {
351         ft_lock.lock("ft_Stroker_Export");
352         FT_Stroker_Export(stroker, outline);
353         ft_lock.unlock();
354 }
355
356 FT_Error ft_Stroker_GetCounts(FT_Stroker stroker, FT_UInt *anum_points, FT_UInt *anum_contours)
357 {
358         ft_lock.lock("ft_Stroker_GetCounts");
359         FT_Error ret = FT_Stroker_GetCounts(stroker, anum_points, anum_contours);
360         ft_lock.unlock();
361         return ret;
362 }
363
364 FT_Error ft_Stroker_New(FT_Library library, FT_Stroker  *astroker)
365 {
366         ft_lock.lock("ft_Stroker_New");
367         FT_Error ret = FT_Stroker_New(library, astroker);
368         ft_lock.unlock();
369         return ret;
370 }
371
372 FT_Error ft_Stroker_ParseOutline(FT_Stroker stroker, FT_Outline *outline, FT_Bool opened)
373 {
374         ft_lock.lock("ft_Stroker_ParseOutline");
375         FT_Error ret = FT_Stroker_ParseOutline(stroker, outline, opened);
376         ft_lock.unlock();
377         return ret;
378 }
379
380 void ft_Stroker_Set(FT_Stroker stroker, FT_Fixed radius, FT_Stroker_LineCap line_cap, FT_Stroker_LineJoin line_join, FT_Fixed miter_limit)
381 {
382         ft_lock.lock("ft_Stroker_Set");
383         FT_Stroker_Set(stroker, radius, line_cap, line_join, miter_limit);
384         ft_lock.unlock();
385 }
386
387
388 static Mutex &fc_lock = xft_lock;
389
390 FcBool fcCharSetAddChar(FcCharSet *fcs, FcChar32 ucs4)
391 {
392         fc_lock.lock("fcCharSetAddChar");
393         FcBool ret = FcCharSetAddChar(fcs, ucs4);
394         fc_lock.unlock();
395         return ret;
396 }
397
398 FcCharSet *fcCharSetCreate(void)
399 {
400         fc_lock.lock("fcCharSetCreate");
401         FcCharSet *ret = FcCharSetCreate();
402         fc_lock.unlock();
403         return ret;
404 }
405 void fcCharSetDestroy(FcCharSet *fcs)
406 {
407         fc_lock.lock("fcCharSetDestroy");
408         FcCharSetDestroy(fcs);
409         fc_lock.unlock();
410 }
411
412 FcBool fcCharSetHasChar(const FcCharSet *fcs, FcChar32 ucs4)
413 {
414         fc_lock.lock("fcCharSetHasChar");
415         FcBool ret = FcCharSetHasChar(fcs, ucs4);
416         fc_lock.unlock();
417         return ret;
418 }
419
420 FcBool fcConfigAppFontAddDir(FcConfig *config, const FcChar8 *dir)
421 {
422         fc_lock.lock("fcConfigAppFontAddDir");
423         FcBool ret = FcConfigAppFontAddDir(config, dir);
424         fc_lock.unlock();
425         return ret;
426 }
427
428 FcConfig *fcConfigGetCurrent()
429 {
430         fc_lock.lock("fcConfigGetCurrent");
431         FcConfig *ret = FcConfigGetCurrent();
432         fc_lock.unlock();
433         return ret;
434 }
435
436 FcBool fcConfigSetRescanInterval(FcConfig *config, int rescanInterval)
437 {
438         fc_lock.lock("fcConfigSetRescanInterval");
439         FcBool ret = FcConfigSetRescanInterval(config, rescanInterval);
440         fc_lock.unlock();
441         return ret;
442 }
443
444 FcFontSet *fcFontList(FcConfig *config, FcPattern *p, FcObjectSet *os)
445 {
446         fc_lock.lock("fcFontList");
447         FcFontSet *ret = FcFontList(config, p, os);
448         fc_lock.unlock();
449         return ret;
450 }
451
452 void fcFontSetDestroy(FcFontSet *s)
453 {
454         fc_lock.lock("fcFontSetDestroy");
455         FcFontSetDestroy(s);
456         fc_lock.unlock();
457 }
458
459 FcPattern *fcFreeTypeQueryFace(const FT_Face face, const FcChar8 *file, unsigned int id, FcBlanks *blanks)
460 {
461         fc_lock.lock("fcFreeTypeQueryFace");
462         FcPattern *ret = FcFreeTypeQueryFace(face, file, id, blanks);
463         fc_lock.unlock();
464         return ret;
465 }
466
467 FcBool fcInit(void)
468 {
469         fc_lock.lock("fcInit");
470         FcBool ret = FcInit();
471         fc_lock.unlock();
472         return ret;
473 }
474
475 FcBool fcLangSetAdd(FcLangSet *ls, const FcChar8 *lang)
476 {
477         fc_lock.lock("fcLangSetAdd");
478         FcBool ret = FcLangSetAdd(ls, lang);
479         fc_lock.unlock();
480         return ret;
481 }
482
483 FcLangSet *fcLangSetCreate(void)
484 {
485         fc_lock.lock("fcLangSetCreate");
486         FcLangSet *ret = FcLangSetCreate();
487         fc_lock.unlock();
488         return ret;
489 }
490
491 void fcLangSetDestroy(FcLangSet *ls)
492 {
493         fc_lock.lock("fcLangSetDestroy");
494         FcLangSetDestroy(ls);
495         fc_lock.unlock();
496 }
497
498 FcObjectSet *fcObjectSetBuild(const char *first, ...)
499 {
500         fc_lock.lock("fcObjectSetBuild");
501         va_list va;  va_start(va, first);
502         FcObjectSet *ret = FcObjectSetVaBuild(first, va);
503         va_end(va);
504         fc_lock.unlock();
505         return ret;
506 }
507
508 void fcObjectSetDestroy(FcObjectSet *os)
509 {
510         fc_lock.lock("fcObjectSetDestroy");
511         FcObjectSetDestroy(os);
512         fc_lock.unlock();
513 }
514
515 FcBool fcPatternAddBool(FcPattern *p, const char *object, FcBool b)
516 {
517         fc_lock.lock("fcPatternAddBool");
518         FcBool ret = FcPatternAddBool(p, object, b);
519         fc_lock.unlock();
520         return ret;
521 }
522
523 FcBool fcPatternAddCharSet(FcPattern *p, const char *object, const FcCharSet *c)
524 {
525         fc_lock.lock("fcPatternAddCharSet");
526         FcBool ret = FcPatternAddCharSet(p, object, c);
527         fc_lock.unlock();
528         return ret;
529 }
530
531 FcBool fcPatternAddDouble(FcPattern *p, const char *object, double d)
532 {
533         fc_lock.lock("fcPatternAddDouble");
534         FcBool ret = FcPatternAddDouble(p, object, d);
535         fc_lock.unlock();
536         return ret;
537 }
538
539 FcBool fcPatternAddInteger(FcPattern *p, const char *object, int i)
540 {
541         fc_lock.lock("fcPatternAddInteger");
542         FcBool ret = FcPatternAddInteger(p, object, i);
543         fc_lock.unlock();
544         return ret;
545 }
546
547 FcBool fcPatternAddLangSet(FcPattern *p, const char *object, const FcLangSet *ls)
548 {
549         fc_lock.lock("fcPatternAddLangSet");
550         FcBool ret = FcPatternAddLangSet(p, object, ls);
551         fc_lock.unlock();
552         return ret;
553 }
554
555 FcResult fcPatternGetInteger(const FcPattern *p, const char *object, int n, int *i)
556 {
557         fc_lock.lock("fcPatternGetInteger");
558         FcResult ret = FcPatternGetInteger(p, object, n, i);
559         fc_lock.unlock();
560         return ret;
561 }
562
563 FcResult fcPatternGetDouble (const FcPattern *p, const char *object, int n, double *d)
564 {
565         fc_lock.lock("fcPatternGetDouble");
566         FcResult ret = FcPatternGetDouble(p, object, n, d);
567         fc_lock.unlock();
568         return ret;
569 }
570
571 FcResult fcPatternGetString(const FcPattern *p, const char *object, int n, FcChar8 **s)
572 {
573         fc_lock.lock("fcPatternGetString");
574         FcResult ret = FcPatternGetString(p, object, n, s);
575         fc_lock.unlock();
576         return ret;
577 }
578
579 FcPattern *fcPatternCreate(void)
580 {
581         fc_lock.lock("fcPatternCreate");
582         FcPattern *ret = FcPatternCreate();
583         fc_lock.unlock();
584         return ret;
585 }
586
587 FcBool fcPatternDel(FcPattern *p, const char *object)
588 {
589         fc_lock.lock("fcPatternDel");
590         FcBool ret = FcPatternDel(p, object);
591         fc_lock.unlock();
592         return ret;
593 }
594
595 void fcPatternDestroy(FcPattern *p)
596 {
597         fc_lock.lock("fcPatternDestroy ");
598         FcPatternDestroy(p);
599         fc_lock.unlock();
600 }
601
602 FcPattern *fcPatternDuplicate(const FcPattern *p)
603 {
604         fc_lock.lock("fcPatternDuplicate");
605         FcPattern *ret = FcPatternDuplicate(p);
606         fc_lock.unlock();
607         return ret;
608 }
609
610 FcResult fcPatternGetCharSet(const FcPattern *p, const char *object, int n, FcCharSet **c)
611 {
612         fc_lock.lock("fcPatternGetCharSet");
613         FcResult ret = FcPatternGetCharSet(p, object, n, c);
614         fc_lock.unlock();
615         return ret;
616 }
617
618 #endif