Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@
x:Class="moonlight_xbox_dx.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:moonlight_xbox_dx">
xmlns:local="using:moonlight_xbox_dx"
xmlns:controls="using:Microsoft.UI.Xaml.Controls">

<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

<controls:XamlControlsResources />

<ResourceDictionary Source="ms-appx:///UI/Styles/Colors.xaml"/>
<ResourceDictionary Source="ms-appx:///UI/Styles/Controls.xaml"/>

</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
72 changes: 51 additions & 21 deletions App.xaml.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//
//
// App.xaml.cpp
// Implementation of the App class.
//

#include "pch.h"
#define MLOG_TAG_OVERRIDE "App"
#include <Utils.hpp>
#include "MoonlightWelcome.xaml.h"
#include "UI\Pages\MoonlightWelcome.xaml.h"
#include "UI\Pages\MoonlightSettings.xaml.h"
#include "UI\Utilities\XamlHelpers.h"
#include "UI\Utilities\ToastService.h"

using namespace moonlight_xbox_dx;

Expand All @@ -23,17 +27,47 @@ using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::Xaml::Media::Animation;

static Windows::UI::Xaml::Controls::Frame^ s_rootFrame = nullptr;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
{
InitializeComponent();
Utils::InitFileLogging();
Utils::InstallCrashHandlers();
RequiresPointerMode = Windows::UI::Xaml::ApplicationRequiresPointerMode::WhenRequested;
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
displayRequest = ref new Windows::System::Display::DisplayRequest();

this->UnhandledException += ref new Windows::UI::Xaml::UnhandledExceptionEventHandler(
[](Platform::Object^, Windows::UI::Xaml::UnhandledExceptionEventArgs^ e) {
try {
if (e != nullptr && e->Message != nullptr) {
std::wstring msg = e->Message->Data();
MLOGF(Utils::LogLevel::Error, "Unhandled XAML exception: %S", msg.c_str());
}
} catch (...) {}
try { if (e != nullptr) e->Handled = true; } catch (...) {}
});

GlobalMenuItems = ref new Platform::Collections::Vector<moonlight_xbox_dx::MenuItem^>();
GlobalMenuItems->Append(ref new moonlight_xbox_dx::MenuItem(
ref new Platform::String(L"App Settings"),
ref new Platform::String(L""),
ref new Windows::Foundation::EventHandler<Platform::Object^>([](Platform::Object^ s, Platform::Object^ e) {
try {
if (s_rootFrame != nullptr) {
s_rootFrame->Navigate(Windows::UI::Xaml::Interop::TypeName(MoonlightSettings::typeid), nullptr, ref new Windows::UI::Xaml::Media::Animation::EntranceNavigationTransitionInfo());
}
} catch(...) {}
})
));
}

/// <summary>
Expand All @@ -50,34 +84,27 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent
// DebugSettings->EnableFrameRateCounter = true;
// }
// #endif
moonlight_xbox_dx::Utils::Log("Hello from Moonlight!\n");
auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
MLOG(moonlight_xbox_dx::Utils::LogLevel::Info, "Hello from Moonlight!\n");

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == nullptr)
if (s_rootFrame == nullptr)
{
// Create a Frame to act as the navigation context and associate it with
// a SuspensionManager key
rootFrame = ref new Frame();

rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed);
s_rootFrame = ref new Frame();
s_rootFrame->NavigationFailed += ref new NavigationFailedEventHandler(this, &App::OnNavigationFailed);

// Place the frame in the current Window
Window::Current->Content = rootFrame;
auto rootGrid = ref new Grid();
rootGrid->Children->Append(s_rootFrame);
InitializeToastService(rootGrid);
Window::Current->Content = rootGrid;
}

if (rootFrame->Content == nullptr)
if (s_rootFrame->Content == nullptr)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame->Navigate(TypeName(HostSelectorPage::typeid), e->Arguments);
s_rootFrame->Navigate(TypeName(HostSelectorPage::typeid), e->Arguments, ref new Windows::UI::Xaml::Media::Animation::SuppressNavigationTransitionInfo());
}

if (m_menuPage == nullptr)
{
m_menuPage = dynamic_cast<HostSelectorPage^>(rootFrame->Content);
m_menuPage = dynamic_cast<HostSelectorPage^>(s_rootFrame->Content);
}
// Ensure the current window is active
Window::Current->Activate();
Expand Down Expand Up @@ -127,6 +154,9 @@ void App::OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Naviga
dialog->Content = e->Exception.ToString();
dialog->CloseButtonText = L"OK";
dialog->ShowAsync();
//throw ref new FailureException("Failed to load Page " + e->SourcePageType.Name);
}

