diff options
author | jvanverth <jvanverth@google.com> | 2015-10-02 09:12:05 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-02 09:12:05 -0700 |
commit | 44dcb8a84bcced3a42609ecb4abac1f3e7cc6cbe (patch) | |
tree | 71ea56128998b5d513b83faa40bb2ff178ca5495 /src/ports/SkOSFile_stdio.cpp | |
parent | a7e878064509ef96b54d5507dab0b50def66dc13 (diff) |
Some iOS fixes to make SampleApp work better.
Changes:
- Rebuild argc and argv so we can process command line arguments
- Remove unnecessary SimpleiOSApp files
- Add support for reading files from the app bundle
- Add gpu flag so we can start up directly into OpenGL
Review URL: https://codereview.chromium.org/1382943004
Diffstat (limited to 'src/ports/SkOSFile_stdio.cpp')
-rw-r--r-- | src/ports/SkOSFile_stdio.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp index 261d0613bb..53a2bb47ec 100644 --- a/src/ports/SkOSFile_stdio.cpp +++ b/src/ports/SkOSFile_stdio.cpp @@ -17,6 +17,34 @@ #include <io.h> #endif +#ifdef SK_BUILD_FOR_IOS +#import <CoreFoundation/CoreFoundation.h> + +static FILE* ios_open_from_bundle(const char path[], const char* perm) { + // Get a reference to the main bundle + CFBundleRef mainBundle = CFBundleGetMainBundle(); + + // Get a reference to the file's URL + CFStringRef pathRef = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8); + CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, pathRef, NULL, NULL); + if (!imageURL) { + return nullptr; + } + + // Convert the URL reference into a string reference + CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle); + + // Get the system encoding method + CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); + + // Convert the string reference into a C string + const char *finalPath = CFStringGetCStringPtr(imagePath, encodingMethod); + + return fopen(finalPath, perm); +} +#endif + + SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) { char perm[4]; char* p = perm; @@ -29,10 +57,22 @@ SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) { } *p++ = 'b'; *p = 0; - + //TODO: on Windows fopen is just ASCII or the current code page, //convert to utf16 and use _wfopen - SkFILE* file = (SkFILE*)::fopen(path, perm); + SkFILE* file = nullptr; +#ifdef SK_BUILD_FOR_IOS + // if read-only, try to open from bundle first + if (kRead_SkFILE_Flag == flags) { + file = (SkFILE*)ios_open_from_bundle(path, perm); + } + // otherwise just read from the Documents directory (default) + if (!file) { +#endif + file = (SkFILE*)::fopen(path, perm); +#ifdef SK_BUILD_FOR_IOS + } +#endif if (nullptr == file && (flags & kWrite_SkFILE_Flag)) { SkDEBUGF(("sk_fopen: fopen(\"%s\", \"%s\") returned NULL (errno:%d): %s\n", path, perm, errno, strerror(errno))); |