コード例 #1
0
        // Test in-app and window acrylic created while in fallback mode
        void RunAcrylicCreatedInFallbackMode()
        {
            using (var setup = new MaterialSetupHelper(true /* ignoreAreEffectsFast*/, true /* simulateDisabledByPolicy */))
            {
                // Test app acrylic
                _acrylicBrush = new AcrylicBrush
                {
                    BackgroundSource = AcrylicBackgroundSource.Backdrop,
                    FallbackColor    = Color.FromArgb(0xFF, 0x0, 0x0, 0xFF),
                    TintOpacity      = TintOpacity.Value
                };

                _acrylicTestApi.AcrylicBrush = _acrylicBrush;

                Rectangle1.Fill = _acrylicBrush;
                bool result1 = VerifyFallbackColor();

                // Test window acrylic
                _acrylicBrush = new AcrylicBrush
                {
                    BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                    FallbackColor    = Color.FromArgb(0xFF, 0x0, 0xFF, 0xFF),
                    TintOpacity      = TintOpacity.Value
                };
                _acrylicTestApi.AcrylicBrush = _acrylicBrush;

                Rectangle1.Fill = _acrylicBrush;
                bool result2 = VerifyFallbackColor();

                TestResult.Text = "AcrylicCreatedInFallbackMode: " + (result1 && result2 ? "Passed" : "Failed ");
            }
        }
コード例 #2
0
        void RunTintTransitionDuration()
        {
            int durationMS = 0;

            if (_iteration_TintTransitionDuration == 0)
            {
                durationMS = 0;
            }
            else if (_iteration_TintTransitionDuration == 1)
            {
                durationMS = 500;
            }
            else if (_iteration_TintTransitionDuration == 2)
            {
                durationMS = 999;
            }

            _iteration_TintTransitionDuration++;

            _acrylicBrush = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Green,
                TintOpacity      = 0.8
            };
            _acrylicTestApi.AcrylicBrush = _acrylicBrush;
            Rectangle1.Fill = _acrylicBrush;

            _acrylicBrush.TintTransitionDuration = new TimeSpan(0, 0, 0, 0, durationMS);
            _acrylicBrush.TintColor = Colors.DarkOrange;
        }
コード例 #3
0
        // Test adding an AcrylicBrush, animating the affected element, and then removing the brush
        void RunVerifyDisconnectedState()
        {
            _acrylicBrush = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Color.FromArgb(0xFF, 0x0, 0x0, 0xFF),
                TintOpacity      = TintOpacity.Value
            };
            _acrylicTestApi.AcrylicBrush = _acrylicBrush;
            Rectangle1.Fill = _acrylicBrush;

            if (_acrylicTestApi.IsUsingAcrylicBrush == false)
            {
                TestResult.Text = "VerifyDisconnectedState: Skipped";
                return;
            }

            DoubleAnimation positionAnimation = new DoubleAnimation();

            positionAnimation.By       = 100;
            positionAnimation.Duration = new TimeSpan(0, 0, 0, 0, 200);
            Storyboard.SetTarget(positionAnimation, MyTranslateTransform);
            Storyboard.SetTargetProperty(positionAnimation, "X");
            Storyboard sb = new Storyboard();

            sb.Children.Add(positionAnimation);
            sb.Completed += RunVerifyDisconnectedState_AnimationCompleted;
            sb.Begin();
        }
コード例 #4
0
        private void UpdateMaterialBlurStyle()
        {
            if (_grid == null || Element.MaterialTheme != MaterialFrame.Theme.AcrylicBlur)
            {
                return;
            }

            var acrylicBrush = new AcrylicBrush {
                BackgroundSource = AcrylicBackgroundSource.Backdrop
            };

            switch (Element.MaterialBlurStyle)
            {
            case MaterialFrame.BlurStyle.ExtraLight:
                acrylicBrush.TintColor = ExtraLightBlurOverlayColor.ToWindowsColor();
                break;

            case MaterialFrame.BlurStyle.Dark:
                acrylicBrush.TintColor = DarkBlurOverlayColor.ToWindowsColor();
                break;

            default:
                acrylicBrush.TintColor = LightBlurOverlayColor.ToWindowsColor();
                break;
            }

            _grid.Background = acrylicBrush;
        }
