graphicsdriver/metal: Reduce calls of SetLayer

This commit is contained in:
Hajime Hoshi 2020-06-14 05:06:40 +09:00
parent 1395ab5e84
commit e023425be0
2 changed files with 9 additions and 1 deletions

View File

@ -28,6 +28,8 @@ type view struct {
window unsafe.Pointer window unsafe.Pointer
uiview uintptr uiview uintptr
windowChanged bool
device mtl.Device device mtl.Device
ml ca.MetalLayer ml ca.MetalLayer

View File

@ -25,7 +25,9 @@ import (
) )
func (v *view) setWindow(window unsafe.Pointer) { func (v *view) setWindow(window unsafe.Pointer) {
// NSView can be updated e.g., fullscreen-state is switched.
v.window = window v.window = window
v.windowChanged = true
} }
func (v *view) setUIView(uiview uintptr) { func (v *view) setUIView(uiview uintptr) {
@ -33,10 +35,14 @@ func (v *view) setUIView(uiview uintptr) {
} }
func (v *view) update() { func (v *view) update() {
// NSView can be changed anytime (probably). Set this everyframe. if !v.windowChanged {
return
}
cocoaWindow := ns.NewWindow(v.window) cocoaWindow := ns.NewWindow(v.window)
cocoaWindow.ContentView().SetLayer(v.ml) cocoaWindow.ContentView().SetLayer(v.ml)
cocoaWindow.ContentView().SetWantsLayer(true) cocoaWindow.ContentView().SetWantsLayer(true)
v.windowChanged = false
} }
const ( const (