portico/Sources/Portico/Generated/GraphicsOffload.swift

314 lines
16 KiB
Swift

// Generated by PorticoGen. DO NOT EDIT. See Sources/PorticoGen to make changes.
import Adw
import Gtk
import Gio
import Gdk
// PorticoGen: generateStruct | source: Gtk.GraphicsOffload
/// Bypasses gsk rendering by passing the content of its child directly to the compositor.
///
/// Graphics offload is an optimization to reduce overhead and battery use that is
/// most useful for video content. It only works on some platforms and in certain
/// situations. GTK will automatically fall back to normal rendering if it doesn't.
///
/// Graphics offload is most efficient if there are no controls drawn on top of the
/// video content.
///
/// You should consider using graphics offload for your main widget if it shows
/// frequently changing content (such as a video, or a VM display) and you provide
/// the content in the form of dmabuf textures (see [class`Gdk`.DmabufTextureBuilder]),
/// in particular if it may be fullscreen.
///
/// Numerous factors can prohibit graphics offload:
///
/// - Unsupported platforms. Currently, graphics offload only works on Linux with Wayland.
///
/// - Clipping, such as rounded corners that cause the video content to not be rectangular
///
/// - Unsupported dmabuf formats (see [method`Gdk`.Display.get_dmabuf_formats])
///
/// - Translucent video content (content with an alpha channel, even if it isn't used)
///
/// - Transforms that are more complex than translations and scales
///
/// - Filters such as opacity, grayscale or similar
///
/// To investigate problems related graphics offload, GTK offers debug flags to print
/// out information about graphics offload and dmabuf use:
///
/// GDK_DEBUG=offload
/// GDK_DEBUG=dmabuf
///
/// The GTK inspector provides a visual debugging tool for graphics offload.
///
/// A Portico view that mounts a `Gtk.GraphicsOffload`.
@MainActor public struct GraphicsOffload: View {
private let make: (MountContext) -> Gtk.GraphicsOffload
private var configure: [(Gtk.GraphicsOffload, MountContext) -> Void] = []
public var body: Never { fatalError() }
// PorticoGen: generateInits(static) | source: Gtk.GraphicsOffload.init(child:)
/// Creates a new GtkGraphicsOffload widget.
///
/// Applied once at mount; use the `Binding` or closure overload for values that change.
/// Each closure is evaluated once; children are added in order and slot closures mount their first view.
/// An empty closure adds no children and leaves slots unset.
/// Optional value parameters are applied only when non-`nil`; a `nil` argument leaves the widget's own default in place and cannot clear a nullable property - use the matching modifier for that.
///
/// - Parameter blackBackground: Whether to draw a black background.
/// - Parameter enabled: Whether graphics offload is enabled.
/// - Parameter child: A closure supplying the single view passed to `Gtk.GraphicsOffload.init` as `child`. Exactly one view is required; an empty closure is a compile-time error.
public init(blackBackground: Bool? = nil, enabled: Gtk.GraphicsOffloadEnabled? = nil, @SingleViewBuilder child: @escaping () -> AnyView) {
var __slot_child: Portico.SingleChildSlot?
make = { ctx in
let __newSlot_child = Portico.SingleChildSlot(child, ctx)
__slot_child = __newSlot_child
return Gtk.GraphicsOffload(child: __slot_child!.widget!)
}
configure.append { w, ctx in
__slot_child?.attach { v in w.setChild(child: v) }
if let blackBackground { w.setBlackBackground(value: blackBackground) }
if let enabled { w.setEnabled(enabled: enabled) }
}
}
}
extension GraphicsOffload: WidgetView {
public typealias Target = Gtk.GraphicsOffload
@_spi(Portico) public func appending(
_ step: @escaping (Gtk.GraphicsOffload, MountContext) -> Void
) -> Self {
var c = self
c.configure.append(step)
return c
}
}
@_spi(Portico) extension GraphicsOffload: Mountable {
@_spi(Portico) public func mount(_ ctx: MountContext) -> Gtk.Widget {
let w = make(ctx)
for step in configure { step(w, ctx) }
return w
}
}
// PorticoGen: generateModifierExtension | source: Gtk.GraphicsOffload
/// Modifiers for `Gtk.GraphicsOffload`, available on every Portico view whose
/// backing widget is `Gtk.GraphicsOffload` or one of its subclasses.
extension WidgetView where Target: Gtk.GraphicsOffload {
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.GraphicsOffload.setBlackBackground(value:)
/// Sets whether this GtkGraphicsOffload widget will draw a black
/// background.
///
/// A main use case for this is **_letterboxing_** where black bars are
/// visible next to the content if the aspect ratio of the content does
/// not match the dimensions of the monitor.
///
/// Using this property for letterboxing instead of CSS allows compositors
/// to show content with maximum efficiency, using direct scanout to avoid
/// extra copies in the compositor.
///
/// On Wayland, this is implemented using the
/// [single-pixel buffer](https://wayland.app/protocols/single-pixel-buffer-v1)
/// protocol.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter blackBackground: Whether to draw a black background.
/// - Returns: A copy of this view with the modifier applied.
public func blackBackground(_ blackBackground: Bool) -> Self {
appending { w, _ in
w.setBlackBackground(value: blackBackground)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.GraphicsOffload.setBlackBackground(value:), GObject.Object.connectNotify(detail:_:), Gtk.GraphicsOffload.getBlackBackground()
/// Sets whether this GtkGraphicsOffload widget will draw a black
/// background.
///
/// A main use case for this is **_letterboxing_** where black bars are
/// visible next to the content if the aspect ratio of the content does
/// not match the dimensions of the monitor.
///
/// Using this property for letterboxing instead of CSS allows compositors
/// to show content with maximum efficiency, using direct scanout to avoid
/// extra copies in the compositor.
///
/// On Wayland, this is implemented using the
/// [single-pixel buffer](https://wayland.app/protocols/single-pixel-buffer-v1)
/// protocol.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Bool` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func blackBackground(_ blackBackground: Portico.Binding<Bool>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, blackBackground, registry: ctx.registry, notifyDetail: "black-background",
read: { [w] in w.getBlackBackground() },
write: { [w] v in w.setBlackBackground(value: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.GraphicsOffload.setBlackBackground(value:)
/// Sets whether this GtkGraphicsOffload widget will draw a black
/// background.
///
/// A main use case for this is **_letterboxing_** where black bars are
/// visible next to the content if the aspect ratio of the content does
/// not match the dimensions of the monitor.
///
/// Using this property for letterboxing instead of CSS allows compositors
/// to show content with maximum efficiency, using direct scanout to avoid
/// extra copies in the compositor.
///
/// On Wayland, this is implemented using the
/// [single-pixel buffer](https://wayland.app/protocols/single-pixel-buffer-v1)
/// protocol.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.GraphicsOffload.setBlackBackground(value:)`.
///
/// - Parameter blackBackground: Whether to draw a black background.
/// - Returns: A copy of this view with the modifier applied.
public func blackBackground(_ blackBackground: @escaping () -> Bool) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setBlackBackground(value: blackBackground()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.GraphicsOffload.setChild(child:)
/// Sets the child of `self`.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: Gtk.Widget?) -> Self {
appending { w, _ in
w.setChild(child: child)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(viewBuilder) | source: Gtk.GraphicsOffload.setChild(child:)
/// Sets the child of `self`.
///
/// The closure is evaluated once when the modifier is applied. Its first view is mounted into the slot.
/// Additional views are ignored; an empty closure leaves the slot unset.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(@ViewBuilder _ child: () -> [AnyView]) -> Self {
let childViews = child()
return appending { w, ctx in
guard let v = childViews.first else { return }
w.setChild(child: v.makeWidget(ctx))
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.GraphicsOffload.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.GraphicsOffload.getChild()
/// Sets the child of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.Widget?` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func child<W: Gtk.Widget>(_ child: Portico.Binding<W?>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(lifted,twoWay) | source: Gtk.GraphicsOffload.setChild(child:), GObject.Object.connectNotify(detail:_:), Gtk.GraphicsOffload.getChild()
/// Sets the child of `self`.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// `Binding` is invariant, so a `Binding<Gtk.Widget>` is not accepted by the nullable overload; this one takes it and promotes each value. Pass a `Binding<Gtk.Widget?>` to be able to clear the property.
/// When `Gtk.Widget` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
/// A `nil` widget value is never written back into the binding.
///
/// - Returns: A copy of this view with the modifier applied.
public func child<W: Gtk.Widget>(_ child: Portico.Binding<W>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, child, registry: ctx.registry, notifyDetail: "child",
read: { [w] in w.getChild() as? W },
write: { [w] v in w.setChild(child: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.GraphicsOffload.setChild(child:)
/// Sets the child of `self`.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.GraphicsOffload.setChild(child:)`.
///
/// - Parameter child: The child widget.
/// - Returns: A copy of this view with the modifier applied.
public func child(_ child: @escaping () -> Gtk.Widget?) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setChild(child: child()) }
tracker.run()
ctx.registry.add(tracker)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(static) | source: Gtk.GraphicsOffload.setEnabled(enabled:)
/// Sets whether this GtkGraphicsOffload widget will attempt
/// to offload the content of its child widget.
///
/// Applied once at mount; use the `Binding` or closure overload for a value that changes.
///
/// - Parameter enabled: Whether graphics offload is enabled.
/// - Returns: A copy of this view with the modifier applied.
public func enabled(_ enabled: Gtk.GraphicsOffloadEnabled) -> Self {
appending { w, _ in
w.setEnabled(enabled: enabled)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers -> bindingModifier(twoWay) | source: Gtk.GraphicsOffload.setEnabled(enabled:), GObject.Object.connectNotify(detail:_:), Gtk.GraphicsOffload.getEnabled()
/// Sets whether this GtkGraphicsOffload widget will attempt
/// to offload the content of its child widget.
///
/// Applied at mount and re-applied on every change the binding publishes.
/// When `Gtk.GraphicsOffloadEnabled` conforms to `Equatable` this binds in both directions: the widget's `notify` signal writes its current value back into the binding, so changes made in the UI propagate to the bound state. Each direction compares before writing, which terminates the echo after one hop. A value type that is not `Equatable` binds one way only, because the echo cannot be broken.
///
/// - Returns: A copy of this view with the modifier applied.
public func enabled(_ enabled: Portico.Binding<Gtk.GraphicsOffloadEnabled>) -> Self {
appending { w, ctx in
Portico.bindProperty(
w, enabled, registry: ctx.registry, notifyDetail: "enabled",
read: { [w] in w.getEnabled() },
write: { [w] v in w.setEnabled(enabled: v) }
)
}
}
// PorticoGen: generateModifierExtension -> generatePropertyModifiers(closure) | source: Gtk.GraphicsOffload.setEnabled(enabled:)
/// Sets whether this GtkGraphicsOffload widget will attempt
/// to offload the content of its child widget.
///
/// The closure runs inside a `DependencyTracker`, so any `@State` it reads re-runs it and pushes the new value through `Gtk.GraphicsOffload.setEnabled(enabled:)`.
///
/// - Parameter enabled: Whether graphics offload is enabled.
/// - Returns: A copy of this view with the modifier applied.
public func enabled(_ enabled: @escaping () -> Gtk.GraphicsOffloadEnabled) -> Self {
appending { w, ctx in
let tracker = DependencyTracker { [w] in w.setEnabled(enabled: enabled()) }
tracker.run()
ctx.registry.add(tracker)
}
}
}