Merged PR 244494: Convert entire gallery to use ImageLoader

Convert entire gallery to use ImageLoader
- Port all samples to use ImageLoader and ManagedSurface classes.
- Remove SurfaceLoader
- Make ImageLoader a singleton, remove unnecessary allocations of ImageLoader per sample.
- Simplify ImageLoader and ManagedSurface classes removing unnecessary interfaces and methods.
- Make ImageLoader and ManagedSurface content agnostic.  ImageLoader is responsible for managing devices while ManagedSurface is responsible for manging content loading and recovery.
- Introduce ContentDrawer abstract class and derived classes used for loading specific types of content.
- Add native helper library to properly capture device removed events.
This commit is contained in:
Rob Aldinger 2017-03-07 17:16:39 +00:00
Родитель 61a653f7c4
Коммит 149948231d
43 изменённых файлов: 960 добавлений и 860 удалений

Просмотреть файл

@ -34,6 +34,7 @@ namespace CompositionSampleGallery
public sealed partial class MainPage : Page
{
private static MainPage _instance;
private ManagedSurface _splashSurface;
#if SDKVERSION_INSIDER
private static CompositionCapabilities _capabilities;
#endif
@ -58,8 +59,8 @@ namespace CompositionSampleGallery
_runtimeCapabilities = new RuntimeSupportedSDKs();
this.InitializeComponent();
// Initialize the surface loader
SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);
// Initialize the image loader
ImageLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);
// Show the custome splash screen
ShowCustomSplashScreen(imageBounds);
@ -109,7 +110,7 @@ namespace CompositionSampleGallery
page.OnCapabiliesChanged(_areEffectsSupported, _areEffectsFast);
}
//MySampleListControl.RefreshSampleList();
SampleDefinitions.RefreshSampleList();
//
@ -139,7 +140,7 @@ namespace CompositionSampleGallery
}
#endif
private async void ShowCustomSplashScreen(Rect imageBounds)
private void ShowCustomSplashScreen(Rect imageBounds)
{
Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
Vector2 windowSize = new Vector2((float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height);
@ -171,9 +172,9 @@ namespace CompositionSampleGallery
// exactly cover the Splash screen image so it will be a seamless transition between the two
//
CompositionDrawingSurface surface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Assets/StoreAssets/Wide.png"));
_splashSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Assets/StoreAssets/Wide.png"));
SpriteVisual imageSprite = compositor.CreateSpriteVisual();
imageSprite.Brush = compositor.CreateSurfaceBrush(surface);
imageSprite.Brush = compositor.CreateSurfaceBrush(_splashSurface.Surface);
imageSprite.Offset = new Vector3((float)imageBounds.X,(float)imageBounds.Y, 0f);
imageSprite.Size = new Vector2((float)imageBounds.Width, (float)imageBounds.Height);
container.Children.InsertAtTop(imageSprite);
@ -232,6 +233,12 @@ namespace CompositionSampleGallery
{
// Now that the animations are complete, dispose of the custom Splash Screen visuals
ElementCompositionPreview.SetElementChildVisual(this, null);
if (_splashSurface != null)
{
_splashSurface.Dispose();
_splashSurface = null;
}
}
private void Page_Loaded(object sender, RoutedEventArgs e)

Просмотреть файл

@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26208.0
VisualStudioVersion = 15.0.26202.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleGallery", "SampleGallery.csproj", "{B39C562B-EA01-4368-8AD9-DF79CC5A533A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\SamplesCommon\SamplesCommon\SamplesCommon.csproj", "{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SamplesNative", "..\SamplesNative\SamplesNative.vcxproj", "{B0DCA768-5521-406C-803D-FDCCF67181D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -19,9 +21,9 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|Any CPU.ActiveCfg = Debug|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|Any CPU.Build.0 = Debug|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|Any CPU.Deploy.0 = Debug|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|Any CPU.ActiveCfg = Debug|x64
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|Any CPU.Build.0 = Debug|x64
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|Any CPU.Deploy.0 = Debug|x64
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|ARM.ActiveCfg = Debug|ARM
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|ARM.Build.0 = Debug|ARM
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|ARM.Deploy.0 = Debug|ARM
@ -31,9 +33,9 @@ Global
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|x86.ActiveCfg = Debug|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|x86.Build.0 = Debug|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Debug|x86.Deploy.0 = Debug|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|Any CPU.ActiveCfg = Release|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|Any CPU.Build.0 = Release|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|Any CPU.Deploy.0 = Release|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|Any CPU.ActiveCfg = Release|x64
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|Any CPU.Build.0 = Release|x64
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|Any CPU.Deploy.0 = Release|x64
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|ARM.ActiveCfg = Release|ARM
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|ARM.Build.0 = Release|ARM
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|ARM.Deploy.0 = Release|ARM
@ -43,22 +45,38 @@ Global
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|x86.ActiveCfg = Release|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|x86.Build.0 = Release|x86
{B39C562B-EA01-4368-8AD9-DF79CC5A533A}.Release|x86.Deploy.0 = Release|x86
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|Any CPU.ActiveCfg = Debug|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|Any CPU.Build.0 = Debug|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|ARM.ActiveCfg = Debug|ARM
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|ARM.Build.0 = Debug|ARM
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|x64.ActiveCfg = Debug|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|x64.Build.0 = Debug|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|x86.ActiveCfg = Debug|x86
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Debug|x86.Build.0 = Debug|x86
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|Any CPU.Build.0 = Release|Any CPU
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|Any CPU.ActiveCfg = Release|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|Any CPU.Build.0 = Release|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|ARM.ActiveCfg = Release|ARM
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|ARM.Build.0 = Release|ARM
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|x64.ActiveCfg = Release|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|x64.Build.0 = Release|x64
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|x86.ActiveCfg = Release|x86
{0B6A4830-D1FF-4018-BAA2-7257EB4579FE}.Release|x86.Build.0 = Release|x86
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|Any CPU.ActiveCfg = Debug|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|Any CPU.Build.0 = Debug|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|ARM.ActiveCfg = Debug|ARM
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|ARM.Build.0 = Debug|ARM
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|x64.ActiveCfg = Debug|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|x64.Build.0 = Debug|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|x86.ActiveCfg = Debug|Win32
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Debug|x86.Build.0 = Debug|Win32
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|Any CPU.ActiveCfg = Release|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|Any CPU.Build.0 = Release|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|ARM.ActiveCfg = Release|ARM
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|ARM.Build.0 = Release|ARM
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|x64.ActiveCfg = Release|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|x64.Build.0 = Release|x64
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|x86.ActiveCfg = Release|Win32
{B0DCA768-5521-406C-803D-FDCCF67181D1}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -256,32 +256,20 @@ namespace CompositionSampleGallery.PointerEffectTechniques
return null;
}
private CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget)
private void ApplyBlurEffect(CompositionDrawingSurface surface, CanvasBitmap bitmap, CompositionGraphicsDevice device)
{
GaussianBlurEffect blurEffect = new GaussianBlurEffect()
{
Source = bitmap,
BlurAmount = 10.0f,
BlurAmount = 40.0f,
BorderMode = EffectBorderMode.Hard,
};
float fDownsample = .3f;
Size sizeSource = bitmap.Size;
if (sizeTarget == Size.Empty)
using (var ds = CanvasComposition.CreateDrawingSession(surface))
{
sizeTarget = sizeSource;
ds.DrawImage(blurEffect);
ds.FillRectangle(new Rect(0, 0, surface.Size.Width, surface.Size.Height), Windows.UI.Color.FromArgb(60, 0, 0, 0));
}
sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample);
CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
using (var ds = CanvasComposition.CreateDrawingSession(blurSurface))
{
Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height);
ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height));
ds.FillRectangle(destination, Windows.UI.Color.FromArgb(60, 0, 0, 0));
}
return blurSurface;
}
public override void ReleaseResources()
@ -320,7 +308,7 @@ namespace CompositionSampleGallery.PointerEffectTechniques
public class SpotLightTechnique : EffectTechniques
{
CompositionDrawingSurface _lightMap;
ManagedSurface _lightMap;
ExpressionAnimation _transformExpression;
ScalarKeyFrameAnimation _enterAnimation;
ScalarKeyFrameAnimation _exitAnimation;
@ -349,7 +337,7 @@ namespace CompositionSampleGallery.PointerEffectTechniques
_effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" });
// Create the image
_lightMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/conemap.jpg"));
_lightMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/conemap.jpg"));
// Create the animations
float sweep = (float)Math.PI / 10f;
@ -410,7 +398,7 @@ namespace CompositionSampleGallery.PointerEffectTechniques
public override CompositionEffectBrush CreateBrush()
{
CompositionEffectBrush brush = base.CreateBrush();
brush.SetSourceParameter("LightMap", _compositor.CreateSurfaceBrush(_lightMap));
brush.SetSourceParameter("LightMap", _lightMap.Brush);
return brush;
}
@ -437,7 +425,7 @@ namespace CompositionSampleGallery.PointerEffectTechniques
public class PointLightFollowTechnique : EffectTechniques
{
CompositionDrawingSurface _lightMap;
ManagedSurface _lightMap;
ExpressionAnimation _transformExpression;
ScalarKeyFrameAnimation _enterAnimation;
Vector2KeyFrameAnimation _exitAnimation;
@ -466,7 +454,7 @@ namespace CompositionSampleGallery.PointerEffectTechniques
_effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" });
// Create the image
_lightMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/pointmap.jpg"));
_lightMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/pointmap.jpg"));
// Create the animations
CubicBezierEasingFunction easeIn = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.51f), new Vector2(1.0f, 0.51f));
@ -524,7 +512,7 @@ namespace CompositionSampleGallery.PointerEffectTechniques
public override CompositionEffectBrush CreateBrush()
{
CompositionEffectBrush brush = base.CreateBrush();
brush.SetSourceParameter("LightMap", _compositor.CreateSurfaceBrush(_lightMap));
brush.SetSourceParameter("LightMap", _lightMap.Brush);
return brush;
}

Просмотреть файл

@ -136,12 +136,12 @@ namespace CompositionSampleGallery
private async void ApplyEffect(CompositionImage image)
{
Task<CompositionDrawingSurface> task = null;
ManagedSurface effectSurface = null;
// If we've requested a load time effect input, kick it off now
if (_currentTechnique.LoadTimeEffectHandler != null)
{
task = SurfaceLoader.LoadFromUri(image.Source, Size.Empty, _currentTechnique.LoadTimeEffectHandler);
effectSurface = await ImageLoader.Instance.LoadFromUriAsync(image.Source, Size.Empty, _currentTechnique.LoadTimeEffectHandler);
}
// Create the new brush, set the inputs and set it on the image
@ -149,13 +149,10 @@ namespace CompositionSampleGallery
brush.SetSourceParameter("ImageSource", image.SurfaceBrush);
image.Brush = brush;
// If we've got an active task, wait for it to finish
if (task != null)
{
CompositionDrawingSurface effectSurface = await task;
// Set the effect surface as input
brush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(effectSurface));
if (effectSurface != null)
{
brush.SetSourceParameter("EffectSource", effectSurface.Brush);
}
}

Просмотреть файл

