Revert "internal/graphicsdriver/metal: bug fix: use 3 drawables for fullscreen"

This reverts commit 3c7bcf3035.

Reason: the window unexpectedly blinks when exiting from fullscreen

Updates #2880
This commit is contained in:
Hajime Hoshi 2024-01-02 22:47:09 +09:00
parent 3c7bcf3035
commit ec9613dd94
3 changed files with 15 additions and 46 deletions

View File

@ -22,16 +22,16 @@ import (
) )
type view struct { type view struct {
window uintptr
uiview uintptr
windowChanged bool
vsyncDisabled bool vsyncDisabled bool
device mtl.Device device mtl.Device
ml ca.MetalLayer ml ca.MetalLayer
maximumDrawableCount int
once sync.Once once sync.Once
viewPlatform
} }
func (v *view) setDrawableSize(width, height int) { func (v *view) setDrawableSize(width, height int) {
@ -52,24 +52,14 @@ func (v *view) setDisplaySyncEnabled(enabled bool) {
func (v *view) forceSetDisplaySyncEnabled(enabled bool) { func (v *view) forceSetDisplaySyncEnabled(enabled bool) {
v.ml.SetDisplaySyncEnabled(enabled) v.ml.SetDisplaySyncEnabled(enabled)
v.vsyncDisabled = !enabled v.vsyncDisabled = !enabled
v.updateMaximumDrawableCount()
}
func (v *view) updateMaximumDrawableCount() { if v.vsyncDisabled {
var count int
if v.vsyncDisabled || v.isFullscreen() {
// Apparently 2 makes FPS half. Use 3. // Apparently 2 makes FPS half. Use 3.
count = 3 v.ml.SetMaximumDrawableCount(3)
} else { } else {
// Use 2 in a usual case not to cause rendering delays (#2822). // Use 2 in a usual case not to cause rendering delays (#2822).
count = 2 v.ml.SetMaximumDrawableCount(2)
} }
if v.maximumDrawableCount == count {
return
}
v.ml.SetMaximumDrawableCount(count)
v.maximumDrawableCount = count
} }
func (v *view) colorPixelFormat() mtl.PixelFormat { func (v *view) colorPixelFormat() mtl.PixelFormat {

View File

@ -42,10 +42,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
) )
type viewPlatform struct {
uiview uintptr
}
func (v *view) setWindow(window uintptr) { func (v *view) setWindow(window uintptr) {
panic("metal: setWindow is not available on iOS") panic("metal: setWindow is not available on iOS")
} }
@ -64,10 +60,6 @@ func (v *view) update() {
C.setFrame(v.ml.Layer(), unsafe.Pointer(v.uiview)) C.setFrame(v.ml.Layer(), unsafe.Pointer(v.uiview))
} }
func (v *view) isFullscreen() bool {
return false
}
const ( const (
storageMode = mtl.StorageModeShared storageMode = mtl.StorageModeShared
resourceStorageMode = mtl.ResourceStorageModeShared resourceStorageMode = mtl.ResourceStorageModeShared

View File

@ -23,15 +23,9 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
) )
type viewPlatform struct {
window cocoa.NSWindow
windowChanged bool
fullscreen bool
}
func (v *view) setWindow(window uintptr) { func (v *view) setWindow(window uintptr) {
// NSView can be updated e.g., fullscreen-state is switched. // NSView can be updated e.g., fullscreen-state is switched.
v.window = cocoa.NSWindow{ID: objc.ID(window)} v.window = window
v.windowChanged = true v.windowChanged = true
} }
@ -40,22 +34,15 @@ func (v *view) setUIView(uiview uintptr) {
} }
func (v *view) update() { func (v *view) update() {
if v.windowChanged { if !v.windowChanged {
return
}
// TODO: Should this be called on the main thread? // TODO: Should this be called on the main thread?
v.window.ContentView().SetLayer(uintptr(v.ml.Layer())) cocoaWindow := cocoa.NSWindow{ID: objc.ID(v.window)}
v.window.ContentView().SetWantsLayer(true) cocoaWindow.ContentView().SetLayer(uintptr(v.ml.Layer()))
cocoaWindow.ContentView().SetWantsLayer(true)
v.windowChanged = false v.windowChanged = false
}
fullscreen := v.window.StyleMask()&cocoa.NSWindowStyleMaskFullScreen != 0
if v.fullscreen != fullscreen {
v.fullscreen = fullscreen
v.updateMaximumDrawableCount()
}
}
func (v *view) isFullscreen() bool {
return v.fullscreen
} }
const ( const (