Fixes for better performance in some experimental code, also fixed some formatting in the code.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2287 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-11-15 14:11:00 +00:00
parent fa02394047
commit 75a841b31e
6 changed files with 72 additions and 24 deletions

View file

@ -183,6 +183,13 @@ namespace Greenshot.Forms {
// Toggle mouse cursor
capture.CursorVisible = !capture.CursorVisible;
Invalidate();
} else if (e.KeyCode == Keys.V) {
if (capture.CaptureDetails.CaptureMode != CaptureMode.Video) {
capture.CaptureDetails.CaptureMode = CaptureMode.Video;
} else {
capture.CaptureDetails.CaptureMode = captureMode;
}
Invalidate();
} else if (e.KeyCode == Keys.Z) {
// Toggle zoom
if (zoomForm == null) {
@ -400,7 +407,11 @@ namespace Greenshot.Forms {
if (mouseDown || captureMode == CaptureMode.Window) {
captureRect.Intersect(new Rectangle(Point.Empty, capture.ScreenBounds.Size)); // crop what is outside the screen
Rectangle fixedRect = new Rectangle( captureRect.X, captureRect.Y, captureRect.Width, captureRect.Height );
graphics.FillRectangle(GreenOverlayBrush, fixedRect);
if (capture.CaptureDetails.CaptureMode == CaptureMode.Video) {
graphics.FillRectangle(RedOverlayBrush, fixedRect);
} else {
graphics.FillRectangle(GreenOverlayBrush, fixedRect);
}
graphics.DrawRectangle(OverlayPen, fixedRect);
// rulers

View file

@ -180,8 +180,10 @@
<DependentUpon>MovableShowColorForm.cs</DependentUpon>
</Compile>
<None Include="App.config" />
<None Include="Helpers\AviHelper.cs" />
<Compile Include="Forms\ZoomForm.cs" />
<Compile Include="Helpers\AviHelper.cs" />
<Compile Include="Forms\ZoomForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Helpers\CaptureHelper.cs" />
<Compile Include="Helpers\Colors.cs" />
<Compile Include="Helpers\CopyData.cs" />
@ -203,7 +205,7 @@
<Compile Include="Memento\IMemento.cs" />
<Compile Include="Memento\DrawableContainerBoundsChangeMemento.cs" />
<Compile Include="Memento\SurfaceBackgroundChangeMemento.cs" />
<None Include="Helpers\ScreenCaptureHelper.cs" />
<Compile Include="Helpers\ScreenCaptureHelper.cs" />
<Compile Include="Helpers\UpdateHelper.cs" />
<Compile Include="Helpers\EnvironmentInfo.cs" />
<Compile Include="Helpers\GuiRectangle.cs" />

View file

@ -45,7 +45,7 @@ namespace Greenshot.Helpers {
public class CaptureHelper {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(CaptureHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
//private static ScreenCaptureHelper screenCapture = null;
private static ScreenCaptureHelper screenCapture = null;
private List<WindowDetails> windows = new List<WindowDetails>();
private WindowDetails selectedCaptureWindow = null;
private Rectangle captureRect = Rectangle.Empty;
@ -160,6 +160,12 @@ namespace Greenshot.Helpers {
/// Make Capture with specified destinations
/// </summary>
private void MakeCapture() {
// Experimental code
if (screenCapture != null) {
screenCapture.Stop();
screenCapture = null;
return;
}
// This fixes a problem when a balloon is still visible and a capture needs to be taken
// forcefully removes the balloon!
if (!conf.HideTrayicon) {
@ -892,6 +898,24 @@ namespace Greenshot.Helpers {
// windowDetailsThread.Join();
//}
// Experimental code for Video capture
if (capture.CaptureDetails.CaptureMode == CaptureMode.Video) {
if (captureForm.UsedCaptureMode == CaptureMode.Window) {
screenCapture = new ScreenCaptureHelper(selectedCaptureWindow);
} else if (captureForm.UsedCaptureMode == CaptureMode.Region) {
screenCapture = new ScreenCaptureHelper(captureRect);
}
if (screenCapture != null) {
screenCapture.RecordMouse = capture.CursorVisible;
if (screenCapture.Start(25)) {
return;
}
// User clicked cancel or a problem occured
screenCapture.Stop();
screenCapture = null;
return;
}
}
// Take the captureRect, this already is specified as bitmap coordinates
capture.Crop(captureRect);

View file

@ -44,7 +44,6 @@ namespace Greenshot.Helpers {
public class ScreenCaptureHelper {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ScreenCaptureHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private const int MAX_FRAMES = 500;
private const int ALIGNMENT = 8;
private IntPtr hWndDesktop = IntPtr.Zero;
private IntPtr hDCDesktop = IntPtr.Zero;
@ -63,11 +62,19 @@ namespace Greenshot.Helpers {
private Bitmap GDIBitmap;
private string filename = null;
private Stopwatch stopwatch = new Stopwatch();
private bool disabledDWM = false;
public ScreenCaptureHelper(Rectangle recordingRectangle) {
private ScreenCaptureHelper() {
if (DWM.isDWMEnabled()) {
// with DWM Composition disabled the capture goes ~2x faster
DWM.DisableComposition();
disabledDWM = true;
}
}
public ScreenCaptureHelper(Rectangle recordingRectangle) : this() {
this.recordingRectangle = recordingRectangle;
}
public ScreenCaptureHelper(WindowDetails recordingWindow) {
public ScreenCaptureHelper(WindowDetails recordingWindow) : this() {
this.recordingWindow = recordingWindow;
}
@ -111,14 +118,14 @@ namespace Greenshot.Helpers {
LOG.InfoFormat("Starting recording rectangle {0}", recordingRectangle);
recordingSize = recordingRectangle.Size;
}
if (recordingSize.Width % ALIGNMENT > 0) {
LOG.InfoFormat("Correcting width to be factor alignment, {0} => {1}", recordingSize.Width, recordingSize.Width + (ALIGNMENT - (recordingSize.Width % ALIGNMENT)));
recordingSize = new Size(recordingSize.Width + (ALIGNMENT - (recordingSize.Width % ALIGNMENT)), recordingSize.Height);
}
if (recordingSize.Height % ALIGNMENT > 0) {
LOG.InfoFormat("Correcting Height to be factor alignment, {0} => {1}", recordingSize.Height, recordingSize.Height + (ALIGNMENT - (recordingSize.Height % ALIGNMENT)));
recordingSize = new Size(recordingSize.Width, recordingSize.Height + (ALIGNMENT - (recordingSize.Height % ALIGNMENT)));
}
//if (recordingSize.Width % ALIGNMENT > 0) {
// LOG.InfoFormat("Correcting width to be factor alignment, {0} => {1}", recordingSize.Width, recordingSize.Width + (ALIGNMENT - (recordingSize.Width % ALIGNMENT)));
// recordingSize = new Size(recordingSize.Width + (ALIGNMENT - (recordingSize.Width % ALIGNMENT)), recordingSize.Height);
//}
//if (recordingSize.Height % ALIGNMENT > 0) {
// LOG.InfoFormat("Correcting Height to be factor alignment, {0} => {1}", recordingSize.Height, recordingSize.Height + (ALIGNMENT - (recordingSize.Height % ALIGNMENT)));
// recordingSize = new Size(recordingSize.Width, recordingSize.Height + (ALIGNMENT - (recordingSize.Height % ALIGNMENT)));
//}
this.framesPerSecond = framesPerSecond;
// "P/Invoke" Solution for capturing the screen
hWndDesktop = User32.GetDesktopWindow();
@ -162,7 +169,7 @@ namespace Greenshot.Helpers {
throw exceptionToThrow;
}
// Create a GDI Bitmap so we can use GDI and GDI+ operations on the same memory
GDIBitmap = new Bitmap(recordingSize.Width, recordingSize.Height, 32, PixelFormat.Format32bppArgb, bits0);
GDIBitmap = new Bitmap(recordingSize.Width, recordingSize.Height, 32, PixelFormat.Format32bppPArgb, bits0);
// select the bitmap object and store the old handle
hOldObject = GDI32.SelectObject(hDCDest, hDIBSection);
stop = false;
@ -202,7 +209,8 @@ namespace Greenshot.Helpers {
captureLocation = new Point(recordingRectangle.X, recordingRectangle.Y);
}
// "Capture"
GDI32.BitBlt(hDCDest, 0, 0, recordingSize.Width, recordingSize.Height, hDCDesktop, captureLocation.X, captureLocation.Y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
GDI32.BitBlt(hDCDest, 0, 0, recordingSize.Width, recordingSize.Height, hDCDesktop, captureLocation.X, captureLocation.Y, CopyPixelOperation.SourceCopy);
//GDI32.BitBlt(hDCDest, 0, 0, recordingSize.Width, recordingSize.Height, hDCDesktop, captureLocation.X, captureLocation.Y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
// Mouse
if (RecordMouse) {
@ -282,6 +290,10 @@ namespace Greenshot.Helpers {
aviWriter = null;
MessageBox.Show("Recording written to " + filename);
}
if (disabledDWM) {
DWM.EnableComposition();
}
}
}
}

View file

@ -609,7 +609,6 @@ namespace GreenshotPlugin.Core {
} else {
LOG.Debug("CaptureRectangle Called!");
}
// .NET GDI+ Solution, according to some post this has a GDI+ leak...
// See http://connect.microsoft.com/VisualStudio/feedback/details/344752/gdi-object-leak-when-calling-graphics-copyfromscreen
// Bitmap capturedBitmap = new Bitmap(captureBounds.Width, captureBounds.Height);
@ -697,7 +696,7 @@ namespace GreenshotPlugin.Core {
GDI32.DeleteObject(hDIBSection);
}
return returnBitmap;
}
return returnBitmap;
}
}
}

View file

@ -26,7 +26,7 @@ namespace Greenshot.Plugin {
/// <summary>
/// The capture mode for Greenshot
/// </summary>
public enum CaptureMode { None, Region, FullScreen, ActiveWindow, Window, LastRegion, Clipboard, File, IE, Import };
public enum CaptureMode { None, Region, FullScreen, ActiveWindow, Window, LastRegion, Clipboard, File, IE, Import, Video };
public enum ScreenCaptureMode { Auto, FullScreen, Fixed};
/// <summary>