Minor tweaks to HAVE_NATIVE_SCALING code

This mostly just reindents.
* src/image.c (x_set_image_size): Always define, but to a no-op
if !HAVE_NATIVE_SCALING, to avoid an #ifdef elsewhere.
(x_create_x_image_and_pixmap): Move decl to avoid an #ifdef.
(image_create_x_image_and_pixmap): Move #ifdef outside of call.
* src/xterm.c (x_composite_image): Avoid ‘else #endif’.
This commit is contained in:
Paul Eggert 2019-01-10 15:29:21 -08:00
parent a1b7a3f2a3
commit 9609db9d98
3 changed files with 52 additions and 55 deletions

View file

@ -32,7 +32,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#endif /* USE_X_TOOLKIT */
#ifdef HAVE_XRENDER
#include <X11/extensions/Xrender.h>
# include <X11/extensions/Xrender.h>
#endif
#else /* !HAVE_X_WINDOWS */
@ -2938,10 +2938,9 @@ struct redisplay_interface
#ifdef HAVE_WINDOW_SYSTEM
#if defined (HAVE_X_WINDOWS) && defined (HAVE_XRENDER) \
|| defined (HAVE_NS)
#define HAVE_NATIVE_SCALING
#endif
# if defined HAVE_XRENDER || defined HAVE_NS
# define HAVE_NATIVE_SCALING
# endif
/* Structure describing an image. Specific image formats like XBM are
converted into this form, so that display only has to deal with
@ -2967,10 +2966,10 @@ struct image
synchronized to Pixmap. */
XImagePtr ximg, mask_img;
#ifdef HAVE_NATIVE_SCALING
# ifdef HAVE_NATIVE_SCALING
/* Picture versions of pixmap and mask for compositing. */
Picture picture, mask_picture;
#endif
# endif
#endif
/* Colors allocated for this image, if any. Allocated via xmalloc. */

View file

@ -1859,47 +1859,48 @@ compute_image_size (size_t width, size_t height,
*d_width = desired_width;
*d_height = desired_height;
}
#endif /* HAVE_IMAGEMAGICK || HAVE_NATIVE_SCALING */
#ifdef HAVE_NATIVE_SCALING
static void
x_set_image_size (struct frame *f, struct image *img)
{
#ifdef HAVE_IMAGEMAGICK
#ifdef HAVE_NATIVE_SCALING
# ifdef HAVE_IMAGEMAGICK
/* ImageMagick images are already the correct size. */
if (!EQ (image_spec_value (img->spec, QCtype, NULL), Qimagemagick))
#endif
if (EQ (image_spec_value (img->spec, QCtype, NULL), Qimagemagick))
return;
# endif
int width, height;
compute_image_size (img->width, img->height, img->spec, &width, &height);
# ifdef HAVE_NS
ns_image_set_size (img->pixmap, width, height);
img->width = width;
img->height = height;
# endif
# ifdef HAVE_XRENDER
if (img->picture)
{
int width, height;
double xscale = img->width / (double) width;
double yscale = img->height / (double) height;
compute_image_size (img->width, img->height, img->spec, &width, &height);
XTransform tmat
= {{{XDoubleToFixed (xscale), XDoubleToFixed (0), XDoubleToFixed (0)},
{XDoubleToFixed (0), XDoubleToFixed (yscale), XDoubleToFixed (0)},
{XDoubleToFixed (0), XDoubleToFixed (0), XDoubleToFixed (1)}}};
XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->picture, FilterBest,
0, 0);
XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->picture, &tmat);
#ifdef HAVE_NS
ns_image_set_size (img->pixmap, width, height);
img->width = width;
img->height = height;
#endif
#ifdef HAVE_XRENDER
if (img->picture)
{
double xscale = (double) img->width/width;
double yscale = (double) img->height/height;
XTransform tmat = {{{XDoubleToFixed (xscale), XDoubleToFixed (0), XDoubleToFixed (0)},
{XDoubleToFixed (0), XDoubleToFixed (yscale), XDoubleToFixed (0)},
{XDoubleToFixed (0), XDoubleToFixed (0), XDoubleToFixed (1)}}};
XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->picture, FilterBest, 0, 0);
XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->picture, &tmat);
img->width = width;
img->height = height;
}
#endif
}
}
# endif
#endif
#endif /* HAVE_IMAGEMAGICK || HAVE_XRENDER || HAVE_NS */
}
/* Return the id of image with Lisp specification SPEC on frame F.
@ -1956,9 +1957,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
`:background COLOR'. */
Lisp_Object ascent, margin, relief, bg;
int relief_bound;
#ifdef HAVE_NATIVE_SCALING
x_set_image_size (f, img);
#endif
ascent = image_spec_value (spec, QCascent, NULL);
if (FIXNUMP (ascent))
@ -2139,9 +2138,6 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
Display *display = FRAME_X_DISPLAY (f);
Drawable drawable = FRAME_X_DRAWABLE (f);
Screen *screen = FRAME_X_SCREEN (f);
#ifdef HAVE_XRENDER
int event_basep, error_basep;
#endif
eassert (input_blocked_p ());
@ -2178,7 +2174,8 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
return 0;
}
#ifdef HAVE_XRENDER
# ifdef HAVE_XRENDER
int event_basep, error_basep;
if (picture && XRenderQueryExtension (display, &event_basep, &error_basep))
{
XRenderPictFormat *format;
@ -2191,7 +2188,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
: PictStandardA8);
*picture = XRenderCreatePicture (display, *pixmap, format, 0, &attr);
}
#endif
# endif
return 1;
#endif /* HAVE_X_WINDOWS */
@ -2367,14 +2364,13 @@ image_create_x_image_and_pixmap (struct frame *f, struct image *img,
{
eassert ((!mask_p ? img->pixmap : img->mask) == NO_PIXMAP);
Picture *picture = NULL;
#ifdef HAVE_XRENDER
picture = !mask_p ? &img->picture : &img->mask_picture;
#endif
return x_create_x_image_and_pixmap (f, width, height, depth, ximg,
!mask_p ? &img->pixmap : &img->mask,
#ifdef HAVE_XRENDER
!mask_p ? &img->picture : &img->mask_picture
#else
NULL
#endif
);
picture);
}
/* Put X image XIMG into image IMG on frame F, as a mask if and only

View file

@ -3001,13 +3001,14 @@ x_composite_image (struct glyph_string *s, Pixmap dest,
width, height);
XRenderFreePicture (s->display, destination);
return;
}
else
#endif
XCopyArea (s->display, s->img->pixmap,
dest, s->gc,
srcX, srcY,
width, height, dstX, dstY);
XCopyArea (s->display, s->img->pixmap,
dest, s->gc,
srcX, srcY,
width, height, dstX, dstY);
}
@ -3060,7 +3061,8 @@ x_draw_image_foreground (struct glyph_string *s)
image_rect.width = s->slice.width;
image_rect.height = s->slice.height;
if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
x_composite_image (s, FRAME_X_DRAWABLE (s->f), s->slice.x + r.x - x, s->slice.y + r.y - y,
x_composite_image (s, FRAME_X_DRAWABLE (s->f),
s->slice.x + r.x - x, s->slice.y + r.y - y,
r.x, r.y, r.width, r.height);
}
else