Example #1
0
 public CompositionMaskHelper(Compositor compositor)
 {
     _compositor        = compositor;
     _canvasDevice      = new CanvasDevice();
     _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
     _surfaceFactory    = SurfaceFactory.CreateFromCompositor(_compositor);
 }
        /// <summary>
        /// Initializes the Composition Brush.
        /// </summary>
        protected override void OnConnected()
        {
            base.OnConnected();

            // Delay creating composition resources until they're required.
            if (CompositionBrush == null)
            {
                // Abort if effects aren't supported.
                if (!CompositionCapabilities.GetForCurrentView().AreEffectsSupported())
                {
                    return;
                }

                var size = new Vector2(SurfaceWidth, SurfaceHeight);

                var device   = CanvasDevice.GetSharedDevice();
                var graphics = CanvasComposition.CreateCompositionGraphicsDevice(Window.Current.Compositor, device);

                var surface = graphics.CreateDrawingSurface(size.ToSize(), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

                using (var session = CanvasComposition.CreateDrawingSession(surface))
                {
                    // Call Implementor to draw on session.
                    if (!OnDraw(device, session, size))
                    {
                        return;
                    }
                }

                _surfaceBrush         = Window.Current.Compositor.CreateSurfaceBrush(surface);
                _surfaceBrush.Stretch = CompositionStretch.Fill;

                CompositionBrush = _surfaceBrush;
            }
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="compositor">Compositor</param>
        /// <param name="useSharedCanvasDevice">Whether to use a shared CanvasDevice or to create a new one.</param>
        /// <param name="useSoftwareRenderer">Whether to use Software Renderer when creating a new CanvasDevice.</param>
        public CompositionGenerator(Compositor compositor, bool useSharedCanvasDevice = true, bool useSoftwareRenderer = false)
        {
            if (compositor == null)
            {
                throw new ArgumentNullException(nameof(compositor), "Compositor cannot be null!");
            }

            // Compositor
            _compositor = compositor;

            // Disposing Lock
            _disposingLock = new object();

            // Canvas Device
            _canvasDevice = useSharedCanvasDevice ?
                            CanvasDevice.GetSharedDevice() : new CanvasDevice(useSoftwareRenderer);
            _isCanvasDeviceCreator = !useSharedCanvasDevice;

            _canvasDevice.DeviceLost += DeviceLost;

            // Composition Graphics Device
            _graphicsDevice          = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
            _isGraphicsDeviceCreator = true;

            _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced;
            if (!DesignMode.DesignModeEnabled)
            {
                DisplayInformation.DisplayContentsInvalidated += OnDisplayContentsInvalidated;
            }
        }
Example #4
0
        public FrameServerHandler(MediaPlayer player, FrameworkElement container, string id, IPropertySet properties)
        {
            CanvasDevice      = CanvasDevice.GetSharedDevice();
            Container         = container;
            ID                = id;
            Player            = player;
            ContainerVisual   = ElementCompositionPreview.GetElementVisual(container);
            Compositor        = ContainerVisual.Compositor;
            CompositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(Compositor, CanvasDevice);
            SpriteVisual      = Compositor.CreateSpriteVisual();
            SurfaceBrush      = Compositor.CreateSurfaceBrush();

            SpriteVisual.Brush   = SurfaceBrush;
            SurfaceBrush.Stretch = CompositionStretch.Uniform;
            ElementCompositionPreview.SetElementChildVisual(container, SpriteVisual);
            var sizeAni = Compositor.CreateExpressionAnimation("Container.Size");

            sizeAni.SetReferenceParameter("Container", ContainerVisual);
            SpriteVisual.StartAnimation("Size", sizeAni);

            CanvasDevice.DeviceLost += CanvasDevice_DeviceLost;

            Container.SizeChanged += Container_SizeChanged;

            player.IsVideoFrameServerEnabled = true;
            player.VideoFrameAvailable      += Player_VideoFrameAvailable;
            player.MediaOpened += Player_MediaOpened;
            //createDestinationTarget();
        }
        /// <summary>

        /// Creates an instance of the ColorBloomTransitionHelper.

        /// Any visuals to be later created and animated will be hosted within the specified UIElement.

        /// </summary>

        public ColorBloomTransitionHelper(UIElement hostForVisual)

        {
            this.hostForVisual = hostForVisual;



            // we have an element in the XAML tree that will host our Visuals

            var visual = ElementCompositionPreview.GetElementVisual(hostForVisual);

            _compositor = visual.Compositor;



            // create a container

            // adding children to this container adds them to the live visual tree

            _containerForVisuals = _compositor.CreateContainerVisual();

            ElementCompositionPreview.SetElementChildVisual(hostForVisual, _containerForVisuals);
            _canvasDevice   = new CanvasDevice();
            _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);

            // Create the circle mask

            _circleMaskSurface = LoadCircle(200, Colors.White);
        }
Example #6
0
        private void Setup()
        {
            _canvasDevice = new CanvasDevice();

            var compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(
                Window.Current.Compositor,
                _canvasDevice);

            var compositor = Window.Current.Compositor;

            _surface = compositionGraphicsDevice.CreateDrawingSurface(
                new Size(1000, 600),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);
            // 现在只有这个参数能在 Composition 使用

            var visual = compositor.CreateSpriteVisual();

            visual.RelativeSizeAdjustment = Vector2.One;
            var brush = compositor.CreateSurfaceBrush(_surface);

            brush.Stretch = CompositionStretch.Uniform;
            visual.Brush  = brush;
            ElementCompositionPreview.SetElementChildVisual(this, visual);

            _compositionGraphicsDevice = compositionGraphicsDevice;
        }
        private static async Task <CompositionDrawingSurface> GetCompositionDrawingSurface(Compositor compositor, RenderTargetBitmap renderTargetBitmap)
        {
            IBuffer pixels = await renderTargetBitmap.GetPixelsAsync();

            using (var canvasDevice = new CanvasDevice())
                using (CompositionGraphicsDevice graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice))
                {
                    float dpi = DisplayInformation.GetForCurrentView().LogicalDpi;
                    using (var canvasBitmap = CanvasBitmap.CreateFromBytes(canvasDevice, pixels.ToArray(),
                                                                           renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight,
                                                                           DirectXPixelFormat.B8G8R8A8UIntNormalized, dpi))
                    {
                        CompositionDrawingSurface surface = graphicsDevice.CreateDrawingSurface(
                            new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight),
                            DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);
                        using (CanvasDrawingSession session = CanvasComposition.CreateDrawingSession(surface))
                        {
                            session.DrawImage(canvasBitmap, 0, 0,
                                              new Rect(0, 0, canvasBitmap.Size.Width, canvasBitmap.Size.Height));
                        }

                        return(surface);
                    }
                }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // This container visual is optional - content could go directly into the root
            // containerVisual. This lets you overlay just the picture box, and you could add
            // other container visuals to overlay other areas of the UI.
            pictureOverlayVisual        = compositor.CreateContainerVisual();
            pictureOverlayVisual.Offset = new Vector3(pictureBox1.Bounds.Left, pictureBox1.Bounds.Top, 0);
            pictureOverlayVisual.Size   = new Vector2(pictureBox1.Width, pictureBox1.Height);
            containerVisual.Children.InsertAtTop(pictureOverlayVisual);

            rectWidth  = pictureBox1.Width / 2;
            rectHeight = pictureBox1.Height / 2;

            // Get graphics device.
            compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice);

            // Create surface.
            var noiseDrawingSurface = compositionGraphicsDevice.CreateDrawingSurface(
                new Windows.Foundation.Size(rectWidth, rectHeight),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);

            // Draw to surface and create surface brush.
            var noiseFilePath = AppDomain.CurrentDomain.BaseDirectory + "Assets\\NoiseAsset_256X256.png";

            LoadSurface(noiseDrawingSurface, noiseFilePath);
            noiseSurfaceBrush = compositor.CreateSurfaceBrush(noiseDrawingSurface);

            // Add composition content to tree.
            AddCompositionContent();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="compositor">Compositor</param>
        /// <param name="graphicsDevice">CompositionGraphicsDevice</param>
        /// <param name="sharedLock">shared lock</param>
        public CompositionMaskGenerator(Compositor compositor, CompositionGraphicsDevice graphicsDevice = null,
                                        object sharedLock = null)
        {
            if (compositor == null)
            {
                throw new ArgumentNullException(nameof(compositor), "Compositor cannot be null!");
            }

            _compositor  = compositor;
            _drawingLock = sharedLock ?? new object();

            if (_canvasDevice == null)
            {
                _canvasDevice             = CanvasDevice.GetSharedDevice();
                _canvasDevice.DeviceLost += DeviceLost;
            }

            if (graphicsDevice == null)
            {
                // Create the Composition Graphics Device
                _graphicsDevice  = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
                _isDeviceCreator = true;
            }
            else
            {
                _graphicsDevice  = graphicsDevice;
                _isDeviceCreator = false;
            }

            // Subscribe to events
            _graphicsDevice.RenderingDeviceReplaced       += RenderingDeviceReplaced;
            DisplayInformation.DisplayContentsInvalidated += OnDisplayContentsInvalidated;
        }
