Skip to content

Commit 44c2fd2

Browse files
committed
Fix substancial performance bottleneck fon ParagraphBuilderFactory
1 parent 177f908 commit 44c2fd2

File tree

3 files changed

+54
-32
lines changed

3 files changed

+54
-32
lines changed

package/cpp/api/JsiSkApi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "JsiSkMaskFilterFactory.h"
2525
#include "JsiSkMatrix.h"
2626
#include "JsiSkPaint.h"
27+
#include "JsiSkParagraphBuilderFactory.h"
2728
#include "JsiSkParagraphBuilder.h"
2829
#include "JsiSkPath.h"
2930
#include "JsiSkPathEffect.h"

package/cpp/api/JsiSkParagraphBuilder.h

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class JsiSkParagraphBuilder : public JsiSkHostObject {
113113
sk_sp<SkFontMgr> fontManager)
114114
: JsiSkHostObject(std::move(context)) {
115115
_fontCollection = sk_make_sp<para::FontCollection>();
116-
_fontCollection->setDefaultFontManager(getContext()->createFontMgr());
116+
_fontCollection->setDefaultFontManager(JsiSkFontMgrFactory::getFontMgr(context));
117117
if (fontManager != nullptr) {
118118
_fontCollection->setAssetFontManager(fontManager);
119119
}
@@ -125,35 +125,4 @@ class JsiSkParagraphBuilder : public JsiSkHostObject {
125125
std::unique_ptr<para::ParagraphBuilder> _builder;
126126
sk_sp<para::FontCollection> _fontCollection;
127127
};
128-
129-
/**
130-
Implementation of the ParagraphBuilderFactory for making ParagraphBuilder JSI
131-
object
132-
*/
133-
class JsiSkParagraphBuilderFactory : public JsiSkHostObject {
134-
public:
135-
JSI_HOST_FUNCTION(Make) {
136-
// Get paragraph style from params
137-
auto paragraphStyle =
138-
count > 0 ? JsiSkParagraphStyle::fromValue(runtime, arguments[0])
139-
: para::ParagraphStyle();
140-
141-
// get font manager
142-
auto fontMgr =
143-
count > 1 ? JsiSkTypefaceFontProvider::fromValue(runtime, arguments[1])
144-
: nullptr;
145-
146-
// Create the paragraph builder
147-
return jsi::Object::createFromHostObject(
148-
runtime, std::make_shared<JsiSkParagraphBuilder>(
149-
getContext(), paragraphStyle, fontMgr));
150-
}
151-
152-
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkParagraphBuilderFactory, Make))
153-
154-
explicit JsiSkParagraphBuilderFactory(
155-
std::shared_ptr<RNSkPlatformContext> context)
156-
: JsiSkHostObject(std::move(context)) {}
157-
};
158-
159128
} // namespace RNSkia
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#pragma once
2+
3+
#include <jsi/jsi.h>
4+
5+
#include <JsiSkParagraphBuilder.h>
6+
#include <JsiSkParagraphStyle.h>
7+
8+
#pragma clang diagnostic push
9+
#pragma clang diagnostic ignored "-Wdocumentation"
10+
11+
#include "ParagraphBuilder.h"
12+
13+
#pragma clang diagnostic pop
14+
15+
16+
namespace RNSkia {
17+
18+
namespace jsi = facebook::jsi;
19+
20+
namespace para = skia::textlayout;
21+
22+
/**
23+
Implementation of the ParagraphBuilderFactory for making ParagraphBuilder JSI
24+
object
25+
*/
26+
class JsiSkParagraphBuilderFactory : public JsiSkHostObject {
27+
public:
28+
JSI_HOST_FUNCTION(Make) {
29+
// Get paragraph style from params
30+
auto paragraphStyle =
31+
count > 0 ? JsiSkParagraphStyle::fromValue(runtime, arguments[0])
32+
: para::ParagraphStyle();
33+
34+
// get font manager
35+
auto fontMgr =
36+
count > 1 ? JsiSkTypefaceFontProvider::fromValue(runtime, arguments[1])
37+
: nullptr;
38+
39+
// Create the paragraph builder
40+
return jsi::Object::createFromHostObject(
41+
runtime, std::make_shared<JsiSkParagraphBuilder>(
42+
getContext(), paragraphStyle, fontMgr));
43+
}
44+
45+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkParagraphBuilderFactory, Make))
46+
47+
explicit JsiSkParagraphBuilderFactory(
48+
std::shared_ptr<RNSkPlatformContext> context)
49+
: JsiSkHostObject(std::move(context)) {}
50+
};
51+
52+
} // namespace RNSkia

0 commit comments

Comments
 (0)