Skia on iOS

1,239 views
Skip to first unread message

Romain

unread,
Sep 23, 2014, 12:08:31 PM9/23/14
to skia-d...@googlegroups.com
Hi everyone,

I've been trying to use Skia on iOS lately, and it seems like it is somewhat unmaintained. Either that or the documentation isn't so great. Anyway, there's an issue, and I'd be very happy to help fix it :-)

Here's my experience with Skia (commit d39c191) so far. I'm going to address different topics in this message, just tell me if that isn't appropriate and I'll repost as different messages.

Building for iOS

Building the library was ok. The library builds fine using gyp, and I could get Skia to draw to a PDF and PNG file without too much trouble.

Fat binaries on iOS / OS X

I would like to point out a few things regarding the build process though. On iOS you're supposed to be building fat binaries. Mach-O has support for multiple binaries in the same object file, and using this feature makes the build process a lot easier. For example, this lets you you add a "single" static library to your project and have it work on the iPhone Simulator and each iPhone CPU (ARMv7, v7s, ARM64, etc…). Skia doesn't seem use that feature right now. Would you think this would be a nice addition?

Building optimizations

Also, you guys decided to split arch-specific optimization in different files. This obviously makes a lot of sense, but also somehow complexifies the build process. Indeed, you need to have different targets depending on your architecture. But thing is, we already pass a lot of information regarding the architecture to the compiler (e.g. SK_ARM_NEON_IS_NONE). So it would be possible to use an umbrella C file that would dynamically include this or that assembly-optimized file based on said flags. This would tremendously simplify the build process: just build that one "umbrella.c" file, and let the pre-processor use whatever optimization makes sense based on the provided C flags.

Why didn't you guys pick that option? I'm sure you guys thought of this before, and I'm curious about why you didn't use such a solution.

OS X / iOS naming

Parts of the code for iOS lives in a "mac" folder. Namely things in src/utils/mac. It think it would make sense to rename that folder it to "apple" or to the specific frameworks that are needed (CoreGraphics).

NEON on iOS

The website says to build with arm_neon=0. Why is that so? Again, if I can help, I'd be glad :)

Displaying stuff on iOS

Like I said, rendering to a file seems to be OK. Now I've been trying to display stuff using Skia. And so far, it's been a failure.

I've been trying to figure out how SkUIView and SkOSWindow_iOS are supposed to work together, but I couldn't make sense out of the code. Also it seems like this code doesn't live in the proper place, and isn't built by the right targets. (Namely I would expect SkUIView t it in src/views/ios since its OS X counterpart lives in src/views/mac).

Am I doing thins wrong, or is that part of the code unmaintained? I'd be very happy to help update that code if some help is needed. Just let me know.

Thanks a lot,

 - Romain

Cary Clark

unread,
Sep 23, 2014, 12:28:32 PM9/23/14
to skia-d...@googlegroups.com
Hi Romain

You're right, the iOS build doesn't get much love. We don't currently have a client that uses it, so we haven't invested a lot energy maintaining it.

Feel free to create bugs and CLs to address the issues you've described, and we'll work through them one at a time. You can put me


on the bugs. It may be easiest to add discussion about the why or why not on the bug, but in short the 'why not?' is because no one asked :)

Cary

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Jim Van Verth

unread,
Sep 23, 2014, 12:56:46 PM9/23/14
to skia-d...@googlegroups.com
I'd be interested to see how things go with iOS, so please cc: me (jvan...@google.com) on the bugs as well.

As far as displaying things with Skia in the short term, you might look at the SampleApp target, which renders samples and GMs in an app.

Romain

unread,
Sep 23, 2014, 2:34:04 PM9/23/14
to skia-d...@googlegroups.com
Hi Cary, hi Jim,

Thanks a lot for the quick reply. Regarding the lack of iOS client, that's what I thought… Maybe someday Apple will let 3rd party browser on their platform ;-)

Anyway, I'll create bugs tomorrow, and depending on the interest I'll submit patches where I can.

Jim, I tried looking at the SampleApp target, from what I remember it just didn't work. Should it? Because after looking at the code, it seems like it has drifted away…

Also, and I know this can be annoying to set up, but a nice way to prevent the iOS target from breaking without anyone noticing would be to setup a continuous integration environment. Which would make a lot of sense on Skia since you guys have a solid test suite. Anyway, you already know that since you guys have an Android buildbot. If I can help setting up an iOS counterpart, that's also something I'd be glad to help with.

Cheers,

 - Romain

Jim Van Verth

unread,
Sep 23, 2014, 3:00:36 PM9/23/14
to skia-d...@googlegroups.com
It looks like adding #include "SkApplication.h" to the top of SampleApp.cpp and opening out/gyp/SampleApp.xcodeproj directly should allow you to compile and run (I'm using Xcode 5.1), at least in the simulator. I'll fix that file shortly.

Romain

unread,
Sep 23, 2014, 3:21:42 PM9/23/14
to skia-d...@googlegroups.com
Sweet. I definitely overlooked that then. Thanks!

Romain

unread,
Sep 24, 2014, 7:26:48 AM9/24/14
to skia-d...@googlegroups.com
Hi Jim,

So I tried building following your instructions, but it didn't work.

Here's what I did :

mkdir skia
cd skia
gclient config --name . --unmanaged https://skia.googlesource.com/skia.git
gclient sync
GYP_DEFINES="skia_os='ios' skia_arch_type='arm' armv7=1 arm_neon=0" ./gyp_skia
open out/gyp/SampleApp.xcodeproj


