rendering graphics with node?

1,107 views
Skip to first unread message

Tom Carden

unread,
Mar 2, 2010, 2:36:24 PM3/2/10
to nodejs
I've been wondering about a server-side implementation of the canvas
API for node and wondered if anyone has experimented with something
similar yet?

I added a note on the GSOC ideas page: http://wiki.github.com/ry/node/google-summer-of-code-2010-ideas
and I'd be happy to mentor such a project from the point of view of a
consumer of graphics APIs. However I wouldn't be much use on the
implementation side of things.

I imagine that the canvas API itself could be iterated on in pure js,
and the main big task would be exposing bindings to a suitable low-
level library such as Cairo, Skia or AGG.

I also imagine that optimising and structuring such a framework for a
non-blocking event driven environment could be an interesting
challenge in its own way. There's only so much you can draw before the
next event comes along :)

Interested to hear your thoughts,

Tom.

Schell

unread,
Mar 2, 2010, 9:08:18 PM3/2/10
to nod...@googlegroups.com
What about opengl bindings? Or is that overkill?

--
Schell Scivally
sch...@efnx.com (efsub...@gmail.com)
http://blog.efnx.com

Ivan Boldyrev

unread,
Mar 2, 2010, 10:55:58 PM3/2/10
to nod...@googlegroups.com
On Wed, Mar 3, 2010 at 1:36 AM, Tom Carden <tom.c...@gmail.com> wrote:
> I also imagine that optimising and structuring such a framework for a
> non-blocking event driven environment could be an interesting
> challenge in its own way. There's only so much you can draw before the
> next event comes along :)

Then drawing should be performed on another thread, otherwise event
interface is useless, as drawing is usually memory- and CPU-bound, not
I/O-bound.

--
Ivan Boldyrev

Ryan Dahl

unread,
Mar 2, 2010, 11:02:42 PM3/2/10
to nod...@googlegroups.com

Yes - which makes it a rather difficult project.

Felix Geisendörfer

unread,
Mar 3, 2010, 5:29:29 AM3/3/10
to nodejs
I've been looking into this myself a little bit. Afaik there is no
existing infrastructure for non-blocking graphics one could build on.

So given the complexity of rolling a new graphics library from
scratch, I'd say something threaded will be the way to go for this.

-- fg

On Mar 3, 5:02 am, Ryan Dahl <coldredle...@gmail.com> wrote:
> On Tue, Mar 2, 2010 at 7:55 PM, Ivan Boldyrev <lisp...@gmail.com> wrote:

Blaine Cook

unread,
Mar 3, 2010, 9:55:06 AM3/3/10
to nodejs
Is it necessary for graphics to be non-blocking? Canvas in the browser
isn't non-blocking, nor are (correct me if I'm wrong!) ActionScript
graphics. I could be wrong, but my understanding is that most
Javascript-based graphics (and most long-running graphics in general)
draw on a timer, something like setTimeout(redrawScene(), 20), which
would handily yield control to node and prevent an infinitely blocking
case.

I know very little about graphics, but I like the idea of node.js
being a fast & scalable Javascript graphics engine, and thought it
might be worthwhile to emphasize that the solution might be much
simpler than running things in a thread.

b.

2010/3/3 Felix Geisendörfer <fe...@debuggable.com>:

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

Ryan Dahl

unread,
Mar 3, 2010, 9:57:44 AM3/3/10
to nod...@googlegroups.com
On Wed, Mar 3, 2010 at 6:55 AM, Blaine Cook <rom...@gmail.com> wrote:
> Is it necessary for graphics to be non-blocking? Canvas in the browser
> isn't non-blocking, nor are (correct me if I'm wrong!) ActionScript
> graphics. I could be wrong, but my understanding is that most
> Javascript-based graphics (and most long-running graphics in general)
> draw on a timer, something like setTimeout(redrawScene(), 20), which
> would handily yield control to node and prevent an infinitely blocking
> case.
>
> I know very little about graphics, but I like the idea of node.js
> being a fast & scalable Javascript graphics engine, and thought it
> might be worthwhile to emphasize that the solution might be much
> simpler than running things in a thread.

The concern is that the graphics I/O could slow down network I/O. It
would be nice to have them on different threads. A single thread
solution would work - it probably just wouldn't be optimal.

christkv

unread,
Mar 3, 2010, 11:59:15 AM3/3/10
to nodejs
Yeah it needs to be multithreaded which begs the question if Ryan will
accept some sort of threading support in node.js ?

Christian

Ryan Dahl

unread,
Mar 3, 2010, 12:07:54 PM3/3/10
to nod...@googlegroups.com
On Wed, Mar 3, 2010 at 8:59 AM, christkv <chri...@gmail.com> wrote:
> Yeah it needs to be multithreaded which begs the question if Ryan will
> accept some sort of threading support in node.js ?

What would that mean? There is threading support in the form of libeio
- but that is inappropriate for such a graphics thread.