コード例 #5
0
        // Test noise cache is functional:
        // 1. Validate two AcrylicBrushes both use the same noise
        // 2. Validate destroying these AB's and creating a new one still use the same noise.
        void RunAcrylicNoiseCache()
        {
            AcrylicBrush acrylicBrush1 = new AcrylicBrush {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Green,
                TintOpacity      = 0.1
            };

            AcrylicBrush acrylicBrush2 = new AcrylicBrush {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Bisque,
                TintOpacity      = 1
            };

            Rectangle1.Fill = acrylicBrush1;
            _acrylicTestApi.AcrylicBrush = acrylicBrush1;
            CompositionBrush noiseBrush1 = UpdateNoiseBrush();

            if (_acrylicTestApi.IsUsingAcrylicBrush == false)
            {
                TestResult.Text = "AcrylicNoiseCache: Skipped";
                return;
            }

            Rectangle1.Stroke            = acrylicBrush2;
            _acrylicTestApi.AcrylicBrush = acrylicBrush2;
            CompositionBrush noiseBrush2 = UpdateNoiseBrush();

            // Make sure two brushes conccurrently in tree use the same noise
            bool result1 = Object.ReferenceEquals(noiseBrush1, noiseBrush2);

            // Destroy existing brushes
            Rectangle1.Fill              = new SolidColorBrush(Colors.PaleGoldenrod);
            Rectangle1.Stroke            = new SolidColorBrush(Colors.PaleGoldenrod);
            acrylicBrush1                = null;
            acrylicBrush2                = null;
            _acrylicTestApi.AcrylicBrush = null;
            GC.Collect();

            AcrylicBrush acrylicBrush3 = new AcrylicBrush {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.DarkOliveGreen,
                TintOpacity      = 0.25
            };

            Rectangle1.Fill = acrylicBrush3;
            _acrylicTestApi.AcrylicBrush = acrylicBrush3;
            CompositionBrush noiseBrush3 = UpdateNoiseBrush();

            // Make sure new brush still uses the same noise
            bool result2 = Object.ReferenceEquals(noiseBrush2, noiseBrush3);

            bool   result       = result1 && result2;
            string resultString = System.String.Format("({0},{1})", result1, result2);

            TestResult.Text = "AcrylicNoiseCache: " + (result ? "Passed" : ("Failed " + resultString));
        }
コード例 #6
0
        // Test adding an AcrylicBrush and switching its tint transparency status
        // to validate that we use optimized opaque tint effect chain
        void RunVerifyOpaqueTintOptimization()
        {
            // Start out with transparent tint
            _acrylicBrush = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Green,
                TintOpacity      = 0.1
            };
            _acrylicTestApi.AcrylicBrush = _acrylicBrush;
            Rectangle1.Fill = _acrylicBrush;

            if (_acrylicTestApi.IsUsingAcrylicBrush == false)
            {
                TestResult.Text = "VerifyOpaqueTintOptimization: Skipped";
                return;
            }

            bool[] results = { false, false, false, false };

            CompositionBrush originalTransparentBrush = UpdateCompositionBrush();

            results[0] = VerifyAcrylic();

            // Switch to opaque tint
            _acrylicBrush.TintOpacity = 1.0;
            CompositionBrush updatedOpaqueBrush = UpdateCompositionBrush();

            results[1] = VerifyAcrylic();

            // Switch back to transparent tint
            _acrylicBrush.TintOpacity = 0.1;
            CompositionBrush updatedTransapentBrush = UpdateCompositionBrush();

            results[2] = VerifyAcrylic();

            // Make a new brush got created in each case
            results[3] =
                !Object.ReferenceEquals(originalTransparentBrush, updatedOpaqueBrush) &&
                !Object.ReferenceEquals(originalTransparentBrush, updatedTransapentBrush) &&
                !Object.ReferenceEquals(updatedOpaqueBrush, updatedTransapentBrush);

            bool   result       = results[0] && results[1] && results[2] && results[3];
            string resultString = System.String.Format("({0},{1},{2},{3})", results[0], results[1], results[2], results[3]);

            TestResult.Text = "VerifyOpaqueTintOptimization: " + (result ? "Passed" : ("Failed " + resultString));
        }
コード例 #7
0
        private void UpdateBlur()
        {
            if (Element.UwpBlurOverlayColor != Color.Default)
            {
                var acrylicBrush = new AcrylicBrush
                {
                    BackgroundSource = AcrylicBackgroundSource.Backdrop,
                    TintColor        = Element.UwpBlurOverlayColor.ToWindowsColor(),
                };

                _grid.Background = acrylicBrush;
                return;
            }

            UpdateMaterialBlurStyle();
        }
コード例 #8
0
        private void RunTestButton_Clicked(object sender, RoutedEventArgs e)
        {
            bool[] results = { false, false, false };

            _acrylicTestApi.AcrylicBrush = AcrylicBrush1;
            results[0] = VerifyAcrylic();

            _acrylicTestApi.AcrylicBrush = AcrylicBrush2;
            results[1] = VerifyAcrylic();

            _acrylicTestApi.AcrylicBrush = AcrylicBrush3;
            _acrylicBrush = AcrylicBrush3;
            results[2]    = VerifyFallbackColor();

            bool   result       = results[0] && results[1] && results[2];
            string resultString = System.String.Format("({0},{1},{2})", results[0], results[1], results[2]);

            TestResult.Text = "AcrylicFromMarkup: " + (result ? "Passed" : ("Failed " + resultString));
        }
