예제 #1
0
파일: D3DRenderer.cs 프로젝트: rox00/WPF
        /// <summary>
        /// Configures D3DImage with a new surface.  This happens immediately
        /// </summary>
        private void SetBackBufferInternal(IntPtr backBuffer)
        {
            /* Do nothing if we don't have a new surface available */
            if (!m_newSurfaceAvailable)
            {
                return;
            }

            if (!D3DImage.Dispatcher.CheckAccess())
            {
                D3DImage.Dispatcher.BeginInvoke((Action)(() => SetBackBufferInternal(backBuffer)));
                return;
            }

            /* We have this around a try/catch just in case we
             * lose the device and our Surface is invalid. The
             * try/catch may not be needed, but testing needs
             * to take place before it's removed */
            try
            {
                D3DImage.Lock();
                D3DImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, backBuffer);
                D3DImage.Unlock();
                SetNaturalWidthHeight();
            }
            catch (Exception ex)
            { }

            /* Clear our flag, so this won't be ran again
             * until a new surface is sent */
            m_newSurfaceAvailable = false;
        }
예제 #2
0
파일: D3DRenderer.cs 프로젝트: rox00/WPF
        /// <summary>
        /// Invalidates the entire Direct3D image, notifying WPF to redraw
        /// </summary>
        protected void InternalInvalidateVideoImage()
        {
            /* Ensure we run on the correct Dispatcher */
            if (!D3DImage.Dispatcher.CheckAccess())
            {
                D3DImage.Dispatcher.Invoke((Action)(() => InvalidateVideoImage()));
                return;
            }

            /* If there is a new Surface to set,
             * this method will do the trick */
            SetBackBufferInternal(m_pBackBuffer);

            /* Only render the video image if possible, or if IsRenderingEnabled is true */
            if (D3DImage.IsFrontBufferAvailable && IsRenderingEnabled && m_pBackBuffer != IntPtr.Zero)
            {
                try
                {
                    /* Invalidate the entire image */
                    D3DImage.Lock();
                    D3DImage.AddDirtyRect(new Int32Rect(0,                   /* Left */
                                                        0,                   /* Top */
                                                        D3DImage.PixelWidth, /* Width */
                                                        D3DImage.PixelHeight /* Height */));
                    D3DImage.Unlock();
                }
                catch (Exception)
                { }
            }

            /* Invalidate all of our cloned D3DRenderers */
            InvalidateClonedVideoImages();
        }
예제 #3
0
 private unsafe void OnIsFrontBufferAvailableChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     // If the front buffer becomes unavailable, the D3DImage is discarded. This is for robustness since in
     // some situations the front buffer seems never to become available again.
     if (d3dImage.IsFrontBufferAvailable)
     {
         ReleaseBackBuffer();
         SetBackBuffer();
         RenderScene();
         if (surfaceType == SurfaceType.DirectX9)
         {
             ResetDevice();
         }
     }
     else
     {
         imageBrush = null;
         d3dImage.IsFrontBufferAvailableChanged -= OnIsFrontBufferAvailableChanged;
         d3dImage = null;
         if (surfaceType == SurfaceType.DirectX9 && graphicsDeviceService9.UseDeviceEx == false)
         {
             if (graphicsDeviceService9.GraphicsDevice.TestCooperativeLevel() == ResultCode.DeviceNotReset)
             {
                 ResetDevice();
             }
             ReleaseBackBuffer();
         }
     }
 }
        public void UpdateSurface(D3DImage previewSurface, string bsChannelID, string bsEventName, string bsEventParam, object pEventObject)
        {
            if (bsEventName == "wpf_nextframe")
            {
                IntPtr pSurfaceIUnk = Marshal.GetIUnknownForObject(pEventObject);
                if (pSurfaceIUnk != SavedSurfaceIUnk)
                {
                    if (SavedSurfaceIUnk != IntPtr.Zero)
                    {
                        Marshal.Release(SavedSurfaceIUnk);
                    }

                    SavedSurfaceIUnk = pSurfaceIUnk;
                    Marshal.AddRef(SavedSurfaceIUnk);

                    previewSurface.Lock();
                    previewSurface.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
                    previewSurface.SetBackBuffer(D3DResourceType.IDirect3DSurface9, SavedSurfaceIUnk);
                    previewSurface.Unlock();
                }

                if (pSurfaceIUnk != IntPtr.Zero)
                {
                    Marshal.Release(pSurfaceIUnk);
                }

                previewSurface.Lock();
                previewSurface.AddDirtyRect(new Int32Rect(0, 0, previewSurface.PixelWidth, previewSurface.PixelHeight));
                previewSurface.Unlock();
            }

            Marshal.ReleaseComObject(pEventObject);
        }
