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

feat: Draw onto a Skia Canvas in a Frame Processor #1345

Closed
wants to merge 91 commits into from

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Nov 17, 2022

"Write-back Frame Processors" aka "Skia Frame Processors" aka "Draw onto Frame" (#1376)

ezgif com-gif-maker-2

@@ -26,6 +26,7 @@ import { examplePlugin } from './frame-processors/ExamplePlugin';
import type { Routes } from './Routes';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { useIsFocused } from '@react-navigation/core';
import { SkCanvas, useDrawCallback } from '@shopify/react-native-skia';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <1371> reported by reviewdog 🐶
This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.

@@ -26,6 +26,7 @@
import type { Routes } from './Routes';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { useIsFocused } from '@react-navigation/core';
import { SkCanvas, useDrawCallback } from '@shopify/react-native-skia';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <6133> reported by reviewdog 🐶
'useDrawCallback' is declared but its value is never read.

@@ -197,10 +198,10 @@
console.log('re-rendering camera page without active camera');
}

const frameProcessor = useFrameProcessor((frame) => {
const frameProcessor = useFrameProcessor((frame, canvas: SkCanvas) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <2345> reported by reviewdog 🐶
Argument of type '(frame: any, canvas: SkCanvas) => void' is not assignable to parameter of type 'FrameProcessor'.

@@ -197,10 +198,10 @@
console.log('re-rendering camera page without active camera');
}

const frameProcessor = useFrameProcessor((frame) => {
const frameProcessor = useFrameProcessor((frame, canvas: SkCanvas) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <7006> reported by reviewdog 🐶
Parameter 'frame' implicitly has an 'any' type.

@@ -197,10 +198,10 @@
console.log('re-rendering camera page without active camera');
}

const frameProcessor = useFrameProcessor((frame) => {
const frameProcessor = useFrameProcessor((frame, canvas: SkCanvas) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <6133> reported by reviewdog 🐶
'canvas' is declared but its value is never read.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 18, 2022

yarn.lock changes

Click to toggle table visibility
Name Status Previous Current
@shopify/react-native-skia ADDED - 0.1.163
@types/pixelmatch ADDED - 5.2.4
@types/pngjs ADDED - 6.0.1
@types/ws ADDED - 8.5.3
canvaskit-wasm ADDED - 0.36.1
pixelmatch ADDED - 5.3.0
pngjs ADDED - 6.0.0
react-reconciler ADDED - 0.27.0
scheduler UPDATED 0.20.2 0.21.0
ws UPDATED 7.5.7 8.11.0

@@ -26,6 +26,7 @@ import { examplePlugin } from './frame-processors/ExamplePlugin';
import type { Routes } from './Routes';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { useIsFocused } from '@react-navigation/core';
import { SkCanvas, useDrawCallback } from '@shopify/react-native-skia';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <6192> reported by reviewdog 🐶
All imports in import declaration are unused.

@@ -26,6 +26,7 @@ import { examplePlugin } from './frame-processors/ExamplePlugin';
import type { Routes } from './Routes';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { useIsFocused } from '@react-navigation/core';
import { PaintStyle, SkCanvas, useDrawCallback } from '@shopify/react-native-skia';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <6192> reported by reviewdog 🐶
All imports in import declaration are unused.

const shaderToUse = useSharedValue(noShader);

const frameProcessor = useFrameProcessor(
(frame) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tsc] <6133> reported by reviewdog 🐶
'frame' is declared but its value is never read.

* feat: Draw into offscren texture

* Clear with black

* Create all the weird Metal shit

(still doesn't work)

* Try to load `PassThrough.metallib` as bundle / library

* Revert "Try to load `PassThrough.metallib` as bundle / library"

This reverts commit 4c05f66.

* Revert "Create all the weird Metal shit"

This reverts commit a272ec9.

* Revert "Clear with black"

This reverts commit e35844e.

* pod install

* feat: Use Skia to draw off-screen Texture onto CAMetalLayer

* Draw Debug FPS on screen

* Fix MTLTextureUsageRenderTarget

* Clean up/Refactor a bit

* Set `_hasNewFrame` to false

* Lock before checking _hasNewFrame

* Remove `_hasNewFrame`

* Create `SkContext` eagerly

* flush -> flushAndSubmit

* Put `SkSurface::MakeFromCAMetalLayer` under lock as well

* Render `RCTFPSGraph` to show FPS

* Update label on main queue

* Render FPS Graph in CameraView

* Update CameraView.swift

* Update SkiaMetalCanvasProvider.h

* Don't redraw if no new frame is available

* Create separate Skia Contexts for the two Threads
@mrousavy mrousavy closed this Sep 4, 2023
@mrousavy mrousavy deleted the feat/skia-canvas-in-frame-processor branch September 4, 2023 12:53
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