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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
19 additions and
2 deletions
-
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
-
src/Skia/Avalonia.Skia/SkiaOptions.cs
-
src/Skia/Avalonia.Skia/SkiaPlatform.cs
|
|
|
@ -18,7 +18,7 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
private GRContext GrContext { get; } |
|
|
|
|
|
|
|
public PlatformRenderInterface(ICustomSkiaGpu customSkiaGpu) |
|
|
|
public PlatformRenderInterface(ICustomSkiaGpu customSkiaGpu, long maxResourceBytes = 100000000) |
|
|
|
{ |
|
|
|
if (customSkiaGpu != null) |
|
|
|
{ |
|
|
|
@ -26,6 +26,10 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
GrContext = _customSkiaGpu.GrContext; |
|
|
|
|
|
|
|
GrContext.GetResourceCacheLimits(out var maxResources, out _); |
|
|
|
|
|
|
|
GrContext.SetResourceCacheLimits(maxResources, maxResourceBytes); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -39,6 +43,10 @@ namespace Avalonia.Skia |
|
|
|
: GRGlInterface.AssembleGlesInterface((_, proc) => display.GlInterface.GetProcAddress(proc))) |
|
|
|
{ |
|
|
|
GrContext = GRContext.Create(GRBackend.OpenGL, iface); |
|
|
|
|
|
|
|
GrContext.GetResourceCacheLimits(out var maxResources, out _); |
|
|
|
|
|
|
|
GrContext.SetResourceCacheLimits(maxResources, maxResourceBytes); |
|
|
|
} |
|
|
|
display.ClearContext(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -8,9 +8,18 @@ namespace Avalonia |
|
|
|
/// </summary>
|
|
|
|
public class SkiaOptions |
|
|
|
{ |
|
|
|
public SkiaOptions() |
|
|
|
{ |
|
|
|
MaxGpuResourceSizeBytes = 512000000; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// Custom gpu factory to use. Can be used to customize behavior of Skia renderer.
|
|
|
|
/// </summary>
|
|
|
|
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; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -18,7 +18,7 @@ namespace Avalonia.Skia |
|
|
|
public static void Initialize(SkiaOptions options) |
|
|
|
{ |
|
|
|
var customGpu = options.CustomGpuFactory?.Invoke(); |
|
|
|
var renderInterface = new PlatformRenderInterface(customGpu); |
|
|
|
var renderInterface = new PlatformRenderInterface(customGpu, options.MaxGpuResourceSizeBytes); |
|
|
|
|
|
|
|
AvaloniaLocator.CurrentMutable |
|
|
|
.Bind<IPlatformRenderInterface>().ToConstant(renderInterface) |
|
|
|
|