Unverified Commit 80ef24e9 authored by Elijah Semyonov's avatar Elijah Semyonov Committed by GitHub

Skip presenting CAMetalDrawable for CAMetalLayer that changed size (#779)

parent a662a791
......@@ -112,11 +112,9 @@ internal class MetalRedrawer(
override fun redrawImmediately() {
check(!isDisposed) { "MetalRedrawer is disposed" }
inDrawScope {
setVSyncEnabled(device.ptr, enabled = false)
update(System.nanoTime())
if (!isDisposed) { // Redrawer may be disposed in user code, during `update`
performDraw()
setVSyncEnabled(device.ptr, properties.isVsyncEnabled)
}
}
}
......
......@@ -61,11 +61,25 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_context_MetalContextHandler_fini
if (currentDrawable) {
id<MTLCommandBuffer> commandBuffer = [device.queue commandBuffer];
commandBuffer.label = @"Present";
[commandBuffer presentDrawable:currentDrawable];
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
/// commands have completed, allow next waiting (if any) to start encoding new work to gpu
dispatch_semaphore_signal(device.inflightSemaphore);
}];
[commandBuffer addScheduledHandler:^(id<MTLCommandBuffer> buffer) {
int drawableWidth = currentDrawable.texture.width;
int drawableHeight = currentDrawable.texture.height;
int layerWidth = device.layer.drawableSize.width;
int layerHeight = device.layer.drawableSize.height;
/// Avoid presenting drawable on layer that has already changed size by the moment it was scheduled
if (drawableWidth == layerWidth && drawableHeight == layerHeight) {
[currentDrawable present];
}
}];
[commandBuffer commit];
device.drawableHandle = nil;
}
......
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