Fixing IE by porting Canvas to Flash
This is a guest blog from Grant Jones.
In the Algorithm Ink blog post, I mentioned that I’d be interested to see if a Flash implementation of ContextFree.js would be faster than the pure Javascript, and if so, how much faster. Would an implementation of the Canvas API done in Flash make a better solution for Canvas in IE than Google’s excanvas? Within days, Grant had jumped in, wrote some slick code, and answered those questions!
My hat is off to Grant for the awesome work he’s done, as well as for writing this post.
Intro to Internet Explorer Canvas-Emulation
Before we go into the current state of Internet Explorer canvas-emulation, here’s a brief look back at the history – or the history as far as I could tell from blog posts:
- Manish Jethani mentions something about the canvas tag being used for a 3D game, John Dowdell from adobe responds in Nov. 2005
- Manish Jethani suggests a way to do a SWF-based Canvas on Dec 1st, 2005
- iecanvas from Emil A Eklund released December, 2005 (uses VML)
- excanvas from Google released March, 2006 (uses VML)
- AFLAX (uses ExternalInterface) adds canvas emulation in March 2006
Overall, interest in this area seems to die off after that. Only recently with things like Processing.js and ContextFree.js has there been a renewed interested in backwards compatibility for the canvas tag.
What is FlashCanvas?
FlashCanvas is a canvas tag to flash bridge for browsers which do not support the canvas tag like Internet Explorer. FlashCanvas is an experiment to see if any performance improvement could be realized by using flash technology. The javascript code is a fork of the ExplorerCanvas project:
Firefox, Safari and Opera 9 support the canvas tag to allow 2D command-based drawing. ExplorerCanvas brings the same functionality to Internet Explorer. To use, web developers only need to include a single script tag in their existing web pages.
Back in July I was using the canvas element to create simple ‘platformer’ style games. The original idea was to create one basic game every Monday, Wednesday, and Friday. The first few were Flash-based but the rest were done in javascript and HTML. The problem is that Internet Explorer still has a major percentage of the market share and couldn’t play my games. I tried excanvas from Google, found it was too slow, and in the grand tradition of rolling-my-own created FlashCanvas.
How does FlashCanvas work?
FlashCanvas is modeled after ExplorerCanvas which means it is a turn-key solution for adding Canvas support to IE. You can code away, happily using open standards and then use FlashCanvas to forcefully and silently upgrade IE to also being standards compliant.
There are two main components in FlashCanvas: the base FlashCanvas.swf flash file (a mere 688 bytes), and the FlashCanvas.js wrapper. I’ve used the excellent swfobject.js to embed the Flash into the page.
The FlashCanvas.js file implements a fake-canvas object and converts all existing canvas element into a flash object. The javascript intercepts canvas commands and forwards them to the FlashCanvas.swf movie file using the ExternalInterface provided by the flash player. The flash movie clip then interprets the command and draws accordingly.
Download FlashCanvas
Download it here: FlashCanvas 0.2.
Version 0.2 includes a batched mode. Look for the “example1_stress.htm” inside of the examples folder for a demo of it in use. It’s Released under the same Apache License as the explorer canvas project.
FlashCanvas is a one-day project, meaning that this release only implements lines and fills, which is only enought to support the first two examples from ExplorerCanvas.
Unfortunately, there exists a flash player bug which does not allow local connections to communication with actionscript from javascript using ExternalInterface even if permission is granted. A python script for running a SimpleHTTPServer instance is provided for testing purposes.
Does FlashCanvas provide better performance?
The short version: not really.
The longer version: All drawing commands are being forwarded from Javascript -> ExternalInterface (down into the browser) -> ActionScript -> Flash Drawing commands. This is a lot of overhead for drawing code. Doing something simple like a moveTo and lineTo would result in at a very minimum 8 separate levels of indirection.
Performance
FlashCanvas did not yield as much of a speed increase as I was expected. The question is, where is the slowdown occuring.
Flash performance is not the limiting factor as it is roughly the same across all platforms, and is quiet speedy with graphics. The speed of javascript execution is also not the limiting factor. Although, from the limited testing I did it is clear that javascript executes slower on Internet Explorer than in either Firefox or Safari — it is not enough to explain the difference in render times.
The slowdown is occurring somewhere between the javascript call and the actual rendering to the Flash MovieClip. To investiage further, I wrote a dummy ping-pong page/flash file which simply calls a “ping” method from javascript into actionscript to test timing.
The results revealed where the problem was:

