Merged PR 241133: Add proper capabilities checking to SampleGallery.

Add proper capabilities checking to SampleGallery.
- Filter sample list based on capability requirements of each sample.
- Add virtual on SamplePage to allow samples to handle capability changes.
This commit is contained in:
Rob Aldinger 2017-02-06 20:02:00 +00:00
Родитель d8a8696c9d
Коммит 9020235680
5 изменённых файлов: 158 добавлений и 48 удалений

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

@ -14,7 +14,6 @@
using SamplesCommon;
using System;
using System.Collections.Generic;
using System.Numerics;
using Windows.Foundation;
using Windows.UI;
@ -27,12 +26,27 @@ namespace CompositionSampleGallery
{
public sealed partial class MainPage : Page
{
private static MainPage _instance;
private static MainPage _instance;
#if SDKVERSION_INSIDER
private static CompositionCapabilities _capabilities;
#endif
private static bool _areEffectsSupported;
private static bool _areEffectsFast;
public MainPage(Rect imageBounds)
{
_instance = this;
// Get hardware capabilities and register changed event listener
#if SDKVERSION_INSIDER
_capabilities = CompositionCapabilities.GetForCurrentView();
_capabilities.Changed += HandleCapabilitiesChangedAsync;
_areEffectsSupported = _capabilities.AreEffectsSupported();
_areEffectsFast = _capabilities.AreEffectsFast();
#else
_areEffectsSupported = true;
_areEffectsFast = true;
#endif
this.InitializeComponent();
// Initialize the surface loader
@ -47,6 +61,58 @@ namespace CompositionSampleGallery
get { return _instance; }
}
public static bool AreEffectsSupported
{
get { return _areEffectsSupported; }
}
public static bool AreEffectsFast
{
get { return _areEffectsFast; }
}
#if SDKVERSION_INSIDER
private async void HandleCapabilitiesChangedAsync(CompositionCapabilities sender, object args)
{
_areEffectsSupported = _capabilities.AreEffectsSupported();
_areEffectsFast = _capabilities.AreEffectsFast();
if (MainFrame.Content is SampleHost host)
{
SamplePage page = (SamplePage)host.ContentFrame.Content;
page.OnCapabiliesChanged(_areEffectsSupported, _areEffectsFast);
}
MySampleListControl.RefreshSampleList();
//
// Let the user know that the display config has changed and some samples may or may
// not be available
//
if (!_areEffectsSupported || !_areEffectsFast)
{
string message;
if (!_areEffectsSupported)
{
message = "Your display configuration may have changed. Your current graphics hardware does not support effects. Some samples will not be available";
}
else
{
message = "Your display configuration may have changed. Your current graphics hardware does not support advanced effects. Some samples will not be available";
}
var messageDialog = new MessageDialog(message);
messageDialog.Commands.Add(new UICommand("Close"));
// Show the message dialog
await messageDialog.ShowAsync();
}
}
#endif
private async void ShowCustomSplashScreen(Rect imageBounds)
{
Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

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

@ -58,7 +58,6 @@ namespace CompositionSampleGallery
// Get hardware capabilities and register changed event listener
_capabilities = CompositionCapabilities.GetForCurrentView();
_capabilities.Changed += HandleCapabilitiesChanged;
}
/// <summary>
@ -95,6 +94,7 @@ namespace CompositionSampleGallery
_backgroundImageVisual = _compositor.CreateSpriteVisual();
_imageContainer = _compositor.CreateContainerVisual();
_imageSurfaceBrush = _compositor.CreateSurfaceBrush();
_capabilities.Changed += HandleCapabilitiesChanged;
ElementCompositionPreview.SetElementChildVisual(ImageCanvas, _imageContainer);
@ -250,6 +250,8 @@ namespace CompositionSampleGallery
/// </summary>
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
_capabilities.Changed -= HandleCapabilitiesChanged;
if (_imageSurfaceBrush != null)
{
_imageLoader.Dispose();

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

@ -39,13 +39,17 @@ namespace CompositionSampleGallery
private Type _pageType;
private SampleType _sampleType;
private SampleCategory _sampleCategory;
private bool _requiresFastEffects;
private bool _requiresEffects;
public SampleDefinition(string name, Type pageType, SampleType sampleType, SampleCategory sampleArea)
public SampleDefinition(string name, Type pageType, SampleType sampleType, SampleCategory sampleArea, bool requiresEffects, bool requiresFastEffects)
{
_name = name;
_pageType = pageType;
_sampleType = sampleType;
_sampleCategory = sampleArea;
_requiresEffects = requiresEffects;
_requiresFastEffects = requiresFastEffects;
}
public string Name { get { return _name; } }
@ -66,6 +70,9 @@ namespace CompositionSampleGallery
}
}
}
public bool RequiresEffects { get { return _requiresEffects; } }
public bool RequiresFastEffects { get { return _requiresFastEffects; } }
}
public class SampleDefinitions
@ -73,49 +80,49 @@ namespace CompositionSampleGallery
static SampleDefinition[] definitions =
{
#if SDKVERSION_INSIDER
new SampleDefinition(BorderPlayground.StaticSampleName, typeof(BorderPlayground), SampleType.Reference, SampleCategory.Effects),
new SampleDefinition(CompCapabilities.StaticSampleName, typeof(CompCapabilities), SampleType.Reference, SampleCategory.Effects),
new SampleDefinition(TransparentWindow.StaticSampleName, typeof(TransparentWindow), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(BorderPlayground.StaticSampleName, typeof(BorderPlayground), SampleType.Reference, SampleCategory.Effects, false, true),
new SampleDefinition(CompCapabilities.StaticSampleName, typeof(CompCapabilities), SampleType.Reference, SampleCategory.Effects, false, false),
new SampleDefinition(TransparentWindow.StaticSampleName, typeof(TransparentWindow), SampleType.EndToEnd, SampleCategory.Effects, true, true),
#endif
#if SDKVERSION_14393
new SampleDefinition(BackDropSample.StaticSampleName, typeof(BackDropSample), SampleType.Reference, SampleCategory.Effects),
new SampleDefinition(Curtain.StaticSampleName, typeof(Curtain), SampleType.Reference, SampleCategory.Interactions),
new SampleDefinition(ForegroundFocusEffects.StaticSampleName, typeof(ForegroundFocusEffects), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(Gears.StaticSampleName, typeof(Gears), SampleType.EndToEnd, SampleCategory.ExpressionAnimations),
new SampleDefinition(ImplicitAnimationTransformer.StaticSampleName, typeof(ImplicitAnimationTransformer), SampleType.Reference, SampleCategory.Animations),
new SampleDefinition(NowPlaying.StaticSampleName, typeof(NowPlaying), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(PhotoViewer.StaticSampleName, typeof(PhotoViewer), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(PullToAnimate.StaticSampleName, typeof(PullToAnimate), SampleType.EndToEnd, SampleCategory.Interactions),
new SampleDefinition(ShadowPlayground.StaticSampleName, typeof(ShadowPlayground), SampleType.Reference, SampleCategory.Visuals),
new SampleDefinition(ShadowInterop.StaticSampleName, typeof(ShadowInterop), SampleType.Reference, SampleCategory.Visuals),
new SampleDefinition(ShadowsAdvanced.StaticSampleName, typeof(ShadowsAdvanced), SampleType.Reference, SampleCategory.Visuals),
new SampleDefinition(TextShimmer.StaticSampleName, typeof(TextShimmer), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(ThumbnailLighting.StaticSampleName, typeof(ThumbnailLighting), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(BlurPlayground.StaticSampleName, typeof(BlurPlayground), SampleType.Reference, SampleCategory.Effects),
new SampleDefinition(VideoPlayground.StaticSampleName, typeof(VideoPlayground), SampleType.Reference, SampleCategory.Effects),
new SampleDefinition(LayerDepth.StaticSampleName, typeof(LayerDepth), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(Photos.StaticSampleName, typeof(Photos), SampleType.EndToEnd, SampleCategory.Animations),
new SampleDefinition(Interactions3D.StaticSampleName, typeof(Interactions3D), SampleType.EndToEnd, SampleCategory.Interactions),
new SampleDefinition(TreeEffects.StaticSampleName, typeof(TreeEffects), SampleType.Reference, SampleCategory.Effects),
new SampleDefinition(LayerVisualAnd3DTransform.StaticSampleName, typeof(LayerVisualAnd3DTransform), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(NineGridResizing.StaticSampleName, typeof(NineGridResizing), SampleType.Reference, SampleCategory.Visuals),
new SampleDefinition(LightSphere.StaticSampleName, typeof(LightSphere), SampleType.Reference, SampleCategory.Effects),
new SampleDefinition(BackDropSample.StaticSampleName, typeof(BackDropSample), SampleType.Reference, SampleCategory.Effects, true, true),
new SampleDefinition(Curtain.StaticSampleName, typeof(Curtain), SampleType.Reference, SampleCategory.Interactions, false, false),
new SampleDefinition(ForegroundFocusEffects.StaticSampleName, typeof(ForegroundFocusEffects), SampleType.EndToEnd, SampleCategory.Effects, true, true),
new SampleDefinition(Gears.StaticSampleName, typeof(Gears), SampleType.EndToEnd, SampleCategory.ExpressionAnimations, false, false),
new SampleDefinition(ImplicitAnimationTransformer.StaticSampleName, typeof(ImplicitAnimationTransformer), SampleType.Reference, SampleCategory.Animations, false, false),
new SampleDefinition(NowPlaying.StaticSampleName, typeof(NowPlaying), SampleType.EndToEnd, SampleCategory.Effects, true, true),
new SampleDefinition(PhotoViewer.StaticSampleName, typeof(PhotoViewer), SampleType.EndToEnd, SampleCategory.Effects, true, false),
new SampleDefinition(PullToAnimate.StaticSampleName, typeof(PullToAnimate), SampleType.EndToEnd, SampleCategory.Interactions, true, true),
new SampleDefinition(ShadowPlayground.StaticSampleName, typeof(ShadowPlayground), SampleType.Reference, SampleCategory.Visuals, true, true),
new SampleDefinition(ShadowInterop.StaticSampleName, typeof(ShadowInterop), SampleType.Reference, SampleCategory.Visuals, false, false),
new SampleDefinition(ShadowsAdvanced.StaticSampleName, typeof(ShadowsAdvanced), SampleType.Reference, SampleCategory.Visuals, false, false),
new SampleDefinition(TextShimmer.StaticSampleName, typeof(TextShimmer), SampleType.EndToEnd, SampleCategory.Effects, true, true),
new SampleDefinition(ThumbnailLighting.StaticSampleName, typeof(ThumbnailLighting), SampleType.EndToEnd, SampleCategory.Effects, true, true),
new SampleDefinition(BlurPlayground.StaticSampleName, typeof(BlurPlayground), SampleType.Reference, SampleCategory.Effects, true, true),
new SampleDefinition(VideoPlayground.StaticSampleName, typeof(VideoPlayground), SampleType.Reference, SampleCategory.Effects, true, true),
new SampleDefinition(LayerDepth.StaticSampleName, typeof(LayerDepth), SampleType.EndToEnd, SampleCategory.Effects, true, true),
new SampleDefinition(Photos.StaticSampleName, typeof(Photos), SampleType.EndToEnd, SampleCategory.Animations, false, false),
new SampleDefinition(Interactions3D.StaticSampleName, typeof(Interactions3D), SampleType.EndToEnd, SampleCategory.Interactions, false, false),
new SampleDefinition(TreeEffects.StaticSampleName, typeof(TreeEffects), SampleType.Reference, SampleCategory.Effects, true, true),
new SampleDefinition(LayerVisualAnd3DTransform.StaticSampleName, typeof(LayerVisualAnd3DTransform), SampleType.EndToEnd, SampleCategory.Effects, true, true),
new SampleDefinition(NineGridResizing.StaticSampleName, typeof(NineGridResizing), SampleType.Reference, SampleCategory.Visuals, false, false),
new SampleDefinition(LightSphere.StaticSampleName, typeof(LightSphere), SampleType.Reference, SampleCategory.Effects, true, true),
#endif
#if SDKVERSION_10586
new SampleDefinition(BasicXamlInterop.StaticSampleName, typeof(BasicXamlInterop), SampleType.Reference, SampleCategory.Visuals),
new SampleDefinition(ParallaxingListItems.StaticSampleName, typeof(ParallaxingListItems), SampleType.EndToEnd, SampleCategory.ExpressionAnimations),
new SampleDefinition(Perspective.StaticSampleName, typeof(Perspective), SampleType.Reference, SampleCategory.Visuals),
new SampleDefinition(PointerEnterEffects.StaticSampleName, typeof(PointerEnterEffects), SampleType.EndToEnd, SampleCategory.Effects),
new SampleDefinition(PropertySets.StaticSampleName, typeof(PropertySets), SampleType.Reference, SampleCategory.ExpressionAnimations),
new SampleDefinition(ColorBloomTransition.StaticSampleName, typeof(ColorBloomTransition), SampleType.EndToEnd, SampleCategory.Transitions),
new SampleDefinition(ColorSlideTransition.StaticSampleName, typeof(ColorSlideTransition), SampleType.EndToEnd, SampleCategory.Transitions),
new SampleDefinition(ZoomWithPerspective.StaticSampleName, typeof(ZoomWithPerspective), SampleType.EndToEnd, SampleCategory.Visuals),
new SampleDefinition(FlipToReveal.StaticSampleName, typeof(FlipToReveal), SampleType.EndToEnd, SampleCategory.Transitions),
new SampleDefinition(Z_OrderScrolling.StaticSampleName, typeof(Z_OrderScrolling), SampleType.EndToEnd, SampleCategory.ExpressionAnimations),
new SampleDefinition(ConnectedAnimationShell.StaticSampleName, typeof(ConnectedAnimationShell), SampleType.EndToEnd, SampleCategory.Transitions),
new SampleDefinition(BasicLayoutAndTransforms.StaticSampleName, typeof(BasicLayoutAndTransforms), SampleType.Reference, SampleCategory.Visuals),
new SampleDefinition(BasicXamlInterop.StaticSampleName, typeof(BasicXamlInterop), SampleType.Reference, SampleCategory.Visuals, false, false),
new SampleDefinition(ParallaxingListItems.StaticSampleName, typeof(ParallaxingListItems), SampleType.EndToEnd, SampleCategory.ExpressionAnimations, false, false),
new SampleDefinition(Perspective.StaticSampleName, typeof(Perspective), SampleType.Reference, SampleCategory.Visuals, false, false),
new SampleDefinition(PointerEnterEffects.StaticSampleName, typeof(PointerEnterEffects), SampleType.EndToEnd, SampleCategory.Effects, true, false),
new SampleDefinition(PropertySets.StaticSampleName, typeof(PropertySets), SampleType.Reference, SampleCategory.ExpressionAnimations, false, false),
new SampleDefinition(ColorBloomTransition.StaticSampleName, typeof(ColorBloomTransition), SampleType.EndToEnd, SampleCategory.Transitions, false, false),
new SampleDefinition(ColorSlideTransition.StaticSampleName, typeof(ColorSlideTransition), SampleType.EndToEnd, SampleCategory.Transitions, false, false),
new SampleDefinition(ZoomWithPerspective.StaticSampleName, typeof(ZoomWithPerspective), SampleType.EndToEnd, SampleCategory.Visuals, false, false),
new SampleDefinition(FlipToReveal.StaticSampleName, typeof(FlipToReveal), SampleType.EndToEnd, SampleCategory.Transitions, false, false),
new SampleDefinition(Z_OrderScrolling.StaticSampleName, typeof(Z_OrderScrolling), SampleType.EndToEnd, SampleCategory.ExpressionAnimations, false, false),
new SampleDefinition(ConnectedAnimationShell.StaticSampleName, typeof(ConnectedAnimationShell), SampleType.EndToEnd, SampleCategory.Transitions, false, false),
new SampleDefinition(BasicLayoutAndTransforms.StaticSampleName, typeof(BasicLayoutAndTransforms), SampleType.Reference, SampleCategory.Visuals, false, false),
#endif
};

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

@ -15,6 +15,7 @@
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
namespace CompositionSampleGallery
{
@ -24,12 +25,7 @@ namespace CompositionSampleGallery
{
this.InitializeComponent();
var result = from sampleDef in SampleDefinitions.Definitions
orderby sampleDef.DisplayName
group sampleDef by sampleDef.SampleCategory into sampleGroup
orderby sampleGroup.Key
select sampleGroup;
SampleViewSource.Source = result;
RefreshSampleList();
}
private void SampleList_ItemClick(object sender, ItemClickEventArgs e)
@ -39,5 +35,39 @@ namespace CompositionSampleGallery
SamplesSplitView.IsPaneOpen = false;
}
public void RefreshSampleList()
{
IOrderedEnumerable<IGrouping<SampleCategory, SampleDefinition>> result;
if (MainPage.AreEffectsFast)
{
result = from sampleDef in SampleDefinitions.Definitions
orderby sampleDef.DisplayName
group sampleDef by sampleDef.SampleCategory into sampleGroup
orderby sampleGroup.Key
select sampleGroup;
}
else if (MainPage.AreEffectsSupported)
{
result = from sampleDef in SampleDefinitions.Definitions
where !sampleDef.RequiresFastEffects
orderby sampleDef.DisplayName
group sampleDef by sampleDef.SampleCategory into sampleGroup
orderby sampleGroup.Key
select sampleGroup;
}
else
{
result = from sampleDef in SampleDefinitions.Definitions
where !sampleDef.RequiresEffects
orderby sampleDef.DisplayName
group sampleDef by sampleDef.SampleCategory into sampleGroup
orderby sampleGroup.Key
select sampleGroup;
}
SampleViewSource.Source = result;
}
}
}

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

@ -27,7 +27,7 @@ namespace CompositionSampleGallery
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Parameter is SampleHost)
{
SampleHost host = (SampleHost)e.Parameter;
@ -37,5 +37,10 @@ namespace CompositionSampleGallery
host.SampleCode.NavigateUri = new Uri(SampleCodeUri);
}
}
public virtual void OnCapabiliesChanged(bool areEffectSupported, bool areEffectsFast)
{
}
}
}