diff options
| author | Po Lu | 2024-04-23 15:57:45 +0800 |
|---|---|---|
| committer | Po Lu | 2024-04-23 15:57:45 +0800 |
| commit | cd7456e00d719d32c203c71b4e23c98b0c4e1967 (patch) | |
| tree | 496bdb8d0a1f49aa4668d68c08e2f9309fd1868a /src | |
| parent | b9c191d690fd5d1480858469df23cc4509996fae (diff) | |
| download | emacs-cd7456e00d719d32c203c71b4e23c98b0c4e1967.tar.gz emacs-cd7456e00d719d32c203c71b4e23c98b0c4e1967.zip | |
Enable configuring Emacs for "pseudo-grayscale" systems on Android
* doc/emacs/android.texi (Android Windowing): Document how to
configure Emacs for monochrome displays.
* src/androidfns.c (Fx_display_visual_class): Return
Qstatic_gray when n_planes is smaller than 24.
(Fandroid_get_connection): Set n_planes by the value of
android_display_planes.
(syms_of_androidfns): <Qstatic_gray>: New function.
* src/androidterm.c (android_alloc_nearest_color): Allocate
monochrome colors similarly to the X server.
(android_query_colors): Fix typos.
(android_draw_fringe_bitmap): Create bitmaps of n_image_planes
depth.
(android_term_init): Initialize n_image_planes to 24.
(syms_of_androidterm) <android_display_planes>: New variable.
* src/androidterm.h (struct android_display_info): New field
`n_image_planes'.
* src/image.c (n_planes) [HAVE_ANDROID]: Define to
n_image_planes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/androidfns.c | 19 | ||||
| -rw-r--r-- | src/androidterm.c | 48 | ||||
| -rw-r--r-- | src/androidterm.h | 5 | ||||
| -rw-r--r-- | src/image.c | 3 |
4 files changed, 64 insertions, 11 deletions
diff --git a/src/androidfns.c b/src/androidfns.c index 9f7ac8b69b2..b6df7ae0677 100644 --- a/src/androidfns.c +++ b/src/androidfns.c | |||
| @@ -1345,7 +1345,12 @@ DEFUN ("x-display-visual-class", Fx_display_visual_class, | |||
| 1345 | doc: /* SKIP: real doc in xfns.c. */) | 1345 | doc: /* SKIP: real doc in xfns.c. */) |
| 1346 | (Lisp_Object terminal) | 1346 | (Lisp_Object terminal) |
| 1347 | { | 1347 | { |
| 1348 | check_android_display_info (terminal); | 1348 | struct android_display_info *dpyinfo; |
| 1349 | |||
| 1350 | dpyinfo = check_android_display_info (terminal); | ||
| 1351 | |||
| 1352 | if (dpyinfo->n_planes < 24) | ||
| 1353 | return Qstatic_gray; | ||
| 1349 | 1354 | ||
| 1350 | return Qtrue_color; | 1355 | return Qtrue_color; |
| 1351 | } | 1356 | } |
| @@ -1805,7 +1810,16 @@ Android, so there is no equivalent of `x-open-connection'. */) | |||
| 1805 | terminal = Qnil; | 1810 | terminal = Qnil; |
| 1806 | 1811 | ||
| 1807 | if (x_display_list) | 1812 | if (x_display_list) |
| 1808 | XSETTERMINAL (terminal, x_display_list->terminal); | 1813 | { |
| 1814 | XSETTERMINAL (terminal, x_display_list->terminal); | ||
| 1815 | |||
| 1816 | /* Update the display's bit depth from | ||
| 1817 | `android_display_planes'. */ | ||
| 1818 | x_display_list->n_planes | ||
| 1819 | = (android_display_planes > 8 | ||
| 1820 | ? 24 : (android_display_planes > 1 | ||
| 1821 | ? android_display_planes : 1)); | ||
| 1822 | } | ||
| 1809 | 1823 | ||
| 1810 | return terminal; | 1824 | return terminal; |
| 1811 | #endif | 1825 | #endif |
| @@ -3479,6 +3493,7 @@ syms_of_androidfns (void) | |||
| 3479 | { | 3493 | { |
| 3480 | /* Miscellaneous symbols used by some functions here. */ | 3494 | /* Miscellaneous symbols used by some functions here. */ |
| 3481 | DEFSYM (Qtrue_color, "true-color"); | 3495 | DEFSYM (Qtrue_color, "true-color"); |
| 3496 | DEFSYM (Qstatic_gray, "static-color"); | ||
| 3482 | DEFSYM (Qwhen_mapped, "when-mapped"); | 3497 | DEFSYM (Qwhen_mapped, "when-mapped"); |
| 3483 | 3498 | ||
| 3484 | DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape, | 3499 | DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape, |
diff --git a/src/androidterm.c b/src/androidterm.c index c920375fdbe..e4f3abdb2d3 100644 --- a/src/androidterm.c +++ b/src/androidterm.c | |||
| @@ -1964,10 +1964,33 @@ android_parse_color (struct frame *f, const char *color_name, | |||
| 1964 | bool | 1964 | bool |
| 1965 | android_alloc_nearest_color (struct frame *f, Emacs_Color *color) | 1965 | android_alloc_nearest_color (struct frame *f, Emacs_Color *color) |
| 1966 | { | 1966 | { |
| 1967 | unsigned int ntsc; | ||
| 1968 | |||
| 1967 | gamma_correct (f, color); | 1969 | gamma_correct (f, color); |
| 1968 | color->pixel = RGB_TO_ULONG (color->red / 256, | 1970 | |
| 1969 | color->green / 256, | 1971 | if (FRAME_DISPLAY_INFO (f)->n_planes == 1) |
| 1970 | color->blue / 256); | 1972 | { |
| 1973 | /* Black and white. I think this is the luminance formula applied | ||
| 1974 | by the X server on generic monochrome framebuffers. */ | ||
| 1975 | color->pixel = ((((30l * color->red | ||
| 1976 | + 59l * color->green | ||
| 1977 | + 11l * color->blue) >> 8) | ||
| 1978 | >= (((1 << 8) -1) * 50)) | ||
| 1979 | ? 0xffffff : 0); | ||
| 1980 | } | ||
| 1981 | else if (FRAME_DISPLAY_INFO (f)->n_planes <= 8) | ||
| 1982 | { | ||
| 1983 | /* 256 grays. */ | ||
| 1984 | ntsc = min (255, ((color->red * 0.299 | ||
| 1985 | + color->green * 0.587 | ||
| 1986 | + color->blue * 0.114) | ||
| 1987 | / 256)); | ||
| 1988 | color->pixel = RGB_TO_ULONG (ntsc, ntsc, ntsc); | ||
| 1989 | } | ||
| 1990 | else | ||
| 1991 | color->pixel = RGB_TO_ULONG (color->red / 256, | ||
| 1992 | color->green / 256, | ||
| 1993 | color->blue / 256); | ||
| 1971 | 1994 | ||
| 1972 | return true; | 1995 | return true; |
| 1973 | } | 1996 | } |
| @@ -1980,8 +2003,8 @@ android_query_colors (struct frame *f, Emacs_Color *colors, int ncolors) | |||
| 1980 | for (i = 0; i < ncolors; ++i) | 2003 | for (i = 0; i < ncolors; ++i) |
| 1981 | { | 2004 | { |
| 1982 | colors[i].red = RED_FROM_ULONG (colors[i].pixel) * 257; | 2005 | colors[i].red = RED_FROM_ULONG (colors[i].pixel) * 257; |
| 1983 | colors[i].green = RED_FROM_ULONG (colors[i].pixel) * 257; | 2006 | colors[i].green = GREEN_FROM_ULONG (colors[i].pixel) * 257; |
| 1984 | colors[i].blue = RED_FROM_ULONG (colors[i].pixel) * 257; | 2007 | colors[i].blue = BLUE_FROM_ULONG (colors[i].pixel) * 257; |
| 1985 | } | 2008 | } |
| 1986 | } | 2009 | } |
| 1987 | 2010 | ||
| @@ -2630,7 +2653,7 @@ android_draw_fringe_bitmap (struct window *w, struct glyph_row *row, | |||
| 2630 | clipmask = ANDROID_NONE; | 2653 | clipmask = ANDROID_NONE; |
| 2631 | background = face->background; | 2654 | background = face->background; |
| 2632 | cursor_pixel = f->output_data.android->cursor_pixel; | 2655 | cursor_pixel = f->output_data.android->cursor_pixel; |
| 2633 | depth = FRAME_DISPLAY_INFO (f)->n_planes; | 2656 | depth = FRAME_DISPLAY_INFO (f)->n_image_planes; |
| 2634 | 2657 | ||
| 2635 | /* Intersect the destination rectangle with that of the row. | 2658 | /* Intersect the destination rectangle with that of the row. |
| 2636 | Setting a clip mask overrides the clip rectangles provided by | 2659 | Setting a clip mask overrides the clip rectangles provided by |
| @@ -6504,8 +6527,8 @@ android_term_init (void) | |||
| 6504 | terminal = android_create_terminal (dpyinfo); | 6527 | terminal = android_create_terminal (dpyinfo); |
| 6505 | terminal->kboard = allocate_kboard (Qandroid); | 6528 | terminal->kboard = allocate_kboard (Qandroid); |
| 6506 | terminal->kboard->reference_count++; | 6529 | terminal->kboard->reference_count++; |
| 6507 | |||
| 6508 | dpyinfo->n_planes = 24; | 6530 | dpyinfo->n_planes = 24; |
| 6531 | dpyinfo->n_image_planes = 24; | ||
| 6509 | 6532 | ||
| 6510 | /* This function should only be called once at startup. */ | 6533 | /* This function should only be called once at startup. */ |
| 6511 | eassert (!x_display_list); | 6534 | eassert (!x_display_list); |
| @@ -6702,6 +6725,17 @@ Emacs is running on. */); | |||
| 6702 | doc: /* Name of the developer of the running version of Android. */); | 6725 | doc: /* Name of the developer of the running version of Android. */); |
| 6703 | Vandroid_build_manufacturer = Qnil; | 6726 | Vandroid_build_manufacturer = Qnil; |
| 6704 | 6727 | ||
| 6728 | DEFVAR_INT ("android-display-planes", android_display_planes, | ||
| 6729 | doc: /* Depth and visual class of the display. | ||
| 6730 | This variable controls the visual class and depth of the display, which | ||
| 6731 | cannot be detected on Android. The default value of 24, and values from | ||
| 6732 | there to 8 represent a TrueColor display providing 24 planes, values | ||
| 6733 | between 8 and 1 StaticGray displays providing that many planes, and 1 or | ||
| 6734 | lower monochrome displays with a single plane. Modifications to this | ||
| 6735 | variable must be completed before the window system is initialized, in, | ||
| 6736 | for instance, `early-init.el', or they will be of no effect. */); | ||
| 6737 | android_display_planes = 24; | ||
| 6738 | |||
| 6705 | DEFVAR_LISP ("x-ctrl-keysym", Vx_ctrl_keysym, | 6739 | DEFVAR_LISP ("x-ctrl-keysym", Vx_ctrl_keysym, |
| 6706 | doc: /* SKIP: real doc in xterm.c. */); | 6740 | doc: /* SKIP: real doc in xterm.c. */); |
| 6707 | Vx_ctrl_keysym = Qnil; | 6741 | Vx_ctrl_keysym = Qnil; |
diff --git a/src/androidterm.h b/src/androidterm.h index fd4cc99f641..24eb2c30f12 100644 --- a/src/androidterm.h +++ b/src/androidterm.h | |||
| @@ -77,8 +77,9 @@ struct android_display_info | |||
| 77 | /* Mouse highlight information. */ | 77 | /* Mouse highlight information. */ |
| 78 | Mouse_HLInfo mouse_highlight; | 78 | Mouse_HLInfo mouse_highlight; |
| 79 | 79 | ||
| 80 | /* Number of planes on this screen. Always 24. */ | 80 | /* Number of planes on this screen, and the same for the purposes of |
| 81 | int n_planes; | 81 | image processing. */ |
| 82 | int n_planes, n_image_planes; | ||
| 82 | 83 | ||
| 83 | /* Mask of things causing the mouse to be grabbed. */ | 84 | /* Mask of things causing the mouse to be grabbed. */ |
| 84 | int grabbed; | 85 | int grabbed; |
diff --git a/src/image.c b/src/image.c index 3028c2e707a..d1faadee968 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -198,6 +198,9 @@ typedef android_pixmap Pixmap; | |||
| 198 | #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG (color) * 0x101) | 198 | #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG (color) * 0x101) |
| 199 | #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG (color) * 0x101) | 199 | #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG (color) * 0x101) |
| 200 | 200 | ||
| 201 | /* DPYINFO->n_planes is unsuitable for this file, because it accepts | ||
| 202 | values that may not be supported for pixmap creation. */ | ||
| 203 | #define n_planes n_image_planes | ||
| 201 | #endif | 204 | #endif |
| 202 | 205 | ||
| 203 | static void image_disable_image (struct frame *, struct image *); | 206 | static void image_disable_image (struct frame *, struct image *); |