Skip to content

Commit 7f633aa

Browse files
authored
ScreenshotManager: simplify composite_stage_cursor (#2740)
Add cursor to the `image` directly instead of copying `image` to `target` and then adding cursor
1 parent c0ced5d commit 7f633aa

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/ScreenshotManager.vala

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public class Gala.ScreenshotManager : Object {
345345
image.set_device_scale (resource_scale, resource_scale);
346346
}
347347

348-
image = composite_stage_cursor (image, { rect.x, rect.y, rect.width, rect.height });
348+
composite_stage_cursor (image, { rect.x, rect.y, rect.width, rect.height });
349349
}
350350

351351
unconceal_text ();
@@ -592,7 +592,7 @@ public class Gala.ScreenshotManager : Object {
592592
return image;
593593
}
594594

595-
private Cairo.ImageSurface composite_stage_cursor (Cairo.ImageSurface image, Cairo.RectangleInt image_rect) {
595+
private void composite_stage_cursor (Cairo.ImageSurface image, Cairo.RectangleInt image_rect) {
596596
#if HAS_MUTTER48
597597
unowned var cursor_tracker = wm.get_display ().get_compositor ().get_backend ().get_cursor_tracker ();
598598
#else
@@ -603,12 +603,12 @@ public class Gala.ScreenshotManager : Object {
603603

604604
var region = new Cairo.Region.rectangle (image_rect);
605605
if (!region.contains_point ((int) coords.x, (int) coords.y)) {
606-
return image;
606+
return;
607607
}
608608

609-
unowned Cogl.Texture texture = cursor_tracker.get_sprite ();
609+
unowned Cogl.Texture? texture = cursor_tracker.get_sprite ();
610610
if (texture == null) {
611-
return image;
611+
return;
612612
}
613613

614614
int width = (int)texture.get_width ();
@@ -618,18 +618,10 @@ public class Gala.ScreenshotManager : Object {
618618
texture.get_data (Cogl.PixelFormat.RGBA_8888, 0, data);
619619

620620
var cursor_image = new Cairo.ImageSurface.for_data (data, Cairo.Format.ARGB32, width, height, width * 4);
621-
var target = new Cairo.ImageSurface (Cairo.Format.ARGB32, image_rect.width, image_rect.height);
622-
623-
var cr = new Cairo.Context (target);
624-
cr.set_operator (Cairo.Operator.OVER);
625-
cr.set_source_surface (image, 0, 0);
626-
cr.paint ();
627-
621+
var cr = new Cairo.Context (image);
628622
cr.set_operator (Cairo.Operator.OVER);
629623
cr.set_source_surface (cursor_image, coords.x - image_rect.x, coords.y - image_rect.y);
630624
cr.paint ();
631-
632-
return (Cairo.ImageSurface)cr.get_target ();
633625
}
634626

635627
private async void wait_stage_repaint () {

0 commit comments

Comments
 (0)