예제 #5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            try
            {
                viewbox       = (Viewbox)this.Template.FindName("PART_viewbox", this);
                hostGrid      = (Grid)this.Template.FindName("PART_hostGrid", this);
                targetImage   = (Image)this.Template.FindName("PART_targetImage", this);
                d3dImage      = (D3DImage)this.Template.FindName("PART_d3dImage", this);
                canvasPushPin = (Canvas)this.Template.FindName("PART_canvasPushPin", this);

                targetImage.AddHandler(Contacts.PreviewContactDownEvent, new ContactEventHandler(targetImage_PreviewContactDown));
                targetImage.AddHandler(Contacts.PreviewContactChangedEvent, new ContactEventHandler(targetImage_PreviewContactChanged));
                targetImage.AddHandler(Contacts.PreviewContactUpEvent, new ContactEventHandler(targetImage_PreviewContactUp));
            }
            catch (Exception)
            {
            }

            //Are we in Visual Studio Designer?
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                //then set a sample image and do anything else
                TextBlock tb = new TextBlock();
                tb.Text       = "VE";
                tb.FontSize   = 24;
                tb.Background = new SolidColorBrush(Colors.Green);

                this.hostGrid.Background = new VisualBrush(tb);
                return;
            }
        }
예제 #6
0
        public RenderTarget GetOrCreateRenderTarget()
        {
            EnsureDirectX();
            var scale = _impl.GetScaling();
            var size  = new IntSize(_impl.ActualWidth * scale.X, _impl.ActualHeight * scale.Y);
            var dpi   = scale * 96;

            if (_backBuffer != null && _backBuffer.Size == size)
            {
                return(_backBuffer.Target);
            }

            if (_image == null || _oldDpi.X != dpi.X || _oldDpi.Y != dpi.Y)
            {
                _image = new D3DImage(dpi.X, dpi.Y);
            }
            _impl.ImageSource = _image;

            RemoveAndDispose(ref _backBuffer);
            if (size == default(IntSize))
            {
                _image.Lock();
                _image.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
                _image.Unlock();
                return(null);
            }
            _backBuffer = new SwapBuffer(size, dpi);

            return(_backBuffer.Target);
        }
