commit 3e88d3fe5168adef96bf95c722a7129ff7dbea0c parent f4ce24c1f53f4483ed4fa19e27e6710fbbbd9872 Author: Tomas Hlavaty <tom@logand.com> Date: Thu, 18 Jun 2020 23:05:54 +0200 added framebuffer-draw-test Diffstat:
M | emacs-framebuffer.el | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 42 insertions(+), 0 deletions(-)
diff --git a/emacs-framebuffer.el b/emacs-framebuffer.el @@ -50,6 +50,19 @@ (defvar framebuffer-size nil) +(defun framebuffer-virtual-size () + (with-temp-buffer + ;; TODO which framebuffer if more than one? + (insert-file-contents "/sys/class/graphics/fb0/virtual_size") + (search-forward-regexp "\\([0-9]+\\),\\([0-9]+\\)") + (cons (read (match-string 1)) (read (match-string 2))))) + +(defun framebuffer-bits-per-pixel () + (with-temp-buffer + ;; TODO which framebuffer if more than one? + (insert-file-contents "/sys/class/graphics/fb0/bits_per_pixel") + (read (current-buffer)))) + (defun framebuffer-size () (if (and framebuffer-width framebuffer-height) (cons framebuffer-width framebuffer-height) @@ -304,4 +317,33 @@ (define-key dired-mode-map "N" 'framebuffer-image-file-dired-next) (define-key dired-mode-map "P" 'framebuffer-image-file-dired-previous))) +(defun framebuffer-draw-test () + (interactive) + (destructuring-bind (fbw &rest fbh) (framebuffer-size) + (destructuring-bind (vw &rest vh) (framebuffer-virtual-size) + (destructuring-bind (x1 y1 x2 y2) (window-edges (get-buffer-window) t) + (let* ((fw (frame-width)) + (fh (frame-height)) + (cw (floor fbw fw)) + (ch (floor fbh fh)) + (wx (* x1 cw)) + (wy (* y1 ch)) + (ww (* (- x2 x1) cw)) + (wh (* (- y2 y1) ch))) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally "/dev/fb0") + (ecase (framebuffer-bits-per-pixel) + (32 + (dotimes (y wh) + (goto-char (+ (point-min) (* 4 vw (+ y wy)) (* 4 wx))) + (dotimes (x ww) + (delete-char 4) + (insert (mod x 256)) + (insert (mod y 256)) + (insert (random 256)) + (insert 0))))) + (let ((coding-system-for-write 'raw-text-unix)) + (write-region (point-min) (point-max) "/dev/fb0")))))))) + (provide 'framebuffer)