Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge the Windows-specific files into their formerly cross-platform c…
…ounterparts.
  • Loading branch information
teo-tsirpanis committed Apr 19, 2022
commit 21d4509e19da1883ed52b4c56b9855f52f8ba314
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DefineConstants>$(DefineConstants);DRAWING_NAMESPACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down Expand Up @@ -204,47 +204,30 @@ Since .NET 7, non-Windows platforms are not supported. See https://aka.ms/system
<!-- Windows-specific -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
<Compile Include="SRDescriptionAttribute.cs" />
<Compile Include="System\Drawing\Bitmap.Windows.cs" />
<Compile Include="System\Drawing\BitmapSelector.cs" />
<Compile Include="System\Drawing\BufferedGraphics.Windows.cs" />
<Compile Include="System\Drawing\BufferedGraphicsContext.Windows.cs" />
<Compile Include="System\Drawing\BufferedGraphicsManager.Windows.cs" />
<Compile Include="System\Drawing\Drawing2D\CustomLineCap.Windows.cs" />
<Compile Include="System\Drawing\Drawing2D\GraphicsPath.Windows.cs" />
<Compile Include="System\Drawing\BufferedGraphicsManager.cs" />
<Compile Include="System\Drawing\Drawing2D\GraphicsPath.cs" />
<Compile Include="System\Drawing\DrawingCom.cs" />
<Compile Include="System\Drawing\Font.Windows.cs" />
<Compile Include="System\Drawing\FontFamily.Windows.cs" />
<Compile Include="System\Drawing\GdiplusNative.Windows.cs" />
<Compile Include="System\Drawing\Graphics.Windows.cs" />
<Compile Include="System\Drawing\GraphicsContext.cs" />
<Compile Include="System\Drawing\Icon.Windows.cs" />
<Compile Include="System\Drawing\Image.Windows.cs" />
<Compile Include="System\Drawing\Imaging\BitmapData.Windows.cs" />
<Compile Include="System\Drawing\Imaging\Metafile.Windows.cs" />
<Compile Include="System\Drawing\Imaging\MetafileHeader.Windows.cs" />
<Compile Include="System\Drawing\Imaging\MetaHeader.Windows.cs" />
<Compile Include="System\Drawing\Icon.cs" />
<Compile Include="System\Drawing\Imaging\MetafileHeader.cs" />
<Compile Include="System\Drawing\Imaging\MetaHeader.cs" />
<Compile Include="System\Drawing\Internal\GpPathData.cs" />
<Compile Include="System\Drawing\Internal\GPStream.cs" />
<Compile Include="System\Drawing\Internal\SystemColorTracker.cs" />
<Compile Include="System\Drawing\LocalAppContextSwitches.Windows.cs" />
<Compile Include="System\Drawing\Pen.Windows.cs" />
<Compile Include="System\Drawing\Printing\DefaultPrintController.cs" />
<Compile Include="System\Drawing\Printing\ModeField.cs" />
<Compile Include="System\Drawing\Printing\PageSettings.Windows.cs" />
<Compile Include="System\Drawing\Printing\PreviewPrintController.Windows.cs" />
<Compile Include="System\Drawing\Printing\PrintController.Windows.cs" />
<Compile Include="System\Drawing\Printing\PrintDocument.Windows.cs" />
<Compile Include="System\Drawing\Printing\PrinterSettings.Windows.cs" />
<Compile Include="System\Drawing\Printing\PrintEventArgs.Windows.cs" />
<Compile Include="System\Drawing\Printing\PrintPageEventArgs.Windows.cs" />
<Compile Include="System\Drawing\Printing\PageSettings.cs" />
<Compile Include="System\Drawing\Printing\PrintDocument.cs" />
<Compile Include="System\Drawing\Printing\PrinterSettings.cs" />
<Compile Include="System\Drawing\Printing\PrintEventArgs.cs" />
<Compile Include="System\Drawing\Printing\PrintPageEventArgs.cs" />
<Compile Include="System\Drawing\Printing\PrintPreviewGraphics.cs" />
<Compile Include="System\Drawing\Printing\TriState.cs" />
<Compile Include="System\Drawing\Region.Windows.cs" />
<Compile Include="System\Drawing\ScreenDC.cs" />
<Compile Include="System\Drawing\SystemFonts.Windows.cs" />
<Compile Include="System\Drawing\SystemIcons.Windows.cs" />
<Compile Include="System\Drawing\SystemIcons.cs" />
<Compile Include="System\Drawing\ToolboxBitmapAttribute.cs" />
<Compile Include="System\Drawing\Text\PrivateFontCollection.Windows.cs" />
<Compile Include="misc\DbgUtil.cs" />
<Compile Include="misc\DpiHelper.cs" />
<Compile Include="misc\GDI\ApplyGraphicsProperties.cs" />
Expand Down Expand Up @@ -333,14 +316,14 @@ Since .NET 7, non-Windows platforms are not supported. See https://aka.ms/system
<Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.IStream.COMWrappers.cs"
Link="Common\Interop\Windows\Ole32\Interop.IStream.COMWrappers.cs" />
<Compile Include="System\Drawing\DrawingCom.COMWrappers.cs" />
<Compile Include="System\Drawing\Icon.Windows.COMWrappers.cs" />
<Compile Include="System\Drawing\Icon.COMWrappers.cs" />
<Compile Include="System\Drawing\Internal\GPStream.COMWrappers.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true' and '$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="$(CommonPath)Interop\Windows\Ole32\Interop.IStream.NoCOMWrappers.cs"
Link="Common\Interop\Windows\Ole32\Interop.IStream.NoCOMWrappers.cs" />
<Compile Include="System\Drawing\DrawingCom.NoCOMWrappers.cs" />
<Compile Include="System\Drawing\Icon.Windows.NoCOMWrappers.cs" />
<Compile Include="System\Drawing\Icon.NoCOMWrappers.cs" />
<Compile Include="System\Drawing\Internal\GPStream.NoCOMWrappers.cs" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0')) and '$(TargetsAnyOS)' != 'true'">
Expand Down

This file was deleted.

23 changes: 22 additions & 1 deletion src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.ComponentModel;
using System.Drawing.Imaging;
using System.Drawing.Internal;
using System.IO;
using System.Runtime.InteropServices;
using Gdip = System.Drawing.SafeNativeMethods.Gdip;
Expand All @@ -14,7 +15,7 @@ namespace System.Drawing
"System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public sealed partial class Bitmap : Image
public sealed class Bitmap : Image
{
private static readonly Color s_defaultTransparentColor = Color.LightGray;

Expand Down Expand Up @@ -53,6 +54,26 @@ public Bitmap(Stream stream) : this(stream, false)
{
}

public unsafe Bitmap(Stream stream!!, bool useIcm)
{
using DrawingCom.IStreamWrapper streamWrapper = DrawingCom.GetComWrapper(new GPStream(stream));

IntPtr bitmap = IntPtr.Zero;
if (useIcm)
{
Gdip.CheckStatus(Gdip.GdipCreateBitmapFromStreamICM(streamWrapper.Ptr, &bitmap));
}
else
{
Gdip.CheckStatus(Gdip.GdipCreateBitmapFromStream(streamWrapper.Ptr, &bitmap));
}

ValidateImage(bitmap);

SetNativeImage(bitmap);
EnsureSave(this, null, stream);
}

public Bitmap(Type type, string resource) : this(GetResourceStream(type, resource))
{
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,99 @@ namespace System.Drawing
/// buffer is locked. The general design is such that under normal conditions a single BufferedGraphics will be in
/// use at one time for a given BufferedGraphicsContext.
/// </summary>
public sealed partial class BufferedGraphics : IDisposable
public sealed class BufferedGraphics : IDisposable
{
private Graphics? _targetGraphics;
private readonly IntPtr _targetDC;
private Graphics _bufferedGraphicsSurface;
private BufferedGraphicsContext _context;
private readonly Point _targetLoc;
private readonly Size _virtualSize;

/// <summary>
/// Internal constructor, this class is created by BufferedGraphicsContext.
/// </summary>
internal BufferedGraphics(Graphics bufferedGraphicsSurface, BufferedGraphicsContext context, Graphics? targetGraphics,
IntPtr targetDC, Point targetLoc, Size virtualSize)
{
_context = context;
_bufferedGraphicsSurface = bufferedGraphicsSurface;
_targetDC = targetDC;
_targetGraphics = targetGraphics;
_targetLoc = targetLoc;
_virtualSize = virtualSize;
}

public void Dispose()
{
if (_context != null)
{
_context.ReleaseBuffer(this);

if (DisposeContext)
{
_context.Dispose();
_context = null!;
}
}

if (_bufferedGraphicsSurface != null)
{
_bufferedGraphicsSurface.Dispose();
_bufferedGraphicsSurface = null!;
}
}

/// <summary>
/// Allows access to the Graphics wrapper for the buffer.
/// </summary>
public Graphics Graphics => _bufferedGraphicsSurface;

/// <summary>
/// Renders the buffer to the specified target graphics.
/// </summary>
public void Render(Graphics? target)
{
if (target != null)
{
IntPtr targetDC = target.GetHdc();

try
{
RenderInternal(new HandleRef(target, targetDC));
}
finally
{
target.ReleaseHdcInternal(targetDC);
}
}
}

/// <summary>
/// Internal method that renders the specified buffer into the target.
/// </summary>
private void RenderInternal(HandleRef refTargetDC)
{
IntPtr sourceDC = Graphics.GetHdc();

try
{
Interop.Gdi32.BitBlt(
refTargetDC,
_targetLoc.X,
_targetLoc.Y,
_virtualSize.Width,
_virtualSize.Height,
new HandleRef(Graphics, sourceDC),
0,
0,
Interop.Gdi32.RasterOp.SRCCOPY);
}
finally
{
Graphics.ReleaseHdcInternal(sourceDC);
}
}

/// <summary>
/// Determines if we need to dispose of the Context when this is disposed.
Expand Down
Loading