예제 #7
0
        private void OnLoaded(object sender, EventArgs e)
        {
            UpdateTargetSize();

            InitializeXna();

            _d3dImage = new D3DImage();
            _d3dImage.Lock();

            try
            {
                _d3dImage.SetBackBuffer(
                    D3DResourceType.IDirect3DSurface9,
                    _frontBufferPointer);
            }
            finally
            {
                _d3dImage.Unlock();
            }

            _targetImage.Source = _d3dImage;

            if (_deviceManager.GraphicsDevice.GraphicsDeviceCapabilities.DeviceType == DeviceType.Hardware)
            {
                CompositionTarget.Rendering += OnCompositionTargetRendering;
            }
            else
            {
                _timer       = XnaHelper.CreateRenderTimer();
                _timer.Tick += OnCompositionTargetRendering;
                _timer.Start();
            }

            _stopwatch.Start();
        }
        /// <summary>
        /// レンダリングシステムを準備する
        /// </summary>
        private void SetupRendering()
        {
            // くっきり表示させる
            RenderOptions.SetEdgeMode(Image, EdgeMode.Aliased);
            RenderOptions.SetBitmapScalingMode(Image, BitmapScalingMode.NearestNeighbor);


            // ウィンドウハンドルを生成
            var hwndSrc = new HwndSource(0, 0, 0, 0, 0, "DxLib", IntPtr.Zero);

            // Imageは1920*1080固定
            var imageSize = new Size(1920, 1080);

            Image.RenderSize = imageSize;
            Image.Width      = imageSize.Width;
            Image.Height     = imageSize.Height;
            _soundEffectToolVM.CreateDxView(hwndSrc.Handle, _windowName, Image.RenderSize);

            D3DImage     = new D3DImage();
            Image.Source = D3DImage;

            // 描画の更新
            CompositionTarget.Rendering            += UpdateRendering;
            D3DImage.IsFrontBufferAvailableChanged += D3DImage_IsFrontBufferAvailableChanged;

            // 描画対象に設定
            _wavePixelsPerSec = _soundEffectToolVM.GetDefaultPixelsPerSec();
            _soundEffectToolVM.SetWaveData(_windowName, SoundKey);
            var size = _soundEffectToolVM.GetDrawSize(_windowName);

            ImageRect.Width  = size.Width;
            ImageRect.Height = size.Height;
        }
예제 #9
0
        public D2DRender(FooTextBox textbox, double width, double height, Image image)
        {
            this.fontFamily        = textbox.FontFamily;
            this.fontSize          = textbox.FontSize;
            this.fontWeigth        = textbox.FontWeight;
            this.fontStyle         = textbox.FontStyle;
            this.Foreground        = ToColor4(textbox.Foreground);
            this.Background        = ToColor4(textbox.Background);
            this.ControlChar       = ToColor4(textbox.ControlChar);
            this.Hilight           = ToColor4(textbox.Hilight);
            this.Comment           = ToColor4(textbox.Comment);
            this.Url               = ToColor4(textbox.URL);
            this.Keyword1          = ToColor4(textbox.Keyword1);
            this.Keyword2          = ToColor4(textbox.Keyword2);
            this.Literal           = ToColor4(textbox.Literal);
            this.InsertCaret       = ToColor4(textbox.InsertCaret);
            this.OverwriteCaret    = ToColor4(textbox.OverwriteCaret);
            this.LineMarker        = ToColor4(textbox.LineMarker);
            this.UpdateArea        = ToColor4(textbox.UpdateArea);
            this.LineNumber        = ToColor4(textbox.LineNumber);
            this.HilightForeground = ToColor4(textbox.HilightForeground);
            this.store             = textbox.TextStore;

            this.CreateDevice();

            this.ConstructRenderAndResource(width, height);
            this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(this.fontWeigth), this.GetDWFontStyle(this.fontStyle));

            this.imageSource = new D3DImage();
            this.imageSource.Lock();
            this.imageSource.SetBackBuffer(D3DResourceType.IDirect3DSurface9, this.surface9.NativePointer);  //設定しないとロード時に例外が発生する
            this.imageSource.Unlock();

            image.Source = this.imageSource;
        }
