Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: canvas debug information not showing #2691

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SamuelScheit
Copy link
Contributor

@SamuelScheit SamuelScheit commented Oct 13, 2024

I've tried to measure the rendering performance of the <Canvas /> component and enabled the debug option by setting debug to true:

export default function App() {
	const paint = Skia.Paint();
	paint.setColor(Skia.Color("rgb(255,0,0)"));

	return (
		<Canvas mode="continuous" style={{ flex: 1, margin: 50, borderWidth: 1 }} debug={true}>
			{new Array(100).fill(0).map((_, i) => (
				<Rect key={i} x={i * 10} y={i * 10 + 200} width={100} height={100} paint={paint} />
			))}
		</Canvas>
	);

and in early versions this worked and displayed the render time and average fps, however not anymore in the latest version 1.4.2. (I unfortunately don't know when this bug got introduced)

Before

Android iOS

auto font = SkFont();
font.setSize(14);
auto paint = SkPaint();
paint.setColor(SkColors::kRed);
canvas->drawSimpleText(debugString.c_str(), debugString.size(),
SkTextEncoding::kUTF8, 8, 18, font, paint);

To find the issue I've called measureText in RNSkDomView.cpp and found out that it returned 0.
This means the text won't be rendered, probably because no valid font was registered/found.
I've fixed this issue by getting the system font manager and initializing the font in the constructor:

auto style = SkFontStyle::Normal();
auto fontMgr = _platformContext->createFontMgr();
auto _typeface = fontMgr->matchFamilyStyle("Arial", style);
_font = SkFont(_typeface, 14);

and just reuse the _font when rendering the debug overlay:

canvas->drawSimpleText(debugString.c_str(), debugString.size(), SkTextEncoding::kUTF8, 8, 18, _font, paint);

After

Android iOS

@wcandillon
Copy link
Contributor

Hello Samuel,

Thank you for this PR. I'm a bit torn about this. This is not a feature that will be available in the future. We also suspect that the current information in the debug prop might be somewhat erroneous. As this debug into be useful to you?

@SamuelScheit
Copy link
Contributor Author

SamuelScheit commented Oct 17, 2024

Yes, it's very useful.
I'm currently implementing a custom skia list renderer and I need a way to measure the performance and fps.
Especially to see frame drops when scrolling and rerendering.
If FPS is erroneous an alternative would be to display the amount of dropped frames

@wcandillon
Copy link
Contributor

we have reasons to believe that information might not be correct on Android, if you are building your own renderer, wouldn't be better to measure/display debug info on your side? But I think we will merge this change nonetheless 👍 Thank you for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants