Improve D2D1 types generation and other helper methods.

This commit is contained in:
Amer Koleci
2022-12-06 10:57:28 +01:00
parent a67fab7cae
commit c1d457d5fd
56 changed files with 733 additions and 508 deletions

View File

@@ -2,10 +2,10 @@
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using System.Drawing;
using static Win32.Apis;
using Win32.Graphics.Direct2D.Common;
using Win32.Graphics.Imaging;
using Win32.Numerics;
using static Win32.Apis;
using static Win32.Graphics.Direct2D.Apis;
namespace Win32.Graphics.Direct2D;
@@ -114,7 +114,7 @@ public unsafe partial struct ID2D1DeviceContext
public void DrawImage(
ID2D1Effect* effect,
PointF* targetOffset = null,
Vector2* targetOffset = null,
Common.RectF* imageRectangle = null,
InterpolationMode interpolationMode = InterpolationMode.Linear,
CompositeMode compositeMode = CompositeMode.SourceOver)
@@ -142,7 +142,7 @@ public unsafe partial struct ID2D1DeviceContext
}
public void DrawImage(ID2D1Image* image,
PointF targetOffset,
Vector2 targetOffset,
InterpolationMode interpolationMode = InterpolationMode.Linear,
CompositeMode compositeMode = CompositeMode.SourceOver)
{
@@ -150,7 +150,7 @@ public unsafe partial struct ID2D1DeviceContext
}
public void DrawImage(ID2D1Effect* effect,
PointF targetOffset,
Vector2 targetOffset,
InterpolationMode interpolationMode = InterpolationMode.Linear,
CompositeMode compositeMode = CompositeMode.SourceOver)
{
@@ -158,7 +158,7 @@ public unsafe partial struct ID2D1DeviceContext
}
public void DrawImage(ID2D1Image* image,
PointF targetOffset,
Vector2 targetOffset,
Common.RectF* imageRectangle,
InterpolationMode interpolationMode = InterpolationMode.Linear,
CompositeMode compositeMode = CompositeMode.SourceOver)
@@ -167,7 +167,7 @@ public unsafe partial struct ID2D1DeviceContext
}
public void DrawImage(ID2D1Effect* effect,
PointF targetOffset,
Vector2 targetOffset,
Common.RectF* imageRectangle,
InterpolationMode interpolationMode = InterpolationMode.Linear,
CompositeMode compositeMode = CompositeMode.SourceOver)
@@ -175,8 +175,66 @@ public unsafe partial struct ID2D1DeviceContext
DrawImage(effect, &targetOffset, imageRectangle, interpolationMode, compositeMode);
}
public void DrawGdiMetafile(ID2D1GdiMetafile* gdiMetafile, PointF targetOffset)
public void DrawGdiMetafile(ID2D1GdiMetafile* gdiMetafile, Vector2 targetOffset)
{
DrawGdiMetafile(gdiMetafile, &targetOffset);
}
}
public static unsafe partial class ID2D1DeviceContextExtensions
{
public static HResult SetDpiCompensatedEffectInput<TD2D1DeviceContext>(
ref this TD2D1DeviceContext self,
ID2D1Effect* effect,
uint inputIndex,
ID2D1Bitmap* inputBitmap,
InterpolationMode interpolationMode = InterpolationMode.Linear,
BorderMode borderMode = BorderMode.Hard)
where TD2D1DeviceContext : unmanaged, ID2D1DeviceContext.Interface
{
HResult hr = HResult.Ok;
ID2D1Effect* dpiCompensationEffect = null;
if (inputBitmap == null)
{
effect->SetInput(inputIndex, null);
return hr;
}
hr = self.CreateEffect((Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID_D2D1DpiCompensation)), &dpiCompensationEffect);
if (hr.Success)
{
if (hr.Success)
{
dpiCompensationEffect->SetInput(0, (ID2D1Image*)inputBitmap);
Vector2 bitmapDpi;
inputBitmap->GetDpi(&bitmapDpi.X, &bitmapDpi.Y);
hr = dpiCompensationEffect->SetValue(DpiCompensationProp.InputDpi, &bitmapDpi);
}
if (hr.Success)
{
hr = dpiCompensationEffect->SetValue(DpiCompensationProp.InterpolationMode, &interpolationMode);
}
if (hr.Success)
{
hr = dpiCompensationEffect->SetValue(DpiCompensationProp.BorderMode, &borderMode);
}
if (hr.Success)
{
effect->SetInputEffect(inputIndex, dpiCompensationEffect);
}
if (dpiCompensationEffect != null)
{
_ = dpiCompensationEffect->Release();
}
}
return hr;
}
}