12f850c8e1
* Create Shaders.ts * Add `previewType` and `enableFpsGraph` * Add RN Skia native dependency * Add Skia Preview View on iOS * Pass 1 * Update FrameHostObject.mm * Wrap Canvas * Lockfiles * fix: Fix stuff * chore: Upgrade RNWorklets * Add `previewType` to set the Preview * feat: Add Example * Update project.pbxproj * `enableFpsGraph` * Cache the `std::shared_ptr<FrameHostObject>` * Update CameraView+RecordVideo.swift * Update SkiaMetalCanvasProvider.mm * Android: Integrate Skia Dependency * fix: Use new Prefix * Add example for rendering shader * chore: Upgrade CameraX * Remove KTX * Enable `viewBinding` * Revert "Enable `viewBinding`" This reverts commit f2a603f53b33ea4311a296422ffd1a910ce03f9e. * Revert "chore: Upgrade CameraX" This reverts commit 8dc832cf8754490d31a6192e6c1a1f11cdcd94fe. * Remove unneeded `ProcessCameraProvider.getInstance()` call * fix: Add REA hotfix patch * fix: Fix FrameHostObject dead in runAsync * fix: Make `runAsync` run truly async by dropping new Frames while executing * chore: Upgrade RN Worklets to latest * chore: Upgrade RN Skia * Revert "Remove KTX" This reverts commit 253f586633f7af2da992d2279fc206dc62597129. * Make Skia optional in CMake * Fix import * Update CMakeLists.txt * Update build.gradle * Update CameraView.kt * Update CameraView.kt * Update CameraView.kt * Update Shaders.ts * Center Blur * chore: Upgrade RN Worklets * feat: Add `toByteArray()`, `orientation`, `isMirrored` and `timestamp` to `Frame` (#1487) * feat: Implement `orientation` and `isMirrored` on Frame * feat: Add `toArrayBuffer()` func * perf: Do faster buffer copy * feat: Implement `toArrayBuffer()` on Android * feat: Add `orientation` and `isMirrored` to Android * feat: Add `timestamp` to Frame * Update Frame.ts * Update JImageProxy.h * Update FrameHostObject.cpp * Update FrameHostObject.cpp * Update CameraPage.tsx * fix: Format Swift
60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
//
|
|
// PreviewSkiaView.mm
|
|
// VisionCamera
|
|
//
|
|
// Created by Marc Rousavy on 17.11.22.
|
|
// Copyright © 2022 mrousavy. All rights reserved.
|
|
//
|
|
|
|
#import "PreviewSkiaView.h"
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "SkiaMetalCanvasProvider.h"
|
|
|
|
#include <exception>
|
|
#include <string>
|
|
|
|
#if SHOW_FPS
|
|
#import <React/RCTFPSGraph.h>
|
|
#endif
|
|
|
|
@implementation PreviewSkiaView {
|
|
std::shared_ptr<SkiaMetalCanvasProvider> _canvasProvider;
|
|
}
|
|
|
|
- (void)drawFrame:(CMSampleBufferRef)buffer withCallback:(DrawCallback _Nonnull)callback {
|
|
if (_canvasProvider == nullptr) {
|
|
throw std::runtime_error("Cannot draw new Frame to Canvas when SkiaMetalCanvasProvider is null!");
|
|
}
|
|
|
|
_canvasProvider->renderFrameToCanvas(buffer, ^(SkCanvas* canvas) {
|
|
callback((void*)canvas);
|
|
});
|
|
}
|
|
|
|
- (void) willMoveToSuperview:(UIView *)newWindow {
|
|
if (newWindow == NULL) {
|
|
// Remove implementation view when the parent view is not set
|
|
if (_canvasProvider != nullptr) {
|
|
[_canvasProvider->getLayer() removeFromSuperlayer];
|
|
_canvasProvider = nullptr;
|
|
}
|
|
} else {
|
|
// Create implementation view when the parent view is set
|
|
if (_canvasProvider == nullptr) {
|
|
_canvasProvider = std::make_shared<SkiaMetalCanvasProvider>();
|
|
[self.layer addSublayer: _canvasProvider->getLayer()];
|
|
_canvasProvider->start();
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void) layoutSubviews {
|
|
if (_canvasProvider != nullptr) {
|
|
_canvasProvider->setSize(self.bounds.size.width, self.bounds.size.height);
|
|
}
|
|
}
|
|
|
|
@end
|
|
|