From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ari Roponen Newsgroups: gmane.emacs.bugs Subject: bug#31288: [PATCH v2] Make cairo build usable Date: Sat, 28 Apr 2018 10:33:40 +0300 Message-ID: <87h8nv23aj.fsf@gmail.com> References: <87lgd8kcrv.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1524900731 10395 195.159.176.226 (28 Apr 2018 07:32:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 28 Apr 2018 07:32:11 +0000 (UTC) To: 31288@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 28 09:32:07 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fCKKw-0002Wp-MJ for geb-bug-gnu-emacs@m.gmane.org; Sat, 28 Apr 2018 09:32:02 +0200 Original-Received: from localhost ([::1]:51188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCKN3-0002ow-MT for geb-bug-gnu-emacs@m.gmane.org; Sat, 28 Apr 2018 03:34:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fCKMx-0002iJ-6D for bug-gnu-emacs@gnu.org; Sat, 28 Apr 2018 03:34:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fCKMt-0004Iy-Sn for bug-gnu-emacs@gnu.org; Sat, 28 Apr 2018 03:34:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33656) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fCKMt-0004Is-Mv for bug-gnu-emacs@gnu.org; Sat, 28 Apr 2018 03:34:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fCKMt-0003H9-Cl for bug-gnu-emacs@gnu.org; Sat, 28 Apr 2018 03:34:03 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87lgd8kcrv.fsf@gmail.com> Resent-From: Ari Roponen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Apr 2018 07:34:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31288 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 31288-submit@debbugs.gnu.org id=B31288.152490083212574 (code B ref 31288); Sat, 28 Apr 2018 07:34:03 +0000 Original-Received: (at 31288) by debbugs.gnu.org; 28 Apr 2018 07:33:52 +0000 Original-Received: from localhost ([127.0.0.1]:41553 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fCKMh-0003Gd-Fo for submit@debbugs.gnu.org; Sat, 28 Apr 2018 03:33:52 -0400 Original-Received: from mail-lf0-f48.google.com ([209.85.215.48]:33869) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fCKMe-0003GO-Kw for 31288@debbugs.gnu.org; Sat, 28 Apr 2018 03:33:49 -0400 Original-Received: by mail-lf0-f48.google.com with SMTP id h4-v6so5766288lfc.1 for <31288@debbugs.gnu.org>; Sat, 28 Apr 2018 00:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version; bh=sHMobkSozHnXuwxxLqVA5x1x2FtE+Prcm1phTkLygrA=; b=cV2+12IEdqM15c0jZ5GVKLx849exNGFI9dPayb3SJNwwLQrNVIoMl2AS+uCbfFBpvi kXL+nLmZYBqkC0nEsFCMYyFeQbwlsuZmhHrzz6Q5/i60nO8ExZdPbgqvZgWFBw25ap0z Q8KVFTjrDK5JqysIdeAaeGupq0Kx1ZItDQ2h8xQ5Zihdrj6woUzRjRfrjWdZqJLAvasG MeKjRKCSLbfpfZ4osFgef453VbKbBUIaN2a6tnMAA91L0tqoayIpqB1eK0ubBbRBaM0x cBvY+iFWGKl6e1LRJLLHRAmKB0lIoWceH/6pjtZs148SrYNnZ67lTd/XFlT/vFgJVjzi 3jzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=sHMobkSozHnXuwxxLqVA5x1x2FtE+Prcm1phTkLygrA=; b=hjEzpKLyuo/68KesqMIBcmEP8a3D1WNKol/YyWtkV7kGfaIdM0PxHPBsDV3jz99Jnt Hg45QzZTUi+DnWhkRrch7AcYZz6nm26s7yHpwRt1UrbpD8Wakh95dY9bpdLfypyzsAGg snhQfStYbjl4k0sVlfLGEmBq/9PAqn2Z8dzA24hpdCOE1Su3Ev4bXXHkDN4gcKCDjmQw enshatiJK72AnEnLjFp3ddTmwmaKPsxqiMfBMTtouMrM0lgCwc7Bye+KSHZARXNWeOtw mgkV6aehuVyoaYQT42RIuD4fsOZgBCDKLfbao4exJum8uTBUeHyMw1oR5bJwreDeRPMx VDvA== X-Gm-Message-State: ALQs6tDjcfTy7wosx749/nh4GdRXfGZeGgXYGx2hFFyXamcySzhVFP88 XwZzvpW3LHl+NITjnAM3bQ== X-Google-Smtp-Source: AB8JxZo/nF4C+i7j6E7uPDrrYSlGiKxldP6hxRl3arN9X6CGGkYyLIDxAhMoDLQIAuE2VLm+ktRW0Q== X-Received: by 2002:a2e:808a:: with SMTP id i10-v6mr3381289ljg.67.1524900822692; Sat, 28 Apr 2018 00:33:42 -0700 (PDT) Original-Received: from arirop ([2001:2003:f7af:fd00:930:26ef:d4a3:c2ea]) by smtp.gmail.com with ESMTPSA id p74-v6sm598396lfe.42.2018.04.28.00.33.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 28 Apr 2018 00:33:41 -0700 (PDT) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:145795 Archived-At: --=-=-= Content-Type: text/plain Hi, attached are new versions of patches. This time, the cairo support for imagemagick is better integrated into existing code. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Fix-cairo-problems.patch >From d197ca49c2f0ff6b73e4410ba8e3414f3bbf2e1d Mon Sep 17 00:00:00 2001 From: Ari Roponen 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]: Remove GTK3-specific code. (x_scroll_run) [USE_CAIRO]: Implement scrolling. --- src/xterm.c | 84 +++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index 6ab4a03002..35e10568fa 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); @@ -1234,32 +1229,24 @@ x_update_end (struct frame *f) #ifdef USE_CAIRO if (FRAME_CR_SURFACE (f)) { - cairo_t *cr = 0; - block_input(); -#if defined (USE_GTK) && defined (HAVE_GTK3) - if (FRAME_GTK_WIDGET (f)) - { - GdkWindow *w = gtk_widget_get_window (FRAME_GTK_WIDGET (f)); - cr = gdk_cairo_create (w); - } - else -#endif - { - cairo_surface_t *surface; - int width = FRAME_PIXEL_WIDTH (f); - int height = FRAME_PIXEL_HEIGHT (f); - if (! FRAME_EXTERNAL_TOOL_BAR (f)) - height += FRAME_TOOL_BAR_HEIGHT (f); - if (! FRAME_EXTERNAL_MENU_BAR (f)) - height += FRAME_MENU_BAR_HEIGHT (f); - surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f), - FRAME_X_DRAWABLE (f), - FRAME_DISPLAY_INFO (f)->visual, - width, - height); - cr = cairo_create (surface); - cairo_surface_destroy (surface); - } + cairo_t *cr; + cairo_surface_t *surface; + int width, height; + + block_input (); + width = FRAME_PIXEL_WIDTH (f); + height = FRAME_PIXEL_HEIGHT (f); + if (! FRAME_EXTERNAL_TOOL_BAR (f)) + height += FRAME_TOOL_BAR_HEIGHT (f); + if (! FRAME_EXTERNAL_MENU_BAR (f)) + height += FRAME_MENU_BAR_HEIGHT (f); + surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f), + FRAME_X_DRAWABLE (f), + FRAME_DISPLAY_INFO (f)->visual, + width, + height); + cr = cairo_create (surface); + cairo_surface_destroy (surface); cairo_set_source_surface (cr, FRAME_CR_SURFACE (f), 0, 0); cairo_paint (cr); @@ -4271,7 +4258,28 @@ 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 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Fix-image-support-for-cairo-builds.patch >From 3bcf9bb961bbe42ea02191ac22f3ed3bb681c771 Mon Sep 17 00:00:00 2001 From: Ari Roponen Date: Fri, 27 Apr 2018 15:14:36 +0300 Subject: [PATCH 2/2] Fix 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 support for cairo. --- src/image.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/image.c b/src/image.c index 37416c1616..4d5a1bf5e6 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 @@ -8537,7 +8539,9 @@ imagemagick_load_image (struct frame *f, struct image *img, int width, height; size_t image_width, image_height; MagickBooleanType status; +#ifndef USE_CAIRO XImagePtr ximg; +#endif int x, y; MagickWand *image_wand; PixelIterator *iterator; @@ -8551,6 +8555,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 = NULL; +#endif /* Initialize the ImageMagick environment. */ static bool imagemagick_initialized; @@ -8759,6 +8766,12 @@ imagemagick_load_image (struct frame *f, struct image *img, /* Magicexportimage is normally faster than pixelpushing. This method is also well tested. Some aspects of this method are ad-hoc and needs to be more researched. */ + void *dataptr; +#ifdef USE_CAIRO + data = xmalloc (width * height * 4); + const char *exportdepth = "BGRA"; + dataptr = data; +#else int imagedepth = 24; /*MagickGetImageDepth(image_wand);*/ const char *exportdepth = imagedepth <= 8 ? "I" : "BGRP"; /*"RGBP";*/ /* Try to create a x pixmap to hold the imagemagick pixmap. */ @@ -8771,6 +8784,8 @@ imagemagick_load_image (struct frame *f, struct image *img, image_error ("Imagemagick X bitmap allocation failure"); goto imagemagick_error; } + dataptr = ximg->data; +#endif /* not USE_CAIRO */ /* Oddly, the below code doesn't seem to work:*/ /* switch(ximg->bitmap_unit){ */ @@ -8793,14 +8808,17 @@ imagemagick_load_image (struct frame *f, struct image *img, */ int pixelwidth = CharPixel; /*??? TODO figure out*/ MagickExportImagePixels (image_wand, 0, 0, width, height, - exportdepth, pixelwidth, ximg->data); + exportdepth, pixelwidth, dataptr); } else #endif /* HAVE_MAGICKEXPORTIMAGEPIXELS */ { size_t image_height; MagickRealType color_scale = 65535.0 / QuantumRange; - +#ifdef USE_CAIRO + data = xmalloc (width * height * 4); + color_scale /= 256; +#else /* Try to create a x pixmap to hold the imagemagick pixmap. */ if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) @@ -8811,6 +8829,7 @@ imagemagick_load_image (struct frame *f, struct image *img, image_error ("Imagemagick X bitmap allocation failure"); goto imagemagick_error; } +#endif /* Copy imagemagick image to x with primitive yet robust pixel pusher loop. This has been tested a lot with many different @@ -8823,7 +8842,9 @@ imagemagick_load_image (struct frame *f, struct image *img, #ifdef COLOR_TABLE_SUPPORT free_color_table (); #endif +#ifndef USE_CAIRO x_destroy_x_image (ximg); +#endif image_error ("Imagemagick pixel iterator creation failed"); goto imagemagick_error; } @@ -8839,16 +8860,27 @@ imagemagick_load_image (struct frame *f, struct image *img, for (x = 0; x < xlim; x++) { PixelGetMagickColor (pixels[x], &pixel); +#ifdef USE_CAIRO + ((uint32_t *)data)[width * y + x] = + lookup_rgb_color (f, + color_scale * pixel.red, + color_scale * pixel.green, + color_scale * pixel.blue); +#else XPutPixel (ximg, x, y, lookup_rgb_color (f, color_scale * pixel.red, color_scale * pixel.green, color_scale * pixel.blue)); +#endif } } DestroyPixelIterator (iterator); } +#ifdef USE_CAIRO + create_cairo_image_surface (img, data, width, height); +#else #ifdef COLOR_TABLE_SUPPORT /* Remember colors allocated for this image. */ img->colors = colors_in_color_table (&img->ncolors); @@ -8860,6 +8892,7 @@ imagemagick_load_image (struct frame *f, struct image *img, /* Put ximg into the image. */ image_put_x_image (f, img, ximg, 0); +#endif /* Final cleanup. image_wand should be the only resource left. */ DestroyMagickWand (image_wand); -- 2.17.0 --=-=-=--