willRecreateSurface

This commit is contained in:
Михаил Капелько committed 2026-10-29 23:38:53 +03:00
1 parent de36ad782c
commit ea68f48608
5 files changed
+44 -3

No files matched your search

+5
View File
@@ -12,3 +12,8 @@ func renderPixelSize(_ view: UIView) -> [Int32] {
let h = Int32(max(1, (view.bounds.height * scale).rounded())) let h = Int32(max(1, (view.bounds.height * scale).rounded()))
return [w, h] return [w, h]
} }
func renderRecreateSurface(_ vm: RenderVM) {
eglResetSurface(&vm.glView.st)
eglMakeCurrentContext(&vm.glView.st)
}
@@ -25,9 +25,6 @@ final class RenderGLView: UIView {
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if st.surface != nil {
guard eglResetSurface(&st), eglMakeCurrentContext(&st) else { fatalError("ERROR Could not reset EGL surface") }
}
let ps = renderPixelSize(self) let ps = renderPixelSize(self)
renderSet(F.reshapePixelSize, ps) renderSet(F.reshapePixelSize, ps)
} }
+4
View File
@@ -13,3 +13,7 @@ func renderPixelSize(_ view: NSView) -> [Int32] {
let h = Int32(max(1, backing.height)) let h = Int32(max(1, backing.height))
return [w, h] return [w, h]
} }
func renderRecreateSurface(_ vm: RenderVM) {
// No-op on macOS
}
+8
View File
@@ -33,6 +33,7 @@ RenderContext:
pixelSize: [Int32] pixelSize: [Int32]
reshapePixelSize: [Int32] reshapePixelSize: [Int32]
willDeinit: Bool willDeinit: Bool
willRecreateSurface: Bool
RenderComponent: RenderComponent:
type: component type: component
@@ -42,6 +43,7 @@ RenderComponent:
- didPrepareGL: renderStartTimer(RenderVM.shared!) - didPrepareGL: renderStartTimer(RenderVM.shared!)
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
- willDeinit: renderDeinit(RenderVM.shared!) - willDeinit: renderDeinit(RenderVM.shared!)
- willRecreateSurface: renderRecreateSurface(RenderVM.shared!)
shoulds: shoulds:
didLaunch: didLaunch:
1. Only once during the first setup: 1. Only once during the first setup:
@@ -78,3 +80,9 @@ RenderComponent:
c.recentField == F.backingPixelSize c.recentField == F.backingPixelSize
then: then:
c.pixelSize = c.backingPixelSize c.pixelSize = c.backingPixelSize
willRecreateSurface:
1. Upon resize:
if:
c.recentField == F.reshapePixelSize
then:
c.willRecreateSurface = true
+27
View File
@@ -128,6 +128,7 @@ public struct F {
public static let pixelSize = "pixelSize" public static let pixelSize = "pixelSize"
public static let reshapePixelSize = "reshapePixelSize" public static let reshapePixelSize = "reshapePixelSize"
public static let willDeinit = "willDeinit" public static let willDeinit = "willDeinit"
public static let willRecreateSurface = "willRecreateSurface"
} }
public struct BlueContext: DialectContext { public struct BlueContext: DialectContext {
@@ -171,6 +172,7 @@ public struct RenderContext: DialectContext {
public var pixelSize = [Int32]() public var pixelSize = [Int32]()
public var reshapePixelSize = [Int32]() public var reshapePixelSize = [Int32]()
public var willDeinit = Bool() public var willDeinit = Bool()
public var willRecreateSurface = Bool()
public var recentField = "" public var recentField = ""
@@ -202,6 +204,9 @@ public struct RenderContext: DialectContext {
else if (name == "willDeinit") { else if (name == "willDeinit") {
return willDeinit as! T return willDeinit as! T
} }
else if (name == "willRecreateSurface") {
return willRecreateSurface as! T
}
return "unknown-field-name" as! T return "unknown-field-name" as! T
} }
@@ -237,6 +242,9 @@ public struct RenderContext: DialectContext {
else if (name == "willDeinit") { else if (name == "willDeinit") {
willDeinit = value as! Bool willDeinit = value as! Bool
} }
else if (name == "willRecreateSurface") {
willRecreateSurface = value as! Bool
}
} }
} }
@@ -353,6 +361,23 @@ func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext {
return c return c
} }
func renderShouldResetWillRecreateSurface(_ c: RenderContext) -> RenderContext {
var c = c
/* 1. Upon resize */
if
c.recentField == F.reshapePixelSize
{
c.willRecreateSurface = true
c.recentField = F.willRecreateSurface
return c
}
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
return c
}
func blueRegisterShoulds(_ ctrl: DialectController) { func blueRegisterShoulds(_ ctrl: DialectController) {
[ [
blueShouldResetDidLaunch, blueShouldResetDidLaunch,
@@ -367,6 +392,7 @@ func renderRegisterShoulds(_ ctrl: DialectController) {
renderShouldResetDidLaunch, renderShouldResetDidLaunch,
renderShouldResetDidPrepareGL, renderShouldResetDidPrepareGL,
renderShouldResetPixelSize, renderShouldResetPixelSize,
renderShouldResetWillRecreateSurface,
].forEach { f in ].forEach { f in
ctrl.registerFunction { c in f(c as! RenderContext) } ctrl.registerFunction { c in f(c as! RenderContext) }
@@ -380,6 +406,7 @@ func renderRegisterEffects(_ ctrl: DialectController) {
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) }, F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
F.willRecreateSurface, { (c: RenderContext) in renderRecreateSurface(RenderVM.shared!) },
]) ])
} }