Scoop API

scoop:scoop.graphics:0.1.0

src/platform/darwin/metal.scoop

Selected production source · src/platform/darwin/metal.scoop

1package scoop.graphics.native.metal
3import scoop.graphics.*
4import scoop.graphics.native.RenderTarget
6/** Shared Ganesh state for Metal targets using the supplied device and command queue. */
7public class MetalContext private constructor(private val resource: GraphicsResource): Closeable {
8 /** The caller must supply a live BGRA8 drawable texture belonging to this device. */
9 @Unsafe
10 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 scale
19 )
20 }
21 /** Waits for this context's submitted GPU work; used for explicit teardown. */
22 public fun drain() {
23 @Unsafe
24 {
25 graphicsResult(metalDrain(resource.get()), "drain Metal context")
26 }
27 }
28 public override fun close() {
29 resource.checkThread()
30 if (resource.isClosed)
31 return
32 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 @Unsafe
41 public fun create(device: Ptr<Unit>, queue: Ptr<Unit>): MetalContext =
42 MetalContext(ownedGraphics(metalContext(device, queue), "create Ganesh Metal context"))
43 }
46@Extern(name = "scoop_graphics_metal_context")
47private fun metalContext(device: Ptr<Unit>, queue: Ptr<Unit>): Ptr<Unit>?
49@Extern(name = "scoop_graphics_metal_target")
50private fun metalTarget(context: Ptr<Unit>, texture: Ptr<Unit>, width: Int, height: Int): Ptr<Unit>?
52@Extern(name = "scoop_graphics_metal_drain")
53private fun metalDrain(context: Ptr<Unit>): Int