Example #10
0
        private void Setup()
        {
            _canvasDevice = new CanvasDevice();

            _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(
                Windows.UI.Xaml.Window.Current.Compositor,
                _canvasDevice);

            _compositor = Windows.UI.Xaml.Window.Current.Compositor;

            _surface = _compositionGraphicsDevice.CreateDrawingSurface(
                new Windows.Foundation.Size(400, 400),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);    // This is the only value that currently works with
                                                    // the composition APIs.

            var visual = _compositor.CreateSpriteVisual();

            visual.RelativeSizeAdjustment = Vector2.One;
            var brush = _compositor.CreateSurfaceBrush(_surface);

            brush.HorizontalAlignmentRatio = 0.5f;
            brush.VerticalAlignmentRatio   = 0.5f;
            brush.Stretch = CompositionStretch.Uniform;
            visual.Brush  = brush;
            ElementCompositionPreview.SetElementChildVisual(this, visual);
            StartCaptureInternal(MainPage.targetcap);
        }
        private void CompositionHostControl_Loaded(object sender, RoutedEventArgs e)
        {
            _currentDpi = WindowsMedia.VisualTreeHelper.GetDpi(this);

            _rectWidth  = CompositionHostElement.ActualWidth / 2;
            _rectHeight = CompositionHostElement.ActualHeight / 2;

            // Get graphics device.
            _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);

            // Create surface.
            var noiseDrawingSurface = _compositionGraphicsDevice.CreateDrawingSurface(
                new Windows.Foundation.Size(_rectWidth, _rectHeight),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);

            // Draw to surface and create surface brush.
            var noiseFilePath = AppDomain.CurrentDomain.BaseDirectory + "Assets\\NoiseAsset_256X256.png";

            LoadSurface(noiseDrawingSurface, noiseFilePath);
            _noiseSurfaceBrush = _compositor.CreateSurfaceBrush(noiseDrawingSurface);

            // Add composition content to tree.
            _compositionHost.SetChild(_containerVisual);
            AddCompositionContent();

            ToggleAcrylic();
        }
