// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "VideoProducer.h" #include "Widgets/SWindow.h" #include "RendererInterface.h" #include "Delegates/IDelegateInstance.h" namespace UE::EditorPixelStreaming2 { using namespace UE::PixelStreaming2; /** * Use this if you want to send the full UE editor as video input. */ class PIXELSTREAMING2EDITOR_API FVideoProducerBackBufferComposited : public FVideoProducer { public: static TSharedPtr Create(); virtual ~FVideoProducerBackBufferComposited(); virtual FString ToString() override; virtual bool IsFrameAlreadyCopied() override { return true; } DECLARE_MULTICAST_DELEGATE_OneParam(FOnFrameSizeChanged, TWeakPtr); FOnFrameSizeChanged OnFrameSizeChanged; private: // Our class to keep window and texture information. Use of this struct prevents SWindow properties being updated composition as well // as preventing deletion of our staging textures pre composition class FTexturedWindow { public: FTexturedWindow(FVector2D InPositionInScreen, FVector2D InSizeInScreen, float InOpacity, EWindowType InType, SWindow* InOwningWindow) : PositionInScreen(InPositionInScreen), SizeInScreen(InSizeInScreen), Opacity(InOpacity), Type(InType), Texture(nullptr), OwningWindow(InOwningWindow) { } FVector2D GetPositionInScreen() { return PositionInScreen; } FVector2D GetSizeInScreen() { return SizeInScreen; } float GetOpacity() { return Opacity; } EWindowType GetType() { return Type; } SWindow* GetOwningWindow() { return OwningWindow; } TRefCountPtr& GetTexture() { return Texture; } void SetTexture(TRefCountPtr InTexture) { Texture = InTexture; } private: FVector2D PositionInScreen; FVector2D SizeInScreen; float Opacity; EWindowType Type; TRefCountPtr Texture; SWindow* OwningWindow; }; private: FVideoProducerBackBufferComposited(); void CompositeWindows(TSharedPtr UserData); void OnBackBufferReady(SWindow& SlateWindow, const FTextureRHIRef& FrameBuffer); void OnPreTick(float DeltaTime); FDelegateHandle OnBackBufferReadyToPresentHandle; FDelegateHandle OnPreTickHandle; TArray TopLevelWindows; FCriticalSection TopLevelWindowsCriticalSection; TSharedPtr SharedFrameRect; private: // Util functions for 2D vectors template T VectorMax(const T A, const T B) { // Returns the component-wise maximum of two vectors return T(FMath::Max(A.X, B.X), FMath::Max(A.Y, B.Y)); } template T VectorMin(const T A, const T B) { // Returns the component-wise minimum of two vectors return T(FMath::Min(A.X, B.X), FMath::Min(A.Y, B.Y)); } }; } // namespace UE::EditorPixelStreaming2