private bool disposedValue = false; // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 释放托管状态(托管对象)。
                    factory.Dispose();
                    adapter.Dispose();
                    device.Dispose();
                    output.Dispose();
                    output1.Dispose();
                    screenTexture.Dispose();
                }

                // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
                // TODO: 将大型字段设置为 null。
                factory       = null;
                adapter       = null;
                device        = null;
                output        = null;
                output1       = null;
                screenTexture = null;

                disposedValue = true;
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        /// <summary>
        ///   Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources
        /// </summary>
        public void Dispose()
        {
            // release resources
            Alive = false;

            Duplication.Dispose();
            Duplication = null;

            Output.Dispose();
            Output = null;

            Output1?.Dispose();
            Output1 = null;

            Output6?.Dispose();
            Output6 = null;

            DxgiDevice.Dispose();
            DxgiDevice = null;

            Device.Dispose();
            Device = null;

            Texture.Dispose();
            Texture = null;

            Adapter1.Dispose();
            Adapter1 = null;
        }
Beispiel #3
0
 protected virtual void Dispose(bool disposing)
 {
     DestroyOutputDuplicator();
     screenTexture?.Dispose();
     screen?.Dispose();
     output?.Dispose();
     device?.Dispose();
     adapter?.Dispose();
     factory?.Dispose();
 }
 public override void Dispose()
 {
     _adapter?.Dispose();
     _device?.Dispose();
     _output?.Dispose();
     _output1?.Dispose();
     _screenTexture?.Dispose();
     _duplicatedOutput?.Dispose();
     base.Dispose();
 }
 /// <summary>
 /// Dispose all
 /// </summary>
 public void close()
 {
     duplicatedOutput.Dispose();
     screenTexture.Dispose();
     output1.Dispose();
     output.Dispose();
     device.Dispose();
     adapter.Dispose();
     factory.Dispose();
 }
Beispiel #6
0
 private void Cleanup()
 {
     _duplicatedOutput?.Dispose();
     _screenTexture?.Dispose();
     _output1?.Dispose();
     _output?.Dispose();
     _device?.Dispose();
     _adapter?.Dispose();
     _factory?.Dispose();
 }
Beispiel #7
0
 public void Dispose()
 {
     duplicatedOutput?.Dispose();
     output1?.Dispose();
     output?.Dispose();
     device?.Dispose();
     adapter?.Dispose();
     factory?.Dispose();
     CurrentFrame?.Dispose();
     PreviousFrame?.Dispose();
 }
 public void Disposer()
 {
     _device.Dispose();
     _output1.Dispose();
     _texture2D.Dispose();
     _outputDuplication.Dispose();
     //_textureDescription.Dispose();
     _bitmap.Dispose();
     _bitmapPlayerRect.Dispose();
     _screenResource.Dispose();
     //_frameCaptureData.Dispose();
     GC.Collect();
 }
Beispiel #9
0
 /// <inheritdoc />
 /// <summary>
 ///   Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources
 /// </summary>
 public void Dispose()
 {
     // release resources
     Duplication.Dispose();
     Output.Dispose();
     Output1?.Dispose();
     Output6?.Dispose();
     Context.Dispose();
     DxgiDevice.Dispose();
     Device.Dispose();
     Texture.Dispose();
     Adapter1.Dispose();
 }
 public void Dispose()
 {
     _duplicatedOutput?.Dispose();
     _output1?.Dispose();
     _output?.Dispose();
     _stagingTexture?.Dispose();
     _smallerTexture?.Dispose();
     _smallerTextureView?.Dispose();
     _device?.Dispose();
     _adapter?.Dispose();
     _factory?.Dispose();
     _lastCapturedFrame = null;
     _disposed          = true;
 }
Beispiel #11
0
 public void Dispose()
 {
     try
     {
         // If there are any errors, that means the items are disposed or not yet newed up. We should be fine moving on.
         Texture.Dispose();
         OutputDuplication.Dispose();
         _output1.ReleaseOwnership();
         _output.ReleaseOwnership();
         _output1.Dispose();
         _output.Dispose();
         Device.Dispose();
         _adapter.Dispose();
         _factory.Dispose();
     }
     catch
     {
     }
 }
Beispiel #12
0
        public void Dispose()
        {
            if (pinnedMemBuffer.IsAllocated)
            {
                pinnedMemBuffer.Free();
            }

            TryReleaseFrame();
            if (Settings.SettingsHwnd != IntPtr.Zero)  // restore window background color
            {
                try {
                    device?.ImmediateContext.ClearRenderTargetView(renderTarget, SharpDX.Color.WhiteSmoke);
                    renderWindow?.Present(0, PresentFlags.None);
                } catch { }
            }

            Settings.Model.PropertyChanged -= LedsChanged;
            fpsCounter?.Dispose();
            fpsColor?.Dispose();
            fpsFont?.Dispose();
            renderOverlay?.Dispose();
            renderTarget?.Dispose();
            renderTexture?.Dispose();
            renderWindow?.Dispose();

            try {
                device?.ImmediateContext?.ClearState();
                device?.ImmediateContext?.Flush();
                device?.ImmediateContext?.Dispose();
            } catch { }

            adapter?.Dispose();
            output?.Dispose();
            device?.Dispose();
            duplicator?.Dispose();
            capture?.Dispose();
            scaler?.Dispose();
            gpuTexture?.Dispose();
            cpuTexture?.Dispose();
        }
        /// <summary>
        /// Changes the capture settings.
        /// </summary>
        /// <param name="newSettings">The new settings.</param>
        /// <returns></returns>
        public HRESULT ChangeCaptureSettings(CaptureSettings newSettings)
        {
            lock (m_Filter.FilterLock)
            {
                if (m_Filter.IsActive)
                {
                    return(VFW_E_WRONG_STATE);
                }

                m_CaptureSettings = newSettings;

                if (m_Adapter != null)
                {
                    m_Adapter.Dispose();
                }
                m_Adapter = m_Factory.GetAdapter1(m_CaptureSettings.m_Adapter);

                if (m_Adapter == null)
                {
                    return(E_POINTER);
                }

                if (m_Device != null)
                {
                    m_Device.Dispose();
                }
                m_Device = new Device(m_Adapter);

                if (m_Device == null)
                {
                    return(E_POINTER);
                }

                if (m_Output != null)
                {
                    m_Output.Dispose();
                }
                m_Output = m_Adapter.GetOutput(m_CaptureSettings.m_Output).QueryInterface <Output1>();

                if (m_Output == null)
                {
                    return(E_POINTER);
                }

                Texture2DDescription textureDesc = new Texture2DDescription
                {
                    CpuAccessFlags    = CpuAccessFlags.Read,
                    BindFlags         = BindFlags.None,
                    Format            = Format.B8G8R8A8_UNorm,
                    Width             = m_nWidth,
                    Height            = m_nHeight,
                    OptionFlags       = ResourceOptionFlags.None,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    SampleDescription = { Count = 1, Quality = 0 },
                    Usage             = ResourceUsage.Staging
                };

                if (m_ScreenTexture != null)
                {
                    m_ScreenTexture.Dispose();
                }
                m_ScreenTexture = new Texture2D(m_Device, textureDesc);

                if (m_ScreenTexture == null)
                {
                    return(E_POINTER);
                }

                if (m_DuplicatedOutput != null)
                {
                    m_DuplicatedOutput.Dispose();
                }
                m_DuplicatedOutput = m_Output.DuplicateOutput(m_Device);

                if (m_DuplicatedOutput == null)
                {
                    return(E_POINTER);
                }

                return((HRESULT)ReconnectPin());
            }
        }