Windows::UI::Xaml::Controls::Frame^ App::GetRootFrame()
{
return s_rootFrame;
}
9 changes: 7 additions & 2 deletions App.xaml.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//
//
// App.xaml.h
// Declaration of the App class.
//

#pragma once

#include "App.g.h"
#include <Pages\HostSelectorPage.xaml.h>
#include "UI\Models\MenuItem.h"
#include "UI\Pages\HostSelectorPage.xaml.h"

namespace moonlight_xbox_dx
{
Expand All @@ -17,6 +18,10 @@ namespace moonlight_xbox_dx
{
public:
App();

static Windows::UI::Xaml::Controls::Frame^ GetRootFrame();

property Windows::Foundation::Collections::IObservableVector<moonlight_xbox_dx::MenuItem^>^ GlobalMenuItems;
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override;
void OnStateLoaded();
private:
Expand Down
Binary file modified Assets/LargeTile.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/LargeTile.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/LargeTile.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/LargeTile.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/LargeTile.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Play1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SmallTile.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SmallTile.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SmallTile.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SmallTile.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SmallTile.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SplashScreen.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SplashScreen.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SplashScreen.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SplashScreen.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/SplashScreen.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square150x150Logo.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square150x150Logo.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square150x150Logo.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square150x150Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square150x150Logo.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square44x44Logo.altform-lightunplated_targetsize-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square44x44Logo.altform-lightunplated_targetsize-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square44x44Logo.altform-lightunplated_targetsize-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square44x44Logo.altform-lightunplated_targetsize-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Square44x44Logo.altform-lightunplated_targetsize-48.png
Binary file modified Assets/Square44x44Logo.altform-unplated_targetsize-16.png
Binary file modified Assets/Square44x44Logo.altform-unplated_targetsize-256.png
Binary file modified Assets/Square44x44Logo.altform-unplated_targetsize-32.png
Binary file modified Assets/Square44x44Logo.altform-unplated_targetsize-48.png
Binary file modified Assets/Square44x44Logo.scale-100.png
Binary file modified Assets/Square44x44Logo.scale-125.png
Binary file modified Assets/Square44x44Logo.scale-150.png
Binary file modified Assets/Square44x44Logo.scale-200.png
Binary file modified Assets/Square44x44Logo.scale-400.png
Binary file modified Assets/Square44x44Logo.targetsize-16.png
Binary file modified Assets/Square44x44Logo.targetsize-24.png
Binary file modified Assets/Square44x44Logo.targetsize-24_altform-unplated.png
Binary file modified Assets/Square44x44Logo.targetsize-256.png
Binary file modified Assets/Square44x44Logo.targetsize-32.png
Binary file modified Assets/Square44x44Logo.targetsize-48.png
Binary file modified Assets/StoreLogo.scale-100.png
Binary file modified Assets/StoreLogo.scale-125.png
Binary file modified Assets/StoreLogo.scale-150.png
Binary file modified Assets/StoreLogo.scale-200.png
Binary file modified Assets/StoreLogo.scale-400.png
Binary file modified Assets/Wide310x150Logo.scale-100.png
Binary file modified Assets/Wide310x150Logo.scale-125.png
Binary file modified Assets/Wide310x150Logo.scale-150.png
Binary file modified Assets/Wide310x150Logo.scale-200.png
Binary file modified Assets/Wide310x150Logo.scale-400.png
Binary file added Assets/grid.png
Binary file added Assets/loading2.gif
Binary file added Assets/logo1.gif
Binary file added Assets/logo1.png
Binary file added Assets/logo2.gif
Binary file added Assets/logo_a.gif
Binary file added Assets/orbit_load.gif
Binary file added Assets/orbit_load2.gif
Binary file added Assets/orbit_load3.gif
Binary file added Assets/play.png
21 changes: 11 additions & 10 deletions Common/DeviceResources.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "pch.h"
#include "DeviceResources.h"
#define MLOG_TAG_OVERRIDE "DeviceResources"
#include "Utils.hpp"
#include "DirectXHelper.h"
#include "UI\Utilities\EffectsLibrary.h"
#include <windows.ui.xaml.media.dxinterop.h>
#include <winrt/Windows.UI.Core.h>
#include <Pages/StreamPage.xaml.h>
#include <Streaming/FFmpegDecoder.h>
#include <Plot/ImGuiPlots.h>
#include "UI\Pages\StreamPage.xaml.h"
#include "Streaming\FFmpegDecoder.h"
#include "Plot\ImGuiPlots.h"

using namespace moonlight_xbox_dx;
using namespace D2D1;
Expand Down Expand Up @@ -220,7 +223,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources()
0
);

Utils::Logf("m_swapChain->ResizeBuffers(%d x %d)\n",
MLOGF(Utils::LogLevel::Info, "m_swapChain->ResizeBuffers(%d x %d)\n",
lround(m_d3dRenderTargetSize.Width), lround(m_d3dRenderTargetSize.Height));

if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
Expand Down Expand Up @@ -286,7 +289,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources()
)
);