예제 #10
0
        /// <summary>
        /// Creates a new instance of <see cref="SharpDXElement"/> class.
        /// Initializes the D3D9 runtime.
        /// </summary>
        public SharpDXElement()
        {
            image = new D3DImage();

            var presentparams = new PresentParameters
            {
                Windowed             = true,
                SwapEffect           = SwapEffect.Discard,
                DeviceWindowHandle   = GetDesktopWindow(),
                PresentationInterval = PresentInterval.Default
            };

            direct3D = new Direct3DEx();

            device9 = new DeviceEx(direct3D,
                                   0,
                                   DeviceType.Hardware,
                                   IntPtr.Zero,
                                   CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve,
                                   presentparams);

            resizeDelayTimer          = new DispatcherTimer(DispatcherPriority.Normal);
            resizeDelayTimer.Interval = SendResizeDelay;
            resizeDelayTimer.Tick    += HandleResizeDelayTimerTick;

            SizeChanged += HandleSizeChanged;
            Unloaded    += HandleUnloaded;
        }
 private void Start()
 {
     if (_isInitialized)
     {
         return;
     }
     if (Application.Current.MainWindow == null)
     {
         throw new InvalidOperationException("The application must have a MainWindow");
     }
     Application.Current.MainWindow.Closing         += (sender, args) => _viewModel?.OnExiting(this, EventArgs.Empty);
     Application.Current.MainWindow.ContentRendered += (sender, args) => {
         if (_isFirstLoad)
         {
             _graphicsDeviceService.StartDirect3D(Application.Current.MainWindow);
             _viewModel?.Initialize();
             _viewModel?.LoadContent();
             _isFirstLoad = false;
         }
     };
     _direct3DImage = new D3DImage();
     AddChild(new Image {
         Source = _direct3DImage, Stretch = Stretch.None
     });
     //_direct3DImage.IsFrontBufferAvailableChanged += OnDirect3DImageIsFrontBufferAvailableChanged;
     _renderTarget = CreateRenderTarget();
     CompositionTarget.Rendering += OnRender;
     _stopwatch.Start();
     _isInitialized = true;
 }
예제 #12
0
        public D3DImage GetInitSurface(string bsChannelID, string bsEventName, string bsEventParam, object pEventObject)
        {
            var image = new D3DImage();

            UpdateSurface(image, bsChannelID, bsEventName, bsEventParam, pEventObject);

            return(image);
        }
예제 #13
0
        /// <summary>
        /// Initializes the D3DRenderer control
        /// </summary>
        private void InitializeD3DVideo()
        {
            if (m_videoImage != null)
            {
                return;
            }

            /* Create our Image and it's D3DImage source */
            m_videoImage      = new Image();
            m_videoImage.Name = "videoImage";
            m_videoImage.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.Fant);
            RenderOptions.SetBitmapScalingMode(m_videoImage, BitmapScalingMode.Fant);
            m_d3dImage = new D3DImage();
            m_d3dImage.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.Fant);
            RenderOptions.SetBitmapScalingMode(m_d3dImage, BitmapScalingMode.Fant);

            /* We hook into this event to handle when a D3D device is lost */
            D3DImage.IsFrontBufferAvailableChanged += D3DImageIsFrontBufferAvailableChanged;

            /* Set our default stretch value of our video */
            m_videoImage.Stretch          = (Stretch)StretchProperty.DefaultMetadata.DefaultValue;
            m_videoImage.StretchDirection = (StretchDirection)StretchProperty.DefaultMetadata.DefaultValue;

            /* Our source of the video image is the D3DImage */
            m_videoImage.Source = D3DImage;

            /* Register the Image as a visual child */
            //Grid g = new Grid();
            //g.Margin = new Thickness(0);
            //g.Children.Add(m_videoImage);
            //var l = new TextBlock();
            //l.HorizontalAlignment = HorizontalAlignment.Left;
            //l.VerticalAlignment = VerticalAlignment.Top;
            //l.SetValue(Panel.ZIndexProperty, 1000);
            //l.Width = 200;
            //l.Height = 30;
            //l.Background = Brushes.White;
            //l.Foreground = Brushes.Black;
            //l.FontFamily = new FontFamily("Arial");
            //l.FontSize = 16;
            //var b = new Binding("ActualWidth");
            //b.Source = m_videoImage;
            //BindingOperations.SetBinding(l, TextBlock.TextProperty, b);
            //g.Children.Add(l);
            //grid = g;
            AddVisualChild(m_videoImage);

            ///* Bind the horizontal alignment dp of this control to that of the video image */
            //var horizontalAlignmentBinding = new Binding("HorizontalAlignment") { Source = this };
            //m_videoImage.SetBinding(HorizontalAlignmentProperty, horizontalAlignmentBinding);

            ///* Bind the vertical alignment dp of this control to that of the video image */
            //var verticalAlignmentBinding = new Binding("VerticalAlignment") { Source = this };
            //m_videoImage.SetBinding(VerticalAlignmentProperty, verticalAlignmentBinding);

            ToggleDeeperColorEffect((bool)DeeperColorProperty.DefaultMetadata.DefaultValue);
        }
