1 /* This file is part of GEGL.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 3 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
16 * Copyright 2006, 2007 Øyvind Kolås <pippin@gimp.org>
25 #include <glib-object.h>
26 #include <glib/gprintf.h>
29 #include "gegl-types-internal.h"
30 #include "gegl-config.h"
31 #include "gegl-buffer-config.h"
33 #include "opencl/gegl-cl.h"
44 #include <mach/mach.h>
47 #if defined(__APPLE__) || defined(__FreeBSD__)
48 #include <sys/types.h>
49 #include <sys/sysctl.h>
52 G_DEFINE_TYPE (GeglConfig
, gegl_config
, G_TYPE_OBJECT
)
54 static GObjectClass
* parent_class
= NULL
;
63 PROP_SWAP_COMPRESSION
,
69 PROP_APPLICATION_LICENSE
,
73 gint _gegl_threads
= 1;
76 gegl_config_get_property (GObject
*gobject
,
81 GeglConfig
*config
= GEGL_CONFIG (gobject
);
85 case PROP_TILE_CACHE_SIZE
:
86 g_value_set_uint64 (value
, config
->tile_cache_size
);
90 g_value_set_int (value
, config
->chunk_size
);
94 g_value_set_int (value
, config
->tile_width
);
97 case PROP_TILE_HEIGHT
:
98 g_value_set_int (value
, config
->tile_height
);
102 g_value_set_double (value
, config
->quality
);
106 g_value_set_string (value
, config
->swap
);
109 case PROP_SWAP_COMPRESSION
:
110 g_value_set_string (value
, config
->swap_compression
);
114 g_value_set_int (value
, _gegl_threads
);
117 case PROP_USE_OPENCL
:
118 g_value_set_boolean (value
, gegl_cl_is_accelerated());
121 case PROP_QUEUE_SIZE
:
122 g_value_set_int (value
, config
->queue_size
);
125 case PROP_APPLICATION_LICENSE
:
126 g_value_set_string (value
, config
->application_license
);
129 case PROP_MIPMAP_RENDERING
:
130 g_value_set_boolean (value
, config
->mipmap_rendering
);
134 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject
, property_id
, pspec
);
140 gegl_config_set_property (GObject
*gobject
,
145 GeglConfig
*config
= GEGL_CONFIG (gobject
);
149 case PROP_TILE_CACHE_SIZE
:
150 config
->tile_cache_size
= g_value_get_uint64 (value
);
152 case PROP_CHUNK_SIZE
:
153 config
->chunk_size
= g_value_get_int (value
);
155 case PROP_TILE_WIDTH
:
156 config
->tile_width
= g_value_get_int (value
);
158 case PROP_TILE_HEIGHT
:
159 config
->tile_height
= g_value_get_int (value
);
162 config
->quality
= g_value_get_double (value
);
165 g_free (config
->swap
);
166 config
->swap
= g_value_dup_string (value
);
168 case PROP_SWAP_COMPRESSION
:
169 g_free (config
->swap_compression
);
170 config
->swap_compression
= g_value_dup_string (value
);
173 _gegl_threads
= g_value_get_int (value
);
175 case PROP_USE_OPENCL
:
176 config
->use_opencl
= g_value_get_boolean (value
);
178 case PROP_MIPMAP_RENDERING
:
179 config
->mipmap_rendering
= g_value_get_boolean (value
);
181 case PROP_QUEUE_SIZE
:
182 config
->queue_size
= g_value_get_int (value
);
184 case PROP_APPLICATION_LICENSE
:
185 g_free (config
->application_license
);
186 config
->application_license
= g_value_dup_string (value
);
189 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject
, property_id
, pspec
);
195 gegl_config_finalize (GObject
*gobject
)
197 GeglConfig
*config
= GEGL_CONFIG (gobject
);
199 g_free (config
->swap
);
200 g_free (config
->swap_compression
);
201 g_free (config
->application_license
);
203 G_OBJECT_CLASS (gegl_config_parent_class
)->finalize (gobject
);
207 gegl_config_class_init (GeglConfigClass
*klass
)
209 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
211 parent_class
= g_type_class_peek_parent (klass
);
213 gobject_class
->set_property
= gegl_config_set_property
;
214 gobject_class
->get_property
= gegl_config_get_property
;
215 gobject_class
->finalize
= gegl_config_finalize
;
218 g_object_class_install_property (gobject_class
, PROP_TILE_WIDTH
,
219 g_param_spec_int ("tile-width",
221 "default tile width for created buffers.",
224 G_PARAM_STATIC_STRINGS
));
226 g_object_class_install_property (gobject_class
, PROP_TILE_HEIGHT
,
227 g_param_spec_int ("tile-height",
229 "default tile height for created buffers.",
232 G_PARAM_STATIC_STRINGS
));
235 uint64_t default_tile_cache_size
= 1024l * 1024 * 1024;
236 uint64_t mem_total
= default_tile_cache_size
;
237 uint64_t mem_min
= 512 << 20; // 512mb
238 uint64_t mem_available
= mem_min
;
241 # if defined(_MSC_VER) && (_MSC_VER <= 1200)
242 MEMORYSTATUS memory_status
;
243 memory_status
.dwLength
= sizeof (memory_status
);
245 GlobalMemoryStatus (&memory_status
);
246 mem_total
= memory_status
.dwTotalPhys
;
247 mem_available
= memory_status
.dwAvailPhys
;
249 /* requires w2k and newer SDK than provided with msvc6 */
250 MEMORYSTATUSEX memory_status
;
252 memory_status
.dwLength
= sizeof (memory_status
);
254 if (GlobalMemoryStatusEx (&memory_status
))
256 mem_total
= memory_status
.ullTotalPhys
;
257 mem_available
= memory_status
.ullAvailPhys
;
260 #elif defined(__APPLE__)
261 /* get total memory from the HW_MEMSIZE */
263 size_t len
= sizeof usermem
;
264 static int mib
[2] = { CTL_HW
, HW_MEMSIZE
};
266 if (sysctl (mib
, 2, &usermem
, &len
, NULL
, 0) == 0) {
269 /* and available mem from host_statistics64 */
270 vm_size_t page_size
= sysconf (_SC_PAGESIZE
);
271 mach_port_t host
= mach_host_self ();
272 vm_statistics64_data_t vm_stat
;
274 unsigned int count
= HOST_VM_INFO64_COUNT
;
276 kret
= host_statistics64 (host
, HOST_VM_INFO64
, (host_info64_t
)&vm_stat
, &count
);
278 if (kret
== KERN_SUCCESS
)
280 mem_available
= (long) (vm_stat
.free_count
+ vm_stat
.active_count
281 + vm_stat
.inactive_count
282 # ifdef MAC_OS_X_VERSION_10_9
283 + vm_stat
.compressor_page_count
286 mach_port_deallocate (mach_task_self (), host
);
288 #elif defined(__FreeBSD__)
291 unsigned long physmem
;
292 ok
= ok
&& sysctl ((int[2]){ CTL_HW
, HW_PHYSMEM
}, 2, &physmem
,
293 &(size_t){ sizeof physmem
}, NULL
, 0) == 0;
297 uint32_t active_count
;
298 uint32_t wired_count
;
299 ok
= ok
&& sysctlbyname ("vm.stats.vm.v_active_count", &active_count
,
300 &(size_t){ sizeof active_count
}, NULL
, 0) == 0;
301 ok
= ok
&& sysctlbyname ("vm.stats.vm.v_wire_count", &wired_count
,
302 &(size_t){ sizeof wired_count
}, NULL
, 0) == 0;
305 uint32_t laundry_count
;
306 uint64_t zfs_arc_size
;
307 if (sysctlbyname ("vm.stats.vm.v_laundry_count", &laundry_count
,
308 &(size_t){ sizeof laundry_count
}, NULL
, 0) != 0)
310 if (sysctlbyname ("kstat.zfs.misc.arcstats.size", &zfs_arc_size
,
311 &(size_t){ sizeof zfs_arc_size
}, NULL
, 0) != 0)
314 int page_size
= getpagesize ();
315 mem_available
= physmem
- (uint64_t) active_count
* page_size
316 - (uint64_t) wired_count
* page_size
317 - (uint64_t) laundry_count
* page_size
321 mem_total
= (uint64_t) sysconf (_SC_PHYS_PAGES
) * sysconf (_SC_PAGESIZE
);
322 mem_available
= (uint64_t) sysconf (_SC_AVPHYS_PAGES
) * sysconf (_SC_PAGESIZE
);
325 default_tile_cache_size
= mem_total
;
326 if (default_tile_cache_size
> mem_available
)
328 default_tile_cache_size
= mem_available
;
330 if (default_tile_cache_size
< mem_min
)
331 default_tile_cache_size
= mem_min
;
333 if (getenv ("GEGL_BUILD")) /* make .gir reproducible */
334 default_tile_cache_size
= 1024 * 1024 * 256;
336 g_object_class_install_property (gobject_class
, PROP_TILE_CACHE_SIZE
,
337 g_param_spec_uint64 ("tile-cache-size",
339 "size of tile cache in bytes",
340 0, G_MAXUINT64
, default_tile_cache_size
,
342 G_PARAM_STATIC_STRINGS
));
345 g_object_class_install_property (gobject_class
, PROP_CHUNK_SIZE
,
346 g_param_spec_int ("chunk-size",
348 "the number of pixels processed simultaneously by GEGL.",
349 1, G_MAXINT
, 1024 * 1024,
351 G_PARAM_STATIC_STRINGS
|
354 g_object_class_install_property (gobject_class
, PROP_QUALITY
,
355 g_param_spec_double ("quality",
357 "quality/speed trade off 1.0 = full quality, 0.0 = full speed",
360 G_PARAM_STATIC_STRINGS
|
363 g_object_class_install_property (gobject_class
, PROP_SWAP
,
364 g_param_spec_string ("swap",
366 "where gegl stores it's swap files",
369 G_PARAM_STATIC_STRINGS
));
371 g_object_class_install_property (gobject_class
, PROP_SWAP_COMPRESSION
,
372 g_param_spec_string ("swap-compression",
374 "compression algorithm used for data stored in the swap",
377 G_PARAM_STATIC_STRINGS
));
379 _gegl_threads
= g_get_num_processors ();
380 _gegl_threads
= MIN (_gegl_threads
, GEGL_MAX_THREADS
);
382 if (getenv ("GEGL_BUILD")) // to make .gir reproducible
383 _gegl_threads
= GEGL_MAX_THREADS
;
385 g_object_class_install_property (gobject_class
, PROP_THREADS
,
386 g_param_spec_int ("threads",
388 "Number of concurrent evaluation threads",
392 G_PARAM_STATIC_STRINGS
|
395 g_object_class_install_property (gobject_class
, PROP_MIPMAP_RENDERING
,
396 g_param_spec_boolean ("mipmap-rendering",
398 "Enable code paths for mipmap preview rendering, uses approximations for 50% 25% etc zoom factors to reduce processing.",
401 G_PARAM_STATIC_STRINGS
|
404 g_object_class_install_property (gobject_class
, PROP_USE_OPENCL
,
405 g_param_spec_boolean ("use-opencl",
410 G_PARAM_STATIC_STRINGS
|
413 g_object_class_install_property (gobject_class
, PROP_QUEUE_SIZE
,
414 g_param_spec_int ("queue-size",
416 "Maximum size of a file backend's writer thread queue (in bytes)",
417 2, G_MAXINT
, 50 * 1024 *1024,
419 G_PARAM_STATIC_STRINGS
));
421 g_object_class_install_property (gobject_class
, PROP_APPLICATION_LICENSE
,
422 g_param_spec_string ("application-license",
423 "Application license",
424 "A list of additional licenses to allow for operations",
427 G_PARAM_STATIC_STRINGS
|
432 gegl_config_init (GeglConfig
*self
)
434 char *forward_props
[]={"swap",
441 GeglBufferConfig
*bconf
= gegl_buffer_config ();
442 for (int i
= 0; forward_props
[i
]; i
++)
443 g_object_bind_property (bconf
, forward_props
[i
],
444 self
, forward_props
[i
],
445 G_BINDING_BIDIRECTIONAL
| G_BINDING_SYNC_CREATE
);
448 #undef gegl_config_threads
449 int gegl_config_threads(void);
450 int gegl_config_threads(void)
452 return _gegl_threads
;