()
| 35 | } |
| 36 | |
| 37 | @SneakyThrows |
| 38 | public static synchronized void load() { |
| 39 | if (_loaded) return; |
| 40 | |
| 41 | // If `skija.loadFromLibraryPath` is set to true, use System.loadLibrary to load the native library |
| 42 | String loadFromLibraryPath = System.getProperty("skija.loadFromLibraryPath"); |
| 43 | if ("true".equals(loadFromLibraryPath)) { |
| 44 | _loadFromLibraryPath(); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | // If `skija.library.path` is set, load the native library from this path |
| 49 | String libraryPath = System.getProperty("skija.library.path"); |
| 50 | if (libraryPath != null) { |
| 51 | _loadFromDir(new File(libraryPath)); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | boolean failedLoadFromLibraryPath = false; |
| 56 | |
| 57 | // If skija is bundled in JRE, try to load the bundled native library |
| 58 | // User can disable this behavior by set `skija.loadFromLibraryPath` to false |
| 59 | if (loadFromLibraryPath == null) { |
| 60 | URL theClassFile = Library.class.getResource("Library.class"); |
| 61 | if (theClassFile != null && "jrt".equals(theClassFile.getProtocol())) { |
| 62 | try { |
| 63 | _loadFromLibraryPath(); |
| 64 | return; |
| 65 | } catch (UnsatisfiedLinkError e) { |
| 66 | failedLoadFromLibraryPath = true; |
| 67 | Log.warn("Please use skija platform jmod when using jlink"); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | String osName = OperatingSystem.CURRENT.name().toLowerCase(Locale.ROOT); |
| 73 | String archName = Architecture.CURRENT.name().toLowerCase(Locale.ROOT); |
| 74 | String moduleName = "io.github.humbleui.skija." + osName + "." + archName; |
| 75 | String basePath = moduleName.replace('.', '/') + "/"; |
| 76 | |
| 77 | try (ResourceFinder finder = new ResourceFinder(moduleName)) { |
| 78 | URL versionFile = finder.findResource(basePath + "skija.version"); |
| 79 | |
| 80 | // The platform library is bundled in the JRE, but the skija shared is not bundled. |
| 81 | // Platforms without official support can provide native libraries in this way. |
| 82 | if (loadFromLibraryPath == null |
| 83 | && !failedLoadFromLibraryPath |
| 84 | && versionFile != null |
| 85 | && "jrt".equals(versionFile.getProtocol())) { |
| 86 | try { |
| 87 | _loadFromLibraryPath(); |
| 88 | return; |
| 89 | } catch (UnsatisfiedLinkError e) { |
| 90 | failedLoadFromLibraryPath = true; |
| 91 | Log.warn("Please use skija platform jmod when using jlink"); |
| 92 | } |
| 93 | } |
| 94 |
no test coverage detected