Пример #1
0
        public void DrawItem(BluRayAPI.OSDTexture item)
        {
            try
            {
                lock (_syncObj)
                {
                    InitTexture(item);
                    if (_combinedOsdSurface != null)
                    {
                        Rectangle sourceRect = new Rectangle(0, 0, item.Width, item.Height);
                        Rectangle dstRect    = new Rectangle(item.X, item.Y, item.Width, item.Height);

                        using (Texture itemTexture = new Texture(item.Texture))
                            _device.StretchRectangle(itemTexture.GetSurfaceLevel(0), sourceRect, _combinedOsdSurface, dstRect, TextureFilter.None);
                    }
                }
            }
            catch (Exception ex)
            {
                BluRayPlayerBuilder.LogError(ex.ToString());
            }

            if (_onTextureInvalidated != null)
            {
                _onTextureInvalidated();
            }
        }
Пример #2
0
        /// <summary>
        /// Read back the data from the texture into a CPU buffer
        /// </summary>
        /// <param name="buffer"></param>
        public void ReadBack(byte[] buffer)
        {
            Stopwatch Timer = new Stopwatch();

            Timer.Start();
            try
            {
                FDevice.StretchRectangle(this.FTextureShared.GetSurfaceLevel(0), this.FTextureCopied.GetSurfaceLevel(0), TextureFilter.None);
                FDevice.GetRenderTargetData(this.FTextureCopied.GetSurfaceLevel(0), FSurfaceOffscreen);

                var rect = FSurfaceOffscreen.LockRectangle(LockFlags.ReadOnly);
                try
                {
                    rect.Data.Read(buffer, 0, buffer.Length);
                    FSurfaceOffscreen.UnlockRectangle();
                }
                catch (Exception e)
                {
                    FSurfaceOffscreen.UnlockRectangle();
                    throw;
                }
            }
            catch (Exception e)
            {
                FDevice.EndScene();
                throw;
            }
            Timer.Stop();
            Debug.Print(Timer.Elapsed.TotalMilliseconds.ToString());
        }
Пример #3
0
        protected override bool BeginRenderBrushOverride(PrimitiveBuffer primitiveContext, RenderContext renderContext)
        {
            ISlimDXVideoPlayer player;

            if (!GetPlayer(out player))
            {
                return(false);
            }

            if (!RefreshEffectParameters(player))
            {
                return(false);
            }

            lock (player.SurfaceLock)
            {
                Surface playerSurface = player.Surface;
                if (playerSurface == null)
                {
                    return(false);
                }
                DeviceEx           device      = SkinContext.Device;
                SurfaceDescription desc        = playerSurface.Description;
                SurfaceDescription?textureDesc = _texture == null ? new SurfaceDescription?() : _texture.GetLevelDescription(0);
                if (!textureDesc.HasValue || textureDesc.Value.Width != desc.Width || textureDesc.Value.Height != desc.Height)
                {
                    TryDispose(ref _texture);
                    _texture = new Texture(device, desc.Width, desc.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                }
                using (Surface target = _texture.GetSurfaceLevel(0))
                    device.StretchRectangle(playerSurface, target, TextureFilter.None);
            }
            return(_imageContext.StartRender(renderContext, _scaledVideoSize, _texture, _videoTextureClip, BorderColor.ToArgb(), _lastFrameData));
        }
Пример #4
0
        public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwSurface)
        {
            lock (_lock)
                if (dwSurface != IntPtr.Zero && cx != 0 && cy != 0)
                {
                    if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
                    {
                        _originalVideoSize = new Size(cx, cy);
                    }

                    _aspectRatio.Width  = arx;
                    _aspectRatio.Height = ary;

                    // We need to Dispose the created instance because SharpDX tracks all created objects. When the surface is disposed, it will get released
                    // on unmanaged side as well, that's why we set the dwSurface to IntPtr.Zero to avoid duplicated release (which leads to hard crashes).
                    using (Surface surf = new Surface(dwSurface))
                    {
                        SurfaceDescription surfaceDesc = _surface == null ? new SurfaceDescription() : _surface.Description;
                        SurfaceDescription surfDesc    = surf.Description;
                        if (surfaceDesc.Width != surfDesc.Width || surfaceDesc.Height != surfDesc.Height)
                        {
                            if (_surface != null)
                            {
                                _surface.Dispose();
                            }
                            _surface = Surface.CreateRenderTarget(_device, surfDesc.Width, surfDesc.Height, Format.A8R8G8B8, MultisampleType.None, 0, false);
                        }
                        _device.StretchRectangle(surf, _surface, TextureFilter.None);
                    }
                    // Clear pointer, surface was already released.
                    dwSurface = IntPtr.Zero;
                }

            VideoSizePresentDlgt vsp = VideoSizePresent;

            if (vsp != null)
            {
                vsp(this);
                VideoSizePresent = null;
            }

            // Inform caller that we have changed the texture
            if (_onTextureInvalidated != null)
            {
                _onTextureInvalidated();
            }

            if (_renderDlgt != null)
            {
                _renderDlgt();
            }

            return(0);
        }
