Commit 24544c14 authored by Nikolay Igotti's avatar Nikolay Igotti

Use autorelease pools to ensure IOSurface object gets promptly released.

parent f6440a24
...@@ -99,12 +99,16 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_makeMeta ...@@ -99,12 +99,16 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_makeMeta
JNIEnv * env, jobject redrawer, jlong devicePtr, jint width, jint height) JNIEnv * env, jobject redrawer, jlong devicePtr, jint width, jint height)
{ {
MetalDevice *device = (MetalDevice *) devicePtr; MetalDevice *device = (MetalDevice *) devicePtr;
GrBackendRenderTarget* renderTarget = NULL;
@autoreleasepool {
id<CAMetalDrawable> currentDrawable = [device.layer nextDrawable]; id<CAMetalDrawable> currentDrawable = [device.layer nextDrawable];
if (!currentDrawable) return 0;
device.drawableHandle = currentDrawable;
GrMtlTextureInfo info; GrMtlTextureInfo info;
info.fTexture.retain(currentDrawable.texture); info.fTexture.retain(currentDrawable.texture);
GrBackendRenderTarget* renderTarget = new GrBackendRenderTarget(width, height, 0, info); renderTarget = new GrBackendRenderTarget(width, height, 0, info);
device.drawableHandle = currentDrawable; }
return (jlong) renderTarget; return (jlong) renderTarget;
} }
...@@ -139,12 +143,12 @@ BOOL isUsingIntegratedGPU() { ...@@ -139,12 +143,12 @@ BOOL isUsingIntegratedGPU() {
return output != 0; return output != 0;
} }
id<MTLDevice> MTLCreateIntegratedDevice(int adpapterPriority) { id<MTLDevice> MTLCreateIntegratedDevice(int adapterPriority) {
BOOL isIntegratedGPU = NO; BOOL isIntegratedGPU = NO;
if (adpapterPriority == AdpapterPriorityAuto) { if (adapterPriority == AdpapterPriorityAuto) {
isIntegratedGPU = isUsingIntegratedGPU(); isIntegratedGPU = isUsingIntegratedGPU();
} else if (adpapterPriority == AdpapterPriorityIntegrated) { } else if (adapterPriority == AdpapterPriorityIntegrated) {
isIntegratedGPU = YES; isIntegratedGPU = YES;
} }
...@@ -234,13 +238,21 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_finishFra ...@@ -234,13 +238,21 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_finishFra
JNIEnv *env, jobject redrawer, jlong devicePtr) JNIEnv *env, jobject redrawer, jlong devicePtr)
{ {
MetalDevice *device = (MetalDevice *) devicePtr; MetalDevice *device = (MetalDevice *) devicePtr;
id<CAMetalDrawable> currentDrawable = device.drawableHandle; id<CAMetalDrawable> currentDrawable = device.drawableHandle;
id<MTLCommandBuffer> commandBuffer = [device.queue commandBuffer]; id<MTLCommandBuffer> commandBuffer = [device.queue commandBuffer];
commandBuffer.label = @"Present"; commandBuffer.label = @"Present";
[currentDrawable addPresentedHandler:^(id<MTLDrawable> dr) {
CFRelease(currentDrawable);
}];
[commandBuffer presentDrawable:currentDrawable]; [commandBuffer presentDrawable:currentDrawable];
[commandBuffer commit]; [commandBuffer commit];
device.drawableHandle = nil;
currentDrawable = nil;
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_disposeDevice( JNIEXPORT void JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_disposeDevice(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment