diff --git a/packages/skia/android/cpp/jni/JniPlatformContext.cpp b/packages/skia/android/cpp/jni/JniPlatformContext.cpp index 2ef8a9767a..ecc0a37894 100644 --- a/packages/skia/android/cpp/jni/JniPlatformContext.cpp +++ b/packages/skia/android/cpp/jni/JniPlatformContext.cpp @@ -63,6 +63,10 @@ using TSelf = jni::local_ref; void JniPlatformContext::registerNatives() { registerHybrid({ makeNativeMethod("initHybrid", JniPlatformContext::initHybrid), + makeNativeMethod("getPixelDensity", + JniPlatformContext::getPixelDensity), + makeNativeMethod("setPixelDensity", + JniPlatformContext::setPixelDensity), }); } @@ -71,6 +75,14 @@ TSelf JniPlatformContext::initHybrid(jni::alias_ref jThis, return makeCxxInstance(jThis, pixelDensity); } +float JniPlatformContext::getPixelDensity() { + return _pixelDensity; +} + +void JniPlatformContext::setPixelDensity(float pixelDensity) { + _pixelDensity=pixelDensity; +} + jni::global_ref JniPlatformContext::createVideo(const std::string &url) { jni::Environment::ensureCurrentThreadIsAttached(); diff --git a/packages/skia/android/cpp/jni/include/JniPlatformContext.h b/packages/skia/android/cpp/jni/include/JniPlatformContext.h index 99a33e48b9..fc2bc3b24e 100644 --- a/packages/skia/android/cpp/jni/include/JniPlatformContext.h +++ b/packages/skia/android/cpp/jni/include/JniPlatformContext.h @@ -27,6 +27,9 @@ class JniPlatformContext : public jni::HybridClass { static void registerNatives(); + float getPixelDensity(); + void setPixelDensity(float pixelDensity); + void performStreamOperation( const std::string &sourceUri, const std::function)> &op); @@ -37,8 +40,6 @@ class JniPlatformContext : public jni::HybridClass { void runTaskOnMainThread(std::function task); - float getPixelDensity() { return _pixelDensity; } - sk_sp takeScreenshotFromViewTag(size_t tag); jni::global_ref createVideo(const std::string &url); diff --git a/packages/skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h b/packages/skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h index 90ac5498fe..610462eac4 100644 --- a/packages/skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +++ b/packages/skia/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h @@ -42,6 +42,10 @@ class RNSkAndroidPlatformContext : public RNSkPlatformContext { ~RNSkAndroidPlatformContext() {} + float getPixelDensity() override { + return _jniPlatformContext->getPixelDensity(); + } + void performStreamOperation( const std::string &sourceUri, const std::function)> &op) override { diff --git a/packages/skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java b/packages/skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java index 62fa75d6c5..64a6a677a1 100644 --- a/packages/skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +++ b/packages/skia/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java @@ -29,7 +29,9 @@ public class PlatformContext { public PlatformContext(ReactContext reactContext) { mContext = reactContext; - mHybridData = initHybrid(reactContext.getResources().getDisplayMetrics().density); + float density = mContext.getResources().getDisplayMetrics().density; + //Log.d(TAG, "density=" + Float.toString(density)); + mHybridData = initHybrid(density); } @DoNotStrip @@ -99,6 +101,15 @@ public byte[] getJniStreamFromSource(String sourceUri) throws IOException { return null; } + void onResume() { + _isPaused = false; + Log.i(TAG, "Resume"); + + float density = mContext.getResources().getDisplayMetrics().density; + //Log.d(TAG, "density=" + Float.toString(density)); + setPixelDensity(density); + } + @Override protected void finalize() throws Throwable { mHybridData.resetNative(); @@ -107,4 +118,6 @@ protected void finalize() throws Throwable { // Private c++ native methods private native HybridData initHybrid(float pixelDensity); + private native float getPixelDensity(); + private native void setPixelDensity(float pixelDensity); } \ No newline at end of file diff --git a/packages/skia/cpp/rnskia/RNSkPlatformContext.h b/packages/skia/cpp/rnskia/RNSkPlatformContext.h index 6f9c31f20c..f5479cf7f0 100644 --- a/packages/skia/cpp/rnskia/RNSkPlatformContext.h +++ b/packages/skia/cpp/rnskia/RNSkPlatformContext.h @@ -143,7 +143,7 @@ class RNSkPlatformContext { /** * @return Current scale factor for pixels */ - float getPixelDensity() { return _pixelDensity; } + virtual float getPixelDensity() { return _pixelDensity; } private: float _pixelDensity;