Utils::Logf("CreateSwapChainForComposition(%d x %d)\n",
MLOGF(Utils::LogLevel::Info, "CreateSwapChainForComposition(%d x %d)\n",
lround(m_d3dRenderTargetSize.Width), lround(m_d3dRenderTargetSize.Height));

DX::ThrowIfFailed(
Expand Down Expand Up @@ -374,9 +377,6 @@ void DX::DeviceResources::SetSwapChainPanel(SwapChainPanel^ panel)
m_compositionScaleX = panel->CompositionScaleX;
m_compositionScaleY = panel->CompositionScaleY;

Utils::Logf("SwapChain logical size: %.0fx%.0f @ composition scale %.1fx%.1f\n",
m_logicalSize.Width, m_logicalSize.Height, m_compositionScaleX, m_compositionScaleY);

CreateWindowSizeDependentResources();

ComPtr<ISwapChainPanelNative> panelNative;
Expand All @@ -387,6 +387,7 @@ void DX::DeviceResources::SetSwapChainPanel(SwapChainPanel^ panel)
// Setup Dear ImGui context
float dpi = currentDisplayInformation->LogicalDpi / 96.0f;
ImGui_Init(panelNative, dpi);

}

// This method is called in the event handler for the SizeChanged event.
Expand Down Expand Up @@ -490,7 +491,7 @@ void DX::DeviceResources::HandleDeviceLost()

m_swapChain = nullptr;

Utils::Log("HandleDeviceLost()\n");
MLOG(Utils::LogLevel::Error, "HandleDeviceLost()\n");

if (m_deviceNotify != nullptr)
{
Expand Down Expand Up @@ -541,7 +542,7 @@ void DX::DeviceResources::Present()
}
else if (hr == DXGI_ERROR_INVALID_CALL) {
// Try to reset
Utils::Logf("Present() failed with DXGI_ERROR_INVALID_CALL\n");
MLOGF(Utils::LogLevel::Error, "Present() failed with DXGI_ERROR_INVALID_CALL\n");
HandleDeviceLost();
}
else {
Expand Down
4 changes: 2 additions & 2 deletions Common/DirectXHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace DX
// Set a breakpoint on this line to catch Win32 API errors.
char msg[4096];
sprintf(msg, "Got generic error from HRESULT: %x\n", hr);
moonlight_xbox_dx::Utils::Log(msg);
moonlight_xbox_dx::Utils::Log(moonlight_xbox_dx::Utils::LogLevel::Error, msg);

throw Platform::Exception::CreateException(hr);
}
Expand All @@ -25,7 +25,7 @@ namespace DX
// Set a breakpoint on this line to catch Win32 API errors.
char msg[4096];
sprintf(msg, "Got generic error from %s: %x\n", reason, hr);
moonlight_xbox_dx::Utils::Log(msg);
moonlight_xbox_dx::Utils::Log(moonlight_xbox_dx::Utils::LogLevel::Error, msg);

throw Platform::Exception::CreateException(hr);
}
Expand Down
Binary file removed Common/ModalDialog.xaml
Binary file not shown.
Binary file removed Common/ModalDialog.xaml.cpp
Binary file not shown.
Binary file removed Common/ModalDialog.xaml.h
Binary file not shown.
44 changes: 42 additions & 2 deletions Common/TextConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "pch.h"
#include "TextConsole.h"
#define MLOG_TAG_OVERRIDE "TextConsole"
#include "../Utils.hpp"