예제 #14
0
        public DX3DHost()
        {
            image        = new Image();
            d3dimage     = new D3DImage();
            image.Source = d3dimage;

            this.Content    = image;
            this.components = new DrawableComponentsManager();
            this.camera     = new Camera();
        }
예제 #15
0
        private void CreateD3DImage()
        {
            if (_image != null)
            {
                return;
            }

            var dpi = _shared.Dpi;

            _image = new D3DImage(dpi.DpiX, dpi.DpiY);
        }
예제 #16
0
 // Render the DirectX scene onto the D3DImage when WPF itself is ready to render
 private void CompositionTarget_Rendering(object sender, EventArgs e)
 {
     if (D3DImage.IsFrontBufferAvailable)
     {
         D3DImage.Lock();
         PlatformMethods.Render();
         // Invalidate the whole area:
         D3DImage.AddDirtyRect(new Int32Rect(0, 0, D3DImage.PixelWidth, D3DImage.PixelHeight));
         D3DImage.Unlock();
     }
 }
예제 #17
0
 public CameraParams(Videoinsight.LIB.Camera _camera, int _w, int _h, int _displayRow, int _displayCol, int _surfaceIndex, IntPtr _pSurface, D3DImage _d3dImage = null)
 {
     camera       = _camera;
     Width        = _w;
     Height       = _h;
     DisplayRow   = _displayRow;
     DisplayCol   = _displayCol;
     SurfaceIndex = _surfaceIndex;
     pSurface     = _pSurface;
     d3dImage     = _d3dImage;
 }
예제 #18
0
 public CameraParams()
 {
     camera       = null;
     Width        = 0;
     Height       = 0;
     DisplayRow   = 0;
     DisplayCol   = 0;
     SurfaceIndex = -1;
     pSurface     = IntPtr.Zero;
     d3dImage     = null;
 }
예제 #19
0
        public GraphicsDeviceContextNode()
        {
            _deviceContext = new GraphicsDeviceContext(_width, _height);
            Width          = 90;
            Height         = 90;
            Name           = "Graphics Device Context";
            ResizeEnabled  = true;
            D3DImage       = new D3DImage(96, 96);
            D3DImage.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged;

            BeginRenderingScene();
        }
예제 #20
0
        /// <summary>
        /// Creates a new instance of the FastGLControl-class.
        /// </summary>
        public FastGLControl()
        {
            InitializeComponent();

            _image = new D3DImage();
            _image.IsFrontBufferAvailableChanged += IsFrontBufferAvailableChanged;

            Background   = new ImageBrush(_image);
            Loaded      += new RoutedEventHandler((object sender, RoutedEventArgs args) => { StartRendering(); });
            SizeChanged += new SizeChangedEventHandler(FastGLControl_SizeChanged);
            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
        }
예제 #21
0
 public void RecreateD3DImage(bool setBackBuffer)
 {
     if (d3dImage != null)
     {
         d3dImage.IsFrontBufferAvailableChanged -= OnIsFrontBufferAvailableChanged;
     }
     d3dImage   = new D3DImage();
     imageBrush = new ImageBrush(d3dImage);
     d3dImage.IsFrontBufferAvailableChanged += new DependencyPropertyChangedEventHandler(OnIsFrontBufferAvailableChanged);
     if (setBackBuffer)
     {
         SetBackBuffer();
     }
 }
