gsk: Fold gsk_renderer_begin_draw_frame() into renderer

It doesn't need to be exported anymore.

As a side effect, the inspector no longer has any information about the
render region, so remove the code that was taking care of that.
This commit is contained in:
Benjamin Otte 2018-03-28 01:29:39 +02:00
parent b19d7630ae
commit d0873c7dec
12 changed files with 36 additions and 187 deletions

View File

@ -5,8 +5,6 @@ gsk_renderer_get_surface
gsk_renderer_get_display
gsk_renderer_realize
gsk_renderer_unrealize
gsk_renderer_begin_draw_frame
gsk_renderer_end_draw_frame
gsk_renderer_render
gsk_renderer_render_texture
<SUBSECTION Standard>

View File

@ -24,9 +24,8 @@
* #GskRenderer is a class that renders a scene graph defined via a
* tree of #GskRenderNode instances.
*
* Typically you will use a #GskRenderer instance with a #GdkDrawingContext
* associated to a #GdkSurface, and call gsk_renderer_render() with the
* drawing context and the scene to be rendered.
* Typically you will use a #GskRenderer instance to repeatedly call
* gsk_renderer_render() to update the contents of its associated #GdkSurface.
*
* It is necessary to realize a #GskRenderer instance using gsk_renderer_realize()
* before calling gsk_renderer_render(), in order to create the appropriate
@ -505,18 +504,24 @@ gsk_renderer_render_texture (GskRenderer *renderer,
* gsk_renderer_render:
* @renderer: a #GskRenderer
* @root: a #GskRenderNode
* @context: The drawing context created via gsk_renderer_begin_draw_frame()
* @region: the #cairo_region_t that must be redrawn or %NULL for the whole
* window
*
* Renders the scene graph, described by a tree of #GskRenderNode instances,
* using the given #GdkDrawingContext.
* ensuring that the given @region gets redrawn.
*
* Renderers must ensure that changes of the contents given by the @root
* node as well as the area given by @region are redrawn. They are however
* free to not redraw any pixel outside of @region if they can guarantee that
* it didn't change.
*
* The @renderer will acquire a reference on the #GskRenderNode tree while
* the rendering is in progress.
*/
void
gsk_renderer_render (GskRenderer *renderer,
GskRenderNode *root,
GdkDrawingContext *context)
gsk_renderer_render (GskRenderer *renderer,
GskRenderNode *root,
const cairo_region_t *region)
{
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
@ -524,11 +529,26 @@ gsk_renderer_render (GskRenderer *renderer,
g_return_if_fail (priv->is_realized);
g_return_if_fail (GSK_IS_RENDER_NODE (root));
g_return_if_fail (priv->root_node == NULL);
g_return_if_fail (GDK_IS_DRAWING_CONTEXT (context));
g_return_if_fail (context == priv->drawing_context);
priv->root_node = gsk_render_node_ref (root);
if (region == NULL || GSK_RENDERER_DEBUG_CHECK (renderer, FULL_REDRAW))
{
cairo_region_t *full_surface;
full_surface = cairo_region_create_rectangle (&(GdkRectangle) {
0, 0,
gdk_surface_get_width (priv->surface),
gdk_surface_get_height (priv->surface)
});
priv->drawing_context = GSK_RENDERER_GET_CLASS (renderer)->begin_draw_frame (renderer, full_surface);
cairo_region_destroy (full_surface);
}
else
priv->drawing_context = GSK_RENDERER_GET_CLASS (renderer)->begin_draw_frame (renderer, region);
GSK_RENDERER_GET_CLASS (renderer)->render (renderer, root);
#ifdef G_ENABLE_DEBUG
@ -548,6 +568,9 @@ gsk_renderer_render (GskRenderer *renderer,
}
#endif
GSK_RENDERER_GET_CLASS (renderer)->end_draw_frame (renderer, priv->drawing_context);
priv->drawing_context = NULL;
g_clear_pointer (&priv->root_node, gsk_render_node_unref);
}
@ -722,75 +745,6 @@ gsk_renderer_new_for_surface (GdkSurface *surface)
return NULL;
}
/**
* gsk_renderer_begin_draw_frame:
* @renderer: a #GskRenderer
* @region: the #cairo_region_t that you wish to draw
*
* Indicates that you are beginning the process of redrawing @region using
* @renderer, and provides you with a #GdkDrawingContext to use for this.
*
* Returns: (transfer none): a #GdkDrawingContext context that should be used to
* draw the contents of the @renderer. This context is owned by GDK.
*/
GdkDrawingContext *
gsk_renderer_begin_draw_frame (GskRenderer *renderer,
const cairo_region_t *region)
{
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL);
g_return_val_if_fail (region != NULL, NULL);
g_return_val_if_fail (priv->drawing_context == NULL, NULL);
#ifdef G_ENABLE_DEBUG
if (GSK_RENDERER_DEBUG_CHECK (renderer, FULL_REDRAW))
{
cairo_region_t *full_surface;
full_surface = cairo_region_create_rectangle (&(GdkRectangle) {
0, 0,
gdk_surface_get_width (priv->surface),
gdk_surface_get_height (priv->surface)
});
priv->drawing_context = GSK_RENDERER_GET_CLASS (renderer)->begin_draw_frame (renderer, full_surface);
cairo_region_destroy (full_surface);
}
else
#endif
priv->drawing_context = GSK_RENDERER_GET_CLASS (renderer)->begin_draw_frame (renderer, region);
return priv->drawing_context;
}
/**
* gsk_renderer_end_draw_frame:
* @renderer: a #GskRenderer
* @context: the drawing context returned by the matching call to
* gsk_renderer_begin_draw_frame()
*
* Release the drawning context returned by gsk_renderer_begin_draw_frame().
*
* Calls to gsk_renderer_begin_draw_frame() and gsk_renderer_end_draw_frame()
* must be paired.
*/
void
gsk_renderer_end_draw_frame (GskRenderer *renderer,
GdkDrawingContext *context)
{
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
g_return_if_fail (GSK_IS_RENDERER (renderer));
g_return_if_fail (GDK_IS_DRAWING_CONTEXT (context));
g_return_if_fail (priv->drawing_context == context);
priv->drawing_context = NULL;
GSK_RENDERER_GET_CLASS (renderer)->end_draw_frame (renderer, context);
}
GskDebugFlags
gsk_renderer_get_debug_flags (GskRenderer *renderer)
{

View File

@ -60,15 +60,9 @@ GdkTexture * gsk_renderer_render_texture (GskRenderer
const graphene_rect_t *viewport);
GDK_AVAILABLE_IN_ALL
GdkDrawingContext * gsk_renderer_begin_draw_frame (GskRenderer *renderer,
const cairo_region_t *region);
GDK_AVAILABLE_IN_ALL
void gsk_renderer_render (GskRenderer *renderer,
GskRenderNode *root,
GdkDrawingContext *context);
GDK_AVAILABLE_IN_ALL
void gsk_renderer_end_draw_frame (GskRenderer *renderer,
GdkDrawingContext *context);
const cairo_region_t *region);
G_END_DECLS

