From 3e3c9a6129354bb70180e5e1d01ab1135a25a49e Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Fri, 16 Jul 2021 18:36:32 -0500 Subject: [PATCH] Replaced some DX9/GDI implementations with crude Skia ones --- .../Iris/Render/Internal/RenderCaps.cs | 21 +- .../Iris/Render/Internal/RenderEngine.cs | 161 +++----- .../Iris/Render/Internal/RenderSession.cs | 13 +- .../Iris/Render/Internal/SkiaRenderCaps.cs | 99 ----- .../Iris/Render/Internal/SkiaRenderEngine.cs | 224 ----------- .../Iris/Render/Internal/SkiaRenderSession.cs | 366 ------------------ .../Microsoft/Iris/Render/RenderApi.cs | 4 +- 7 files changed, 75 insertions(+), 813 deletions(-) delete mode 100644 UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderCaps.cs delete mode 100644 UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderEngine.cs delete mode 100644 UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderSession.cs diff --git a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderCaps.cs b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderCaps.cs index b1ae684..9a0ef3e 100644 --- a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderCaps.cs +++ b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderCaps.cs @@ -7,27 +7,28 @@ using Microsoft.Iris.Render.Common; using Microsoft.Iris.Render.Protocol; using Microsoft.Iris.Render.Protocols.Splash.Rendering; +using SkiaSharp; using System; namespace Microsoft.Iris.Render.Internal { - internal class RenderCaps : RenderObject, IRenderHandleOwner, IRenderCapsCallback + internal class RenderCaps : RenderObject, IRenderCapsCallback { - private RemoteRenderCaps m_remoteObject; + private SKSurface m_remoteObject; private Vector m_graphicsCapsList; private Vector m_soundCapsList; private bool m_hasValidCaps; private bool m_capsPending; private uint m_currentRequestId; - internal RenderCaps(RenderSession ownerSession) + internal RenderCaps(SKSurface skSurface) { this.m_hasValidCaps = false; this.m_capsPending = false; this.m_currentRequestId = 0U; this.m_graphicsCapsList = new Vector(); this.m_soundCapsList = new Vector(); - this.m_remoteObject = ownerSession.RenderingProtocol.BuildRemoteRenderCaps(this, ownerSession.RenderingProtocol.LocalRenderCapsCallbackHandle); + this.m_remoteObject = skSurface; } internal bool HasValidCaps => this.m_hasValidCaps; @@ -41,10 +42,14 @@ namespace Microsoft.Iris.Render.Internal if (this.m_capsPending) return; ++this.m_currentRequestId; - this.m_remoteObject.SendCheckCaps(this.m_currentRequestId); this.m_capsPending = true; - // TODO + // TODO: Is there any way to get the graphics capabilities from an SKSurface? + Graphics.Add(new GraphicsCaps + { + DeviceType = GraphicsDeviceType.Skia + }); + ((IRenderCapsCallback)this).OnEndCapsCheck(default, 0); } @@ -57,10 +62,6 @@ namespace Microsoft.Iris.Render.Internal this.CapsAvailable(this, EventArgs.Empty); } - RENDERHANDLE IRenderHandleOwner.RenderHandle => this.m_remoteObject.RenderHandle; - - void IRenderHandleOwner.OnDisconnect() => this.m_remoteObject = null; - void IRenderCapsCallback.OnBeginCapsCheck(RENDERHANDLE target, uint cookie) { this.m_graphicsCapsList.Clear(); diff --git a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderEngine.cs b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderEngine.cs index 5fa8d85..3d4f7e4 100644 --- a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderEngine.cs +++ b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderEngine.cs @@ -1,10 +1,4 @@ -// Decompiled with JetBrains decompiler -// Type: Microsoft.Iris.Render.Internal.RenderEngine -// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217 -// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1 -// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll - -using Microsoft.Iris.Library; +using Microsoft.Iris.Library; using Microsoft.Iris.Render.Common; using Microsoft.Iris.Render.Protocol; using Microsoft.Iris.Render.Sound; @@ -25,8 +19,6 @@ namespace Microsoft.Iris.Render.Internal private RenderCaps m_renderCaps; private GraphicsDeviceType m_typeGraphics; private SoundDeviceType m_typeSound; - private RenderWindow m_renderWindow; - private DisplayManager m_displayManager; private InputSystem m_inputSystem; private SoundDevice m_soundDevice; private ContextID m_localContextId; @@ -38,18 +30,14 @@ namespace Microsoft.Iris.Render.Internal { Debug2.Validate(engineInfo != null, typeof(ArgumentNullException), nameof(engineInfo)); Debug2.Validate(renderHost != null, typeof(ArgumentNullException), nameof(renderHost)); - this.m_engineInfo = engineInfo; - this.m_engineContextId = AllocateContextId(); - this.m_localContextId = AllocateContextId(); - this.m_primaryToken = new RenderToken(engineInfo, this.m_localContextId, this.m_engineContextId, RENDERGROUP.NULL); - this.m_messagingSession = new MessagingSession(renderHost, this.m_primaryToken); - this.m_messagingSession.Connect(); + m_engineInfo = engineInfo; + m_engineContextId = AllocateContextId(); + m_localContextId = AllocateContextId(); + m_primaryToken = new RenderToken(engineInfo, m_localContextId, m_engineContextId, RENDERGROUP.NULL); + m_messagingSession = new MessagingSession(renderHost, this.m_primaryToken); this.m_renderSession = new RenderSession(this); - this.m_renderCaps = new RenderCaps(this.m_renderSession); + this.m_renderCaps = new RenderCaps(engineInfo.Surface); this.m_renderCaps.RequestCaps(); - this.m_messagingSession.FlushBatch(); - while (!this.m_renderCaps.HasValidCaps) - MessagingSession.DoEvents(50U); } protected override void Dispose(bool fInDispose) @@ -58,32 +46,32 @@ namespace Microsoft.Iris.Render.Internal { if (fInDispose) { - this.m_renderSession.ReleaseSharedResources(); - if (this.m_renderWindow != null) - this.m_renderWindow.WindowCreatedEvent -= new EventHandler(this.OnRenderWindowCreated); - if (this.m_soundDevice != null) - this.m_soundDevice.Dispose(); - if (this.m_renderWindow != null) - this.m_renderWindow.Dispose(); - if (this.m_inputSystem != null) - this.m_inputSystem.Dispose(); - if (this.m_displayManager != null) - this.m_displayManager.Dispose(); - if (this.m_renderSession != null) - this.m_renderSession.Dispose(); + //this.m_renderSession.ReleaseSharedResources(); + //if (this.m_renderWindow != null) + // this.m_renderWindow.WindowCreatedEvent -= new EventHandler(OnRenderWindowCreated); + if (m_soundDevice != null) + m_soundDevice.Dispose(); + //if (this.m_renderWindow != null) + // this.m_renderWindow.Dispose(); + if (m_inputSystem != null) + m_inputSystem.Dispose(); + //if (this.m_displayManager != null) + // this.m_displayManager.Dispose(); + //if (this.m_renderSession != null) + // this.m_renderSession.Dispose(); if (this.m_messagingSession != null) { if (this.m_messagingSession.IsConnected) this.m_messagingSession.Disconnect(); this.m_messagingSession.Dispose(); } - FreeContextId(this.m_localContextId); - FreeContextId(this.m_engineContextId); + FreeContextId(m_localContextId); + FreeContextId(m_engineContextId); } - this.m_soundDevice = null; - this.m_displayManager = null; - this.m_renderWindow = null; - this.m_renderSession = null; + m_soundDevice = null; + //this.m_displayManager = null; + //this.m_renderWindow = null; + //this.m_renderSession = null; this.m_messagingSession = null; } finally @@ -98,37 +86,25 @@ namespace Microsoft.Iris.Render.Internal GraphicsRenderingQuality renderingQuality, SoundDeviceType typeSound) { - Debug2.Validate(this.m_messagingSession.IsConnected, typeof(InvalidOperationException), "Must be connected before attempting to initialize"); - Debug2.Validate(this.m_renderSession != null, typeof(ArgumentNullException), "Session must exist before calling Initialize"); - Debug2.Validate(this.IsGraphicsDeviceAvailable(typeGraphics, false), typeof(InvalidOperationException), "Graphics device type not available"); - Debug2.Validate(this.IsSoundDeviceAvailable(typeSound), typeof(InvalidOperationException), "Sound device type not available"); - this.m_renderSession.AssertOwningThread(); - this.m_typeGraphics = typeGraphics; - this.m_typeSound = typeSound; - this.m_displayManager = DisplayManager.CreateDisplayManager(this.m_renderSession, this, false); - this.m_renderWindow = new RenderWindow(this.m_renderSession, this.m_displayManager, typeGraphics, renderingQuality); - this.m_renderWindow.WindowCreatedEvent += new EventHandler(this.OnRenderWindowCreated); - this.m_renderSession.Initialize(); - this.m_inputSystem = new InputSystem(this.m_renderSession, this.m_renderWindow); + Debug2.Validate(IsGraphicsDeviceAvailable(typeGraphics, false), typeof(InvalidOperationException), "Graphics device type not available"); + Debug2.Validate(IsSoundDeviceAvailable(typeSound), typeof(InvalidOperationException), "Sound device type not available"); + m_typeGraphics = typeGraphics; + m_typeSound = typeSound; + // TODO: Set up input system + //m_inputSystem = new InputSystem(this.m_renderSession, this.m_renderWindow); } - private MessagingSession MessagingSession => this.m_messagingSession; + IRenderSession IRenderEngine.Session => null;//throw new NotSupportedException("Skia does not use render sessions"); m_renderSession; - IRenderSession IRenderEngine.Session => m_renderSession; + internal RenderSession Session => null; - internal RenderSession Session => this.m_renderSession; + IRenderWindow IRenderEngine.Window => null; - IRenderWindow IRenderEngine.Window => m_renderWindow; + IDisplayManager IRenderEngine.DisplayManager => null; - internal RenderWindow Window => this.m_renderWindow; + public InputSystem InputSystem => throw new NotImplementedException("Skia does not support input yet");// m_inputSystem; - IDisplayManager IRenderEngine.DisplayManager => m_displayManager; - - public DisplayManager DisplayManager => this.m_displayManager; - - public InputSystem InputSystem => this.m_inputSystem; - - internal SoundDevice SoundDevice => this.m_soundDevice; + internal SoundDevice SoundDevice => m_soundDevice; internal Vector GraphicsCaps => this.m_renderCaps.Graphics; @@ -136,46 +112,24 @@ namespace Microsoft.Iris.Render.Internal private void DoEvents(uint nTimeoutInMsecs) { - this.m_messagingSession.AssertOwningThread(); MessagingSession.DoEvents(nTimeoutInMsecs); } - bool IRenderEngine.ProcessNativeEvents() - { - this.m_renderSession.AssertOwningThread(); - Win32Api.MSG msg; - EngineApi.WorkResult nResult; - EngineApi.SpPeekMessage(out msg, HWND.NULL, 0U, 0U, 1U, out nResult); - if (!Bits.TestFlag((uint)nResult, 2U)) - return Bits.TestFlag((uint)nResult, 1U); - if (this.m_renderWindow != null) - this.m_renderWindow.ForwardWindowMessage(ref msg); - Win32Api.TranslateMessage(ref msg); - Win32Api.DispatchMessage(ref msg); - return true; - } - void IRenderEngine.WaitForWork(uint nTimeoutInMsecs) { - this.m_renderSession.AssertOwningThread(); EngineApi.SpWaitMessage(nTimeoutInMsecs, IntPtr.Zero); } - void IRenderEngine.InterThreadWake() => EngineApi.SpInvoke(this.m_localContextId, IntPtr.Zero, IntPtr.Zero, false); - void IRenderEngine.FlushBatch() { - this.m_renderSession.AssertOwningThread(); - this.m_messagingSession.FlushBatch(); + } bool IRenderEngine.IsGraphicsDeviceAvailable( GraphicsDeviceType type, bool fFilterRecommended) { - Debug2.Validate(this.m_renderCaps != null, typeof(ArgumentNullException), "RenderCaps must be initialized prior to calling"); - this.m_renderSession.AssertOwningThread(); - return this.IsGraphicsDeviceAvailable(type, fFilterRecommended); + return IsGraphicsDeviceAvailable(type, fFilterRecommended); } private bool IsGraphicsDeviceAvailable(GraphicsDeviceType type, bool fFilterRecommended) @@ -188,18 +142,13 @@ namespace Microsoft.Iris.Render.Internal return false; } - bool IRenderEngine.IsSoundDeviceAvailable(SoundDeviceType type) - { - Debug2.Validate(this.m_renderCaps != null, typeof(ArgumentNullException), "RenderCaps must be initialized prior to calling"); - this.m_renderSession.AssertOwningThread(); - return this.IsSoundDeviceAvailable(type); - } + bool IRenderEngine.IsSoundDeviceAvailable(SoundDeviceType type) => IsSoundDeviceAvailable(type); private bool IsSoundDeviceAvailable(SoundDeviceType type) { if (type == SoundDeviceType.None) return true; - foreach (Microsoft.Iris.Render.Internal.SoundCaps soundCaps in this.m_renderCaps.Sound) + foreach (SoundCaps soundCaps in this.m_renderCaps.Sound) { if ((SoundDeviceType)soundCaps.DeviceType == type) return true; @@ -210,21 +159,22 @@ namespace Microsoft.Iris.Render.Internal private void OnRenderWindowCreated(object sender, EventArgs args) { SoundDevice soundDevice = null; - switch (this.m_typeSound) + switch (m_typeSound) { case SoundDeviceType.None: - this.m_soundDevice = soundDevice; + m_soundDevice = soundDevice; break; case SoundDeviceType.DirectSound8: - soundDevice = new Ds8SoundDevice(this.m_renderSession, m_renderWindow); - goto case SoundDeviceType.None; + //soundDevice = new Ds8SoundDevice(this.m_renderSession, m_renderWindow); + //goto case SoundDeviceType.None; case SoundDeviceType.WaveAudio: case SoundDeviceType.XAudio: + case SoundDeviceType.XAudio2: Debug2.Validate(false, typeof(NotImplementedException), "{0} is not yet supported"); - goto case SoundDeviceType.None; + break; default: Debug2.Validate(false, typeof(ArgumentException), "typeSound"); - goto case SoundDeviceType.None; + break; } } @@ -260,10 +210,15 @@ namespace Microsoft.Iris.Render.Internal protected override void Invariant() { - Debug2.Validate(this.m_localContextId != ContextID.NULL, typeof(InvalidOperationException), "local ContextId should not be NULL while running"); - Debug2.Validate(this.m_engineContextId != ContextID.NULL, typeof(InvalidOperationException), "engine ContextId should not be NULL while running"); - Debug2.Validate(this.MessagingSession != null, typeof(InvalidOperationException), "MessagingSession should not be null while running"); - Debug2.Validate(this.MessagingSession.IsConnected, typeof(InvalidOperationException), "MessagingSession should be connected while running"); + Debug2.Validate(m_localContextId != ContextID.NULL, typeof(InvalidOperationException), "local ContextId should not be NULL while running"); + Debug2.Validate(m_engineContextId != ContextID.NULL, typeof(InvalidOperationException), "engine ContextId should not be NULL while running"); + } + + bool IRenderEngine.ProcessNativeEvents() => true; + + void IRenderEngine.InterThreadWake() + { + } } } diff --git a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderSession.cs b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderSession.cs index 8b35da1..26eacc4 100644 --- a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderSession.cs +++ b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/RenderSession.cs @@ -1,9 +1,4 @@ -// Decompiled with JetBrains decompiler -// Type: Microsoft.Iris.Render.Internal.RenderSession -// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217 -// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1 -// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll - +using Microsoft.Iris.Library; using Microsoft.Iris.Render.Animation; using Microsoft.Iris.Render.Common; using Microsoft.Iris.Render.Graphics; @@ -30,8 +25,8 @@ namespace Microsoft.Iris.Render.Internal private ProtocolSplashRendering m_protocolRenderingLocal; private AnimationSystem m_animationSystem; private ObjectCacheManager m_cacheManager; - private Microsoft.Iris.Render.Common.ObjectCache m_cacheSprite; - private Microsoft.Iris.Render.Common.ObjectCache m_cacheContainer; + private Common.ObjectCache m_cacheSprite; + private Common.ObjectCache m_cacheContainer; internal RenderSession(RenderEngine renderEngine) { @@ -189,7 +184,7 @@ namespace Microsoft.Iris.Render.Internal { foreach (GraphicsCaps graphicsCap in this.m_renderEngine.GraphicsCaps) { - if ((GraphicsDeviceType)graphicsCap.DeviceType == type) + if (graphicsCap.DeviceType.FulfillsRequirement(type)) return graphicsCap; } return new GraphicsCaps(); diff --git a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderCaps.cs b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderCaps.cs deleted file mode 100644 index 76ac14d..0000000 --- a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderCaps.cs +++ /dev/null @@ -1,99 +0,0 @@ -// Decompiled with JetBrains decompiler -// Type: Microsoft.Iris.Render.Internal.RenderCaps -// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217 -// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1 -// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll - -using Microsoft.Iris.Render.Common; -using Microsoft.Iris.Render.Protocol; -using Microsoft.Iris.Render.Protocols.Splash.Rendering; -using SkiaSharp; -using System; - -namespace Microsoft.Iris.Render.Internal -{ - internal class SkiaRenderCaps : RenderObject, IRenderCapsCallback - { - private SKSurface m_remoteObject; - private Vector m_graphicsCapsList; - private Vector m_soundCapsList; - private bool m_hasValidCaps; - private bool m_capsPending; - private uint m_currentRequestId; - - internal SkiaRenderCaps(SKSurface skSurface) - { - this.m_hasValidCaps = false; - this.m_capsPending = false; - this.m_currentRequestId = 0U; - this.m_graphicsCapsList = new Vector(); - this.m_soundCapsList = new Vector(); - this.m_remoteObject = skSurface; - } - - internal bool HasValidCaps => this.m_hasValidCaps; - - internal Vector Graphics => this.m_graphicsCapsList; - - internal Vector Sound => this.m_soundCapsList; - - internal void RequestCaps() - { - if (this.m_capsPending) - return; - ++this.m_currentRequestId; - this.m_capsPending = true; - - // TODO: Is there any way to get the graphics capabilities from an SKSurface? - Graphics.Add(new GraphicsCaps - { - DeviceType = GraphicsDeviceType.Skia - }); - - ((IRenderCapsCallback)this).OnEndCapsCheck(default, 0); - } - - internal event EventHandler CapsAvailable; - - protected void NotifyCapsAvailable() - { - if (this.CapsAvailable == null) - return; - this.CapsAvailable(this, EventArgs.Empty); - } - - void IRenderCapsCallback.OnBeginCapsCheck(RENDERHANDLE target, uint cookie) - { - this.m_graphicsCapsList.Clear(); - this.m_soundCapsList.Clear(); - this.m_hasValidCaps = false; - } - - void IRenderCapsCallback.OnEndCapsCheck(RENDERHANDLE target, uint cookie) - { - this.m_hasValidCaps = true; - this.m_capsPending = false; - this.NotifyCapsAvailable(); - } - - void IRenderCapsCallback.OnGraphicsCaps( - RENDERHANDLE target, - uint cookie, - GraphicsCaps caps) - { - if ((int)this.m_currentRequestId != (int)cookie) - return; - this.m_graphicsCapsList.Add(caps); - } - - void IRenderCapsCallback.OnSoundCaps( - RENDERHANDLE target, - uint cookie, - SoundCaps caps) - { - if ((int)this.m_currentRequestId != (int)cookie) - return; - this.m_soundCapsList.Add(caps); - } - } -} diff --git a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderEngine.cs b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderEngine.cs deleted file mode 100644 index e1eeb8b..0000000 --- a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderEngine.cs +++ /dev/null @@ -1,224 +0,0 @@ -using Microsoft.Iris.Library; -using Microsoft.Iris.Render.Common; -using Microsoft.Iris.Render.Protocol; -using Microsoft.Iris.Render.Sound; -using System; -using System.Collections; - -namespace Microsoft.Iris.Render.Internal -{ - internal class SkiaRenderEngine : RenderObject, IRenderEngine, IRenderObject, IDisposable - { - private static BitArray s_contexts; - private static uint s_contextIdSeed = 1; - private static uint s_maxContextId = 254; - private IrisEngineInfo m_engineInfo; - private RenderToken m_primaryToken; - private MessagingSession m_messagingSession; - private RenderSession m_renderSession; - private SkiaRenderCaps m_renderCaps; - private GraphicsDeviceType m_typeGraphics; - private SoundDeviceType m_typeSound; - private InputSystem m_inputSystem; - private SoundDevice m_soundDevice; - private ContextID m_localContextId; - private ContextID m_engineContextId; - - static SkiaRenderEngine() => s_contexts = new BitArray((int)s_maxContextId + 1); - - internal SkiaRenderEngine(IrisEngineInfo engineInfo, IRenderHost renderHost) - { - Debug2.Validate(engineInfo != null, typeof(ArgumentNullException), nameof(engineInfo)); - Debug2.Validate(renderHost != null, typeof(ArgumentNullException), nameof(renderHost)); - m_engineInfo = engineInfo; - m_engineContextId = AllocateContextId(); - m_localContextId = AllocateContextId(); - m_primaryToken = new RenderToken(engineInfo, m_localContextId, m_engineContextId, RENDERGROUP.NULL); - m_messagingSession = new MessagingSession(renderHost, this.m_primaryToken); - this.m_renderSession = new RenderSession(this); - this.m_renderCaps = new SkiaRenderCaps(engineInfo.Surface); - this.m_renderCaps.RequestCaps(); - } - - protected override void Dispose(bool fInDispose) - { - try - { - if (fInDispose) - { - //this.m_renderSession.ReleaseSharedResources(); - //if (this.m_renderWindow != null) - // this.m_renderWindow.WindowCreatedEvent -= new EventHandler(OnRenderWindowCreated); - if (m_soundDevice != null) - m_soundDevice.Dispose(); - //if (this.m_renderWindow != null) - // this.m_renderWindow.Dispose(); - if (m_inputSystem != null) - m_inputSystem.Dispose(); - //if (this.m_displayManager != null) - // this.m_displayManager.Dispose(); - //if (this.m_renderSession != null) - // this.m_renderSession.Dispose(); - if (this.m_messagingSession != null) - { - if (this.m_messagingSession.IsConnected) - this.m_messagingSession.Disconnect(); - this.m_messagingSession.Dispose(); - } - FreeContextId(m_localContextId); - FreeContextId(m_engineContextId); - } - m_soundDevice = null; - //this.m_displayManager = null; - //this.m_renderWindow = null; - //this.m_renderSession = null; - this.m_messagingSession = null; - } - finally - { - base.Dispose(fInDispose); - } - } - - void IRenderEngine.Initialize( - SkiaSharp.SKSurface skSurface, - GraphicsDeviceType typeGraphics, - GraphicsRenderingQuality renderingQuality, - SoundDeviceType typeSound) - { - Debug2.Validate(IsGraphicsDeviceAvailable(typeGraphics, false), typeof(InvalidOperationException), "Graphics device type not available"); - Debug2.Validate(IsSoundDeviceAvailable(typeSound), typeof(InvalidOperationException), "Sound device type not available"); - m_typeGraphics = typeGraphics; - m_typeSound = typeSound; - // TODO: Set up input system - //m_inputSystem = new InputSystem(this.m_renderSession, this.m_renderWindow); - } - - IRenderSession IRenderEngine.Session => null;//throw new NotSupportedException("Skia does not use render sessions"); m_renderSession; - - internal RenderSession Session => null; - - IRenderWindow IRenderEngine.Window => null; - - IDisplayManager IRenderEngine.DisplayManager => null; - - public InputSystem InputSystem => throw new NotImplementedException("Skia does not support input yet");// m_inputSystem; - - internal SoundDevice SoundDevice => m_soundDevice; - - internal Vector GraphicsCaps => this.m_renderCaps.Graphics; - - internal Vector SoundCaps => this.m_renderCaps.Sound; - - private void DoEvents(uint nTimeoutInMsecs) - { - MessagingSession.DoEvents(nTimeoutInMsecs); - } - - void IRenderEngine.WaitForWork(uint nTimeoutInMsecs) - { - EngineApi.SpWaitMessage(nTimeoutInMsecs, IntPtr.Zero); - } - - void IRenderEngine.FlushBatch() - { - - } - - bool IRenderEngine.IsGraphicsDeviceAvailable( - GraphicsDeviceType type, - bool fFilterRecommended) - { - return IsGraphicsDeviceAvailable(type, fFilterRecommended); - } - - private bool IsGraphicsDeviceAvailable(GraphicsDeviceType type, bool fFilterRecommended) - { - foreach (GraphicsCaps graphic in this.m_renderCaps.Graphics) - { - if (graphic.DeviceType.FulfillsRequirement(type)) - return !fFilterRecommended || graphic.DriverWarning == 0; - } - return false; - } - - bool IRenderEngine.IsSoundDeviceAvailable(SoundDeviceType type) => IsSoundDeviceAvailable(type); - - private bool IsSoundDeviceAvailable(SoundDeviceType type) - { - if (type == SoundDeviceType.None) - return true; - foreach (SoundCaps soundCaps in this.m_renderCaps.Sound) - { - if ((SoundDeviceType)soundCaps.DeviceType == type) - return true; - } - return false; - } - - private void OnRenderWindowCreated(object sender, EventArgs args) - { - SoundDevice soundDevice = null; - switch (m_typeSound) - { - case SoundDeviceType.None: - m_soundDevice = soundDevice; - break; - case SoundDeviceType.DirectSound8: - //soundDevice = new Ds8SoundDevice(this.m_renderSession, m_renderWindow); - //goto case SoundDeviceType.None; - case SoundDeviceType.WaveAudio: - case SoundDeviceType.XAudio: - case SoundDeviceType.XAudio2: - Debug2.Validate(false, typeof(NotImplementedException), "{0} is not yet supported"); - break; - default: - Debug2.Validate(false, typeof(ArgumentException), "typeSound"); - break; - } - } - - internal static ContextID AllocateContextId() - { - uint num1 = 0; - lock (s_contexts) - { - for (int index = 0; index < s_maxContextId; ++index) - { - uint num2 = s_contextIdSeed++; - if (s_contextIdSeed > s_maxContextId) - s_contextIdSeed = 1U; - if (!s_contexts[(int)num2]) - { - num1 = num2; - s_contexts[(int)num1] = true; - break; - } - } - } - Debug2.Validate(num1 != 0U, typeof(InvalidOperationException), "Failed to allocate a context ID"); - return ContextID.FromUInt32(num1); - } - - private static void FreeContextId(ContextID contextId) - { - uint uint32 = ContextID.ToUInt32(contextId); - Debug2.Validate(s_contexts[(int)uint32], typeof(InvalidOperationException), "ContextID is not in use"); - lock (s_contexts) - s_contexts[(int)uint32] = false; - } - - protected override void Invariant() - { - Debug2.Validate(m_localContextId != ContextID.NULL, typeof(InvalidOperationException), "local ContextId should not be NULL while running"); - Debug2.Validate(m_engineContextId != ContextID.NULL, typeof(InvalidOperationException), "engine ContextId should not be NULL while running"); - } - - bool IRenderEngine.ProcessNativeEvents() => true; - - void IRenderEngine.InterThreadWake() - { - - } - } -} diff --git a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderSession.cs b/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderSession.cs deleted file mode 100644 index e635451..0000000 --- a/UIX.RenderApi.Skia/Microsoft/Iris/Render/Internal/SkiaRenderSession.cs +++ /dev/null @@ -1,366 +0,0 @@ -using Microsoft.Iris.Library; -using Microsoft.Iris.Render.Animation; -using Microsoft.Iris.Render.Common; -using Microsoft.Iris.Render.Graphics; -using Microsoft.Iris.Render.Protocol; -using Microsoft.Iris.Render.Protocols.Splash.Desktop; -using Microsoft.Iris.Render.Protocols.Splash.Desktop.Nt; -using Microsoft.Iris.Render.Protocols.Splash.Rendering; -using Microsoft.Iris.Render.Protocols.Splash.Rendering.Nt; -using Microsoft.Iris.Render.Remote; -using Microsoft.Iris.Render.Sound; -using System; - -namespace Microsoft.Iris.Render.Internal -{ - internal class SkiaRenderSession : RenderObject, IRenderSession, IRenderObject, IDisposable - { - private SkiaRenderEngine m_renderEngine; - private MessagingSession m_owningSession; - private VisualPropertyManager m_visPropManager; - private ProtocolSplashDesktop m_protocolDesktop; - private ProtocolSplashDesktopNt m_protocolDesktopNt; - private ProtocolSplashRendering m_protocolRendering; - private ProtocolSplashRenderingNt m_protocolRenderingNt; - private ProtocolSplashRendering m_protocolRenderingLocal; - private AnimationSystem m_animationSystem; - private ObjectCacheManager m_cacheManager; - private Common.ObjectCache m_cacheSprite; - private Common.ObjectCache m_cacheContainer; - - internal SkiaRenderSession(SkiaRenderEngine renderEngine) - { - Debug2.Validate(renderEngine != null, typeof(ArgumentNullException), nameof(renderEngine)); - this.RegisterOwningThread(); - this.m_protocolRendering = ProtocolSplashRendering.Bind(this.Messaging.RenderingPort); - this.m_protocolDesktop = ProtocolSplashDesktop.Bind(this.Messaging.WindowingPort); - this.m_protocolRenderingNt = ProtocolSplashRenderingNt.Bind(this.Messaging.RenderingPort); - this.m_protocolDesktopNt = ProtocolSplashDesktopNt.Bind(this.Messaging.WindowingPort); - if (this.Messaging.WindowingPort != this.Messaging.RenderingPort) - this.m_protocolRenderingLocal = ProtocolSplashRendering.Bind(this.Messaging.WindowingPort); - this.m_renderEngine = renderEngine; - this.m_visPropManager = new VisualPropertyManager(); - this.m_cacheManager = null; - } - - internal void Initialize() => this.m_animationSystem = new AnimationSystem(this); - - protected override void Dispose(bool fInDispose) - { - try - { - if (fInDispose && this.m_animationSystem != null) - this.m_animationSystem.UnregisterUsage(this); - this.UnregisterOwningThread(); - this.m_animationSystem = null; - this.m_visPropManager.Dispose(); - } - finally - { - base.Dispose(fInDispose); - } - } - - IGraphicsDevice IRenderSession.GraphicsDevice => m_renderEngine.Window.GraphicsDevice; - - ISoundDevice IRenderSession.SoundDevice => m_renderEngine.SoundDevice; - - internal SoundDevice SoundDevice => this.m_renderEngine.SoundDevice; - - IAnimationSystem IRenderSession.AnimationSystem => m_animationSystem; - - IInputSystem IRenderSession.InputSystem => m_renderEngine.InputSystem; - - internal MessagingSession Messaging => this.m_owningSession; - - internal RenderPort RenderingPort => this.m_owningSession.RenderingPort; - - internal RenderPort WindowingPort => this.m_owningSession.WindowingPort; - - internal ProtocolSplashDesktop DesktopProtocol => this.m_protocolDesktop; - - internal ProtocolSplashDesktopNt NtDesktopProtocol => this.m_protocolDesktopNt; - - internal ProtocolSplashRendering RenderingProtocol => this.m_protocolRendering; - - internal ProtocolSplashRenderingNt NtRenderingProtocol => this.m_protocolRenderingNt; - - internal ProtocolSplashRendering LocalRenderingProtocol => this.m_protocolRenderingLocal; - - internal bool IsValid => this.m_owningSession.IsConnected; - - internal bool IsForeignByteOrderOnWindowing => this.WindowingPort.ForeignByteOrder; - - internal VisualPropertyManager VisualPropertyManager => this.m_visPropManager; - - internal ObjectCacheManager CacheManager => this.m_cacheManager; - - public IEffectTemplate CreateEffectTemplate(object objUser, string stName) - { - Debug2.Validate(objUser != null, typeof(ArgumentNullException), nameof(objUser)); - EffectTemplate effectTemplate = this.m_renderEngine.Window.GraphicsDevice.CreateEffectTemplate(stName); - effectTemplate.RegisterUsage(objUser); - return effectTemplate; - } - - public IVideoStream CreateVideoStream(object objUser) - { - Debug2.Validate(objUser != null, typeof(ArgumentNullException), nameof(objUser)); - VideoStream videoStream = new VideoStream(this, this.m_renderEngine.Window.GraphicsDevice); - videoStream.RegisterUsage(objUser); - return videoStream; - } - - public IVisualContainer CreateVisualContainer( - object objUser, - object objOwnerData) - { - Debug2.Validate(objUser != null, typeof(ArgumentNullException), nameof(objUser)); - VisualContainer visualContainer = null; - if (this.m_cacheContainer != null) - { - visualContainer = (VisualContainer)this.m_cacheContainer.Remove(objUser); - if (visualContainer != null) - visualContainer.OwnerData = objOwnerData; - } - if (visualContainer == null) - { - RemoteVisual remoteVisual; - visualContainer = new VisualContainer(false, this, this.m_renderEngine.Window, objOwnerData, out remoteVisual); - visualContainer.RegisterUsage(objUser); - visualContainer.Cache = this.m_cacheContainer; - } - return visualContainer; - } - - public ICamera CreateCamera(object objUser) - { - Debug2.Validate(objUser != null, typeof(ArgumentNullException), nameof(objUser)); - Camera camera = new Camera(this); - camera.RegisterUsage(objUser); - return camera; - } - - public IGradient CreateGradient(object objUser) - { - Debug2.Validate(objUser != null, typeof(ArgumentNullException), nameof(objUser)); - Gradient gradient = new Gradient(this, this.m_renderEngine.Window.GraphicsDevice.RemoteDevice); - gradient.RegisterUsage(objUser); - return gradient; - } - - public ISprite CreateSprite(object objUser, object objOwnerData) - { - Debug2.Validate(objUser != null, typeof(ArgumentNullException), nameof(objUser)); - Sprite sprite = null; - if (this.m_cacheSprite != null) - { - sprite = (Sprite)this.m_cacheSprite.Remove(objUser); - if (sprite != null) - sprite.OwnerData = objOwnerData; - } - if (sprite == null) - { - sprite = new Sprite(this, this.m_renderEngine.Window, objOwnerData); - sprite.RegisterUsage(objUser); - sprite.Cache = this.m_cacheSprite; - } - return sprite; - } - - public IImage CreateImage( - object objUser, - string identifier, - ContentNotifyHandler handler) - { - Debug2.Validate(objUser != null, typeof(ArgumentNullException), nameof(objUser)); - Debug2.Validate(handler != null, typeof(InvalidOperationException), "Invalid handler"); - Image image = this.m_renderEngine.Window.GraphicsDevice.CreateImage(identifier, handler); - image.RegisterUsage(objUser); - return image; - } - - internal GraphicsCaps GetGraphicsCaps(GraphicsDeviceType type) - { - foreach (GraphicsCaps graphicsCap in this.m_renderEngine.GraphicsCaps) - { - if (graphicsCap.DeviceType.FulfillsRequirement(type)) - return graphicsCap; - } - return new GraphicsCaps(); - } - - private void RegisterOwningThread() => this.m_owningSession = MessagingSession.Current; - - private void UnregisterOwningThread() => this.m_owningSession = null; - - internal void AssertOwningThread() - { - } - - internal bool IsOwningThread() => this.m_owningSession == MessagingSession.Current; - - public void DeferredInvoke(Delegate method, object args, DeferredInvokePriority priority) - { - if (this.m_owningSession == null) - return; - this.m_owningSession.DeferredInvoke(method, args, priority, TimeSpan.FromMilliseconds(0.0)); - } - - public void DeferredInvoke( - SharedRenderObject owner, - Delegate method, - object args, - DeferredInvokePriority priority) - { - if (this.m_owningSession == null) - return; - this.m_owningSession.DeferredInvoke(owner, method, args, priority, TimeSpan.FromMilliseconds(0.0)); - } - - internal void DeferredInvoke( - Delegate method, - object args, - DeferredInvokePriority priority, - TimeSpan delay) - { - if (this.m_owningSession == null) - return; - this.m_owningSession.DeferredInvoke(method, args, priority, delay); - } - - internal void ReleaseSharedResources() - { - if (this.m_cacheSprite != null) - { - this.m_cacheManager.UnregisterCache(this.m_cacheSprite); - this.m_cacheSprite.Dispose(); - this.m_cacheSprite = null; - } - if (this.m_cacheContainer == null) - return; - this.m_cacheManager.UnregisterCache(this.m_cacheContainer); - this.m_cacheContainer.Dispose(); - this.m_cacheContainer = null; - } - - internal RENDERHANDLE AllocateRenderHandle(IRenderHandleOwner owner) => this.RenderingPort.AllocHandle(owner); - - internal void FreeRenderHandle(RENDERHANDLE handle) => this.RenderingPort.FreeHandle(handle); - - internal IVisual TryGetHandleOwner(uint dwHandleData) => this.WindowingPort.TryGetHandleOwner(RENDERHANDLE.FromUInt32(dwHandleData)) as IVisual; - - public RemoteDesktopManager BuildRemoteDesktopManager( - DisplayManager owner, - bool fEnumDisplayModes) - { - Debug2.Validate(this.IsOwningThread(), typeof(InvalidOperationException), "Must be called on the session's owning client thread"); - return this.NtDesktopProtocol.BuildRemoteDesktopManager(owner, this.NtDesktopProtocol.LocalDesktopManagerCallbackHandle, fEnumDisplayModes); - } - - internal RemoteFormWindow BuildRemoteFormWindow( - RenderWindow window, - DisplayManager displayManager) - { - Debug2.Validate(this.IsOwningThread(), typeof(InvalidOperationException), "Must be called on the session's owning client thread"); - return this.NtDesktopProtocol.BuildRemoteFormWindow(window, displayManager.RemoteStub, this.DesktopProtocol.LocalFormWindowCallbackHandle); - } - - internal RemoteInputRouter BuildRemoteInputRouter( - InputSystem inputSystem, - RenderWindow window) - { - Debug2.Validate(this.IsOwningThread(), typeof(InvalidOperationException), "Must be called on the session's owning client thread"); - RemoteInputRouter remoteInputRouter = this.DesktopProtocol.BuildRemoteInputRouter(inputSystem, this.DesktopProtocol.LocalInputCallbackHandle); - remoteInputRouter?.SendRegisterWithInputSource(this.WindowingPort.DefaultGroupID, ((IRenderHandleOwner)window).RenderHandle); - return remoteInputRouter; - } - - internal RemoteNtDevice BuildRemoteNtDevice(NtGraphicsDevice device) => this.NtRenderingProtocol.BuildRemoteNtDevice(device, this.RenderingProtocol.LocalDeviceCallbackHandle); - - internal RemoteGdiDevice BuildRemoteGdiDevice(GdiGraphicsDevice device) => this.NtRenderingProtocol.BuildRemoteGdiDevice(device, this.RenderingProtocol.LocalDeviceCallbackHandle); - - internal RemoteNullDevice BuildRemoteNullDevice( - NullGraphicsDevice device, - bool fUseSplitWindowingPort) - { - return fUseSplitWindowingPort ? this.LocalRenderingProtocol.BuildRemoteNullDevice(device, this.LocalRenderingProtocol.LocalDeviceCallbackHandle) : this.RenderingProtocol.BuildRemoteNullDevice(device, this.RenderingProtocol.LocalDeviceCallbackHandle); - } - - internal unsafe DataBuffer BuildDataBuffer(byte[] pData, uint cbSize) => new DataBuffer(this.RenderingPort, pData, cbSize); - - internal void LoadSurface(DataBuffer buffer, Surface surface, ImageHeader header) => RemoteRasterizer.SendLoadRawImage(this.RenderingProtocol, surface.RemoteStub, buffer.RemoteStub, header); - - internal RemoteDx9EffectResource BuildRemoteDx9EffectResource( - Dx9EffectResource effectResource, - Dx9GraphicsDevice dx9Device, - DataBuffer dataBuffer) - { - return this.RenderingProtocol.BuildRemoteDx9EffectResource(effectResource, dx9Device.RemoteDevice, dataBuffer.RemoteStub); - } - - internal RemoteDx9Effect BuildRemoteDx9Effect(Dx9Effect effect) => RemoteDx9Effect.Create(this.RenderingProtocol, effect); - - internal RemoteGdiEffect BuildRemoteGdiEffect(GdiEffect effect) => RemoteGdiEffect.Create(this.NtRenderingProtocol, effect); - - internal RemoteCamera BuildRemoteCamera(Camera camera) => this.RenderingProtocol.BuildRemoteCamera(camera); - - internal RemoteVisualContainer BuildRemoteVisualContainer(Visual visual) => this.RenderingProtocol.BuildRemoteVisualContainer(visual); - - internal RemoteSprite BuildRemoteSprite(Sprite sprite, RenderWindow window) - { - switch (window.GraphicsDeviceType) - { - case GraphicsDeviceType.Gdi: - return this.NtRenderingProtocol.BuildRemoteGdiSprite(sprite); - case GraphicsDeviceType.Direct3D9: - case GraphicsDeviceType.XeDirectX9: - return this.RenderingProtocol.BuildRemoteDx9Sprite(sprite); - default: - Debug2.Throw(false, "Unrecognized device type: {0}", window.GraphicsDeviceType); - return null; - } - } - - internal RemoteSoundBuffer BuildSoundBufferFromHandle(RENDERHANDLE handle) => RemoteSoundBuffer.CreateFromHandle(this.RenderingPort, handle); - - internal RemoteSound BuildSoundFromHandle(RENDERHANDLE handle) => RemoteSound.CreateFromHandle(this.RenderingPort, handle); - - public RemoteAnimationManager BuildRemoteAnimationManager( - AnimationSystem owner) - { - Debug2.Validate(this.IsOwningThread(), typeof(InvalidOperationException), "Must be called on the session's owning client thread"); - return this.RenderingProtocol.BuildRemoteAnimationManager(owner); - } - - public RemoteAnimation BuildRemoteAnimation( - KeyframeAnimation owner, - AnimationInputType animationType) - { - Debug2.Validate(this.IsOwningThread(), typeof(InvalidOperationException), "Must be called on the session's owning client thread"); - return this.RenderingProtocol.BuildRemoteAnimation(owner, animationType, this.RenderingProtocol.LocalAnimationCallbackHandle); - } - - public RemoteExternalAnimationInput BuildRemoteExternalAnimationInput( - ExternalAnimationInput owner, - uint uniqueId) - { - Debug2.Validate(this.IsOwningThread(), typeof(InvalidOperationException), "Must be called on the session's owning client thread"); - return this.RenderingProtocol.BuildRemoteExternalAnimationInput(owner, uniqueId); - } - - public RemoteAnimationInputProvider BuildRemoteAnimationInputProvider( - AnimationInputProvider owner, - uint externalAnimationInputId) - { - Debug2.Validate(this.IsOwningThread(), typeof(InvalidOperationException), "Must be called on the session's owning client thread"); - return this.RenderingProtocol.BuildRemoteAnimationInputProvider(owner, externalAnimationInputId); - } - - protected override void Invariant() - { - this.AssertOwningThread(); - Debug2.Validate(this.m_owningSession != null, typeof(InvalidOperationException), this.GetType().ToString()); - } - } -} diff --git a/UIX.RenderApi.Skia/Microsoft/Iris/Render/RenderApi.cs b/UIX.RenderApi.Skia/Microsoft/Iris/Render/RenderApi.cs index 906bbc5..78a8f71 100644 --- a/UIX.RenderApi.Skia/Microsoft/Iris/Render/RenderApi.cs +++ b/UIX.RenderApi.Skia/Microsoft/Iris/Render/RenderApi.cs @@ -27,7 +27,7 @@ namespace Microsoft.Iris.Render Debug2.Validate(renderHost != null, typeof(ArgumentNullException), nameof(renderHost)); IRenderEngine renderEngine = null; if (engineInfo.Type == EngineType.Iris) - renderEngine = new SkiaRenderEngine(engineInfo as IrisEngineInfo, renderHost); + renderEngine = new RenderEngine(engineInfo as IrisEngineInfo, renderHost); return renderEngine; } @@ -40,7 +40,7 @@ namespace Microsoft.Iris.Render Debug2.Validate(renderHost != null, typeof(ArgumentNullException), nameof(renderHost)); IRenderSession renderSession = null; if (sessionToken.EngineInfo.Type == EngineType.Iris) - renderSession = new RenderSession(null); + renderSession = new RenderSession((RenderEngine)null); return renderSession; }