-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render using canvas #938
Render using canvas #938
Conversation
const isAscii = code < 256; | ||
const isBasicColor = (colorIndex > 1 && fg < 16); | ||
const isDefaultColor = fg >= 256; | ||
if (isAscii && (isBasicColor || isDefaultColor)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This problem might actually be related to the 15px font size in the demo. Using 14px or any of the font sizes that are supported in Terminal.app
gives good looking results. I am wondering if that's the reason why Terminal.app
restricts the font-sizes to 9,10,11,12,13,14,18,24,... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should include this in this PR but one was we could fix this is by have 2 render layers/canvases for the foreground, one for odd rows, one for even. That would allow characters like _
to overlap cells while still being able to clear them without interfering with other cells.
I didn't think powerline used ligatures? powerline/fonts#42 Do you have a screenshot of the problem? |
@Tyriar Just double-checked, I thought some of the glyphs that are used by powerline are coming from the ligatures, but I was wrong, sorry 😓 |
0e5b62d
to
75b91c6
Compare
🎉 |
@@ -63,6 +64,7 @@ export class CompositionHelper { | |||
* @param {CompositionEvent} ev The event. | |||
*/ | |||
public compositionupdate(ev: CompositionEvent): void { | |||
console.log('compositionupdate'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a logger here I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch 😅 #983
I'm curious, does this renderer supports copy/pasting? |
Hi @arcanis. |
@arcanis copy and paste was barely touched at all, only the drawing of the selection and the events that copy/paste listened to were tweaked. |
this._ctx.scale(window.devicePixelRatio, window.devicePixelRatio); | ||
return result; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi. I am curious about why we chose createImageBitmap
over passing canvas out directly. I thought ImageBitmap
is for worker thread or image decoding on background thread. Does this gain any performance improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment that explains this:
// ImageBitmap's draw about twice as fast as from a canvas
This is when I initially measured it. I also found that ImageBitmap
was cripplingly slow on Firefox and wasn't supported on Safari, these fall back to drawing from HTMLCanvas
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.ImageBitmap
is for fast accessing and drawing. Thanks for the reply!
Will selection and copy/paste still work on iOS? |
@tbodt probably not, I'm thinking we should probably bring back the old renderer anyway for environment edge cases. Some computers take much longer to render using canvas which I think it something to do with GPU rendering being disabled or something. |
@parisk @mofux I don't expect the code to change much now, it's mainly just tests, documentation and any bugs that pop up at this point. Please review, I know it's big but most of the changes are in new files inside
src/renderer
😄Resolves #935
Fixes #936
Fixes #681
Fixes #730
Fixes #720
Fixes #475
Fixes #937
Fixes #920
Fixes #919
New Stuff!
Ascii characters with their foreground, 8 color and 8 bright/bold colors are pre-rendered and stored in an
ImageBitmap
. This is used as a texture atlas to draw to canvas really fast.Multiple canvases are used to layer different things onto the terminal, this method is fast and allows for a nice separation of logic.
Render layers keep track of what they have drawn (when it makes sense) and as such will diff the new contents and only draw when necessary. This turns single character changes in lines to typically take < 0.25ms, down from ~6ms.
Better support for line height, font size and font family. As they're all managed within
Terminal
now, justsetOption
and run thefit
addon if necessary.There is now a very clean separation from the model and everything rendering, pretty mcuh everything that renders is within
./src/renderer
(viewport being the only exception, which needs a background color set). We should move towards doing similar with the model and the DOM in Terminal to simplify and make testing easier.Link handlers are getting reworked quite a bit as previously the
validationCallback
exposes theHTMLElement
of the link to allow tooltips to be attached. There is now ahoverCallback
which achieves a similar goal.This fixes a bunch of bugs (see the link of "Fixes #x" above), a notable bug fixes is line characters being misaligned in
vtop
vtop features misaligned lines #937.API Changes
See complete list of changes in the xterm.d.ts diff.
Limitations & regressions
Deferred
Benchmarks
This table contains the average time it takes to render when running various actions or programs.
2.9.2
canvas_render
vtop
idlels -lR large_folder
yes
* Rendering took multiple frames
Setup
In pictures
Here's one of my favorites; comparing
vtop
's performance 🔥.Before
After
TODO List
Terminal.setOption
ITheme
TODO
's in codeImageBitmap
so falls back toHTMLCanvas
ImageBitmap
, explicit fallback toHTMLCanvas
IE11/Windows- 💣