[gnome-shell/gbsneto/offscreen-paint-node: 375/378] glsl-effect: Switch to create_pipeline vfunc




commit 216508e6896db002c564e485cd0eaa7b37c606df
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Jul 5 17:40:46 2020 -0300

    glsl-effect: Switch to create_pipeline vfunc
    
    This new ClutterOffscreenEffect vastly simplyfies subclasses
    by allowing them to hand the parent class a CoglPipeline to
    use.
    
    Override the create_pipeline() vfunc and return the (cached)
    pipeline. Remove the paint_target() override and the now
    unnecessary texture size fields from the structure.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1350

 src/shell-glsl-effect.c | 55 +++++++------------------------------------------
 1 file changed, 8 insertions(+), 47 deletions(-)
---
diff --git a/src/shell-glsl-effect.c b/src/shell-glsl-effect.c
index 1f62380fcb..599aa52eda 100644
--- a/src/shell-glsl-effect.c
+++ b/src/shell-glsl-effect.c
@@ -18,9 +18,6 @@ typedef struct _ShellGLSLEffectPrivate ShellGLSLEffectPrivate;
 struct _ShellGLSLEffectPrivate
 {
   CoglPipeline  *pipeline;
-
-  gint tex_width;
-  gint tex_height;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (ShellGLSLEffect, shell_glsl_effect, CLUTTER_TYPE_OFFSCREEN_EFFECT);
@@ -29,15 +26,7 @@ static gboolean
 shell_glsl_effect_pre_paint (ClutterEffect       *effect,
                              ClutterPaintContext *paint_context)
 {
-  ShellGLSLEffect *self = SHELL_GLSL_EFFECT (effect);
-  ClutterOffscreenEffect *offscreen_effect = CLUTTER_OFFSCREEN_EFFECT (effect);
-  ShellGLSLEffectPrivate *priv = shell_glsl_effect_get_instance_private (self);
   ClutterEffectClass *parent_class;
-  CoglHandle texture;
-  gboolean success;
-
-  if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (effect)))
-    return FALSE;
 
   if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL))
     {
@@ -52,49 +41,21 @@ shell_glsl_effect_pre_paint (ClutterEffect       *effect,
     }
 
   parent_class = CLUTTER_EFFECT_CLASS (shell_glsl_effect_parent_class);
-  success = parent_class->pre_paint (effect, paint_context);
-
-  if (!success)
-    return FALSE;
-
-  texture = clutter_offscreen_effect_get_texture (offscreen_effect);
-  priv->tex_width = cogl_texture_get_width (texture);
-  priv->tex_height = cogl_texture_get_height (texture);
-
-  cogl_pipeline_set_layer_texture (priv->pipeline, 0, texture);
-
-  return TRUE;
+  return parent_class->pre_paint (effect, paint_context);
 }
 
-static void
-shell_glsl_effect_paint_target (ClutterOffscreenEffect *effect,
-                                ClutterPaintContext    *paint_context)
+static CoglPipeline *
+shell_glsl_effect_create_pipeline (ClutterOffscreenEffect *effect,
+                                   CoglTexture            *texture)
 {
   ShellGLSLEffect *self = SHELL_GLSL_EFFECT (effect);
-  ShellGLSLEffectPrivate *priv;
-  ClutterActor *actor;
-  guint8 paint_opacity;
-  CoglFramebuffer *framebuffer;
-
-  priv = shell_glsl_effect_get_instance_private (self);
-
-  actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect));
-  paint_opacity = clutter_actor_get_paint_opacity (actor);
+  ShellGLSLEffectPrivate *priv = shell_glsl_effect_get_instance_private (self);
 
-  cogl_pipeline_set_color4ub (priv->pipeline,
-                              paint_opacity,
-                              paint_opacity,
-                              paint_opacity,
-                              paint_opacity);
+  cogl_pipeline_set_layer_texture (priv->pipeline, 0, texture);
 
-  framebuffer = clutter_paint_context_get_framebuffer (paint_context);
-  cogl_framebuffer_draw_rectangle (framebuffer,
-                                   priv->pipeline,
-                                   0, 0,
-                                   priv->tex_width, priv->tex_height);
+  return cogl_object_ref (priv->pipeline);
 }
 
-
 /**
  * shell_glsl_effect_add_glsl_snippet:
  * @effect: a #ShellGLSLEffect
@@ -199,7 +160,7 @@ shell_glsl_effect_class_init (ShellGLSLEffectClass *klass)
   ClutterOffscreenEffectClass *offscreen_class;
 
   offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass);
-  offscreen_class->paint_target = shell_glsl_effect_paint_target;
+  offscreen_class->create_pipeline = shell_glsl_effect_create_pipeline;
 
   effect_class->pre_paint = shell_glsl_effect_pre_paint;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]