#include "SimpleMath.h"
Expand All @@ -28,6 +29,7 @@ using namespace moonlight_xbox_dx;
TextConsole::TextConsole() noexcept
: m_layout{},
m_textColor(1.f, 1.f, 1.f, 1.f),
m_currentWriteColor(1.f, 1.f, 1.f, 1.f),
m_debugOutput(false),
m_columns(0),
m_rows(0)
Expand All @@ -40,6 +42,7 @@ _Use_decl_annotations_
TextConsole::TextConsole(ID3D11DeviceContext* context, const wchar_t* fontName) noexcept(false)
: m_layout{},
m_textColor(1.f, 1.f, 1.f, 1.f),
m_currentWriteColor(1.f, 1.f, 1.f, 1.f),
m_debugOutput(false),
m_columns(0),
m_rows(0),
Expand All @@ -63,7 +66,7 @@ void TextConsole::Render()
const float x = float(m_layout.left);
const float y = float(m_layout.top);

const XMVECTOR color = XMLoadFloat4(&m_textColor);
const XMVECTOR defaultColor = XMLoadFloat4(&m_textColor);

m_batch->Begin();

Expand All @@ -75,6 +78,7 @@ void TextConsole::Render()

if (*m_lines[textLine])
{
const XMVECTOR color = m_lineColors ? XMLoadFloat4(&m_lineColors[textLine]) : defaultColor;
m_font->DrawString(m_batch.get(), m_lines[textLine], pos, color);
}

Expand Down Expand Up @@ -103,6 +107,23 @@ void TextConsole::Write(const wchar_t* str)
{
std::lock_guard<std::mutex> lock(m_mutex);

m_currentWriteColor = m_textColor;
ProcessString(str);

#ifndef NDEBUG
if (m_debugOutput)
{
OutputDebugStringW(str);
}
#endif
}

_Use_decl_annotations_
void XM_CALLCONV TextConsole::Write(const wchar_t* str, DirectX::FXMVECTOR color)
{
std::lock_guard<std::mutex> lock(m_mutex);

XMStoreFloat4(&m_currentWriteColor, color);
ProcessString(str);

#ifndef NDEBUG
Expand All @@ -119,6 +140,7 @@ void TextConsole::WriteLine(const wchar_t* str)
{
std::lock_guard<std::mutex> lock(m_mutex);

m_currentWriteColor = m_textColor;
ProcessString(str);
IncrementLine();

Expand Down Expand Up @@ -151,6 +173,7 @@ void TextConsole::Format(const wchar_t* strFormat, ...)

va_end(argList);

m_currentWriteColor = m_textColor;
ProcessString(m_tempBuffer.data());

#ifndef NDEBUG
Expand Down Expand Up @@ -185,6 +208,12 @@ void TextConsole::SetWindow(const RECT& layout)
lines[line] = buffer.get() + (columns + 1) * line;
}

auto lineColors = std::make_unique<XMFLOAT4[]>(rows);
for (unsigned int line = 0; line < rows; ++line)
{
lineColors[line] = m_textColor;
}

if (m_lines)
{
const unsigned int c = std::min<unsigned int>(columns, m_columns);
Expand All @@ -194,14 +223,23 @@ void TextConsole::SetWindow(const RECT& layout)
{
memcpy(lines[line], m_lines[line], c * sizeof(wchar_t));
}

if (m_lineColors)
{
for (unsigned int line = 0; line < r; ++line)
{
lineColors[line] = m_lineColors[line];
}
}
}

std::swap(columns, m_columns);
std::swap(rows, m_rows);
std::swap(buffer, m_buffer);
std::swap(lines, m_lines);
std::swap(lineColors, m_lineColors);

Utils::Logf("TextConsole initialized at (%d,%d) - (%d,%d) with %u rows, %u columns\n",
MLOGF(Utils::LogLevel::Info, "TextConsole initialized at (%d,%d) - (%d,%d) with %u rows, %u columns\n",
layout.left, layout.top, layout.right, layout.bottom, m_rows, m_columns);

if ((m_currentColumn >= m_columns) || (m_currentLine >= m_rows))
Expand Down Expand Up @@ -283,6 +321,8 @@ void TextConsole::ProcessString(_In_z_ const wchar_t* str)

bool increment = false;

if (m_lineColors) m_lineColors[m_currentLine] = m_currentWriteColor;

if (m_currentColumn >= m_columns)
{
increment = true;
Expand Down
Loading