Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(945)

Unified Diff: src/ports/SkOSFile_stdio.cpp

Issue 1382943004: Some iOS fixes to make SampleApp work better. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add missing comma Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkOSFile_stdio.cpp
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp
index 261d0613bb88131a80ab3806754437ece92b0037..53a2bb47ecde1a320d48229acb236407b9cb8f2d 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)));
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698