Win2D – creating open source at Microsoft


If you had asked me a couple of years ago the probability that I would find myself in 2014 paid by Microsoft to work full time on open source code, I would have said near zero.  And yet here we are!

Win2D is not my first open source project.  I ran what grew to be a substantial one while in college, and more recently a smaller side project that sat alongside my regular day job.  But this is my first time trying to combine the worlds of open source and software development at a large corporation.

I have seen companies approach open source in many different ways.  Sometimes they just throw code over the wall without any support when a product reaches what would otherwise be the end of its lifespan.  Other times they release periodic snapshots of code that is developed internally, with no path for others to contribute to it.  Or they ship code without its tests(1), or code that requires tools not available to outsiders to build it.

(1)  Yup, I’m guilty as charged of this with DirectXTK  🙁

Plus of course, companies often do open source enthusiastically and whole-heartedly, which is what I hope to achieve with Win2D.  For me this includes:

  1. Share everything.  Not just the product code but also tests, source materials used to generate the documentation, scripts needed to build and validate the product, etc.
  2. Don’t depend on anything proprietary or hard to get hold of  (building and testing Win2D currently requires nothing more than Visual Studio, plus the open source Sandcastle Help File Builder if you want to rebuild the documentation).
  3. Ship early, update often, and share a roadmap.
  4. Accept contributions from others, as long as they are of sufficiently high quality and fit the goals of the project.
  5. Use a standard license that people are already familiar with.

My last few months have involved many round-peg square-hole problems as we worked out how to apply existing Microsoft processes that were designed for very different goals (such as building and shipping Windows) to this new way of working.  I’m feeling good about how things have turned out so far…


