Images.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. extension BackendFeatures {
  2. /// Backend methods for image rendering.
  3. ///
  4. /// These are used by ``Image``.
  5. @MainActor
  6. public protocol Images: Core {
  7. /// If `true`, all images in a window will get updated when the window's
  8. /// scale factor changes (``EnvironmentValues/windowScaleFactor``).
  9. ///
  10. /// Backends based on modern UI frameworks can usually get away with setting
  11. /// this to `false`, but backends such as `Gtk3Backend` have to set this to
  12. /// `true` to properly support HiDPI (aka Retina) displays because they
  13. /// manually rescale the image meaning that it must get rescaled when the
  14. /// scale factor changes.
  15. var requiresImageUpdateOnScaleFactorChange: Bool { get }
  16. /// Creates an image view.
  17. ///
  18. /// Predominantly used by ``Image``.
  19. ///
  20. /// - Returns: An image view.
  21. func createImageView() -> Widget
  22. /// Sets the image data to be displayed.
  23. ///
  24. /// - Parameters:
  25. /// - imageView: The image view to update.
  26. /// - rgbaData: The pixel data, as rows of pixels concatenated into a
  27. /// flat array.
  28. /// - width: The width of the image in pixels. Should only be used to
  29. /// interpret `rgbaData`, _not_ to set the size of the image on-screen.
  30. /// - height: The height of the image in pixels. Should only be used to
  31. /// interpret `rgbaData`, _not_ to set the size of the image on-screen.
  32. /// - targetWidth: The width that the image must have on-screen.
  33. /// Guaranteed to match the width the widget will be given, so backends
  34. /// that don't have to manually scale the underlying pixel data can
  35. /// safely ignore this parameter.
  36. /// - targetHeight: The height that the image must have on-screen.
  37. /// Guaranteed to match the height the widget will be given, so backends
  38. /// that don't have to manually scale the underlying pixel data can
  39. /// safely ignore this parameter.
  40. /// - dataHasChanged: If `false`, then `rgbaData` hasn't changed since the
  41. /// last call, so backends that don't have to manually resize the image
  42. /// data don't have to do anything.
  43. /// - environment: The current environment.
  44. func updateImageView(
  45. _ imageView: Widget,
  46. rgbaData: [UInt8],
  47. width: Int,
  48. height: Int,
  49. targetWidth: Int,
  50. targetHeight: Int,
  51. dataHasChanged: Bool,
  52. environment: EnvironmentValues
  53. )
  54. }
  55. }