Example #12
0
        public Screenshot()
        {
            _canvasDevice = new CanvasDevice();

            _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(
                Window.Current.Compositor,
                _canvasDevice);

            _compositor = Window.Current.Compositor;

            _surface = _compositionGraphicsDevice.CreateDrawingSurface(
                new Size(400, 400),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);    // This is the only value that currently works with
                                                    // the composition APIs.

            //var visual = _compositor.CreateSpriteVisual();
            //visual.RelativeSizeAdjustment = Vector2.One;
            //var brush = _compositor.CreateSurfaceBrush(_surface);
            //brush.HorizontalAlignmentRatio = 0.5f;
            //brush.VerticalAlignmentRatio = 0.5f;
            //brush.Stretch = CompositionStretch.Uniform;
            //visual.Brush = brush;
            //ElementCompositionPreview.SetElementChildVisual(this, visual);
        }
 internal void InitializeComposition()
 {
     _compositor  = ElementCompositionPreview.GetElementVisual(this).Compositor;
     _win2DDevice = CanvasDevice.GetSharedDevice();
     _comositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _win2DDevice);
     _myDrawingVisual          = _compositor.CreateSpriteVisual();
     ElementCompositionPreview.SetElementChildVisual(this, _myDrawingVisual);
 }
 public void InitializeComposition()
 {
     compositor  = ElementCompositionPreview.GetElementVisual(this as UIElement).Compositor;
     win2dDevice = CanvasDevice.GetSharedDevice();
     comositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, win2dDevice);
     myDrawingVisual          = compositor.CreateSpriteVisual();
     ElementCompositionPreview.SetElementChildVisual(virtualSurfaceHost, myDrawingVisual);
 }
Example #15
0
        //初始化CanvasDevice和GraphicsDevice
        private void SetupDevices()
        {
            DisplayInformation.DisplayContentsInvalidated += DisplayInformation_DisplayContentsInvalidated;

            _canvasDevice   = CanvasDevice.GetSharedDevice();
            _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_Compositor, _canvasDevice);

            _canvasDevice.DeviceLost += _canvasDevice_DeviceLost;
            _graphicsDevice.RenderingDeviceReplaced += _graphicsDevice_RenderingDeviceReplaced;
        }
