12 ms·
Skia: an open source 2D graphics library
- stevemk14ebr 9y agoC++ 11, nice. Does anyone use this? And if you do how does it compare to alternatives
- adamnemecek 9y ago> It serves as the graphics engine for Google Chrome and Chrome OS, Android, Mozilla Firefox and Firefox OS, and many other products.
- abarth 9y agoSkia is used by Chrome, Android, and Flutter at Google. I believe Adobe and Microsoft also use Skia in various products.
- tonyedgecombe 9y agoDoesn’t Microsoft have Direct2D for this sort of thing.
- adamnemecek 9y agoI think it's for Xamarin.
- speps 9y agoGoogle Chrome
- PeCaN 9y agoSkia is probably the most popular 2D graphics library at the moment. I don't really know why this got on HN now. It's already extremely popular. I use it in a little WIP game engine. It's very pleasant, excellent little library. There's an online jsfiddle-esque demo here https://fiddle.skia.org/ https://fiddle.skia.org/ if you want to try it out.
- emmelaich 9y agoNice but got "Failed to run, possibly violated security container"
- hwc 9y agoThe little server that runs fiddle.skia.org is probably overloaded.
- percentcer 9y agoI have a little 2d game that I'd like to port over to Skia. What did you end up using to handle input and audio and other gamey things?
- megaman22 9y agoI would think SDL would be an easy cross-platform choice there.
- deleted 9y ago[deleted]
- emmelaich 9y agoYou might look at https://sciter.com/ https://sciter.com/ Which apparently uses Cairo, Direct2D or Skia depending on the platform.
- PeCaN 9y agoI used https://github.com/jkuhlmann/gainput https://github.com/jkuhlmann/gainput for input. I never did get around to handling audio. For the UI I used imgui. Skia actually comes with an imgui backend (it's used for the Viewer tool) that is easy enough to hack into whatever you need.
- puzzle 9y agoThe funny thing is that Skia is a startup in NC that was acquired more than a decade ago and turned into one of the smallest and most elusive Google engineering offices, basically just to keep Mike Reed (TrueType and TrueType GX) and his people.
- guessmyname 9y agoSublimeText uses Skia for rendering.
- throwaway2016a 9y agoFor anyone thinking of skipping looking at this one. I was not interested either until I read this part: > It serves as the graphics engine for Google Chrome and Chrome OS, Android, Mozilla Firefox and Firefox OS, and many other products.
- dsego 9y agoSublime Text afaik.
- j_s 9y agoSimilar situation to the freetype/harfbuzz all-but-Microsoft/Apple (open source) monoculture. I'm interested to understand more about how some categories of software libraries don't foster multiple strong open source alternatives, while others do.
- gatmne 9y agoI was thinking about this recently. I think this type of consolidation starts to make sense if you think of software as mathematics. A formula gets devised, iterated upon and refined, adopted, and then finally built upon. It makes more sense to adapt a standard formula to a given use case than it is to derive a custom formula from the ground up. I suspect the reason why its not the case for software is because of copyright and IP laws. Likewise, I expect mathematics wouldn't have advanced as much as it has had there been IP laws enacted for mathematics. People would too limited by the licensing terms for their Leibniz™ and Euler™ formulas to be able to be able to build the next step.
- bjz_ 9y agoThere are many degrees of freedom to work on when it comes to mathematics, many perspectives to look at the same problem. Some are elegant, some are ugly, others are painful to work with, and make future progress hard. Just as it is with software. We constantly need to reassess our foundations, and not get too coupled to a single perspective, lest it drive us into a corner and stifle further innovation.
- 9y ago
- electricslpnsld 9y agoThis looks really useful! Does anyone know how this compares to something like Cairo?
- ttd 9y agoSkia (via SkiaSharp) is the rendering backend for my vector graphics diagramming application (https://vexlio.com https://vexlio.com). I chose it in part because it had much better performance than Cairo when I was testing both. Also the MIT license was more appealing to me than Cairo's LGPL or Mozilla Public License.
- tenken 9y agoLooks like a nice project. For my own (web development) kind of projects I love to diagram infrastructure, Classes, etc. But, I do nearly all my work on Linux -- which is a pity because I'd love to try out a tool like Vexlio. For now I guess I'll continue to stick with yEd, because it actually works everywhere (java works).
- NKCSS 9y agoSite looks great; well done!
- anonova 9y agoNote that Skia is a C++ library and does not provide a stable C API.
- hcmiller 9y agoSkia has a C API under development that is our approach to API stability, but it is not comprehensive and still being added to (sometimes by our clients to get access to the APIs they need).
- emmelaich 9y agoThat's the first question that occurred to me so I web-searched. Seems it is faster and has a broader API. I sort of expected that Raph Levien(1) might have contributed or that Cairo would be part of the base of Skia. But apparently not. (1) works at Google and wrote Cairo
- adelarsq 9y agoAlso there is a Rust adapted version https://github.com/servo/skia https://github.com/servo/skia, used on Servo
- EddieSpeaks 9y agoSkiaSharp on Xamarin is fantastic for some cross-platform graphical apps
- bratsche 9y agoThere is also a .NET binding for Windows and Xamarin: https://www.nuget.org/packages/SkiaSharp/ https://www.nuget.org/packages/SkiaSharp/
- voltagex_ 9y agoHas anyone used this? Are there any examples?
- alkonaut 9y agoI’m converting a large desktop (CAD) app from GDI+ to SkiaSharp at the moment. Really liking the Api and the quality of the C# wrapper. Also maps very well to GDI concepts so a conversion is fairly painless.
- voltagex_ 9y agoCool. Are you able to share any more details? I'm guessing this isn't a standard WinForms app. What advantages does moving away from GDI+ give you?
- alkonaut 9y agoIt’s a winforms app, and there isn’t much nonstandard about it other than that large performance sensitive drawing apps are perhaps quite nonstandard to begin with. We want to handle some large cad scenarios in it (e.g smooth pan/zoom in drawings with 500k lines), it’s not the default use case, but it happens. The main advandtage over gdi+ ) is better support for retained mode drawing (record/playback style drawing), more efficient automatic culling, etc.
- needusername2 9y agoWhy are you converting to SkiaSharp, if I may ask? Is it for performance or multiplatform reasons?
- 9y ago
- guessmyname 9y agoWith all the fuss with "modern" text editors built on top of web engines, I feel the need to remind you all that one of the fastest graphical code editors that I have ever used — SublimeText — was built using Skia for the rendering. I believe many people have noticed how smooth the interface and most of the operations feel, a very good selling point if you want to build a GUI in the future.
- raphlinus 9y agoFor xi-editor I considered Skia but ultimately decided to write my own OpenGL renderer. I think Skia would have worked, but the dependency was heavyweight and I'm able to tweak my renderer (for example, it gets linear-sRGB color blending right, while Skia uses an approximation). I have a draft blog post on this in the queue, but juggling just a few too many things at the moment.
- bla2 9y agoIsn't skia able to call OpenGL too? Do you think your own thing will be lighter weight in the end? Which parts of skia do you think you won't need? (For sRGB, a patch for skia might be less work than a full new 2d library. Also depends on if your goal is to write fun code or to get a product out, of course.)
- raphlinus 9y agoIt all depends how you count. I consider the total cost of adopting a dependency the size of Skia to be quite a bit more than the lines of code written; I would have had to write _some_ code to do the interfacing. Then there's the question of source code download size and clean build times, which would have both gone up by more than an order of magnitude.
- mrlambchop 9y agoWhen leading an Android platform team several years ago, we enable the OpenGL backend to Skia to see if it would accelerate general UI rendering. The conclusion was after a whole bunch of bug fixes (OpenGL ES 2.0 IIRC), it ran but (a) ate up a lot of GPU memory (b) was slower than the 2D rendering for 80% of the drawing operations (c) some rendering ops (such as the font wide) could not be easily accelerated, meaning you would need to flush the GPU partially rendered frame periodically, then bring into the CPU cache, draw over and then flush again before writing more GPU operations. Fun experiment - poor outcome!
- Matheus28 9y agoI've used it to create a desktop port of http://diep.io/ http://diep.io/. It's great (easy to use, reasonably documented), but it's a pretty big dependency (I don't remember exactly, but I think like 20 MB or so?). Since diep.io uses the canvas 2d API, porting was pretty straight forward. The performance on desktop is unsurprisingly many times faster than the browser.
- electricslpnsld 9y agoWhat motivated your choice of Skia over WebGL?
- Matheus28 9y agoYou mean canvas 2d? If you're making a 2d game, it's good enough and looks really nice. Performance is good enough in most cases. Because of some OpenGL gotchas in some drivers (macOS mostly), some operations are a lot slower in those OSes (I have a demo that runs at 3 fps on my macbook, and >144 fps on my windows). It's easier to use canvas 2d as you don't have to deal with any of that.
- bch 9y agoUgh... This build system is _horrible_. bash-dependent meta-builder for ninja-build working in git checkouts. Are both actual releases and traditional build systems that out of fashion?
- bch 9y agoYou guys are killing me. After downloading twenty-some git repos(?) as dependencies (most of which my system already has), this (I’ll try to quit complaining about this better mousetrap now): kamloops$ gn Traceback (most recent call last): File "/home/bch/work/skia/src/vendor/depot_tools/gn.py", line 38, in <module> sys.exit(main(sys.argv)) File "/home/bch/work/skia/src/vendor/depot_tools/gn.py", line 22, in main bin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath() File "/home/bch/work/skia/src/vendor/depot_tools/gclient_utils.py", line 749, in GetBuildtoolsPlatformBinaryPath raise Error('Unknown platform: ' + sys.platform) gclient_utils.Error: Unknown platform: netbsd8
- hwc 9y ago> After downloading twenty-some git repos(?) as dependencies (most of which my system already has) Skia statically links in copies of these dependencies for testing purposes only. There is a mode ("is_official_build") that will search for your system libraies.
- bch 9y agoAh. I used that flag on first build attempt (which failed), then did a “tools/git-sync-deps” to pacify the build system (w/o any flags), wherein the repo cloning did commence.
- matt2000 9y agoAmong all the other things mentioned in the comments, AFAIK this is the rendering engine for https://flutter.io/ https://flutter.io/ too
- Skylled 9y agoWhich means it's also used in most Fuchsia projects.
- tony 9y agoAseprite switched to Skia a year or so ago (https://github.com/aseprite/aseprite https://github.com/aseprite/aseprite). Regret it. Google doesn't care to maintain CMake support for it, so there goes pulling it in via source and building as a library dependency. https://github.com/aseprite/aseprite/issues/1598#issuecomment-341869884 https://github.com/aseprite/aseprite/issues/1598#issuecommen... You may ask, "why don't you just write your own CMake module like everyone else?" I've tried. I think the build system changed a bit since, but back when I last tried, it required grabbing depot tools, checking out a source tree and a ton of other dependencies. I am the original person that got Aseprite building on FreeBSD - but now I can't build it on any platform at all. Skia has too many points of failure in the build process. (Here's another issue where I spend hours trying to figure out what's going on https://github.com/aseprite/aseprite/issues/1081 https://github.com/aseprite/aseprite/issues/1081) Every other graphics library (SDL2, Allegro, SFML) can work with CMake. Another pain point: Skia isn't on any package managers to my knowledge. Here's the debian RFP https://bugs.debian.org/818180 https://bugs.debian.org/818180.
- jchw 9y agoOut of curiosity, aside from the obvious disadvantages you mentioned, what advantages does it bring to the table? Long-time casual user of Aseprite. To be honest, I never knew it was open source until just now, I actually own a couple copies.
- git-pull 9y agoAllegro, SDL2, SFML, et al. do more things (audio, joystick support, keyboard/mouse events) across platforms. Skia does one thing really well, 2D graphics. There is a ticket open for building an abstraction layer @ https://github.com/aseprite/aseprite/issues/139 https://github.com/aseprite/aseprite/issues/139 In terms of Aseprite: > > But what made it the choice over Allegro 5, SFML, and SDL2? > through all these years I reached to the conclusion that you need full control of mouse and keyboard messages (and all window messages in particular, e.g. to give proper support to pen/stylus). [1] [1] https://github.com/aseprite/aseprite/issues/139#issuecomment-311833621 https://github.com/aseprite/aseprite/issues/139#issuecomment...
- FascinatedBox 9y agoThe roadmap needs to be updated. It's for 2016-2017.
- hcmiller 9y agoIt has been updated with the doc of high level themes we are chasing for 2018.
- pjmlp 9y agoFun fact, it is used in Android, but not exposed to the NDK. So C++ applications on Android that wish to use Skia, do have to use the Java API via JNI (android.graphics.Canvas) with the respective performance impact due to marshaling, or package their own Skia version, thus increasing their APK size and having to deal with a build system that only makes sense for Google employees.
- 1inuxoid 9y agoThis can't be intentional, right?
- pjmlp 9y agoGoogle does not seem interested in making the NDK anything more than implementing Java native methods, 3D graphics, audio or porting code from other platforms. Everything else should be done at Java level. I understand from the point of view of security, but what is safer, provide bindings to libraries already validated and installed on the device or forcing devs to package something else? Also even though they implement native APIs in nice C++ with RAII and stuff, it gets exposed as unsafe C APIs, so the security story isn't 100% correct.
- mdwrigh2 9y agoSkia does not have a stable ABI, which is a requirement for inclusion in the NDK: https://github.com/google/skia/blob/master/experimental/c-api-example/c.md https://github.com/google/skia/blob/master/experimental/c-ap...
- pjmlp 9y agoIt has a stable API for Java clients on Android, if Google actually would care they could expose that one. And in any case, creating a 2D abstraction layer stable API on top of platforms specific version APIs, specially given that all NDK APIs are C based even if written in C++, it is not rocket science, rather a matter of wanting to do it.
- 9y ago
- roel_v 9y agoHow about font rendering? Would I use freetype/harfbuzz with this? They're such a bitch to build on Windows. Currently I'm using DirectWrite but having portability would be a nice bonus, as it seems that the API of this isn't worse than Direct2D.
- TwoBit 9y agofreetype and harfbuzz don't draw text. Freetype reads font files and gives you individual glyphs, and harfbuzz does "shaping". Pango does layout but also doesn't draw text.
- roel_v 9y agoI know, which is why I said 'font rendering' - but of course (for any practical purpose) that extends into drawing onto a context/canvas/whatever it's called in a specific ecosystem. Pango can draw to Cairo (modulus some very pedantic definitions of 'draw'), for example, but in some combinations of glyph rendering/layouting/drawing libraries you have to fiddle with getting one library to render as a path and then use generic path drawing routines to actually rasterize. I can't be bothered with that sort of minutiae, hence my question - how much (if at all) is this library integrated with other functionality to render, query the rendered form, and rasterize text. I mean, say what you want about DirectWrite and the Direct2D environment - but at least it's very clear how things fit together and it works very well, even for niche use cases. In open source land, you spend days just puzzling together the pieces - let alone build them and getting them to actually do something useful from code. I've tried plenty over the last 15 years. (edit: typos)
- bjz_ 9y agoThe Firefox and Servo team are currently hard at work on Pathfinder, which should solve this for both fonts and SVG. It'll run on the GPU like WebRender which is super exciting: https://github.com/pcwalton/pathfinder https://github.com/pcwalton/pathfinder - alas it's still a WIP at the moment.
- roel_v 9y ago
- robert_foss 9y agoThere are alternatives to Skia that are even faster like FastUIDraw. https://www.x.org/wiki/Events/XDC2016/Program/rogovin_fast_ui_draw/ https://www.x.org/wiki/Events/XDC2016/Program/rogovin_fast_u... https://github.com/intel/fastuidraw https://github.com/intel/fastuidraw
- Taniwha 9y agoSo back in the early 90s Apple had a graphics library called "skia" - are these related?
- speps 9y agoSee this post from earlier: https://news.ycombinator.com/item?id=16148185 https://news.ycombinator.com/item?id=16148185
- ahartmetz 9y agoSomehow the text it renders looks worse than all the other common graphics libraries on Linux - which all use FreeType and Harfbuzz. I am not sure what QtWebEngine does differently, because it uses Blink and the text looks fine.
- hwc 9y ago"looks worse" is a pretty nebulous statement. Can you go into detail? Do you think text in Chrome looks bad?
- ahartmetz 9y agoIt seems like lack if subpixel rendering plus the spacing between letters is somehow screwed. Really hard to put a finger on it, it just looks wrong to me. I do think that text in Chrome looks bad on Linux. I could compare magnified screenshots now but I'm too lazy, sorry. Don't care much about Chrome anyway.
- nbsd4lyfe 9y agojust a heads up, skia doesn't work on big endian.
- mamcx 9y agoHow good/hard to build an UI library (like bootstrap) on it? I'm already on F#/C# so I don't will have issues with building it (I imagine!)