Comments (18)

  1. Dev says:

    Hi,

    Why not contribute to or fork MonoGame instead? MonoGame being the alternative for XNA would benefit from this quite a lot.

    Otherwise it would be nice to resurrect XNA, since this is exactly what people want as per 18'000+ UserVoice suggestion: visualstudio.uservoice.com/…/3725445-xna-5

    Thank you for your work.

  2. ShawnHargreaves says:

    MonoGame is a great project, and seems to be doing fine already. I'm not really sure what we could contribute there.

    Win2D and XNA are actually pretty different both in features and what problems they are attempting to solve.

  3. Stranger says:

    How is this different than other 2D libraries available already like Cairo and Skia. Skia has GPU accelerated backend.

  4. @MujkicHaris says:

    This is great. Looking forward to see how this API grows. Will this API have an option to plug our own effects (shaders)?

  5. ShawnHargreaves says:

    > Will this API have an option to plug our own effects (shaders)?

    Eventually yes, but we're concentrating on a rich set of built-in effect types first.

    Native D2D Imaging API does support custom effects, but the process of writing them is somewhat arcane, so we want to make that much easier in Win2D.  Not entirely sure what the API for it will look like yet though.

  6. willmotil says:

    sounds cool

    you and walbourn are hero's man, god i loved xna

  7. Aaron says:

    How will Win2D compete with universal APIs built on top of WebGL?  Pixi.js and Three.js can produce 3D accelerated 2D and 3D applications right in the browser, with great performance.  Also, with WinJS and Windows Store Apps, you can produce highly optimized 3D games inside Visual Studio, using Javascript, HTML, and CSS.  All the javascript gets minified/optimized and the underlying WebGL code gets translated by the Trident rendering engine in IE11 into calls to DirectX.  The result is a development experience that feels as fast as bare-metal DirectX, with the duck-typing freedom of Javascript.  Plus, you get all the UI for "free" with HTML/CSS.  You can finally have text input boxes, combo boxes, and buttons without having to program their logic and rendered appearance yourself!

    I'm currently developing a game in Visual Studio Express for Windows, using WinJS as the base, Pixi.js for 2D sprite rendering, Three.js for some 3D model rendering, and HTML/CSS for UI controls.  Of course, my target audience is limited to Windows Store apps, but since all the code is written in javascript and HTML/CSS, it's completely portable to any other platform that supports Javascript/HTML/CSS.

    If Microsoft continues to develop WinJS and the Universal Apps paradigm, I struggle to see the use for Win2D (but I only struggle to see at the moment because I am woefully ignorant of it).

    I'm assuming you can't share much more detail on Win2D at the moment, but here are some additional questions I have about it:

    1.  Will it eventually support additional languages besides C#/XAML and C++?

    2.  What target platforms is it really designed for?

    3.  Why does Win2D exist?

    I hope I don't come across as sounding critical, I'm actually very curious about the project and additionally interested because it's you–the man–Shawn Hargreaves working on it.  I remember you helping me out during the XNA days and thinking how awesome it was that you were willing to take the time to answer questions.  Your passion for Managed DirectX and then XNA was very motivating.

  8. ShawnHargreaves says:

    Aaron, this article will hopefully answer your questions about why we are building Win2D:

    blogs.msdn.com/…/introducing-win2d-gpu-accelerated-2d-graphics-programming-in-the-windows-runtime.aspx

    As for where we plan to go with it in future, see the work backlog: github.com/…/Backlog

    JavaScript/HTML/WinJS etc. is a great development platform, but it's not the perfect answer for all developers and all types of content. Horses for courses, as they say…

  9. Aaron says:

    Thank you for the info Shawn, it does help satiate my curiosity.  🙂

    At first glance, it seems as though Win2D is designed to bring the capabilities of Direct2D into the managed developer space and in so doing, take advantage of the simplicity and RAD that .NET and the WinRT offers. It seems as though Win2D is basically just Managed Direct2D, which I know is an inaccurate and possibly unfair assumption. But after looking at the rather extensive backlog list, it's evident that Win2D is much more than Managed Direct2D, it will be a completely new framework with "features" chosen to match parity with Direct2D and not reach outside the scope of Direct2D.

    I guess my concern now is that I (perhaps naively) feel like you guys are reinventing the wheel with this. I can't say for sure, but I get the sneaking suspicion that Managed DirectX had the potential to bring DirectX properly into the managed space, but instead was mutated into a "games only" development platform called XNA.  XNA then (apparently) backed itself into a corner from which it could not escape from (by being strictly designed for and marketed to game development only).

    Now with Win2D, it appears that once again you are taking what could just be Managed DirectX and mutating it into a strictly 2D graphics API for .NET, potentially walling yourself into another corner.  I guess I would feel better if I knew that Win2D was just one component in a grander scheme to bring the power and capability of the entire DirectX API into managed space.  Right off the bat, Win2D (even with the road map outlined in the backlog) is limited as a game platform because there will be no 3D capability.  Enter Win3D?  At that point, you may as well unify the APIs into one API with 2D/3D capability and all it WinGraphics!  😀

    Regardless of all this, I will follow Win2D with interest and look forward to possibly using it for some niche applications in the future.

    Thanks for listening.  🙂

  10. ShawnHargreaves says:

    I'm not convinced that a single API trying to do both 2D and 3D in one go is a good idea.  Easy interop between different APIs is very important (and a key goal for Win2D) but in my experience trying to do everything at once is usually a recipe for not doing any of it especially well!  Even in the native C++ APIs, we have different API surface in D2D vs. D3D, each one specialized for a different purpose.

  11. Aaron says:

    I couldn't agree more.  Doing 2D and 3D in one go is not a good idea and easy interop between differing APIs is crucial (this is why I like WebGL and all the existing javascript libraries that target it).  As I mentioned previously, Pixi.js does fast 2D rendering with sprites.  Three.js and Babylon.js provide scene graphs, modeling, and other 3D capabilities. HTML5 Canvas provides shape and line drawing.  And plain old HTML elements with CSS styling provide UI elements.  All these can work harmoniously together to create any 2D/3D application or game and they can all run flawlessly inside WinRT using the JavaScript for Windows Store project templates in Visual Studio Express for Windows.

    I like the idea of Win2D in so far as it's an alternative for those seeking a framework for developing hardware accelerated 2D graphics applications and use C#/C++ to do it.  I think you may find that 3D capability requests will popup more and more as the framework matures, especially if you intend to cater to game developers.  Would 3D support be something you think could be tacked on later?

    I hope it doesn't seem like I'm crapping on your parade here…lol.  I will support anything you work on and I look forward to seeing how Win2D evolves in time.  🙂

  12. Disalvo says:

    As a game Developer I can just hope this opens a path again for us from Microsoft's end. Am I right in hoping this?

  13. Beoran says:

    Well it's nice that Microsoft is allowing you to program open source, but again it's a completely non-portabe API, fraught with complexity. I would be far happier if Microsoft paid you to work on the Windows port of Allegro, and on C# bindings for it…  

    Allegro was and still is one of your most brilliant ideas, and the Allegro community really gave it wings. I have used Allegro since the DOS days, and it's still going strong after 15 years. Allegro is resilient, it has outlived XNA, and I think it will outlive Win2D as well.

    Now with Allegro 5.1.x, we have a portable cross-platform API for 2D and 3D graphics, game programming and multimedia that is brilliant yet simple. Just look, for example, at Args.DrawingSession.DrawEllipse versus al_draw_ellipse. But still I feel Allegro misses you and your brilliance at times. If only we could convince Microsoft of the value of Allegro…

  14. Eric says:

    Super Excited for this.  Would Win2D be suitable for the following?

    I wanted to build a Universal Windows App with C++/XAML/Direct2D.  However I ran into issues with certain unsupported Win32 APIs  (ones partitioned to the DESKTOP).  The app would be side loaded.  At the very heart of the app was a SwapChainPanel for my Direct2D content.  My Device is embedded and runs on Windows 10 on Intel based HW.  I do not want to use IPC mechanisms to get around the needed APIs.

    The APIs I need are CreateFile, ReadFile, WriteFile, DeviceIoControl and CloseHandle to read and write to all locations of the file system and also to communicate to device drivers.

    I have been looking for an alternative to a Windows Universal App so that I can have unrestricted Win32 API access but have not liked my UI framework choices:  WPF, QT, etc..

    Any thing I should be aware of?  I have a touch panel as part of my HW.

  15. Eric, Win32 is a UWP graphics API.  It won't help if you're wanting to make a classic desktop app.

  16. Eric says:

    Thanks Shawn,

    I have seen some open source implementations based on DirectUI and/or Jupiter.  They seem to be exactly what I need.  Is there anyway to get MS to bless and/or contribute to https://dui.codeplex.com/  or http://www.codeproject.com/…/DirectUI or others.  I also see a post indicating that:

    (Update: Windows 8 opens the door to DirectUI for programmers)

    stackoverflow.com/…/what-is-the-fact-of-directui

    The issue is that I really need a desktop UI solution with great Direct2D support

  17. Laith says:

    Hi Shawn.

    Just wanted to thank you for all your hard work (and the rest of your team). Win2D has opened new possibilities for us and we're able to create amazing high-performance apps.

    The next version of our app is taking full advantage of Win2D.

    Many thanks from Australia!

  18. Thank you Laith, that's nice to hear!

Skip to main content