I have implemented a new version of the Emacs canvas patch. Refreshing avoids redrawing or even checking the entire buffer. Only the single glyph where the canvas is attached as display property is redrawn.

I welcome help with testing or porting to other platforms than Cairo/Pgtk or X. @divyaranjan ported his Pale library to the new version of the canvas API, with good results.

Canvas patch and test program:
https://github.com/minad/emacs-canvas-patch

Discussion on the bug tracker:
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=80281

GitHub - minad/emacs-canvas-patch

Contribute to minad/emacs-canvas-patch development by creating an account on GitHub.

GitHub

@minad In the latest exchanges, Eli asked for performance on older machines. The oldest machine I currently have access to is a Thinkpad T440p with i5 4th gen.

Are there any #Emacs users with older machines, say core 2 duo and the like, who would be interested in testing this patch out?

@divyaranjan @minad Why not run it in an (underclocked) VM?
@pkal @minad Indeed, I've started testing it there. I'll also ask Eli for clarification on whether VMs are comparable or not.
@divyaranjan @minad @pkal i have access to a t400. it already has some old Emacs version installed. if you are able to explain the steps to test it (ideally alongside existing emacs install), i could poss do so this week. (explain the steps, as in, to layfolk; i love (e)lisp but i am no pro)

@mousebot @minad @pkal

Here are the steps:

1. Clone the following fork of Emacs:
https://codeberg.org/monadicsheep/emacs

And then build it with `make bootstrap` and then `make -j`.

2. Test that the above works by opening `src/emacs -Q`.

3. Clone the following, switch to `canvas` branch and do a `make all`:
https://codeberg.org/monadicsheep/pale

4. Do `src/emacs -q -L /path/to/pale/`.

5. Then, in the new Emacs' scratch buffer, evaluate:

```
(setq video-player (pale-create-canvas 1280 720 'canvas-id))
(switch-to-buffer "*pale-video*")
(pale-display video-player)
(pale-video-play video-player "/path/to/video")
```
You can change the dimensions, and the canvas id as you see fit.

Try rendering both an usual 720p 30fps videos, and then push towards 60fps videos. See how the CPU responds. Also compare it with how mpv's performance is, whether Emacs takes more CPU.

emacs

GNU Emacs, the extensible, customizable, self-documenting real-time display editor, with the canvas patch set. See: https://lists.gnu.org/archive/html/bug-gnu-emacs/2026-01/msg01995.html

Codeberg.org

@divyaranjan while waiting for guix pull on the old machine, i'm unable to build pale.

i get

pale.el:29:1:Error: Module could not be opened: "/home/mouse/code/elisp/pale/pale-module.so", "libEGL.so.1: cannot open shared object file: No such file or directory

i have libegl and libegl-dev packages installed, so not sure what i'm missing?

@mousebot Do you have `mesa`?
@divyaranjan i have libegl-mesa0 and libegl1-mesa-dev. i have none of the libegl-nvidia packages. i guess i'm running old debian stable. the mesa versions are 20.3.5-1.
@mousebot That is weird, you got no errors when compiling pale?
@divyaranjan that is the error that i get, make errors and pale doesn't build. i cloned then called `make all` in the directory. if there's something else i need to do maybe walk me thru it, unforch i have close to zero experience compiling C programmes.

@divyaranjan here is the full output i see after calling make all:

gcc -O3 -g -fPIC -DUSE_PALE_GPU -D_GNU_SOURCE -c libpale.c -o libpale.o
gcc -O3 -g -fPIC -DUSE_PALE_GPU -D_GNU_SOURCE -c pale-video.c -o pale-video.o
gcc -O3 -g -fPIC -DUSE_PALE_GPU -D_GNU_SOURCE -c pale-diag.c -o pale-diag.o
gcc -O3 -g -fPIC -DUSE_PALE_GPU -D_GNU_SOURCE -c elisp-helpers.c -o elisp-helpers.o
gcc -O3 -g -fPIC -DUSE_PALE_GPU -D_GNU_SOURCE -c pale-gpu.c -o pale-gpu.o
gcc -O3 -g -fPIC -DUSE_PALE_GPU -D_GNU_SOURCE -shared \
pale-module.c libpale.o pale-video.o pale-diag.o elisp-helpers.o pale-gpu.o -o pale-module.so -lEGL -lGL -lpthread -ldl
emacs --batch -Q --eval '(setq enable-dir-local-variables nil)' -L . -f batch-byte-compile pale.el

In toplevel form:
pale.el:29:1:Error: Module could not be opened: "/path/to/pale/pale-module.so", "libEGL.so.1: cannot open shared object file: No such file or directory"
make: *** [Makefile:84: pale.elc] Error 1

@mousebot That's pretty much all you need to do. So GCC is able to link with EGL but somehow the resulted shared object can't find libEGL.
@divyaranjan i just built it fine on my daily driver, so there's something broken with it on the old machine only...
@mousebot On debian can you install the libegl1 package and then try?
@mousebot And/or libgl1 package
@divyaranjan i have both installed it seems. i don't have the "transitional dummy package" versions tho, e.g. `libegl1-mesa`, or `libgl1-mesa-glx`
@mousebot I see, I have zero idea how debian works with these things...
@divyaranjan @mousebot BTW don't you want them to test the canvas branch. Which, AFAIA, doesn't require mesa?
@tusharhero @mousebot Oh, right. Slipped from my mind. Yes @mousebot if you switch to the canvas branch and then rebuild Pale you should be able to render stuff.
@divyaranjan @mousebot you should edit the instructions.
@divyaranjan @tusharhero same error trying to build it with branch canvas checked out
@mousebot @tusharhero Yeah but in this case it's a red herring. Go ahead and load pale into an emacs session and render a video.
@divyaranjan @tusharhero i also somehow (sorry) failed to get your guix channel to be respected by my guix. added it from the repo, then guix pull, took ages but worked, but now guix describe doesn't show the channel and i can't install emacs-canvas :/ i am a tester failure.
@mousebot @divyaranjan guix time-machine -C channels.scm -- install emacs-canvas
@mousebot @divyaranjan Though your problem is probably that you are using the wrong guix. (the older one).
@mousebot @tusharhero haha this sort of thing happens. Don't call yourself a failure! Thanks for taking the time!
@divyaranjan @tusharhero well damn, so last night i also failed to build emacs-canvas on my old machine from your channel. it spent a v long time building (using the time-machine cmd tusharhero suggested), then failed and gave me a binary(!) log message of the build failure, which i don't know how to inspect. i was fated to not help out, at least yesterday.

@mousebot @divyaranjan zcat or emacs to read the "binary" log.

I suggest just downloading the compiled tarball instead:

wget https://codeberg.org/api/packages/MonadicSheep/generic/emacs-canvas/31.0.50/emacs-canvas-tarball-pack.tar.gz
tar xzf it.

then go and find emacs in ./gnu/store/ (btw, I suggest extracting into /tmp/), follow the other instructions as before.

@tusharhero @divyaranjan i extracted the tar into a tmp dir in my home (for space), found the emacs dir under /gnu/store/, cd into it, then call bin/emacs -q -L /path/to/pale-dir/. if i try to eval-buffer in pale.el, i get the same error: "Module could not be opened: /path/to/pale-module.so", "libEGL.so.1: cannot open shared object file: No such file or directory"....
@mousebot @tusharhero Create an issue on Codeberg let's track it there.
@mousebot @divyaranjan the Make file has still not been updated smh
@tusharhero @mousebot well we should always link the graphical libraries, but we never use them in the branch.