/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { d2dDragHandler = new DragHandler(d2dCanvas) { CursorOver = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1) }; d2dBrush = new ImageBrush(); d2dRectangle.Fill = d2dBrush; effectRenderer = new EffectRenderer(); deviceManager = new DeviceManager(); int pixelWidth = (int)(d2dRectangle.Width * DisplayProperties.LogicalDpi / 96.0); int pixelHeight = (int)(d2dRectangle.Height * DisplayProperties.LogicalDpi / 96.0); d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); d2dBrush.ImageSource = d2dTarget.ImageSource; d2dTarget.OnRender += effectRenderer.Render; deviceManager.OnInitialize += d2dTarget.Initialize; deviceManager.OnInitialize += effectRenderer.Initialize; deviceManager.Initialize(DisplayProperties.LogicalDpi); var window = CoreWindow.GetForCurrentThread(); if (window.Visible) BindRenderingEvents(); window.VisibilityChanged += (_, args) => { if (args.Visible) BindRenderingEvents(); else UnbindRenderingEvents(); }; }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { d2dDragHandler = new DragHandler(d2dCanvas) { CursorOver = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1) }; d2dBrush = new ImageBrush(); d2dRectangle.Fill = d2dBrush; effectRenderer = new EffectRenderer(d2dRectangle, root); deviceManager = new DeviceManager(); int pixelWidth = (int)(d2dRectangle.Width * DisplayProperties.LogicalDpi / 96.0); int pixelHeight = (int)(d2dRectangle.Height * DisplayProperties.LogicalDpi / 96.0); d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); d2dBrush.ImageSource = d2dTarget.ImageSource; d2dTarget.OnRender += effectRenderer.Render; deviceManager.OnInitialize += d2dTarget.Initialize; deviceManager.OnInitialize += effectRenderer.Initialize; deviceManager.Initialize(DisplayProperties.LogicalDpi); // Setup rendering callback CompositionTarget.Rendering += CompositionTarget_Rendering; }
public override void initContent(SurfaceImageSourceTarget target, DrawingSize pixelSize) { this.size = pixelSize; context = target.DeviceManager.ContextDirect2D; pixelBrush = new SolidColorBrush(context, color); dimmingBrush = new SolidColorBrush(context, new Color(0, 0, 0, 10)); }
public override void initContent(SurfaceImageSourceTarget target, DrawingSize pixelSize) { this.drawingSize = pixelSize; this.size = new DrawingSize((int) (pixelSize.Width/scaling), (int) (pixelSize.Height/scaling)); context = target.DeviceManager.ContextDirect2D; Mandelbrot engine = new BasicMandelbrot(iters); view = new TrajectoryMandelbrotView(engine, trajectory, size.Width, size.Height); data = new int[size.Width * size.Height]; PixelFormat format = new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Ignore); BitmapProperties props = new BitmapProperties(format); buf = Bitmap.New<int>(context, size, data, props); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { DeviceManager = new CommonDX.DeviceManager(); D2DBrush = new ImageBrush(); v_renderTarget.Fill = D2DBrush; D2DTarget = new SurfaceImageSourceTarget((int) (v_renderTarget.Width * DisplayProperties.LogicalDpi / 96.0), (int) (v_renderTarget.Height * DisplayProperties.LogicalDpi / 96.0)); D2DBrush.ImageSource = D2DTarget.ImageSource; DeviceManager.OnInitialize += D2DTarget.Initialize; D2DTarget.OnRender += MainViewModel.Render; DeviceManager.Initialize(DisplayProperties.LogicalDpi); CompositionTarget.Rendering += PerformRender; }
/// <summary> /// Detaches the renderer. /// </summary> private void DetachRenderer() { lock (this.deviceManager) { if (this.terminalRenderer == null) { return; } CompositionTarget.Rendering -= CompositionTarget_Rendering; this.d2dTarget.OnRender -= terminalRenderer.Render; this.rectangle.Fill = null; this.deviceManager.OnInitialize -= this.d2dTarget.Initialize; this.deviceManager.OnInitialize -= this.terminalRenderer.Initialize; this.d2dTarget.Dispose(); this.d2dTarget = null; this.terminalRenderer.Dispose(); this.terminalRenderer = null; } }
/// <summary> /// Attaches a renderer. /// </summary> /// <param name="pixelWidth">The width of the display area in pixels.</param> /// <param name="pixelHeight">The height of the display area in pixels.</param> /// <exception cref="InvalidOperationException">A renderer is already attached.</exception> private void AttachRenderer(int pixelWidth, int pixelHeight) { lock (this.deviceManager) { if (this.terminalRenderer != null) { throw new InvalidOperationException("Renderer already attached."); } this.terminalRenderer = new ScreenDisplayRenderer(this, this.terminal.RenderableScreen); this.d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); this.forceRender = true; this.deviceManager.OnInitialize += this.d2dTarget.Initialize; this.deviceManager.OnInitialize += this.terminalRenderer.Initialize; this.deviceManager.Initialize(DisplayInformation.GetForCurrentView().LogicalDpi); this.rectangle.Fill = new ImageBrush() { ImageSource = this.d2dTarget.ImageSource }; this.d2dTarget.OnRender += terminalRenderer.Render; CompositionTarget.Rendering += CompositionTarget_Rendering; } }
public virtual void initContent(SurfaceImageSourceTarget target, DrawingSize pixelSize) { }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { d3dDragHandler = new DragHandler(d3dCanvas) { CursorOver = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1) }; d2dDragHandler = new DragHandler(d2dCanvas) { CursorOver = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1) }; d3dBrush = new ImageBrush(); d3dRectangle.Fill = d3dBrush; d2dBrush = new ImageBrush(); d2dRectangle.Fill = d2dBrush; // Safely dispose any previous instance // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC) deviceManager = new DeviceManager(); // New CubeRenderer cubeRenderer = new CubeRenderer(); shapeRenderer = new ShapeRenderer(); int pixelWidth = (int)(d3dRectangle.Width * DisplayProperties.LogicalDpi / 96.0); int pixelHeight = (int)(d3dRectangle.Height * DisplayProperties.LogicalDpi / 96.0); // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget) d3dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); d3dBrush.ImageSource = d3dTarget.ImageSource; d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); d2dBrush.ImageSource = d2dTarget.ImageSource; // Add Initializer to device manager deviceManager.OnInitialize += d3dTarget.Initialize; deviceManager.OnInitialize += d2dTarget.Initialize; deviceManager.OnInitialize += cubeRenderer.Initialize; deviceManager.OnInitialize += shapeRenderer.Initialize; // Render the cube within the CoreWindow d3dTarget.OnRender += cubeRenderer.Render; d2dTarget.OnRender += shapeRenderer.Render; // Initialize the device manager and all registered deviceManager.OnInitialize deviceManager.Initialize(DisplayProperties.LogicalDpi); // Setup rendering callback CompositionTarget.Rendering += CompositionTarget_Rendering; // Callback on DpiChanged DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged; }
private void Page_SizeChanged(object sender, SizeChangedEventArgs e) { if (e.PreviousSize == new Size(0, 0)) { return; } _D3dBrush.ImageSource = null; _SurfaceImageSourceTarget.OnRender -= _SurfaceImageSourceTarget_OnRender; var pixelWidth = (int)(this.RenderTarget.ActualWidth * DisplayProperties.LogicalDpi / 96.0); var pixelHeight = (int)(this.RenderTarget.ActualHeight * DisplayProperties.LogicalDpi / 96.0); _SurfaceImageSourceTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); _SurfaceImageSourceTarget.OnRender += _SurfaceImageSourceTarget_OnRender; _SurfaceImageSourceTarget.Initialize(_DeviceManager); _D3dBrush.ImageSource = _SurfaceImageSourceTarget.ImageSource; }
private void RenderTarget_Loaded(object sender, RoutedEventArgs e) { var pixelWidth = (int)(this.RenderTarget.ActualWidth * DisplayProperties.LogicalDpi / 96.0); var pixelHeight = (int)(this.RenderTarget.ActualHeight * DisplayProperties.LogicalDpi / 96.0); _SurfaceImageSourceTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); _SurfaceImageSourceTarget.OnRender += _SurfaceImageSourceTarget_OnRender; _D3dBrush.ImageSource = _SurfaceImageSourceTarget.ImageSource; _DeviceManager.OnInitialize += _DeviceManager_OnInitialize; _DeviceManager.Initialize(DisplayProperties.LogicalDpi); Windows.UI.Xaml.Media.CompositionTarget.Rendering += CompositionTarget_Rendering; DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged; }
private void load(Object sender, RoutedEventArgs e) { // Create bitmap and set it to black ImageBrush d2dBrush = new ImageBrush(); d2dRectangle.Fill = d2dBrush; DeviceManager deviceManager = new DeviceManager(); DrawingSize size = new DrawingSize((int)d2dContainer.ActualWidth, (int)d2dContainer.ActualHeight); d2dTarget = new SurfaceImageSourceTarget(size.Width, size.Height); d2dBrush.ImageSource = d2dTarget.ImageSource; deviceManager.OnInitialize += d2dTarget.Initialize; deviceManager.Initialize(DisplayProperties.LogicalDpi); d2dTarget.OnRender += item.drawContent; item.initContent(d2dTarget, size); CompositionTarget.Rendering += CompositionTarget_Rendering; }
//public SharpDX.Direct2D1.Bitmap1 CreateBitmapTarget() //{ // return d2dTarget.CreateNewBitmapTarget(); //} void DrawingSurfaceSIS_Unloaded(object sender, RoutedEventArgs e) { CompositionTarget.Rendering -= CompositionTarget_Rendering; _deviceManager.OnInitialize -= _sisTarget1.Initialize; _deviceManager.OnInitialize -= _sisTarget2.Initialize; _deviceManager.OnInitialize -= _effectRenderer.Initialize; _deviceManager.OnInitialize -= _magicRenderer.Initialize; _deviceManager.Dispose(); _deviceManager = null; _sisTarget1.OnRender -= _effectRenderer.Render; _sisTarget1.Dispose(); _sisTarget1 = null; _sisTarget2.OnRender -= _magicRenderer.Render; _sisTarget2.Dispose(); _sisTarget2 = null; _hasInitializedSurface = false; this.Unloaded -= DrawingSurfaceSIS_Unloaded; }
private void mainGrid_Loaded(object sender, RoutedEventArgs e) { if (!_hasInitializedSurface) { int pixelWidth = (int)(d2dRectangleBottom.ActualWidth * DisplayProperties.LogicalDpi / 96.0); int pixelHeight = (int)(d2dRectangleBottom.ActualHeight * DisplayProperties.LogicalDpi / 96.0); _ibTarget1 = new ImageBrush(); _ibTarget2 = new ImageBrush(); //_rectEffect = new Windows.UI.Xaml.Shapes.Rectangle() { HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch, VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch, Width = pixelWidth, Height = pixelHeight }; //mainGrid.Children.Add(_rectEffect); //_rectMagic = new Windows.UI.Xaml.Shapes.Rectangle() { HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch, VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch, Width = pixelWidth, Height = pixelHeight }; //mainGrid.Children.Add(_rectMagic); d2dRectangleBottom.Opacity = 1.0f; d2dRectangleBottom.Fill = _ibTarget1; d2dRectangleTop.Opacity = 1.0f; d2dRectangleTop.Fill = _ibTarget2; //_rectEffect.Fill = _ibTarget1; //_rectMagic.Fill = _ibTarget2; _deviceManager = new DeviceManager(); _sisTarget1 = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); _sisTarget2 = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); _ibTarget1.ImageSource = _sisTarget1.ImageSource; _ibTarget2.ImageSource = _sisTarget2.ImageSource; _sisTarget1.OnRender += _effectRenderer.Render; _sisTarget2.OnRender += _magicRenderer.Render; _deviceManager.OnInitialize += _sisTarget1.Initialize; _deviceManager.OnInitialize += _effectRenderer.Initialize; _deviceManager.OnInitialize += _sisTarget2.Initialize; _deviceManager.OnInitialize += _magicRenderer.Initialize; _deviceManager.Initialize(DisplayProperties.LogicalDpi); _effectRenderer.InitializeUI(root, _rectEffect);//d2dRectangleBottom); _magicRenderer.InitializeUI(root, _rectMagic); //var fpsRenderer = new FpsRenderer(); //fpsRenderer.Initialize(deviceManager); //d2dTarget.OnRender += fpsRenderer.Render; if (_assetUri != null && _assetUri != string.Empty) _effectRenderer.LoadLocalAsset(_assetUri); _hasInitializedSurface = true; } this.Unloaded += DrawingSurfaceSIS_Unloaded; }
//public SharpDX.Direct2D1.Bitmap1 CreateBitmapTarget() //{ // return d2dTarget.CreateNewBitmapTarget(); //} //void DrawingSurfaceSIS_Unloaded(object sender, RoutedEventArgs e) //{ // Unload(); //} public void Unload() { //if (_effectRenderer != null && _sisTarget1!=null ) _sisTarget1.OnRender -= _effectRenderer.Render; if (_renderRendererAction != null) _loadAssetUriRendererAction = null; CompositionTarget.Rendering -= CompositionTarget_Rendering; //this.Unloaded -= DrawingSurfaceSIS_Unloaded; if(_deviceManager!=null && _sisTarget1!=null) { _deviceManager.OnInitialize -= _sisTarget1.Initialize; } //if(_deviceManager!=null && _effectRenderer!=null) { _deviceManager.OnInitialize -= _effectRenderer.Initialize; } if (_initializeRendererAction != null) _initializeRendererAction = null; //_deviceManager.Dispose(); //_deviceManager = null; if (_unloadRendererAction != null) { //_effectRenderer.Unload(); //_effectRenderer = null; _unloadRendererAction(); _unloadRendererAction = null; } if (_sisTarget1 != null) { _sisTarget1.Dispose(); _sisTarget1 = null; } _hasInitializedSurface = false; _deviceManager = null; d2dRectangleBottom.Fill = null; if (_ibTarget1 != null) { _ibTarget1.ImageSource = null; _ibTarget1 = null; } _initializeUIRendererAction = null; _loadAssetUriRendererAction = null; _unloadRendererAction = null; }
private void mainGrid_Loaded(object sender, RoutedEventArgs e) { if (!_hasInitializedSurface) { _ibTarget1 = new ImageBrush(); d2dRectangleBottom.Opacity = 1.0f; d2dRectangleBottom.Fill = _ibTarget1; //_deviceManager = new DeviceManager(); int pixelWidth = (int)(d2dRectangleBottom.ActualWidth * DisplayProperties.LogicalDpi / 96.0); int pixelHeight = (int)(d2dRectangleBottom.ActualHeight * DisplayProperties.LogicalDpi / 96.0); _sisTarget1 = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); _ibTarget1.ImageSource = _sisTarget1.ImageSource; //_sisTarget1.OnRender += _effectRenderer.Render; _sisTarget1.OnRender += _renderRendererAction; _deviceManager.OnInitialize += _sisTarget1.Initialize; //_deviceManager.OnInitialize += _effectRenderer.Initialize; _deviceManager.OnInitialize += _initializeRendererAction; _deviceManager.Initialize(DisplayProperties.LogicalDpi); //_effectRenderer.InitializeUI(root, d2dRectangleBottom); if (_initializeUIRendererAction!=null) _initializeUIRendererAction(root, d2dRectangleBottom); //var fpsRenderer = new FpsRenderer(); //fpsRenderer.Initialize(deviceManager); //d2dTarget.OnRender += fpsRenderer.Render; //if (_assetUri != null && _assetUri != string.Empty) _effectRenderer.LoadLocalAsset(_assetUri); if (_assetUri != null && _assetUri != string.Empty) _loadAssetUriRendererAction(_assetUri); //this.Unloaded += DrawingSurfaceSIS_Unloaded; _hasInitializedSurface = true; } }