コード例 #9
0
        CompositionBrush _previousCompositionBrush;          // Used by test helpers that get called multiple times

        public AcrylicBrushPage()
        {
            this.InitializeComponent();

            if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.XamlCompositionBrushBase"))
            {
                AutomationProperties.SetName(this, "AcrylicBrushPage");
                AutomationProperties.SetAutomationId(this, "AcrylicBrushPage");

                _acrylicBrush = new AcrylicBrush {
                    BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                    FallbackColor    = Color.FromArgb(0xFF, 0x0, 0x0, 0xFF),
                    TintOpacity      = TintOpacity.Value
                };

                _acrylicTestApi = new AcrylicTestApi();

                _iteration_RunHideAndShowWindow   = 0;
                _iteration_TintTransitionDuration = 0;
            }
        }
コード例 #10
0
        public void VerifyDefaultPropertyValues()
        {
            if (!OnRS2OrGreater())
            {
                return;
            }

            RunOnUIThread.Execute(() =>
            {
                AcrylicBrush acrylicBrush = new AcrylicBrush();
                Verify.IsNotNull(acrylicBrush);

                MatrixTransform identityTransform = new MatrixTransform();
                identityTransform.Matrix          = Matrix.Identity;

                Log.Comment("Verifying AcrylicBrush default property values");
                Verify.AreEqual(acrylicBrush.BackgroundSource, AcrylicBackgroundSource.Backdrop);
                Verify.AreEqual(acrylicBrush.FallbackColor, Color.FromArgb(0, 255, 255, 255));
                Verify.AreEqual(acrylicBrush.AlwaysUseFallback, false);
                Verify.AreEqual(acrylicBrush.TintColor, Color.FromArgb(204, 255, 255, 255));
                Verify.AreEqual(acrylicBrush.TintOpacity, 1.0);
                Verify.AreEqual(acrylicBrush.Opacity, 1.0);
            });
        }
コード例 #11
0
        // In non fallback mode, we have crossfading and non crossfading effects.
        // crossfading only last for hundren ms in the transition between fallback mode and acrylic mode.
        //
        void RunVerifyAcrylicBrushEffect()
        {
            bool[] results = { false, false };

            AcrylicBrush acrylicBrush1 = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Green,
                TintOpacity      = 0.1
            };

            // Add Ellipse with Acrylic Fill and Stroke
            Ellipse1.Visibility = Visibility.Visible;
            Ellipse1.Fill       = acrylicBrush1;

            _acrylicTestApi.AcrylicBrush = acrylicBrush1;

            // Force to create a AcrylicBrush which is used for animation. So it's a CrosssFading effect brush
            _acrylicTestApi.ForceCreateAcrylicBrush(true /*useCrossFadeEffect*/);

            var fallbackColor = Colors.Black;
            var tintColor     = Colors.Black;

            // Get FallbackColor and TintColor. Only CrossFading effect brush provides animation properties for both and TryGetColor success.
            CompositionGetValueStatus fallbackColorValueStatus = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("FallbackColor.Color", out fallbackColor);
            CompositionGetValueStatus tintColorValueStatus     = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("TintColor.Color", out tintColor);

            if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
            {
                // On 19H1+, Luminosity impacts the effective tint value, so don't validate it here.
                results[0] = tintColorValueStatus != CompositionGetValueStatus.NotFound &&
                             fallbackColorValueStatus != CompositionGetValueStatus.NotFound &&
                             fallbackColor == acrylicBrush1.FallbackColor;
            }
            else
            {
                var expectIintColor = acrylicBrush1.TintColor;
                expectIintColor.A = (byte)Math.Ceiling(255 * acrylicBrush1.TintOpacity); // alpha channel
                results[0]        = fallbackColor == acrylicBrush1.FallbackColor &&
                                    expectIintColor == tintColor;
            }

            // Force to create a non crosssFading effect brush
            _acrylicTestApi.ForceCreateAcrylicBrush(false /*useCrossFadeEffect*/);

            fallbackColor = Colors.Black;
            tintColor     = Colors.Black;

            // Get FallbackColor and TintColor. Non CrossFading effect brush doesn't provide FallbackColor.Color.
            fallbackColorValueStatus = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("FallbackColor.Color", out fallbackColor);
            tintColorValueStatus     = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("TintColor.Color", out tintColor);


            if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
            {
                // On 19H1+, Luminosity impacts the effective tint value, so don't validate it here.
                results[1] = fallbackColorValueStatus == CompositionGetValueStatus.NotFound;
            }
            else
            {
                var expectIintColor = acrylicBrush1.TintColor;
                expectIintColor.A = (byte)Math.Ceiling(255 * acrylicBrush1.TintOpacity); // alpha channel

                results[1] = fallbackColorValueStatus == CompositionGetValueStatus.NotFound &&
                             expectIintColor == tintColor;
            }

            bool   result       = results[0] && results[1];
            string resultString = System.String.Format("({0},{1})", results[0], results[1]);

            TestResult.Text = "VerifyAcrylicBrushEffect: " + (result ? "Passed" : ("Failed " + resultString));
        }