Example #16
0
        static public void Initialize(Compositor compositor)
        {
            Debug.Assert(!_intialized);

            _compositor        = compositor;
            _canvasDevice      = new CanvasDevice();
            _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);

            _intialized = true;
        }
Example #17
0
        static public void Initialize(Compositor compositor)
        {
            if (!IsInitialized)
            {
                _compositor        = compositor;
                _canvasDevice      = new CanvasDevice();
                _compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);

                IsInitialized = true;
            }
        }
Example #18
0
        public void OnInitialization()
        {
            //LND
            lnd = new LEDandDisplay(50, 30, 16, "COM6", 1650, 1050, false, 50);
            Update();

            //WriteSittings();
            ReadSittings();
            ShowSittings();
            //rec
            _canvasDevice = new CanvasDevice();
            _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(
                Window.Current.Compositor,
                _canvasDevice);

            //framerate
            dt = DateTime.Now;

            //Arduino
            ArduinoInit();

            //background
            bgndSession        = new ExtendedExecutionSession();
            bgndSession.Reason = ExtendedExecutionReason.Unspecified;

            //drawing
            _compositor = Window.Current.Compositor;

            _surface = _compositionGraphicsDevice.CreateDrawingSurface(
                new Size(100, 100),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);
            var visual = _compositor.CreateSpriteVisual();

            visual.RelativeSizeAdjustment = Vector2.One;
            var brush = _compositor.CreateSurfaceBrush(_surface);

            brush.HorizontalAlignmentRatio = 0.5f;
            brush.VerticalAlignmentRatio   = 0.5f;
            brush.Stretch = CompositionStretch.Uniform;
            visual.Brush  = brush;
            ElementCompositionPreview.SetElementChildVisual(this, visual);
            if (!GraphicsCaptureSession.IsSupported())
            {
                CaptureButton.Visibility = Visibility.Collapsed;
            }
            //autostart
            if (lnd.autostart == true)
            {
                _item = lnd.item;
                //StartCaptureInternal(lnd.item);
                StartCaptureAsync();
            }
        }
Example #19
0
        private static async Task <CompositionSurfaceBrush> LoadWin2DSurfaceBrushFromImageAsync(
            [NotNull] Compositor compositor, [NotNull] Uri uri, bool reload = false)
        {
            // Lock the semaphore and check the cache first
            await Win2DSemaphore.WaitAsync();

            if (!reload && SurfacesCache.TryGetValue(uri.ToString(), out CompositionSurfaceBrush cached))
            {
                Win2DSemaphore.Release();
                return(cached);
            }

            // Load the image
            CompositionSurfaceBrush brush;

            try
            {
                // This will throw and the canvas will re-initialize the Win2D device if needed
                CanvasDevice sharedDevice = CanvasDevice.GetSharedDevice();
                using (CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(sharedDevice, uri))
                {
                    // Get the device and the target surface
                    CompositionGraphicsDevice device  = CanvasComposition.CreateCompositionGraphicsDevice(compositor, sharedDevice);
                    CompositionDrawingSurface surface = device.CreateDrawingSurface(default(Size),
                                                                                    DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied);

                    // Calculate the surface size
                    Size size = bitmap.Size;
                    CanvasComposition.Resize(surface, size);

                    // Draw the image on the surface and get the resulting brush
                    using (CanvasDrawingSession session = CanvasComposition.CreateDrawingSession(surface))
                    {
                        session.Clear(Color.FromArgb(0, 0, 0, 0));
                        session.DrawImage(bitmap, new Rect(0, 0, size.Width, size.Height), new Rect(0, 0, size.Width, size.Height));
                        brush = surface.Compositor.CreateSurfaceBrush(surface);
                    }
                }
            }
            catch
            {
                // Device error
                brush = null;
            }
            String key = uri.ToString();

            if (brush != null && !SurfacesCache.ContainsKey(key))
            {
                SurfacesCache.Add(key, brush);
            }
            Win2DSemaphore.Release();
            return(brush);
        }
Example #20
0
        public ManagedSurface LoadCircle(float radius, Color color)

        {
            _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);


            ManagedSurface surface = new ManagedSurface(CreateSurface(new Size(radius * 2, radius * 2)));

            var ignored = surface.Draw(_graphicsDevice, _drawingLock, new CircleDrawer(radius, color));



            return(surface);
        }
