GDK-Win32: Reorganize gdkgdlcontext-win32.c

Group the WGL-specific code and GLES-specific code together, so that we
can reduce the number of #ifdef ... in the code, to make the code more
readable and easily maintained.  This will pave the way to add a
fallback mode to use libANGLE (OpenGL/ES) in case the Desktop OpenGL
support is inadequte, if OpenGL/ES support is enabled in the build.

This is somewhat based on the updates that were done in GTK master, so
we are using one subclass for WGL-based GdkGLContexts, and another for
GLES-based GdkGLContexts.

Also remove the underscores in many of the functions in
gdkglcontext-win32.*.

Clean up the code a bit as a result.
This commit is contained in:
Chun-wei Fan 2021-08-18 18:47:15 +08:00
parent 543b7defec
commit 9e949209a1
6 changed files with 841 additions and 737 deletions

View File

@ -1299,7 +1299,7 @@ gdk_win32_display_class_init (GdkWin32DisplayClass *klass)
display_class->convert_selection = _gdk_win32_display_convert_selection;
display_class->text_property_to_utf8_list = _gdk_win32_display_text_property_to_utf8_list;
display_class->utf8_to_string_target = _gdk_win32_display_utf8_to_string_target;
display_class->make_gl_context_current = _gdk_win32_display_make_gl_context_current;
display_class->make_gl_context_current = gdk_win32_display_make_gl_context_current;
display_class->get_n_monitors = gdk_win32_display_get_n_monitors;
display_class->get_monitor = gdk_win32_display_get_monitor;

View File