예제 #22
0
 /// <summary>
 /// Convenient method for making frame shots.
 /// For the exceptions, see <see cref="D3DImage.SetBackBuffer(D3DResourceType, IntPtr)". />
 /// </summary>
 public static void SetBackBufferWithLock(D3DImage d3d, IntPtr backBuffer)
 {
     try
     {
         d3d.Lock();
         d3d.SetBackBuffer(D3DResourceType.IDirect3DSurface9, backBuffer);
         // necessary when rendering on WPF screen only
         AddDirtyRectAll(d3d);
     }
     finally
     {
         d3d.Unlock();
     }
 }
예제 #23
0
        public D3DImageSource(int adapterId)
        {
            this.renderLock = new object();

            this.isVistaOrBetter = IsVistaOrBetter;

            this.imageSource = new D3DImage();
            this.imageSource.IsFrontBufferAvailableChanged += this.OnIsFrontBufferAvailableChanged;

            this.InitD3D(adapterId);

            this.dummyWindow = new Form();
            this.hwnd        = this.dummyWindow.Handle;
        }
예제 #24
0
        private void CompositionTarget_Rendering(object?sender, EventArgs e)
        {
            _d2DRenderTarget.BeginDraw();

            OnRender(_d2DRenderTarget);

            _d2DRenderTarget.EndDraw();

            D3DImage.Lock();

            D3DImage.AddDirtyRect(new Int32Rect(0, 0, D3DImage.PixelWidth, D3DImage.PixelHeight));

            D3DImage.Unlock();
        }
예제 #25
0
        public DrawingSurface()
        {
            _d3dImage = new D3DImage();

            _image = new Image {
                Source = _d3dImage, Stretch = Stretch.None
            };
            AddChild(_image);

            _d3dImage.IsFrontBufferAvailableChanged += OnD3DImageIsFrontBufferAvailableChanged;

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;
        }
예제 #26
0
        /// <summary>
        /// Creates new instance of Media Vault Library Control for WPF
        /// </summary>
        public MVPlayer()
        {
            InitializeComponent();

            if ((LicenseManager.UsageMode == LicenseUsageMode.Runtime))
            {
                if (!MV_Manager.IsInitialized)
                {
                    throw new InvalidOperationException("MediaVault library is not initialized! Call MV_Manager.InitilizeMediaVault() before using this control in runtime!");
                }

                if (MV_Manager.GetMVLibDLL() == null)
                {
                    throw new NullReferenceException("Unable to obtain loaded MVLib! Are you sure initialization was succeeded?");
                }

                Type mvlibWrapperType = null;

                foreach (Type type in MV_Manager.GetMVLibDLL().GetExportedTypes())
                {
                    if (type.Name == MVLIB_WRAPPER_TYPE)
                    {
                        mvlibWrapperType = type;
                        break;
                    }
                }

                if (mvlibWrapperType == null)
                {
                    throw new InvalidOperationException("Unable to find MVLibWrapper class in loaded assemblies! Check if you dependencies are correct!\nPlease visit https://github.com/Kuba-MV/MVLib-DotNet if you need to download additional dependencies!");
                }

                _media_wrapper = Activator.CreateInstance(mvlibWrapperType);

                if (_media_wrapper == null)
                {
                    throw new InvalidOperationException("Unable to create MVLibWrapper instance. Check if your dependencies are correct!");
                }

                _media_wrapper.CreateD3DOffScreenRenderer();

                _d3d_render = new D3DImage();
                _d3d_render.IsFrontBufferAvailableChanged += _d3d_render_IsFrontBufferAvailableChanged;

                videoImage.Source = _d3d_render;

                CompositionTarget.Rendering += CompositionTarget_Rendering;
            }
        }
        //Solution 1 Ori
        //[System.Runtime.InteropServices.DllImport("gdi32.dll")]
        //public static extern bool DeleteObject(IntPtr hObject);

        //Solution 2 Ori
        //public BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
        //{
        //    using (MemoryStream stream = new MemoryStream())
        //    {
        //        bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        //        stream.Position = 0;
        //        BitmapImage result = new BitmapImage();
        //        result.BeginInit();
        //        result.CacheOption = BitmapCacheOption.OnLoad;
        //        result.StreamSource = stream;
        //        result.EndInit();
        //        result.Freeze();
        //        return result;
        //    }
        //}

        // D3D Solution
        private void RenderD3D(IntPtr surface, D3DImage d3dImage)
        {
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                if (d3dImage.IsFrontBufferAvailable && surface != IntPtr.Zero)
                {
                    var showRect = new Int32Rect(0, 0, d3dImage.PixelWidth, d3dImage.PixelHeight);
                    d3dImage.Lock();
                    d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface);

                    d3dImage.AddDirtyRect(showRect);
                    d3dImage.Unlock();
                }
            }));
        }