Matthew Ranney

unread,
Mar 3, 2010, 12:17:29 PM3/3/10
to nod...@googlegroups.com
On Wed, Mar 3, 2010 at 6:57 AM, Ryan Dahl <coldre...@gmail.com> wrote:
The concern is that the graphics I/O could slow down network I/O. It
would be nice to have them on different threads. A single thread
solution would work - it probably just wouldn't be optimal

Is graphics really "I/O" though?  To me, graphics seems more like general computation, like a math library or something.

And yeah, it'd be really neat to have the canvas API available in node.

christkv

unread,
Mar 3, 2010, 12:20:34 PM3/3/10
to nodejs
I mean more in the style of

new Thread(function() { dosomething }) using system threads and not
processes. Posix Threads or something I guess.

Christian

On Mar 3, 6:17 pm, Matthew Ranney <m...@ranney.com> wrote:

Jim R. Wilson

unread,
Mar 3, 2010, 12:23:04 PM3/3/10
to nod...@googlegroups.com
Speaking of processes, would it be possible to perform graphics
operations in a separate forked process?

-- Jim R. Wilson (jimbojw)

Ryan Dahl

unread,
Mar 3, 2010, 12:28:16 PM3/3/10
to nod...@googlegroups.com
On Wed, Mar 3, 2010 at 9:20 AM, christkv <chri...@gmail.com> wrote:
> I mean more in the style of
>
> new Thread(function() { dosomething }) using system threads and not
> processes. Posix Threads or something I guess.

Javascript doesn't have threads and the entire point of this project
is to eliminate that sort of programming. So, no.

On Wed, Mar 3, 2010 at 9:23 AM, Jim R. Wilson <wilson...@gmail.com> wrote:
> Speaking of processes, would it be possible to perform graphics
> operations in a separate forked process?

Yes, that should be possible. We could just tell people to not put
graphics and networking in the same process - of course that means
they'll need to do a lot of IPC - but maybe that's okay. My thought
was that the library could do the IPC for the user (by communicating
commands to the internal graphics thread).

christkv

unread,
Mar 3, 2010, 12:34:01 PM3/3/10
to nodejs
To bad

Object.seal( obj )
Object.freeze( obj )

are not implemented or one could have Threading without the pain using
a erlang style approach to threading with immutable objects. Most of
the classic pain with threading is the shared state right.

Just my 5 cents.

Christian

On Mar 3, 6:28 pm, Ryan Dahl <coldredle...@gmail.com> wrote:


> On Wed, Mar 3, 2010 at 9:20 AM, christkv <chris...@gmail.com> wrote:
> > I mean more in the style of
>
> > new Thread(function() { dosomething }) using system threads and not
> > processes. Posix Threads or something I guess.
>
> Javascript doesn't have threads and the entire point of this project
> is to eliminate that sort of programming. So, no.
>

Blaine Cook

unread,
Mar 3, 2010, 12:59:52 PM3/3/10
to nod...@googlegroups.com
On 3 March 2010 06:57, Ryan Dahl <coldre...@gmail.com> wrote:
> The concern is that the graphics I/O could slow down network I/O. It
> would be nice to have them on different threads. A single thread
> solution would work - it probably just wouldn't be optimal.

Ahh, okay - I was imagining that the sort of graphics work that might
target node.js would be file- or network-bound image generation. More
OpenStreetMap tile generation or "graphs and charts" than desktop /
gaming 30 fps no-more-no-less graphics; places where web workers or
just multiple processes would be more than adequate if processing
capacity were a problem.

b.

Karl Guertin

unread,
Mar 3, 2010, 1:16:01 PM3/3/10
to nod...@googlegroups.com
Don't know if people missed this since it wasn't announced on the
list, but there's a set of GD bindings for people who want something
now:

http://github.com/taggon/node-gd

Haven't tested it, just noticed it when it showed up on the modules page.

Tom Carden

unread,
Mar 3, 2010, 9:41:08 PM3/3/10
to nodejs
On Mar 3, 9:59 am, Blaine Cook <rom...@gmail.com> wrote:

Rasterisation might be the only asynchronous work needed (done in
native threaded code) . This is analagous to how a browser does canvas
or svg rendering off in its own thread, away from javascript. Or how
Flash rendering works, where once you've chewed through a bunch of
drawing calls in actionscript, the Flash Player does its best to
rasterise those and blit them to screen in the remaining frame time
(usually a few 10s of milliseconds). So a scene description would be
built in js and everything else would be handled elsewhere.

Mentioning OpenStreetMap and graphs and charts it's almost like you
know what I want to do already ;)

Tom.

Tim Caswell

unread,
Mar 3, 2010, 10:10:23 PM3/3/10
to nod...@googlegroups.com
If you have rsvg on the command line, then you can just pipe is some svg text and read the output using a child process.

Reply all
Reply to author
Forward
0 new messages