From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Anand Tamariya Newsgroups: gmane.emacs.devel Subject: Re: SVG hack for display engine Date: Thu, 18 Nov 2021 05:17:47 +0530 Message-ID: References: <83zgq41cra.fsf@gnu.org> <83k0h818zw.fsf@gnu.org> <83mtm2zyf6.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000fb0d3c05d104ab76" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1441"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Alexander Adolf , Emacs Devel To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 18 00:48:39 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mnUfO-000AdW-T2 for ged-emacs-devel@m.gmane-mx.org; Thu, 18 Nov 2021 00:48:39 +0100 Original-Received: from localhost ([::1]:40708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnUfM-0003nL-VP for ged-emacs-devel@m.gmane-mx.org; Wed, 17 Nov 2021 18:48:36 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnUeo-00037S-K7 for emacs-devel@gnu.org; Wed, 17 Nov 2021 18:48:02 -0500 Original-Received: from [2607:f8b0:4864:20::135] (port=34621 helo=mail-il1-x135.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mnUem-0003nq-OF; Wed, 17 Nov 2021 18:48:02 -0500 Original-Received: by mail-il1-x135.google.com with SMTP id j28so4605409ila.1; Wed, 17 Nov 2021 15:48:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6Dm9rkcdjMChggtB7f0wOZRM9LNMPSqcY6JHqfBB4N8=; b=pnvnQ1OUjTXKf7KLTO2269y4fRkIFtpH0/5kbuQNgQKB/PplQtYO/8a6SZZJjeWNVD ri323L759rO2az0uZzxQHwPlUB8Jsv2/LWHEp1P+xE4bFeUAh8wKKg673DxEdsHaNIjs 6BbjGx6j3taPMvTCZChok2xIbpuFzqUpcQZZTcP+B+D++bioyjuak07KfoCds1JPn36N wEQJ/n/S59VMfE+LCSuj8NbUj7WrOHlX7U/Krv7NZd9RREEoiWwNdt5NNmtsYjVacSsa xayoHnu63v06QvP98Ixce04px9xxgKZQsbpCcya2OwP8v2ZEPH9u3tdEwaxKvArUQmL3 ceQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6Dm9rkcdjMChggtB7f0wOZRM9LNMPSqcY6JHqfBB4N8=; b=FhmSman+q7A/EtpGK6Wj5NaWmTlygwJscFTgpfTKvNIZfciWkaYuEcTJL5lMF12QjJ piToJeILhUvbTFrgZs+qci0EGGFa8V/kIGRQziUn1uChnKpsuyfPKMNtwPHueWtScOUA YcMa4wLn8bkjKwcbDnn2qWPQf+6TbDImgV1PllIW7E2DnDvb5XNSw7TyzHIX2w+AcDzM v0MOPmiAI9nPL62wuyjBT6dzlnHtsjvMkDYKqtkUj09+bYsfPu5VmviAqAFAMC+zGCuG o7xyxH1jxMcw/IJIZSl04Mzv8uW9aFxfc1+L2y5qCJjLn21T4oxs9pUM3ea44cmJ7U0h XbzQ== X-Gm-Message-State: AOAM533N/I2TtZv7sdw/r/Ts/qnw99OfEo3LehSX8YMTd8L5WkAjiCE5 Ve2e2SA49mUMb0d/+dZPkTJzp1XAh0mDsE1gU2s19FZPc47Q9ZSr X-Google-Smtp-Source: ABdhPJzXoLo5uy/maNQULOVusNhsTGZK0/UKPAKvoJT6jYZ6eD1JU9dpWaGpOHM3iDpLMN8jiAtBJtDOIfjIH+OaaV0= X-Received: by 2002:a05:6e02:1a2c:: with SMTP id g12mr13048408ile.62.1637192878983; Wed, 17 Nov 2021 15:47:58 -0800 (PST) In-Reply-To: <83mtm2zyf6.fsf@gnu.org> X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::135 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::135; envelope-from=atamariya@gmail.com; helo=mail-il1-x135.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:279645 Archived-At: --000000000000fb0d3c05d104ab76 Content-Type: text/plain; charset="UTF-8" > Please describe the intended use of these APIs and the hook to provide > the display feature(s) you have in mind, and how will that work in > concert with the display engine. I don't think I have a clear picture > of that yet. > > Also, please describe what happens with use of these APIs when just a > small part of the Emacs display needs to be redrawn. > > Maybe a demo ( https://youtu.be/1343m3LY4mo ) will help you visualize my suggestion. In the video, an event loop is started in the scratch buffer. All the edit operations update text and text property in a temporary buffer, say a.txt. Based on this information, in-memory SVG DOM is updated. Ultimately, the display engine updates the view with this SVG image. In cases like this, the mode can have full control over the display if so desired. Since you have a problem accessing my repo, I've added the code of a function I call in my event loop at the end of this mail. With a tighter integration, Emacs would define a new data structure {svg, x, y, w, h} and two new variables with this type - new_svg and prev_svg. Then the sequence of operations would be: - Display engine refreshes the view bitmap with current logic - full or partial refresh as the case may be. - If it's a graphical display - prev_svg = new_svg - Run display-svg-hook. The registered user function will call (svg-render) function passing required information. This API sets the value in new_svg. - If the bounding box of new_svg < the bounding box of prev_svg, display engine refreshes the area of prev_svg in the view bitmap. - Generate a bitmap for new_svg and superimpose it on the view bitmap. - Display the view bitmap to the user. Hope this helps. (defun formula-canvas-mode (key svg) (let* ((func (lookup-key global-map (vector key))) (i 0) (size 20) mkey win text x y id point pos start end opts) ;; (message "Before: %s %s" key func) (unless func (setq mkey (lookup-key local-function-key-map (vector key)) func (lookup-key global-map mkey))) ;; (message "After: %s %s" key func) (with-current-buffer (get-buffer-create "a.txt") (when func (condition-case var (if (eq func 'self-insert-command) (funcall func 1 key) (funcall func 1)) (error (message (format "Error: %s" (car var))))) (save-excursion (setq win (get-buffer-window)) (goto-char (window-start win)) ;; Need to keep popup at the end ;; (setq svg (subseq svg 0 2)) (dom-remove-node svg (car (dom-by-id svg "_popup"))) (while (< (point) (window-end win)) (setq start (point) end (progn (end-of-line) (point)) text (buffer-substring start end) id (number-to-string i) x 0 y (* (1+ i) size)) (setq i (1+ i)) (forward-line) ;; Text (svg-text svg text :id id :x x :y y :xml:space "preserve"))) ;; Cursor (setq pos (posn-col-row (posn-at-point (point) win)) point (* 4 (car pos)) y (* size (cdr pos))) (svg-rectangle svg point y 5 size :id "_cursor" :fill "black" :opacity "0.4") ;; Popup (setq opts '("a" "b" "c" )) (if opts (formula-canvas-popup svg point (+ y size) opts)) (svg-possibly-update-image svg) ) ))) --000000000000fb0d3c05d104ab76 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Please describe the intended use of these APIs and the hook to provide
the display feature(s) you have in mind, and how will that work in
concert with the display engine.=C2=A0 I don't think I have a clear pic= ture
of that yet.

Also, please describe what happens with use of these APIs when just a
small part of the Emacs display needs to be redrawn.

Maybe a demo ( https://youtu.be= /1343m3LY4mo ) will help you visualize my suggestion. In the video, an = event loop is started in the scratch buffer. All the edit operations update= text and text property in a temporary buffer, say a.txt. Based on this inf= ormation, in-memory SVG DOM is updated. Ultimately, the display engine upda= tes the view with this SVG image. In cases like this, the mode can have ful= l control over the display if so desired.

Sinc= e you have a problem accessing my repo, I've added the code of a functi= on I call in my event loop at the end of this mail.

With a tighter integration, Emacs would define a new data structure {= svg, x, y, w, h} and two new variables with this type - new_svg and prev_sv= g. Then the sequence of operations would be:
- Display engine ref= reshes the view bitmap with current logic - full or partial refresh as the = case may be.
- If it's a graphical display
- prev_svg =3D new_svg
- Run display-svg-hook. The registered user function will call (svg= -render) function passing required information. This API sets the value in = new_svg.
- If the bounding box of new_= svg < the bounding box of prev_svg, display engine refreshes the area of= prev_svg in the view bitmap.
- Ge= nerate a bitmap for new_svg and superimpose it on the view bitmap.
- D= isplay the view bitmap to the user.

Hope this helps.

(defun formula-canvas-mode (key sv= g)
=C2=A0 (let* ((func (lookup-key global-map (vector key)))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(i 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(size= 20)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mkey win
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0text x y id point pos start end opts)
=C2=A0 =C2=A0 ;; (mes= sage "Before: %s %s" key func)
=C2=A0 =C2=A0 (unless func
= =C2=A0 =C2=A0 =C2=A0 (setq mkey (lookup-key local-function-key-map (vector = key))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 func (lookup-key global-= map mkey)))
=C2=A0 =C2=A0 ;; (message "After: %s %s" key func)=

=C2=A0 =C2=A0 (with-current-buffer (get-buffer-create "a.txt&q= uot;)
=C2=A0 =C2=A0 =C2=A0 (when func
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (co= ndition-case var
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (eq func = 'self-insert-command)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (funcall func 1 key)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (funcall func 1))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (error (= message (format "Error: %s" (car var)))))

=C2=A0 =C2=A0 = =C2=A0 =C2=A0 (save-excursion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq w= in (get-buffer-window))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char (w= indow-start win))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Need to keep pop= up at the end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; (setq svg (subseq sv= g 0 2))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (dom-remove-node svg (car (do= m-by-id svg "_popup")))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (wh= ile (< (point) (window-end win))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (setq start (point)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 end (progn (end-of-line) (point))
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 text (buffer-substring start end= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 id (num= ber-to-string i)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 x 0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 y (* (1+ i) size))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq i= (1+ i))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (forward-line)
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Text
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (svg-text svg text :id id :x x :y y :xml:space "pres= erve")))

=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Cursor
=C2=A0 =C2=A0= =C2=A0 =C2=A0 (setq pos (posn-col-row (posn-at-point (point) win))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 point (* 4 (car pos))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 y (* size (cdr pos)))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 (svg-rectangle svg point y 5 size
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0:id &= quot;_cursor" :fill "black" :opacity "0.4")
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 ;; Popup
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq opts= '("a" "b" "c" ))
=C2=A0 =C2=A0 =C2=A0= =C2=A0 (if opts
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (formula-canv= as-popup svg point (+ y size) opts))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (svg-po= ssibly-update-image svg)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0 = =C2=A0 )))
=
--000000000000fb0d3c05d104ab76--