Browse Source
Add IImageBrushSource.GetBitmap(), update build/api suppressions (#21638 )
* Expose IRef/IImageBrushSource, update build/api suppressions
* Hide IRef from image brush source API
Internalized `IRef<T>` and removed it from the `IImageBrushSource` public surface by making `Bitmap` internal. Added a `[PrivateApi]` `GetBitmap()` helper returning `IBitmapImpl?` so internal consumers can still access the bitmap without exposing ref-count internals. Updated Skia drawing code to use `GetBitmap()` and refreshed API suppression entries accordingly.
pull/21904/head
James Jackson-South
2 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
32 additions and
2 deletions
Directory.Build.props
api/Avalonia.nupkg.xml
src/Avalonia.Base/Media/IImageBrush.cs
src/Avalonia.Base/Utilities/Ref.cs
src/Skia/Avalonia.Skia/DrawingContextImpl.cs
@ -10,6 +10,8 @@
<LangVersion>14.0</LangVersion>
<TreatWarningsAsErrors Condition="'$(TreatWarningsAsErrors)' == ''">$(AvnTreatWarningsAsErrors)</TreatWarningsAsErrors>
<TreatWarningsAsErrors Condition="'$(TreatWarningsAsErrors)' == '' And '$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>
<!-- Suppress NU1507 so local source builds do not warn about the consuming solution's package sources. -->
<NoWarn>$(NoWarn);NU1507</NoWarn>
<CreateHardLinksForCopyAdditionalFilesIfPossible>true</CreateHardLinksForCopyAdditionalFilesIfPossible>
<CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>true</CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>
<CreateHardLinksForCopyLocalIfPossible>true</CreateHardLinksForCopyLocalIfPossible>
@ -157,6 +157,12 @@
<Left > baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right > current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression >
<DiagnosticId > CP0006</DiagnosticId>
<Target > P:Avalonia.Media.IImageBrushSource.Bitmap</Target>
<Left > baseline/Avalonia/lib/net10.0/Avalonia.Base.dll</Left>
<Right > current/Avalonia/lib/net10.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression >
<DiagnosticId > CP0006</DiagnosticId>
<Target > M:Avalonia.Controls.Platform.IWin32OptionsTopLevelImpl.SetWindowCornerPreference(Avalonia.Controls.Win32Properties.WindowCornerPreference)</Target>
@ -181,6 +187,12 @@
<Left > baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right > current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression >
<DiagnosticId > CP0006</DiagnosticId>
<Target > P:Avalonia.Media.IImageBrushSource.Bitmap</Target>
<Left > baseline/Avalonia/lib/net8.0/Avalonia.Base.dll</Left>
<Right > current/Avalonia/lib/net8.0/Avalonia.Base.dll</Right>
</Suppression>
<Suppression >
<DiagnosticId > CP0006</DiagnosticId>
<Target > M:Avalonia.Controls.Platform.IWin32OptionsTopLevelImpl.SetWindowCornerPreference(Avalonia.Controls.Win32Properties.WindowCornerPreference)</Target>
@ -17,9 +17,21 @@ namespace Avalonia.Media
IImageBrushSource ? Source { get ; }
}
/// <summary>
/// Provides access to the image source of an <see cref="IImageBrush"/>.
/// </summary>
[NotClientImplementable]
public interface IImageBrushSource
{
internal IRef < IBitmapImpl > ? Bitmap { get ; }
/// <summary>
/// Gets the bitmap implementation of the image source.
/// </summary>
/// <returns>
/// The <see cref="IBitmapImpl"/> instance if available; otherwise, <c>null</c>.
/// </returns>
[PrivateApi]
IBitmapImpl ? GetBitmap ( ) = > Bitmap ? . Item ;
}
}
@ -7,7 +7,11 @@ namespace Avalonia.Utilities
/// <summary>
/// A ref-counted wrapper for a disposable object.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">
/// The type of the item being ref-counted.
/// Must be a reference type to avoid issues with copying value types and must be disposable
/// to ensure the item is cleaned up when the refcount reaches 0.
/// </typeparam>
internal interface IRef < out T > : IDisposable where T : class
{
/// <summary>
@ -1428,7 +1428,7 @@ namespace Avalonia.Skia
}
else
{
tileBrushImage = ( tileBrush as IImageBrush ) ? . Source ? . Bitmap ? . Item as IDrawableBitmapImpl ;
tileBrushImage = ( tileBrush as IImageBrush ) ? . Source ? . GetBitmap ( ) as IDrawableBitmapImpl ;
}
if ( tileBrush ! = null & & tileBrushImage ! = null )