Repository navigation
Description
I've heard a lot of interest in using Servo as the UI toolkit for native apps in Rust. This basically turns the notion of an embeddable browser inside-out.
Imagine a 3D modelling program. The program's window is simply a chrome-less instance of Servo. The UI is designed in HTML + CSS and its behavior is specified in JS. The computational and graphical heavy lifting is done by C++ or Rust code that draws to a <canvas> element using native OpenGL calls. Like every other part of the UI, it can be styled and transformed by developers with no knowledge of OpenGL or C++/Rust.
This has some advantages over Emscripten + WebGL:
- True native-code performance where it matters
- Real native threads of any form you like. You can even use realtime scheduler modes which (afaik) would be very hard to do in Emscripten.
- Access to hardware and native APIs that don't have equivalents on the Web. Mozilla generally believes in closing this gap instead, but it's a never-ending task and there's some stuff that won't ever be in the Web platform. (I'm thinking of my laser cutter that was controlled from Linux-CNC by bit-banging stepper motor waveforms out the parallel port.)
- Lower memory footprint, using a stripped down copy of the Servo engine rather than a browser with full web compatibility
- Access to whatever OpenGL calls are supported by your drivers, instead of the subset provided by WebGL
Some apps can take advantage of these features but will also work in Emscripten + WebGL with reduced performance and functionality. In those cases, you can have a single codebase that builds as either a native app or an ordinary web page.
Once we have basic support for WebGL <canvas>, I think we could implement this variant with relative ease. We'll probably want to use the texture-sending machinery so that embedders can use their own OpenGL context.
Activity
[-]Allow embeders to draw custom elements[/-][+]Allow embedders to draw custom elements[/+]brendanzab commentedon Oct 11, 2014
In #3579 and IRC @mbrubeck mentioned that he was working on turning the windowing library dependency 'inside out' - ie. Servo could be used with any OpenGL context. Could that work help with this?
pcwalton commentedon Oct 11, 2014
I'm a little worried about essentially recreating NPAPI.
pcwalton commentedon Oct 11, 2014
That said if it's not exposed to content it seems less bad.
kmcallister commentedon Oct 11, 2014
What do you think are the main lessons learned from NPAPI?
pcwalton commentedon Oct 11, 2014
Someone who's actually worked with it would have to chime in, but I think the biggest issues were:
Of course there may well be ways to mitigate these issues, I'm just saying what I understand the problems with NPAPI to be.
mcpherrinm commentedon Oct 11, 2014
Exposing native code to the web is surely a bad idea. I didn't think that's what kmc was proposing (or at least that's not where I see value).
I loathe making simple UIs to wrap around the OpenGL hacks I've written, and usually end up making something crummy in OpenGL. I'd much rather write native code, whether Rust or C++, with the native OpenGL features available, and all the host APIs that aren't suitable for exposing to JS.
Ms2ger commentedon Oct 11, 2014
I'm somewhat skeptical about putting our limited resources in non-web stuff at this point.
EdorianDark commentedon Oct 11, 2014
It would be for most applications enough to call Javascript functions and to expose functions which would be callable by Javascript.
kmcallister commentedon Oct 11, 2014
Well, it's a bad idea that people keep attempting in various forms ;)
But yeah, the conservative version of this isn't really "the web" at all. The embedded copy of Servo wouldn't support HTTP or even
file://URLs; it gets all its resources directly from the embedding app.Of course that does negate some of the value of using Web tech as your UI toolkit, and in practice I think a lot of people would want to hook up HTTP content, which will be a can of worms.
Fair enough. I mostly opened this ticket in hopes of drawing new contributors from the game dev community or such :)
wickerwaka commentedon Oct 11, 2014
Coherent UI (http://coherent-labs.com/overview/) is an existing example of HTML and related technologies being used for game UIs. For games, and maybe other applications, developers want a lot of control over the final presentation and wrapping the your view up inside a and rendering that would be limiting. I believe the approach Coherent takes is allowing you to create and draw multiple UI frames wherever you want into your current rendering context. This allows you to draw your 3d scene (maybe with UI within that scene itself), apply post processing, draw your UI(s) on top of that, then maybe additional post processing on that combined view.
jmacdonald commentedon Mar 17, 2015
I think this is a great idea. The main difference (in my mind) between this and NPAPI is that the point is not to extend the browser's functionality, but to use the browser's rendering engine to build a UI using HTML, CSS and JS. It effectively replaces Qt and GTK+ as a UI layer for Rust. There are already projects aimed at desktop application development using a web stack:
The main drawback to these is that they use JavaScript exclusively for all of the application code. While still very useful for handling events, it would be brilliant to be able to run computationally expensive tasks in Rust. You could build a cross-platform photo management application capable of non-destructive edits and filters. A text editor could be built to do all of its lexical analysis and data management in Rust, leaving JS to handle user events and HTML/CSS to present the UI. To that effect, the author of Sublime Text wrote a brief statement about how he builds for various platforms; it would seem like an ideal candidate for a project like this.
I don't picture this being a part of Servo itself. It would be more about shaping its API so that such a thing would be possible, and having a separate framework project that provides the configuration to bootstrap an application with the necessary components. Something where the Rust and JavaScript interface API is clearly defined and the rendering engine has the necessary hooks to load an initial HTML file with associated (local) CSS and JS files. The aforementioned application development frameworks have done all of this (albeit with Chromium), but have chosen to extend JavaScript with NodeJS, rather than with another language. Having Rust as the extension to JavaScript would be, in my opinion, far more powerful.
miketang84 commentedon Jan 11, 2016
compared to QT environment.
Rust <--> C++
Html <--> XML
Js <--> QML
Servo <--> Qt
all are wonderful. I think we should build a native system do not contain javascript, and consider html as optional.
https://github.com/daogangtang/panda-rs
bugmenot2 commentedon Feb 26, 2017
Are we going to be able to hook into DOM without JS any time soon? Is anyone looking into this? Thanks
jdm commentedon Feb 26, 2017
Nobody is looking into that. It poses big challenges and would require a lot of work that would not benefit Servo's primary use case at all.
bugmenot2 commentedon Feb 27, 2017
@jdm I reckon JS already maps to native methods, so why would it be hard to expose the same interface natively? Surely shipping my own browser with my app should be able to free me from the tyranny of JS
BrenBarn commentedon Apr 18, 2017
Strongly agree with bugmenot2. The inability to separate the HTML/CSS rendering engine from the JS engine is to me the critical limitation of the "web platform". This is also in line with modularity, which is one of the explicit goals stated right on the front page of servo.org . The rendering engine and the JS engine are two very different and very separate things, and are a natural thing to modularize.
nox commentedon Sep 30, 2017
The whole DOM is owned by the JavaScript GC. The JavaScript engine is at the very core of Servo.
BrenBarn commentedon Sep 30, 2017
Yes. That is the problem. Why is the core not just a DOM rendering engine, with the language for manipulating it as a fully pluggable component? What is modular about Servo?
nox commentedon Sep 30, 2017
BrenBarn commentedon Oct 15, 2017
I see. So instead we just recreate the status quo, which is that it's impossible to render HTML in anything that is not a browser.
I had hoped that Servo's goal of modularity would finally open the door to having usable HTML rendering in things that are not browsers, but I guess my hopes are dashed.
nox commentedon Oct 15, 2017
As mentioned by @jdm, this is simply not a priority. Let's not make it sound like it would be an easy task to make Servo's core "just a DOM rendering engine", to reuse your own words. Things are tightly tied together by sheer necessity, nothing else.
SimonSapin commentedon Oct 15, 2017
PrinceXML is not a browser. It’s a batch processing thing (as in: non-interactive) that transforms HTML/CSS documents into PDF. And yet, even they ended up adding JavaScript support because enough of their customers needed it.
The time of JavaScript being an optional part of the web platform is well past.