gtk: Port GtkWindow to render nodes

WARNING: BROKEN COMMIT
This commit is contained in:
Emmanuele Bassi 2016-07-27 09:42:25 +01:00
parent cd0de3f87c
commit f0c04cdd09

View File

@ -36,6 +36,7 @@
#include "gtkwindowprivate.h" #include "gtkwindowprivate.h"
#include "gtkaccelgroupprivate.h" #include "gtkaccelgroupprivate.h"
#include "gtkbindings.h" #include "gtkbindings.h"
#include "gtkcontainerprivate.h"
#include "gtkcsscornervalueprivate.h" #include "gtkcsscornervalueprivate.h"
#include "gtkcssiconthemevalueprivate.h" #include "gtkcssiconthemevalueprivate.h"
#include "gtkcssrgbavalueprivate.h" #include "gtkcssrgbavalueprivate.h"
@ -447,6 +448,8 @@ static gboolean gtk_window_enable_debugging (GtkWindow *window,
gboolean toggle); gboolean toggle);
static gint gtk_window_draw (GtkWidget *widget, static gint gtk_window_draw (GtkWidget *widget,
cairo_t *cr); cairo_t *cr);
static GskRenderNode *gtk_window_get_render_node (GtkWidget *widget,
GskRenderer *renderer);
static void gtk_window_unset_transient_for (GtkWindow *window); static void gtk_window_unset_transient_for (GtkWindow *window);
static void gtk_window_transient_parent_realized (GtkWidget *parent, static void gtk_window_transient_parent_realized (GtkWidget *parent,
GtkWidget *window); GtkWidget *window);
@ -703,7 +706,6 @@ gtk_window_class_init (GtkWindowClass *klass)
widget_class->focus_out_event = gtk_window_focus_out_event; widget_class->focus_out_event = gtk_window_focus_out_event;
widget_class->focus = gtk_window_focus; widget_class->focus = gtk_window_focus;
widget_class->move_focus = gtk_window_move_focus; widget_class->move_focus = gtk_window_move_focus;
widget_class->draw = gtk_window_draw;
widget_class->window_state_event = gtk_window_state_event; widget_class->window_state_event = gtk_window_state_event;
widget_class->get_preferred_width = gtk_window_get_preferred_width; widget_class->get_preferred_width = gtk_window_get_preferred_width;
widget_class->get_preferred_width_for_height = gtk_window_get_preferred_width_for_height; widget_class->get_preferred_width_for_height = gtk_window_get_preferred_width_for_height;
@ -711,6 +713,7 @@ gtk_window_class_init (GtkWindowClass *klass)
widget_class->get_preferred_height_for_width = gtk_window_get_preferred_height_for_width; widget_class->get_preferred_height_for_width = gtk_window_get_preferred_height_for_width;
widget_class->state_flags_changed = gtk_window_state_flags_changed; widget_class->state_flags_changed = gtk_window_state_flags_changed;
widget_class->style_updated = gtk_window_style_updated; widget_class->style_updated = gtk_window_style_updated;
widget_class->get_render_node = gtk_window_get_render_node;
container_class->remove = gtk_window_remove; container_class->remove = gtk_window_remove;
container_class->check_resize = gtk_window_check_resize; container_class->check_resize = gtk_window_check_resize;
@ -6844,12 +6847,8 @@ gtk_window_realize (GtkWidget *widget)
if (priv->renderer == NULL) if (priv->renderer == NULL)
{ {
graphene_rect_t viewport;
priv->renderer = gsk_renderer_get_for_display (gtk_widget_get_display (widget)); priv->renderer = gsk_renderer_get_for_display (gtk_widget_get_display (widget));
gsk_renderer_set_scale_factor (priv->renderer, gtk_widget_get_scale_factor (widget));
graphene_rect_init (&viewport, 0, 0, allocation.width, allocation.height);
gsk_renderer_set_viewport (priv->renderer, &viewport);
} }
if (gtk_widget_get_parent_window (widget)) if (gtk_widget_get_parent_window (widget))
@ -7254,13 +7253,17 @@ _gtk_window_set_allocation (GtkWindow *window,
graphene_matrix_t projection; graphene_matrix_t projection;
graphene_matrix_t modelview; graphene_matrix_t modelview;
graphene_point3d_t tmp; graphene_point3d_t tmp;
int scale;
scale = gtk_widget_get_scale_factor (widget);
gsk_renderer_set_scale_factor (priv->renderer, scale);
graphene_rect_init (&viewport, 0, 0, allocation->width, allocation->height); graphene_rect_init (&viewport, 0, 0, allocation->width, allocation->height);
gsk_renderer_set_viewport (priv->renderer, &viewport); gsk_renderer_set_viewport (priv->renderer, &viewport);
graphene_matrix_init_ortho (&projection, graphene_matrix_init_ortho (&projection,
0, allocation->width, 0, allocation->width * scale,
0, allocation->height, 0, allocation->height * scale,
-1, 1); -1, 1);
gsk_renderer_set_projection (priv->renderer, &projection); gsk_renderer_set_projection (priv->renderer, &projection);
@ -9571,98 +9574,107 @@ gtk_window_compute_hints (GtkWindow *window,
* Redrawing functions * * Redrawing functions *
***********************/ ***********************/
static gboolean static GskRenderNode *
gtk_window_draw (GtkWidget *widget, gtk_window_get_render_node (GtkWidget *widget,
cairo_t *cr) GskRenderer *renderer)
{ {
GtkWindowPrivate *priv = GTK_WINDOW (widget)->priv; GtkWindowPrivate *priv = GTK_WINDOW (widget)->priv;
GtkStyleContext *context; GtkStyleContext *context;
gboolean ret = FALSE; GskRenderNode *node;
GtkAllocation allocation; GtkAllocation allocation;
GtkBorder window_border; GtkBorder window_border;
gint title_height; gint title_height;
graphene_rect_t bounds;
graphene_matrix_t m;
graphene_point3d_t p;
cairo_t *cr;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
get_shadow_width (GTK_WINDOW (widget), &window_border); get_shadow_width (GTK_WINDOW (widget), &window_border);
_gtk_widget_get_allocation (widget, &allocation); _gtk_widget_get_allocation (widget, &allocation);
if (gtk_cairo_should_draw_window (cr, _gtk_widget_get_window (widget))) graphene_rect_init (&bounds, allocation.x, allocation.y, allocation.width, allocation.height);
graphene_matrix_init_translate (&m, graphene_point3d_init (&p, allocation.x, allocation.y, 0.));
node = gsk_render_node_new ();
gsk_render_node_set_name (node, "Window Decoration");
gsk_render_node_set_bounds (node, &bounds);
gsk_render_node_set_transform (node, &m);
cr = gsk_render_node_get_draw_context (node);
if (priv->client_decorated &&
priv->decorated &&
!priv->fullscreen &&
!priv->maximized)
{ {
if (priv->client_decorated && gtk_style_context_save_to_node (context, priv->decoration_node);
priv->decorated &&
!priv->fullscreen && if (priv->use_client_shadow)
!priv->maximized)
{ {
gtk_style_context_save_to_node (context, priv->decoration_node); GtkBorder padding, border;
if (priv->use_client_shadow) gtk_style_context_get_padding (context, &padding);
{ gtk_style_context_get_border (context, &border);
GtkBorder padding, border; sum_borders (&border, &padding);
gtk_style_context_get_padding (context, &padding); gtk_render_background (context, cr,
gtk_style_context_get_border (context, &border); window_border.left - border.left, window_border.top - border.top,
sum_borders (&border, &padding); allocation.width -
(window_border.left + window_border.right - border.left - border.right),
gtk_render_background (context, cr, allocation.height -
window_border.left - border.left, window_border.top - border.top, (window_border.top + window_border.bottom - border.top - border.bottom));
allocation.width - gtk_render_frame (context, cr,
(window_border.left + window_border.right - border.left - border.right), window_border.left - border.left, window_border.top - border.top,
allocation.height - allocation.width -
(window_border.top + window_border.bottom - border.top - border.bottom)); (window_border.left + window_border.right - border.left - border.right),
gtk_render_frame (context, cr, allocation.height -
window_border.left - border.left, window_border.top - border.top, (window_border.top + window_border.bottom - border.top - border.bottom));
allocation.width -
(window_border.left + window_border.right - border.left - border.right),
allocation.height -
(window_border.top + window_border.bottom - border.top - border.bottom));
}
else
{
gtk_render_background (context, cr, 0, 0,
allocation.width,
allocation.height);
gtk_render_frame (context, cr, 0, 0,
allocation.width,
allocation.height);
}
gtk_style_context_restore (context);
} }
else
if (!gtk_widget_get_app_paintable (widget))
{ {
if (priv->title_box && gtk_render_background (context, cr, 0, 0,
gtk_widget_get_visible (priv->title_box) && allocation.width,
gtk_widget_get_child_visible (priv->title_box)) allocation.height);
title_height = priv->title_height;
else
title_height = 0;
gtk_render_background (context, cr, gtk_render_frame (context, cr, 0, 0,
window_border.left, allocation.width,
window_border.top + title_height, allocation.height);
allocation.width - }
(window_border.left + window_border.right), gtk_style_context_restore (context);
allocation.height - }
(window_border.top + window_border.bottom +
title_height)); if (!gtk_widget_get_app_paintable (widget))
gtk_render_frame (context, cr, {
if (priv->title_box &&
gtk_widget_get_visible (priv->title_box) &&
gtk_widget_get_child_visible (priv->title_box))
title_height = priv->title_height;
else
title_height = 0;
gtk_render_background (context, cr,
window_border.left, window_border.left,
window_border.top + title_height, window_border.top + title_height,
allocation.width - allocation.width -
(window_border.left + window_border.right), (window_border.left + window_border.right),
allocation.height - allocation.height -
(window_border.top + window_border.bottom + (window_border.top + window_border.bottom + title_height));
title_height)); gtk_render_frame (context, cr,
} window_border.left,
window_border.top + title_height,
allocation.width -
(window_border.left + window_border.right),
allocation.height -
(window_border.top + window_border.bottom + title_height));
} }
if (GTK_WIDGET_CLASS (gtk_window_parent_class)->draw) cairo_destroy (cr);
ret = GTK_WIDGET_CLASS (gtk_window_parent_class)->draw (widget, cr);
return ret; gtk_container_propagate_render_node (GTK_CONTAINER (widget), renderer, node);
return node;
} }
/** /**