Commit b1c54750 authored by Emmanuele Bassi's avatar Emmanuele Bassi

gsk: Move scaling filters to GskRenderNode

The renderer will always use nearest-neighbor filters because it renders
at 1:1 pixel to texel ratio.

On the other hand, render nodes may be scaled, so we need to offer a way
to control the minification and magnification filters.
parent ea3c2f48
......@@ -107,9 +107,6 @@ struct _GskGLRenderer
GskGLProfiler *gl_profiler;
GskShaderBuilder *shader_builder;
int gl_min_filter;
int gl_mag_filter;
int blend_program_id;
int blit_program_id;
......@@ -515,15 +512,11 @@ render_item (GskGLRenderer *self,
}
static void
get_gl_scaling_filters (GskRenderer *renderer,
int *min_filter_r,
int *mag_filter_r)
get_gl_scaling_filters (GskRenderNode *node,
int *min_filter_r,
int *mag_filter_r)
{
GskScalingFilter min_filter, mag_filter;
gsk_renderer_get_scaling_filters (renderer, &min_filter, &mag_filter);
switch (min_filter)
switch (node->min_filter)
{
case GSK_SCALING_FILTER_NEAREST:
*min_filter_r = GL_NEAREST;
......@@ -538,7 +531,7 @@ get_gl_scaling_filters (GskRenderer *renderer,
break;
}
switch (mag_filter)
switch (node->mag_filter)
{
case GSK_SCALING_FILTER_NEAREST:
*mag_filter_r = GL_NEAREST;
......@@ -711,6 +704,9 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
else if (gsk_render_node_has_surface (node))
{
cairo_surface_t *surface = gsk_render_node_get_surface (node);
int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter);
/* Upload the Cairo surface to a GL texture */
item.render_data.texture_id = gsk_gl_driver_create_texture (self->gl_driver,
......@@ -720,8 +716,8 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
gsk_gl_driver_init_texture_with_surface (self->gl_driver,
item.render_data.texture_id,
surface,
self->gl_min_filter,
self->gl_mag_filter);
gl_min_filter,
gl_mag_filter);
}
else
{
......@@ -869,9 +865,6 @@ gsk_gl_renderer_render (GskRenderer *renderer,
gsk_gl_renderer_update_frustum (self, &modelview, &projection);
get_gl_scaling_filters (GSK_RENDERER (self),
&self->gl_min_filter,
&self->gl_mag_filter);
if (!gsk_gl_renderer_validate_tree (self, root, &projection))
goto out;
......
......@@ -82,8 +82,6 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GskRenderer, gsk_renderer, G_TYPE_OBJECT)
enum {
PROP_VIEWPORT = 1,
PROP_MINIFICATION_FILTER,
PROP_MAGNIFICATION_FILTER,
PROP_AUTO_CLEAR,
PROP_USE_ALPHA,
PROP_SCALE_FACTOR,
......@@ -149,14 +147,6 @@ gsk_renderer_set_property (GObject *gobject,
gsk_renderer_set_viewport (self, g_value_get_boxed (value));
break;
case PROP_MINIFICATION_FILTER:
gsk_renderer_set_scaling_filters (self, g_value_get_enum (value), priv->mag_filter);
break;
case PROP_MAGNIFICATION_FILTER:
gsk_renderer_set_scaling_filters (self, priv->min_filter, g_value_get_enum (value));
break;
case PROP_AUTO_CLEAR:
gsk_renderer_set_auto_clear (self, g_value_get_boolean (value));
break;
......@@ -195,14 +185,6 @@ gsk_renderer_get_property (GObject *gobject,
g_value_set_boxed (value, &priv->viewport);
break;
case PROP_MINIFICATION_FILTER:
g_value_set_enum (value, priv->min_filter);
break;
case PROP_MAGNIFICATION_FILTER:
g_value_set_enum (value, priv->mag_filter);
break;
case PROP_AUTO_CLEAR:
g_value_set_boolean (value, priv->auto_clear);
break;
......@@ -276,44 +258,6 @@ gsk_renderer_class_init (GskRendererClass *klass)
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* GskRenderer:minification-filter:
*
* The filter to be used when scaling textures down.
*
* See also: gsk_renderer_set_scaling_filters()
*
* Since: 3.22
*/
gsk_renderer_properties[PROP_MINIFICATION_FILTER] =
g_param_spec_enum ("minification-filter",
"Minification Filter",
"The minification filter used by the renderer for texture targets",
GSK_TYPE_SCALING_FILTER,
GSK_SCALING_FILTER_LINEAR,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* GskRenderer:magnification-filter:
*
* The filter to be used when scaling textures up.
*
* See also: gsk_renderer_set_scaling_filters()
*
* Since: 3.22
*/
gsk_renderer_properties[PROP_MAGNIFICATION_FILTER] =
g_param_spec_enum ("magnification-filter",
"Magnification Filter",
"The magnification filter used by the renderer for texture targets",
GSK_TYPE_SCALING_FILTER,
GSK_SCALING_FILTER_LINEAR,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* GskRenderer:auto-clear:
*
......@@ -419,9 +363,6 @@ gsk_renderer_init (GskRenderer *self)
priv->auto_clear = TRUE;
priv->scale_factor = 1;
priv->min_filter = GSK_SCALING_FILTER_LINEAR;
priv->mag_filter = GSK_SCALING_FILTER_LINEAR;
}
/**
......@@ -478,72 +419,6 @@ gsk_renderer_get_viewport (GskRenderer *renderer,
graphene_rect_init_from_rect (viewport, &priv->viewport);
}
/**
* gsk_renderer_set_scaling_filters:
* @renderer: a #GskRenderer
* @min_filter: the minification scaling filter
* @mag_filter: the magnification scaling filter
*
* Sets the scaling filters to be applied when scaling textures
* up and down.
*
* Since: 3.22
*/
void
gsk_renderer_set_scaling_filters (GskRenderer *renderer,
GskScalingFilter min_filter,
GskScalingFilter mag_filter)
{
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
GObject *gobject;
g_return_if_fail (GSK_IS_RENDERER (renderer));
gobject = G_OBJECT (renderer);
g_object_freeze_notify (gobject);
if (priv->min_filter != min_filter)
{
priv->min_filter = min_filter;
g_object_notify_by_pspec (gobject, gsk_renderer_properties[PROP_MINIFICATION_FILTER]);
}
if (priv->mag_filter != mag_filter)
{
priv->mag_filter = mag_filter;
g_object_notify_by_pspec (gobject, gsk_renderer_properties[PROP_MAGNIFICATION_FILTER]);
}
g_object_thaw_notify (gobject);
}
/**
* gsk_renderer_get_scaling_filters:
* @renderer: a #GskRenderer
* @min_filter: (out) (nullable): return location for the minification filter
* @mag_filter: (out) (nullable): return location for the magnification filter
*
* Retrieves the minification and magnification filters used by the #GskRenderer.
*
* Since: 3.22
*/
void
gsk_renderer_get_scaling_filters (GskRenderer *renderer,
GskScalingFilter *min_filter,
GskScalingFilter *mag_filter)
{
GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
g_return_if_fail (GSK_IS_RENDERER (renderer));
if (min_filter != NULL)
*min_filter = priv->min_filter;
if (mag_filter != NULL)
*mag_filter = priv->mag_filter;
}
/**
* gsk_renderer_set_scale_factor:
* @renderer: a #GskRenderer
......
......@@ -49,14 +49,6 @@ GDK_AVAILABLE_IN_3_22
void gsk_renderer_get_viewport (GskRenderer *renderer,
graphene_rect_t *viewport);
GDK_AVAILABLE_IN_3_22
void gsk_renderer_set_scaling_filters (GskRenderer *renderer,
GskScalingFilter min_filter,
GskScalingFilter mag_filter);
GDK_AVAILABLE_IN_3_22
void gsk_renderer_get_scaling_filters (GskRenderer *renderer,
GskScalingFilter *min_filter,
GskScalingFilter *mag_filter);
GDK_AVAILABLE_IN_3_22
void gsk_renderer_set_scale_factor (GskRenderer *renderer,
int scale_factor);
GDK_AVAILABLE_IN_3_22
......
......@@ -182,6 +182,9 @@ gsk_render_node_init (GskRenderNode *self)
self->opacity = 1.0;
self->min_filter = GSK_SCALING_FILTER_NEAREST;
self->mag_filter = GSK_SCALING_FILTER_NEAREST;
self->is_mutable = TRUE;
self->needs_world_matrix_update = TRUE;
}
......@@ -1244,6 +1247,19 @@ gsk_render_node_get_surface (GskRenderNode *node)
return node->surface;
}
void
gsk_render_node_set_scaling_filters (GskRenderNode *node,
GskScalingFilter min_filter,
GskScalingFilter mag_filter)
{
g_return_if_fail (GSK_IS_RENDER_NODE (node));
if (node->min_filter != min_filter)
node->min_filter = min_filter;
if (node->mag_filter != mag_filter)
node->mag_filter = mag_filter;
}
/*< private >
* gsk_render_node_get_world_matrix:
* @node: a #GskRenderNode
......
......@@ -123,6 +123,11 @@ GDK_AVAILABLE_IN_3_22
void gsk_render_node_set_texture (GskRenderNode *node,
int texture_id);
GDK_AVAILABLE_IN_3_22
void gsk_render_node_set_scaling_filter (GskRenderNode *node,
GskScalingFilter min_filter,
GskScalingFilter mag_filter);
GDK_AVAILABLE_IN_3_22
int gsk_render_node_get_scale_factor (GskRenderNode *node);
......
......@@ -47,6 +47,10 @@ struct _GskRenderNode
/* Blend mode */
GskBlendMode blend_mode;
/* Scaling filters */
GskScalingFilter min_filter;
GskScalingFilter mag_filter;
/* Clip rectangle */
graphene_rect_t bounds;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment