예제 #1
0
        public void GetNextFrame()
        {
            try
            {
                if (NeedsInit)
                {
                    Logger.Write("Init needed in DXCapture.  Switching desktops.");
                    if (Win32Interop.SwitchToInputDesktop())
                    {
                        Win32Interop.GetCurrentDesktop(out var desktopName);
                        Logger.Write($"Switch to desktop {desktopName} after capture error in DXCapture.");
                    }
                    Init();
                }

                Win32Interop.SwitchToInputDesktop();

                PreviousFrame?.Dispose();
                PreviousFrame = (Bitmap)CurrentFrame.Clone();

                if (directxScreens.ContainsKey(SelectedScreen))
                {
                    GetDirectXFrame();
                }
                else
                {
                    GetBitBltFrame();
                }
            }
            catch (Exception e)
            {
                Logger.Write(e);
                NeedsInit = true;
            }
        }
예제 #2
0
        public void Dispose()
        {
            SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
            ClearDirectXOutputs();

            CurrentFrame?.Dispose();
            PreviousFrame?.Dispose();
        }
예제 #3
0
 public void Dispose()
 {
     duplicatedOutput?.Dispose();
     output1?.Dispose();
     output?.Dispose();
     device?.Dispose();
     adapter?.Dispose();
     factory?.Dispose();
     CurrentFrame?.Dispose();
     PreviousFrame?.Dispose();
 }
        public void Dispose()
        {
            if (_isRetainPreviousFrame)
            {
                PreviousFrame.Dispose();
            }

            Graphic.Dispose();
            CurrentFrame.Dispose();
            _originBitmap.Dispose();
        }
예제 #5
0
 public void GetNextFrame()
 {
     try
     {
         PreviousFrame?.Dispose();
         PreviousFrame = (Bitmap)CurrentFrame.Clone();
         RefreshCurrentFrame();
     }
     catch (Exception ex)
     {
         Logger.Write(ex);
         Init();
     }
 }
예제 #6
0
        /// <summary>
        /// The state engine controller. this method sets all of the boolean values to allow for description of the frame's game state.
        /// </summary>
        public override void HandleFrameStatus()
        {
            if (!IsScoringComplete)
            {
                if (null != PreviousFrame && !PreviousFrame.IsScoringComplete)
                {
                    //Update the previous frame
                    PreviousFrame.HandleFrameStatus();
                }
                else
                {
                    IsPreviousFrameScored = true;
                }

                if (BallScores.Count == 3)
                {
                    IsClosed            = IsSpare(BallScores) || BallScores[0].IsStrike();
                    IsReadyForNextFrame = true;
                    IsReadyToScore      = NextTwoFrames.Count == 0 || (NextTwoFrames.Count > 0 && IsClosed && NextTwoBallsBowled());
                }
                //handle frame status on second ball
                if (BallScores.Count == 2)
                {
                    IsClosed            = false;
                    IsReadyForNextFrame = !BallScores[0].IsStrike() && !IsSpare(BallScores);
                    IsReadyToScore      = (IsPreviousFrameScored && IsReadyForNextFrame);
                }
                //handle frame status on first ball
                else if (BallScores.Count == 1)
                {
                    bool isStrikeOnFault = (BallScores[0].IsFault() && LostPinsByFault == Constant.NUMBER_OF_PINS);
                    IsClosed            = false;
                    IsReadyForNextFrame = (isStrikeOnFault);
                    IsReadyToScore      = (IsPreviousFrameScored && IsReadyForNextFrame);
                }

                if (IsReadyToScore)
                {
                    CalculateScore();
                    IsScoringComplete = true;
                }
            }
            else
            {
                IsPreviousFrameScored = true;
            }
        }