Example #21
0
        void CreateDevice()
        {
            _device             = CanvasDevice.GetSharedDevice();
            _device.DeviceLost += Device_DeviceLost;

            if (_compositionGraphicsDevice == null)
            {
                _compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _device);
            }
            else
            {
                CanvasComposition.SetCanvasDevice(_compositionGraphicsDevice, _device);
            }
        }
Example #22
0
        async Task ShowBitmapOnTargetAsync(CanvasBitmap bitmap)
        {
            int scale = (int)Math.Ceiling(ActualSize.Y / bitmap.Size.Height);

            Height = bitmap.Size.Height / bitmap.Size.Width * ActualSize.X;

            _previousBitmap = bitmap;
            _previousColors = null;

            var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            var compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, CanvasDevice.GetSharedDevice());

            if (_patternBitmap is null)
            {
                _patternBitmap = await CanvasBitmap.LoadAsync(CanvasDevice.GetSharedDevice(), @"Assets\BackgroundPattern.png");
            }

            var surface = compositionGraphicsDevice.CreateDrawingSurface(
                new Size(bitmap.Size.Width * scale, bitmap.Size.Height * scale),
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                DirectXAlphaMode.Premultiplied);

            using (var drawingSession = CanvasComposition.CreateDrawingSession(surface))
            {
                var border = new BorderEffect
                {
                    ExtendX = CanvasEdgeBehavior.Wrap,
                    ExtendY = CanvasEdgeBehavior.Wrap,
                    Source  = _patternBitmap,
                };

                var scaleEffect = new ScaleEffect
                {
                    Scale             = new Vector2(scale, scale),
                    InterpolationMode = CanvasImageInterpolation.NearestNeighbor,
                };

                scaleEffect.Source = border;
                drawingSession.DrawImage(scaleEffect);
                scaleEffect.Source = bitmap;
                drawingSession.DrawImage(scaleEffect);
            }

            var surfaceBrush = compositor.CreateSurfaceBrush(surface);

            _spriteVisual.Brush = surfaceBrush;
        }
Example #23
0
        private void CreateDevice()
        {
            if (_compositor != null)
            {
                if (_canvasDevice == null)
                {
                    _canvasDevice             = CanvasDevice.GetSharedDevice();
                    _canvasDevice.DeviceLost += DeviceLost;
                }

                if (_graphicsDevice == null)
                {
                    _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
                    _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced;
                }
            }
        }
Example #24
0
        public ImageLoader(Compositor compositor)
        {
            Debug.Assert(compositor != null && _compositor == null);

            _compositor       = compositor;
            _drawingLock      = new object();
            _deviceLostHelper = new DeviceLostHelper();

            _canvasDevice             = new CanvasDevice();
            _canvasDevice.DeviceLost += DeviceLost;

            _deviceLostHelper.WatchDevice(_canvasDevice);
            _deviceLostHelper.DeviceLost += DeviceRemoved;

            _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _canvasDevice);
            _graphicsDevice.RenderingDeviceReplaced += RenderingDeviceReplaced;
        }
        protected override void OnConnected()
        {
            if (CompositionBrush == null)
            {
                IsConnected    = true;
                canvasDevice   = CanvasDevice.GetSharedDevice();
                graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(Compositor, canvasDevice);
                surface1       = graphicsDevice.CreateDrawingSurface(
                    new Windows.Foundation.Size(100, 100),
                    Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                    Windows.Graphics.DirectX.DirectXAlphaMode.Premultiplied);
                surface2 = graphicsDevice.CreateDrawingSurface(
                    new Windows.Foundation.Size(100, 100),
                    Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized,
                    Windows.Graphics.DirectX.DirectXAlphaMode.Premultiplied);
                surfaceBrush1         = Compositor.CreateSurfaceBrush(surface1);
                surfaceBrush2         = Compositor.CreateSurfaceBrush(surface2);
                surfaceBrush1.Stretch = CompositionStretch.Fill;
                surfaceBrush2.Stretch = CompositionStretch.Fill;

                colorBrush1 = Compositor.CreateColorBrush();
                colorBrush2 = Compositor.CreateColorBrush();

                Source1Animation = Compositor.CreateScalarKeyFrameAnimation();
                Source1Animation.InsertKeyFrame(0f, 1f);
                Source1Animation.InsertKeyFrame(1f, 0f);
                Source1Animation.Duration = Duration;

                Source2Animation = Compositor.CreateScalarKeyFrameAnimation();
                Source2Animation.InsertKeyFrame(0f, 0f);
                Source2Animation.InsertKeyFrame(1f, 1f);
                Source2Animation.Duration = Duration;

                var effect = new ArithmeticCompositeEffect()
                {
                    Name           = "effect",
                    Source1        = new CompositionEffectSourceParameter("source1"),
                    Source2        = new CompositionEffectSourceParameter("source2"),
                    Source1Amount  = 1f,
                    Source2Amount  = 0f,
                    MultiplyAmount = 0,
                };
                CompositionBrush = Compositor.CreateEffectFactory(effect, new[] { "effect.Source1Amount", "effect.Source2Amount" }).CreateBrush();
            }
        }