@ -12,7 +12,7 @@
//
//*********************************************************
using SamplesCommon.ImageLoader;
using SamplesCommon;
using System;
using System.Numerics;
using Windows.UI;
@ -40,7 +40,6 @@ namespace CompositionSampleGallery
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Compositor compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;
_imageLoader = ImageLoaderFactory.CreateImageLoader(compositor);
ContainerVisual container = compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(MyGrid, container);
@ -49,13 +48,8 @@ namespace CompositionSampleGallery
// Create a couple of SurfaceBrushes for the orbiters and center
//
CompositionSurfaceBrush redBrush = compositor.CreateSurfaceBrush();
_redBallSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png"));
redBrush.Surface = _redBallSurface.Surface;
CompositionSurfaceBrush blueBrush = compositor.CreateSurfaceBrush();
_blueBallSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png"));
blueBrush.Surface = _blueBallSurface.Surface;
_redBallSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png"));
_blueBallSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png"));
//
@ -63,13 +57,13 @@ namespace CompositionSampleGallery
//
SpriteVisual redSprite = compositor.CreateSpriteVisual();
redSprite.Brush = redBrush;
redSprite.Brush = _redBallSurface.Brush;
redSprite.Size = new Vector2(100f, 100f);
redSprite.Offset = new Vector3((float)Window.Current.Bounds.Width / 2 - redSprite.Size.X/2, 150f, 0f);
container.Children.InsertAtTop(redSprite);
SpriteVisual blueSprite = compositor.CreateSpriteVisual();
blueSprite.Brush = blueBrush;
blueSprite.Brush = _blueBallSurface.Brush;
blueSprite.Size = new Vector2(25f, 25f);
blueSprite.Offset = new Vector3((float)Window.Current.Bounds.Width / 2 - redSprite.Size.X / 2, 50f, 0f);
container.Children.InsertAtTop(blueSprite);
@ -125,12 +119,10 @@ namespace CompositionSampleGallery
{
_redBallSurface.Dispose();
_blueBallSurface.Dispose();
_imageLoader.Dispose();
}
private IImageLoader _imageLoader;
private IManagedSurface _redBallSurface;
private IManagedSurface _blueBallSurface;
private ManagedSurface _redBallSurface;
private ManagedSurface _blueBallSurface;
private CompositionPropertySet _propertySet;
}
}

Просмотреть файл

@ -14,9 +14,8 @@
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using SamplesCommon.ImageLoader;
using SamplesCommon;
using System;
using System.Linq;
using System.Numerics;
using Windows.Foundation;
using Windows.UI;
@ -37,8 +36,7 @@ namespace CompositionSampleGallery
Compositor _compositor;
ContainerVisual _containerForVisuals;
ScalarKeyFrameAnimation _bloomAnimation;
IImageLoader _imageLoader;
ICircleSurface _circleMaskSurface;
ManagedSurface _circleMaskSurface;
#endregion
@ -62,9 +60,8 @@ namespace CompositionSampleGallery
_containerForVisuals = _compositor.CreateContainerVisual();
ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);
// initialize the ImageLoader and create the circle mask
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
_circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
// Create the circle mask
_circleMaskSurface = ImageLoader.Instance.LoadCircle(200, Colors.White);
}
#endregion
@ -106,7 +103,6 @@ namespace CompositionSampleGallery
public void Dispose()
{
_circleMaskSurface.Dispose();
_imageLoader.Dispose();
}
#endregion
@ -195,9 +191,8 @@ namespace CompositionSampleGallery
//
// Create the mask brush using the circle mask
//
CompositionSurfaceBrush maskBrush = _compositor.CreateSurfaceBrush();
maskBrush.Surface = _circleMaskSurface.Surface;
brush.SetSourceParameter("mask", maskBrush);
brush.SetSourceParameter("mask", _circleMaskSurface.Brush);
return brush;

Просмотреть файл

@ -16,7 +16,6 @@ using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.Graphics.Canvas.UI.Composition;
using SamplesCommon;
using SamplesCommon.ImageLoader;
using System;
using System.Numerics;
using System.Threading.Tasks;
@ -49,15 +48,15 @@ namespace CompositionSampleGallery
/// </summary>
/// <param name="sender">not used</param>
/// <param name="e">not used</param>
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
_compositor = ElementCompositionPreview.GetElementVisual(sender as UIElement).Compositor;
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(Scroller);
var uri = new Uri("ms-appx:///Samples/SDK 10586/Z-Order Scrolling/RollingWaves.jpg");
_blurSurface = ImageLoader.Instance.LoadFromUri(uri, Size.Empty, ApplyBlurEffect);
ParallaxingImage.Source = uri;
ParallaxingImage.Brush = await InitializeCrossFadeEffect(uri);
ParallaxingImage.Brush = InitializeCrossFadeEffect();
var maskedBrush = InitializeCompositeEffect();
@ -79,7 +78,7 @@ namespace CompositionSampleGallery
{
_profilePictureSurface.Dispose();
_circleMaskSurface.Dispose();
_imageLoader.Dispose();
_blurSurface.Dispose();
}
/// <summary>
@ -344,18 +343,14 @@ namespace CompositionSampleGallery
//
// Load in the profile picture as a brush using the Composition Toolkit.
//
CompositionSurfaceBrush profileBrush = _compositor.CreateSurfaceBrush();
_profilePictureSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/Z-Order Scrolling/teched3ae5a27b-4f78-e111-94ad-001ec953730b.jpg"));
profileBrush.Surface = _profilePictureSurface.Surface;
brush.SetSourceParameter("image", profileBrush);
_profilePictureSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/Z-Order Scrolling/teched3ae5a27b-4f78-e111-94ad-001ec953730b.jpg"));
brush.SetSourceParameter("image", _profilePictureSurface.Brush);
//
// Load in the circular mask picture asx a brush using the composition Toolkit.
//
CompositionSurfaceBrush maskBrush = _compositor.CreateSurfaceBrush();
_circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
maskBrush.Surface = _circleMaskSurface.Surface;
brush.SetSourceParameter("mask", maskBrush);
_circleMaskSurface = ImageLoader.Instance.LoadCircle(200, Colors.White);
brush.SetSourceParameter("mask", _circleMaskSurface.Brush);
return brush;
@ -365,7 +360,7 @@ namespace CompositionSampleGallery
/// Function is responsible for creating the circular alpha masked profile brush
/// </summary>
/// <returns></returns>
private async Task<CompositionEffectBrush> InitializeCrossFadeEffect(Uri uri)
private CompositionEffectBrush InitializeCrossFadeEffect()
{
var graphicsEffect = new ArithmeticCompositeEffect
{
@ -379,44 +374,30 @@ namespace CompositionSampleGallery
var factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" });
CompositionDrawingSurface blurSurface = await SurfaceLoader.LoadFromUri(uri, Size.Empty, ApplyBlurEffect);
CompositionEffectBrush crossFadeBrush = factory.CreateBrush(); ;
crossFadeBrush.SetSourceParameter("ImageSource", ParallaxingImage.SurfaceBrush);
crossFadeBrush.SetSourceParameter("BlurImage", _compositor.CreateSurfaceBrush(blurSurface));
crossFadeBrush.SetSourceParameter("BlurImage", _blurSurface.Brush);
return crossFadeBrush;
}
CompositionDrawingSurface ApplyBlurEffect(CanvasBitmap bitmap, Windows.UI.Composition.CompositionGraphicsDevice device, Size sizeTarget)
void ApplyBlurEffect(CompositionDrawingSurface surface, CanvasBitmap bitmap, Windows.UI.Composition.CompositionGraphicsDevice device)
{
GaussianBlurEffect blurEffect = new GaussianBlurEffect()
{
Source = bitmap,
BlurAmount = 20.0f,
BlurAmount = 40.0f,
BorderMode = EffectBorderMode.Hard,
};
float fDownsample = .3f;
Size sizeSource = bitmap.Size;
if (sizeTarget == Size.Empty)
using (var ds = CanvasComposition.CreateDrawingSession(surface))
{
sizeTarget = sizeSource;
ds.Clear(Color.FromArgb(255, 255, 255, 255));
ds.DrawImage(blurEffect);
}
sizeTarget = new Size(sizeTarget.Width * fDownsample, sizeTarget.Height * fDownsample);
CompositionDrawingSurface blurSurface = device.CreateDrawingSurface(sizeTarget, DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
using (var ds = CanvasComposition.CreateDrawingSession(blurSurface))
{
Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height);
ds.Clear(Windows.UI.Color.FromArgb(255, 255, 255, 255));
ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height));
}
return blurSurface;
}
private Compositor _compositor;
private IImageLoader _imageLoader;
private SpriteVisual _backVisual;
private ExpressionAnimation _behindOpacityAnimation;
@ -437,8 +418,9 @@ namespace CompositionSampleGallery
private ExpressionAnimation _profileContentTranslationAnimation;
private ExpressionAnimation _profileContentScaleAnimation;
private ICircleSurface _circleMaskSurface;
private IManagedSurface _profilePictureSurface;
private ManagedSurface _circleMaskSurface;
private ManagedSurface _profilePictureSurface;
private ManagedSurface _blurSurface;
private float _initialScaleAmount = .8f;
private float _finalScaleAmount = .4f;

Просмотреть файл

@ -37,6 +37,7 @@ namespace CompositionSampleGallery
private Compositor _compositor;
private CompositionScopedBatch
_scopeBatch;
private ManagedSurface _maskSurface;
public enum EffectTypes
{
@ -62,7 +63,7 @@ namespace CompositionSampleGallery
public override string SampleCodeUri { get { return "http://go.microsoft.com/fwlink/p/?LinkID=761179"; } }
public LocalDataSource Model { set; get; }
private void Page_Loaded(object sender, RoutedEventArgs e)
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
ThumbnailList.ItemsSource = Model.Items;
@ -89,6 +90,9 @@ namespace CompositionSampleGallery
// Start out with the destination layer invisible to avoid any cost until necessary
_destinationSprite.IsVisible = false;
// Create the mask surface
_maskSurface = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Samples/SDK 14393/ForegroundFocusEffects/mask.png"));
ElementCompositionPreview.SetElementChildVisual(ThumbnailList, _destinationSprite);
// Update the effect to set the appropriate brush
@ -106,6 +110,12 @@ namespace CompositionSampleGallery
_destinationSprite.Dispose();
_destinationSprite = null;
}
if (_maskSurface != null)
{
_maskSurface.Dispose();
_maskSurface = null;
}
}
private void ListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
@ -279,7 +289,7 @@ namespace CompositionSampleGallery
UpdateEffect();
}
private async void UpdateEffect()
private void UpdateEffect()
{
if (_compositor != null)
{
@ -355,12 +365,9 @@ namespace CompositionSampleGallery
}
};
CompositionDrawingSurface backgroundSurface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/ForegroundFocusEffects/mask.png"));
CompositionSurfaceBrush maskBrush = _compositor.CreateSurfaceBrush(backgroundSurface);
maskBrush.Stretch = CompositionStretch.UniformToFill;
maskBrush.CenterPoint = _destinationSprite.Size * .5f;
secondaryBrush = maskBrush;
_maskSurface.Brush.Stretch = CompositionStretch.UniformToFill;
_maskSurface.Brush.CenterPoint = _destinationSprite.Size * .5f;
secondaryBrush = _maskSurface.Brush;
}
break;
case EffectTypes.Blur:

Просмотреть файл

@ -62,6 +62,8 @@ namespace CompositionSampleGallery
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
_compositor = ElementCompositionPreview.GetElementVisual(this)?.Compositor;
Setup();
}

Просмотреть файл

@ -12,26 +12,13 @@
//
//*********************************************************
using Microsoft.Graphics.Canvas.Effects;
using SamplesCommon.ImageLoader;
using SamplesCommon;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace CompositionSampleGallery
{
@ -47,8 +34,7 @@ namespace CompositionSampleGallery
// Windows.UI.Composition
private Compositor _compositor;
private ContainerVisual _root;
private List<CompositionSurfaceBrush> _imageBrushList;
private IImageLoader _imageLoader;
private List<ManagedSurface> _imageList;
// Constants
private const float _posX = 600;
@ -98,12 +84,11 @@ namespace CompositionSampleGallery
//Create a list of image brushes that can be applied to a visual
string[] imageNames = { "60Banana.png", "60Lemon.png", "60Vanilla.png", "60Mint.png", "60Orange.png", "110Strawberry.png", "60SprinklesRainbow.png" };
_imageBrushList = new List<CompositionSurfaceBrush>();
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
_imageList = new List<ManagedSurface>(10);
for (int k = 0; k < imageNames.Length; k++)
{
var surface = _imageLoader.LoadImageFromUri(new Uri("ms-appx:///Samples/SDK 14393/ImplicitAnimationTransformer/" + imageNames[k]));
_imageBrushList.Add(_compositor.CreateSurfaceBrush(surface));
ManagedSurface surface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/ImplicitAnimationTransformer/" + imageNames[k]));
_imageList.Add(surface);
}
// Create nxn matrix of visuals where n=row/ColumnCount-1 and passes random image brush to the function
@ -113,7 +98,7 @@ namespace CompositionSampleGallery
posXUpdated = i * _distance;
for (int j = 1; j < _columnCount; j++)
{
CompositionSurfaceBrush brush = _imageBrushList[randomBrush.Next(_imageBrushList.Count)];
CompositionSurfaceBrush brush = _imageList[randomBrush.Next(_imageList.Count)].Brush;
posYUpdated = j * _distance;
_root.Children.InsertAtTop(CreateChildElement(brush, posXUpdated, posYUpdated));
@ -377,11 +362,10 @@ namespace CompositionSampleGallery
private void ImplicitAnimationTransformer_Unloaded(object sender, RoutedEventArgs e)
{
foreach(var brush in _imageBrushList)
foreach(var surface in _imageList)
{
brush.Dispose();
}
_imageLoader.Dispose();
surface.Dispose();
}
}
}
}

Просмотреть файл

@ -20,7 +20,6 @@ using System.Numerics;
using Windows.UI.Composition;
using Windows.UI.Composition.Interactions;
using Windows.UI.Xaml.Hosting;
using SamplesCommon.ImageLoader;
using Windows.Foundation;
using Windows.UI.Xaml.Input;
using SamplesCommon;
@ -72,11 +71,10 @@ namespace CompositionSampleGallery
_scaleTracker.Dispose();
_scaleTracker = null;
foreach(var brush in _imageBrushes)
foreach(var surface in _managedSurfaces)
{
brush.Dispose();
surface.Dispose();
}
_imageLoader.Dispose();
}
@ -223,13 +221,10 @@ namespace CompositionSampleGallery
}
async private void LoadImages()
private async void LoadImages()
{
int loadedImageCount = 0;
// Create the loader
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
//
// Populate/load our unique list of image textures.
@ -240,10 +235,7 @@ namespace CompositionSampleGallery
var name = (NamedImage)i;
Uri uri = new Uri($"ms-appx:///Assets/Photos/{name.ToString()}.jpg");
_managedSurfaces[i] = _imageLoader.CreateManagedSurfaceFromUri(uri);
var surface = await _imageLoader.LoadImageFromUriAsync(uri);
_imageBrushes[i] = _compositor.CreateSurfaceBrush(surface);
_managedSurfaces[i] = await ImageLoader.Instance.LoadFromUriAsync(uri);
loadedImageCount++;
}
@ -259,9 +251,9 @@ namespace CompositionSampleGallery
{
var textNode = _textNodes[i];
var textSurface = SurfaceLoader.LoadText(textNode.Text, new Size(textNode.TextureSize.X, textNode.TextureSize.Y), textNode.TextFormat, Colors.Black, Colors.Transparent);
var textSurface = ImageLoader.Instance.LoadText(textNode.Text, new Size(textNode.TextureSize.X, textNode.TextureSize.Y), textNode.TextFormat, Colors.Black, Colors.Transparent);
_textBrushes[i] = _compositor.CreateSurfaceBrush(textSurface);
_textBrushes[i] = _compositor.CreateSurfaceBrush(textSurface.Surface);
//
// Remember the index of the brush so that we can refer to it later.
@ -279,7 +271,7 @@ namespace CompositionSampleGallery
// Once we've loaded all of the images, we can continue populating the world.
//
if (loadedImageCount == _imageBrushes.Length + _textBrushes.Length)
if (loadedImageCount == _managedSurfaces.Length + _textBrushes.Length)
{
PopulateWorld();
}
@ -316,7 +308,7 @@ namespace CompositionSampleGallery
private void AddImage(ImageNodeInfo imageNodeInfo)
{
AddImage(_imageBrushes[(int)imageNodeInfo.NamedImage], imageNodeInfo);
AddImage(_managedSurfaces[(int)imageNodeInfo.NamedImage].Brush, imageNodeInfo);
}
@ -680,16 +672,13 @@ namespace CompositionSampleGallery
private VisualInteractionSource _interactionSource2;
private Visual _rootContainer;
private Visual _rootContainer2;
private IImageLoader _imageLoader;
private List<NodeInfo> _nodes;
private Compositor _compositor;
private DispatcherTimer _timer;
private int _lastAmbientAnimationIndex = -1;
private List<Tuple<AmbientAnimationTarget, CompositionAnimation>>
_ambientAnimations;
private IManagedSurface[] _managedSurfaces = new IManagedSurface[(int)NamedImage.Count];
private CompositionSurfaceBrush[]
_imageBrushes = new CompositionSurfaceBrush[(int)NamedImage.Count];
private ManagedSurface[] _managedSurfaces = new ManagedSurface[(int)NamedImage.Count];
private CompositionSurfaceBrush[]
_textBrushes;

Просмотреть файл

@ -1,9 +1,5 @@
using SamplesCommon.ImageLoader;
using System;
using System.Collections.Generic;
using System;
using System.Numerics;
using Windows.UI.Text;
using Windows.UI.Xaml.Media;
using Microsoft.Graphics.Canvas.Text;
namespace CompositionSampleGallery

Просмотреть файл

@ -248,25 +248,19 @@ namespace CompositionSampleGallery
/// </summary>
private sealed class LayerItem
{
private readonly Uri imageUri;
private SpriteVisual visual;
private ManagedSurface _surface;
private SpriteVisual _visual;
public LayerItem(Uri imageUri)
{
this.imageUri = imageUri;
_surface = ImageLoader.Instance.LoadFromUri(imageUri);
}
public SpriteVisual CreateVisual(Compositor compositor)
{
visual = compositor.CreateSpriteVisual();
LoadImageAsync(compositor);
return visual;
}
private async void LoadImageAsync(Compositor compositor)
{
var surface = await SurfaceLoader.LoadFromUri(imageUri);
visual.Brush = compositor.CreateSurfaceBrush(surface);
_visual = compositor.CreateSpriteVisual();
_visual.Brush = _surface.Brush;
return _visual;
}
}
}

Просмотреть файл

@ -18,11 +18,9 @@ using System.Numerics;
using Microsoft.Graphics.Canvas.Effects;
using Windows.Graphics.Effects;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.Composition;
using Windows.UI.Xaml.Hosting;
using System.Collections.Generic;
using SamplesCommon.ImageLoader;
using SamplesCommon;
@ -369,7 +367,7 @@ namespace CompositionSampleGallery
_sectionContentParams[i][j].VisualInstance.CenterPoint =
new Vector3(contentASize.X * 0.5f, contentASize.Y * 0.5f, 0);
AddImageSpriteVisual(_imageSurfaces[j * _fColumnCount + i],
AddImageSpriteVisual(_imageSurfaces[j * _fColumnCount + i].Brush,
_sectionContentParams[i][j].VisualInstance.Size, _sectionContentParams[i][j].VisualInstance);
}
}
@ -457,8 +455,6 @@ namespace CompositionSampleGallery
async private Task LoadImages()
{
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
string[] imageNames = { "Photos/Pic06", "Photos/Pic30", "Photos/Pic39", "Landscapes/Landscape-7",
"Landscapes/Landscape-8", "Landscapes/Landscape-9", "Landscapes/Landscape-12", "Photos/pic22",
"Photos/Pic11" };
@ -466,8 +462,7 @@ namespace CompositionSampleGallery
for (int i = 0; i < imageNames.Length; ++i)
{
var uri = new Uri($"ms-appx:///Assets/{imageNames[i]}.jpg");
var surface = await SurfaceLoader.LoadFromUri(uri);
_imageSurfaces[i] = _compositor.CreateSurfaceBrush(surface);
_imageSurfaces[i] = await ImageLoader.Instance.LoadFromUriAsync(uri);
}
}
@ -558,18 +553,16 @@ namespace CompositionSampleGallery
private void SamplePage_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
foreach(var brush in _imageSurfaces)
foreach (var surface in _imageSurfaces)
{
brush.Dispose();
surface.Dispose();
}
_imageLoader.Dispose();
}
private const int _fColumnCount = 3;
private Compositor _compositor;
private Visual _roomVisual;
private IImageLoader _imageLoader;
private CompositionSurfaceBrush[] _imageSurfaces = new CompositionSurfaceBrush[_fColumnCount * _fColumnCount];
private ManagedSurface[] _imageSurfaces = new ManagedSurface[_fColumnCount * _fColumnCount];
private EffectParameters[] _sectionParams = new EffectParameters[_fColumnCount];
private EffectParameters[][] _sectionContentParams = new EffectParameters[_fColumnCount][];
}

Просмотреть файл

@ -7,7 +7,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Loaded="SamplePage_Loaded">
Loaded="SamplePage_Loaded"
Unloaded="SamplePage_Unloaded">
<Grid x:Name="RootGrid" SizeChanged="RootGrid_SizeChanged">
<Grid.ColumnDefinitions>

Просмотреть файл

@ -37,6 +37,7 @@ namespace CompositionSampleGallery
private ContainerVisual _worldSpaceContainer;
private List<SpriteVisual> _sphereList;
private List<CompositionEffectBrush> _brushList;
private ManagedSurface _normalMap;
private Vector3 _defaultSphereOffset = new Vector3(-1500, 700, -1000);
private int _defaultSphereSpace = 350;
@ -77,8 +78,7 @@ namespace CompositionSampleGallery
{
ConstructWalls();
CompositionDrawingSurface normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/LightSpheres/SphericalWithMask.png"));
CompositionSurfaceBrush normalBrush = _compositor.CreateSurfaceBrush(normalMap);
_normalMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Samples/SDK 14393/LightSpheres/SphericalWithMask.png"));
LightControl1.Offset = new Vector3(-77, 21, -768);
LightControl1.LightColor.Color = Color.FromArgb(255, 255, 255, 255);
@ -173,7 +173,7 @@ namespace CompositionSampleGallery
{
CompositionEffectBrush brush = effectFactory.CreateBrush();
brush.Properties.InsertColor("Color.Color", color);
brush.SetSourceParameter("ImageSource", normalBrush);
brush.SetSourceParameter("ImageSource", _normalMap.Brush);
_brushList.Add(brush);
SpriteVisual sprite = _compositor.CreateSpriteVisual();
@ -191,6 +191,21 @@ namespace CompositionSampleGallery
UpdateAnimationState();
}
private void SamplePage_Unloaded(object sender, RoutedEventArgs e)
{
foreach (CompositionEffectBrush brush in _brushList)
{
brush.Dispose();
}
_brushList.Clear();
if (_normalMap != null)
{
_normalMap.Dispose();
_normalMap = null;
}
}
private void ConstructWalls()
{
// Connect the light controls to the walls

Просмотреть файл

@ -15,7 +15,6 @@
using CompositionSampleGallery.Samples.SDK_14393.NineGridResizing;
using CompositionSampleGallery.Samples.SDK_14393.NineGridResizing.NineGridScenarios;
using SamplesCommon;
using SamplesCommon.ImageLoader;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
@ -32,9 +31,9 @@ namespace CompositionSampleGallery
public sealed partial class NineGridResizing : SamplePage, INotifyPropertyChanged
{
private readonly Compositor _compositor;
private readonly IImageLoader _imageLoader;
private readonly Visual _backgroundContainer;
private readonly SpriteVisual _ninegridVisual;
private readonly ManagedSurface _ninegridSurface;
private readonly CompositionNineGridBrush _ninegridBrush;
private readonly ObservableCollection<INineGridScenario> _nineGridBrushScenarios;
private INineGridScenario _selectedBrushScenario;
@ -54,7 +53,6 @@ namespace CompositionSampleGallery
this.InitializeComponent();
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
// Add page loaded event listener
this.Loaded += NineGridResizing_Loaded;
@ -68,6 +66,7 @@ namespace CompositionSampleGallery
// Create ninegridbrush and paint on visual;
_ninegridBrush = _compositor.CreateNineGridBrush();
_ninegridVisual.Brush = _ninegridBrush;
_ninegridSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/NineGridResizing/RoundedRect.png"));
// Clip compgrid
var compGrid = ElementCompositionPreview.GetElementVisual(CompGrid);
@ -80,7 +79,7 @@ namespace CompositionSampleGallery
ElementCompositionPreview.SetElementChildVisual(ngHost, _ninegridVisual);
// Instatiate brush scenario list and fill with created brush scenarios
_nineGridBrushScenarios = new ObservableCollection<INineGridScenario>(CreateBrushes(_compositor, _imageLoader, _ninegridVisual.Size));
_nineGridBrushScenarios = new ObservableCollection<INineGridScenario>(CreateBrushes(_compositor, _ninegridSurface, _ninegridVisual.Size));
// Set default combo box selection to first item
BrushScenarioSelected = _nineGridBrushScenarios.FirstOrDefault();
@ -139,22 +138,19 @@ namespace CompositionSampleGallery
/// <summary>
/// Instantiate brush scenarios to use on the visual; used in combobox BrushSelection changed event.
/// </summary>
private static INineGridScenario[] CreateBrushes(Compositor compositor, IImageLoader imageLoader, Vector2 visualSize)
private static INineGridScenario[] CreateBrushes(Compositor compositor, ManagedSurface ninegridSurface, Vector2 visualSize)
{
// Load image to surfaceBrush (this asset serves as the alpha mask as well)
var surface = imageLoader.LoadImageFromUri(new Uri("ms-appx:///Samples/SDK 14393/NineGridResizing/RoundedRect.png"));
var imageBrush = compositor.CreateSurfaceBrush(surface);
imageBrush.Stretch = CompositionStretch.Fill;
ninegridSurface.Brush.Stretch = CompositionStretch.Fill;
// Create INineGridScenario array to return. Surface scenario is special because it's used as input to another scenario
var surfaceNineGridScenario = new SurfaceNineGridScenario(compositor, imageBrush, "Source: SurfaceBrush");
var surfaceNineGridScenario = new SurfaceNineGridScenario(compositor, ninegridSurface.Brush, "Source: SurfaceBrush");
return new INineGridScenario[]
{
new ColorNineGridScenario(compositor, "Source: ColorBrush(hollow)"),
new BorderNineGridScenario(compositor, imageBrush, visualSize, "Source: ColorBrush(w/ content)"),
new BorderNineGridScenario(compositor, ninegridSurface.Brush, visualSize, "Source: ColorBrush(w/ content)"),
surfaceNineGridScenario,
new EffectNineGridScenario(compositor, (CompositionNineGridBrush)surfaceNineGridScenario.Brush, "Input to: EffectBrush"),
new MaskNineGridScenario(compositor, imageBrush, "Input to: MaskBrush")
new MaskNineGridScenario(compositor, ninegridSurface.Brush, "Input to: MaskBrush")
};
}
@ -360,7 +356,6 @@ namespace CompositionSampleGallery
_valueTimerXSlider.Dispose();
_valueTimerYSlider.Dispose();
_valueTimerScaleSlider.Dispose();
_imageLoader.Dispose();
}
}
}

Просмотреть файл

@ -115,9 +115,9 @@ namespace CompositionSampleGallery
// Make the surface twice the height to give us room to scroll
Vector2 surfaceSize = new Vector2(sizeLightBounds.X, 2f * sizeLightBounds.Y);
CompositionDrawingSurface textSurface = SurfaceLoader.LoadText(text, surfaceSize.ToSize(),
ManagedSurface textSurface = ImageLoader.Instance.LoadText(text, surfaceSize.ToSize(),
textFormat, Colors.White, Colors.Transparent);
brush.SetSourceParameter("Text", _compositor.CreateSurfaceBrush(textSurface));
brush.SetSourceParameter("Text", textSurface.Brush);
// Create the sprite and parent it to the panel with the clip
_textSprite = _compositor.CreateSpriteVisual();

Просмотреть файл

@ -255,17 +255,11 @@ namespace CompositionSampleGallery
(byte)(maxColor >> 8), (byte)(maxColor >> 0));
}
private CompositionDrawingSurface SampleImageColor(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget)
private void SampleImageColor(CompositionDrawingSurface surface, CanvasBitmap bitmap, CompositionGraphicsDevice device)
{
// Extract the color to tint the blur with
Color predominantColor = ExtractPredominantColor(bitmap.GetPixelColors(), bitmap.Size);
Size sizeSource = bitmap.Size;
if (sizeTarget.IsEmpty)
{
sizeTarget = sizeSource;
}
// Create a heavily blurred version of the image
GaussianBlurEffect blurEffect = new GaussianBlurEffect()
{
@ -273,16 +267,13 @@ namespace CompositionSampleGallery
BlurAmount = 20.0f
};
CompositionDrawingSurface surface = device.CreateDrawingSurface(sizeTarget,
DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
Size size = surface.Size;
using (var ds = CanvasComposition.CreateDrawingSession(surface))
{
Rect destination = new Rect(0, 0, sizeTarget.Width, sizeTarget.Height);
Rect destination = new Rect(0, 0, size.Width, size.Height);
ds.FillRectangle(destination, predominantColor);
ds.DrawImage(blurEffect, destination, new Rect(0, 0, sizeSource.Width, sizeSource.Height), .6f);
ds.DrawImage(blurEffect, destination, new Rect(0, 0, size.Width, size.Height), .6f);
}
return surface;
}
private void ListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)

Просмотреть файл

@ -13,12 +13,8 @@
//*********************************************************
using SamplesCommon;
using SamplesCommon.ImageLoader;
using System;
using System.Numerics;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
namespace CompositionSampleGallery
@ -29,8 +25,7 @@ namespace CompositionSampleGallery
private Compositor _compositor;
private SpriteVisual _imageVisual;
private CompositionImage _image;
private IImageLoader _imageLoader;
private ICircleSurface _imageMaskSurface;
private ManagedSurface _imageMaskSurface;
private CompositionMaskBrush _maskBrush;
private bool _isMaskEnabled;
@ -55,19 +50,14 @@ namespace CompositionSampleGallery
_imageVisual = _image.SpriteVisual;
// Load mask asset onto surface using helpers in SamplesCommon
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
_imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
// Create surface brush for mask
CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
mask.Surface = _imageMaskSurface.Surface;
_imageMaskSurface = ImageLoader.Instance.LoadCircle(200, Colors.White);
// Get surface brush from composition image
CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;
// Create mask brush for toggle mask functionality
_maskBrush = _compositor.CreateMaskBrush();
_maskBrush.Mask = mask;
_maskBrush.Mask = _imageMaskSurface.Brush;
_maskBrush.Source = source;
// Initialize toggle mask
@ -80,11 +70,6 @@ namespace CompositionSampleGallery
{
_imageMaskSurface.Dispose();
}
if (_imageLoader != null)
{
_imageLoader.Dispose();
}
}
private void MaskButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)

Просмотреть файл

@ -43,7 +43,7 @@ namespace CompositionSampleGallery
// Sample metadata
public static string StaticSampleName { get { return "Advanced Shadows"; } }
public override string SampleName { get { return StaticSampleName; } }
public override string SampleDescription { get { return "Demonstrates advanced shadow scenarios."; } }
public override string SampleDescription { get { return "Demonstrates advanced shadow scenario with a simulated light position."; } }
public override string SampleCodeUri { get { return "http://go.microsoft.com/fwlink/p/?LinkID=761171"; } }
public ShadowsAdvanced()

Просмотреть файл

@ -8,7 +8,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data="using:CompositionSampleGallery.Shared"
mc:Ignorable="d"
Loaded ="Page_Loaded">
Loaded ="Page_Loaded"
Unloaded="Page_Unloaded">
<Grid>
<Grid.RowDefinitions>

Просмотреть файл

@ -35,12 +35,12 @@ namespace CompositionSampleGallery
{
private Compositor _compositor;
private CompositionEffectFactory _effectFactory;
private CompositionSurfaceBrush _flatNormalsBrush;
private CompositionSurfaceBrush _circleNormalsBrush;
private AmbientLight _ambientLight;
private PointLight _pointLight;
private DistantLight _distantLight;
private SpotLight _spotLight;
private ManagedSurface _sphereNormalMap;
private ManagedSurface _edgeNormalMap;
public enum LightingTypes
{
@ -100,9 +100,8 @@ namespace CompositionSampleGallery
// for masking off the rectangular edges.
//
CompositionDrawingSurface normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/ThumbnailLighting/SphericalWithMask.png"));
_circleNormalsBrush = _compositor.CreateSurfaceBrush(normalMap);
_circleNormalsBrush.Stretch = CompositionStretch.Fill;
_sphereNormalMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Samples/SDK 14393/ThumbnailLighting/SphericalWithMask.png"));
_sphereNormalMap.Brush.Stretch = CompositionStretch.Fill;
//
@ -110,14 +109,28 @@ namespace CompositionSampleGallery
// the edges, flat in the middle.
//
normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/ThumbnailLighting/BeveledEdges.jpg"));
_flatNormalsBrush = _compositor.CreateSurfaceBrush(normalMap);
_flatNormalsBrush.Stretch = CompositionStretch.Fill;
_edgeNormalMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Samples/SDK 14393/ThumbnailLighting/BeveledEdges.jpg"));
_edgeNormalMap.Brush.Stretch = CompositionStretch.Fill;
// Update the effect brushes now that the normal maps are available.
UpdateEffectBrush();
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
if (_sphereNormalMap != null)
{
_sphereNormalMap.Dispose();
_sphereNormalMap = null;
}
if (_edgeNormalMap != null)
{
_edgeNormalMap.Dispose();
_edgeNormalMap = null;
}
}
private void UpdateEffectBrush()
{
if (ThumbnailList.ItemsPanelRoot != null)
@ -229,10 +242,10 @@ namespace CompositionSampleGallery
case LightingTypes.PointSpecular:
case LightingTypes.DistantDiffuse:
case LightingTypes.DistantSpecular:
brush.SetSourceParameter("NormalMap", _circleNormalsBrush);
brush.SetSourceParameter("NormalMap", _sphereNormalMap == null ? null : _sphereNormalMap.Brush);
break;
default:
brush.SetSourceParameter("NormalMap", _flatNormalsBrush);
brush.SetSourceParameter("NormalMap", _edgeNormalMap == null ? null : _edgeNormalMap.Brush);
break;
}

Просмотреть файл

@ -3,10 +3,8 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using CompositionSampleGallery.Commands;
using Windows.Media.Core;
@ -16,11 +14,10 @@ using Windows.Storage.Pickers;
using Windows.UI.Composition;
using Windows.UI.Core;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
using SamplesCommon.ImageLoader;
using Windows.UI;
using SamplesCommon;
namespace CompositionSampleGallery
{
@ -65,12 +62,11 @@ namespace CompositionSampleGallery
private ContainerVisual _videoRootVisual;
private SpriteVisual _videoVisual;
private CompositionSurfaceBrush _videoBrush;
private IImageLoader _imageLoader;
// Composition - Lighting
private LightMode _lightMode;
private List<Light> _lights;
private ICircleSurface _circleSurface;
private CompositionSurfaceBrush _circleBrush;
private ManagedSurface _circleSurface;
// Page specific objects/variables.
private ObservableCollection<double> _durationList;
@ -636,7 +632,7 @@ namespace CompositionSampleGallery
EnsureCircleBrush();
visual.Brush = _circleBrush;
visual.Brush = _circleSurface.Brush;
return visual;
}
@ -646,11 +642,9 @@ namespace CompositionSampleGallery
/// </summary>
private void EnsureCircleBrush()
{
if (_circleBrush == null)
if (_circleSurface == null)
{
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
_circleSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
_circleBrush = _compositor.CreateSurfaceBrush(_circleSurface.Surface);
_circleSurface = ImageLoader.Instance.LoadCircle(200, Colors.White);
}
}
@ -685,7 +679,6 @@ namespace CompositionSampleGallery
if (_circleSurface != null)
{
_imageLoader.Dispose();
_circleSurface.Dispose();
}
}

Просмотреть файл

@ -6,7 +6,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Loaded="Page_Loaded">
Loaded="Page_Loaded"
Unloaded="Page_Unloaded">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>

Просмотреть файл

@ -14,6 +14,7 @@
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using SamplesCommon;
using System;
using System.Collections.Generic;
using System.Numerics;
@ -21,7 +22,6 @@ using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
using SamplesCommon.ImageLoader;
using Windows.UI.Xaml.Media.Imaging;
namespace CompositionSampleGallery
@ -30,8 +30,7 @@ namespace CompositionSampleGallery
{
private Compositor _compositor;
private SpriteVisual _sprite;
private CompositionSurfaceBrush _imageBrush;
private IImageLoader _imageLoader;
private ManagedSurface _image;
enum ImageName
{
@ -42,7 +41,6 @@ namespace CompositionSampleGallery
public BorderPlayground()
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
this.InitializeComponent();
}
@ -53,7 +51,6 @@ namespace CompositionSampleGallery
private void Page_Loaded(object sender, RoutedEventArgs e)
{
_imageBrush = _compositor.CreateSurfaceBrush();
_sprite = _compositor.CreateSpriteVisual();
_sprite.Size = new Vector2((float)BorderImage.ActualWidth, (float)BorderImage.ActualHeight);
ElementCompositionPreview.SetElementChildVisual(BorderImage, _sprite);
@ -74,10 +71,18 @@ namespace CompositionSampleGallery
ExtendYBox.SelectedIndex = 0;
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
if (_image != null)
{
_image.Dispose();
_image = null;
}
}
private void SetImageBrush(string uri)
{
// Update the sprite
_imageBrush.Surface = _imageLoader.LoadImageFromUri(new Uri(uri));
_image = ImageLoader.Instance.LoadFromUri(new Uri(uri));
UpdateImageBrush();
// Update the preview image
@ -119,7 +124,7 @@ namespace CompositionSampleGallery
};
var brush = _compositor.CreateEffectFactory(borderEffect).CreateBrush();
brush.SetSourceParameter("source", _imageBrush);
brush.SetSourceParameter("source", _image.Brush);
_sprite.Brush = brush;
}
@ -142,16 +147,16 @@ namespace CompositionSampleGallery
void UpdateImageBrush()
{
_imageBrush.Scale = new Vector2((float)ScaleX.Value, (float)ScaleY.Value);
_imageBrush.Offset = new Vector2((float)OffsetX.Value, (float)OffsetY.Value);
_imageBrush.RotationAngleInDegrees = (float)Rotation.Value;
_imageBrush.Stretch = CompositionStretch.None;
_imageBrush.CenterPoint = new Vector2(_sprite.Size.X / 2f, _sprite.Size.Y / 2f);
_image.Brush.Scale = new Vector2((float)ScaleX.Value, (float)ScaleY.Value);
_image.Brush.Offset = new Vector2((float)OffsetX.Value, (float)OffsetY.Value);
_image.Brush.RotationAngleInDegrees = (float)Rotation.Value;
_image.Brush.Stretch = CompositionStretch.None;
_image.Brush.CenterPoint = new Vector2(_sprite.Size.X / 2f, _sprite.Size.Y / 2f);
}
private void Slider_ValueChanged(object sender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e)
{
if (_imageBrush != null)
if (_image != null)
{
UpdateImageBrush();
}

Просмотреть файл

@ -14,7 +14,6 @@
using Microsoft.Graphics.Canvas.Effects;
using SamplesCommon;
using SamplesCommon.ImageLoader;
using System;
using System.ComponentModel;
using System.Numerics;
@ -31,10 +30,10 @@ namespace CompositionSampleGallery
private SpriteVisual _circleImageVisual;
private SpriteVisual _backgroundImageVisual;
private CompositionCapabilities _capabilities;
private CompositionSurfaceBrush _imageSurfaceBrush;
private ManagedSurface _surface;
private ManagedSurface _circleMaskSurface;
private ContainerVisual _imageContainer;
private string _capabilityText = "";
private IImageLoader _imageLoader;
private bool _containsCircleImage = false;
public static string StaticSampleName { get { return "Composition Capabilities"; } }
@ -54,8 +53,6 @@ namespace CompositionSampleGallery
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
// Get hardware capabilities and register changed event listener
_capabilities = CompositionCapabilities.GetForCurrentView();
}
@ -93,18 +90,15 @@ namespace CompositionSampleGallery
{
_backgroundImageVisual = _compositor.CreateSpriteVisual();
_imageContainer = _compositor.CreateContainerVisual();
_imageSurfaceBrush = _compositor.CreateSurfaceBrush();
_capabilities.Changed += HandleCapabilitiesChanged;
ElementCompositionPreview.SetElementChildVisual(ImageCanvas, _imageContainer);
// Load in image
var uri = new Uri("ms-appx:///Assets/Landscapes/Landscape-7.jpg");
var surface = await SurfaceLoader.LoadFromUri(uri);
var imageSurface = _compositor.CreateSurfaceBrush(surface);
_imageSurfaceBrush.Surface = imageSurface.Surface;
_imageSurfaceBrush.Stretch = CompositionStretch.Fill;
// Load the image
_surface = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Assets/Landscapes/Landscape-7.jpg"));
_surface.Brush.Stretch = CompositionStretch.Fill;
_circleMaskSurface = ImageLoader.Instance.LoadCircle(200, Colors.White);
_circleMaskSurface.Brush.Stretch = CompositionStretch.Uniform;
_imageContainer.Size = new Vector2((float)ImageCanvas.ActualWidth, (float)ImageCanvas.ActualHeight);
@ -131,7 +125,7 @@ namespace CompositionSampleGallery
if (!_containsCircleImage)
{
// Create circle mask
var circleMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
_circleMaskSurface = ImageLoader.Instance.LoadCircle(200, Colors.White);
// Create image visual to use as the circle-masked center image
_circleImageVisual = _compositor.CreateSpriteVisual();
@ -140,15 +134,10 @@ namespace CompositionSampleGallery
var yOffset = (float)(ImageCanvas.ActualHeight / 2 - _circleImageVisual.Size.Y / 2);
_circleImageVisual.Offset = new Vector3(xOffset, yOffset, 0);
// Create circle image surface
CompositionSurfaceBrush circleSurfaceBrush = _compositor.CreateSurfaceBrush();
circleSurfaceBrush.Surface = circleMaskSurface.Surface;
circleSurfaceBrush.Stretch = CompositionStretch.Uniform;
// Apply mask to visual
CompositionMaskBrush maskBrush = _compositor.CreateMaskBrush();
maskBrush.Source = _imageSurfaceBrush;
maskBrush.Mask = circleSurfaceBrush;
maskBrush.Source = _surface.Brush;
maskBrush.Mask = _circleMaskSurface.Brush;
_circleImageVisual.Brush = maskBrush;
@ -181,7 +170,7 @@ namespace CompositionSampleGallery
CompositionEffectFactory chainedEffectFactory = _compositor.CreateEffectFactory(chainedEffect);
CompositionEffectBrush effectBrush = chainedEffectFactory.CreateBrush();
effectBrush.SetSourceParameter("SaturationSource", _imageSurfaceBrush);
effectBrush.SetSourceParameter("SaturationSource", _surface.Brush);
_backgroundImageVisual.Brush = effectBrush;
@ -193,7 +182,7 @@ namespace CompositionSampleGallery
CompositionEffectFactory saturationEffectFactory = _compositor.CreateEffectFactory(saturationEffect);
CompositionEffectBrush saturationBrush = saturationEffectFactory.CreateBrush();
saturationBrush.SetSourceParameter("SaturationSource", _imageSurfaceBrush);
saturationBrush.SetSourceParameter("SaturationSource", _surface.Brush);
_backgroundImageVisual.Brush = saturationBrush;
@ -213,7 +202,7 @@ namespace CompositionSampleGallery
_containsCircleImage = false;
}
_backgroundImageVisual.Brush = _imageSurfaceBrush;
_backgroundImageVisual.Brush = _surface.Brush;
CapabilityText = "Effects not supported. No effects are applied.";
}
@ -252,10 +241,16 @@ namespace CompositionSampleGallery
{
_capabilities.Changed -= HandleCapabilitiesChanged;
if (_imageSurfaceBrush != null)
if (_surface != null)
{
_imageLoader.Dispose();
_imageSurfaceBrush.Dispose();
_surface.Dispose();
_surface = null;
}
if (_circleMaskSurface != null)
{
_circleMaskSurface.Dispose();
_circleMaskSurface = null;
}
}
}

Просмотреть файл

@ -52,7 +52,7 @@ namespace CompositionSampleGallery
// Automatically have the FlipView progress to the next item
if (Model.FlipViewItems.Count() > 1)
{
ProgressFlipView();
Task t = ProgressFlipView();
}
}

Просмотреть файл

@ -101,14 +101,22 @@ namespace CompositionSampleGallery
{
static SampleDefinitions()
{
// Populate the _definitions array only with samples that are supported by the current runtime
var samples = _allDefinitions.Where(s => MainPage.RuntimeCapabilities.AllSupportedSdkVersions.Contains(s.SDKVersion));
Array.Resize<SampleDefinition>(ref _definitions, samples.Count());
Array.Copy(samples.ToArray<SampleDefinition>(), _definitions, samples.Count());
RefreshSampleList();
}
static public void RefreshSampleList()
{
// Populate the _definitions array only with samples that are supported by the current runtime and hardware
var result = from sampleDef in _allDefinitions
where MainPage.RuntimeCapabilities.AllSupportedSdkVersions.Contains(sampleDef.SDKVersion) &&
(!sampleDef.RequiresFastEffects || MainPage.AreEffectsFast) &&
(!sampleDef.RequiresEffects || MainPage.AreEffectsSupported)
select sampleDef;
_definitions = result.ToList();
}
// A filtered list of runtime-supported samples
static SampleDefinition[] _definitions = { };
static List<SampleDefinition> _definitions = new List<SampleDefinition>();
// Full list of all definitions
static SampleDefinition[] _allDefinitions =
@ -163,7 +171,7 @@ namespace CompositionSampleGallery
#endif
};
public static SampleDefinition[] Definitions
public static List<SampleDefinition> Definitions
{
get { return _definitions; }
}

Просмотреть файл

