Browse Source

Merge pull request #3889 from AvaloniaUI/feature/allow-user-to-configure-video-memory

Allow user to set GPU VMem limit.
repro-items-repeater-issue
danwalmsley 6 years ago
committed by GitHub
parent
commit
9626565ea7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  2. 9
      src/Skia/Avalonia.Skia/SkiaOptions.cs
  3. 2
      src/Skia/Avalonia.Skia/SkiaPlatform.cs

10
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs

@ -18,7 +18,7 @@ namespace Avalonia.Skia
private GRContext GrContext { get; } private GRContext GrContext { get; }
public PlatformRenderInterface(ICustomSkiaGpu customSkiaGpu) public PlatformRenderInterface(ICustomSkiaGpu customSkiaGpu, long maxResourceBytes = 100000000)
{ {
if (customSkiaGpu != null) if (customSkiaGpu != null)
{ {
@ -26,6 +26,10 @@ namespace Avalonia.Skia
GrContext = _customSkiaGpu.GrContext; GrContext = _customSkiaGpu.GrContext;
GrContext.GetResourceCacheLimits(out var maxResources, out _);
GrContext.SetResourceCacheLimits(maxResources, maxResourceBytes);
return; return;
} }
@ -39,6 +43,10 @@ namespace Avalonia.Skia
: GRGlInterface.AssembleGlesInterface((_, proc) => display.GlInterface.GetProcAddress(proc))) : GRGlInterface.AssembleGlesInterface((_, proc) => display.GlInterface.GetProcAddress(proc)))
{ {
GrContext = GRContext.Create(GRBackend.OpenGL, iface); GrContext = GRContext.Create(GRBackend.OpenGL, iface);
GrContext.GetResourceCacheLimits(out var maxResources, out _);
GrContext.SetResourceCacheLimits(maxResources, maxResourceBytes);
} }
display.ClearContext(); display.ClearContext();
} }

9
src/Skia/Avalonia.Skia/SkiaOptions.cs

@ -8,9 +8,18 @@ namespace Avalonia
/// </summary> /// </summary>
public class SkiaOptions public class SkiaOptions
{ {
public SkiaOptions()
{
MaxGpuResourceSizeBytes = 512000000;
}
/// <summary> /// <summary>
/// Custom gpu factory to use. Can be used to customize behavior of Skia renderer. /// Custom gpu factory to use. Can be used to customize behavior of Skia renderer.
/// </summary> /// </summary>
public Func<ICustomSkiaGpu> CustomGpuFactory { get; set; } public Func<ICustomSkiaGpu> CustomGpuFactory { get; set; }
/// <summary>
/// The maximum number of bytes for video memory to store textures and resources.
/// </summary>
public long MaxGpuResourceSizeBytes { get; set; }
} }
} }

2
src/Skia/Avalonia.Skia/SkiaPlatform.cs

@ -18,7 +18,7 @@ namespace Avalonia.Skia
public static void Initialize(SkiaOptions options) public static void Initialize(SkiaOptions options)
{ {
var customGpu = options.CustomGpuFactory?.Invoke(); var customGpu = options.CustomGpuFactory?.Invoke();
var renderInterface = new PlatformRenderInterface(customGpu); var renderInterface = new PlatformRenderInterface(customGpu, options.MaxGpuResourceSizeBytes);
AvaloniaLocator.CurrentMutable AvaloniaLocator.CurrentMutable
.Bind<IPlatformRenderInterface>().ToConstant(renderInterface) .Bind<IPlatformRenderInterface>().ToConstant(renderInterface)

Loading…
Cancel
Save