Then in Xcode, I hit the "build" button (the active target was Sample App, targeting the iPhone Simulator).

The build fails with the following errors:

skia/experimental/iOSSampleApp/SkSampleUIView.mm:137:59: error: no matching constructor for initialization of 'SkGpuDevice'
                    SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(fCurContext,
                                                          ^           ~~~~~~~~~~~~
In file included from skia/experimental/iOSSampleApp/SkSampleUIView.mm:18:
../src/gpu/SkGpuDevice.h:149:5: note: candidate constructor not viable: no known conversion from 'GrContext *' to 'GrSurface *' for 1st argument
    SkGpuDevice(GrSurface*, const SkSurfaceProps&, unsigned flags = 0);
    ^
../src/gpu/SkGpuDevice.h:32:14: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class SK_API SkGpuDevice : public SkBaseDevice {
             ^
skia/experimental/iOSSampleApp/SkSampleUIView.mm:335:27: error: allocating an object of abstract class type 'SkiOSDeviceManager'
        fDevManager = new SkiOSDeviceManager(fGL.fFramebuffer);
                          ^
In file included from skia/experimental/iOSSampleApp/SkSampleUIView.mm:1:
In file included from ../experimental/iOSSampleApp/SkSampleUIView.h:8:
skia/samplecode/SampleApp.h:79:28: note: unimplemented pure virtual method 'createSurface' in 'SkiOSDeviceManager'
        virtual SkSurface* createSurface(DeviceType dType, SampleWindow* win) = 0;
                           ^
skia/experimental/iOSSampleApp/SkSampleUIView.mm:422:42: error: no member named 'createCanvas' in 'SkOSWindow'
    SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas());
                                  ~~~~~  ^
skia/experimental/iOSSampleApp/SkSampleUIView.mm:438:42: error: no member named 'createCanvas' in 'SkOSWindow'
    SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas());
                                  ~~~~~  ^

Note that I'm using Xcode 6, but I don't think it is related :-)

Cheers,

Jim Van Verth

unread,
Sep 24, 2014, 9:13:39 AM9/24/14
to skia-d...@googlegroups.com
Apologies, my local depot was a few days out of date. We've recently changed how we set up a GPU device, and it doesn't look like those changes got propagated to iOS.  That'll take a little more time to fix, so go ahead and file the bug.

Romain

unread,
Sep 24, 2014, 12:03:41 PM9/24/14
to skia-d...@googlegroups.com
No worries. So I created a few issues, but it seems like the interface exposed to the public is severly limited.
I couldn't tag the bugs (i don't know if that's something you usually do) nor could I CC you guys.

Anyway, without further ado, here are the bugs:

 #2961: SampleApp doesn't build on iOS https://code.google.com/p/skia/issues/detail?id=2961
 #2962: Support building fat binaries on iOS and OS X https://code.google.com/p/skia/issues/detail?id=2962
 #2963: Let the compiler pick up the appropriate optimzations https://code.google.com/p/skia/issues/detail?id=2963
 #2964: Rename the "mac" folders https://code.google.com/p/skia/issues/detail?id=2964
 #2965: Support NEON on iOS https://code.google.com/p/skia/issues/detail?id=2965
 #2966: Add an iOS build bot https://code.google.com/p/skia/issues/detail?id=2966

Just let me know if I goofed anything up :-)

Cheers,

 - Romain

Heather Miller

unread,
Sep 24, 2014, 2:08:54 PM9/24/14
to skia-d...@googlegroups.com
Thanks Romain, I'll fix up the CCs and labels- appreciate you filing the bugs and spending some time helping us identify what is needed on iOS.

Romain

unread,
Sep 25, 2014, 11:45:58 AM9/25/14
to skia-d...@googlegroups.com
Thanks Heather!

I eventually managed to get Skia to display stuff on iOS using GL ES! I wasted like an hour because I forgot to flush the context (shame on me…).

Anyway, I attached a very short sample code (that uses GLKit). The code is probably dirty and leaks memory, but at less than a 100 lines I think it might help other people understand how to get started :-)

Also, while I'm at it, I feel like the view/window subsystem is somewhat broken on iOS. For instance, SkOSWindow_iOS.mm seems tightly coupled to SkUIView.m, but SkUIView.m is not part of skia proper (it's compiled in sample code only). Am I overlooking something? If not, I'd be happy to file a new bug and to contribute a fix, if needed.

Cheers,

 - Romain
SkiaDemoViewController.h
SkiaDemoViewController.mm

Heather Miller

unread,
Oct 7, 2014, 9:23:48 AM10/7/14
to skia-d...@googlegroups.com
Romain,

I realized I never got back to your final question about SkOSWindow_iOS.mm.  I looked and also chatted with Cary, and you are on to something there.  We have a mix of core and experimental/sample code coming together to make things work on this newer-supported platform, so in time, those things need to utilize or become a part of core code.  It probably just hasn't hit our top priority list, but bugs and fixes for these kinds of things are most welcome!

Thanks again,

Heather

ays...@163.com

unread,
Aug 8, 2017, 4:53:14 AM8/8/17
to skia-discuss
when I build skia for iOS , eventually I get .a file, but not include header file. How I solve this question. Thanks

在 2014年9月24日星期三 UTC+8上午12:08:31,Romain写道:
Reply all
Reply to author
Forward
0 new messages