Skip to content

Commit

Permalink
tweak 2
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Jan 15, 2025
1 parent b778c36 commit aaaba8b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions Studio/CelesteStudio.WPF/SkiaDrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ protected override void OnRender(DrawingContext drawingContext) {
}

if (drawable.CanDraw) {
if (bitmap == null || surface == null || width != bitmap.PixelWidth || height != bitmap.PixelHeight) {
if (width != bitmap.PixelWidth || height != bitmap.PixelHeight) {
bitmap = null;
surface = null;
}

if (bitmap == null) {
const double bitmapDpi = 96.0;
bitmap = new WriteableBitmap(width, height, bitmapDpi * dpiX, bitmapDpi * dpiY, PixelFormats.Pbgra32, null);

}
if (surface == null) {
surface?.Dispose();
surface = SKSurface.Create(new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul), bitmap.BackBuffer, bitmap.BackBufferStride, new SKSurfaceProperties(SKPixelGeometry.Unknown));
surface.Canvas.Scale((float)dpiX, (float)dpiY);
Expand All @@ -55,12 +61,21 @@ protected override void OnRender(DrawingContext drawingContext) {
canvas.Flush();

bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
if (DateTime.Now.Second % 10 > 5) {
bitmap.Invalidate();
}
bitmap.Unlock();

drawingContext.DrawImage(bitmap, new Rect(drawable.DrawX, drawable.DrawY, width / dpiX, height / dpiY));

if (DateTime.Now.Second % 15 > 10) {
bitmap = null;
System.Console.WriteLine("Bitmap clear");
} else if (DateTime.Now.Second % 15 > 5) {
surface = null;
System.Console.WriteLine("Surface clear");
} else {
bitmap = null;
surface = null;
System.Console.WriteLine("Bitmap surface clear");
}
} else {
drawable.Invalidate();
}
Expand Down

0 comments on commit aaaba8b

Please sign in to comment.