@ -12,12 +12,12 @@ namespace SamplesCommon
{
Compositor m_compositor;
SpriteVisual m_blurVisual;
CompositionBrush m_blurBrush;
CompositionEffectBrush m_blurBrush;
Visual m_rootVisual;
#if SDKVERSION_14393
bool m_setUpExpressions;
CompositionSurfaceBrush m_noiseBrush;
ManagedSurface m_noiseSurface;
#endif
public BackDrop()
@ -28,8 +28,6 @@ namespace SamplesCommon
m_blurVisual = Compositor.CreateSpriteVisual();
#if SDKVERSION_14393
m_noiseBrush = Compositor.CreateSurfaceBrush();
CompositionEffectBrush brush = BuildBlurBrush();
brush.SetSourceParameter("source", m_compositor.CreateBackdropBrush());
m_blurBrush = brush;
@ -118,8 +116,9 @@ namespace SamplesCommon
OnSizeChanged(this, null);
#if SDKVERSION_14393
m_noiseBrush.Surface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Assets/Noise.jpg"));
m_noiseBrush.Stretch = CompositionStretch.UniformToFill;
m_noiseSurface = ImageLoader.Instance.LoadFromUri(new Uri("ms-appx:///Assets/Noise.jpg"));
m_noiseSurface.Brush.Stretch = CompositionStretch.UniformToFill;
m_blurBrush.SetSourceParameter("NoiseImage", m_noiseSurface.Brush);
#endif
}
@ -190,9 +189,7 @@ namespace SamplesCommon
new[] { "Blur.BlurAmount", "Color.Color" }
);
CompositionEffectBrush brush = factory.CreateBrush();
brush.SetSourceParameter("NoiseImage", m_noiseBrush);
return brush;
return factory.CreateBrush();
}
public CompositionPropertySet VisualProperties

Просмотреть файл

@ -33,7 +33,7 @@ namespace SamplesCommon
private Compositor _compositor;
private SpriteVisual _sprite;
private Uri _uri;
private CompositionDrawingSurface _surface;
private ManagedSurface _surface;
private CompositionSurfaceBrush _surfaceBrush;
private CompositionBrush _brush;
private LoadTimeEffectHandler _loadEffectDelegate;
@ -82,12 +82,6 @@ namespace SamplesCommon
_staticsInitialized = true;
}
// Initialize the surface loader if needed
if (!SurfaceLoader.IsInitialized)
{
SurfaceLoader.Initialize(ElementCompositionPreview.GetElementVisual(this).Compositor);
}
_placeholderDelay = TimeSpan.FromMilliseconds(50);
_surfaceBrush = _compositor.CreateSurfaceBrush(null);
}
@ -102,6 +96,11 @@ namespace SamplesCommon
_surface.Dispose();
_surfaceBrush.Surface = null;
}
else
{
// No longer being managed
ImageLoader.Instance.UnregisterSurface(_surface);
}
_surface = null;
}
}
@ -237,7 +236,7 @@ namespace SamplesCommon
private void UpdateBrush()
{
_surfaceBrush.Surface = _surface;
_surfaceBrush.Surface = _surface == null ? null : _surface.Surface;
_surfaceBrush.Stretch = _stretchMode;
if (_sprite != null)
@ -375,7 +374,7 @@ namespace SamplesCommon
}
// Load the image asynchronously
CompositionDrawingSurface surface = await SurfaceLoader.LoadFromUri(_uri, Size.Empty, _loadEffectDelegate);
ManagedSurface surface = await ImageLoader.Instance.LoadFromUriAsync(_uri, Size.Empty, _loadEffectDelegate);
if (_surface != null)
{

Просмотреть файл

@ -1,97 +0,0 @@
using Microsoft.Graphics.Canvas.UI.Composition;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Composition;
namespace SamplesCommon.ImageLoader
{
public interface ICircleSurface : IDisposable
{
IImageLoader ImageLoader { get; }
ICompositionSurface Surface { get; }
float Radius { get; set; }
Color Color { get; set; }
Size Size { get; }
void RedrawSurface();
}
class CircleSurface : ICircleSurface
{
private IImageLoaderInternal _imageLoader;
private CompositionDrawingSurface _surface;
private float _radius;
private Color _color;
public IImageLoader ImageLoader { get { return _imageLoader; } }
public ICompositionSurface Surface { get { return _surface; } }
public Size Size { get { return _surface.Size; } }
public float Radius
{
get { return _radius; }
set
{
if (_radius != value)
{
_radius = value;
_imageLoader.ResizeSurface(_surface, new Size(_radius * 2, _radius * 2));
RedrawSurface();
}
}
}
public Color Color
{
get { return _color; }
set
{
if (_color != value)
{
_color = value;
RedrawSurface();
}
}
}
public CircleSurface(IImageLoaderInternal imageLoader, float radius, Color color)
{
_imageLoader = imageLoader;
_radius = radius;
_color = color;
_surface = _imageLoader.CreateSurface(new Size(radius * 2, radius * 2));
_imageLoader.DeviceReplacedEvent += OnDeviceReplaced;
}
private void OnDeviceReplaced(object sender, object e)
{
RedrawSurface();
}
public void RedrawSurface()
{
_imageLoader.DrawIntoSurface(_surface, (surface, device) =>
{
using (var session = CanvasComposition.CreateDrawingSession(surface))
{
session.Clear(Colors.Transparent);
session.FillCircle(new Vector2(_radius, _radius), _radius, _color);
}
});
}
public void Dispose()
{
_surface.Dispose();
_imageLoader.DeviceReplacedEvent -= OnDeviceReplaced;
_surface = null;
_imageLoader = null;
}
}
}

Просмотреть файл

@ -0,0 +1,133 @@
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Graphics.Canvas.UI.Composition;
using System;
using System.Numerics;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Composition;
namespace SamplesCommon
{
public abstract class ContentDrawer
{
public abstract Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size);
}
public delegate void LoadTimeEffectHandler(CompositionDrawingSurface surface, CanvasBitmap bitmap, CompositionGraphicsDevice device);
public class BitmapDrawer : ContentDrawer
{
Uri _uri;
LoadTimeEffectHandler _handler;
public BitmapDrawer(Uri uri, LoadTimeEffectHandler handler)
{
_uri = uri;
_handler = handler;
}
public Uri Uri
{
get { return _uri; }
}
public override async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size)
{
var canvasDevice = CanvasComposition.GetCanvasDevice(device);
using (var canvasBitmap = await CanvasBitmap.LoadAsync(canvasDevice, _uri))
{
var bitmapSize = canvasBitmap.Size;
//
// Because the drawing is done asynchronously and multiple threads could
// be trying to get access to the device/surface at the same time, we need
// to do any device/surface work under a lock.
//
lock (drawingLock)
{
Size surfaceSize = size;
if (surface.Size != size || surface.Size == new Size(0, 0))
{
// Resize the surface to the size of the image
CanvasComposition.Resize(surface, bitmapSize);
surfaceSize = bitmapSize;
}
// Allow the app to process the bitmap if requested
if (_handler != null)
{
_handler(surface, canvasBitmap, device);
}
else
{
// Draw the image to the surface
using (var session = CanvasComposition.CreateDrawingSession(surface))
{
session.Clear(Windows.UI.Color.FromArgb(0, 0, 0, 0));
session.DrawImage(canvasBitmap, new Rect(0, 0, surfaceSize.Width, surfaceSize.Height), new Rect(0, 0, bitmapSize.Width, bitmapSize.Height));
}
}
}
}
}
}
internal class CircleDrawer : ContentDrawer
{
private float _radius;
private Color _color;
public CircleDrawer(float radius, Color color)
{
_radius = radius;
_color = color;
}
public float Radius
{
get { return _radius; }
}
public Color Color
{
get { return _color; }
}
#pragma warning disable 1998
public override async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size)
{
using (var ds = CanvasComposition.CreateDrawingSession(surface))
{
ds.Clear(Colors.Transparent);
ds.FillCircle(new Vector2(_radius, _radius), _radius, _color);
}
}
}
internal class TextDrawer : ContentDrawer
{
private string _text;
private CanvasTextFormat _textFormat;
private Color _textColor;
private Color _backgroundColor;
public TextDrawer(string text, CanvasTextFormat textFormat, Color textColor, Color bgColor)
{
_text = text;
_textFormat = textFormat;
_textColor = textColor;
_backgroundColor = bgColor;
}
public override async Task Draw(CompositionGraphicsDevice device, Object drawingLock, CompositionDrawingSurface surface, Size size)
{
using (var ds = CanvasComposition.CreateDrawingSession(surface))
{
ds.Clear(_backgroundColor);
ds.DrawText(_text, new Rect(0, 0, surface.Size.Width, surface.Size.Height), _textColor, _textFormat);
}
}
}
}

Просмотреть файл

