diff --git a/Sources/Screen/ScreenObject.swift b/Sources/Screen/ScreenObject.swift index ee55613a3..75e2bb1d2 100644 --- a/Sources/Screen/ScreenObject.swift +++ b/Sources/Screen/ScreenObject.swift @@ -35,6 +35,11 @@ open class ScreenObject { case bottom } + enum BlendMode { + case normal + case alpha + } + /// The screen object container that contains this screen object public internal(set) weak var parent: ScreenObjectContainer? @@ -71,6 +76,10 @@ open class ScreenObject { /// Specifies the alignment position along the horizontal axis. public var horizontalAlignment: HorizontalAlignment = .left + var blendMode: BlendMode { + .alpha + } + var shouldInvalidateLayout = true /// Creates a screen object. @@ -220,6 +229,13 @@ public final class VideoTrackScreenObject: ScreenObject, ChromaKeyProcessable { } } + override var blendMode: ScreenObject.BlendMode { + if 0.0 < cornerRadius || chromaKeyColor != nil { + return .alpha + } + return .normal + } + private var queue: TypedBlockQueue? private var effects: [VideoEffect] = .init() diff --git a/Sources/Screen/ScreenRenderer.swift b/Sources/Screen/ScreenRenderer.swift index 99b54c95a..1c83046f6 100644 --- a/Sources/Screen/ScreenRenderer.swift +++ b/Sources/Screen/ScreenRenderer.swift @@ -21,6 +21,7 @@ public protocol ScreenRenderer: AnyObject { final class ScreenRendererByCPU: ScreenRenderer { static let noFlags = vImage_Flags(kvImageNoFlags) + static let doNotTile = vImage_Flags(kvImageDoNotTile) var bounds: CGRect = .init(origin: .zero, size: Screen.size) @@ -165,12 +166,22 @@ final class ScreenRendererByCPU: ScreenRenderer { switch pixelFormatType { case kCVPixelFormatType_32ARGB: - vImageAlphaBlend_ARGB8888( - &image, - &destination, - &destination, - vImage_Flags(kvImageDoNotTile) - ) + switch screenObject.blendMode { + case .normal: + vImageCopyBuffer( + &image, + &destination, + 4, + Self.doNotTile + ) + case .alpha: + vImageAlphaBlend_ARGB8888( + &image, + &destination, + &destination, + Self.doNotTile + ) + } default: break } diff --git a/Sources/Screen/StreamScreenObject.swift b/Sources/Screen/StreamScreenObject.swift index 3c0597c37..408e36e9a 100644 --- a/Sources/Screen/StreamScreenObject.swift +++ b/Sources/Screen/StreamScreenObject.swift @@ -29,6 +29,13 @@ public final class StreamScreenObject: ScreenObject, ChromaKeyProcessable { } } + override var blendMode: ScreenObject.BlendMode { + if 0.0 < cornerRadius || chromaKeyColor != nil { + return .alpha + } + return .normal + } + override public func makeBounds(_ size: CGSize) -> CGRect { guard parent != nil, let image = sampleBuffer?.formatDescription?.dimensions.size else { return super.makeBounds(size)