コード例 #12
0
        // >> Test changes to TintOpacity, TintColor, AcrylicBackgroundsource and Fallback Color
        //    recreate or reuse exsiting AcrylicBursh as expected.
        // >> Also covers AcrylicBrush sharing and rendering in SW-rasterized element (Ellipse)
        void RunAcrylicPropertyChanges()
        {
            AcrylicBrush acrylicBrush1 = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Green,
                TintOpacity      = 0.1
            };

            AcrylicBrush acrylicBrush2 = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Bisque,
                TintOpacity      = 0.8
            };

            // Add Ellipse with Acrylic Fill and Stroke
            Ellipse1.Visibility = Visibility.Visible;
            Ellipse1.Fill       = acrylicBrush1;
            Ellipse1.Stroke     = acrylicBrush2;

            // Reuse Ellipse's brush in Rectangle
            Rectangle1.Fill = acrylicBrush2;

            _acrylicTestApi.AcrylicBrush = acrylicBrush1;
            if (_acrylicTestApi.IsUsingAcrylicBrush == false)
            {
                TestResult.Text = "VerifyOpaqueTintOptimization: Skipped";
                return;
            }

            bool[] results = { false, false, false, false, false, false, false };

            _acrylicTestApi.AcrylicBrush = acrylicBrush1;
            results[0] = VerifyAcrylic();

            _acrylicTestApi.AcrylicBrush = acrylicBrush2;
            results[1] = VerifyAcrylic();

            // Update Tint - should not recreate brush
            _acrylicTestApi.AcrylicBrush = acrylicBrush1;
            CompositionBrush originalAcrylicBrush = UpdateCompositionBrush();

            acrylicBrush1.TintColor = Colors.DeepSkyBlue;
            CompositionBrush updatedAcrylicBrush1 = UpdateCompositionBrush();

            results[2] = VerifyAcrylic() && Object.ReferenceEquals(originalAcrylicBrush, updatedAcrylicBrush1);

            // Update TintOpacity - should not recreate brush
            acrylicBrush1.TintOpacity = 0.123456789;
            CompositionBrush updatedAcrylicBrush2 = UpdateCompositionBrush();

            results[3] = VerifyAcrylic() && Object.ReferenceEquals(originalAcrylicBrush, updatedAcrylicBrush2);

            // Update BackgroundSource to HostBackdrop - should recreate brush
            acrylicBrush1.BackgroundSource = AcrylicBackgroundSource.HostBackdrop;
            CompositionBrush updatedAcrylicBrush3 = UpdateCompositionBrush();

            results[4] = VerifyAcrylic() && !Object.ReferenceEquals(originalAcrylicBrush, updatedAcrylicBrush3);

            // Update BackgroundSource back to Backdrop - should recreate brush
            acrylicBrush1.BackgroundSource = AcrylicBackgroundSource.Backdrop;
            CompositionBrush updatedAcrylicBrush4 = UpdateCompositionBrush();

            results[5] = VerifyAcrylic() &&
                         !Object.ReferenceEquals(originalAcrylicBrush, updatedAcrylicBrush4) &&
                         !Object.ReferenceEquals(updatedAcrylicBrush3, updatedAcrylicBrush4);

            // Update FallbackColor  - should not recreate brush or trigger fallback
            acrylicBrush1.FallbackColor = Colors.LightGoldenrodYellow;
            CompositionBrush updatedAcrylicBrush5 = UpdateCompositionBrush();

            results[6] = VerifyAcrylic() && !Object.ReferenceEquals(originalAcrylicBrush, updatedAcrylicBrush5);

            bool   result       = results[0] && results[1] && results[2] && results[3] && results[4] && results[5] && results[6];
            string resultString = System.String.Format("({0},{1},{2},{3},{4},{5},{6})", results[0], results[1], results[2], results[3], results[4], results[5], results[6]);

            TestResult.Text = "AcrylicPropertyChanges: " + (result ? "Passed" : ("Failed " + resultString));
        }