Repository: airbnb/lottie-ios
File: Sources/Public/LottieConfiguration.swift (Swift)

Code before:
    useDisplayP3: Bool = false)
  {
    self.renderingEngine = renderingEngine
    self.decodingStrategy = decodingStrategy
    self.useDisplayP3 = useDisplayP3
  }

  // MARK: Public

  /// The global configuration of Lottie,
  /// which applies to all `LottieAnimationView`s by default.
  public static var shared = LottieConfiguration()

  /// The rendering engine implementation to use when displaying an animation
  ///  - Defaults to `RenderingEngineOption.automatic`, which uses the
  ///    Core Animation rendering engine for supported animations, and
  ///    falls back to using the Main Thread rendering engine for
  ///    animations that use features not supported by the Core Animation engine.
  public var renderingEngine: RenderingEngineOption

  /// The decoding implementation to use when parsing an animation JSON file
  public var decodingStrategy: DecodingStrategy

  /// Use the display P3 color space for rendering instead of the default RGB
  ///  - Defaults to `false`
  public var useDisplayP3: Bool
}

extension LottieConfiguration {
  var renderingColorSpace: CGColorSpace {
    if
      useDisplayP3,
      let colorspace = CGColorSpace(name: CGColorSpace.displayP3)
    {
      return colorspace
    } else {
      return CGColorSpaceCreateDeviceRGB()
    }
  }
}

// MARK: - RenderingEngineOption

public enum RenderingEngineOption: Hashable {
  /// Uses the Core Animation engine for supported animations, and falls back to using
  /// the Main Thread engine for animations that use features not supported by the
  /// Core Animation engine.
  case automatic

  /// Uses the specified rendering engine
  case specific(RenderingEngine)

Review comment (suggestion):
Rather than having a boolean for toggling Display P3, could we have a `animationColorSpace: CGColorSpace` property? That API would be more flexible since it lets consumers use any color space. We could include instructions / sample code in the doc comment on how to set the color space to Display P3.

Code after:
    colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB())
  {
    self.renderingEngine = renderingEngine
    self.decodingStrategy = decodingStrategy
    self.colorSpace = colorSpace
  }

  // MARK: Public

  /// The global configuration of Lottie,
  /// which applies to all `LottieAnimationView`s by default.
  public static var shared = LottieConfiguration()

  /// The rendering engine implementation to use when displaying an animation
  ///  - Defaults to `RenderingEngineOption.automatic`, which uses the
  ///    Core Animation rendering engine for supported animations, and
  ///    falls back to using the Main Thread rendering engine for
  ///    animations that use features not supported by the Core Animation engine.
  public var renderingEngine: RenderingEngineOption

  /// The decoding implementation to use when parsing an animation JSON file
  public var decodingStrategy: DecodingStrategy

  /// The color space to be used for rendering
  ///  - Defaults to `CGColorSpaceCreateDeviceRGB()`
  public var colorSpace: CGColorSpace
}

// MARK: - RenderingEngineOption

public enum RenderingEngineOption: Hashable {
  /// Uses the Core Animation engine for supported animations, and falls back to using
  /// the Main Thread engine for animations that use features not supported by the
  /// Core Animation engine.
  case automatic

  /// Uses the specified rendering engine
  case specific(RenderingEngine)

  // MARK: Public

  /// The Main Thread rendering engine, which supports all Lottie features
  /// but runs on the main thread, which comes with some CPU overhead and
  /// can cause the animation to play at a low framerate when the CPU is busy.
  public static var mainThread: RenderingEngineOption { .specific(.mainThread) }

  /// The Core Animation rendering engine, that animates using Core Animation
  /// and has better performance characteristics than the Main Thread engine,
  /// but doesn't support all Lottie features.
  ///  - In general, prefer using `RenderingEngineOption.automatic` over
  ///    `RenderingEngineOption.coreAnimation`. The Core Animation rendering