Simplify InitializeVideoRenderer()
This commit is contained in:
@@ -670,44 +670,41 @@ namespace winrt::Vav2Player::implementation
|
||||
|
||||
void VideoPlayerControl::InitializeVideoRenderer()
|
||||
{
|
||||
// Initialize rendering mode based on user selection
|
||||
if (!m_useHardwareRendering)
|
||||
{
|
||||
// Ensure software rendering UI is visible
|
||||
VideoSwapChainPanel().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Collapsed);
|
||||
VideoImage().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Visible);
|
||||
// Try hardware rendering if enabled, fallback to software
|
||||
bool useGPU = m_useHardwareRendering && TryInitializeGPURenderer();
|
||||
SetRenderingMode(useGPU);
|
||||
}
|
||||
|
||||
bool VideoPlayerControl::TryInitializeGPURenderer()
|
||||
{
|
||||
// Create GPU renderer if needed
|
||||
if (!m_gpuRenderer) {
|
||||
m_gpuRenderer = std::make_unique<SimpleGPURenderer>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hardware rendering setup
|
||||
|
||||
// Get container dimensions
|
||||
auto container = VideoDisplayArea();
|
||||
uint32_t width = static_cast<uint32_t>(container.ActualWidth());
|
||||
uint32_t height = static_cast<uint32_t>(container.ActualHeight());
|
||||
|
||||
// Container must be ready with valid dimensions
|
||||
if (width == 0 || height == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize GPU renderer
|
||||
HRESULT hr = m_gpuRenderer->InitializeWithSwapChain(VideoSwapChainPanel(), width, height);
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
void VideoPlayerControl::SetRenderingMode(bool useGPU)
|
||||
{
|
||||
if (useGPU) {
|
||||
VideoSwapChainPanel().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Visible);
|
||||
VideoImage().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Collapsed);
|
||||
|
||||
if (!m_gpuRenderer)
|
||||
{
|
||||
m_gpuRenderer = std::make_unique<SimpleGPURenderer>();
|
||||
}
|
||||
|
||||
// Initialize GPU renderer with actual container size
|
||||
auto container = VideoDisplayArea();
|
||||
uint32_t containerWidth = static_cast<uint32_t>(container.ActualWidth());
|
||||
uint32_t containerHeight = static_cast<uint32_t>(container.ActualHeight());
|
||||
|
||||
// Wait for container to be ready - don't use arbitrary fallback sizes
|
||||
if (containerWidth == 0 || containerHeight == 0) {
|
||||
// Temporarily use CPU rendering until container size is available
|
||||
VideoSwapChainPanel().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Collapsed);
|
||||
VideoImage().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Visible);
|
||||
return;
|
||||
}
|
||||
|
||||
HRESULT hr = m_gpuRenderer->InitializeWithSwapChain(VideoSwapChainPanel(), containerWidth, containerHeight);
|
||||
if (!SUCCEEDED(hr))
|
||||
{
|
||||
// GPU initialization failed - temporarily use CPU rendering
|
||||
VideoSwapChainPanel().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Collapsed);
|
||||
VideoImage().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Visible);
|
||||
}
|
||||
} else {
|
||||
VideoSwapChainPanel().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Collapsed);
|
||||
VideoImage().Visibility(winrt::Microsoft::UI::Xaml::Visibility::Visible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,8 @@ namespace winrt::Vav2Player::implementation
|
||||
|
||||
// Helper methods
|
||||
void InitializeVideoRenderer();
|
||||
bool TryInitializeGPURenderer();
|
||||
void SetRenderingMode(bool useGPU);
|
||||
void ProcessSingleFrame();
|
||||
void RenderFrameToScreen(const VideoFrame& frame);
|
||||
void RenderFrameSoftware(const VideoFrame& frame);
|
||||
|
||||
Reference in New Issue
Block a user