[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/pgtk 24d8263 031/100: Improve drawing efficency by refactoring c
From: |
Yuuki Harano |
Subject: |
feature/pgtk 24d8263 031/100: Improve drawing efficency by refactoring code |
Date: |
Tue, 24 Nov 2020 08:02:31 -0500 (EST) |
branch: feature/pgtk
commit 24d82638bc674d0c258ed95649fe98b22113d42f
Author: Yuuki Harano <masm+github@masm11.me>
Commit: Jeff Walsh <fejfighter@gmail.com>
Improve drawing efficency by refactoring code
* ../src/pgtkterm.c (fill_background, fill_background_by_face)
(x_draw_glyph_string_background, x_draw_glyph_string_bg_rect)
(x_draw_image_glyph_string, x_draw_stretch_glyph_string)
(pgtk_clear_under_internal_border): Refator duplcate code
更に効率化。
---
src/pgtkterm.c | 100 ++++++++++++---------------------------------------------
1 file changed, 21 insertions(+), 79 deletions(-)
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 3e8357e..50ee31e 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -1003,45 +1003,37 @@ x_clear_glyph_string_rect (struct glyph_string *s, int
x, int y, int w, int h)
}
-static cairo_surface_t *
-create_background_surface_by_face (struct frame *f, struct face *face, int x,
int y, int width, int height)
+static void
+fill_background_by_face (struct frame *f, struct face *face, int x, int y, int
width, int height)
{
- cairo_surface_t *surface = cairo_surface_create_similar (FRAME_CR_SURFACE
(f),
- CAIRO_CONTENT_COLOR,
- width,
- height);
-
- {
- cairo_t *cr = cairo_create (surface);
+ cairo_t *cr = pgtk_begin_cr_clip(f);
- double r = ((face->background >> 16) & 0xff) / 255.0;
- double g = ((face->background >> 8) & 0xff) / 255.0;
- double b = ((face->background >> 0) & 0xff) / 255.0;
- cairo_set_source_rgb (cr, r, g, b);
- cairo_paint (cr);
+ cairo_rectangle (cr, x, y, width, height);
+ cairo_clip (cr);
- cairo_destroy (cr);
- }
+ double r = ((face->background >> 16) & 0xff) / 255.0;
+ double g = ((face->background >> 8) & 0xff) / 255.0;
+ double b = ((face->background >> 0) & 0xff) / 255.0;
+ cairo_set_source_rgb (cr, r, g, b);
+ cairo_paint (cr);
if (face->stipple != 0) {
cairo_pattern_t *mask = FRAME_DISPLAY_INFO (f)->bitmaps[face->stipple -
1].pattern;
- cairo_t *cr = cairo_create (surface);
double r = ((face->foreground >> 16) & 0xff) / 255.0;
double g = ((face->foreground >> 8) & 0xff) / 255.0;
double b = ((face->foreground >> 0) & 0xff) / 255.0;
cairo_set_source_rgb (cr, r, g, b);
cairo_mask (cr, mask);
- cairo_destroy (cr);
}
- return surface;
+ pgtk_end_cr_clip (f);
}
-static cairo_surface_t *
-create_background_surface (struct glyph_string *s, int x, int y, int width,
int height)
+static void
+fill_background (struct glyph_string *s, int x, int y, int width, int height)
{
- return create_background_surface_by_face (s->f, s->face, x, y, width,
height);
+ fill_background_by_face (s->f, s->face, x, y, width, height);
}
/* Draw the background of glyph_string S. If S->background_filled_p
@@ -1072,20 +1064,9 @@ x_draw_glyph_string_background (struct glyph_string *s,
bool force_p)
{
/* Fill background with a stipple pattern. */
- cairo_surface_t *bg = create_background_surface (s,
- s->x, s->y +
box_line_width,
- s->background_width,
s->height - 2 * box_line_width);
-
- cairo_t *cr = pgtk_begin_cr_clip (s->f);
- cairo_set_source_surface (cr, bg, s->x, s->y + box_line_width);
- cairo_rectangle (cr,
+ fill_background (s,
s->x, s->y + box_line_width,
s->background_width, s->height - 2 * box_line_width);
- cairo_fill (cr);
- pgtk_end_cr_clip (s->f);
-
- cairo_surface_destroy (bg);
-
s->background_filled_p = true;
}
else
@@ -1893,15 +1874,7 @@ x_draw_glyph_string_bg_rect (struct glyph_string *s, int
x, int y, int w, int h)
{
/* Fill background with a stipple pattern. */
- cairo_surface_t *bg = create_background_surface (s, x, y, w, h);
-
- cairo_t *cr = pgtk_begin_cr_clip (s->f);
- cairo_set_source_surface (cr, bg, x, y);
- cairo_rectangle (cr, x, y, w, h);
- cairo_fill (cr);
- pgtk_end_cr_clip (s->f);
-
- cairo_surface_destroy (bg);
+ fill_background (s, x, y, w, h);
}
else
x_clear_glyph_string_rect (s, x, y, w, h);
@@ -1975,15 +1948,7 @@ x_draw_image_glyph_string (struct glyph_string *s)
{
if (s->img->mask)
{
- cairo_surface_t *bg = create_background_surface (s, s->x, s->y,
s->background_width, s->height);
-
- cairo_t *cr = pgtk_begin_cr_clip (s->f);
- cairo_set_source_surface (cr, bg, s->x, s->y);
- cairo_rectangle (cr, s->x, s->y, s->background_width, s->height);
- cairo_fill (cr);
- pgtk_end_cr_clip (s->f);
-
- cairo_surface_destroy (bg);
+ fill_background (s, s->x, s->y, s->background_width, s->height);
}
else
{
@@ -2001,15 +1966,7 @@ x_draw_image_glyph_string (struct glyph_string *s)
if (s->slice.y == 0)
y += box_line_vwidth;
- cairo_surface_t *bg = create_background_surface (s, x, y, width,
height);
-
- cairo_t *cr = pgtk_begin_cr_clip (s->f);
- cairo_set_source_surface (cr, bg, x, y);
- cairo_rectangle (cr, x, y, width, height);
- cairo_fill (cr);
- pgtk_end_cr_clip (s->f);
-
- cairo_surface_destroy (bg);
+ fill_background (s, x, y, width, height);
}
s->background_filled_p = true;
@@ -2111,13 +2068,7 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
if (s->face->stipple)
{
/* Fill background with a stipple pattern. */
- cairo_surface_t *bg = create_background_surface (s, x, y, w, h);
- cairo_t *cr = pgtk_begin_cr_clip (s->f);
- cairo_set_source_surface (cr, bg, x, y);
- cairo_rectangle (cr, x, y, w, h);
- cairo_fill (cr);
- pgtk_end_cr_clip (s->f);
- cairo_surface_destroy (bg);
+ fill_background (s, x, y, w, h);
}
else
{
@@ -3235,13 +3186,7 @@ pgtk_draw_fringe_bitmap (struct window *w, struct
glyph_row *row, struct draw_fr
mono-displays, the fill style may have been changed to
FillSolid in x_draw_glyph_string_background. */
if (face->stipple) {
- cairo_surface_t *bg = create_background_surface_by_face(f, face, p->bx,
p->by, p->nx, p->ny);
- cairo_t *cr = pgtk_begin_cr_clip (f);
- cairo_set_source_surface (cr, bg, p->bx, p->by);
- cairo_rectangle (cr, p->bx, p->by, p->nx, p->ny);
- cairo_fill (cr);
- pgtk_end_cr_clip (f);
- cairo_surface_destroy (bg);
+ fill_background_by_face(f, face, p->bx, p->by, p->nx, p->ny);
} else {
pgtk_set_cr_source_with_color(f, face->background);
cairo_rectangle(cr, p->bx, p->by, p->nx, p->ny);
@@ -4794,10 +4739,7 @@ pgtk_clear_under_internal_border (struct frame *f)
int y = rects[i].y;
int w = rects[i].w;
int h = rects[i].h;
- cairo_surface_t *bg = create_background_surface_by_face (f, face,
x, y, w, h);
- cairo_set_source_surface (cr, bg, x, y);
- cairo_rectangle (cr, x, y, w, h);
- cairo_fill (cr);
+ fill_background_by_face (f, face, x, y, w, h);
}
}
else
- feature/pgtk b3a20d7 027/100: Implement Scroll-bar-forground and scroll-bar-background, (continued)
- feature/pgtk b3a20d7 027/100: Implement Scroll-bar-forground and scroll-bar-background, Yuuki Harano, 2020/11/24
- feature/pgtk b721cbc 002/100: Add set_undecorated frame parameter, Yuuki Harano, 2020/11/24
- feature/pgtk f15c6a4 003/100: Add set_skip_taskbar frame parm, Yuuki Harano, 2020/11/24
- feature/pgtk 045e252 005/100: Add support for cursor_foreground_colors, Yuuki Harano, 2020/11/24
- feature/pgtk f4920a6 011/100: Add pgtk-read-file-name function, Yuuki Harano, 2020/11/24
- feature/pgtk 519a4ac 022/100: Implement Meta key detection, Yuuki Harano, 2020/11/24
- feature/pgtk 31bba95 023/100: Use gsettings instead of X resource database, Yuuki Harano, 2020/11/24
- feature/pgtk ea3ecd3 020/100: init border_pixel., Yuuki Harano, 2020/11/24
- feature/pgtk 4de4d9e 051/100: follow x_set_internal_border_width change., Yuuki Harano, 2020/11/24
- feature/pgtk 1fe7caf 068/100: Fix coding style, Yuuki Harano, 2020/11/24
- feature/pgtk 24d8263 031/100: Improve drawing efficency by refactoring code,
Yuuki Harano <=
- feature/pgtk 72f79d8 060/100: * src/pgtkselect.c: change coding style, Yuuki Harano, 2020/11/24
- feature/pgtk 806b764 039/100: Before sleep, dispatch draw events., Yuuki Harano, 2020/11/24
- feature/pgtk 209c611 063/100: * src/pgtkterm.h: Remove unused code, Yuuki Harano, 2020/11/24
- feature/pgtk 04bfe70 048/100: implement popup/context menu, Yuuki Harano, 2020/11/24
- feature/pgtk d899fc1 087/100: Fix tooltips don't hide on events, Yuuki Harano, 2020/11/24
- feature/pgtk 640f770 088/100: Fix mouse cursor doesn't appear on motion events on xwidgets, Yuuki Harano, 2020/11/24
- feature/pgtk d437aab 092/100: Avoid gtk warnings on X, Yuuki Harano, 2020/11/24
- feature/pgtk 886fcb2 096/100: Update copyright dates for PGTK files, Yuuki Harano, 2020/11/24
- feature/pgtk d6ef9af 100/100: Fix crash when .schema.xml is not installed, Yuuki Harano, 2020/11/24
- feature/pgtk 12cc104 009/100: Cleanup x_* to gui_ to match upstream work, Yuuki Harano, 2020/11/24