]> Pileus Git - ~andy/gtk/blob - gdk/gdkmedialib.c
597726824b5699084f3c23f9f8c972d36c115459
[~andy/gtk] / gdk / gdkmedialib.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2001-2007 Sun Microsystems, Inc.  All rights reserved.
3  * (Brian Cameron, Dmitriy Demin, James Cheng, Padraig O'Briain)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Modified by the GTK+ Team and others 1997-2007.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
26  */
27
28 #include "config.h"
29
30 #include "gdkmedialib.h"
31
32 #include <stdlib.h>
33 #include <dlfcn.h>
34
35 #ifdef HAVE_STRINGS_H
36 #include <strings.h>
37 #endif
38
39 #ifdef HAVE_STRING_H
40 #include <string.h>
41 #endif
42
43 #if defined(HAVE_SYS_SYSTEMINFO_H)
44 #include <sys/systeminfo.h>
45 #elif defined(HAVE_SYS_SYSINFO_H)
46 #include <sys/sysinfo.h>
47 #endif
48
49 typedef char *      (*ml_version)         (void);
50
51 static ml_version                 medialib_version = mlib_version;
52
53 gboolean 
54 _gdk_use_medialib (void)
55 {
56   char *mlib_version_string;
57   char sys_info[257];
58   long count;
59
60   /*
61    * Sun mediaLib(tm) support.
62    *
63    *   http://www.sun.com/processors/vis/mlib.html
64    *
65    */
66   if (getenv ("GDK_DISABLE_MEDIALIB"))
67     return FALSE;
68
69   /*
70    * The imaging functions we want to use were added in mediaLib version 2.
71    * So turn off mediaLib support if the user has an older version.
72    * mlib_version returns a string in this format:
73    *
74    * mediaLib:0210:20011101:v8plusa
75    * ^^^^^^^^ ^^^^ ^^^^^^^^ ^^^^^^^
76    * libname  vers build    ISALIST identifier
77    *               date     (in this case sparcv8plus+vis)
78    *
79    * The first 2 digits of the version are the major version.  The 3rd digit
80    * is the minor version, and the 4th digit is the micro version. So the
81    * above string corresponds to version 2.1.0.In the following test we only
82    * care about the major version.
83    */
84    mlib_version_string = medialib_version ();
85
86    count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257);
87              
88    if (count != -1)
89      {
90        if (strcmp (sys_info, "i386") == 0)
91          {
92            char *mlib_target_isa = &mlib_version_string[23];
93   
94            /*
95             * For x86 processors mediaLib generic C implementation
96             * does not give any performance advantage so disable it.
97             */
98            if (strncmp (mlib_target_isa, "sse", 3) != 0)
99              {
100                return FALSE;
101              }
102
103            /*
104             * For x86 processors use of libumem conflicts with
105             * mediaLib, so avoid using it.
106             */
107            if (dlsym (RTLD_PROBE,   "umem_alloc") != NULL)
108              {
109                return FALSE;
110              }
111          }
112      }
113    else
114      {
115        /* Failed to get system architecture, disable mediaLib */
116        return FALSE;
117      }
118
119   return TRUE;
120 }