Skip to content

Commit

Permalink
Go via Clutter.Actor.context to get Clutter.Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jan 11, 2025
1 parent 8ee6c5a commit d600a6f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
19 changes: 16 additions & 3 deletions lib/Drawing/Canvas.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,33 @@ public class Gala.Drawing.Canvas : GLib.Object, Clutter.Content {
private int height = -1;
private float scale_factor = 1.0f;

private Cogl.Context? cogl_context;

private Cogl.Texture? texture = null;
private Cogl.Bitmap? bitmap = null;

private bool dirty = false;

public signal void draw (Cairo.Context cr, int width, int height);

private void emit_draw () requires (width > 0 && height > 0) {
public override void attached (Clutter.Actor actor) {
#if HAS_MUTTER47
cogl_context = actor.context.get_backend ().get_cogl_context ();
#else
cogl_context = Clutter.get_default_backend ().get_cogl_context ();
#endif
}

public override void detached (Clutter.Actor actor) {
cogl_context = null;
}

private void emit_draw () requires (width > 0 && height > 0 && cogl_context != null) {
dirty = true;
int real_width = (int) Math.ceilf (width * scale_factor);
int real_height = (int) Math.ceilf (height * scale_factor);
if (bitmap == null) {
unowned Cogl.Context ctx = Clutter.get_default_backend ().get_cogl_context ();
bitmap = new Cogl.Bitmap.with_size (ctx, real_width, real_height, Cogl.PixelFormat.CAIRO_ARGB32_COMPAT);
bitmap = new Cogl.Bitmap.with_size (cogl_context, real_width, real_height, Cogl.PixelFormat.CAIRO_ARGB32_COMPAT);
}

unowned Cogl.Buffer? buffer = bitmap.get_buffer ();
Expand Down
20 changes: 15 additions & 5 deletions lib/ShadowEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,33 @@ public class Gala.ShadowEffect : Clutter.Effect {
public int border_radius { get; set; default = 9;}

private int shadow_size;
private Cogl.Pipeline pipeline;
private Cogl.Pipeline? pipeline;
private string? current_key = null;

public ShadowEffect (string css_class = "") {
Object (css_class: css_class);
}

construct {
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
}

~ShadowEffect () {
if (current_key != null) {
decrement_shadow_users (current_key);
}
}

public override void set_actor (Clutter.Actor? actor) {
base.set_actor (actor);

if (actor != null) {
#if HAS_MUTTER47
pipeline = new Cogl.Pipeline (actor.context.get_backend ().get_cogl_context ());
#else
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
#endif
} else {
pipeline = null;
}
}

private Cogl.Texture? get_shadow (Cogl.Context context, int width, int height, int shadow_size) {
var old_key = current_key;
current_key = "%ix%i:%i".printf (width, height, shadow_size);
Expand Down
12 changes: 12 additions & 0 deletions src/Background/BlurEffect.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public class Gala.BlurEffect : Clutter.Effect {
}

construct {
#if HAS_MUTTER47
unowned var ctx = actor.context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif

actor_pipeline = new Cogl.Pipeline (ctx);
actor_pipeline.set_layer_null_texture (0);
Expand Down Expand Up @@ -98,7 +102,11 @@ public class Gala.BlurEffect : Clutter.Effect {
return true;
}

#if HAS_MUTTER47
unowned var ctx = actor.context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif

framebuffer = null;
texture = null;
Expand Down Expand Up @@ -136,7 +144,11 @@ public class Gala.BlurEffect : Clutter.Effect {

actor_painted = false;

#if HAS_MUTTER47
unowned var ctx = actor.context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif

actor_framebuffer = null;
actor_texture = null;
Expand Down
10 changes: 8 additions & 2 deletions src/Widgets/DwellClickTimer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ namespace Gala {
visible = false;
reactive = false;

pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
#if HAS_MUTTER47
unowned var backend = context.get_backend ();
#else
unowned var backend = Clutter.get_default_backend ();
#endif

pipeline = new Cogl.Pipeline (backend.get_cogl_context ());

transition = new Clutter.PropertyTransition ("angle");
transition.set_progress_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
Expand All @@ -65,7 +71,7 @@ namespace Gala {

interface_settings = new GLib.Settings ("org.gnome.desktop.interface");

var seat = Clutter.get_default_backend ().get_default_seat ();
var seat = backend.get_default_seat ();
seat.set_pointer_a11y_dwell_click_type (Clutter.PointerA11yDwellClickType.PRIMARY);

seat.ptr_a11y_timeout_started.connect ((device, type, timeout) => {
Expand Down
8 changes: 7 additions & 1 deletion src/Widgets/PointerLocator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ namespace Gala {
reactive = false;

settings = new GLib.Settings ("org.gnome.desktop.interface");
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());

#if HAS_MUTTER47
unowned var ctx = context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif
pipeline = new Cogl.Pipeline (ctx);

var pivot = Graphene.Point ();
pivot.init (0.5f, 0.5f);
Expand Down
7 changes: 6 additions & 1 deletion src/Widgets/WorkspaceClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ namespace Gala {
}

construct {
pipeline = new Cogl.Pipeline (Clutter.get_default_backend ().get_cogl_context ());
#if HAS_MUTTER47
unowned var ctx = context.get_backend ().get_cogl_context ();
#else
unowned var ctx = Clutter.get_default_backend ().get_cogl_context ();
#endif
pipeline = new Cogl.Pipeline (ctx);
var primary = display.get_primary_monitor ();
var monitor_geom = display.get_monitor_geometry (primary);

Expand Down

0 comments on commit d600a6f

Please sign in to comment.