linuxOS_AP06/buildroot/package/weston/0072-client-desktop-shell-Speed-up-background-image-drawi.patch
2025-06-03 12:28:32 +08:00

86 lines
2.7 KiB
Diff

From 2bf3318219ef803f7a42450447f202be8814a921 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Tue, 12 Dec 2023 10:21:42 +0800
Subject: [PATCH 72/95] client: desktop-shell: Speed up background image
drawing
Note: The background color been ignored when painting background image.
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
clients/desktop-shell.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index fb32632..30292df 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -893,7 +893,6 @@ background_draw(struct widget *widget, void *data)
struct background *background = data;
cairo_surface_t *surface, *image;
cairo_pattern_t *pattern;
- cairo_matrix_t matrix;
cairo_t *cr;
double im_w, im_h;
double sx, sy, s;
@@ -927,26 +926,27 @@ background_draw(struct widget *widget, void *data)
sx = im_w / allocation.width;
sy = im_h / allocation.height;
- pattern = cairo_pattern_create_for_surface(image);
-
switch (background->type) {
case BACKGROUND_SCALE:
- cairo_matrix_init_scale(&matrix, sx, sy);
- cairo_pattern_set_matrix(pattern, &matrix);
- cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
+ cairo_scale(cr, 1 / sx, 1 / sy);
+ cairo_set_source_surface(cr, image, 0, 0);
+ cairo_paint(cr);
break;
case BACKGROUND_SCALE_CROP:
s = (sx < sy) ? sx : sy;
/* align center */
tx = (im_w - s * allocation.width) * 0.5;
ty = (im_h - s * allocation.height) * 0.5;
- cairo_matrix_init_translate(&matrix, tx, ty);
- cairo_matrix_scale(&matrix, s, s);
- cairo_pattern_set_matrix(pattern, &matrix);
- cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
+ cairo_scale(cr, 1 / s, 1 / s);
+ cairo_set_source_surface(cr, image, -tx, -ty);
+ cairo_paint(cr);
break;
case BACKGROUND_TILE:
+ pattern = cairo_pattern_create_for_surface(image);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
+ cairo_set_source(cr, pattern);
+ cairo_pattern_destroy (pattern);
+ cairo_mask(cr, pattern);
break;
case BACKGROUND_CENTERED:
s = (sx < sy) ? sx : sy;
@@ -957,16 +957,13 @@ background_draw(struct widget *widget, void *data)
tx = (im_w - s * allocation.width) * 0.5;
ty = (im_h - s * allocation.height) * 0.5;
- cairo_matrix_init_translate(&matrix, tx, ty);
- cairo_matrix_scale(&matrix, s, s);
- cairo_pattern_set_matrix(pattern, &matrix);
+ cairo_scale(cr, 1 / s, 1 / s);
+ cairo_set_source_surface(cr, image, -tx, -ty);
+ cairo_paint(cr);
break;
}
- cairo_set_source(cr, pattern);
- cairo_pattern_destroy (pattern);
cairo_surface_destroy(image);
- cairo_mask(cr, pattern);
}
cairo_destroy(cr);
--
2.20.1