예제 #28
0
        public DrawingSurface()
        {
            GraphicsProfile = GraphicsProfile.HiDef;
            AddChild(Image  = new Image()
            {
                Source = D3dImage = new D3DImage()
            });
            Image.Stretch = Stretch.None;
            Image.Source  = D3dImage = new D3DImage();
            D3dImage.IsFrontBufferAvailableChanged += new DependencyPropertyChangedEventHandler(D3dImage_IsFrontBufferAvailableChanged);

            SizeChanged += new SizeChangedEventHandler(DrawingSurface_SizeChanged);
            Loaded      += new RoutedEventHandler(DrawingSurface_Loaded);
            Unloaded    += new RoutedEventHandler(DrawingSurface_Unloaded);
        }
예제 #29
0
        public MainWindow()
        {
            InitializeComponent();

            visualizerImage = FindName("D3DImage") as D3DImage;

            visualizerHeight = (uint)visualizerImage.PixelHeight;
            visualizerWidth  = (uint)visualizerImage.PixelWidth;

            HRESULT.Check(SetSize(1024, 1024));
            HRESULT.Check(SetAlpha(false));
            HRESULT.Check(SetNumDesiredSamples(4));

            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
        }
예제 #30
0
        /// <summary>
        /// Invalidates the entire Direct3D image, notifying WPF to redraw
        /// </summary>
        protected void InternalInvalidateVideoImage()
        {
            /* Ensure we run on the correct Dispatcher */
            if (!D3DImage.Dispatcher.CheckAccess())
            {
                D3DImage.Dispatcher.BeginInvoke((Action)(() => InternalInvalidateVideoImage()));
                return;
            }

            /* If there is a new Surface to set,
             * this method will do the trick */
            SetBackBufferInternal(m_pBackBuffer);

            // may save a few AddDirtyRect calls when the rendering thread is too busy
            // or RenderOnCompositionTargetRendering is set but the video is not playing
            bool invalid = GetSetVideoImageInvalid(false);

            if (!invalid)
            {
                return;
            }

            /* Only render the video image if possible, or if IsRenderingEnabled is true */
            if (IsRenderingEnabled && m_pBackBuffer != IntPtr.Zero)
            {
                try
                {
                    if (!D3DImage.TryLock(InvalidateVideoImageLockDuration))
                    {
                        return;
                    }
                    /* Invalidate the entire image */
                    D3DImage.AddDirtyRect(new Int32Rect(0,                   /* Left */
                                                        0,                   /* Top */
                                                        D3DImage.PixelWidth, /* Width */
                                                        D3DImage.PixelHeight /* Height */));
                }
                catch (Exception)
                { }
                finally
                {
                    D3DImage.Unlock();
                }
            }

            /* Invalidate all of our cloned D3DRenderers */
            InvalidateClonedVideoImages();
        }