Ejemplo n.º 1
0
 public void ReleaseFrame(ILogger logger)
 {
     try
     {
         _outputDuplication.ReleaseFrame();
     }
     catch (SharpGenException ex)
     {
         if (ex.ResultCode.Failure)
         {
             logger.LogWarning($"Failed to release frame: {ex.Descriptor.Description}");
         }
     }
 }
        public override void Update(double deltaTime)
        {
            IDXGIResource    screenResource;
            OutduplFrameInfo frameInfo;

            try
            {
                if (release)
                {
                    duplication.ReleaseFrame();
                    release = false;
                }

                duplication.AcquireNextFrame(500, out frameInfo, out screenResource);

                using (var tempTexture = screenResource.QueryInterface <ID3D11Texture2D>())
                    device.ImmediateContext.CopySubresourceRegion(smallerTexture, 0, 0, 0, 0, tempTexture, 0);

                device.ImmediateContext.GenerateMips(smallerTextureView);
                device.ImmediateContext.CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, smallerTexture, 1);

                var dataBox = device.ImmediateContext.Map(stagingTexture, 0, MapMode.Read, Vortice.Direct3D11.MapFlags.None);

                ProcessDataIntoSKPixmap(dataBox);

                device.ImmediateContext.Unmap(stagingTexture, 0);

                screenResource.Dispose();
                release = true;
                //duplication.ReleaseFrame();
            }
            catch (SharpGen.Runtime.SharpGenException e)
            {
                if (e.ResultCode == Vortice.DXGI.ResultCode.AccessLost)
                {
                    StartDesktopDuplicator(0, 0);
                }
                else if (e.ResultCode == Vortice.DXGI.ResultCode.WaitTimeout)
                {
                    //ignore
                }
                else
                {
                }
                //throw;
            }
        }