Skip to content

Commit

Permalink
Merge pull request #1490 from Shopify/fix/1475-fix-memory-issue-ios
Browse files Browse the repository at this point in the history
#1475: iOS: Reverted commit to fix memory regression
  • Loading branch information
chrfalch authored Apr 14, 2023
2 parents c75872e + 1c9dba9 commit 29b1b30
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,29 @@
// usage growing very fast in the simulator without this.
@autoreleasepool {

GrMTLHandle drawableHandle;
auto skSurface = SkSurface::MakeFromCAMetalLayer(
renderContext->skContext.get(), (__bridge GrMTLHandle)_layer,
kTopLeft_GrSurfaceOrigin, 1, kBGRA_8888_SkColorType, nullptr, nullptr,
&drawableHandle);
/* It is super important that we use the pattern of calling nextDrawable
inside this autoreleasepool and not depend on Skia's
SkSurface::MakeFromCAMetalLayer to encapsulate since we're seeing a lot of
drawables leaking if they're not done this way.
This is now reverted from:
(https://github.com/Shopify/react-native-skia/commit/2e2290f8e6dfc6921f97b79f779d920fbc1acceb)
back to the original implementation.
*/
id<CAMetalDrawable> currentDrawable = [_layer nextDrawable];
if (currentDrawable == nullptr) {
return;
}

GrMtlTextureInfo fbInfo;
fbInfo.fTexture.retain((__bridge void *)currentDrawable.texture);

GrBackendRenderTarget backendRT(_layer.drawableSize.width,
_layer.drawableSize.height, 1, fbInfo);

auto skSurface = SkSurface::MakeFromBackendRenderTarget(
renderContext->skContext.get(), backendRT, kTopLeft_GrSurfaceOrigin,
kBGRA_8888_SkColorType, nullptr, nullptr);

if (skSurface == nullptr || skSurface->getCanvas() == nullptr) {
RNSkia::RNSkLogger::logToConsole(
Expand All @@ -120,11 +138,8 @@

skSurface->flushAndSubmit();

id<CAMetalDrawable> currentDrawable =
(__bridge id<CAMetalDrawable>)drawableHandle;
id<MTLCommandBuffer> commandBuffer(
[renderContext->commandQueue commandBuffer]);
commandBuffer.label = @"PresentSkia";
[commandBuffer presentDrawable:currentDrawable];
[commandBuffer commit];
}
Expand Down

0 comments on commit 29b1b30

Please sign in to comment.