Пример #5
0
        public int PresentSurface(short cx, short cy, short arx, short ary, uint dwSurface)
        {
            lock (_lock)
                if (dwSurface != 0 && cx != 0 && cy != 0)
                {
                    if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height)
                    {
                        _originalVideoSize = new Size(cx, cy);
                    }

                    _aspectRatio.Width  = arx;
                    _aspectRatio.Height = ary;

                    using (Surface surf = Surface.FromPointer(new IntPtr(dwSurface)))
                    {
                        SurfaceDescription surfaceDesc = _surface == null ? new SurfaceDescription() : _surface.Description;
                        SurfaceDescription surfDesc    = surf.Description;
                        if (surfaceDesc.Width != surfDesc.Width || surfaceDesc.Height != surfDesc.Height)
                        {
                            if (_surface != null)
                            {
                                _surface.Dispose();
                            }
                            _surface = Surface.CreateRenderTarget(_device, surfDesc.Width, surfDesc.Height, Format.A8R8G8B8, MultisampleType.None, 0, false);
                        }

                        _device.StretchRectangle(surf, _surface, TextureFilter.None);
                    }
                }

            VideoSizePresentDlgt vsp = VideoSizePresent;

            if (vsp != null)
            {
                vsp(this);
                VideoSizePresent = null;
            }

            // Inform caller that we have changed the texture
            if (_onTextureInvalidated != null)
            {
                _onTextureInvalidated();
            }

            if (_renderDlgt != null)
            {
                _renderDlgt();
            }

            return(0);
        }
        protected static Texture CreateTextureCopy(Texture sourceTexture, out SizeF textureSize)
        {
            if (sourceTexture == null)
            {
                textureSize = new SizeF();
                return(null);
            }
            SurfaceDescription desc = sourceTexture.GetLevelDescription(0);

            textureSize = new SizeF(desc.Width, desc.Height);
            DeviceEx device = SkinContext.Device;
            Texture  result = new Texture(device, desc.Width, desc.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Default);

            using (Surface target = result.GetSurfaceLevel(0))
                using (Surface source = sourceTexture.GetSurfaceLevel(0))
                    device.StretchRectangle(source, target, TextureFilter.None);
            return(result);
        }