@ -33,6 +33,15 @@ typedef enum _GdkWin32ProcessDpiAwareness {
PROCESS_PER_MONITOR_DPI_AWARE = 2
} GdkWin32ProcessDpiAwareness;
/* Define values for GL type used */
typedef enum _GdkWin32GLContextType
{
GDK_WIN32_GL_PENDING,
GDK_WIN32_GL_NONE,
GDK_WIN32_GL_WGL,
GDK_WIN32_GL_EGL
} GdkWin32GLContextType;
/* APIs from shcore.dll */
typedef HRESULT (WINAPI *funcSetProcessDpiAwareness) (GdkWin32ProcessDpiAwareness value);
typedef HRESULT (WINAPI *funcGetProcessDpiAwareness) (HANDLE handle,
@ -81,20 +90,11 @@ struct _GdkWin32Display
HWND hwnd;
HWND clipboard_hwnd;
/* WGL/OpenGL Items */
guint have_wgl : 1;
/* OpenGL Items */
GdkWin32GLContextType gl_type;
guint gl_version;
#ifdef GDK_WIN32_ENABLE_EGL
/* EGL (Angle) Items */
guint have_egl : 1;
guint egl_version;
EGLDisplay egl_disp;
HDC hdc_egl_temp;
#endif
GPtrArray *monitors;
/* WGL Items */
guint hasWglARBCreateContext : 1;
guint hasWglEXTSwapControl : 1;
guint hasWglOMLSyncControl : 1;
@ -104,12 +104,19 @@ struct _GdkWin32Display
/* compensate around Intel OpenGL driver issues on blitting, see issue #3487 */
guint needIntelGLWorkaround : 1;
/* EGL (Angle) Items */
HDC hdc_egl_temp;
#ifdef GDK_WIN32_ENABLE_EGL
EGLDisplay egl_disp;
EGLConfig egl_config;
guint hasEglKHRCreateContext : 1;
guint hasEglSurfacelessContext : 1;
EGLint egl_min_swap_interval;
#endif
GPtrArray *monitors;
/* HiDPI Items */
guint have_at_least_win81 : 1;
GdkWin32ProcessDpiAwareness dpi_aware_type;

View File

@ -3348,7 +3348,7 @@ gdk_event_translate (MSG *msg,
do_show_window (window, msg->wParam == SC_MINIMIZE ? TRUE : FALSE);
if (msg->wParam == SC_RESTORE)
_gdk_win32_window_invalidate_egl_framebuffer (window);
gdk_win32_window_invalidate_egl_framebuffer (window);
break;
case SC_MAXIMIZE:
impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
@ -3436,7 +3436,7 @@ gdk_event_translate (MSG *msg,
{
MINMAXINFO our_mmi;
_gdk_win32_window_invalidate_egl_framebuffer (window);
gdk_win32_window_invalidate_egl_framebuffer (window);
if (_gdk_win32_window_fill_min_max_info (window, &our_mmi))
{

File diff suppressed because it is too large Load Diff

View File

@ -32,62 +32,29 @@
#include "gdkdisplayprivate.h"
#include "gdkvisual.h"
#include "gdkwindow.h"
#include "gdkinternals.h"
#include "gdkmain.h"
G_BEGIN_DECLS
struct _GdkWin32GLContext
{
GdkGLContext parent_instance;
#define GDK_WIN32_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WIN32_GL_CONTEXT, GdkWin32GLContextClass))
#define GDK_WIN32_GL_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WIN32_GL_CONTEXT, GdkWin32GLContextClass))
#define GDK_WIN32_IS_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_WIN32_GL_CONTEXT)
/* WGL Context Items */
HGLRC hglrc;
HDC gl_hdc;
guint need_alpha_bits : 1;
/* other items */
guint is_attached : 1;
guint do_frame_sync : 1;
guint do_blit_swap : 1;
#ifdef GDK_WIN32_ENABLE_EGL
/* EGL (Angle) Context Items */
EGLContext egl_context;
EGLConfig egl_config;
#endif
};
struct _GdkWin32GLContextClass
{
GdkGLContextClass parent_class;
};
void
gdk_win32_window_invalidate_egl_framebuffer (GdkWindow *window);
GdkGLContext *
_gdk_win32_window_create_gl_context (GdkWindow *window,
gboolean attached,
GdkGLContext *share,
GError **error);
gdk_win32_window_create_gl_context (GdkWindow *window,
gboolean attached,
GdkGLContext *share,
GError **error);
void
_gdk_win32_window_invalidate_for_new_frame (GdkWindow *window,
cairo_region_t *update_area);
void
_gdk_win32_gl_context_end_frame (GdkGLContext *context,
cairo_region_t *painted,
cairo_region_t *damage);
gdk_win32_window_invalidate_for_new_frame (GdkWindow *window,
cairo_region_t *update_area);
gboolean
_gdk_win32_display_make_gl_context_current (GdkDisplay *display,
GdkGLContext *context);
gboolean
_gdk_win32_gl_context_realize (GdkGLContext *context,
GError **error);
void
_gdk_win32_window_invalidate_egl_framebuffer (GdkWindow *window);
gdk_win32_display_make_gl_context_current (GdkDisplay *display,
GdkGLContext *context);
G_END_DECLS

View File

@ -1690,7 +1690,7 @@ gdk_win32_window_move_resize (GdkWindow *window,
}
else
{
_gdk_win32_window_invalidate_egl_framebuffer (window);
gdk_win32_window_invalidate_egl_framebuffer (window);
if (with_move)
{
gdk_win32_window_move_resize_internal (window, x, y, width, height);
@ -4758,7 +4758,7 @@ gdk_win32_window_end_move_resize_drag (GdkWindow *window)
GdkW32DragMoveResizeContext *context = &impl->drag_move_resize_context;
if (context->op == GDK_WIN32_DRAGOP_RESIZE)
_gdk_win32_window_invalidate_egl_framebuffer (window);
gdk_win32_window_invalidate_egl_framebuffer (window);
context->op = GDK_WIN32_DRAGOP_NONE;
@ -5279,7 +5279,7 @@ gdk_win32_window_unmaximize (GdkWindow *window)
GDK_WINDOW_HWND (window),
_gdk_win32_window_state_to_string (window->state)));
_gdk_win32_window_invalidate_egl_framebuffer (window);
gdk_win32_window_invalidate_egl_framebuffer (window);
if (GDK_WINDOW_IS_MAPPED (window))
GtkShowWindow (window, SW_RESTORE);
@ -5376,7 +5376,7 @@ gdk_win32_window_unfullscreen (GdkWindow *window)
impl->hint_flags = fi->hint_flags;
SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, fi->style);
_gdk_win32_window_invalidate_egl_framebuffer (window);
gdk_win32_window_invalidate_egl_framebuffer (window);
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_NOTOPMOST,
fi->r.left, fi->r.top,
fi->r.right - fi->r.left, fi->r.bottom - fi->r.top,
@ -6279,8 +6279,8 @@ gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass)
impl_class->get_property = _gdk_win32_window_get_property;
impl_class->change_property = _gdk_win32_window_change_property;
impl_class->delete_property = _gdk_win32_window_delete_property;
impl_class->create_gl_context = _gdk_win32_window_create_gl_context;
impl_class->invalidate_for_new_frame = _gdk_win32_window_invalidate_for_new_frame;
impl_class->create_gl_context = gdk_win32_window_create_gl_context;
impl_class->invalidate_for_new_frame = gdk_win32_window_invalidate_for_new_frame;
impl_class->get_scale_factor = _gdk_win32_window_get_scale_factor;
impl_class->get_unscaled_size = _gdk_win32_window_get_unscaled_size;
}