Subject: bug#31288: closed (Re: bug#31288: [PATCH v2] Make cairo build usable)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 26 Mar 2019 07:46:02 +0000

Your bug report

#31288: 27.0.50; [PATCH] Make cairo build somewhat usable

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
31288: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=31288
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#31288: [PATCH v2] Make cairo build usable
From: YAMAMOTO Mitsuharu <[email-masked]>
To: Ari Roponen <[email-masked]>
Cc: Eli Zaretskii <[email-masked]>, [email-masked]
Date: Tue, 26 Mar 2019 16:45:15 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

On Tue, 26 Mar 2019 15:13:58 +0900,
Ari Roponen wrote:
> 
> YAMAMOTO Mitsuharu <[email-masked]> writes:
> 
> > It causes display corruption when scroll bars are on the left.  I
> > think the patch below will fix it.
> >
> > 				     YAMAMOTO Mitsuharu
> > 				[email-masked]
> 
> Yes, I can see the corruption too, and your patch fixes it. Thank you.

Thanks for checking.  I pushed the following to master.

				     YAMAMOTO Mitsuharu
				[email-masked]

commit 9a6cba2bd397414c68217f4f5a9ea2888293ae1c
Author: YAMAMOTO Mitsuharu <[email-masked]>
Date:   Tue Mar 26 16:39:07 2019 +0900

    Fix cairo scrolling for left scroll bars case
    
    * src/xterm.c (x_scroll_run) [USE_CAIRO]: Fix scrolling by unusing
    WINDOW_LEFT_EDGE_X.  (Bug#31288)

Subject: 27.0.50; [PATCH] Make cairo build somewhat usable
From: Ari Roponen <[email-masked]>
To: [email-masked]
Date: Fri, 27 Apr 2018 16:19:16 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

Attached are two patches to make --with-cairo builds more usable.

First patch tries to fix screen corruption, and the second patch allows
cairo builds to display images.

These patches are only slightly tested, but I hope they will be useful.

In GNU Emacs 27.0.50 (build 10, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
 of 2018-04-27 built on arirop
Repository revision: caa93364d47bd28633cc065e31dd5972a1e916d5
Windowing system distributor 'Fedora Project', version 11.0.11906000
System Description: Fedora 28 (Twenty Eight)

>From 3e93c1a5290bbed7a9b923e1a16f930ec0fbd74a Mon Sep 17 00:00:00 2001
From: Ari Roponen <[email-masked]>
Date: Fri, 27 Apr 2018 15:13:12 +0300
Subject: [PATCH 1/2] Fix cairo problems

* src/xterm.c (x_begin_cr_clip): Create image surface.
(x_update_end) [USE_CAIRO]: Disable GTK3-specific code for now.
(x_scroll_run) [USE_CAIRO]: Implement scrolling.
---
 src/xterm.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index 6ab4a03002..52fe24e0fb 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -360,17 +360,12 @@ x_begin_cr_clip (struct frame *f, GC gc)
 
       if (! FRAME_CR_SURFACE (f))
         {
-          cairo_surface_t *surface;
-          surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f),
-                                               FRAME_X_DRAWABLE (f),
-                                               FRAME_DISPLAY_INFO (f)->visual,
-                                               FRAME_PIXEL_WIDTH (f),
-                                               FRAME_PIXEL_HEIGHT (f));
-          cr = cairo_create (surface);
-          cairo_surface_destroy (surface);
-        }
-      else
-        cr = cairo_create (FRAME_CR_SURFACE (f));
+	  FRAME_CR_SURFACE (f) =
+	    cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+					FRAME_PIXEL_WIDTH (f),
+					FRAME_PIXEL_HEIGHT (f));
+	}
+      cr = cairo_create (FRAME_CR_SURFACE (f));
       FRAME_CR_CONTEXT (f) = cr;
     }
   cairo_save (cr);
