Skip to content

Commit 2c72be6

Browse files
authored
Merge pull request #1 from callstack/feat/native-build
[wip] base setup for basis universal
2 parents 66e4b34 + cd2f572 commit 2c72be6

File tree

97 files changed

+53664
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+53664
-23
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ DerivedData
2828
*.ipa
2929
*.xcuserstate
3030
project.xcworkspace
31+
cpp/basisu
32+
example/ios/.xcode.env
33+
example/ios/*/content.xcworkspacedata
3134

3235
# Android/IJ
3336
#
@@ -39,6 +42,7 @@ project.xcworkspace
3942
.settings
4043
local.properties
4144
android.iml
45+
bazel-*
4246

4347
# Cocoapods
4448
#

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "externals/basis_universal"]
2+
path = externals/basis_universal
3+
url = https://github.com/BinomialLLC/basis_universal.git

BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@rules_apple//apple:apple.bzl", "apple_static_xcframework")
2+
3+
apple_static_xcframework(
4+
name = "rn_basis_universal",
5+
deps = ["@basis_universal"],
6+
ios = {
7+
"simulator": ["x86_64", "arm64"],
8+
"device": ["arm64"]
9+
},
10+
minimum_os_versions = {
11+
"ios": "11.0"
12+
}
13+
)

MODULE.bazel.lock

+1,256
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpp/react-native-basis-universal.cpp

+81-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,91 @@
11
#include "react-native-basis-universal.h"
22

3+
using namespace basist;
4+
using namespace basisu;
5+
36
namespace facebook::react {
47

8+
class BasisEncoder : public jsi::NativeState {
9+
public:
10+
basis_compressor_params m_params;
11+
};
12+
13+
std::shared_ptr<BasisEncoder> tryGetBasisEncoder(jsi::Runtime& rt, jsi::Object& basisEncoderObj) {
14+
if (!basisEncoderObj.hasNativeState(rt)) {
15+
return nullptr;
16+
}
17+
18+
auto encoder = std::dynamic_pointer_cast<BasisEncoder>(basisEncoderObj.getNativeState(rt));
19+
return encoder;
20+
}
21+
522
ReactNativeBasisUniversal::ReactNativeBasisUniversal(std::shared_ptr<CallInvoker> jsInvoker)
623
: NativeBasisUniversalCxxSpecJSI(jsInvoker), _callInvoker(jsInvoker) {}
724

8-
double ReactNativeBasisUniversal::multiply(jsi::Runtime &rt, double a, double b) {
9-
return a * b;
25+
void ReactNativeBasisUniversal::initializeBasis(jsi::Runtime &rt)
26+
{
27+
if (basis_initialized_flag) {
28+
return;
29+
}
30+
31+
#if BASISU_SUPPORT_ENCODING
32+
basisu_encoder_init();
33+
#endif
34+
35+
basisu_transcoder_init();
36+
37+
basis_initialized_flag = true;
38+
}
39+
40+
jsi::Object ReactNativeBasisUniversal::createBasisHandle(jsi::Runtime &rt) {
41+
jsi::Object basisObject{rt};
42+
basisObject.setNativeState(rt, std::make_shared<BasisEncoder>());
43+
return basisObject;
44+
}
45+
46+
void ReactNativeBasisUniversal::setDebug(jsi::Runtime &rt, jsi::Object handle, bool flag) {
47+
auto encoder = tryGetBasisEncoder(rt, handle);
48+
encoder->m_params.m_debug = flag;
49+
}
50+
51+
void ReactNativeBasisUniversal::setCreateKTX2File(jsi::Runtime &rt, jsi::Object handle, bool flag) {
52+
auto encoder = tryGetBasisEncoder(rt, handle);
53+
encoder->m_params.m_create_ktx2_file = flag;
54+
}
55+
56+
void ReactNativeBasisUniversal::setComputeStats(jsi::Runtime &rt, jsi::Object handle, bool flag) {
57+
auto encoder = tryGetBasisEncoder(rt, handle);
58+
encoder->m_params.m_compute_stats = flag;
59+
}
60+
61+
void ReactNativeBasisUniversal::setUASTC(jsi::Runtime &rt, jsi::Object handle, bool flag) {
62+
auto encoder = tryGetBasisEncoder(rt, handle);
63+
encoder->m_params.m_uastc = flag;
64+
}
65+
66+
void ReactNativeBasisUniversal::setKTX2UASTCSupercompression(jsi::Runtime &rt, jsi::Object handle, bool flag) {
67+
auto encoder = tryGetBasisEncoder(rt, handle);
68+
encoder->m_params.m_ktx2_uastc_supercompression = flag ? basist::KTX2_SS_ZSTANDARD : basist::KTX2_SS_NONE;;
69+
}
70+
71+
void ReactNativeBasisUniversal::setQualityLevel(jsi::Runtime &rt, jsi::Object handle, int qualityLevel) {
72+
73+
}
74+
75+
void ReactNativeBasisUniversal::setSliceSourceImage(jsi::Runtime &rt, jsi::Object handle, int sliceIndex, jsi::Object imageArray, int width, int height, bool isPng) {
76+
if (imageArray.isArrayBuffer(rt)) {
77+
throw jsi::JSError(rt, "Image Array needs to be ArrayBuffer");
78+
}
79+
auto arrayBuffer = imageArray.getArrayBuffer(rt);
80+
auto data = arrayBuffer.data(rt);
81+
}
82+
83+
void ReactNativeBasisUniversal::setPackUASTCFlags(jsi::Runtime &rt, jsi::Object handle, int flags) {
84+
85+
}
86+
87+
void ReactNativeBasisUniversal::setCompressionLevel(jsi::Runtime &rt, jsi::Object handle, int level) {
88+
1089
}
1190

1291
}

cpp/react-native-basis-universal.h

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
#include <ReactCommon/TurboModule.h>
44
#include <RNBasisUniversalSpecJSI.h>
5+
#include "rn_basis_universal/transcoder/basisu.h"
6+
#include "rn_basis_universal/transcoder/basisu_transcoder.h"
7+
8+
#include "rn_basis_universal/encoder/basisu_comp.h"
9+
10+
#ifndef BASISU_SUPPORT_ENCODING
11+
#define BASISU_SUPPORT_ENCODING 1
12+
#endif
513

614
namespace facebook::react {
715

@@ -10,13 +18,24 @@ using namespace facebook;
1018
class ReactNativeBasisUniversal : public NativeBasisUniversalCxxSpecJSI {
1119
public:
1220
explicit ReactNativeBasisUniversal(std::shared_ptr<CallInvoker> jsInvoker);
13-
14-
public:
15-
double multiply(jsi::Runtime &rt, double a, double b) override;
1621
constexpr static auto kModuleName = "BasisUniversal";
1722

23+
void initializeBasis(jsi::Runtime &rt) override;
24+
jsi::Object createBasisHandle(jsi::Runtime &rt) override;
25+
void setCreateKTX2File(jsi::Runtime &rt, jsi::Object handle, bool flag) override;
26+
void setDebug(jsi::Runtime &rt, jsi::Object handle, bool flag) override;
27+
void setComputeStats(jsi::Runtime &rt, jsi::Object handle, bool flag) override;
28+
void setUASTC(jsi::Runtime &rt, jsi::Object handle, bool flag) override;
29+
void setCompressionLevel(jsi::Runtime &rt, jsi::Object handle, int level) override;
30+
void setKTX2UASTCSupercompression(jsi::Runtime &rt, jsi::Object handle, bool flag) override;
31+
void setSliceSourceImage(jsi::Runtime &rt, jsi::Object handle, int sliceIndex, jsi::Object imageArray, int width, int height, bool isPng) override;
32+
void setPackUASTCFlags(jsi::Runtime &rt, jsi::Object handle, int flags) override;
33+
void setQualityLevel(jsi::Runtime &rt, jsi::Object handle, int qualityLevel) override;
34+
35+
1836
private:
1937
std::shared_ptr<CallInvoker> _callInvoker;
38+
bool basis_initialized_flag;
2039
};
2140

2241
} // namespace facebook::react

example/ios/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ SPEC CHECKSUMS:
17411741
React-logger: d79b704bf215af194f5213a6b7deec50ba8e6a9b
17421742
React-Mapbuffer: b982d5bba94a8bc073bda48f0d27c9b28417fae3
17431743
React-microtasksnativemodule: 8fa285fed833a04a754bf575f8ded65fc240b88d
1744-
react-native-basis-universal: 2e1160a6dfcde0aa6cd51503480e0ec982667f9e
1744+
react-native-basis-universal: 5a9b05e51cc23161be95911a7c442d0b204d189f
17451745
React-nativeconfig: 8c83d992b9cc7d75b5abe262069eaeea4349f794
17461746
React-NativeModulesApple: b8465afc883f5bf3fe8bac3767e394d581a5f123
17471747
React-perflogger: 59e1a3182dca2cee7b9f1f7aab204018d46d1914

example/src/App.tsx

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1-
import { StyleSheet, View, Text } from 'react-native';
2-
import { multiply } from '@callstack/react-native-basis-universal';
3-
4-
const result = multiply(3, 7);
1+
import React from 'react';
2+
import { StyleSheet, View, Button } from 'react-native';
3+
import {
4+
initializeBasis,
5+
BasisEncoder,
6+
} from '@callstack/react-native-basis-universal';
57

68
export default function App() {
79
return (
810
<View style={styles.container}>
9-
<Text>Result: {result}</Text>
11+
<Button title="Initialize Basis" onPress={initializeBasis} />
12+
<Button
13+
title="Encode"
14+
onPress={() => {
15+
const basisEncoder = new BasisEncoder();
16+
basisEncoder.setCreateKTX2File(true);
17+
basisEncoder.setDebug(true);
18+
basisEncoder.setComputeStats(true);
19+
// basisEncoder.setSliceSourceImage(0, new Uint8Array(), 0, 0, false);
20+
// basisEncoder.setUASTC(true);
21+
// basisEncoder.setKTX2UASTCSupercompression(true);
22+
// basisEncoder.setPackUASTCFlags(0);
23+
// basisEncoder.setQualityLevel(0);
24+
// basisEncoder.setCompressionLevel(0);
25+
// basisEncoder.setPerceptual(true);
26+
// basisEncoder.setMipSRGB(true);
27+
// basisEncoder.setKTX2SRGBTransferFunc(true);
28+
// basisEncoder.setNormalMap();
29+
}}
30+
/>
1031
</View>
1132
);
1233
}

ios/BasisUniversal.mm

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#import "BasisUniversal.h"
2-
#include "react-native-basis-universal.h"
32
#include <ReactCommon/CxxTurboModuleUtils.h>
4-
#include <RNBasisUniversalSpecJSI.h>
53

64
@implementation BasisUniversal
75

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AvailableLibraries</key>
6+
<array>
7+
<dict>
8+
<key>LibraryIdentifier</key>
9+
<string>ios-arm64</string>
10+
<key>LibraryPath</key>
11+
<string>rn_basis_universal.framework</string>
12+
<key>SupportedArchitectures</key>
13+
<array>
14+
<string>arm64</string>
15+
</array>
16+
<key>SupportedPlatform</key>
17+
<string>ios</string>
18+
</dict>
19+
<dict>
20+
<key>LibraryIdentifier</key>
21+
<string>ios-arm64_x86_64-simulator</string>
22+
<key>LibraryPath</key>
23+
<string>rn_basis_universal.framework</string>
24+
<key>SupportedArchitectures</key>
25+
<array>
26+
<string>arm64</string>
27+
<string>x86_64</string>
28+
</array>
29+
<key>SupportedPlatform</key>
30+
<string>ios</string>
31+
<key>SupportedPlatformVariant</key>
32+
<string>simulator</string>
33+
</dict>
34+
</array>
35+
<key>CFBundlePackageType</key>
36+
<string>XFWK</string>
37+
<key>XCFrameworkFormatVersion</key>
38+
<string>1.0</string>
39+
</dict>
40+
</plist>

0 commit comments

Comments
 (0)