@shopify/react-native-skia 0.1.194 → 0.1.196
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +1 -0
- package/android/build.gradle +6 -11
- package/android/cpp/rnskia-android/RNSkAndroidView.h +4 -0
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +3 -2
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -1
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +35 -69
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +1 -12
- package/cpp/api/JsiSkDataFactory.h +4 -6
- package/cpp/api/JsiSkImageFactory.h +5 -4
- package/cpp/jsi/JsiPromises.cpp +39 -0
- package/cpp/jsi/JsiPromises.h +50 -0
- package/cpp/rnskia/RNSkDomView.cpp +3 -2
- package/cpp/rnskia/RNSkPictureView.h +8 -15
- package/cpp/rnskia/RNSkView.h +13 -2
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +1 -1
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +7 -5
- package/ios/RNSkia-iOS/SkiaUIView.mm +10 -0
- package/package.json +1 -1
- package/cpp/skia/include/core/SkEncodedImageFormat.h +0 -9
- package/cpp/skia/include/core/SkICC.h +0 -9
package/android/CMakeLists.txt
CHANGED
@@ -51,6 +51,7 @@ add_library(
|
|
51
51
|
"${PROJECT_SOURCE_DIR}/cpp/jsi/JsiValue.cpp"
|
52
52
|
"${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeLifecycleMonitor.cpp"
|
53
53
|
"${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeAwareCache.cpp"
|
54
|
+
"${PROJECT_SOURCE_DIR}/cpp/jsi/JsiPromises.cpp"
|
54
55
|
|
55
56
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkManager.cpp"
|
56
57
|
"${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkJsView.cpp"
|
package/android/build.gradle
CHANGED
@@ -137,6 +137,12 @@ android {
|
|
137
137
|
abortOnError false
|
138
138
|
}
|
139
139
|
|
140
|
+
publishing {
|
141
|
+
singleVariant("release") {
|
142
|
+
withSourcesJar()
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
140
146
|
externalNativeBuild {
|
141
147
|
cmake {
|
142
148
|
path file('CMakeLists.txt')
|
@@ -223,12 +229,6 @@ dependencies {
|
|
223
229
|
}
|
224
230
|
|
225
231
|
afterEvaluate { project ->
|
226
|
-
task androidSourcesJar(type: Jar) {
|
227
|
-
classifier = 'sources'
|
228
|
-
from android.sourceSets.main.java.srcDirs
|
229
|
-
include '**/*.java'
|
230
|
-
}
|
231
|
-
|
232
232
|
android.libraryVariants.all { variant ->
|
233
233
|
def name = variant.name.capitalize()
|
234
234
|
def javaCompileTask = variant.javaCompileProvider.get()
|
@@ -237,10 +237,6 @@ afterEvaluate { project ->
|
|
237
237
|
from javaCompileTask.destinationDir
|
238
238
|
}
|
239
239
|
}
|
240
|
-
|
241
|
-
artifacts {
|
242
|
-
archives androidSourcesJar
|
243
|
-
}
|
244
240
|
}
|
245
241
|
|
246
242
|
task extractAARHeaders {
|
@@ -278,7 +274,6 @@ if (ENABLE_PREFAB) {
|
|
278
274
|
into "${project.buildDir}/headers/rnskia/"
|
279
275
|
includeEmptyDirs = false
|
280
276
|
include "**/*.h"
|
281
|
-
duplicatesStrategy = 'include'
|
282
277
|
eachFile {
|
283
278
|
String path = it.path
|
284
279
|
|
@@ -42,6 +42,10 @@ public:
|
|
42
42
|
void surfaceAvailable(jobject surface, int width, int height) override {
|
43
43
|
std::static_pointer_cast<RNSkOpenGLCanvasProvider>(T::getCanvasProvider())
|
44
44
|
->surfaceAvailable(surface, width, height);
|
45
|
+
|
46
|
+
// Try to render directly when the surface has been set so that
|
47
|
+
// we don't have to wait until the draw loop returns.
|
48
|
+
RNSkView::renderImmediate();
|
45
49
|
}
|
46
50
|
|
47
51
|
void surfaceDestroyed() override {
|
@@ -23,11 +23,12 @@ float RNSkOpenGLCanvasProvider::getScaledWidth() { return _width; }
|
|
23
23
|
|
24
24
|
float RNSkOpenGLCanvasProvider::getScaledHeight() { return _height; }
|
25
25
|
|
26
|
-
|
26
|
+
bool RNSkOpenGLCanvasProvider::renderToCanvas(
|
27
27
|
const std::function<void(SkCanvas *)> &cb) {
|
28
28
|
if (_renderer != nullptr) {
|
29
|
-
_renderer->run(cb, _width, _height);
|
29
|
+
return _renderer->run(cb, _width, _height);
|
30
30
|
}
|
31
|
+
return false;
|
31
32
|
}
|
32
33
|
|
33
34
|
void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject surface, int width,
|
@@ -25,7 +25,7 @@ public:
|
|
25
25
|
|
26
26
|
float getScaledHeight() override;
|
27
27
|
|
28
|
-
|
28
|
+
bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override;
|
29
29
|
|
30
30
|
void surfaceAvailable(jobject surface, int width, int height);
|
31
31
|
|
@@ -4,6 +4,8 @@
|
|
4
4
|
#include <android/native_window.h>
|
5
5
|
#include <android/native_window_jni.h>
|
6
6
|
|
7
|
+
#define STENCIL_BUFFER_SIZE 8
|
8
|
+
|
7
9
|
namespace RNSkia {
|
8
10
|
/** Static members */
|
9
11
|
sk_sp<SkSurface> MakeOffscreenGLSurface(int width, int height) {
|
@@ -137,7 +139,7 @@ SkiaOpenGLRenderer::~SkiaOpenGLRenderer() {
|
|
137
139
|
_nativeWindow = nullptr;
|
138
140
|
}
|
139
141
|
|
140
|
-
|
142
|
+
bool SkiaOpenGLRenderer::run(const std::function<void(SkCanvas *)> &cb,
|
141
143
|
int width, int height) {
|
142
144
|
switch (_renderState) {
|
143
145
|
case RenderState::Initializing: {
|
@@ -148,31 +150,48 @@ void SkiaOpenGLRenderer::run(const std::function<void(SkCanvas *)> &cb,
|
|
148
150
|
case RenderState::Rendering: {
|
149
151
|
// Make sure to initialize the rendering pipeline
|
150
152
|
if (!ensureInitialised()) {
|
151
|
-
|
152
|
-
}
|
153
|
-
|
154
|
-
// Ensure we have the Skia surface to draw on. We need to
|
155
|
-
// pass width and height since the surface will be recreated
|
156
|
-
// when the view is resized.
|
157
|
-
if (!ensureSkiaSurface(width, height)) {
|
158
|
-
return;
|
153
|
+
return false;
|
159
154
|
}
|
160
155
|
|
161
156
|
if (cb != nullptr) {
|
162
|
-
//
|
163
|
-
|
157
|
+
// RNSkLogger::logToConsole("SKIARENDER - Render begin");
|
158
|
+
|
164
159
|
getThreadDrawingContext()->skContext->resetContext();
|
165
160
|
|
161
|
+
SkColorType colorType;
|
162
|
+
// setup surface for fbo0
|
163
|
+
GrGLFramebufferInfo fboInfo;
|
164
|
+
fboInfo.fFBOID = 0;
|
165
|
+
fboInfo.fFormat = 0x8058;
|
166
|
+
colorType = kN32_SkColorType;
|
167
|
+
|
168
|
+
GrBackendRenderTarget backendRT(width, height, 0, STENCIL_BUFFER_SIZE,
|
169
|
+
fboInfo);
|
170
|
+
|
171
|
+
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
172
|
+
|
173
|
+
sk_sp<SkSurface> renderTarget(SkSurface::MakeFromBackendRenderTarget(
|
174
|
+
getThreadDrawingContext()->skContext.get(), backendRT,
|
175
|
+
kBottomLeft_GrSurfaceOrigin, colorType, nullptr, &props));
|
176
|
+
|
177
|
+
auto canvas = renderTarget->getCanvas();
|
178
|
+
|
166
179
|
// Draw picture into surface
|
167
|
-
cb(
|
180
|
+
cb(canvas);
|
181
|
+
|
168
182
|
// Flush
|
169
|
-
|
183
|
+
canvas->flush();
|
170
184
|
|
171
185
|
if (!eglSwapBuffers(getThreadDrawingContext()->glDisplay, _glSurface)) {
|
172
186
|
RNSkLogger::logToConsole("eglSwapBuffers failed: %d\n", eglGetError());
|
187
|
+
return false;
|
173
188
|
}
|
189
|
+
|
190
|
+
// RNSkLogger::logToConsole("SKIARENDER - render done");
|
191
|
+
return true;
|
174
192
|
}
|
175
|
-
|
193
|
+
|
194
|
+
return false;
|
176
195
|
}
|
177
196
|
case RenderState::Finishing: {
|
178
197
|
_renderState = RenderState::Done;
|
@@ -184,14 +203,11 @@ void SkiaOpenGLRenderer::run(const std::function<void(SkCanvas *)> &cb,
|
|
184
203
|
_glSurface = EGL_NO_SURFACE;
|
185
204
|
}
|
186
205
|
|
187
|
-
|
188
|
-
_skSurface = nullptr;
|
189
|
-
|
190
|
-
break;
|
206
|
+
return true;
|
191
207
|
}
|
192
208
|
case RenderState::Done: {
|
193
209
|
// Do nothing. We're done.
|
194
|
-
|
210
|
+
return true;
|
195
211
|
}
|
196
212
|
}
|
197
213
|
}
|
@@ -326,54 +342,4 @@ bool SkiaOpenGLRenderer::initGLSurface() {
|
|
326
342
|
|
327
343
|
return true;
|
328
344
|
}
|
329
|
-
|
330
|
-
bool SkiaOpenGLRenderer::ensureSkiaSurface(int width, int height) {
|
331
|
-
if (getThreadDrawingContext()->skContext == nullptr) {
|
332
|
-
return false;
|
333
|
-
}
|
334
|
-
|
335
|
-
if (_skSurface == nullptr || !_skRenderTarget.isValid() ||
|
336
|
-
_prevWidth != width || _prevHeight != height) {
|
337
|
-
glViewport(0, 0, width, height);
|
338
|
-
|
339
|
-
_prevWidth = width;
|
340
|
-
_prevHeight = height;
|
341
|
-
|
342
|
-
GLint buffer;
|
343
|
-
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer);
|
344
|
-
|
345
|
-
GLint stencil;
|
346
|
-
glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
347
|
-
|
348
|
-
GLint samples;
|
349
|
-
glGetIntegerv(GL_SAMPLES, &samples);
|
350
|
-
|
351
|
-
auto maxSamples =
|
352
|
-
getThreadDrawingContext()->skContext->maxSurfaceSampleCountForColorType(
|
353
|
-
kRGBA_8888_SkColorType);
|
354
|
-
|
355
|
-
if (samples > maxSamples)
|
356
|
-
samples = maxSamples;
|
357
|
-
|
358
|
-
GrGLFramebufferInfo fbInfo;
|
359
|
-
fbInfo.fFBOID = buffer;
|
360
|
-
fbInfo.fFormat = 0x8058;
|
361
|
-
|
362
|
-
_skRenderTarget =
|
363
|
-
GrBackendRenderTarget(width, height, samples, stencil, fbInfo);
|
364
|
-
|
365
|
-
_skSurface = SkSurface::MakeFromBackendRenderTarget(
|
366
|
-
getThreadDrawingContext()->skContext.get(), _skRenderTarget,
|
367
|
-
kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, nullptr, nullptr);
|
368
|
-
|
369
|
-
if (!_skSurface) {
|
370
|
-
RNSkLogger::logToConsole(
|
371
|
-
"JniSkiaDrawView::setupSurface - skSurface could not be created!");
|
372
|
-
return false;
|
373
|
-
}
|
374
|
-
|
375
|
-
return true;
|
376
|
-
}
|
377
|
-
return true;
|
378
|
-
}
|
379
345
|
} // namespace RNSkia
|
@@ -60,7 +60,7 @@ public:
|
|
60
60
|
* @param width Width of surface to render if there is a picture
|
61
61
|
* @param height Height of surface to render if there is a picture
|
62
62
|
*/
|
63
|
-
|
63
|
+
bool run(const std::function<void(SkCanvas *)> &cb, int width, int height);
|
64
64
|
|
65
65
|
/**
|
66
66
|
* Sets the state to finishing. Next time the renderer will be called it
|
@@ -102,15 +102,6 @@ private:
|
|
102
102
|
*/
|
103
103
|
bool initGLSurface();
|
104
104
|
|
105
|
-
/**
|
106
|
-
* Ensures that we have a valid Skia surface to draw to. The surface will
|
107
|
-
* be recreated if the width/height change.
|
108
|
-
* @param width Width of the underlying view
|
109
|
-
* @param height Height of the underlying view
|
110
|
-
* @return True if initialization went well
|
111
|
-
*/
|
112
|
-
bool ensureSkiaSurface(int width, int height);
|
113
|
-
|
114
105
|
/**
|
115
106
|
* To be able to use static contexts (and avoid reloading the skia context for
|
116
107
|
* each new view, we track the OpenGL and Skia drawing context per thread.
|
@@ -121,8 +112,6 @@ private:
|
|
121
112
|
EGLSurface _glSurface = EGL_NO_SURFACE;
|
122
113
|
|
123
114
|
ANativeWindow *_nativeWindow = nullptr;
|
124
|
-
GrBackendRenderTarget _skRenderTarget;
|
125
|
-
sk_sp<SkSurface> _skSurface;
|
126
115
|
|
127
116
|
int _prevWidth = 0;
|
128
117
|
int _prevHeight = 0;
|
@@ -3,17 +3,15 @@
|
|
3
3
|
#include <memory>
|
4
4
|
#include <utility>
|
5
5
|
|
6
|
-
#include <ReactCommon/TurboModuleUtils.h>
|
7
6
|
#include <jsi/jsi.h>
|
8
7
|
|
9
|
-
#include "
|
10
|
-
|
8
|
+
#include "JsiPromises.h"
|
11
9
|
#include "JsiSkData.h"
|
10
|
+
#include "SkBase64.h"
|
12
11
|
|
13
12
|
namespace RNSkia {
|
14
13
|
|
15
14
|
namespace jsi = facebook::jsi;
|
16
|
-
namespace react = facebook::react;
|
17
15
|
|
18
16
|
class JsiSkDataFactory : public JsiSkHostObject {
|
19
17
|
public:
|
@@ -21,11 +19,11 @@ public:
|
|
21
19
|
auto jsiLocalUri = arguments[0].asString(runtime);
|
22
20
|
auto localUri = jsiLocalUri.utf8(runtime);
|
23
21
|
auto context = getContext();
|
24
|
-
return
|
22
|
+
return RNJsi::JsiPromises::createPromiseAsJSIValue(
|
25
23
|
runtime,
|
26
24
|
[context = std::move(context), localUri = std::move(localUri)](
|
27
25
|
jsi::Runtime &runtime,
|
28
|
-
std::shared_ptr<
|
26
|
+
std::shared_ptr<RNJsi::JsiPromises::Promise> promise) -> void {
|
29
27
|
// Create a stream operation - this will be run in a
|
30
28
|
// separate thread
|
31
29
|
context->performStreamOperation(
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
#include <jsi/jsi.h>
|
7
7
|
|
8
|
+
#include "JsiPromises.h"
|
8
9
|
#include "JsiSkData.h"
|
9
10
|
#include "JsiSkHostObjects.h"
|
10
11
|
#include "JsiSkImage.h"
|
@@ -41,11 +42,11 @@ public:
|
|
41
42
|
JSI_HOST_FUNCTION(MakeImageFromViewTag) {
|
42
43
|
auto viewTag = arguments[0].asNumber();
|
43
44
|
auto context = getContext();
|
44
|
-
return
|
45
|
+
return RNJsi::JsiPromises::createPromiseAsJSIValue(
|
45
46
|
runtime,
|
46
|
-
[context = std::move(context),
|
47
|
-
|
48
|
-
|
47
|
+
[context = std::move(context), viewTag](
|
48
|
+
jsi::Runtime &runtime,
|
49
|
+
std::shared_ptr<RNJsi::JsiPromises::Promise> promise) -> void {
|
49
50
|
// Create a stream operation - this will be run on the main thread
|
50
51
|
context->makeViewScreenshot(
|
51
52
|
viewTag, [&runtime, context = std::move(context),
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#include "JsiPromises.h"
|
2
|
+
|
3
|
+
namespace RNJsi {
|
4
|
+
|
5
|
+
JsiPromises::Promise::Promise(jsi::Runtime &rt, jsi::Function resolve,
|
6
|
+
jsi::Function reject)
|
7
|
+
: runtime_(rt), resolve_(std::move(resolve)), reject_(std::move(reject)) {}
|
8
|
+
|
9
|
+
void JsiPromises::Promise::resolve(const jsi::Value &result) {
|
10
|
+
resolve_.call(runtime_, result);
|
11
|
+
}
|
12
|
+
|
13
|
+
void JsiPromises::Promise::reject(const std::string &message) {
|
14
|
+
jsi::Object error(runtime_);
|
15
|
+
error.setProperty(runtime_, "message",
|
16
|
+
jsi::String::createFromUtf8(runtime_, message));
|
17
|
+
reject_.call(runtime_, error);
|
18
|
+
}
|
19
|
+
|
20
|
+
jsi::Value
|
21
|
+
JsiPromises::createPromiseAsJSIValue(jsi::Runtime &rt,
|
22
|
+
PromiseSetupFunctionType &&func) {
|
23
|
+
jsi::Function JSPromise = rt.global().getPropertyAsFunction(rt, "Promise");
|
24
|
+
jsi::Function fn = jsi::Function::createFromHostFunction(
|
25
|
+
rt, jsi::PropNameID::forAscii(rt, "fn"), 2,
|
26
|
+
[func = std::move(func)](jsi::Runtime &rt2, const jsi::Value &thisVal,
|
27
|
+
const jsi::Value *args, size_t count) {
|
28
|
+
jsi::Function resolve = args[0].getObject(rt2).getFunction(rt2);
|
29
|
+
jsi::Function reject = args[1].getObject(rt2).getFunction(rt2);
|
30
|
+
auto wrapper = std::make_shared<Promise>(rt2, std::move(resolve),
|
31
|
+
std::move(reject));
|
32
|
+
func(rt2, wrapper);
|
33
|
+
return jsi::Value::undefined();
|
34
|
+
});
|
35
|
+
|
36
|
+
return JSPromise.callAsConstructor(rt, fn);
|
37
|
+
}
|
38
|
+
|
39
|
+
} // namespace RNJsi
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <string>
|
5
|
+
#include <utility>
|
6
|
+
|
7
|
+
#include <jsi/jsi.h>
|
8
|
+
|
9
|
+
#include "SkBase64.h"
|
10
|
+
|
11
|
+
namespace RNJsi {
|
12
|
+
namespace jsi = facebook::jsi;
|
13
|
+
|
14
|
+
/**
|
15
|
+
These classes are taken from ReactCommon TurboModuleUtils. It is no longer (RN
|
16
|
+
0.72) possible to include and uses TurboModulesUtils without a lot of trouble
|
17
|
+
when use_frameworks are true in POD file. Instead we're now just including the
|
18
|
+
implementations ourselves.
|
19
|
+
*/
|
20
|
+
|
21
|
+
class LongLivedObject {
|
22
|
+
public:
|
23
|
+
void allowRelease();
|
24
|
+
|
25
|
+
protected:
|
26
|
+
LongLivedObject() = default;
|
27
|
+
virtual ~LongLivedObject() = default;
|
28
|
+
};
|
29
|
+
|
30
|
+
class JsiPromises {
|
31
|
+
public:
|
32
|
+
struct Promise : public LongLivedObject {
|
33
|
+
Promise(jsi::Runtime &rt, jsi::Function resolve, jsi::Function reject);
|
34
|
+
|
35
|
+
void resolve(const jsi::Value &result);
|
36
|
+
void reject(const std::string &error);
|
37
|
+
|
38
|
+
jsi::Runtime &runtime_;
|
39
|
+
jsi::Function resolve_;
|
40
|
+
jsi::Function reject_;
|
41
|
+
};
|
42
|
+
|
43
|
+
using PromiseSetupFunctionType =
|
44
|
+
std::function<void(jsi::Runtime &rt, std::shared_ptr<Promise>)>;
|
45
|
+
|
46
|
+
static jsi::Value createPromiseAsJSIValue(jsi::Runtime &rt,
|
47
|
+
PromiseSetupFunctionType &&func);
|
48
|
+
};
|
49
|
+
|
50
|
+
} // namespace RNJsi
|
@@ -36,15 +36,16 @@ bool RNSkDomRenderer::tryRender(
|
|
36
36
|
|
37
37
|
// We render on the main thread
|
38
38
|
if (_renderLock->try_lock()) {
|
39
|
+
bool result = false;
|
39
40
|
// If we have a Dom Node we can render directly on the main thread
|
40
41
|
if (_root != nullptr) {
|
41
|
-
canvasProvider->renderToCanvas(std::bind(
|
42
|
+
result = canvasProvider->renderToCanvas(std::bind(
|
42
43
|
&RNSkDomRenderer::renderCanvas, this, std::placeholders::_1,
|
43
44
|
canvasProvider->getScaledWidth(), canvasProvider->getScaledHeight()));
|
44
45
|
}
|
45
46
|
|
46
47
|
_renderLock->unlock();
|
47
|
-
return
|
48
|
+
return result;
|
48
49
|
} else {
|
49
50
|
return false;
|
50
51
|
}
|
@@ -44,8 +44,7 @@ public:
|
|
44
44
|
: RNSkRenderer(requestRedraw), _platformContext(context) {}
|
45
45
|
|
46
46
|
bool tryRender(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override {
|
47
|
-
performDraw(canvasProvider);
|
48
|
-
return true;
|
47
|
+
return performDraw(canvasProvider);
|
49
48
|
}
|
50
49
|
|
51
50
|
void
|
@@ -56,19 +55,14 @@ public:
|
|
56
55
|
void setPicture(std::shared_ptr<jsi::HostObject> picture) {
|
57
56
|
if (picture == nullptr) {
|
58
57
|
_picture = nullptr;
|
59
|
-
|
58
|
+
} else {
|
59
|
+
_picture = std::dynamic_pointer_cast<JsiSkPicture>(picture);
|
60
60
|
}
|
61
|
-
|
62
|
-
_picture = std::dynamic_pointer_cast<JsiSkPicture>(picture);
|
63
61
|
_requestRedraw();
|
64
62
|
}
|
65
63
|
|
66
64
|
private:
|
67
|
-
|
68
|
-
if (_picture == nullptr) {
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
|
65
|
+
bool performDraw(std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
|
72
66
|
canvasProvider->renderToCanvas([=](SkCanvas *canvas) {
|
73
67
|
// Make sure to scale correctly
|
74
68
|
auto pd = _platformContext->getPixelDensity();
|
@@ -76,10 +70,13 @@ private:
|
|
76
70
|
canvas->save();
|
77
71
|
canvas->scale(pd, pd);
|
78
72
|
|
79
|
-
|
73
|
+
if (_picture != nullptr) {
|
74
|
+
canvas->drawPicture(_picture->getObject());
|
75
|
+
}
|
80
76
|
|
81
77
|
canvas->restore();
|
82
78
|
});
|
79
|
+
return true;
|
83
80
|
}
|
84
81
|
|
85
82
|
std::shared_ptr<RNSkPlatformContext> _platformContext;
|
@@ -109,7 +106,6 @@ public:
|
|
109
106
|
// Clear picture
|
110
107
|
std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
|
111
108
|
->setPicture(nullptr);
|
112
|
-
requestRedraw();
|
113
109
|
continue;
|
114
110
|
} else if (prop.second.getType() !=
|
115
111
|
RNJsi::JsiWrapperValueType::HostObject) {
|
@@ -121,9 +117,6 @@ public:
|
|
121
117
|
// Save picture
|
122
118
|
std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
|
123
119
|
->setPicture(prop.second.getAsHostObject());
|
124
|
-
|
125
|
-
// Request redraw
|
126
|
-
requestRedraw();
|
127
120
|
}
|
128
121
|
}
|
129
122
|
}
|
package/cpp/rnskia/RNSkView.h
CHANGED
@@ -44,7 +44,7 @@ public:
|
|
44
44
|
/**
|
45
45
|
Render to a canvas
|
46
46
|
*/
|
47
|
-
virtual
|
47
|
+
virtual bool renderToCanvas(const std::function<void(SkCanvas *)> &) = 0;
|
48
48
|
|
49
49
|
protected:
|
50
50
|
std::function<void()> _requestRedraw;
|
@@ -123,8 +123,9 @@ public:
|
|
123
123
|
/**
|
124
124
|
Render to a canvas
|
125
125
|
*/
|
126
|
-
|
126
|
+
bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override {
|
127
127
|
cb(_surface->getCanvas());
|
128
|
+
return true;
|
128
129
|
};
|
129
130
|
|
130
131
|
private:
|
@@ -224,6 +225,15 @@ public:
|
|
224
225
|
*/
|
225
226
|
void requestRedraw() { _redrawRequestCounter++; }
|
226
227
|
|
228
|
+
/**
|
229
|
+
Renders immediate. Be carefull to not call this method from another thread
|
230
|
+
than the UI thread
|
231
|
+
*/
|
232
|
+
void renderImmediate() {
|
233
|
+
_renderer->renderImmediate(_canvasProvider);
|
234
|
+
_redrawRequestCounter = 0;
|
235
|
+
}
|
236
|
+
|
227
237
|
/**
|
228
238
|
Sets the native id of the view
|
229
239
|
*/
|
@@ -409,6 +419,7 @@ private:
|
|
409
419
|
|
410
420
|
size_t _drawingLoopId = 0;
|
411
421
|
std::atomic<int> _redrawRequestCounter = {1};
|
422
|
+
bool _initialDrawingDone = false;
|
412
423
|
};
|
413
424
|
|
414
425
|
} // namespace RNSkia
|
@@ -24,7 +24,7 @@ public:
|
|
24
24
|
float getScaledWidth() override;
|
25
25
|
float getScaledHeight() override;
|
26
26
|
|
27
|
-
|
27
|
+
bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override;
|
28
28
|
|
29
29
|
void setSize(int width, int height);
|
30
30
|
|
@@ -63,10 +63,10 @@ float RNSkMetalCanvasProvider::getScaledHeight() {
|
|
63
63
|
/**
|
64
64
|
Render to a canvas
|
65
65
|
*/
|
66
|
-
|
66
|
+
bool RNSkMetalCanvasProvider::renderToCanvas(
|
67
67
|
const std::function<void(SkCanvas *)> &cb) {
|
68
68
|
if (_width <= 0 || _height <= 0) {
|
69
|
-
return;
|
69
|
+
return false;
|
70
70
|
}
|
71
71
|
|
72
72
|
// Make sure to NOT render or try any render operations while we're in the
|
@@ -82,7 +82,7 @@ void RNSkMetalCanvasProvider::renderToCanvas(
|
|
82
82
|
_requestRedraw();
|
83
83
|
// and don't draw now since it might cause errors in the metal renderer if
|
84
84
|
// we try to render while in the background. (see above issue)
|
85
|
-
return;
|
85
|
+
return false;
|
86
86
|
}
|
87
87
|
}
|
88
88
|
|
@@ -113,7 +113,7 @@ void RNSkMetalCanvasProvider::renderToCanvas(
|
|
113
113
|
*/
|
114
114
|
id<CAMetalDrawable> currentDrawable = [_layer nextDrawable];
|
115
115
|
if (currentDrawable == nullptr) {
|
116
|
-
return;
|
116
|
+
return false;
|
117
117
|
}
|
118
118
|
|
119
119
|
GrMtlTextureInfo fbInfo;
|
@@ -129,7 +129,7 @@ void RNSkMetalCanvasProvider::renderToCanvas(
|
|
129
129
|
if (skSurface == nullptr || skSurface->getCanvas() == nullptr) {
|
130
130
|
RNSkia::RNSkLogger::logToConsole(
|
131
131
|
"Skia surface could not be created from parameters.");
|
132
|
-
return;
|
132
|
+
return false;
|
133
133
|
}
|
134
134
|
|
135
135
|
SkCanvas *canvas = skSurface->getCanvas();
|
@@ -142,6 +142,8 @@ void RNSkMetalCanvasProvider::renderToCanvas(
|
|
142
142
|
[commandBuffer presentDrawable:currentDrawable];
|
143
143
|
[commandBuffer commit];
|
144
144
|
}
|
145
|
+
|
146
|
+
return true;
|
145
147
|
};
|
146
148
|
|
147
149
|
void RNSkMetalCanvasProvider::setSize(int width, int height) {
|
@@ -93,6 +93,16 @@
|
|
93
93
|
assert(_impl == nullptr);
|
94
94
|
}
|
95
95
|
|
96
|
+
#pragma Render
|
97
|
+
|
98
|
+
- (void)drawRect:(CGRect)rect {
|
99
|
+
// We override drawRect to ensure we to direct rendering when the
|
100
|
+
// underlying OS view needs to render:
|
101
|
+
if (_impl != nullptr) {
|
102
|
+
_impl->getDrawView()->renderImmediate();
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
96
106
|
#pragma mark Layout
|
97
107
|
|
98
108
|
- (void)layoutSubviews {
|
package/package.json
CHANGED
@@ -1,9 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright 2023 Google LLC
|
3
|
-
*
|
4
|
-
* Use of this source code is governed by a BSD-style license that can be
|
5
|
-
* found in the LICENSE file.
|
6
|
-
*/
|
7
|
-
|
8
|
-
// TODO(kjlubick) remove this shim after clients have been moved to the new location
|
9
|
-
#include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: export
|
@@ -1,9 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright 2023 Google LLC
|
3
|
-
*
|
4
|
-
* Use of this source code is governed by a BSD-style license that can be
|
5
|
-
* found in the LICENSE file.
|
6
|
-
*/
|
7
|
-
|
8
|
-
// TODO(kjlubick) remove this shim after clients have been moved to the new location
|
9
|
-
#include "include/encode/SkICC.h" // IWYU pragma: export
|