JS2AS = JavaScript calling ActionScript; JS2AS2JS = Javascript calling ActionScript and ActionScript calling Javascript; OS X and Windows machines were physically different
Each call via the ExternalInterface is taking approximately 0.5 ms. Since we know the time it takes to call an actionscript method from javascript, we can deduce the amount of time it takes for Flash to render. For the example1.htm page it takes ~24 ms to render 20 anti-aliased lines. In Safari a call into actionscript takes roughly 0.4 ms — this is only the call time, it doesn’t include the time to render anything. For example1.htm a single “particle” calls actionscript 3 times with the commands: [lineStyle,moveTo,lineTo]; each particle takes 1.2 ms in JS-to-AS calls; to take 1 second to render the frame ~833 particles need to be rendered. Changing the example code to render that many particles resulted in:

(where time is in milliseconds)
The conclusion is: the time it taken for the javascript canvas wrapper, the javascript particle simulation and the actionscript code/line rendering is insignificant.
For comparison this is safari doing the same exact thing using it’s native canvas element:

(where time is in milliseconds)
The next logical step is to batching draw commands into an array to be passed only once into the flash renderer. Immediately this raises an issue about how the canvas API has been typically used: there is no explicit end of rendering or flush equivalent so the canvas-wrapper would never really know when drawing is finished. The most fine-grained control would be at the individual path level, which would result in nearly the same performance for something like the example1.htm file. Most graphics API have some sort of buffer flush either explicitly, like glFlush in opengl, or implicitly during a buffer swap.
Still, it was worth testing to see if this could solve the performance issues. A flush was added to the canvas-wrapper but batching commands into an array does not eliminate the performance problem in ExternalInterface. FlashCanvas was changed to batch commands and then send them to flash with only one call via ExternalInterface. The result is only slightly faster (800 ms instead of 1 sec and a really slow 20 secs /frame in Internet Explorer 7). Since that part of flash is all closed this was basically as far as I could go — my guess is that some sort of serialization/translation is taking all the time.
What other approaches could be taken?
Here is where we look to the recent news that Mozilla’s Vladimir Vukićević has a working prototype Active-X plug-in which emulates the canvas element. This is ultimately the best bet as far as performance is concerned. There may still be potential performance issues due to the fact that all the javascript code is still being interpreted by Internet Explorer which seems to have some undesirable characteristics especially in memory management.
RT @aza Fixing IE by porting Canvas to Flash | Follow @aza on Twitter | All blog posts
Benjamin Otte
A large part of that problem is that – at least as far as I know – ExternalInterface does not only translate between the JS object system i the browser and the AS object system in Flash, but that it does so using XML. So a function call like “foo (1, 2)” is first translated to something looking like which then gets unmarshalled in the Flash player again.
I think with a bit of dirty tricking, you could bypass that (at least with Flash 8, not sure about Flash 9) by sending strings yourself, but I’m not sure if this is gonna buy you a lot. I certainly wouldn’t assume you’d gain a 40x speed increase.
nakliyat
haklısın ama program geniş kapsamlı
Todd Cullen
They should take a look at this library –> http://eval.hurlant.com/
With it you could recreated the canvas API in Actionscript and eval the appropriate canvas functions to execute natively as ABC bytecode using Tamarin. Essentially, creating a Canvas JS DSL for the Flash runtime with minimal loss in performance over native Flash development.
I’m using a modified version to generate dynamic powerpoint slides in Flash.
hunter
av ve hunter forum
Ray Cromwell
Nice post. I’ve been shipping something similar in production code since January, see http://timepedia.blogspot.com/2008/01/chronoscope-demo-in-flash-whatwg-canvas.html
I enhance the canvas API with begin/end frame, text drawing, display lists, and layers.
There are other issues you will run into, like emulating all the Porter-Duff blending modes in Flash, which are possible to do, but tricky.
nakliyat
zor ama zevkli ha bu arada yorumun harika .
Lee
[...] dem Artikel von ahtvigitinteracrite und den dazugehörigen Kommetaren werden die wichtigsten Tools [...]
bnfezqxsm
haZUU8 rctqgpwvesbt
Grant Jones
Benjamin: That would certainly explain the performance issues. I wonder why ExternalInterface would convert to XML internally though?
Ray: Thanks for linking to your post, I didn’t see that when I was researching the history. It’s interesting to see the same issues come up. I’d like to see the canvas api implement a flush or beginFrame/endFrame as well as display lists. Did you end up using ExternalInterface to interact with Flash?
AndreasR
Freeciv-Forever.com uses Canvas to render it’s graphics.
For IE support, I think it could really benefit from FlashCanvas.
http://freeciv-forever.com
ankara masaj
Ankara masaj salonları olarak aza raskine selamlar. Teşekkürler dostum.
ankara masaj
çalışmalarınız ve verdiğiniz bilgiler için teşekkürler.
Rick
Is possible create two canvas tag in the same page, using FlashCanvas?
Your work may be the unique way to use canvas for IE8. Congratulations
Scott Schiller
Brad Neuberg has a post (from early 2006) on speeding up externalInterface (though Flash 8): http://codinginparadise.org/weblog/2006/02/how-to-speed-up-flash-8s.html relating to XML serialization. It appears Flash 9 has improved on this, though there is still a delay between JS-Flash which varies between Mac and PC as you noted.
I had experimented with ‘caching’ the serialized calls to see if performance would improve with subsequent calls, but my tests didn’t show anything obvious. (I write and maintain SoundManager 2, which provides a JS sound API by wrapping and extending Flash’s audio features, so I’m interested in the performance aspect as well.)
at9t
It’s quite an interesting approach.
wilq32
That’s a nice work here ! Probably I try this for some CANVAS stuff I do in my snippets :) Just tell me what to do with events ? Will they work correctly in IE ?
Erik Arvidsson
I did some experiments using silverlight and the performance is really good. The silverlight implementation of ExCanvas was faster than Firefox in a lot of cases (I doubt that is still true today).
We have been discussing whether to use the silverlight implementation by default instead of the VML version if silverlight is available. Silverlight has some issueslike no event transparency but all those issues applies to flash as well.
Brad Neuberg
Not that it really matters, but I just wanted to add one more data point to your timeline. I blogged about the possibility of using VML on IE in order to emulate Canvas in August, 2005:
http://codinginparadise.org/weblog/2005/08/emulating-svg-and-safaris-canvas-on.html
Brad Neuberg
Cool article! Not sure if you saw this, but there are some more performance optimizations possible with Flash inside of IE that I posted on Ajaxian. Here it is again:
“[You can] use fscommand and setVariable/play/stop on IE for Flash communication. It is extremely fast, but a pain to program for. Another alternative is to hook deeper into the ExternalInterface architecture to avoid an eval() statement, which the ExternalInterface does on each call and which slows things down. More info on overriding ExternalInterface to get more control on an old blog post on my blog here: http://codinginparadise.org/weblog/2006/02/how-to-speed-up-flash-8s.html“
Aza Raskin
@Brad Very cool. I hadn’t realized that setVariable was that much faster!
naseAlaciency
nice, really nice!
av tüfekleri
av tüfekleri tamiri
Cyril
I couldn’t get any output from the demo in any browser.
All I get is a white rectangle over a black page.
I’m using FP10.
Chris
None of the examples work for me in any versions of IE…
Steveorevo
Aza, this is excellent! Via some other projects with svg emulation in flash, I’m hoping that processing.js latest support for TTF via SVG translation can finally become a reality for a canvas like object to do typography in IE. Is it possible with the current .2 version you have?
http://processingjs.org/source/ttf-pfonts/ttf-pfont-pjs.html
Aleksandr
I have an AS2.0 flash movie where cars bitmaps are being shown instead of each other by the method of increasing/decreasing Alpha. It has perfect perfomance in standalone flash player and in Firefox flash player…. But when I run it in Internet Explorer it is slowing down performance approximately 3 times. Please anyone, do you have an idea what is the possible problem? How to make it play in IE so fast like it’s being done in FF? Thanks!!!
Jarrad
Hi,
I know you could get a way faster implementation in flash.
If you wanted to make this even remotely comparable you’d create contextfree and run the code directly in flash, then instead of using straight graphics drawing calls, pump the generated data to vectors (or fast memory opcodes) and drawGraphicsData, you could also use bitmapdata and push the entire buffer to it.
Zayıflama Lida Fx15 Ve Biber Hapı Zlfvbh
I had experimented with ‘caching’ the serialized calls to see if performance would improve with subsequent calls, but my tests didn’t show anything obvious. (I write and maintain SoundManager 2, which provides a JS sound API by wrapping and extending Flash’s audio features, so I’m interested in the performance aspect as well.)
porno
A large part of that problem is that – at least as far as I know – ExternalInterface does not only translate between the JS object system i the browser and the AS object system in Flash, but that it does so using XML. So a function call like “foo (1, 2)” is first translated to something looking like which then gets unmarshalled in the Flash player again.
Sex
A large part of that problem is that – at least as far as I know – ExternalInterface does not only translate between the JS object system i the browser and the AS object system in Flash, but that it does so using XML. So a function call like “foo (1, 2)” is first translated to something looking like which then gets unmarshalled in the Flash player again.
gucci belts
It retains the mens belts new shape Stretch Jeans cheap gucci belts Slender cheap louis vuitton belts for men September cheap desiger belts gucci belts on sale Have you ever louis vuitton belts cheap thought it was a method as one million U.S. dollars without sacrificing comfort;
sikiş izle
Fixing IE by porting Canvas to Flash
evimtaşnakliyat
sugarda ne neka güzel neka güzel
basur
We have been discussing whether to use the silverlight implementation by default instead of the VML version if silverlight is available. Silverlight has some issueslike no event transparency but all those issues applies to flash as well.
ankara masaj salonları
hello azar….
porno
nice blog thanks
travesti
It looks really good. Going to check it out for my blog. Thanks a lot for sharing
شات كتابي
thnks
goooooooooooood
min:)
Carlo
The link to download FlashCanvas is dead…
Can you update it?
Carlo
I’ve found this alternative link: http://download.revulo.com/Flash/FlashCanvas-0.2b.tar.gz
Evden Eve Nakliyat Fiyatları
ne yapacağın belı olmas
Evden Eve Nakliyat istanbul
bazen yenlıkler daha güzel
Evden Eve
doğrusu nerden bilmek
sikiş
thanks for sharing i love this idea and i will check everytime your post:)) see ya again in new post
wholesale beads
thanks for sharing your knowledge
sikiş
thanks for sharing i love this idea and i will check everytime your post:))
see ya again in new post.wish you continued success
av tüfekleri
You clearly are not familiar with the most recent dollar fluctuations and current facetious exchange rate.
av tüfekleri
An expedition to a tiny island in the South Pacific’s Republic of Vanatu has yielded hundreds of new species, including possibly 1000 new species of crab.
av malzemeleri
Evolution is something that just happens. The animals that had traits better suited to survival in this environment lived long enough to pass on these traits to their offspring. In many instances, one of these traits it something that is referred to as ‘camouflage’.
kemik kesme
BTW, PatriotG, the planet will go on on and for many, many millenia. Possibly a few billion years. Well after man disappears from the face of the earth.
kemik testeresi
Fascinating pictures and creatures. Also fascinating how many are posting from the very narrow perspective of their own biases.
ankara masaj
hi azarsk.in. very good blog.
kıyma makinası
Oh, and for the idiot who thought the locals already knew about these creatures. I highly doubt they were aware of creatures found 150 meters under the water offshore.
Auth
(Paperback) I wish all cotpumer books were written this well! This is not only the best book (by far) on this subject, but it is also the most clear, comprehensive, and engaging programming book I’ve read on any subject! The author is expert at building concepts at just the right pace to make the subject easy to digest, but he never skips over explaining the why, as well as the how of each concept. Chap 6 on controlling the player and overhead multi-axis scrolling (think Gauntlet, or Zelda) is well worth the book’s price alone. Chap 7 “Bumping into things” gives three different methods for collision detection explaining the benefits and drawbacks of each. This is typical of the author’s approach of showing you different ways to accomplish what you wish, and suggesting which method to use in different circumstances, but leaving the use of each tool up to you. He even goes so far as to first demonstrate an inferior, but common way of controlling a player’s movement, so the correct method (which immediately follows) will make more sense, leading you to understand why the better method works so well. Chap 9 on platform game physics (think Mario) is superb, and like Chap 6 is worth the book’s price alone. Side scrolling platform games are at best glossed over in other books. The whole time I read this book I felt like the author was reading my mind, anticipating my questions, and giving me a little more depth where it was needed. When you finish this book, there will be little (if anything) you can’t do in 2D game programming in Flash. Lively, engaging, and actually fun to read, highly recommended!
köfte makinası
You know what I really hate? Capers! People put them in recipes to make them taste better but they just make the whole dish taste like capers. Seriously, enough with the capers!
kuşbaşı makinası
Wow, such hostility. It’s a real shame that you’d all rather fight about who found them first or why they are there than to just stop and appreciate the magnificent species many of us are seeing for the first time. When conserving nature becomes more important than nature itself, what’s the point? Look for the beauty in life, be thankful you can see it before its gone.
cambalkon
I hate capers too! And I hate anybody who’s willing to have anything to do with them. And while I’m at it, I suggest we take down the Bleiman brothers for providing a forum for their mention.
ankara masaj
okey . you are super comment
cambalkon
Anyhoo, Murray is trying to sell them in pairs so they always have a companion and claims that they are easy to house train. He just sold a couple to some British celebrity that we’ve never heard of at about $150 US (1.5 UK Pounds) a pop.
ankara masaj
yes I do. ofcourse . wait you.
cambalkon
I moved to New Mexico 6 years ago and it really is a bit like [quote: Bill Bennett] a “previously unknown new world,” at least to someone from Connecticut.
cambalkon
Truly, the exotic South Pacific. Wonderful site & blog.
cambalkon
This is a beautiful site. I am a retired biology teacher, and I always wanted to go on an adventure like this — find a new insect in South America, and name it after me! Now, at 70 years old, I appreciate the vicarious pleasure. Thanks for the site.
cambalkon
Oh, and one other thing. I’m no tree-hugger, indeed I’m fairly easily annoyed by some sorts of environmentalist. But even so, your use of “greentard” tells me pretty reliably that you have nothing to say worth listening to.
cambalkon
“Woe to you, blind guides! You say, ‘If anyone swears by the temple, it means nothing; but if anyone swears by the gold of the temple, he is bound by his oath.’” – Matthew 23:16
dergi
there really any call for you be on science blogs when you know that no one here will agree with you.
tadilat
Yeah, Dave H. How dare people read a blog post purely for enjoyment’s sake. The nerve…
dekorasyon
Shandooga – you’re such a troll. With the utter miscomprehension of biology and evolutionary theory you’ve displayed over the years, is there really any call for you be on science blogs when you know that no one here will agree with you or appreciate your misguided ID/creationist arguments?
çankırı
That is sooo beautiful. I wish I became a scientist, discovering new species must be the greatest experience ever.
otomatik av tüfekleri
How long until Paris Hilton has one of her own? Tiny pigs…that’s hot.
sikiş
thanks for sharing i love this idea and i will check everytime your post:))
see ya again in new post.wish you continued success
beylikdüzünde günlük kiralık daireler
This has made my day. I wish all psontgis were this good…
Tercüme
thanks for this a post.
ankara.net
teşekürşer paylaşım için
cam balkon fiyatları
thanks for this a post.
cam balkon ankara
seuo
rent a car ankara
anks for this a post.
araç takip
One of the easiest ways for a man to define his style is Cheap Moncler Coats by choosing a high quality piece of outerwear. Especially if the climate in your location is cold, Moncler Vests your Moncler Jackets is the first thing people will see when they meet you for the first time, and you want to make a good impression. Moncler Sweater one of the impressive pieces from Monclers latest collection, Moncler Shoes for Women people will instantly know you are a man of style and respect.
ukrayna vizesi
iyi
arkadaş
teşekürler bilgi için elinize sağlık
pellet mill manufacturer
evolutionary theory you’ve displayed over the years, is there really any call for you be on science blogs when you know that no one here will agree with you or appreciate your misguided ID/creationist arguments?
custom homes scottsdale
You have some really good information in this article. I have really enjoyed your views on this subject. You are a gifted writer. Thank you
teras camlama
Cam Balkon & Kış Bahçesi Sistemleri,Cazip Fiyat, Uygun Ödeme Koşulları % 100 Müşteri Memnuniyeti,0216 306 98 56.
nakliyat
so nice thanks
Wilmer Favilla
There are definitely a whole lot of particulars like that to take into consideration. That is a great point to deliver up. I provide the thoughts above as common inspiration but clearly there are questions just like the one you carry up the place a very powerful thing will likely be working in sincere good faith. I don?t know if finest practices have emerged around things like that, but I’m certain that your job is clearly recognized as a fair game. Both girls and boys really feel the impression of only a moment’s pleasure, for the remainder of their lives.
direk film izle
We hope to enable businesses to highlight the qualities that make their locdfations stand out through professional, high-quality imagery.”
Jeramy Rightley
You made some good points there. I did a search on the subject and found most individuals will go along with with your site.
Hermina Westenhaver
Reading by way of one’s good content, will aid me to complete so sometimes.
çeşme temizlik şirketleri
eve t nası oyun bu olayy gelde goster beaa
çeşme temizlik şirketi
yıllardır var bu fesbook nası oacass
شات صوتي
thnks
goooooooooooood
min:)اااkk
دردشة صوتية
I like such topics
ankara masaj salonları
Ankara da masaj salonları sitesinden azaraskin e selam. you are the best
av tüfeği
güzel paylaşım
küpeşte
Helal olsun
ChristianLouboutinShoe
Ladies who area on beauteous greater heeled will trun actual appropriate into a admirable focus.Inside this time period,sporting Christian Louboutin Belle Zeppa 100 Wedges Ankle Boots to accomplish your cocky assume a lot far added unique.A aggregation of colours and styles of cossack from our christian louboutin abundance so that you can select.To become a avant-garde woman,you are able to not absence 1 brace of accepted cast name analyze footwear. Christian Louboutin Shoes Australia http://christianlouboutinsaustralia.webs.com/
cheapchristianloubouti
Anyway, christian louboutin aperture In avant-garde society, top heels in in indispensability. Cartier apery watches are of assorted grades and values. cheap christian louboutin pumps http://louboutinshoesclub.webs.com/
cheapchristianloubouti
We all apperceive that arch buy Christian louboutin red bottom shoes,an acutely clandestine appropriate women. cheap christian louboutin usa http://christianlouboutinsusa.webs.com/
sineklik
Harika çok güzel :)
izmir temizlik şirketi
efsanler ölmaez ölemez dua edın ıhtıyac var
christian louboutin shoes
I enjoy This christian louboutin shoes!!!!!!
camisetas nba
,http://www.camisetas-baratas-nba.comShare your sounds with Camisetas Nba Muy Baratas by dropping them in the DropBox.
nike dunk heels
Besides, as a way to focus on the demand that a number of skateboarders exercise for extended hours and hours, the skate footwear is created especially for severe comfy, as well as appropriate.. Each year given that then has noticed a whole new design with the Jordan sneaker, each and every one particular marked through the famous “Jumpman” logo. A holy revered person has three. One can find a great selection ofall forms of shoes for kids such as boots, flip flops, sandals, athletic, casual as well asformal.. These are simply several of the fundamentals and these days there are many skate boarding schools that you can go to, nevertheless it is still mostly mastered on the street.. I felt like Supra didn’t invest the same attention to detail, precision and execution that they had in previous models. nike dunk heels http://amritaperformingarts.org/nikedunk.asp
polo ralph lauren
Apesar de cores escuras serem suas preferidas, tons glaciais também são uma grande pedida. De plus, Ambassade des Etats-Unis d’Amérique et Marché Pratunam se trouvent dans les proches environs de cet hôtel. The BBC offers a page about Ancient Greece that would be another useful classroom center website. Pour couronner le tout, sa chef lui met des bâtons dans les roues – elle le paiera d’une mort atroce – quelqu’un usurpe son identité sur son site Internet et ses nuits sont troublées par le souvenir de Benton, son compagnon, victime d’une tueuse en série.. Daniele Buetti has always been an artist, who has had a socio-political approach to the present, who has invested himself and his art, has been in search of the friction between art and life, and has understood his job of an artist as one to be exploited to the extreme (just as other jobs).
mornay mutuelle
Merci de partager autant d’informations. Vous avez une très belle plume, bravo ! Bonne journée
evden eve nakliyat
Vay be benden başka herkes burdaymış