@@ -1236,7 +1231,8 @@ x_update_end (struct frame *f)
     {
       cairo_t *cr = 0;
       block_input();
-#if defined (USE_GTK) && defined (HAVE_GTK3)
+      /* FIXME */
+#if 0 && defined (USE_GTK) && defined (HAVE_GTK3)
       if (FRAME_GTK_WIDGET (f))
         {
           GdkWindow *w = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
@@ -4271,7 +4267,26 @@ x_scroll_run (struct window *w, struct run *run)
   x_clear_cursor (w);
 
 #ifdef USE_CAIRO
-  SET_FRAME_GARBAGED (f);
+  if (FRAME_CR_CONTEXT (f))
+    {
+      cairo_surface_t *s = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+						       width, height);
+      cairo_t *cr = cairo_create (s);
+      cairo_set_source_surface (cr, cairo_get_target (FRAME_CR_CONTEXT (f)),
+				-x, -from_y);
+      cairo_paint (cr);
+      cairo_destroy (cr);
+
+      cr = FRAME_CR_CONTEXT (f);
+      cairo_save (cr);
+      cairo_set_source_surface (cr, s, 0, to_y);
+      cairo_rectangle (cr, x, to_y, width, height);
+      cairo_fill (cr);
+      cairo_restore (cr);
+      cairo_surface_destroy (s);
+    } else {
+    SET_FRAME_GARBAGED (f);
+  }
 #else
   XCopyArea (FRAME_X_DISPLAY (f),
              FRAME_X_DRAWABLE (f), FRAME_X_DRAWABLE (f),
-- 
2.17.0

>From 6a379d983544b3e1b241860854646ca039724151 Mon Sep 17 00:00:00 2001
From: Ari Roponen <[email-masked]>
Date: Fri, 27 Apr 2018 15:14:36 +0300
Subject: [PATCH 2/2] Add partial image support for cairo builds

* src/image.c (lookup_rgb_color): Add cairo support.
(jpeg_load_body): Fix preprocessor symbol.  Move colors definition
into non-cairo part.
(imagemagick_load_image) [USE_CAIRO]: Add partial support for
cairo.
---
 src/image.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/image.c b/src/image.c
index 37416c1616..4c3f6c5ab0 100644
--- a/src/image.c
+++ b/src/image.c
@@ -4629,6 +4629,8 @@ lookup_rgb_color (struct frame *f, int r, int g, int b)
   return PALETTERGB (r >> 8, g >> 8, b >> 8);
 #elif defined HAVE_NS
   return RGB_TO_ULONG (r >> 8, g >> 8, b >> 8);
+#elif defined USE_CAIRO
+  return (0xffu << 24) | (r << 16) | (g << 8) | b;
 #else
   xsignal1 (Qfile_error,
 	    build_string ("This Emacs mishandles this image file type"));
@@ -6702,10 +6704,10 @@ jpeg_load_body (struct frame *f, struct image *img,
   FILE *volatile fp = NULL;
   JSAMPARRAY buffer;
   int row_stride, x, y;
-  unsigned long *colors;
   int width, height;
   int i, ir, ig, ib;
 #ifndef USE_CAIRO
+  unsigned long *colors;
   XImagePtr ximg = NULL;
 #endif
 
@@ -6823,7 +6825,7 @@ jpeg_load_body (struct frame *f, struct image *img,
     else
       ir = 0, ig = 0, ib = 0;
 
-#ifndef CAIRO
+#ifndef USE_CAIRO
     /* Use the color table mechanism because it handles colors that
        cannot be allocated nicely.  Such colors will be replaced with
        a default color, and we don't have to care about which colors
@@ -8551,6 +8553,9 @@ imagemagick_load_image (struct frame *f, struct image *img,
   double rotation;
   char hint_buffer[MaxTextExtent];
   char *filename_hint = NULL;
+#ifdef USE_CAIRO
+  void *data;
+#endif
 
   /* Initialize the ImageMagick environment.  */
   static bool imagemagick_initialized;
@@ -8751,6 +8756,19 @@ imagemagick_load_image (struct frame *f, struct image *img,
   /* We can now get a valid pixel buffer from the imagemagick file, if all
      went ok.  */
 
+#ifdef USE_CAIRO
+  data = xmalloc (width * height * 4);
+#ifdef HAVE_MAGICKEXPORTIMAGEPIXELS
+  MagickExportImagePixels (image_wand, 0, 0, width, height,
+			   "BGRA", CharPixel, data);
+#else
+  /* FIXME: Implement this. For now, make it white. */
+  memset(data, 0xff, width * height * 4);
+#endif
+  create_cairo_image_surface (img, data, width, height);
+  goto done;
+#endif /* USE_CAIRO */
+
   init_color_table ();
 
 #if defined (HAVE_MAGICKEXPORTIMAGEPIXELS) && ! defined (HAVE_NS)
@@ -8861,6 +8879,9 @@ imagemagick_load_image (struct frame *f, struct image *img,
   /* Put ximg into the image.  */
   image_put_x_image (f, img, ximg, 0);
 
+#ifdef USE_CAIRO
+ done:
+#endif
   /* Final cleanup. image_wand should be the only resource left. */
   DestroyMagickWand (image_wand);
   if (bg_wand) DestroyPixelWand (bg_wand);
-- 
2.17.0