summaryrefslogtreecommitdiff
path: root/src/xterm.h
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@raeburn.org>2015-10-03 00:18:50 -0400
committerKen Raeburn <raeburn@raeburn.org>2015-10-08 01:44:42 -0400
commite23ed19ff933c35111f3a806b4104fee8ef42f55 (patch)
treedca1de3b389da477befb537c46a3a7992c02b1ea /src/xterm.h
parentb8eea1d7b1485a147f112127c0ca58cb1a0a8ebb (diff)
downloademacs-e23ed19ff933c35111f3a806b4104fee8ef42f55.tar.gz
emacs-e23ed19ff933c35111f3a806b4104fee8ef42f55.tar.bz2
emacs-e23ed19ff933c35111f3a806b4104fee8ef42f55.zip
Reduce color allocation/query traffic in the TrueColor case.
When working with an X visual with TrueColor class, pixel values can be generated from the RGB values according to mask value provided by the server on connection. Some of the image-handling code was already doing this. * src/xterm.h (x_make_truecolor_pixel): New function; code taken from lookup_rgb_color. (x_mutable_colormap): New function. * src/image.c (lookup_rgb_color): Move pixel composition code to x_make_truecolor_pixel. (x_kill_gs_process): Call x_mutable_colormap. * src/xfaces.c (x_free_colors, x_free_dpy_colors): Call x_mutable_colormap. * src/xftfont.c (xftfont_get_colors): Call x_query_colors. * src/xterm.c (x_query_colors): For a TrueColor display, decompose the pixel value into RGB values directly, and don't send a request to the server. (x_alloc_nearest_color): For a TrueColor display, construct the pixel value with x_make_truecolor_pixel. (x_copy_color): For an immutable color map, just return the provided pixel value.
Diffstat (limited to 'src/xterm.h')
-rw-r--r--src/xterm.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/xterm.h b/src/xterm.h
index 300a8b769f2..d8edbc208f4 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1085,6 +1085,33 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time t)
dpyinfo->last_user_time = t;
}
+INLINE unsigned long
+x_make_truecolor_pixel (struct x_display_info *dpyinfo, int r, int g, int b)
+{
+ unsigned long pr, pg, pb;
+
+ /* Scale down RGB values to the visual's bits per RGB, and shift
+ them to the right position in the pixel color. Note that the
+ original RGB values are 16-bit values, as usual in X. */
+ pr = (r >> (16 - dpyinfo->red_bits)) << dpyinfo->red_offset;
+ pg = (g >> (16 - dpyinfo->green_bits)) << dpyinfo->green_offset;
+ pb = (b >> (16 - dpyinfo->blue_bits)) << dpyinfo->blue_offset;
+
+ /* Assemble the pixel color. */
+ return pr | pg | pb;
+}
+
+/* If display has an immutable color map, freeing colors is not
+ necessary and some servers don't allow it, so we won't do it. That
+ also allows us to make other optimizations relating to server-side
+ reference counts. */
+INLINE bool
+x_mutable_colormap (Visual *visual)
+{
+ int class = visual->class;
+ return (class != StaticColor && class != StaticGray && class != TrueColor);
+}
+
extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
extern bool x_wm_supports (struct frame *, Atom);
extern void x_wait_for_event (struct frame *, int);