MCPcopy Create free account
hub / github.com/Snapchat/Valdi / ResourceResolver

Class ResourceResolver

valdi/src/java/com/snap/valdi/bundle/ResourceResolver.kt:28–174  ·  view source on GitHub ↗

* Loads resources on behalf of Valdi C++. It is currently used only to resolve images. * Methods in this class are used by native code. Don't remove them! */

Source from the content-addressed store, hash-verified

26 * Methods in this class are used by native code. Don't remove them!
27 */
28class ResourceResolver(private val context: Context,
29 private val coordinateResolver: CoordinateResolver,
30 private val postprocessor: ValdiImageLoaderPostprocessor,
31 private val logger: Logger,
32 private val customModuleProvider: IValdiCustomModuleProvider?) {
33
34 @Keep
35 fun getCustomModuleData(path: String, marshallerHandle: Long): ByteArray? {
36 if (customModuleProvider == null) {
37 return null
38 }
39
40 return BridgeCallUtils.handleCall(marshallerHandle) {
41 customModuleProvider.getCustomModuleData(path)
42 }
43 }
44
45 @Keep
46 fun resolveResource(moduleName: String, resourcePath: String): Any? {
47 val currentTime = System.nanoTime()
48 val resourceId = ValdiImage.getImageIdentifier(context, moduleName, resourcePath)
49 if (resourceId == 0) {
50 return null
51 }
52
53 val imageIdentifierTime = System.nanoTime()
54
55 val totalTimeMs = ((imageIdentifierTime - currentTime) / 1000).toDouble() / 1000.0
56
57 logger.info("Loaded image $moduleName/$resourcePath (took ${totalTimeMs}ms)")
58 return LocalAssetLoader.valdiAssetUrlFromResID(resourceId).toString()
59 }
60
61 @Keep
62 fun requestPayloadFromURL(imageLoader: Any, url: String, marshallerHandle: Long): Any? {
63 return BridgeCallUtils.handleCall(marshallerHandle) {
64 (imageLoader as ValdiAssetLoader).getRequestPayload(Uri.parse(url))
65 }
66 }
67
68 /**
69 Called by C++ to perform a load from an image loader
70 */
71 @Keep
72 fun loadAsset(imageLoader: Any,
73 requestPayload: Any,
74 preferredWidth: Int,
75 preferredHeight: Int,
76 colorMatrixFilter: Any?,
77 blurRadiusFilter: Float,
78 outputType: Int,
79 completionHandle: Long): Any? {
80
81 val loadOutputType = when(outputType) {
82 ValdiAssetLoadOutputType.BITMAP.value -> ValdiAssetLoadOutputType.BITMAP
83 ValdiAssetLoadOutputType.RAW_CONTENT.value -> ValdiAssetLoadOutputType.RAW_CONTENT
84 ValdiAssetLoadOutputType.VIDEO.value -> ValdiAssetLoadOutputType.VIDEO
85 else -> ValdiAssetLoadOutputType.VIDEO

Callers 2

ValdiRuntimeManagerClass · 0.85
doCreateRuntimeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected