scoop:scoop.graphics:0.1.0
src/platform/darwin/metal.scoop
Selected production source · src/platform/darwin/metal.scoop
1
package scoop.graphics.native.metal3
import scoop.graphics.*4
import scoop.graphics.native.RenderTarget6
/** Shared Ganesh state for Metal targets using the supplied device and command queue. */7
public class MetalContext private constructor(private val resource: GraphicsResource): Closeable {8
/** The caller must supply a live BGRA8 drawable texture belonging to this device. */9
@Unsafe10
public fun target(texture: Ptr<Unit>, width: Int, height: Int, scale: Double): RenderTarget {11
pixelBytes(width, height);12
checkScalar(scale)13
requireGraphics(scale > 0.0 && scale.toFloat() > 0.0, "invalid target scale")14
return RenderTarget(15
ownedGraphics(metalTarget(resource.get(), texture, width, height), "wrap Metal target"),16
width,17
height,18
scale19
)20
}21
/** Waits for this context's submitted GPU work; used for explicit teardown. */22
public fun drain() {23
@Unsafe24
{25
graphicsResult(metalDrain(resource.get()), "drain Metal context")26
}27
}28
public override fun close() {29
resource.checkThread()30
if (resource.isClosed)31
return32
try {33
drain()34
} finally {35
resource.close()36
}37
}38
public companion object {39
/** Both opaque objects are retained by Skia. All context operations use the creating thread. */40
@Unsafe41
public fun create(device: Ptr<Unit>, queue: Ptr<Unit>): MetalContext =42
MetalContext(ownedGraphics(metalContext(device, queue), "create Ganesh Metal context"))43
}44
}46
@Extern(name = "scoop_graphics_metal_context")47
private fun metalContext(device: Ptr<Unit>, queue: Ptr<Unit>): Ptr<Unit>?49
@Extern(name = "scoop_graphics_metal_target")50
private fun metalTarget(context: Ptr<Unit>, texture: Ptr<Unit>, width: Int, height: Int): Ptr<Unit>?52
@Extern(name = "scoop_graphics_metal_drain")53
private fun metalDrain(context: Ptr<Unit>): Int