@shopify/react-native-skia 0.1.184 → 0.1.186
Sign up to get free protection for your applications and to get access to all the features.
- package/android/build.gradle +2 -1
- package/android/cpp/jni/JniPlatformContext.cpp +92 -3
- package/android/cpp/jni/include/JniPlatformContext.h +4 -0
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +8 -0
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +17 -1
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +180 -0
- package/cpp/api/JsiSkFont.h +1 -1
- package/cpp/api/JsiSkHostObjects.h +1 -1
- package/cpp/api/JsiSkImage.h +8 -1
- package/cpp/api/JsiSkImageFactory.h +29 -0
- package/cpp/api/JsiSkPaint.h +7 -7
- package/cpp/api/JsiSkPathFactory.h +1 -1
- package/cpp/api/JsiSkPicture.h +2 -2
- package/cpp/api/JsiSkRuntimeEffect.h +3 -3
- package/cpp/api/JsiSkSVG.h +12 -2
- package/cpp/api/JsiSkShader.h +1 -1
- package/cpp/api/JsiSkSurface.h +3 -3
- package/cpp/api/JsiSkSurfaceFactory.h +1 -1
- package/cpp/api/JsiSkTypeface.h +1 -1
- package/cpp/rnskia/RNSkAnimation.h +3 -3
- package/cpp/rnskia/RNSkDomView.h +9 -9
- package/cpp/rnskia/RNSkInfoParameter.h +2 -2
- package/cpp/rnskia/RNSkJsView.h +8 -8
- package/cpp/rnskia/RNSkJsiViewApi.h +5 -5
- package/cpp/rnskia/RNSkPictureView.h +8 -8
- package/cpp/rnskia/RNSkPlatformContext.h +32 -3
- package/cpp/rnskia/RNSkValueApi.h +5 -5
- package/cpp/rnskia/RNSkView.h +10 -8
- package/cpp/rnskia/dom/base/ConcatablePaint.h +6 -6
- package/cpp/rnskia/dom/base/Declaration.h +1 -1
- package/cpp/rnskia/dom/base/DeclarationContext.h +7 -7
- package/cpp/rnskia/dom/base/DrawingContext.h +3 -3
- package/cpp/rnskia/dom/base/NodePropsContainer.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +8 -7
- package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +9 -6
- package/cpp/rnskia/dom/nodes/JsiImageNode.h +5 -2
- package/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +9 -9
- package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiPathNode.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiPointsNode.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +7 -3
- package/cpp/rnskia/dom/nodes/JsiTextNode.h +5 -4
- package/cpp/rnskia/dom/nodes/JsiTextPathNode.h +3 -1
- package/cpp/rnskia/dom/props/BlendModeProp.h +1 -1
- package/cpp/rnskia/dom/props/CircleProp.h +1 -1
- package/cpp/rnskia/dom/props/ClipProp.h +1 -1
- package/cpp/rnskia/dom/props/FontProp.h +15 -10
- package/cpp/rnskia/dom/props/ImageProps.h +30 -16
- package/cpp/rnskia/dom/props/PaintProps.h +1 -1
- package/cpp/rnskia/dom/props/PathProp.h +1 -1
- package/cpp/rnskia/dom/props/PointProp.h +1 -1
- package/cpp/rnskia/dom/props/PointsProp.h +1 -1
- package/cpp/rnskia/dom/props/RRectProp.h +2 -2
- package/cpp/rnskia/dom/props/RadiusProp.h +1 -1
- package/cpp/rnskia/dom/props/RectProp.h +1 -1
- package/cpp/rnskia/dom/props/StrokeProps.h +1 -1
- package/cpp/rnskia/dom/props/SvgProp.h +18 -12
- package/cpp/rnskia/dom/props/TextBlobProp.h +60 -57
- package/cpp/rnskia/dom/props/TileModeProp.h +1 -1
- package/cpp/rnskia/dom/props/UniformsProp.h +1 -1
- package/cpp/rnskia/dom/props/VertexModeProp.h +1 -1
- package/cpp/rnskia/dom/props/VerticesProps.h +1 -1
- package/cpp/rnskia/values/RNSkClockValue.h +2 -2
- package/cpp/rnskia/values/RNSkComputedValue.h +1 -1
- package/cpp/rnskia/values/RNSkReadonlyValue.h +3 -3
- package/cpp/rnskia/values/RNSkValue.h +4 -4
- package/cpp/utils/RNSkMeasureTime.h +1 -1
- package/cpp/utils/RNSkTimingInfo.h +1 -1
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +16 -13
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +8 -0
- package/ios/RNSkia-iOS/SkiaManager.mm +20 -1
- package/ios/RNSkia-iOS/ViewScreenshotService.h +21 -0
- package/ios/RNSkia-iOS/ViewScreenshotService.mm +79 -0
- package/lib/commonjs/dom/nodes/drawings/ImageNode.js +22 -1
- package/lib/commonjs/dom/nodes/drawings/ImageNode.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/ImageSVG.js +5 -0
- package/lib/commonjs/dom/nodes/drawings/ImageSVG.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/Text.d.ts +2 -2
- package/lib/commonjs/dom/nodes/drawings/Text.js +13 -2
- package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/Shaders.js +5 -0
- package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/commonjs/dom/types/Drawings.d.ts +5 -5
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/dom/types/Shaders.d.ts +1 -1
- package/lib/commonjs/dom/types/Shaders.js.map +1 -1
- package/lib/commonjs/mock/index.js +2 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/core/Image.d.ts +14 -2
- package/lib/commonjs/skia/core/Image.js +37 -1
- package/lib/commonjs/skia/core/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Image/Image.d.ts +6 -0
- package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +7 -0
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/SVG/SVG.d.ts +4 -1
- package/lib/commonjs/skia/types/SVG/SVG.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -0
- package/lib/commonjs/skia/web/JsiSkImage.js +4 -0
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +7 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/dom/nodes/drawings/ImageNode.js +22 -1
- package/lib/module/dom/nodes/drawings/ImageNode.js.map +1 -1
- package/lib/module/dom/nodes/drawings/ImageSVG.js +5 -0
- package/lib/module/dom/nodes/drawings/ImageSVG.js.map +1 -1
- package/lib/module/dom/nodes/drawings/Text.d.ts +2 -2
- package/lib/module/dom/nodes/drawings/Text.js +13 -2
- package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
- package/lib/module/dom/nodes/paint/Shaders.js +5 -0
- package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/module/dom/types/Drawings.d.ts +5 -5
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/dom/types/Shaders.d.ts +1 -1
- package/lib/module/dom/types/Shaders.js.map +1 -1
- package/lib/module/mock/index.js +2 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/core/Image.d.ts +14 -2
- package/lib/module/skia/core/Image.js +32 -0
- package/lib/module/skia/core/Image.js.map +1 -1
- package/lib/module/skia/types/Image/Image.d.ts +6 -0
- package/lib/module/skia/types/Image/Image.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +7 -0
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/SVG/SVG.d.ts +4 -1
- package/lib/module/skia/types/SVG/SVG.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.d.ts +1 -0
- package/lib/module/skia/web/JsiSkImage.js +4 -0
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -1
- package/lib/module/skia/web/JsiSkImageFactory.js +7 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/typescript/src/dom/nodes/drawings/Text.d.ts +2 -2
- package/lib/typescript/src/dom/types/Drawings.d.ts +5 -5
- package/lib/typescript/src/dom/types/Shaders.d.ts +1 -1
- package/lib/typescript/src/skia/core/Image.d.ts +14 -2
- package/lib/typescript/src/skia/types/Image/Image.d.ts +6 -0
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +7 -0
- package/lib/typescript/src/skia/types/SVG/SVG.d.ts +4 -1
- package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -1
- package/package.json +2 -2
- package/scripts/install-npm.js +3 -2
- package/src/dom/nodes/drawings/ImageNode.ts +9 -1
- package/src/dom/nodes/drawings/ImageSVG.ts +3 -0
- package/src/dom/nodes/drawings/Text.ts +13 -3
- package/src/dom/nodes/paint/Shaders.ts +4 -0
- package/src/dom/types/Drawings.ts +5 -5
- package/src/dom/types/Shaders.ts +1 -1
- package/src/mock/index.ts +1 -0
- package/src/skia/core/Image.ts +43 -1
- package/src/skia/types/Image/Image.ts +7 -0
- package/src/skia/types/Image/ImageFactory.ts +8 -0
- package/src/skia/types/SVG/SVG.ts +4 -1
- package/src/skia/web/JsiSkImage.ts +7 -0
- package/src/skia/web/JsiSkImageFactory.ts +8 -1
package/android/build.gradle
CHANGED
@@ -8,7 +8,51 @@
|
|
8
8
|
#include "SkRefCnt.h"
|
9
9
|
#include "SkStream.h"
|
10
10
|
#include "SkTypes.h"
|
11
|
-
|
11
|
+
|
12
|
+
#include <android/bitmap.h>
|
13
|
+
|
14
|
+
#pragma clang diagnostic push
|
15
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
16
|
+
|
17
|
+
#include "SkBitmap.h"
|
18
|
+
#include "SkPixmap.h"
|
19
|
+
|
20
|
+
#pragma clang diagnostic pop
|
21
|
+
|
22
|
+
static SkAlphaType alpha_type(int32_t flags) {
|
23
|
+
switch ((flags >> ANDROID_BITMAP_FLAGS_ALPHA_SHIFT) &
|
24
|
+
ANDROID_BITMAP_FLAGS_ALPHA_MASK) {
|
25
|
+
case ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE:
|
26
|
+
return kOpaque_SkAlphaType;
|
27
|
+
case ANDROID_BITMAP_FLAGS_ALPHA_PREMUL:
|
28
|
+
return kPremul_SkAlphaType;
|
29
|
+
case ANDROID_BITMAP_FLAGS_ALPHA_UNPREMUL:
|
30
|
+
return kUnpremul_SkAlphaType;
|
31
|
+
default:
|
32
|
+
break;
|
33
|
+
}
|
34
|
+
|
35
|
+
return kUnknown_SkAlphaType;
|
36
|
+
}
|
37
|
+
|
38
|
+
static SkColorType color_type(int32_t format) {
|
39
|
+
switch (format) {
|
40
|
+
case ANDROID_BITMAP_FORMAT_RGBA_8888:
|
41
|
+
return kRGBA_8888_SkColorType;
|
42
|
+
case ANDROID_BITMAP_FORMAT_RGB_565:
|
43
|
+
return kRGB_565_SkColorType;
|
44
|
+
case ANDROID_BITMAP_FORMAT_RGBA_4444:
|
45
|
+
return kARGB_4444_SkColorType;
|
46
|
+
case ANDROID_BITMAP_FORMAT_RGBA_F16:
|
47
|
+
return kRGBA_F16_SkColorType;
|
48
|
+
case ANDROID_BITMAP_FORMAT_A_8:
|
49
|
+
return kAlpha_8_SkColorType;
|
50
|
+
default:
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
|
54
|
+
return kUnknown_SkColorType;
|
55
|
+
}
|
12
56
|
|
13
57
|
namespace RNSkia {
|
14
58
|
|
@@ -31,6 +75,41 @@ TSelf JniPlatformContext::initHybrid(jni::alias_ref<jhybridobject> jThis,
|
|
31
75
|
return makeCxxInstance(jThis, pixelDensity);
|
32
76
|
}
|
33
77
|
|
78
|
+
sk_sp<SkImage> JniPlatformContext::takeScreenshotFromViewTag(size_t tag) {
|
79
|
+
// Call the java method for creating a view screenshot as a bitmap:
|
80
|
+
auto env = jni::Environment::current();
|
81
|
+
static auto method = javaPart_->getClass()->getMethod<jobject(int)>(
|
82
|
+
"takeScreenshotFromViewTag");
|
83
|
+
|
84
|
+
auto bitmap = method(javaPart_.get(), tag).release();
|
85
|
+
|
86
|
+
// Let's convert to a native bitmap and get some info about the bitmap
|
87
|
+
AndroidBitmapInfo bmi;
|
88
|
+
AndroidBitmap_getInfo(env, bitmap, &bmi);
|
89
|
+
|
90
|
+
// Convert android bitmap info to a Skia bitmap info
|
91
|
+
auto colorType = color_type(bmi.format);
|
92
|
+
auto alphaType = alpha_type(bmi.flags);
|
93
|
+
|
94
|
+
auto skInfo = SkImageInfo::Make(SkISize::Make(bmi.width, bmi.height),
|
95
|
+
colorType, alphaType);
|
96
|
+
|
97
|
+
// Lock pixels
|
98
|
+
void *pixels;
|
99
|
+
AndroidBitmap_lockPixels(env, bitmap, &pixels);
|
100
|
+
|
101
|
+
// Create pixmap from pixels and make a copy of it so that
|
102
|
+
// the SkImage owns its own pixels
|
103
|
+
SkPixmap pm(skInfo, pixels, bmi.stride);
|
104
|
+
auto skImage = SkImage::MakeRasterCopy(pm);
|
105
|
+
|
106
|
+
// Unlock pixels
|
107
|
+
AndroidBitmap_unlockPixels(env, bitmap);
|
108
|
+
|
109
|
+
// Return our newly created SkImage!
|
110
|
+
return skImage;
|
111
|
+
}
|
112
|
+
|
34
113
|
void JniPlatformContext::startDrawLoop() {
|
35
114
|
jni::ThreadScope ts;
|
36
115
|
// Start drawing loop
|
@@ -52,7 +131,19 @@ void JniPlatformContext::notifyDrawLoopExternal() {
|
|
52
131
|
_onNotifyDrawLoop();
|
53
132
|
}
|
54
133
|
|
134
|
+
void JniPlatformContext::runTaskOnMainThread(std::function<void()> task) {
|
135
|
+
_taskMutex->lock();
|
136
|
+
_taskCallbacks.push(task);
|
137
|
+
_taskMutex->unlock();
|
138
|
+
|
139
|
+
// Notify Java that task is ready
|
140
|
+
static auto method = javaPart_->getClass()->getMethod<void(void)>(
|
141
|
+
"notifyTaskReadyOnMainThread");
|
142
|
+
method(javaPart_.get());
|
143
|
+
}
|
144
|
+
|
55
145
|
void JniPlatformContext::notifyTaskReadyExternal() {
|
146
|
+
jni::ThreadScope ts;
|
56
147
|
_taskMutex->lock();
|
57
148
|
auto task = _taskCallbacks.front();
|
58
149
|
if (task != nullptr) {
|
@@ -67,8 +158,6 @@ void JniPlatformContext::notifyTaskReadyExternal() {
|
|
67
158
|
void JniPlatformContext::performStreamOperation(
|
68
159
|
const std::string &sourceUri,
|
69
160
|
const std::function<void(std::unique_ptr<SkStreamAsset>)> &op) {
|
70
|
-
auto measure = RNSkMeasureTime("JniPlatformContext::performStreamOperation");
|
71
|
-
|
72
161
|
static auto method = javaPart_->getClass()->getMethod<jbyteArray(jstring)>(
|
73
162
|
"getJniStreamFromSource");
|
74
163
|
|
@@ -44,8 +44,12 @@ public:
|
|
44
44
|
|
45
45
|
void notifyTaskReadyExternal();
|
46
46
|
|
47
|
+
void runTaskOnMainThread(std::function<void()> task);
|
48
|
+
|
47
49
|
float getPixelDensity() { return _pixelDensity; }
|
48
50
|
|
51
|
+
sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag);
|
52
|
+
|
49
53
|
void setOnNotifyDrawLoop(const std::function<void(void)> &callback) {
|
50
54
|
_onNotifyDrawLoop = callback;
|
51
55
|
}
|
@@ -41,6 +41,14 @@ public:
|
|
41
41
|
return MakeOffscreenGLSurface(width, height);
|
42
42
|
}
|
43
43
|
|
44
|
+
void runOnMainThread(std::function<void()> task) override {
|
45
|
+
_jniPlatformContext->runTaskOnMainThread(task);
|
46
|
+
}
|
47
|
+
|
48
|
+
sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag) override {
|
49
|
+
return _jniPlatformContext->takeScreenshotFromViewTag(tag);
|
50
|
+
}
|
51
|
+
|
44
52
|
void startDrawLoop() override { _jniPlatformContext->startDrawLoop(); }
|
45
53
|
|
46
54
|
void stopDrawLoop() override { _jniPlatformContext->stopDrawLoop(); }
|
@@ -1,6 +1,7 @@
|
|
1
1
|
package com.shopify.reactnative.skia;
|
2
2
|
|
3
3
|
import android.app.Application;
|
4
|
+
import android.graphics.Bitmap;
|
4
5
|
import android.os.Handler;
|
5
6
|
import android.os.Looper;
|
6
7
|
import android.util.Log;
|
@@ -53,7 +54,7 @@ public class PlatformContext {
|
|
53
54
|
Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() {
|
54
55
|
@Override
|
55
56
|
public void doFrame(long frameTimeNanos) {
|
56
|
-
if(_isPaused) {
|
57
|
+
if (_isPaused) {
|
57
58
|
return;
|
58
59
|
}
|
59
60
|
notifyDrawLoop();
|
@@ -65,6 +66,21 @@ public class PlatformContext {
|
|
65
66
|
Choreographer.getInstance().postFrameCallback(frameCallback);
|
66
67
|
}
|
67
68
|
|
69
|
+
@DoNotStrip
|
70
|
+
public void notifyTaskReadyOnMainThread() {
|
71
|
+
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
72
|
+
@Override
|
73
|
+
public void run() {
|
74
|
+
notifyTaskReady();
|
75
|
+
}
|
76
|
+
});
|
77
|
+
}
|
78
|
+
|
79
|
+
@DoNotStrip
|
80
|
+
Object takeScreenshotFromViewTag(int tag) {
|
81
|
+
return ViewScreenshotService.makeViewScreenshotFromTag(mContext, tag);
|
82
|
+
}
|
83
|
+
|
68
84
|
@DoNotStrip
|
69
85
|
public void raise(final String message) {
|
70
86
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
@@ -0,0 +1,180 @@
|
|
1
|
+
package com.shopify.reactnative.skia;
|
2
|
+
|
3
|
+
import static android.view.View.VISIBLE;
|
4
|
+
|
5
|
+
import android.graphics.Bitmap;
|
6
|
+
import android.graphics.Canvas;
|
7
|
+
import android.graphics.Matrix;
|
8
|
+
import android.graphics.Paint;
|
9
|
+
import android.os.Build;
|
10
|
+
import android.os.Handler;
|
11
|
+
import android.os.Looper;
|
12
|
+
import android.util.Log;
|
13
|
+
import android.view.PixelCopy;
|
14
|
+
import android.view.SurfaceView;
|
15
|
+
import android.view.TextureView;
|
16
|
+
import android.view.View;
|
17
|
+
import android.view.ViewGroup;
|
18
|
+
|
19
|
+
import androidx.annotation.NonNull;
|
20
|
+
|
21
|
+
import com.facebook.react.bridge.ReactContext;
|
22
|
+
import com.facebook.react.uimanager.UIManagerModule;
|
23
|
+
|
24
|
+
import java.util.ArrayList;
|
25
|
+
import java.util.Collections;
|
26
|
+
import java.util.LinkedList;
|
27
|
+
import java.util.List;
|
28
|
+
import java.util.concurrent.CountDownLatch;
|
29
|
+
import java.util.concurrent.TimeUnit;
|
30
|
+
|
31
|
+
|
32
|
+
public class ViewScreenshotService {
|
33
|
+
private static final long SURFACE_VIEW_READ_PIXELS_TIMEOUT = 5;
|
34
|
+
private static final String TAG = "SkiaScreenshot";
|
35
|
+
|
36
|
+
public static Bitmap makeViewScreenshotFromTag(ReactContext context, int tag) {
|
37
|
+
UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
|
38
|
+
View view = uiManager.resolveView(tag);
|
39
|
+
if (view == null) {
|
40
|
+
throw new RuntimeException("Could not resolve view from view tag " + tag);
|
41
|
+
}
|
42
|
+
|
43
|
+
// Measure and get size of view
|
44
|
+
int width = view.getWidth();
|
45
|
+
int height = view.getHeight();
|
46
|
+
|
47
|
+
if (width <= 0 || height <= 0) {
|
48
|
+
return null;
|
49
|
+
}
|
50
|
+
|
51
|
+
// The following code is taken from react-native-view-shot to be able to handle and
|
52
|
+
// correctly render all kinds of views, also including TextureViews and SurfaceViews
|
53
|
+
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
54
|
+
|
55
|
+
final Paint paint = new Paint();
|
56
|
+
paint.setAntiAlias(true);
|
57
|
+
paint.setFilterBitmap(true);
|
58
|
+
paint.setDither(true);
|
59
|
+
|
60
|
+
// Render the main view and its children
|
61
|
+
final Canvas c = new Canvas(bitmap);
|
62
|
+
view.draw(c);
|
63
|
+
|
64
|
+
// Enumerate children
|
65
|
+
final List<View> childrenList = getAllChildren(view);
|
66
|
+
|
67
|
+
for (final View child : childrenList) {
|
68
|
+
// skip any child that we don't know how to process
|
69
|
+
if (child instanceof TextureView) {
|
70
|
+
// skip all invisible to user child views
|
71
|
+
if (child.getVisibility() != VISIBLE) continue;
|
72
|
+
|
73
|
+
final TextureView tvChild = (TextureView) child;
|
74
|
+
tvChild.setOpaque(false); // <-- switch off background fill
|
75
|
+
|
76
|
+
// TextureView should use bitmaps with matching size,
|
77
|
+
// otherwise content of the TextureView will be scaled to provided bitmap dimensions
|
78
|
+
final Bitmap childBitmapBuffer = tvChild.getBitmap(Bitmap.createBitmap(child.getWidth(), child.getHeight(), Bitmap.Config.ARGB_8888));
|
79
|
+
|
80
|
+
final int countCanvasSave = c.save();
|
81
|
+
applyTransformations(c, view, child);
|
82
|
+
|
83
|
+
// due to re-use of bitmaps for screenshot, we can get bitmap that is bigger in size than requested
|
84
|
+
c.drawBitmap(childBitmapBuffer, 0, 0, paint);
|
85
|
+
|
86
|
+
c.restoreToCount(countCanvasSave);
|
87
|
+
} else if (child instanceof SurfaceView) {
|
88
|
+
final SurfaceView svChild = (SurfaceView)child;
|
89
|
+
final CountDownLatch latch = new CountDownLatch(1);
|
90
|
+
|
91
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
92
|
+
final Bitmap childBitmapBuffer = Bitmap.createBitmap(child.getWidth(), child.getHeight(), Bitmap.Config.ARGB_8888);
|
93
|
+
try {
|
94
|
+
PixelCopy.request(svChild, childBitmapBuffer, new PixelCopy.OnPixelCopyFinishedListener() {
|
95
|
+
@Override
|
96
|
+
public void onPixelCopyFinished(int copyResult) {
|
97
|
+
final int countCanvasSave = c.save();
|
98
|
+
applyTransformations(c, view, child);
|
99
|
+
c.drawBitmap(childBitmapBuffer, 0, 0, paint);
|
100
|
+
c.restoreToCount(countCanvasSave);
|
101
|
+
latch.countDown();
|
102
|
+
}
|
103
|
+
}, new Handler(Looper.getMainLooper()));
|
104
|
+
latch.await(SURFACE_VIEW_READ_PIXELS_TIMEOUT, TimeUnit.SECONDS);
|
105
|
+
} catch (Exception e) {
|
106
|
+
Log.e(TAG, "Cannot PixelCopy for " + svChild, e);
|
107
|
+
}
|
108
|
+
} else {
|
109
|
+
Bitmap cache = svChild.getDrawingCache();
|
110
|
+
if (cache != null) {
|
111
|
+
c.drawBitmap(svChild.getDrawingCache(), 0, 0, paint);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
return bitmap;
|
118
|
+
}
|
119
|
+
|
120
|
+
private static List<View> getAllChildren(@NonNull final View v) {
|
121
|
+
if (!(v instanceof ViewGroup)) {
|
122
|
+
final ArrayList<View> viewArrayList = new ArrayList<>();
|
123
|
+
viewArrayList.add(v);
|
124
|
+
|
125
|
+
return viewArrayList;
|
126
|
+
}
|
127
|
+
|
128
|
+
final ArrayList<View> result = new ArrayList<>();
|
129
|
+
|
130
|
+
ViewGroup viewGroup = (ViewGroup) v;
|
131
|
+
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
132
|
+
View child = viewGroup.getChildAt(i);
|
133
|
+
|
134
|
+
//Do not add any parents, just add child elements
|
135
|
+
result.addAll(getAllChildren(child));
|
136
|
+
}
|
137
|
+
|
138
|
+
return result;
|
139
|
+
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Concat all the transformation matrix's from parent to child.
|
143
|
+
*/
|
144
|
+
@NonNull
|
145
|
+
@SuppressWarnings("UnusedReturnValue")
|
146
|
+
private static Matrix applyTransformations(final Canvas c, @NonNull final View root, @NonNull final View child) {
|
147
|
+
final Matrix transform = new Matrix();
|
148
|
+
final LinkedList<View> ms = new LinkedList<>();
|
149
|
+
|
150
|
+
// find all parents of the child view
|
151
|
+
View iterator = child;
|
152
|
+
do {
|
153
|
+
ms.add(iterator);
|
154
|
+
|
155
|
+
iterator = (View) iterator.getParent();
|
156
|
+
} while (iterator != root);
|
157
|
+
|
158
|
+
// apply transformations from parent --> child order
|
159
|
+
Collections.reverse(ms);
|
160
|
+
|
161
|
+
for (final View v : ms) {
|
162
|
+
c.save();
|
163
|
+
|
164
|
+
// apply each view transformations, so each child will be affected by them
|
165
|
+
final float dx = v.getLeft() + ((v != child) ? v.getPaddingLeft() : 0) + v.getTranslationX();
|
166
|
+
final float dy = v.getTop() + ((v != child) ? v.getPaddingTop() : 0) + v.getTranslationY();
|
167
|
+
c.translate(dx, dy);
|
168
|
+
c.rotate(v.getRotation(), v.getPivotX(), v.getPivotY());
|
169
|
+
c.scale(v.getScaleX(), v.getScaleY());
|
170
|
+
|
171
|
+
// compute the matrix just for any future use
|
172
|
+
transform.postTranslate(dx, dy);
|
173
|
+
transform.postRotate(v.getRotation(), v.getPivotX(), v.getPivotY());
|
174
|
+
transform.postScale(v.getScaleX(), v.getScaleY());
|
175
|
+
}
|
176
|
+
|
177
|
+
return transform;
|
178
|
+
}
|
179
|
+
|
180
|
+
}
|
package/cpp/api/JsiSkFont.h
CHANGED
package/cpp/api/JsiSkImage.h
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
#include <string>
|
5
5
|
#include <utility>
|
6
6
|
|
7
|
+
#include "JsiSkHostObjects.h"
|
7
8
|
#include "JsiSkMatrix.h"
|
8
9
|
#include "JsiSkShader.h"
|
9
|
-
#include <JsiSkHostObjects.h>
|
10
10
|
|
11
11
|
#pragma clang diagnostic push
|
12
12
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -104,6 +104,12 @@ public:
|
|
104
104
|
return jsi::String::createFromAscii(runtime, buffer);
|
105
105
|
}
|
106
106
|
|
107
|
+
JSI_HOST_FUNCTION(makeNonTextureImage) {
|
108
|
+
auto image = getObject()->makeNonTextureImage();
|
109
|
+
return jsi::Object::createFromHostObject(
|
110
|
+
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
111
|
+
}
|
112
|
+
|
107
113
|
JSI_HOST_FUNCTION(dispose) {
|
108
114
|
setObject(nullptr);
|
109
115
|
return jsi::Value::undefined();
|
@@ -115,6 +121,7 @@ public:
|
|
115
121
|
JSI_EXPORT_FUNC(JsiSkImage, makeShaderCubic),
|
116
122
|
JSI_EXPORT_FUNC(JsiSkImage, encodeToBytes),
|
117
123
|
JSI_EXPORT_FUNC(JsiSkImage, encodeToBase64),
|
124
|
+
JSI_EXPORT_FUNC(JsiSkImage, makeNonTextureImage),
|
118
125
|
JSI_EXPORT_FUNC(JsiSkImage, dispose))
|
119
126
|
|
120
127
|
JsiSkImage(std::shared_ptr<RNSkPlatformContext> context,
|
@@ -38,7 +38,36 @@ public:
|
|
38
38
|
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
39
39
|
}
|
40
40
|
|
41
|
+
JSI_HOST_FUNCTION(MakeImageFromViewTag) {
|
42
|
+
auto viewTag = arguments[0].asNumber();
|
43
|
+
auto context = getContext();
|
44
|
+
return react::createPromiseAsJSIValue(
|
45
|
+
runtime,
|
46
|
+
[context = std::move(context),
|
47
|
+
viewTag](jsi::Runtime &runtime,
|
48
|
+
std::shared_ptr<react::Promise> promise) -> void {
|
49
|
+
// Create a stream operation - this will be run on the main thread
|
50
|
+
context->makeViewScreenshot(
|
51
|
+
viewTag, [&runtime, context = std::move(context),
|
52
|
+
promise = std::move(promise)](sk_sp<SkImage> image) {
|
53
|
+
context->runOnJavascriptThread([&runtime,
|
54
|
+
context = std::move(context),
|
55
|
+
promise = std::move(promise),
|
56
|
+
result = std::move(image)]() {
|
57
|
+
if (result == nullptr) {
|
58
|
+
promise->reject("Failed to create image from view tag");
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
promise->resolve(jsi::Object::createFromHostObject(
|
62
|
+
runtime, std::make_shared<JsiSkImage>(
|
63
|
+
std::move(context), std::move(result))));
|
64
|
+
});
|
65
|
+
});
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
41
69
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImageFromEncoded),
|
70
|
+
JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImageFromViewTag),
|
42
71
|
JSI_EXPORT_FUNC(JsiSkImageFactory, MakeImage), )
|
43
72
|
|
44
73
|
explicit JsiSkImageFactory(std::shared_ptr<RNSkPlatformContext> context)
|
package/cpp/api/JsiSkPaint.h
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
#include <jsi/jsi.h>
|
7
7
|
|
8
|
-
#include
|
9
|
-
#include
|
10
|
-
#include
|
11
|
-
#include
|
12
|
-
#include
|
13
|
-
#include
|
14
|
-
#include
|
8
|
+
#include "JsiSkColor.h"
|
9
|
+
#include "JsiSkColorFilter.h"
|
10
|
+
#include "JsiSkHostObjects.h"
|
11
|
+
#include "JsiSkImageFilter.h"
|
12
|
+
#include "JsiSkMaskFilter.h"
|
13
|
+
#include "JsiSkPathEffect.h"
|
14
|
+
#include "JsiSkShader.h"
|
15
15
|
|
16
16
|
#pragma clang diagnostic push
|
17
17
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
package/cpp/api/JsiSkPicture.h
CHANGED
package/cpp/api/JsiSkSVG.h
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
#include <jsi/jsi.h>
|
7
7
|
|
8
|
-
#include
|
8
|
+
#include "JsiSkHostObjects.h"
|
9
9
|
|
10
10
|
#pragma clang diagnostic push
|
11
11
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
@@ -28,6 +28,14 @@ public:
|
|
28
28
|
return jsi::String::createFromUtf8(runtime, "SVG");
|
29
29
|
}
|
30
30
|
|
31
|
+
JSI_HOST_FUNCTION(width) {
|
32
|
+
return static_cast<double>(getObject()->containerSize().width());
|
33
|
+
}
|
34
|
+
|
35
|
+
JSI_HOST_FUNCTION(height) {
|
36
|
+
return static_cast<double>(getObject()->containerSize().height());
|
37
|
+
}
|
38
|
+
|
31
39
|
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSVG, __typename__))
|
32
40
|
|
33
41
|
JSI_HOST_FUNCTION(dispose) {
|
@@ -35,7 +43,9 @@ public:
|
|
35
43
|
return jsi::Value::undefined();
|
36
44
|
}
|
37
45
|
|
38
|
-
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSVG,
|
46
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSVG, width),
|
47
|
+
JSI_EXPORT_FUNC(JsiSkSVG, height),
|
48
|
+
JSI_EXPORT_FUNC(JsiSkSVG, dispose))
|
39
49
|
|
40
50
|
/**
|
41
51
|
Returns the underlying object from a host object of this type
|
package/cpp/api/JsiSkShader.h
CHANGED
package/cpp/api/JsiSkSurface.h
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
|
8
8
|
#include "JsiSkHostObjects.h"
|
9
9
|
|
10
|
-
#include
|
11
|
-
#include
|
12
|
-
#include
|
10
|
+
#include "JsiSkCanvas.h"
|
11
|
+
#include "JsiSkImage.h"
|
12
|
+
#include "JsiSkSurfaceFactory.h"
|
13
13
|
|
14
14
|
#pragma clang diagnostic push
|
15
15
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
package/cpp/api/JsiSkTypeface.h
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
#include <array>
|
4
4
|
#include <memory>
|
5
5
|
|
6
|
-
#include
|
7
|
-
#include
|
8
|
-
#include
|
6
|
+
#include "JsiHostObject.h"
|
7
|
+
#include "RNSkClockValue.h"
|
8
|
+
#include "RNSkPlatformContext.h"
|
9
9
|
#include <jsi/jsi.h>
|
10
10
|
|
11
11
|
namespace RNSkia {
|
package/cpp/rnskia/RNSkDomView.h
CHANGED
@@ -9,21 +9,21 @@
|
|
9
9
|
|
10
10
|
#include <jsi/jsi.h>
|
11
11
|
|
12
|
-
#include
|
13
|
-
#include
|
12
|
+
#include "JsiValueWrapper.h"
|
13
|
+
#include "RNSkView.h"
|
14
14
|
|
15
15
|
#include "JsiDomRenderNode.h"
|
16
|
-
#include
|
17
|
-
#include
|
18
|
-
#include
|
19
|
-
#include
|
16
|
+
#include "RNSkInfoParameter.h"
|
17
|
+
#include "RNSkLog.h"
|
18
|
+
#include "RNSkPlatformContext.h"
|
19
|
+
#include "RNSkTimingInfo.h"
|
20
20
|
|
21
21
|
#pragma clang diagnostic push
|
22
22
|
#pragma clang diagnostic ignored "-Wdocumentation"
|
23
23
|
|
24
|
-
#include
|
25
|
-
#include
|
26
|
-
#include
|
24
|
+
#include "SkBBHFactory.h"
|
25
|
+
#include "SkCanvas.h"
|
26
|
+
#include "SkPictureRecorder.h"
|
27
27
|
|
28
28
|
#pragma clang diagnostic pop
|
29
29
|
|