Skip to content

Commit a25f8b6

Browse files
author
Yuuki Harano
authored
Merge pull request emacs-mirror#7 from fejfighter/pgtk-resize
End Resize flickering by copying surface rather than just clearing
2 parents a6fb588 + e719499 commit a25f8b6

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/gtkutil.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,6 @@ xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight)
10611061
change_frame_size (f, width, height, 0, 1, 0, 1);
10621062
SET_FRAME_GARBAGED (f);
10631063
cancel_mouse_face (f);
1064-
#ifdef HAVE_PGTK
1065-
pgtk_cr_destroy_surface (f);
1066-
#endif
10671064
}
10681065
}
10691066

@@ -1422,7 +1419,10 @@ xg_create_frame_widgets (struct frame *f)
14221419
FIXME: gtk_widget_set_double_buffered is deprecated and might stop
14231420
working in the future. We need to migrate away from combining
14241421
X and GTK+ drawing to a pure GTK+ build. */
1422+
1423+
#ifndef HAVE_PGTK
14251424
gtk_widget_set_double_buffered (wfixed, FALSE);
1425+
#endif
14261426

14271427
#if ! GTK_CHECK_VERSION (3, 22, 0)
14281428
gtk_window_set_wmclass (GTK_WINDOW (wtop),

src/pgtkterm.c

+42
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
2222
interpretation of even the system includes. */
2323
#include <config.h>
2424

25+
#include <cairo.h>
2526
#include <fcntl.h>
2627
#include <math.h>
2728
#include <pthread.h>
@@ -63,6 +64,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
6364

6465
#define FRAME_CR_CONTEXT(f) ((f)->output_data.pgtk->cr_context)
6566
#define FRAME_CR_SURFACE(f) ((f)->output_data.pgtk->cr_surface)
67+
#define FRAME_CR_SURFACE_DESIRED_WIDTH(f) \
68+
((f)->output_data.pgtk->cr_surface_desired_width)
69+
#define FRAME_CR_SURFACE_DESIRED_HEIGHT(f) \
70+
((f)->output_data.pgtk->cr_surface_desired_height)
71+
6672

6773
struct pgtk_display_info *x_display_list; /* Chain of existing displays */
6874
extern Lisp_Object tip_frame;
@@ -4864,6 +4870,7 @@ static void size_allocate(GtkWidget *widget, GtkAllocation *alloc, gpointer *use
48644870
if (f) {
48654871
PGTK_TRACE("%dx%d", alloc->width, alloc->height);
48664872
xg_frame_resized(f, alloc->width, alloc->height);
4873+
pgtk_cr_update_surface_desired_size(f, alloc->width, alloc->height);
48674874
}
48684875
}
48694876

@@ -5287,6 +5294,7 @@ static gboolean configure_event(GtkWidget *widget, GdkEvent *event, gpointer *us
52875294
if (f && widget == FRAME_GTK_OUTER_WIDGET (f)) {
52885295
PGTK_TRACE("%dx%d", event->configure.width, event->configure.height);
52895296
xg_frame_resized(f, event->configure.width, event->configure.height);
5297+
pgtk_cr_update_surface_desired_size(f, event->configure.width, event->configure.height);
52905298
}
52915299
return TRUE;
52925300
}
@@ -6604,6 +6612,40 @@ If set to a non-float value, there will be no wait at all. */);
66046612

66056613
}
66066614

6615+
6616+
void
6617+
pgtk_cr_update_surface_desired_size (struct frame *f, int width, int height)
6618+
{
6619+
PGTK_TRACE("pgtk_cr_update_surface_desired_size");
6620+
6621+
if (FRAME_CR_SURFACE_DESIRED_WIDTH (f) != width
6622+
|| FRAME_CR_SURFACE_DESIRED_HEIGHT (f) != height)
6623+
{
6624+
cairo_surface_t *old_surface = FRAME_CR_SURFACE(f);
6625+
cairo_t *cr = NULL;
6626+
cairo_t *old_cr = FRAME_CR_CONTEXT(f);
6627+
FRAME_CR_SURFACE(f) = gdk_window_create_similar_surface(gtk_widget_get_window(FRAME_GTK_WIDGET(f)),
6628+
CAIRO_CONTENT_COLOR_ALPHA,
6629+
width,
6630+
height);
6631+
6632+
if (old_surface){
6633+
cr = cairo_create(FRAME_CR_SURFACE(f));
6634+
cairo_set_source_surface (cr, old_surface, 0, 0);
6635+
6636+
cairo_paint(cr);
6637+
FRAME_CR_CONTEXT (f) = cr;
6638+
6639+
cairo_destroy(old_cr);
6640+
cairo_surface_destroy (old_surface);
6641+
}
6642+
gtk_widget_queue_draw(FRAME_GTK_WIDGET(f));
6643+
FRAME_CR_SURFACE_DESIRED_WIDTH (f) = width;
6644+
FRAME_CR_SURFACE_DESIRED_HEIGHT (f) = height;
6645+
}
6646+
}
6647+
6648+
66076649
cairo_t *
66086650
pgtk_begin_cr_clip (struct frame *f)
66096651
{

src/pgtkterm.h

+2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ struct pgtk_output
369369
#ifdef USE_CAIRO
370370
/* Cairo drawing context. */
371371
cairo_t *cr_context;
372+
int cr_surface_desired_width, cr_surface_desired_height;
372373
/* Cairo surface for double buffering */
373374
cairo_surface_t *cr_surface;
374375
cairo_surface_t *cr_surface_visible_bell;
@@ -571,6 +572,7 @@ extern int pgtk_select (int nfds, fd_set *readfds, fd_set *writefds,
571572
sigset_t *sigmask);
572573

573574
/* Cairo related functions implemented in pgtkterm.c */
575+
extern void pgtk_cr_update_surface_desired_size (struct frame *, int, int);
574576
extern cairo_t *pgtk_begin_cr_clip (struct frame *f);
575577
extern void pgtk_end_cr_clip (struct frame *f);
576578
extern void pgtk_set_cr_source_with_gc_foreground (struct frame *f, Emacs_GC *gc);

0 commit comments

Comments
 (0)