mirror of
https://github.com/narrrl/proton-stream.git
synced 2026-11-03 16:41:26 +01:00
fix(ios): fit the picture to the window after a rotation
MPVKit's MoltenVK context reads the layer's drawableSize only when mpv builds its video output and reports no resize after that (mpvkit/MPVKit#3). A player opened upright and turned on its side went on drawing the upright frame into a corner of the landscape drawable. The view now tells the player when its drawable changes, and once the size settles the player rebuilds mpv's output by turning the picture off and on, as the background already does. The vid writes run in order off the main thread.
This commit is contained in:
1 parent
cafd969567
commit
8d615579e2
2 files changed
+60
-4
No files matched your search
@@ -724,16 +724,18 @@ struct MpvView: UIViewRepresentable {
|
||||
let player: MpvPlayer
|
||||
|
||||
func makeUIView(context _: Context) -> LayerView {
|
||||
LayerView(layer: player.layer)
|
||||
LayerView(player: player)
|
||||
}
|
||||
|
||||
func updateUIView(_: LayerView, context _: Context) {}
|
||||
|
||||
final class LayerView: UIView {
|
||||
private let player: MpvPlayer
|
||||
private let video: CAMetalLayer
|
||||
|
||||
init(layer video: CAMetalLayer) {
|
||||
self.video = video
|
||||
init(player: MpvPlayer) {
|
||||
self.player = player
|
||||
video = player.layer
|
||||
super.init(frame: .zero)
|
||||
backgroundColor = .black
|
||||
video.removeFromSuperlayer()
|
||||
@@ -759,6 +761,8 @@ struct MpvView: UIViewRepresentable {
|
||||
video.contentsScale = scale
|
||||
video.drawableSize = CGSize(width: bounds.width * scale, height: bounds.height * scale)
|
||||
CATransaction.commit()
|
||||
// A new drawable is not enough on its own: mpv has to be told.
|
||||
player.outputResized()
|
||||
}
|
||||
|
||||
override func didMoveToWindow() {
|
||||
|
||||
Reference in new issue
Block a user