Example #26
0
        /// <summary>
        /// Reloads the <see cref="canvasDevice"/> and <see cref="compositionDevice"/> fields.
        /// </summary>
        private void InitializeDevices()
        {
            if (!(this.canvasDevice is null))
            {
                this.canvasDevice.DeviceLost -= CanvasDevice_DeviceLost;
            }

            if (!(this.compositionDevice is null))
            {
                this.compositionDevice.RenderingDeviceReplaced -= CompositionDevice_RenderingDeviceReplaced;
            }

            this.canvasDevice      = new CanvasDevice();
            this.compositionDevice = CanvasComposition.CreateCompositionGraphicsDevice(this.compositor, this.canvasDevice);

            this.canvasDevice.DeviceLost += CanvasDevice_DeviceLost;
            this.compositionDevice.RenderingDeviceReplaced += CompositionDevice_RenderingDeviceReplaced;
        }
        void CreateDevice()
        {
            Device             = CanvasDevice.GetSharedDevice();
            Device.DeviceLost += Device_DeviceLost;

            if (CompositionGraphicsDevice == null)
            {
                CompositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(Compositor, Device);
            }
            else
            {
                CanvasComposition.SetCanvasDevice(CompositionGraphicsDevice, Device);
            }

            if (SwapChainRenderer != null)
            {
                SwapChainRenderer.SetDevice(Device, new Size(Window.Bounds.Width, Window.Bounds.Height));
            }
        }
    protected ICompositionSurface CreateSurface()
    {
        double                  width          = 20;
        double                  height         = 20;
        CanvasDevice            device         = CanvasDevice.GetSharedDevice();
        var                     graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, device);
        CompositionSurfaceBrush drawingBrush   = _compositor.CreateSurfaceBrush();
        var                     drawingSurface = graphicsDevice.CreateDrawingSurface(
            new Size(width, height),
            DirectXPixelFormat.B8G8R8A8UIntNormalized,
            DirectXAlphaMode.Premultiplied);

        /* Create Drawing Session is not thread safe - only one can ever be active per app */
        using (var ds = CanvasComposition.CreateDrawingSession(drawingSurface))
        {
            ds.Clear(Colors.Transparent);
            ds.DrawCircle(new Vector2(10, 10), 5, Colors.Black, 3);
        }
    }
Example #29
0
        void CreateDevice()
        {
            device             = CanvasDevice.GetSharedDevice();
            device.DeviceLost += Device_DeviceLost;

            if (compositionGraphicsDevice == null)
            {
                compositionGraphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, device);
            }
            else
            {
                CanvasComposition.SetCanvasDevice(compositionGraphicsDevice, device);
            }

            if (swapChainRenderer != null)
            {
                swapChainRenderer.SetDevice(device, new Size(window.Bounds.Width, window.Bounds.Height));
            }
        }
 private static async Task <CompositionDrawingSurface> GetCompositionDrawingSurface(Compositor compositor, RenderTargetBitmap renderTargetBitmap)
 {
     using (var canvasDevice = new CanvasDevice())
         using (CompositionGraphicsDevice graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(compositor, canvasDevice))
             using (CanvasBitmap canvasBitmap = await GetCanvasBitmap(renderTargetBitmap, canvasDevice))
             {
                 CompositionDrawingSurface surface = graphicsDevice.CreateDrawingSurface(
                     new Size(canvasBitmap.Size.Width, canvasBitmap.Size.Height),
                     DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Ignore);
                 using (CanvasDrawingSession session = CanvasComposition.CreateDrawingSession(surface))
                 {
                     session.Clear(Color.FromArgb(0, 0, 0, 0));
                     session.DrawImage(canvasBitmap,
                                       new Rect(0, 0, surface.Size.Width, surface.Size.Height),
                                       new Rect(0, 0, canvasBitmap.Size.Width, canvasBitmap.Size.Height));
                 }
                 return(surface);
             }
 }