Пример #7
0
        public void ProcessSample(Sample srcSample)
        {
            using (var srcBuffer = srcSample.ConvertToContiguousBuffer())
            {
                MediaFactory.GetService(srcBuffer, MediaServiceKeys.Buffer, IID.D3D9Surface, out var pSurf);

                using (SharpDX.Direct3D9.Surface srcSurf = new SharpDX.Direct3D9.Surface(pSurf))
                {
                    device.StretchRectangle(srcSurf, surface, SharpDX.Direct3D9.TextureFilter.Linear);

                    //var data = surface.LockRectangle(LockFlags.ReadOnly);

                    //TestTools.WriteFile(data.DataPointer, 3133440, @"d:\test.raw");

                    //surface.UnlockRectangle();
                }
            }
        }
        public override void Render(RenderContext parentRenderContext)
        {
            Effect effect = Effect;

            if (!IsVisible || effect == null)
            {
                return;
            }

            RectangleF bounds = ActualBounds;

            if (bounds.Width <= 0 || bounds.Height <= 0)
            {
                return;
            }

            Matrix?layoutTransformMatrix = LayoutTransform == null ? new Matrix?() : LayoutTransform.GetTransform();
            Matrix?renderTransformMatrix = RenderTransform == null ? new Matrix?() : RenderTransform.GetTransform();

            RenderContext localRenderContext = parentRenderContext.Derive(bounds, layoutTransformMatrix, renderTransformMatrix, RenderTransformOrigin, Opacity);

            _inverseFinalTransform = Matrix.Invert(localRenderContext.Transform);

            DeviceEx           device      = SkinContext.Device;
            Surface            backBuffer  = device.GetRenderTarget(0);
            SurfaceDescription desc        = backBuffer.Description;
            SurfaceDescription?textureDesc = _texture == null ? new SurfaceDescription?() : _texture.GetLevelDescription(0);

            if (!textureDesc.HasValue || textureDesc.Value.Width != desc.Width || textureDesc.Value.Height != desc.Height)
            {
                TryDispose(ref _texture);
                _texture = new Texture(device, desc.Width, desc.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            }
            using (Surface destSurfaceRef = _texture.GetSurfaceLevel(0))
                device.StretchRectangle(backBuffer, destSurfaceRef, TextureFilter.None);

            UpdateEffectMask(effect, localRenderContext.OccupiedTransformedBounds, desc.Width, desc.Height, localRenderContext.ZOrder);
            if (effect.BeginRender(_texture, new RenderContext(Matrix.Identity, 1.0d, bounds, localRenderContext.ZOrder)))
            {
                _effectContext.Render(0);
                effect.EndRender();
            }
            backBuffer.Dispose();
        }
Пример #9
0
        /// <summary>
        /// Copies the content of the specified texture.
        /// </summary>
        /// <param name="source">The source surface.</param>
        /// <param name="target">The target surface.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source"/> or <paramref name="target"/> is <see langword="null"/>.
        /// </exception>
        public void Copy(Surface source, Surface target)
        {
            ThrowIfDisposed();

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            int width     = Math.Min(source.Description.Width, target.Description.Width);
            int height    = Math.Min(source.Description.Height, target.Description.Height);
            var rectangle = new Rectangle(0, 0, width, height);

            _device.StretchRectangle(source, rectangle, target, rectangle, TextureFilter.None);
        }
Пример #10
0
        protected override bool BeginRenderBrushOverride(PrimitiveBuffer primitiveContext, RenderContext renderContext)
        {
            ISharpDXVideoPlayer player;

            if (!GetPlayer(out player))
            {
                return(false);
            }

            if (!RefreshEffectParameters(player))
            {
                return(false);
            }

            lock (player.SurfaceLock)
            {
                Surface playerSurface = player.Surface;
                if (playerSurface == null)
                {
                    return(false);
                }
                DeviceEx           device      = SkinContext.Device;
                SurfaceDescription desc        = playerSurface.Description;
                SurfaceDescription?textureDesc = _texture == null ? new SurfaceDescription?() : _texture.GetLevelDescription(0);
                if (!textureDesc.HasValue || textureDesc.Value.Width != desc.Width || textureDesc.Value.Height != desc.Height)
                {
                    TryDispose(ref _texture);
                    _texture = new Texture(device, desc.Width, desc.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                }
                using (Surface target = _texture.GetSurfaceLevel(0))
                    device.StretchRectangle(playerSurface, target, TextureFilter.None);
            }

            // Handling of multipass (3D) rendering, transformed rect contains the clipped area of the source image (i.e. left side in Side-By-Side mode).
            RectangleF tranformedRect;

            GraphicsDevice.RenderPipeline.GetVideoClip(_videoTextureClip, out tranformedRect);
            return(_imageContext.StartRender(renderContext, _scaledVideoSize, _texture, tranformedRect, BorderColor, _lastFrameData));
        }