View File

@ -14046,7 +14046,6 @@ gtk_widget_render (GtkWidget *widget,
GdkSurface *surface,
const cairo_region_t *region)
{
GdkDrawingContext *context;
GtkSnapshot *snapshot;
GskRenderer *renderer;
GskRenderNode *root;
@ -14067,19 +14066,15 @@ gtk_widget_render (GtkWidget *widget,
if (root != NULL)
{
context = gsk_renderer_begin_draw_frame (renderer, region);
gtk_inspector_record_render (widget,
renderer,
surface,
region,
context,
root);
gsk_renderer_render (renderer, root, context);
gsk_render_node_unref (root);
gsk_renderer_render (renderer, root, region);
gsk_renderer_end_draw_frame (renderer, context);
gsk_render_node_unref (root);
}
}

View File

@ -105,8 +105,6 @@ recordings_list_row_selected (GtkListBox *box,
gtk_inspector_render_recording_get_node (GTK_INSPECTOR_RENDER_RECORDING (recording)));
gtk_render_node_view_set_clip_region (GTK_RENDER_NODE_VIEW (priv->render_node_view),
gtk_inspector_render_recording_get_clip_region (GTK_INSPECTOR_RENDER_RECORDING (recording)));
gtk_render_node_view_set_render_region (GTK_RENDER_NODE_VIEW (priv->render_node_view),
gtk_inspector_render_recording_get_render_region (GTK_INSPECTOR_RENDER_RECORDING (recording)));
gtk_render_node_view_set_viewport (GTK_RENDER_NODE_VIEW (priv->render_node_view),
gtk_inspector_render_recording_get_area (GTK_INSPECTOR_RENDER_RECORDING (recording)));
gtk_tree_model_render_node_set_root_node (GTK_TREE_MODEL_RENDER_NODE (priv->render_node_model),
@ -1075,18 +1073,15 @@ gtk_inspector_recorder_record_render (GtkInspectorRecorder *recorder,
GskRenderer *renderer,
GdkSurface *surface,
const cairo_region_t *region,
GdkDrawingContext *context,
GskRenderNode *node)
{
GtkInspectorRecording *recording;
GdkFrameClock *frame_clock;
cairo_region_t *clip;
if (!gtk_inspector_recorder_is_recording (recorder))
return;
frame_clock = gtk_widget_get_frame_clock (widget);
clip = gdk_drawing_context_get_clip (context);
recording = gtk_inspector_render_recording_new (gdk_frame_clock_get_frame_time (frame_clock),
gsk_renderer_get_profiler (renderer),
@ -1094,11 +1089,9 @@ gtk_inspector_recorder_record_render (GtkInspectorRecorder *recorder,
gdk_surface_get_width (surface),
gdk_surface_get_height (surface) },
region,
clip,
node);
gtk_inspector_recorder_add_recording (recorder, recording);
g_object_unref (recording);
cairo_region_destroy (clip);
}
void

View File

@ -56,7 +56,6 @@ void gtk_inspector_recorder_record_render (GtkInspectorRec
GskRenderer *renderer,
GdkSurface *surface,
const cairo_region_t *region,
GdkDrawingContext *context,
GskRenderNode *node);
G_END_DECLS

View File

@ -34,7 +34,6 @@ struct _GtkRenderNodeViewPrivate
{
GdkRectangle viewport;
GskRenderNode *render_node;
cairo_region_t *render_region;
cairo_region_t *clip_region;
};
@ -43,7 +42,6 @@ enum
PROP_0,
PROP_VIEWPORT,
PROP_RENDER_NODE,
PROP_RENDER_REGION,
PROP_CLIP_REGION,
LAST_PROP
};
@ -110,10 +108,6 @@ gtk_render_node_view_get_property (GObject *object,
g_value_set_pointer (value, priv->render_node);
break;
case PROP_RENDER_REGION:
g_value_set_boxed (value, priv->render_region);
break;
case PROP_CLIP_REGION:
g_value_set_boxed (value, priv->clip_region);
break;
@ -142,10 +136,6 @@ gtk_render_node_view_set_property (GObject *object,
gtk_render_node_view_set_render_node (view, g_value_get_pointer (value));
break;
case PROP_RENDER_REGION:
gtk_render_node_view_set_render_region (view, g_value_get_boxed (value));
break;
case PROP_CLIP_REGION:
gtk_render_node_view_set_clip_region (view, g_value_get_boxed (value));
break;
@ -163,7 +153,6 @@ gtk_render_node_view_dispose (GObject *object)
GtkRenderNodeViewPrivate *priv = gtk_render_node_view_get_instance_private (view);
g_clear_pointer (&priv->render_node, gsk_render_node_unref);
g_clear_pointer (&priv->render_region, cairo_region_destroy);
g_clear_pointer (&priv->clip_region, cairo_region_destroy);
G_OBJECT_CLASS (gtk_render_node_view_parent_class)->dispose (object);
@ -250,29 +239,6 @@ gtk_render_node_view_snapshot (GtkWidget *widget,
gsk_render_node_draw (priv->render_node, cr);
if (priv->render_region)
{
cairo_region_t *draw;
cairo_pattern_t *linear;
linear = cairo_pattern_create_linear (0, 0, 10, 10);
cairo_pattern_set_extend (linear, CAIRO_EXTEND_REPEAT);
cairo_pattern_add_color_stop_rgba (linear, 0.4, 0, 0, 0, 0);
cairo_pattern_add_color_stop_rgba (linear, 0.45, 0, 0, 0, 0.5);
cairo_pattern_add_color_stop_rgba (linear, 0.55, 0, 0, 0, 0.5);
cairo_pattern_add_color_stop_rgba (linear, 0.6, 0, 0, 0, 0);
draw = cairo_region_create_rectangle (&viewport);
cairo_region_subtract (draw, priv->render_region);
cairo_set_source (cr, linear);
gdk_cairo_region (cr, draw);
cairo_fill (cr);
cairo_region_destroy (draw);
cairo_pattern_destroy (linear);
}
if (priv->clip_region)
{
cairo_region_t *draw;
@ -317,13 +283,6 @@ gtk_render_node_view_class_init (GtkRenderNodeViewClass *klass)
/* GSK_TYPE_RENDER_NODE, */
G_PARAM_READWRITE);
props[PROP_RENDER_REGION] =
g_param_spec_boxed ("render-region",
"Render region",
"Actually rendered region",
CAIRO_GOBJECT_TYPE_REGION,
G_PARAM_READWRITE);
props[PROP_CLIP_REGION] =
g_param_spec_boxed ("clip-region",
"Clip region",
@ -427,28 +386,5 @@ gtk_render_node_view_get_clip_region (GtkRenderNodeView *view)
return priv->clip_region;
}
void
gtk_render_node_view_set_render_region (GtkRenderNodeView *view,
const cairo_region_t *region)
{
GtkRenderNodeViewPrivate *priv = gtk_render_node_view_get_instance_private (view);
if (priv->render_region)
cairo_region_destroy (priv->render_region);
priv->render_region = cairo_region_copy (region);
gtk_widget_queue_draw (GTK_WIDGET (view));
g_object_notify_by_pspec (G_OBJECT (view), props[PROP_RENDER_REGION]);
}
const cairo_region_t*
gtk_render_node_view_get_render_region (GtkRenderNodeView *view)
{
GtkRenderNodeViewPrivate *priv = gtk_render_node_view_get_instance_private (view);
return priv->render_region;
}
// vim: set et sw=2 ts=2:

View File

@ -55,10 +55,6 @@ void gtk_render_node_view_set_clip_region (GtkRenderNodeView
const cairo_region_t *clip);
const cairo_region_t*
gtk_render_node_view_get_clip_region (GtkRenderNodeView *view);
void gtk_render_node_view_set_render_region (GtkRenderNodeView *view,
const cairo_region_t *region);
const cairo_region_t*
gtk_render_node_view_get_render_region (GtkRenderNodeView *view);
G_END_DECLS

View File

@ -28,7 +28,6 @@ gtk_inspector_render_recording_finalize (GObject *object)
GtkInspectorRenderRecording *recording = GTK_INSPECTOR_RENDER_RECORDING (object);
g_clear_pointer (&recording->clip_region, cairo_region_destroy);
g_clear_pointer (&recording->render_region, cairo_region_destroy);
g_clear_pointer (&recording->node, gsk_render_node_unref);
g_clear_pointer (&recording->profiler_info, g_free);
@ -65,7 +64,6 @@ gtk_inspector_render_recording_new (gint64 timestamp,
GskProfiler *profiler,
const GdkRectangle *area,
const cairo_region_t *clip_region,
const cairo_region_t *render_region,
GskRenderNode *node)
{
GtkInspectorRenderRecording *recording;
@ -77,7 +75,6 @@ gtk_inspector_render_recording_new (gint64 timestamp,
collect_profiler_info (recording, profiler);
recording->area = *area;
recording->clip_region = cairo_region_copy (clip_region);
recording->render_region = cairo_region_copy (render_region);
recording->node = gsk_render_node_ref (node);
return GTK_INSPECTOR_RECORDING (recording);
@ -95,12 +92,6 @@ gtk_inspector_render_recording_get_clip_region (GtkInspectorRenderRecording *rec
return recording->clip_region;
}
const cairo_region_t *
gtk_inspector_render_recording_get_render_region (GtkInspectorRenderRecording *recording)
{
return recording->render_region;
}
const cairo_rectangle_int_t *
gtk_inspector_render_recording_get_area (GtkInspectorRenderRecording *recording)
{

View File

@ -42,7 +42,6 @@ typedef struct _GtkInspectorRenderRecording
GdkRectangle area;
cairo_region_t *clip_region;
cairo_region_t *render_region;
GskRenderNode *node;
char *profiler_info;
} GtkInspectorRenderRecording;
@ -59,14 +58,11 @@ GtkInspectorRecording *
GskProfiler *profiler,
const GdkRectangle *area,
const cairo_region_t *clip_region,
const cairo_region_t *render_region,
GskRenderNode *node);
GskRenderNode * gtk_inspector_render_recording_get_node (GtkInspectorRenderRecording *recording);
const cairo_region_t *
gtk_inspector_render_recording_get_clip_region (GtkInspectorRenderRecording *recording);
const cairo_region_t *
gtk_inspector_render_recording_get_render_region (GtkInspectorRenderRecording *recording);
const cairo_rectangle_int_t *
gtk_inspector_render_recording_get_area (GtkInspectorRenderRecording *recording);
const char * gtk_inspector_render_recording_get_profiler_info

View File

@ -374,7 +374,6 @@ gtk_inspector_record_render (GtkWidget *widget,
GskRenderer *renderer,
GdkSurface *surface,
const cairo_region_t *region,
GdkDrawingContext *context,
GskRenderNode *node)
{
GtkInspectorWindow *iw;
@ -392,7 +391,6 @@ gtk_inspector_record_render (GtkWidget *widget,
renderer,
surface,
region,
context,
node);
}

View File

@ -111,7 +111,6 @@ void gtk_inspector_record_render (GtkWidget *widget,
GskRenderer *renderer,
GdkSurface *surface,
const cairo_region_t *region,
GdkDrawingContext *context,
GskRenderNode *node);
G_END_DECLS