Commit 99d0463c by James Clarke Committed by Commit Bot

Windows: add support for SpriteVisuals as a native window type.

Enable SpriteVisuals to work along side HWNDs so that Angle rendered content can be hosted with Windows::UI::Composition APIs or XamlIslands in desktop Win32 applications. Includes a whitebox test, verified Win7 compatibility For more info see: https://docs.google.com/document/d/1ggv6H-aK1a3pXNMTtMF6h0Bv0rulIeBpBxBBCJYR6Zs/edit?usp=sharing Bug: angleproject:2947 Change-Id: Id005739553be2a6268cd4543f1b07aaf89760422 Reviewed-on: https://chromium-review.googlesource.com/c/1236844 Commit-Queue: James Clarke <james.clarke@microsoft.com> Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent a6e8a0c5
......@@ -109,6 +109,7 @@ Microsoft Corporation
Minmin Gong
Shawn Hargreaves
Rafael Cintron
James Clarke
Microsoft Open Technologies, Inc.
Cooper Partin
......
......@@ -1342,6 +1342,7 @@ DisplayExtensions::DisplayExtensions()
getAllProcAddresses(false),
flexibleSurfaceCompatibility(false),
directComposition(false),
windowsUIComposition(false),
createContextNoError(false),
stream(false),
streamConsumerGLTexture(false),
......@@ -1380,6 +1381,7 @@ std::vector<std::string> DisplayExtensions::getStrings() const
InsertExtensionString("EGL_ANGLE_keyed_mutex", keyedMutex, &extensionStrings);
InsertExtensionString("EGL_ANGLE_surface_orientation", surfaceOrientation, &extensionStrings);
InsertExtensionString("EGL_ANGLE_direct_composition", directComposition, &extensionStrings);
InsertExtensionString("EGL_ANGLE_windows_ui_composition", windowsUIComposition, &extensionStrings);
InsertExtensionString("EGL_NV_post_sub_buffer", postSubBuffer, &extensionStrings);
InsertExtensionString("EGL_KHR_create_context", createContext, &extensionStrings);
InsertExtensionString("EGL_EXT_device_query", deviceQuery, &extensionStrings);
......
......@@ -751,6 +751,9 @@ struct DisplayExtensions
// EGL_ANGLE_direct_composition
bool directComposition;
// EGL_ANGLE_windows_ui_composition
bool windowsUIComposition;
// KHR_create_context_no_error
bool createContextNoError;
......
......@@ -64,6 +64,7 @@
#ifdef ANGLE_ENABLE_WINDOWS_STORE
#include "libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h"
#else
#include "libANGLE/renderer/d3d/d3d11/converged/CompositorNativeWindow11.h"
#include "libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h"
#endif
......@@ -1186,6 +1187,12 @@ void Renderer11::generateDisplayExtensions(egl::DisplayExtensions *outExtensions
// All D3D feature levels support robust resource init
outExtensions->robustResourceInitialization = true;
// Compositor Native Window capabilies require WinVer >= 1803
if (CompositorNativeWindow11::IsSupportedWinRelease())
{
outExtensions->windowsUIComposition = true;
}
}
angle::Result Renderer11::flush(Context11 *context11)
......@@ -1240,10 +1247,18 @@ angle::Result Renderer11::finish(Context11 *context11)
bool Renderer11::isValidNativeWindow(EGLNativeWindowType window) const
{
static_assert(sizeof(ABI::Windows::UI::Composition::SpriteVisual *) == sizeof(HWND),
"Pointer size must match Window Handle size");
#ifdef ANGLE_ENABLE_WINDOWS_STORE
return NativeWindow11WinRT::IsValidNativeWindow(window);
#else
return NativeWindow11Win32::IsValidNativeWindow(window);
if (NativeWindow11Win32::IsValidNativeWindow(window))
{
return true;
}
return CompositorNativeWindow11::IsValidNativeWindow(window);
#endif
}
......@@ -1251,14 +1266,23 @@ NativeWindowD3D *Renderer11::createNativeWindow(EGLNativeWindowType window,
const egl::Config *config,
const egl::AttributeMap &attribs) const
{
auto useWinUiComp = !NativeWindow11Win32::IsValidNativeWindow(window);
if (useWinUiComp)
{
return new CompositorNativeWindow11(window, config->alphaSize > 0);
}
else
{
#ifdef ANGLE_ENABLE_WINDOWS_STORE
ANGLE_UNUSED_VARIABLE(attribs);
UNUSED_VARIABLE(attribs);
return new NativeWindow11WinRT(window, config->alphaSize > 0);
#else
return new NativeWindow11Win32(
window, config->alphaSize > 0,
attribs.get(EGL_DIRECT_COMPOSITION_ANGLE, EGL_FALSE) == EGL_TRUE);
#endif
}
}
egl::Error Renderer11::getD3DTextureInfo(const egl::Config *configuration,
......
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CompositorNativeWindow11.h: Implementation of NativeWindow11 using Windows.UI.Composition APIs
// which work in both Win32 and WinRT contexts.
#ifndef LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_
#define LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_
#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h"
#include <DispatcherQueue.h>
#include <VersionHelpers.h>
#include <Windows.ui.composition.interop.h>
#include <windows.foundation.metadata.h>
#include <windows.ui.composition.h>
#include <wrl.h>
namespace rx
{
class RoHelper
{
public:
RoHelper();
~RoHelper();
bool WinRtAvailable() const;
bool SupportedWindowsRelease();
HRESULT GetStringReference(PCWSTR source, HSTRING *act, HSTRING_HEADER *header);
HRESULT GetActivationFactory(const HSTRING act, const IID &interfaceId, void **fac);
HRESULT WindowsCompareStringOrdinal(HSTRING one, HSTRING two, int *result);
HRESULT CreateDispatcherQueueController(
DispatcherQueueOptions options,
ABI::Windows::System::IDispatcherQueueController **dispatcherQueueController);
HRESULT WindowsDeleteString(HSTRING one);
HRESULT RoInitialize(RO_INIT_TYPE type);
void RoUninitialize();
private:
using WindowsCreateStringReference_ = HRESULT __stdcall(PCWSTR,
UINT32,
HSTRING_HEADER *,
HSTRING *);
using GetActivationFactory_ = HRESULT __stdcall(HSTRING, REFIID, void **);
using WindowsCompareStringOrginal_ = HRESULT __stdcall(HSTRING, HSTRING, int *);
using WindowsDeleteString_ = HRESULT __stdcall(HSTRING);
using CreateDispatcherQueueController_ =
HRESULT __stdcall(DispatcherQueueOptions,
ABI::Windows::System::IDispatcherQueueController **);
using RoInitialize_ = HRESULT __stdcall(RO_INIT_TYPE);
using RoUninitialize_ = void __stdcall();
WindowsCreateStringReference_ *mFpWindowsCreateStringReference;
GetActivationFactory_ *mFpGetActivationFactory;
WindowsCompareStringOrginal_ *mFpWindowsCompareStringOrdinal;
CreateDispatcherQueueController_ *mFpCreateDispatcherQueueController;
WindowsDeleteString_ *mFpWindowsDeleteString;
RoInitialize_ *mFpRoInitialize;
RoUninitialize_ *mFpRoUninitialize;
bool mWinRtAvailable;
HMODULE mComBaseModule;
HMODULE mCoreMessagingModule;
};
class CompositorNativeWindow11 : public NativeWindow11
{
public:
CompositorNativeWindow11(EGLNativeWindowType window, bool hasAlpha);
~CompositorNativeWindow11() override = default;
bool initialize() override;
bool getClientRect(LPRECT rect) const override;
bool isIconic() const override;
HRESULT createSwapChain(ID3D11Device *device,
IDXGIFactory *factory,
DXGI_FORMAT format,
UINT width,
UINT height,
UINT samples,
IDXGISwapChain **swapChain) override;
void commitChange() override;
static bool IsValidNativeWindow(EGLNativeWindowType window);
static bool IsSupportedWinRelease();
private:
static bool IsSpriteVisual(EGLNativeWindowType window);
bool mHasAlpha;
RoHelper mRoHelper;
// Namespace prefix required here for some reason despite using namespace
Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ISpriteVisual> mHostVisual;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionBrush> mCompositionBrush;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionSurface> mSurface;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Composition::ICompositionSurfaceBrush> mSurfaceBrush;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_CONVERGED_COMPOSITORNATIVEWINDOW11_H_
\ No newline at end of file
......@@ -570,6 +570,8 @@ libangle_d3d11_sources = [
libangle_d3d11_win32_sources = [
"src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.cpp",
"src/libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h",
"src/libANGLE/renderer/d3d/d3d11/converged/CompositorNativeWindow11.cpp",
"src/libANGLE/renderer/d3d/d3d11/converged/CompositorNativeWindow11.h",
"src/third_party/systeminfo/SystemInfo.cpp",
"src/third_party/systeminfo/SystemInfo.h",
]
......
......@@ -13,6 +13,7 @@ angle_white_box_tests_sources = [
"test_utils/gl_raii.h",
]
angle_white_box_tests_win_sources = [
"egl_tests/EGLDirectCompositionTest.cpp",
"gl_tests/D3D11EmulatedIndexedBufferTest.cpp",
"gl_tests/D3D11FormatTablesTest.cpp",
"gl_tests/D3D11InputLayoutCacheTest.cpp",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment