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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,4 @@ __pycache__/
*.pyc

Dependencies
/CoreWindowHost/Generated Files/winrt
/**/Generated Files/*
20 changes: 20 additions & 0 deletions AngleHosting.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XamlHost", "XamlHost\XamlHost.vcxproj", "{52ADD126-DE01-4344-BD72-99914F83EFD7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Expand Down Expand Up @@ -74,6 +76,24 @@ Global
{5B8FEAB1-1415-446E-AFB0-95E42281D081}.Release|x86.ActiveCfg = Release|Win32
{5B8FEAB1-1415-446E-AFB0-95E42281D081}.Release|x86.Build.0 = Release|Win32
{5B8FEAB1-1415-446E-AFB0-95E42281D081}.Release|x86.Deploy.0 = Release|Win32
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|ARM.ActiveCfg = Debug|ARM
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|ARM.Build.0 = Debug|ARM
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|ARM.Deploy.0 = Debug|ARM
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|x64.ActiveCfg = Debug|x64
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|x64.Build.0 = Debug|x64
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|x64.Deploy.0 = Debug|x64
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|x86.ActiveCfg = Debug|Win32
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|x86.Build.0 = Debug|Win32
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Debug|x86.Deploy.0 = Debug|Win32
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|ARM.ActiveCfg = Release|ARM
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|ARM.Build.0 = Release|ARM
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|ARM.Deploy.0 = Release|ARM
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|x64.ActiveCfg = Release|x64
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|x64.Build.0 = Release|x64
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|x64.Deploy.0 = Release|x64
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|x86.ActiveCfg = Release|Win32
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|x86.Build.0 = Release|Win32
{52ADD126-DE01-4344-BD72-99914F83EFD7}.Release|x86.Deploy.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 5 additions & 1 deletion AngleRenderer/AngleSpriteRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ AngleSpriteRenderer::~AngleSpriteRenderer() {

void AngleSpriteRenderer::Start(const winrt::Windows::UI::Composition::SpriteVisual & withVisual) {
mRender->Start(withVisual);
}
}

void AngleSpriteRenderer::Start(const winrt::Windows::UI::Xaml::Controls::SwapChainPanel & panel) {
mRender->Start(panel);
}
13 changes: 12 additions & 1 deletion AngleRenderer/AngleSpriteRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ void AngleSpriteRendererPrivate::Start(const SpriteVisual & withVisual) {
StartRenderLoop();
}

void AngleSpriteRendererPrivate::Start(const SwapChainPanel& panel) {
mSwapChainPanel = panel;
CreateRenderSurface();
StartRenderLoop();
}

void AngleSpriteRendererPrivate::CreateRenderSurface()
{
if (mOpenGLES && mRenderSurface == EGL_NO_SURFACE)
{
mRenderSurface = mOpenGLES->CreateSurface(mHostVisual);
if (mHostVisual != nullptr) {
mRenderSurface = mOpenGLES->CreateSurface(mHostVisual);
}
else {
mRenderSurface = mOpenGLES->CreateSurface(mSwapChainPanel);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions AngleRenderer/AngleSpriteRendererImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ using namespace winrt;
using namespace Concurrency;
using namespace Windows::Foundation;
using namespace Windows::UI::Composition;
using namespace Windows::UI::Xaml::Controls;

class AngleSpriteRendererPrivate
{
public:
AngleSpriteRendererPrivate();
~AngleSpriteRendererPrivate();
void Start(const SpriteVisual & withVisual);
void Start(const SwapChainPanel& panel);
private:
void CreateRenderSurface();
void DestroyRenderSurface();
Expand All @@ -25,5 +27,6 @@ class AngleSpriteRendererPrivate
Concurrency::critical_section mRenderSurfaceCriticalSection;
IAsyncAction mRenderLoopWorker;
SpriteVisual mHostVisual{nullptr};
SwapChainPanel mSwapChainPanel{nullptr};
};

19 changes: 19 additions & 0 deletions AngleRenderer/OpenGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ EGLSurface OpenGLES::CreateSurface(winrt::Windows::UI::Composition::ISpriteVisua
return surface;
}

EGLSurface OpenGLES::CreateSurface(const winrt::Windows::UI::Xaml::Controls::SwapChainPanel& panel)
{
EGLSurface surface = EGL_NO_SURFACE;

const EGLint surfaceAttributes[] = {
// EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER is part of the same optimization as EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER (see above).
// If you have compilation issues with it then please update your Visual Studio templates.
// EGL_RENDER_BUFFER, EGL_BACK_BUFFER,
EGL_NONE
};

surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, static_cast<EGLNativeWindowType>(winrt::get_abi(panel)), nullptr);
if (surface == EGL_NO_SURFACE) {
throw hresult_error(E_FAIL, L"Failed to create EGL surface");
}

return surface;
}

void OpenGLES::GetSurfaceDimensions(const EGLSurface surface, EGLint* width, EGLint* height)
{
eglQuerySurface(mEglDisplay, surface, EGL_WIDTH, width);
Expand Down
1 change: 1 addition & 0 deletions AngleRenderer/OpenGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class OpenGLES
~OpenGLES();

EGLSurface CreateSurface(winrt::Windows::UI::Composition::ISpriteVisual & visual);
EGLSurface CreateSurface(const winrt::Windows::UI::Xaml::Controls::SwapChainPanel & panel);
void GetSurfaceDimensions(const EGLSurface surface, EGLint *width, EGLint *height);
void DestroySurface(const EGLSurface surface);
void MakeCurrent(const EGLSurface surface);
Expand Down
4 changes: 3 additions & 1 deletion AngleRenderer/inc/AngleSpriteRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <winrt/Windows.UI.Composition.h>
#include <winrt/Windows.UI.Xaml.Controls.h>

class AngleSpriteRendererPrivate;
class AngleSpriteRenderer {
Expand All @@ -9,7 +10,8 @@ class AngleSpriteRenderer {

~AngleSpriteRenderer();

void Start(const winrt::Windows::UI::Composition::SpriteVisual & withVisual);
void Start(const winrt::Windows::UI::Composition::SpriteVisual& withVisual);
void Start(const winrt::Windows::UI::Xaml::Controls::SwapChainPanel& panel);
private:
AngleSpriteRendererPrivate * mRender{ nullptr };
};
Binary file modified AngleRenderer/pch.h
Binary file not shown.
119 changes: 119 additions & 0 deletions XamlHost/App.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include "pch.h"

#include "App.h"
#include "OpenGlPage.h"

using namespace winrt;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace XamlHost;
using namespace XamlHost::implementation;

/// <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();
Suspending({ this, &App::OnSuspending });

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e)
{
if (IsDebuggerPresent())
{
auto errorMessage = e.Message();
__debugbreak();
}
});
#endif
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void App::OnLaunched(LaunchActivatedEventArgs const& e)
{
Frame rootFrame{ nullptr };
auto content = Window::Current().Content();
if (content)
{
rootFrame = content.try_as<Frame>();
}

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

rootFrame.NavigationFailed({ this, &App::OnNavigationFailed });

if (e.PreviousExecutionState() == ApplicationExecutionState::Terminated)
{
// Restore the saved session state only when appropriate, scheduling the
// final launch steps after the restore is complete
}

if (e.PrelaunchActivated() == false)
{
if (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(xaml_typename<XamlHost::OpenGlPage>(), box_value(e.Arguments()));
}
// Place the frame in the current Window
Window::Current().Content(rootFrame);
// Ensure the current window is active
Window::Current().Activate();
}
}
else
{
if (e.PrelaunchActivated() == false)
{
if (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(xaml_typename<XamlHost::OpenGlPage>(), box_value(e.Arguments()));
}
// Ensure the current window is active
Window::Current().Activate();
}
}
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
void App::OnSuspending([[maybe_unused]] IInspectable const& sender, [[maybe_unused]] SuspendingEventArgs const& e)
{
// Save application state and stop any background activity
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void App::OnNavigationFailed(IInspectable const&, NavigationFailedEventArgs const& e)
{
throw hresult_error(E_FAIL, hstring(L"Failed to load Page ") + e.SourcePageType().Name);
}
14 changes: 14 additions & 0 deletions XamlHost/App.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "App.xaml.g.h"

namespace winrt::XamlHost::implementation
{
struct App : AppT<App>
{
App();

void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs const&);
void OnSuspending(IInspectable const&, Windows::ApplicationModel::SuspendingEventArgs const&);
void OnNavigationFailed(IInspectable const&, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs const&);
};
}
3 changes: 3 additions & 0 deletions XamlHost/App.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace XamlHost
{
}
7 changes: 7 additions & 0 deletions XamlHost/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Application
x:Class="XamlHost.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlHost">

</Application>
Binary file added XamlHost/Assets/LockScreenLogo.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 added XamlHost/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 added XamlHost/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 added XamlHost/Assets/Square44x44Logo.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.
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 XamlHost/Assets/StoreLogo.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 XamlHost/Assets/Wide310x150Logo.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.
29 changes: 29 additions & 0 deletions XamlHost/OpenGlPage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "pch.h"
#include "OpenGlPage.h"
#include "OpenGlPage.g.cpp"

using namespace winrt;

using namespace Windows;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Foundation::Numerics;
using namespace Windows::UI;
using namespace Windows::UI::Core;
using namespace Windows::UI::Composition;
using namespace Windows::UI::Xaml::Controls;

namespace winrt::XamlHost::implementation
{
OpenGlPage::OpenGlPage()
{
InitializeComponent();
AddVisual();
}

void OpenGlPage::AddVisual()
{
SwapChainPanel panel;
Content(panel);
m_render.Start(panel);
}
}
25 changes: 25 additions & 0 deletions XamlHost/OpenGlPage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "OpenGlPage.g.h"

namespace winrt::XamlHost::implementation
{
struct OpenGlPage : OpenGlPageT<OpenGlPage>
{
OpenGlPage();

private:
void AddVisual();

winrt::Windows::UI::Composition::CompositionTarget m_target{ nullptr };
winrt::Windows::UI::Composition::VisualCollection m_visuals{ nullptr };
AngleSpriteRenderer m_render;
};
}

namespace winrt::XamlHost::factory_implementation
{
struct OpenGlPage : OpenGlPageT<OpenGlPage, implementation::OpenGlPage>
{
};
}
8 changes: 8 additions & 0 deletions XamlHost/OpenGlPage.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace XamlHost
{
[default_interface]
runtimeclass OpenGlPage : Windows.UI.Xaml.Controls.Page
{
OpenGlPage();
}
}
10 changes: 10 additions & 0 deletions XamlHost/OpenGlPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Page
x:Class="XamlHost.OpenGlPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlHost"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

</Page>
Loading