Results 1 to 4 of 4

Thread: Advantages of Cairo ?

  1. #1

    Thread Starter
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Question Advantages of Cairo ?

    This thread made me wonder about the viability of Cairo for writing 2D engines.

    So can anyone here tell me why they would use Cairo over Windows' native GDI/GDI+ for their rendering. Is it faster, easier ? Why do you use it ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Advantages of Cairo ?

    Olav seems to give a fair summary at the following link.
    http://computer-programming-forum.co...b40f9d52e9.htm

    I assume it is not necessarily faster than well written code that accesses GDI/GDI+ and that take advantage of the "tricks of the trade" to get high speed access to pixels.
    But the point is that it provides better and wider access to these capabilities, so the end user can take advantage of a larger base of 2D drawing capabilities without having to extend GDI/GDI+ themselves to encapsulate them.
    It sounds especially useful for VB6 users, and of course is geared for C from the start. Probably will require some interop considerations if you wanted to use it from VB.Net or C#. (Actually, a quick search shows a language bindings list here.

    I guess that's all I have time to investigate for now.

  3. #3

    Thread Starter
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Advantages of Cairo ?

    Quote Originally Posted by passel View Post
    Olav seems to give a fair summary at the following link.
    http://computer-programming-forum.co...b40f9d52e9.htm

    I assume it is not necessarily faster than well written code that accesses GDI/GDI+ and that take advantage of the "tricks of the trade" to get high speed access to pixels.
    But the point is that it provides better and wider access to these capabilities, so the end user can take advantage of a larger base of 2D drawing capabilities without having to extend GDI/GDI+ themselves to encapsulate them.
    It sounds especially useful for VB6 users, and of course is geared for C from the start. Probably will require some interop considerations if you wanted to use it from VB.Net or C#. (Actually, a quick search shows a language bindings list here.

    I guess that's all I have time to investigate for now.
    Thanks. Based on what I've read there, Cairo doesn't take advantage of hardware acceleration which might mean it wouldn't necessarily perform better than GDI/GDI+. It seems Cairo was made more for flexibility than performance.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: Advantages of Cairo ?

    A few more additions, if I may:

    - Cairo is a 2D graphics API, but its biggest emphasis is vector handling (e.g. paths) and text. It does offer raster capabilities, with some neat features like blend modes, but raster stuff isn't their main focus.

    - Cairo is a low-level C API, so to use it, you need to find a binding for your language. There are two .NET bindings: one provided by the Mono project, and one provided by NDesk. (I'm not sure if the NDesk one is still under development.)

    - Cairo's performance is less about Cairo itself (again, it's just an API), and more about the backend you choose. The default Cairo backend is called Pixman. Pixman is entirely CPU-bound (as you mention), but it makes liberal use of various CPU extensions (SIMD, etc) to improve performance.

    The nice thing about Cairo+Pixman is that it'll run on just about anything. The downside, as you mention, is that its CPU-bound.

    - Cairo does provide an OpenGL backend with GPU support, but it's classified as "experimental" and is primarily focused on Linux support.

    - Cairo used to be the primary 2D API for major projects like Firefox, but they have since moved to Skia. Skia has much better OpenGL support (courtesy of Google's investment, since Google uses it for Chrome), and I believe there's talk of a Direct2D back-end just for Windows. But to my knowledge, Skia doesn't offer a .NET wrapper.

    The Skia project actually offers a nice explanation of why they didn't just wrap GDI and GDI+, if you're curious.

    Anyway, that's my $0.02. GDI is generally faster than Cairo but way more limited, with very poor 32-bit support. GDI+ is generally slower than Cairo (and it's also CPU-bound, while making worse use of specialized CPU extensions) but it offers a similar feature set, excellent 32-bit support, and is obviously easier to use as a .NET developer.

    Last year, some of us VB6 guys threw together a comparison between the various options here. The demo was just for 32-bit alpha blending, with no path or text testing. Performance (fastest to slowest) was:

    1) GDI's AlphaBlend
    2) Cairo (via Olaf's vbRichClient wrapper)
    3) Flat GDI+ calls to GdipDrawImage
    4) Managed GDI+ calls (through WIA)

    I imagine Direct2D would be faster than all the above, but then you have to deal with its ridiculous API design...
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width