@ -1,263 +1,181 @@
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.UI.Composition;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Windows.Graphics.DirectX;
using Windows.Graphics.Display;
using Windows.UI;
using Windows.UI.Composition;
using SamplesNative;
using Microsoft.Graphics.Canvas.Text;
namespace SamplesCommon.ImageLoader
namespace SamplesCommon
{
public interface IImageLoader : IDisposable
public class DeviceReplacedEventArgs : EventArgs
{
event EventHandler<Object> DeviceReplacedEvent;
CompositionDrawingSurface LoadImageFromUri(Uri uri);
CompositionDrawingSurface LoadImageFromUri(Uri uri, Size size);
IAsyncOperation<CompositionDrawingSurface> LoadImageFromUriAsync(Uri uri);
IAsyncOperation<CompositionDrawingSurface> LoadImageFromUriAsync(Uri uri, Size size);
IManagedSurface CreateManagedSurfaceFromUri(Uri uri);
IManagedSurface CreateManagedSurfaceFromUri(Uri uri, Size size);
IAsyncOperation<IManagedSurface> CreateManagedSurfaceFromUriAsync(Uri uri);
IAsyncOperation<IManagedSurface> CreateManagedSurfaceFromUriAsync(Uri uri, Size size);
ICircleSurface CreateCircleSurface(float radius, Color color);
internal DeviceReplacedEventArgs(CompositionGraphicsDevice device, Object drawingLock)
{
GraphicsDevce = device;
DrawingLock = drawingLock;
}
interface IImageLoaderInternal : IImageLoader
{
CompositionDrawingSurface CreateSurface(Size size);
void ResizeSurface(CompositionDrawingSurface surface, Size size);
Task DrawSurface(CompositionDrawingSurface surface, Uri uri, Size size);
void DrawIntoSurface(CompositionDrawingSurface surface, DrawingCallback callback);
public CompositionGraphicsDevice GraphicsDevce { get; set; }
public Object DrawingLock { get; set; }
}
public static class ImageLoaderFactory
public class ImageLoader
{
[DefaultOverloadAttribute]
public static IImageLoader CreateImageLoader(Compositor compositor)
{
var imageLoader = new ImageLoader();
imageLoader.Initialize(compositor);
return imageLoader;
}
public static IImageLoader CreateImageLoader(CompositionGraphicsDevice graphicsDevice)
{
var imageLoader = new ImageLoader();
imageLoader.Initialize(graphicsDevice);
return imageLoader;
}
}
delegate void DrawingCallback(CompositionDrawingSurface surface, CompositionGraphicsDevice device);
class ImageLoader : IImageLoaderInternal
{
public event EventHandler<Object> DeviceReplacedEvent;
private static bool _intialized;
private static ImageLoader _imageLoader;
private DeviceLostHelper _deviceLostHelper;
private Compositor _compositor;
private CanvasDevice _canvasDevice;
private CompositionGraphicsDevice _graphicsDevice;
private Object _drawingLock;
private event EventHandler<Object> _deviceReplacedEvent;
private bool _isDeviceCreator;
public ImageLoader() { }
private void OnDisplayContentsInvalidated(DisplayInformation sender, object args)
public ImageLoader(Compositor compositor)
{
Debug.WriteLine("CompositionImageLoader - Display Contents Invalidated");
//
// This will trigger the device lost event
//
CanvasDevice.GetSharedDevice();
}
Debug.Assert(compositor != null && _compositor == null);
public void Initialize(Compositor compositor)
{
_compositor = compositor;
_drawingLock = new object();
_isDeviceCreator = true;
DisplayInformation.DisplayContentsInvalidated += OnDisplayContentsInvalidated;
CreateDevice();
}
_deviceLostHelper = new DeviceLostHelper();
public void Initialize(CompositionGraphicsDevice graphicsDevice)
{
_graphicsDevice = graphicsDevice;
_graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced;
_drawingLock = new object();
_isDeviceCreator = false;
//
// We don't call CreateDevice, as it wouldn't do anything
// since we don't have a Compositor.
//
}
private void CreateDevice()
{
if (_compositor != null)
{
if (_canvasDevice == null)
{
_canvasDevice = new CanvasDevice();
_canvasDevice.DeviceLost += DeviceLost;
}
if (_graphicsDevice == null)
{
_deviceLostHelper.WatchDevice(_canvasDevice);
_deviceLostHelper.DeviceLost += DeviceRemoved;
_graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
_graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced;
}
static public void Initialize(Compositor compositor)
{
Debug.Assert(!_intialized);
if (!_intialized)
{
_imageLoader = new ImageLoader(compositor);
_intialized = true;
}
}
static public ImageLoader Instance
{
get
{
Debug.Assert(_intialized);
return _imageLoader;
}
}
private void DeviceRemoved(DeviceLostHelper sender, object args)
{
_canvasDevice.RaiseDeviceLost();
}
private void DeviceLost(CanvasDevice sender, object args)
{
Debug.WriteLine("CompositionImageLoader - Canvas Device Lost");
sender.DeviceLost -= DeviceLost;
_canvasDevice = CanvasDevice.GetSharedDevice();
_canvasDevice = new CanvasDevice();
_canvasDevice.DeviceLost += DeviceLost;
_deviceLostHelper.WatchDevice(_canvasDevice);
CanvasComposition.SetCanvasDevice(_graphicsDevice, _canvasDevice);
}
private void RenderingDeviceReplaced(CompositionGraphicsDevice sender, RenderingDeviceReplacedEventArgs args)
{
Debug.WriteLine("CompositionImageLoader - Rendering Device Replaced");
Task.Run(() =>
{
if (DeviceReplacedEvent != null)
if (_deviceReplacedEvent != null)
{
RaiseDeviceReplacedEvent();
}
});
}
public void RegisterSurface(ManagedSurface surface)
{
_deviceReplacedEvent += surface.OnDeviceReplaced;
}
public void UnregisterSurface(ManagedSurface surface)
{
_deviceReplacedEvent -= surface.OnDeviceReplaced;
}
private void RaiseDeviceReplacedEvent()
{
var deviceEvent = DeviceReplacedEvent;
if (deviceEvent != null)
{
deviceEvent(this, new EventArgs());
}
_deviceReplacedEvent?.Invoke(this, new DeviceReplacedEventArgs(_graphicsDevice, _drawingLock));
}
public CompositionDrawingSurface LoadImageFromUri(Uri uri)
public ManagedSurface LoadFromUri(Uri uri)
{
return LoadImageFromUri(uri, Size.Empty);
return LoadFromUri(uri, Size.Empty);
}
public CompositionDrawingSurface LoadImageFromUri(Uri uri, Size size)
public ManagedSurface LoadFromUri(Uri uri, Size size)
{
var surface = CreateSurface(size);
return LoadFromUri(uri, Size.Empty, null);
}
//
// We don't await this call, as we don't want to block
// the caller.
//
var ignored = DrawSurface(surface, uri, size);
public ManagedSurface LoadFromUri(Uri uri, Size size, LoadTimeEffectHandler handler)
{
ManagedSurface surface = new ManagedSurface(CreateSurface(size));
var ignored = surface.Draw(_graphicsDevice, _drawingLock, new BitmapDrawer(uri, handler));
return surface;
}
private async Task<CompositionDrawingSurface> LoadImageFromUriAsyncWorker(Uri uri, Size size)
private async Task<ManagedSurface> LoadFromUriAsyncWorker(Uri uri, Size size, LoadTimeEffectHandler handler)
{
var surface = CreateSurface(size);
await DrawSurface(surface, uri , size);
ManagedSurface surface = new ManagedSurface(CreateSurface(size));
await surface.Draw(_graphicsDevice, _drawingLock, new BitmapDrawer(uri, handler));
return surface;
}
public IAsyncOperation<CompositionDrawingSurface> LoadImageFromUriAsync(Uri uri)
public IAsyncOperation<ManagedSurface> LoadFromUriAsync(Uri uri)
{
return LoadImageFromUriAsync(uri, Size.Empty);
}
public IAsyncOperation<CompositionDrawingSurface> LoadImageFromUriAsync(Uri uri, Size size)
{
return LoadImageFromUriAsyncWorker(uri, size).AsAsyncOperation<CompositionDrawingSurface>();
return LoadFromUriAsyncWorker(uri, Size.Empty, null).AsAsyncOperation<ManagedSurface>();
}
public IManagedSurface CreateManagedSurfaceFromUri(Uri uri)
public IAsyncOperation<ManagedSurface> LoadFromUriAsync(Uri uri, Size size)
{
return CreateManagedSurfaceFromUri(uri, Size.Empty);
return LoadFromUriAsyncWorker(uri, size, null).AsAsyncOperation<ManagedSurface>();
}
public IManagedSurface CreateManagedSurfaceFromUri(Uri uri, Size size)
public IAsyncOperation<ManagedSurface> LoadFromUriAsync(Uri uri, Size size, LoadTimeEffectHandler handler)
{
var managedSurface = new ManagedSurface(this, uri, size);
var ignored = managedSurface.RedrawSurface();
return managedSurface;
return LoadFromUriAsyncWorker(uri, size, handler).AsAsyncOperation<ManagedSurface>();
}
public async Task<IManagedSurface> CreateManagedSurfaceFromUriAsyncWorker(Uri uri, Size size)
public ManagedSurface LoadCircle(float radius, Color color)
{
var managedSurface = new ManagedSurface(this, uri, size);
await managedSurface.RedrawSurface();
ManagedSurface surface = new ManagedSurface(CreateSurface(new Size(radius * 2, radius * 2)));
var ignored = surface.Draw(_graphicsDevice, _drawingLock, new CircleDrawer(radius, color));
return managedSurface;
return surface;
}
public IAsyncOperation<IManagedSurface> CreateManagedSurfaceFromUriAsync(Uri uri)
public ManagedSurface LoadText(string text, Size size, CanvasTextFormat textFormat, Color textColor, Color bgColor)
{
return CreateManagedSurfaceFromUriAsyncWorker(uri, Size.Empty).AsAsyncOperation<IManagedSurface>();
ManagedSurface surface = new ManagedSurface(CreateSurface(size));
var ignored = surface.Draw(_graphicsDevice, _drawingLock, new TextDrawer(text, textFormat, textColor, bgColor));
return surface;
}
public IAsyncOperation<IManagedSurface> CreateManagedSurfaceFromUriAsync(Uri uri, Size size)
{
return CreateManagedSurfaceFromUriAsyncWorker(uri, size).AsAsyncOperation<IManagedSurface>();
}
public ICircleSurface CreateCircleSurface(float radius, Color color)
{
var circleSurface = new CircleSurface(this, radius, color);
circleSurface.RedrawSurface();
return circleSurface;
}
public async Task DrawSurface(CompositionDrawingSurface surface, Uri uri, Size size)
{
var canvasDevice = CanvasComposition.GetCanvasDevice(_graphicsDevice);
using (var canvasBitmap = await CanvasBitmap.LoadAsync(canvasDevice, uri))
{
var bitmapSize = canvasBitmap.Size;
//
// Because the drawing is done asynchronously and multiple threads could
// be trying to get access to the device/surface at the same time, we need
// to do any device/surface work under a lock.
//
lock (_drawingLock)
{
Size surfaceSize = size;
if (surfaceSize.IsEmpty)
{
// Resize the surface to the size of the image
CanvasComposition.Resize(surface, bitmapSize);
surfaceSize = bitmapSize;
}
// Draw the image to the surface
using (var session = CanvasComposition.CreateDrawingSession(surface))
{
session.Clear(Windows.UI.Color.FromArgb(0, 0, 0, 0));
session.DrawImage(canvasBitmap, new Rect(0, 0, surfaceSize.Width, surfaceSize.Height), new Rect(0, 0, bitmapSize.Width, bitmapSize.Height));
}
}
}
}
public CompositionDrawingSurface CreateSurface(Size size)
private CompositionDrawingSurface CreateSurface(Size size)
{
Size surfaceSize = size;
if (surfaceSize.IsEmpty)
@ -274,55 +192,23 @@ namespace SamplesCommon.ImageLoader
return surface;
}
public void ResizeSurface(CompositionDrawingSurface surface, Size size)
{
if (!size.IsEmpty)
{
lock(_drawingLock)
{
CanvasComposition.Resize(surface, size);
}
}
}
public void DrawIntoSurface(CompositionDrawingSurface surface, DrawingCallback callback)
{
lock(_drawingLock)
{
callback(surface, _graphicsDevice);
}
}
public void Dispose()
{
lock (_drawingLock)
{
_compositor = null;
DisplayInformation.DisplayContentsInvalidated -= OnDisplayContentsInvalidated;
if (_canvasDevice != null)
{
_canvasDevice.DeviceLost -= DeviceLost;
//
// Only dispose the canvas device if we own the device.
//
if (_isDeviceCreator)
{
_canvasDevice.Dispose();
}
_canvasDevice = null;
}
if (_graphicsDevice != null)
{
_graphicsDevice.RenderingDeviceReplaced -= RenderingDeviceReplaced;
//
// Only dispose the composition graphics device if we own the device.
//
if (_isDeviceCreator)
{
_graphicsDevice.Dispose();
}
_graphicsDevice = null;
}
}

Просмотреть файл

@ -1,53 +1,32 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Composition;
namespace SamplesCommon.ImageLoader
namespace SamplesCommon
{
public interface IManagedSurface : IDisposable
public class ManagedSurface
{
IImageLoader ImageLoader { get; }
ICompositionSurface Surface { get; }
Uri Source { get; }
Size Size { get; }
IAsyncAction RedrawSurface();
IAsyncAction RedrawSurface(Uri uri);
IAsyncAction RedrawSurface(Uri uri, Size size);
void Resize(Size size);
}
class ManagedSurface : IManagedSurface
{
private IImageLoaderInternal _imageLoader;
private CompositionDrawingSurface _surface;
private Uri _uri;
private ContentDrawer _drawer;
private CompositionSurfaceBrush _brush;
public IImageLoader ImageLoader
public CompositionDrawingSurface Surface
{
get { return _surface; }
}
public CompositionSurfaceBrush Brush
{
get
{
return _imageLoader;
}
if (_brush == null)
{
_brush = _surface.Compositor.CreateSurfaceBrush(_surface);
}
public ICompositionSurface Surface
{
get
{
return _surface;
}
}
public Uri Source
{
get
{
return _uri;
return _brush;
}
}
@ -55,65 +34,54 @@ namespace SamplesCommon.ImageLoader
{
get
{
if (_surface != null)
{
return _surface.Size;
}
else
{
return Size.Empty;
}
return (_surface != null) ? _surface.Size : Size.Empty;
}
}
public ManagedSurface(IImageLoaderInternal imageLoader, Uri uri, Size size)
public ManagedSurface(CompositionDrawingSurface surface)
{
_imageLoader = imageLoader;
_uri = uri;
_surface = _imageLoader.CreateSurface(size);
Debug.Assert(surface != null);
_surface = surface;
_imageLoader.DeviceReplacedEvent += OnDeviceReplaced;
ImageLoader.Instance.RegisterSurface(this);
}
private async void OnDeviceReplaced(object sender, object e)
public async Task Draw(CompositionGraphicsDevice device, Object drawingLock, ContentDrawer drawer)
{
Debug.WriteLine("CompositionImageLoader - Redrawing ManagedSurface from Device Replaced");
await RedrawSurface();
Debug.Assert(_surface != null);
_drawer = drawer;
await _drawer.Draw(device, drawingLock, _surface, _surface.Size);
}
public IAsyncAction RedrawSurface()
private async Task ReloadContent(CompositionGraphicsDevice device, Object drawingLock)
{
return RedrawSurfaceWorker(_uri, Size.Empty).AsAsyncAction();
await _drawer.Draw(device, drawingLock, _surface, _surface.Size);
}
public IAsyncAction RedrawSurface(Uri uri)
public async void OnDeviceReplaced(object sender, object e)
{
return RedrawSurfaceWorker(uri, Size.Empty).AsAsyncAction();
}
public IAsyncAction RedrawSurface(Uri uri, Size size)
{
return RedrawSurfaceWorker(uri, size).AsAsyncAction();
}
public void Resize(Size size)
{
_imageLoader.ResizeSurface(_surface, size);
}
private async Task RedrawSurfaceWorker(Uri uri, Size size)
{
_uri = uri;
await _imageLoader.DrawSurface(_surface, _uri, size);
DeviceReplacedEventArgs args = (DeviceReplacedEventArgs)e;
await ReloadContent(args.GraphicsDevce, args.DrawingLock);
}
public void Dispose()
{
if (_surface != null)
{
_surface.Dispose();
_imageLoader.DeviceReplacedEvent -= OnDeviceReplaced;
_surface = null;
_imageLoader = null;
_uri = null;
}
if (_brush != null)
{
_brush.Dispose();
_brush = null;
}
_drawer = null;
ImageLoader.Instance.UnregisterSurface(this);
}
}
}

Просмотреть файл

@ -115,7 +115,7 @@
<Compile Include="ColorMixer.xaml.cs">
<DependentUpon>ColorMixer.xaml</DependentUpon>
</Compile>
<Compile Include="ImageLoader\CircleSurface.cs" />
<Compile Include="ImageLoader\ContentDrawer.cs" />
<Compile Include="LightControl.xaml.cs" />
<Compile Include="OrientationTrigger.cs" />
<Compile Include="PennerEquationBuilder.cs" />
@ -127,7 +127,6 @@
<Compile Include="CompositionShadow.xaml.cs" Condition="$(TargetPlatformBuild) &gt;10586">
<DependentUpon>CompositionShadow.xaml</DependentUpon>
</Compile>
<Compile Include="SurfaceLoader.cs" />
<Compile Include="SwipeDismissPanel.cs" Condition="$(TargetPlatformBuild) &gt;10586" />
<Compile Include="UIElementExtensionMethods.cs" />
<Compile Include="ValueTimer.cs" />
@ -148,6 +147,12 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SamplesNative\SamplesNative.vcxproj">
<Project>{b0dca768-5521-406c-803d-fdccf67181d1}</Project>
<Name>SamplesNative</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>

Просмотреть файл

@ -1,136 +0,0 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Graphics.Canvas.UI.Composition;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Graphics.DirectX;
using Windows.UI;
using Windows.UI.Composition;
namespace SamplesCommon
{
public delegate CompositionDrawingSurface LoadTimeEffectHandler(CanvasBitmap bitmap, CompositionGraphicsDevice device, Size sizeTarget);
public class SurfaceLoader
{
private static bool _intialized;
private static Compositor _compositor;
private static CanvasDevice _canvasDevice;
private static CompositionGraphicsDevice _compositionDevice;
static public void Initialize(Compositor compositor)
{
Debug.Assert(!_intialized || compositor == _compositor);
if (!_intialized)
{
_compositor = compositor;
_canvasDevice = new CanvasDevice();
_compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
_intialized = true;
}
}
static public void Uninitialize()
{
_compositor = null;
if (_compositionDevice != null)
{
_compositionDevice.Dispose();
_compositionDevice = null;
}
if(_canvasDevice != null)
{
_canvasDevice.Dispose();
_canvasDevice = null;
}
_intialized = false;
}
static public bool IsInitialized
{
get
{
return _intialized;
}
}
static public async Task<CompositionDrawingSurface> LoadFromUri(Uri uri)
{
return await LoadFromUri(uri, Size.Empty);
}
static public async Task<CompositionDrawingSurface> LoadFromUri(Uri uri, Size sizeTarget)
{
Debug.Assert(_intialized);
CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(_canvasDevice, uri);
Size sizeSource = bitmap.Size;
if (sizeTarget.IsEmpty)
{
sizeTarget = sizeSource;
}
CompositionDrawingSurface surface = _compositionDevice.CreateDrawingSurface(sizeTarget,
DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
using (var ds = CanvasComposition.CreateDrawingSession(surface))
{
ds.Clear(Color.FromArgb(0, 0, 0, 0));
ds.DrawImage(bitmap, new Rect(0, 0, sizeTarget.Width, sizeTarget.Height), new Rect(0, 0, sizeSource.Width, sizeSource.Height));
}
return surface;
}
static public CompositionDrawingSurface LoadText(string text, Size sizeTarget, CanvasTextFormat textFormat, Color textColor, Color bgColor)
{
Debug.Assert(_intialized);
CompositionDrawingSurface surface = _compositionDevice.CreateDrawingSurface(sizeTarget,
DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
using (var ds = CanvasComposition.CreateDrawingSession(surface))
{
ds.Clear(bgColor);
ds.DrawText(text, new Rect(0, 0, sizeTarget.Width, sizeTarget.Height), textColor, textFormat);
}
return surface;
}
static public async Task<CompositionDrawingSurface> LoadFromUri(Uri uri, Size sizeTarget, LoadTimeEffectHandler loadEffectHandler)
{
Debug.Assert(_intialized);
if (loadEffectHandler != null)
{
CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(_canvasDevice, uri);
return loadEffectHandler(bitmap, _compositionDevice, sizeTarget);
}
else
{
return await LoadFromUri(uri, sizeTarget);
}
}
}
}

Просмотреть файл

@ -0,0 +1,94 @@
#include "pch.h"
#include "DeviceLostHelper.h"
using namespace SamplesNative;
using namespace Platform;
using namespace Microsoft::WRL;
using namespace Windows::Graphics::DirectX::Direct3D11;
using namespace Windows::Graphics::Display;
DeviceLostHelper::DeviceLostHelper()
{
OnDeviceLostHandler = NULL;
m_eventHandle = NULL;
m_cookie = NULL;
}
DeviceLostHelper::~DeviceLostHelper()
{
StopWatchingCurrentDevice();
OnDeviceLostHandler = NULL;
}
void
DeviceLostHelper::WatchDevice(IDirect3DDevice^ device)
{
// Stop listening for device lost if we currently are
StopWatchingCurrentDevice();
// Set the current device to the new device
m_device = device;
// Get the DXGI Device
ComPtr<IDXGIDevice> dxgiDevice;
__abi_ThrowIfFailed(GetDXGIInterface(device, dxgiDevice.GetAddressOf()));
// QI For the ID3D11Device4 interface
ComPtr<ID3D11Device4> d3dDevice;
__abi_ThrowIfFailed(dxgiDevice.As(&d3dDevice));
// Create a wait struct
OnDeviceLostHandler = {};
OnDeviceLostHandler = CreateThreadpoolWait(DeviceLostHelper::OnDeviceLost, (PVOID)this, NULL);
// Create a handle and a cookie
m_eventHandle = CreateEvent(NULL, FALSE, FALSE, L"DeviceLost");
m_cookie = NULL;
// Register for device lost
SetThreadpoolWait(OnDeviceLostHandler, m_eventHandle, NULL);
__abi_ThrowIfFailed(d3dDevice->RegisterDeviceRemovedEvent(m_eventHandle, &m_cookie));
}
void
DeviceLostHelper::StopWatchingCurrentDevice()
{
if (m_device)
{
// Get the DXGI Device
ComPtr<IDXGIDevice> dxgiDevice;
__abi_ThrowIfFailed(GetDXGIInterface(m_device, dxgiDevice.GetAddressOf()));
// QI For the ID3D11Device4 interface
ComPtr<ID3D11Device4> d3dDevice;
__abi_ThrowIfFailed(dxgiDevice.As(&d3dDevice));
// Unregister from device lost
CloseThreadpoolWait(OnDeviceLostHandler);
d3dDevice->UnregisterDeviceRemoved(m_cookie);
// Clear member variables
OnDeviceLostHandler = NULL;
CloseHandle(m_eventHandle);
m_eventHandle = NULL;
m_cookie = NULL;
m_device = nullptr;
}
}
void
DeviceLostHelper::RaiseDeviceLostEvent(IDirect3DDevice^ oldDevice)
{
DeviceLost(this, DeviceLostEventArgs::Create(oldDevice));
}
void CALLBACK
DeviceLostHelper::OnDeviceLost(PTP_CALLBACK_INSTANCE instance, PVOID context, PTP_WAIT wait, TP_WAIT_RESULT waitResult)
{
auto deviceLostHelper = reinterpret_cast<DeviceLostHelper^>(context);
auto oldDevice = deviceLostHelper->m_device;
deviceLostHelper->StopWatchingCurrentDevice();
deviceLostHelper->RaiseDeviceLostEvent(oldDevice);
}

Просмотреть файл

@ -0,0 +1,53 @@
#pragma once
using namespace Windows::Graphics::DirectX::Direct3D11;
namespace SamplesNative
{
ref class DeviceLostHelper;
public ref class DeviceLostEventArgs sealed
{
public:
property IDirect3DDevice^ Device
{
IDirect3DDevice^ get() { return m_device; }
}
internal:
static DeviceLostEventArgs^ Create(IDirect3DDevice^ device) { return ref new DeviceLostEventArgs(device); }
private:
DeviceLostEventArgs(IDirect3DDevice^ device) : m_device(device) {}
IDirect3DDevice^ m_device;
};
public delegate void DeviceLostEventHandler(DeviceLostHelper^ sender, DeviceLostEventArgs^ args);
public ref class DeviceLostHelper sealed
{
public:
property IDirect3DDevice^ CurrentlyWatchedDevice
{
IDirect3DDevice^ get() { return m_device; }
}
DeviceLostHelper();
void WatchDevice(IDirect3DDevice^ device);
void StopWatchingCurrentDevice();
event DeviceLostEventHandler^ DeviceLost;
private:
~DeviceLostHelper();
void RaiseDeviceLostEvent(IDirect3DDevice^ oldDevice);
static void CALLBACK OnDeviceLost(PTP_CALLBACK_INSTANCE instance, PVOID context, PTP_WAIT wait, TP_WAIT_RESULT waitResult);
private:
IDirect3DDevice^ m_device;
PTP_WAIT OnDeviceLostHandler;
HANDLE m_eventHandle;
DWORD m_cookie;
};
};

Просмотреть файл

@ -0,0 +1,226 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{b0dca768-5521-406c-803d-fdccf67181d1}</ProjectGuid>
<Keyword>WindowsRuntimeComponent</Keyword>
<RootNamespace>SamplesNative</RootNamespace>
<DefaultLanguage>en-US</DefaultLanguage>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.10586.0</WindowsTargetPlatformMinVersion>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>_WINRT_DLL;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>_WINRT_DLL;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>_WINRT_DLL;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="DeviceLostHelper.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DeviceLostHelper.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

Просмотреть файл

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resources">
<UniqueIdentifier>88caef74-4b73-4fbb-a53d-8834568c6575</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
<ClCompile Include="DeviceLostHelper.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="DeviceLostHelper.h" />
</ItemGroup>
</Project>

1
SamplesNative/pch.cpp Normal file
Просмотреть файл

@ -0,0 +1 @@
#include "pch.h"

7
SamplesNative/pch.h Normal file
Просмотреть файл

@ -0,0 +1,7 @@
#pragma once
#include <collection.h>
#include <ppltasks.h>
#include <d3d11.h>
#include <D3d11_4.h>
#include <Windows.Graphics.DirectX.Direct3D11.interop.h>