public PlatformRenderInterface(ICustomSkiaGpu customSkiaGpu, long maxResourceBytes = 100663296) { if (customSkiaGpu != null) { _customSkiaGpu = customSkiaGpu; GrContext = _customSkiaGpu.GrContext; GrContext.GetResourceCacheLimits(out var maxResources, out _); GrContext.SetResourceCacheLimits(maxResources, maxResourceBytes); return; } var gl = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>(); if (gl != null) { var display = gl.ImmediateContext.Display; gl.ImmediateContext.MakeCurrent(); using (var iface = display.Type == GlDisplayType.OpenGL2 ? GRGlInterface.AssembleGlInterface((_, proc) => display.GlInterface.GetProcAddress(proc)) : 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(); } }
public GlSkiaGpu(IWindowingPlatformGlFeature gl, long?maxResourceBytes) { var context = gl.MainContext; using (context.MakeCurrent()) { using (var iface = context.Version.Type == GlProfileType.OpenGL ? GRGlInterface.AssembleGlInterface((_, proc) => context.GlInterface.GetProcAddress(proc)) : GRGlInterface.AssembleGlesInterface((_, proc) => context.GlInterface.GetProcAddress(proc))) { _grContext = GRContext.Create(GRBackend.OpenGL, iface); if (maxResourceBytes.HasValue) { _grContext.GetResourceCacheLimits(out var maxResources, out _); _grContext.SetResourceCacheLimits(maxResources, maxResourceBytes.Value); } } } }