Compare commits

...

5 Commits

Author SHA1 Message Date
Chun-wei Fan 4ecff75743 cogl/cogl-debug.h: Export and properly use _cogl_debug_instances
We need to also export the extern variables _cogl_debug_instances its
consumption in Cogl-Path, so that it can be properly referred to by
Cogl-Path and hence any other libraries that make use of them, such as
Clutter.

On Visual Studio DLL builds, this *must* also be marked with
__declspec(dllimport) when Cogl-Path is being built against Cogl so that
it can be referred to properly, otherwise one will be subject to crashes
as a result.
2020-11-20 11:04:00 +08:00
Chun-wei Fan 0e67927a50 cogl-crate.c: Fix running on 64-bit Windows
CoglPollFD uses an int type for its fd member but the GPollFD that
g_poll() expects uses a gint64 type (a.k.a int64_t, __in64 on Windows)
for its fd member on 64-bit Windows, which will cause loads of
"WaitForMultipleObjectsEx failed:..." to be spewed from GLib on 64-bit
Windows.

This updates the example to use the correct types for the g_poll() call,
which will avoid this kind of situation.
2020-11-20 11:04:00 +08:00
Chun-wei Fan 11ce620d7f cogl/cogl-bitmask.h: Use size_t instead of unsigned long
Using unsigned long is not safe as sizeof(long) is not necessary
sizeof(void*) on some platforms, such as Windows on Visual Studio.  To
avoid this, use size_t instead of unsized long, and use the correct
unsigned suffix accordingly.
2020-11-20 11:04:00 +08:00
Chun-wei Fan 1247a92940 cogl/cogl.c: Do not hardcode COGL_LOCALEDIR on Windows
Instead, we construct it according to where the Cogl DLL is found, as it
is likely that the Cogl DLL will land in somewhere that is not the
initial $(PREFIX)\bin on Windows.
2020-11-20 11:04:00 +08:00
Chun-wei Fan 464ec64ac6 cogl-winsys-sdl2.c: Fix running on 32-bit Windows
When we query for GL APIs, we need to ensure that we are using the
correct calling convention, otherwise running on 32-bit Windows will
crash.
2020-11-20 11:04:00 +08:00
5 changed files with 45 additions and 15 deletions

View File

@ -62,19 +62,25 @@ COGL_BEGIN_DECLS
typedef struct _CoglBitmaskImaginaryType *CoglBitmask;
/* These are internal helper macros */
#if defined (G_OS_WIN32) && (GLIB_SIZEOF_VOID_P == 8)
# define COGL_PTR_APPEND_SUFFIX(x) x##ULL
#else
# define COGL_PTR_APPEND_SUFFIX(x) x##UL
#endif
#define _cogl_bitmask_to_number(bitmask) \
((unsigned long) (*bitmask))
((size_t) (*bitmask))
#define _cogl_bitmask_to_bits(bitmask) \
(_cogl_bitmask_to_number (bitmask) >> 1UL)
(_cogl_bitmask_to_number (bitmask) >> COGL_PTR_APPEND_SUFFIX (1))
/* The least significant bit is set to mark that no array has been
allocated yet */
#define _cogl_bitmask_from_bits(bits) \
((void *) ((((unsigned long) (bits)) << 1UL) | 1UL))
((void *) ((((size_t) (bits)) << COGL_PTR_APPEND_SUFFIX (1)) | COGL_PTR_APPEND_SUFFIX (1)))
/* Internal helper macro to determine whether this bitmask has a
GArray allocated or whether the pointer is just used directly */
#define _cogl_bitmask_has_array(bitmask) \
(!(_cogl_bitmask_to_number (bitmask) & 1UL))
(!(_cogl_bitmask_to_number (bitmask) & COGL_PTR_APPEND_SUFFIX (1)))
/* Number of bits we can use before needing to allocate an array */
#define COGL_BITMASK_MAX_DIRECT_BITS (sizeof (unsigned long) * 8 - 1)
@ -173,7 +179,7 @@ _cogl_bitmask_get (const CoglBitmask *bitmask, unsigned int bit_num)
else if (bit_num >= COGL_BITMASK_MAX_DIRECT_BITS)
return FALSE;
else
return !!(_cogl_bitmask_to_bits (bitmask) & (1UL << bit_num));
return !!(_cogl_bitmask_to_bits (bitmask) & (COGL_PTR_APPEND_SUFFIX (1) << bit_num));
}
/*
@ -192,10 +198,10 @@ _cogl_bitmask_set (CoglBitmask *bitmask, unsigned int bit_num, CoglBool value)
_cogl_bitmask_set_in_array (bitmask, bit_num, value);
else if (value)
*bitmask = _cogl_bitmask_from_bits (_cogl_bitmask_to_bits (bitmask) |
(1UL << bit_num));
(COGL_PTR_APPEND_SUFFIX (1) << bit_num));
else
*bitmask = _cogl_bitmask_from_bits (_cogl_bitmask_to_bits (bitmask) &
~(1UL << bit_num));
~(COGL_PTR_APPEND_SUFFIX (1) << bit_num));
}
/*
@ -304,7 +310,7 @@ _cogl_bitmask_popcount_upto (const CoglBitmask *bitmask,
return _cogl_util_popcountl (_cogl_bitmask_to_bits (bitmask));
else
return _cogl_util_popcountl (_cogl_bitmask_to_bits (bitmask) &
((1UL << upto) - 1));
((COGL_PTR_APPEND_SUFFIX (1) << upto) - 1));
}
COGL_END_DECLS

View File

@ -79,12 +79,13 @@ typedef enum {
COGL_DEBUG_N_FLAGS
} CoglDebugFlags;
extern GHashTable *_cogl_debug_instances;
/* _cogl_debug_flags and _cogl_debug_instances currently needs to exported
* outside of the shared library for cogl-pango and cogl-path. The special
* COGL_EXPORT macro is needed to get this to work when building with MSVC.
*/
COGL_EXPORT extern GHashTable *_cogl_debug_instances;
#define COGL_DEBUG_N_LONGS COGL_FLAGS_N_LONGS_FOR_SIZE (COGL_DEBUG_N_FLAGS)
/* _cogl_debug_flags currently needs to exported outside of the shared
library for cogl-pango. The special COGL_EXPORT macro is needed to
get this to work when building with MSVC */
COGL_EXPORT extern unsigned long _cogl_debug_flags[COGL_DEBUG_N_LONGS];
#define COGL_DEBUG_ENABLED(flag) \