예제 #7
0
 private void GetBitBltFrame()
 {
     try
     {
         Win32Interop.SwitchToInputDesktop();
         PreviousFrame.Dispose();
         PreviousFrame = (Bitmap)CurrentFrame.Clone();
         Graphic.CopyFromScreen(CurrentScreenBounds.Left, CurrentScreenBounds.Top, 0, 0, new Size(CurrentScreenBounds.Width, CurrentScreenBounds.Height));
     }
     catch (Exception ex)
     {
         Logger.Write(ex);
         Logger.Write("Capturer error.  Trying to switch desktops in BitBltCapture.");
         if (Win32Interop.SwitchToInputDesktop())
         {
             Win32Interop.GetCurrentDesktop(out var desktopName);
             Logger.Write($"Switch to desktop {desktopName} after capture error in BitBltCapture.");
         }
         NeedsInit = true;
     }
 }
예제 #8
0
 public void Dispose()
 {
     Graphic.Dispose();
     CurrentFrame.Dispose();
     PreviousFrame.Dispose();
 }
예제 #9
0
 public void Dispose()
 {
     CurrentFrame.Dispose();
     PreviousFrame.Dispose();
 }
예제 #10
0
        public void GetNextFrame()
        {
            try
            {
                if (NeedsInit)
                {
                    Logger.Write("Init needed in DXCapture.  Switching desktops.");
                    if (Win32Interop.SwitchToInputDesktop())
                    {
                        Win32Interop.GetCurrentDesktop(out var desktopName);
                        Logger.Write($"Switch to desktop {desktopName} after capture error in DXCapture.");
                    }

                    Init();
                }

                PreviousFrame.Dispose();
                PreviousFrame = (Bitmap)CurrentFrame.Clone();

                Resource screenResource;
                OutputDuplicateFrameInformation duplicateFrameInformation;

                // Try to get duplicated frame within given time is ms
                var result =
                    duplicatedOutput.TryAcquireNextFrame(100, out duplicateFrameInformation, out screenResource);

                if (result.Failure && result.Code != ResultCode.WaitTimeout.Code)
                {
                    Logger.Write($"TryAcquireFrame error.  Code: {result.Code}");
                    NeedsInit = true;
                    return;
                }


                if (duplicateFrameInformation.AccumulatedFrames == 0)
                {
                    try
                    {
                        duplicatedOutput.ReleaseFrame();
                    }
                    catch
                    {
                    }

                    return;
                }

                // TODO: Get dirty rects.
                //RawRectangle[] dirtyRectsBuffer = new RawRectangle[duplicateFrameInformation.TotalMetadataBufferSize];
                //duplicatedOutput.GetFrameDirtyRects(duplicateFrameInformation.TotalMetadataBufferSize, dirtyRectsBuffer, out var dirtyRectsSizeRequired);


                // copy resource into memory that can be accessed by the CPU
                using (var screenTexture2D = screenResource.QueryInterface <Texture2D>())
                {
                    device.ImmediateContext.CopyResource(screenTexture2D, screenTexture);
                }

                // Get the desktop capture texture
                var mapSource = device.ImmediateContext.MapSubresource(screenTexture, 0, MapMode.Read, MapFlags.None);

                var boundsRect = new Rectangle(0, 0, width, height);

                // Copy pixels from screen capture Texture to GDI bitmap
                var mapDest   = CurrentFrame.LockBits(boundsRect, ImageLockMode.WriteOnly, CurrentFrame.PixelFormat);
                var sourcePtr = mapSource.DataPointer;
                var destPtr   = mapDest.Scan0;
                for (var y = 0; y < height; y++)
                {
                    // Copy a single line
                    Utilities.CopyMemory(destPtr, sourcePtr, width * 4);

                    // Advance pointers
                    sourcePtr = IntPtr.Add(sourcePtr, mapSource.RowPitch);
                    destPtr   = IntPtr.Add(destPtr, mapDest.Stride);
                }

                // Release source and dest locks
                CurrentFrame.UnlockBits(mapDest);
                device.ImmediateContext.UnmapSubresource(screenTexture, 0);

                screenResource.Dispose();
                duplicatedOutput.ReleaseFrame();
            }
            catch (SharpDXException e)
            {
                if (e.ResultCode.Code != ResultCode.WaitTimeout.Result.Code)
                {
                    Logger.Write(e);
                    NeedsInit = true;
                }
            }
            catch (Exception e)
            {
                Logger.Write(e);
                NeedsInit = true;
            }
        }