diff options
author | Jim Van Verth <jvanverth@google.com> | 2017-11-29 11:42:33 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-29 17:06:25 +0000 |
commit | 329c5a6d826b7b90e5e75ec0a7824c75ed5f8077 (patch) | |
tree | cdc91f8575ad0f6b210d3df484bacdf439320dec /src/ports/SkOSFile_ios.h | |
parent | 19ea45ef538b0cbcd2088e85fa7e88384d6932e3 (diff) |
Bundle resources and skps directories into iOS app.
Will bundle resources/ for viewer (and skps/ if
that directory exists in the main Skia directory).
Also updates file code on iOS to fall back to bundle directory.
Docs-Preview: https://skia.org/?cl=76803
Bug: skia:7339
Change-Id: I244f67559c866451a6d02c3f1c4948d89457ec84
Reviewed-on: https://skia-review.googlesource.com/76803
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/ports/SkOSFile_ios.h')
-rw-r--r-- | src/ports/SkOSFile_ios.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/ports/SkOSFile_ios.h b/src/ports/SkOSFile_ios.h new file mode 100644 index 0000000000..d74aa200cc --- /dev/null +++ b/src/ports/SkOSFile_ios.h @@ -0,0 +1,41 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkString.h" + +#ifdef SK_BUILD_FOR_IOS +#import <CoreFoundation/CoreFoundation.h> + +static bool ios_get_path_in_bundle(const char path[], SkString* result) { + // Get a reference to the main bundle + CFBundleRef mainBundle = CFBundleGetMainBundle(); + + // Get a reference to the file's URL + CFStringRef pathRef = CFStringCreateWithCString(nullptr, path, kCFStringEncodingUTF8); + // We use "data" as our subdirectory to match {{bundle_resources_dir}}/data in GN + // Unfortunately "resources" is not a valid top-level name in iOS, so we push it one level down + CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, pathRef, nullptr, CFSTR("data")); + CFRelease(pathRef); + if (!imageURL) { + return false; + } + if (!result) { + return true; + } + + // Convert the URL reference into a string reference + CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle); + CFRelease(imageURL); + + // Get the system encoding method + CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); + + // Convert the string reference into an SkString + result->set(CFStringGetCStringPtr(imagePath, encodingMethod)); + return true; +} +#endif |