View File

@ -758,8 +758,17 @@ _cogl_init (void)
if (initialized == FALSE)
{
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, COGL_LOCALEDIR);
char *localedir = NULL;
#ifdef _WIN32
char *basedir = g_win32_get_package_installation_directory_of_module (NULL);
localedir = g_build_filename (basedir, "share", "locale", NULL);
g_free (basedir);
#else
localedir = g_strdup (COGL_LOCALEDIR);
#endif
bindtextdomain (GETTEXT_PACKAGE, localedir);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
g_free (localedir);
#endif
#if defined(COGL_HAS_GTYPE_SUPPORT) && !GLIB_CHECK_VERSION (2, 36, 0)

View File

@ -48,6 +48,10 @@
#include "cogl-poll-private.h"
#include "cogl-sdl.h"
#ifndef APIENTRY
# define APIENTRY
#endif
typedef struct _CoglContextSdl2
{
SDL_Window *current_window;
@ -158,7 +162,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
CoglError **error)
{
CoglDisplaySdl2 *sdl_display;
const char * (* get_string_func) (GLenum name);
const char * (APIENTRY * get_string_func) (GLenum name);
const char *gl_version;
_COGL_RETURN_VAL_IF_FAIL (display->winsys == NULL, FALSE);

View File

@ -276,6 +276,7 @@ main (int argc, char **argv)
while (1)
{
CoglPollFD *poll_fds;
GPollFD gpoll_fds;
int n_poll_fds;
int64_t timeout;
@ -288,9 +289,18 @@ main (int argc, char **argv)
cogl_poll_renderer_get_info (cogl_context_get_renderer (ctx),
&poll_fds, &n_poll_fds, &timeout);
g_poll ((GPollFD *) poll_fds, n_poll_fds,
#if !defined G_OS_WIN32 || (GLIB_SIZEOF_VOID_P == 4)
gpoll_fds.fd = (int) poll_fds->fd;
#else
gpoll_fds.fd = (int64_t) poll_fds->fd;
#endif
gpoll_fds.events = poll_fds->events;
gpoll_fds.revents = poll_fds->revents;
g_poll (&gpoll_fds, n_poll_fds,
timeout == -1 ? -1 : timeout / 1000);
cogl_poll_renderer_dispatch (cogl_context_get_renderer (ctx),
poll_fds, n_poll_fds);
}