Browse Source

allow resizing of layer texture.

features/manually-managed-layer-textures
Dan Walmsley 6 years ago
parent
commit
77638b6534
  1. 2
      src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs
  2. 27
      src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs
  3. 13
      src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs

2
src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs

@ -8,6 +8,8 @@ namespace Avalonia.Skia
public interface IControlledSurface : IDisposable
{
public SKSurface Surface { get; }
public void Resize(PixelSize size);
}
/// <summary>

27
src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs

@ -54,13 +54,17 @@ namespace Avalonia.Skia
class GlSkiaGpuControlledSurface : IControlledSurface
{
private GRContext _context;
private SKSurface _surface;
private GRBackendTexture _texture;
private IDisposable _disposable;
private int _textureId;
private IWindowingPlatformGlFeature _glFeature;
public GlSkiaGpuControlledSurface(GRContext context, IWindowingPlatformGlFeature glFeature, PixelSize size)
{
_context = context;
_glFeature = glFeature;
var gl = glFeature.MainContext.GlInterface;
var oneArr = new int[1];
@ -98,6 +102,29 @@ namespace Avalonia.Skia
_texture.Dispose();
_disposable.Dispose();
}
public void Resize(PixelSize size)
{
_surface.Dispose();
_texture.Dispose();
var gl = _glFeature.MainContext.GlInterface;
gl.BindTexture(GL_TEXTURE_2D, _textureId);
gl.TexImage2D(GL_TEXTURE_2D, 0,
_glFeature.MainContext.Version.Type == GlProfileType.OpenGLES ? GL_RGBA : GL_RGBA8,
size.Width, size.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, IntPtr.Zero);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
_texture = new GRBackendTexture(size.Width, size.Height, false,
new GRGlTextureInfo(
GL_TEXTURE_2D, (uint)_textureId,
(uint)GL_RGBA8));
_surface = SKSurface.Create(_context, _texture, GRSurfaceOrigin.TopLeft,
SKColorType.Rgba8888);
}
}
}
}

13
src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs

@ -57,10 +57,15 @@ namespace Avalonia.Skia
var imageInfo = MakeImageInfo(width, height, format);
if (skiaGpu != null)
{
s_lastControlledSurface?.Dispose();
s_lastControlledSurface =
skiaGpu.CreateControlledSurface(new PixelSize(width, height));
if (s_lastControlledSurface == null)
{
s_lastControlledSurface =
skiaGpu.CreateControlledSurface(new PixelSize(width, height));
}
else
{
s_lastControlledSurface.Resize(new PixelSize(width, height));
}
return s_lastControlledSurface.Surface;
}

Loading…
Cancel
Save