diff options
-rw-r--r-- | BUILD.gn | 5 | ||||
-rw-r--r-- | bench/nanobench.cpp | 4 | ||||
-rw-r--r-- | dm/DM.cpp | 4 | ||||
-rw-r--r-- | tools/ios_utils.h | 23 | ||||
-rw-r--r-- | tools/ios_utils.m | 19 |
5 files changed, 55 insertions, 0 deletions
@@ -910,6 +910,11 @@ if (skia_enable_tools) { "tools/sk_tool_utils_font.cpp", "tools/timer/Timer.cpp", ] + libs = [] + if (is_ios) { + sources += [ "tools/ios_utils.m" ] + libs += [ "Foundation.framework" ] + } deps = [ ":common_flags", ":flags", diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index c2afca65cb..4e1da2bd98 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -23,6 +23,7 @@ #include "SKPAnimationBench.h" #include "SKPBench.h" #include "Stats.h" +#include "ios_utils.h" #include "SkAndroidCodec.h" #include "SkAutoMalloc.h" @@ -1096,6 +1097,9 @@ static void start_keepalive() { int nanobench_main(); int nanobench_main() { +#if defined(SK_BUILD_FOR_IOS) + cd_Documents(); +#endif SetupCrashHandler(); SkAutoGraphics ag; SkTaskGroup::Enabler enabled(FLAGS_threads); @@ -32,6 +32,7 @@ #include "SkThreadUtils.h" #include "Test.h" #include "Timer.h" +#include "ios_utils.h" #include "picture_utils.h" #include "sk_tool_utils.h" #include "SkScan.h" @@ -1284,6 +1285,9 @@ extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkFontStyle ) int dm_main(); int dm_main() { +#if defined(SK_BUILD_FOR_IOS) + cd_Documents(); +#endif setbuf(stdout, nullptr); setup_crash_handler(); diff --git a/tools/ios_utils.h b/tools/ios_utils.h new file mode 100644 index 0000000000..0287dc14ae --- /dev/null +++ b/tools/ios_utils.h @@ -0,0 +1,23 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef ios_util_DEFINED +#define ios_util_DEFINED + +#if defined(__cplusplus) +extern "C" { +#endif + + // cd into the current app's Documents/ directory. + // (This is the only directory we can easily read and write.) + void cd_Documents(); + +#if defined(__cplusplus) +} +#endif + +#endif//ios_util_DEFINED diff --git a/tools/ios_utils.m b/tools/ios_utils.m new file mode 100644 index 0000000000..b88ab5bfe8 --- /dev/null +++ b/tools/ios_utils.m @@ -0,0 +1,19 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#import <Foundation/Foundation.h> +#include "ios_utils.h" +#include <unistd.h> + +void cd_Documents() { + @autoreleasepool { + NSURL* dir = [[[NSFileManager defaultManager] + URLsForDirectory:NSDocumentDirectory + inDomains:NSUserDomainMask] lastObject]; + chdir([dir.path UTF8String]); + } +} |