internal/graphicsdriver/metal/ca: follow ObjC convention

Updates #2981
This commit is contained in:
Hajime Hoshi 2024-05-06 19:36:16 +09:00
parent a391da6c77
commit 2261cf76de
2 changed files with 19 additions and 19 deletions

View File

@ -35,7 +35,7 @@ import (
// Layer is an object that manages image-based content and // Layer is an object that manages image-based content and
// allows you to perform animations on that content. // allows you to perform animations on that content.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/calayer. // Reference: https://developer.apple.com/documentation/quartzcore/calayer?language=objc.
type Layer interface { type Layer interface {
// Layer returns the underlying CALayer * pointer. // Layer returns the underlying CALayer * pointer.
Layer() unsafe.Pointer Layer() unsafe.Pointer
@ -43,15 +43,15 @@ type Layer interface {
// MetalLayer is a Core Animation Metal layer, a layer that manages a pool of Metal drawables. // MetalLayer is a Core Animation Metal layer, a layer that manages a pool of Metal drawables.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer?language=objc.
type MetalLayer struct { type MetalLayer struct {
metalLayer objc.ID metalLayer objc.ID
} }
// MakeMetalLayer creates a new Core Animation Metal layer. // NewMetalLayer creates a new Core Animation Metal layer.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer?language=objc.
func MakeMetalLayer() (MetalLayer, error) { func NewMetalLayer() (MetalLayer, error) {
coreGraphics, err := purego.Dlopen("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", purego.RTLD_LAZY|purego.RTLD_GLOBAL) coreGraphics, err := purego.Dlopen("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", purego.RTLD_LAZY|purego.RTLD_GLOBAL)
if err != nil { if err != nil {
return MetalLayer{}, err return MetalLayer{}, err
@ -88,14 +88,14 @@ func (ml MetalLayer) Layer() unsafe.Pointer {
// PixelFormat returns the pixel format of textures for rendering layer content. // PixelFormat returns the pixel format of textures for rendering layer content.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478155-pixelformat. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478155-pixelformat?language=objc.
func (ml MetalLayer) PixelFormat() mtl.PixelFormat { func (ml MetalLayer) PixelFormat() mtl.PixelFormat {
return mtl.PixelFormat(ml.metalLayer.Send(objc.RegisterName("pixelFormat"))) return mtl.PixelFormat(ml.metalLayer.Send(objc.RegisterName("pixelFormat")))
} }
// SetDevice sets the Metal device responsible for the layer's drawable resources. // SetDevice sets the Metal device responsible for the layer's drawable resources.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478163-device. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478163-device?language=objc.
func (ml MetalLayer) SetDevice(device mtl.Device) { func (ml MetalLayer) SetDevice(device mtl.Device) {
ml.metalLayer.Send(objc.RegisterName("setDevice:"), uintptr(device.Device())) ml.metalLayer.Send(objc.RegisterName("setDevice:"), uintptr(device.Device()))
} }
@ -111,7 +111,7 @@ func (ml MetalLayer) SetOpaque(opaque bool) {
// PixelFormatRGBA16Float, PixelFormatBGRA10XR, or PixelFormatBGRA10XRSRGB. // PixelFormatRGBA16Float, PixelFormatBGRA10XR, or PixelFormatBGRA10XRSRGB.
// SetPixelFormat panics for other values. // SetPixelFormat panics for other values.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478155-pixelformat. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478155-pixelformat?language=objc.
func (ml MetalLayer) SetPixelFormat(pf mtl.PixelFormat) { func (ml MetalLayer) SetPixelFormat(pf mtl.PixelFormat) {
switch pf { switch pf {
case mtl.PixelFormatRGBA8UNorm, mtl.PixelFormatRGBA8UNormSRGB, mtl.PixelFormatBGRA8UNorm, mtl.PixelFormatBGRA8UNormSRGB, mtl.PixelFormatStencil8: case mtl.PixelFormatRGBA8UNorm, mtl.PixelFormatRGBA8UNormSRGB, mtl.PixelFormatBGRA8UNorm, mtl.PixelFormatBGRA8UNormSRGB, mtl.PixelFormatStencil8:
@ -126,7 +126,7 @@ func (ml MetalLayer) SetPixelFormat(pf mtl.PixelFormat) {
// //
// It can set to 2 or 3 only. SetMaximumDrawableCount panics for other values. // It can set to 2 or 3 only. SetMaximumDrawableCount panics for other values.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2938720-maximumdrawablecount. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2938720-maximumdrawablecount?language=objc.
func (ml MetalLayer) SetMaximumDrawableCount(count int) { func (ml MetalLayer) SetMaximumDrawableCount(count int) {
if count < 2 || count > 3 { if count < 2 || count > 3 {
panic(errors.New(fmt.Sprintf("failed trying to set maximumDrawableCount to %d outside of the valid range of [2, 3]", count))) panic(errors.New(fmt.Sprintf("failed trying to set maximumDrawableCount to %d outside of the valid range of [2, 3]", count)))
@ -137,7 +137,7 @@ func (ml MetalLayer) SetMaximumDrawableCount(count int) {
// SetDisplaySyncEnabled controls whether the Metal layer and its drawables // SetDisplaySyncEnabled controls whether the Metal layer and its drawables
// are synchronized with the display's refresh rate. // are synchronized with the display's refresh rate.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2887087-displaysyncenabled. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2887087-displaysyncenabled?language=objc.
func (ml MetalLayer) SetDisplaySyncEnabled(enabled bool) { func (ml MetalLayer) SetDisplaySyncEnabled(enabled bool) {
if runtime.GOOS == "ios" { if runtime.GOOS == "ios" {
return return
@ -147,7 +147,7 @@ func (ml MetalLayer) SetDisplaySyncEnabled(enabled bool) {
// SetDrawableSize sets the size, in pixels, of textures for rendering layer content. // SetDrawableSize sets the size, in pixels, of textures for rendering layer content.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478174-drawablesize. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478174-drawablesize?language=objc.
func (ml MetalLayer) SetDrawableSize(width, height int) { func (ml MetalLayer) SetDrawableSize(width, height int) {
// TODO: once objc supports calling functions with struct arguments replace this with just a ID.Send call // TODO: once objc supports calling functions with struct arguments replace this with just a ID.Send call
var sel_setDrawableSize = objc.RegisterName("setDrawableSize:") var sel_setDrawableSize = objc.RegisterName("setDrawableSize:")
@ -161,7 +161,7 @@ func (ml MetalLayer) SetDrawableSize(width, height int) {
// NextDrawable returns a Metal drawable. // NextDrawable returns a Metal drawable.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478172-nextdrawable. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478172-nextdrawable?language=objc.
func (ml MetalLayer) NextDrawable() (MetalDrawable, error) { func (ml MetalLayer) NextDrawable() (MetalDrawable, error) {
md := ml.metalLayer.Send(objc.RegisterName("nextDrawable")) md := ml.metalLayer.Send(objc.RegisterName("nextDrawable"))
if md == 0 { if md == 0 {
@ -172,28 +172,28 @@ func (ml MetalLayer) NextDrawable() (MetalDrawable, error) {
// PresentsWithTransaction returns a Boolean value that determines whether the layer presents its content using a Core Animation transaction. // PresentsWithTransaction returns a Boolean value that determines whether the layer presents its content using a Core Animation transaction.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478157-presentswithtransaction // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478157-presentswithtransaction?language=objc
func (ml MetalLayer) PresentsWithTransaction() bool { func (ml MetalLayer) PresentsWithTransaction() bool {
return ml.metalLayer.Send(objc.RegisterName("presentsWithTransaction")) != 0 return ml.metalLayer.Send(objc.RegisterName("presentsWithTransaction")) != 0
} }
// SetPresentsWithTransaction sets a Boolean value that determines whether the layer presents its content using a Core Animation transaction. // SetPresentsWithTransaction sets a Boolean value that determines whether the layer presents its content using a Core Animation transaction.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478157-presentswithtransaction // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/1478157-presentswithtransaction?language=objc
func (ml MetalLayer) SetPresentsWithTransaction(presentsWithTransaction bool) { func (ml MetalLayer) SetPresentsWithTransaction(presentsWithTransaction bool) {
ml.metalLayer.Send(objc.RegisterName("setPresentsWithTransaction:"), presentsWithTransaction) ml.metalLayer.Send(objc.RegisterName("setPresentsWithTransaction:"), presentsWithTransaction)
} }
// SetFramebufferOnly sets a Boolean value that determines whether the layers textures are used only for rendering. // SetFramebufferOnly sets a Boolean value that determines whether the layers textures are used only for rendering.
// //
// https://developer.apple.com/documentation/quartzcore/cametallayer/1478168-framebufferonly // https://developer.apple.com/documentation/quartzcore/cametallayer/1478168-framebufferonly?language=objc
func (ml MetalLayer) SetFramebufferOnly(framebufferOnly bool) { func (ml MetalLayer) SetFramebufferOnly(framebufferOnly bool) {
ml.metalLayer.Send(objc.RegisterName("setFramebufferOnly:"), framebufferOnly) ml.metalLayer.Send(objc.RegisterName("setFramebufferOnly:"), framebufferOnly)
} }
// MetalDrawable is a displayable resource that can be rendered or written to by Metal. // MetalDrawable is a displayable resource that can be rendered or written to by Metal.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametaldrawable. // Reference: https://developer.apple.com/documentation/quartzcore/cametaldrawable?language=objc.
type MetalDrawable struct { type MetalDrawable struct {
metalDrawable objc.ID metalDrawable objc.ID
} }
@ -205,14 +205,14 @@ func (md MetalDrawable) Drawable() unsafe.Pointer {
// Texture returns a Metal texture object representing the drawable object's content. // Texture returns a Metal texture object representing the drawable object's content.
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametaldrawable/1478159-texture. // Reference: https://developer.apple.com/documentation/quartzcore/cametaldrawable/1478159-texture?language=objc.
func (md MetalDrawable) Texture() mtl.Texture { func (md MetalDrawable) Texture() mtl.Texture {
return mtl.NewTexture(md.metalDrawable.Send(objc.RegisterName("texture"))) return mtl.NewTexture(md.metalDrawable.Send(objc.RegisterName("texture")))
} }
// Present presents the drawable onscreen as soon as possible. // Present presents the drawable onscreen as soon as possible.
// //
// Reference: https://developer.apple.com/documentation/metal/mtldrawable/1470284-present. // Reference: https://developer.apple.com/documentation/metal/mtldrawable/1470284-present?language=objc.
func (md MetalDrawable) Present() { func (md MetalDrawable) Present() {
md.metalDrawable.Send(objc.RegisterName("present")) md.metalDrawable.Send(objc.RegisterName("present"))
} }

View File

@ -61,7 +61,7 @@ func (v *view) colorPixelFormat() mtl.PixelFormat {
func (v *view) initialize(device mtl.Device) error { func (v *view) initialize(device mtl.Device) error {
v.device = device v.device = device
ml, err := ca.MakeMetalLayer() ml, err := ca.NewMetalLayer()
if err != nil { if err != nil {
return err return err
} }