Get ClutterBackend/CoglContext from the Actor/Texture

Avoids going through the global backend helper.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3528>
This commit is contained in:
Bilal Elmoussaoui 2024-12-30 14:07:57 +01:00 committed by Marge Bot
parent dee6cf3f6b
commit fea29eb490
11 changed files with 43 additions and 32 deletions

View File

@ -365,7 +365,8 @@ class _Draggable extends Signals.EventEmitter {
device = event.get_device(); device = event.get_device();
if (device === undefined) { if (device === undefined) {
let seat = Clutter.get_default_backend().get_default_seat(); const backend = this.actor.get_context().get_backend();
const seat = backend.get_default_seat();
device = seat.get_pointer(); device = seat.get_pointer();
} }
} }

View File

@ -107,6 +107,8 @@ export class Magnifier extends Signals.EventEmitter {
this._cursorRoot = new Clutter.Actor(); this._cursorRoot = new Clutter.Actor();
this._cursorRoot.add_child(this._mouseSprite); this._cursorRoot.add_child(this._mouseSprite);
const backend = this._cursorRoot.get_context().get_backend();
this._seat = backend.get_default_seat();
// Create the first ZoomRegion and initialize it according to the // Create the first ZoomRegion and initialize it according to the
// magnification settings. // magnification settings.
@ -130,10 +132,8 @@ export class Magnifier extends Signals.EventEmitter {
* Show the system mouse pointer. * Show the system mouse pointer.
*/ */
showSystemCursor() { showSystemCursor() {
const seat = Clutter.get_default_backend().get_default_seat();
if (this._cursorUnfocusInhibited) { if (this._cursorUnfocusInhibited) {
seat.uninhibit_unfocus(); this._seat.uninhibit_unfocus();
this._cursorUnfocusInhibited = false; this._cursorUnfocusInhibited = false;
} }
@ -150,10 +150,8 @@ export class Magnifier extends Signals.EventEmitter {
* Hide the system mouse pointer. * Hide the system mouse pointer.
*/ */
hideSystemCursor() { hideSystemCursor() {
const seat = Clutter.get_default_backend().get_default_seat();
if (!this._cursorUnfocusInhibited) { if (!this._cursorUnfocusInhibited) {
seat.inhibit_unfocus(); this._seat.inhibit_unfocus();
this._cursorUnfocusInhibited = true; this._cursorUnfocusInhibited = true;
} }

View File

@ -640,7 +640,8 @@ export const PadOsd = GObject.registerClass({
this._editionMode = editionMode; this._editionMode = editionMode;
this._padChooser = null; this._padChooser = null;
let seat = Clutter.get_default_backend().get_default_seat(); const backend = this.get_context().get_backend();
const seat = backend.get_default_seat();
seat.connectObject( seat.connectObject(
'device-added', (_seat, device) => { 'device-added', (_seat, device) => {
if (device.get_device_type() === Clutter.InputDeviceType.PAD_DEVICE && if (device.get_device_type() === Clutter.InputDeviceType.PAD_DEVICE &&

View File

@ -176,7 +176,8 @@ class CapsLockWarning extends St.Label {
this.clutter_text.ellipsize = Pango.EllipsizeMode.NONE; this.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
this.clutter_text.line_wrap = true; this.clutter_text.line_wrap = true;
let seat = Clutter.get_default_backend().get_default_seat(); const backend = this.get_context().get_backend();
const seat = backend.get_default_seat();
this._keymap = seat.get_keymap(); this._keymap = seat.get_keymap();
this.connect('notify::mapped', () => { this.connect('notify::mapped', () => {

View File

@ -48,7 +48,8 @@ class DwellClickIndicator extends PanelMenu.Button {
this._a11ySettings.connect(`changed::${KEY_DWELL_CLICK_ENABLED}`, this._syncMenuVisibility.bind(this)); this._a11ySettings.connect(`changed::${KEY_DWELL_CLICK_ENABLED}`, this._syncMenuVisibility.bind(this));
this._a11ySettings.connect(`changed::${KEY_DWELL_MODE}`, this._syncMenuVisibility.bind(this)); this._a11ySettings.connect(`changed::${KEY_DWELL_MODE}`, this._syncMenuVisibility.bind(this));
this._seat = Clutter.get_default_backend().get_default_seat(); const backend = this.get_context().get_backend();
this._seat = backend.get_default_seat();
this._seat.connect('ptr-a11y-dwell-click-type-changed', this._updateClickType.bind(this)); this._seat.connect('ptr-a11y-dwell-click-type-changed', this._updateClickType.bind(this));
this._addDwellAction(DWELL_CLICK_MODES.primary); this._addDwellAction(DWELL_CLICK_MODES.primary);

View File

@ -347,7 +347,8 @@ class UnlockDialogClock extends St.BoxLayout {
this._wallClock = new GnomeDesktop.WallClock({time_only: true}); this._wallClock = new GnomeDesktop.WallClock({time_only: true});
this._wallClock.connect('notify::clock', this._updateClock.bind(this)); this._wallClock.connect('notify::clock', this._updateClock.bind(this));
this._seat = Clutter.get_default_backend().get_default_seat(); const backend = this.get_context().get_backend();
this._seat = backend.get_default_seat();
this._seat.connectObject('notify::touch-mode', this._seat.connectObject('notify::touch-mode',
this._updateHint.bind(this), this); this._updateHint.bind(this), this);

View File

@ -39,6 +39,8 @@
#include <cogl/cogl.h> #include <cogl/cogl.h>
#include "shell-global.h"
struct _ShellInvertLightnessEffect struct _ShellInvertLightnessEffect
{ {
ClutterOffscreenEffect parent_instance; ClutterOffscreenEffect parent_instance;
@ -114,8 +116,7 @@ shell_invert_lightness_effect_init (ShellInvertLightnessEffect *self)
if (G_UNLIKELY (klass->base_pipeline == NULL)) if (G_UNLIKELY (klass->base_pipeline == NULL))
{ {
CoglSnippet *snippet; CoglSnippet *snippet;
CoglContext *ctx = CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
clutter_backend_get_cogl_context (clutter_get_default_backend ());
klass->base_pipeline = cogl_pipeline_new (ctx); klass->base_pipeline = cogl_pipeline_new (ctx);

View File

@ -516,8 +516,7 @@ grab_screenshot_content (ShellScreenshot *screenshot,
// Copy the texture to prevent it from changing shortly after. // Copy the texture to prevent it from changing shortly after.
width = cogl_texture_get_width (cursor_texture); width = cogl_texture_get_width (cursor_texture);
height = cogl_texture_get_height (cursor_texture); height = cogl_texture_get_height (cursor_texture);
ctx = cogl_texture_get_context (cursor_texture);
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
texture = cogl_texture_2d_new_with_size (ctx, width, height); texture = cogl_texture_2d_new_with_size (ctx, width, height);
offscreen = cogl_offscreen_new_with_texture (texture); offscreen = cogl_offscreen_new_with_texture (texture);
@ -1266,7 +1265,7 @@ shell_screenshot_composite_to_stream (CoglTexture *texture,
height = cogl_texture_get_height (texture); height = cogl_texture_get_height (texture);
} }
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); ctx = cogl_texture_get_context (texture);
sub_texture = cogl_sub_texture_new (ctx, texture, x, y, width, height); sub_texture = cogl_sub_texture_new (ctx, texture, x, y, width, height);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,

View File

@ -203,9 +203,10 @@ st_drawing_area_emit_repaint (StDrawingArea *area)
if (priv->buffer == NULL) if (priv->buffer == NULL)
{ {
CoglContext *ctx; ClutterContext *context = clutter_actor_get_context (CLUTTER_ACTOR (area));
ClutterBackend *backend = clutter_context_get_backend (context);
CoglContext *ctx= clutter_backend_get_cogl_context (backend);
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
priv->buffer = cogl_bitmap_new_with_size (ctx, priv->buffer = cogl_bitmap_new_with_size (ctx,
real_width, real_width,
real_height, real_height,

View File

@ -223,8 +223,7 @@ _st_create_texture_pipeline (CoglTexture *src_texture)
pipeline ancestry instead of resorting to the shader cache. */ pipeline ancestry instead of resorting to the shader cache. */
if (G_UNLIKELY (texture_pipeline_template == NULL)) if (G_UNLIKELY (texture_pipeline_template == NULL))
{ {
CoglContext *ctx = CoglContext *ctx = cogl_texture_get_context (src_texture);
clutter_backend_get_cogl_context (clutter_get_default_backend ());
texture_pipeline_template = cogl_pipeline_new (ctx); texture_pipeline_template = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_null_texture (texture_pipeline_template, 0); cogl_pipeline_set_layer_null_texture (texture_pipeline_template, 0);
@ -384,12 +383,11 @@ _st_create_shadow_pipeline (StShadow *shadow_spec,
CoglTexture *src_texture, CoglTexture *src_texture,
float resource_scale) float resource_scale)
{ {
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
g_autoptr (ClutterPaintNode) texture_node = NULL; g_autoptr (ClutterPaintNode) texture_node = NULL;
g_autoptr (ClutterPaintNode) blur_node = NULL; g_autoptr (ClutterPaintNode) blur_node = NULL;
g_autoptr (CoglOffscreen) offscreen = NULL; g_autoptr (CoglOffscreen) offscreen = NULL;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
CoglContext *cogl_context;
ClutterPaintContext *nested_paint_context; ClutterPaintContext *nested_paint_context;
ClutterColorState *color_state; ClutterColorState *color_state;
CoglFramebuffer *fb; CoglFramebuffer *fb;
@ -413,10 +411,11 @@ _st_create_shadow_pipeline (StShadow *shadow_spec,
src_width = cogl_texture_get_width (src_texture); src_width = cogl_texture_get_width (src_texture);
src_height = cogl_texture_get_height (src_texture); src_height = cogl_texture_get_height (src_texture);
cogl_context = cogl_texture_get_context (src_texture);
dst_width = src_width + 2 * sampling_radius; dst_width = src_width + 2 * sampling_radius;
dst_height = src_height + 2 * sampling_radius; dst_height = src_height + 2 * sampling_radius;
texture = cogl_texture_2d_new_with_size (ctx, dst_width, dst_height); texture = cogl_texture_2d_new_with_size (cogl_context, dst_width, dst_height);
if (!texture) if (!texture)
return NULL; return NULL;
@ -440,7 +439,7 @@ _st_create_shadow_pipeline (StShadow *shadow_spec,
}); });
/* Texture */ /* Texture */
texture_pipeline = cogl_context_get_named_pipeline (ctx, texture_pipeline = cogl_context_get_named_pipeline (cogl_context,
&texture_pipeline_key); &texture_pipeline_key);
if (G_UNLIKELY (texture_pipeline == NULL)) if (G_UNLIKELY (texture_pipeline == NULL))
@ -452,11 +451,11 @@ _st_create_shadow_pipeline (StShadow *shadow_spec,
"if (cogl_color_out.a > 0.0)\n" "if (cogl_color_out.a > 0.0)\n"
" cogl_color_out.a = 1.0;"); " cogl_color_out.a = 1.0;");
texture_pipeline = cogl_pipeline_new (ctx); texture_pipeline = cogl_pipeline_new (cogl_context);
cogl_pipeline_add_snippet (texture_pipeline, snippet); cogl_pipeline_add_snippet (texture_pipeline, snippet);
g_object_unref (snippet); g_object_unref (snippet);
cogl_context_set_named_pipeline (ctx, cogl_context_set_named_pipeline (cogl_context,
&texture_pipeline_key, &texture_pipeline_key,
texture_pipeline); texture_pipeline);
} }
@ -488,7 +487,7 @@ _st_create_shadow_pipeline (StShadow *shadow_spec,
if (G_UNLIKELY (shadow_pipeline_template == NULL)) if (G_UNLIKELY (shadow_pipeline_template == NULL))
{ {
shadow_pipeline_template = cogl_pipeline_new (ctx); shadow_pipeline_template = cogl_pipeline_new (cogl_context);
/* We set up the pipeline to blend the shadow texture with the combine /* We set up the pipeline to blend the shadow texture with the combine
* constant, but defer setting the latter until painting, so that we can * constant, but defer setting the latter until painting, so that we can
@ -552,13 +551,17 @@ _st_create_shadow_pipeline_from_actor (StShadow *shadow_spec,
g_autoptr(CoglTexture) buffer = NULL; g_autoptr(CoglTexture) buffer = NULL;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *fb; CoglFramebuffer *fb;
CoglContext *ctx; ClutterBackend *backend;
ClutterContext *context;
CoglContext *cogl_context;
CoglColor clear_color; CoglColor clear_color;
GError *catch_error = NULL; GError *catch_error = NULL;
float x, y; float x, y;
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); context = clutter_actor_get_context (actor);
buffer = cogl_texture_2d_new_with_size (ctx, width, height); backend = clutter_context_get_backend (context);
cogl_context = clutter_backend_get_cogl_context (backend);
buffer = cogl_texture_2d_new_with_size (cogl_context, width, height);
if (buffer == NULL) if (buffer == NULL)
return NULL; return NULL;

View File

@ -1832,17 +1832,21 @@ st_widget_set_hover (StWidget *widget,
void void
st_widget_sync_hover (StWidget *widget) st_widget_sync_hover (StWidget *widget)
{ {
ClutterContext *context;
ClutterBackend *backend;
ClutterInputDevice *pointer; ClutterInputDevice *pointer;
ClutterActor *stage; ClutterActor *stage;
ClutterActor *pointer_actor; ClutterActor *pointer_actor;
ClutterSeat *seat; ClutterSeat *seat;
seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
pointer = clutter_seat_get_pointer (seat);
stage = clutter_actor_get_stage (CLUTTER_ACTOR (widget)); stage = clutter_actor_get_stage (CLUTTER_ACTOR (widget));
if (!stage) if (!stage)
return; return;
context = clutter_actor_get_context (CLUTTER_ACTOR (widget));
backend = clutter_context_get_backend (context);
seat = clutter_backend_get_default_seat (backend);
pointer = clutter_seat_get_pointer (seat);
pointer_actor = clutter_stage_get_device_actor (CLUTTER_STAGE (stage), pointer, NULL); pointer_actor = clutter_stage_get_device_actor (CLUTTER_STAGE (stage), pointer, NULL);
if (pointer_actor && clutter_actor_get_reactive (CLUTTER_ACTOR (widget))) if (pointer_actor && clutter_actor_get_reactive (CLUTTER_ACTOR (widget)))
st_widget_set_hover (widget, clutter_actor_contains (CLUTTER_ACTOR (widget), pointer_actor)); st_widget_set_hover (widget, clutter_actor_contains (CLUTTER_ACTOR (widget), pointer_actor));