From 25436b05492bd52ae54c50a3d95aad7651961260 Mon Sep 17 00:00:00 2001 From: Cameron White Date: Thu, 7 Nov 2024 20:39:48 -0500 Subject: [PATCH 1/4] Update to gir.core 0.6.0-preview.1 - Fixed a few warnings from methods that now have nullable return values. --- Directory.Packages.props | 6 +++--- Pinta.Core/Managers/ImageConverterManager.cs | 6 ++++-- Pinta.Effects/Dialogs/Effects.LevelsDialog.cs | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 7bc053e4d3..642650efad 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,9 +3,9 @@ true - - - + + + diff --git a/Pinta.Core/Managers/ImageConverterManager.cs b/Pinta.Core/Managers/ImageConverterManager.cs index 86453fcf52..d20555ac49 100644 --- a/Pinta.Core/Managers/ImageConverterManager.cs +++ b/Pinta.Core/Managers/ImageConverterManager.cs @@ -74,7 +74,9 @@ private static IEnumerable GetInitialFormats () private static FormatDescriptor CreateFormatDescriptor (PixbufFormat format) { - string formatName = format.GetName ().ToLowerInvariant (); + string formatName = format.GetName ()?.ToLowerInvariant () ?? + throw new ArgumentException ($"{nameof (format)} has an empty name"); + string formatNameUpperCase = formatName.ToUpperInvariant (); var extensions = formatName switch { "jpeg" => new string[] { "jpg", "jpeg", "JPG", "JPEG" }, @@ -95,7 +97,7 @@ private static FormatDescriptor CreateFormatDescriptor (PixbufFormat format) FormatDescriptor formatDescriptor = new ( displayPrefix: formatNameUpperCase, extensions: extensions, - mimes: format.GetMimeTypes (), + mimes: format.GetMimeTypes () ?? Array.Empty (), importer: importer, exporter: exporter, supportsLayers: false); diff --git a/Pinta.Effects/Dialogs/Effects.LevelsDialog.cs b/Pinta.Effects/Dialogs/Effects.LevelsDialog.cs index 8f33b2f19f..6fa7f19369 100644 --- a/Pinta.Effects/Dialogs/Effects.LevelsDialog.cs +++ b/Pinta.Effects/Dialogs/Effects.LevelsDialog.cs @@ -603,7 +603,9 @@ private void HandleColorPanelButtonPressEvent ( if (args.NPress != 2) // double click return; - ColorPanelWidget panel = (ColorPanelWidget) controller.GetWidget (); + ColorPanelWidget panel = (ColorPanelWidget?) controller.GetWidget () ?? + throw new Exception ("Controller widget should be non-null"); + var ccd = Gtk.ColorChooserDialog.New (Translations.GetString ("Choose Color"), chrome.MainWindow); ccd.UseAlpha = true; ccd.SetColor (panel.CairoColor); From 195ad27a907f4b8d0d138145123117ef87d5522e Mon Sep 17 00:00:00 2001 From: Cameron White Date: Thu, 7 Nov 2024 20:58:35 -0500 Subject: [PATCH 2/4] Fix memory growth when drawing the canvas Bug: #939 --- Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs b/Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs index 8b877f02cc..a86a4d6448 100644 --- a/Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs +++ b/Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs @@ -209,6 +209,10 @@ private void Draw (Cairo.Context context, int width, int height) DrawHandles (g, PintaCore.Tools.CurrentTool.Handles); g.Restore (); } + + // Explicitly dispose the context to avoid memory growth (bug #939). + // This can be the last reference to a temporary surface from the GTK widget. + context.Dispose (); } private static void DrawHandles (Cairo.Context cr, IEnumerable controls) From 48822c829135430ea0f17ec7e48aa2f7c516cba2 Mon Sep 17 00:00:00 2001 From: Cameron White Date: Thu, 7 Nov 2024 21:05:48 -0500 Subject: [PATCH 3/4] Explicitly dispose all drawing area contexts, following 195ad27a --- Pinta.Effects/Dialogs/Effects.CurvesDialog.cs | 2 ++ Pinta.Gui.Widgets/Widgets/AnglePickerGraphic.cs | 2 ++ Pinta.Gui.Widgets/Widgets/ColorGradientWidget.cs | 2 ++ Pinta.Gui.Widgets/Widgets/ColorPanelWidget.cs | 2 ++ Pinta.Gui.Widgets/Widgets/HistogramWidget.cs | 2 ++ Pinta.Gui.Widgets/Widgets/Layers/LayersListViewItemWidget.cs | 2 ++ Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs | 2 ++ Pinta.Gui.Widgets/Widgets/Ruler.cs | 2 ++ Pinta.Gui.Widgets/Widgets/StatusBarColorPaletteWidget.cs | 2 ++ Pinta/Dialogs/NewImageDialog.cs | 2 ++ 10 files changed, 20 insertions(+) diff --git a/Pinta.Effects/Dialogs/Effects.CurvesDialog.cs b/Pinta.Effects/Dialogs/Effects.CurvesDialog.cs index 0c70d72ab4..c270099e71 100644 --- a/Pinta.Effects/Dialogs/Effects.CurvesDialog.cs +++ b/Pinta.Effects/Dialogs/Effects.CurvesDialog.cs @@ -483,6 +483,8 @@ private void HandleDrawingDrawnEvent (Context g) DrawGrid (g); DrawControlPoints (g); + g.Dispose (); + return; // Methods diff --git a/Pinta.Gui.Widgets/Widgets/AnglePickerGraphic.cs b/Pinta.Gui.Widgets/Widgets/AnglePickerGraphic.cs index 3bb1b3d9e2..72e594493e 100644 --- a/Pinta.Gui.Widgets/Widgets/AnglePickerGraphic.cs +++ b/Pinta.Gui.Widgets/Widgets/AnglePickerGraphic.cs @@ -131,6 +131,8 @@ private void Draw (Context g) g.DrawEllipse (settings.ellipseOutlineRect, settings.color, 1); g.FillEllipse (settings.gripEllipseRect, settings.color); g.DrawLine (settings.center, settings.endPoint, settings.color, 1); + + g.Dispose (); } public event EventHandler? ValueChanged; diff --git a/Pinta.Gui.Widgets/Widgets/ColorGradientWidget.cs b/Pinta.Gui.Widgets/Widgets/ColorGradientWidget.cs index f74fd02aeb..98389c1458 100644 --- a/Pinta.Gui.Widgets/Widgets/ColorGradientWidget.cs +++ b/Pinta.Gui.Widgets/Widgets/ColorGradientWidget.cs @@ -340,6 +340,8 @@ private void Draw (Context g) { DrawGradient (g); DrawTriangles (g); + + g.Dispose (); } private void OnValueChanged (int index) diff --git a/Pinta.Gui.Widgets/Widgets/ColorPanelWidget.cs b/Pinta.Gui.Widgets/Widgets/ColorPanelWidget.cs index 2504551589..bc8b39c6c2 100644 --- a/Pinta.Gui.Widgets/Widgets/ColorPanelWidget.cs +++ b/Pinta.Gui.Widgets/Widgets/ColorPanelWidget.cs @@ -58,5 +58,7 @@ public ColorPanelWidget () private void Draw (Context cr) { cr.FillRoundedRectangle (new RectangleD (0, 0, GetAllocatedWidth (), GetAllocatedHeight ()), 4, CairoColor); + + cr.Dispose (); } } diff --git a/Pinta.Gui.Widgets/Widgets/HistogramWidget.cs b/Pinta.Gui.Widgets/Widgets/HistogramWidget.cs index d4cfc0deb4..9b2fd62aed 100644 --- a/Pinta.Gui.Widgets/Widgets/HistogramWidget.cs +++ b/Pinta.Gui.Widgets/Widgets/HistogramWidget.cs @@ -162,5 +162,7 @@ private void Draw (Context g) for (int i = 0; i < channelCount; ++i) DrawChannel (g, Histogram.GetVisualColor (i), i, max, mean[i]); + + g.Dispose (); } } diff --git a/Pinta.Gui.Widgets/Widgets/Layers/LayersListViewItemWidget.cs b/Pinta.Gui.Widgets/Widgets/Layers/LayersListViewItemWidget.cs index 98c598835d..c7e3a0cdab 100644 --- a/Pinta.Gui.Widgets/Widgets/Layers/LayersListViewItemWidget.cs +++ b/Pinta.Gui.Widgets/Widgets/Layers/LayersListViewItemWidget.cs @@ -213,5 +213,7 @@ private void DrawThumbnail ( g.LineWidth = 1; g.Stroke (); + + g.Dispose (); } } diff --git a/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs b/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs index 314fab994b..33ad9e155b 100644 --- a/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs +++ b/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs @@ -156,6 +156,8 @@ private void Draw (Context g) // Point g.DrawEllipse (settings.pointMarker, settings.pointMarkerColor, 2); + + g.Dispose (); } private RectangleI GetDrawBounds () diff --git a/Pinta.Gui.Widgets/Widgets/Ruler.cs b/Pinta.Gui.Widgets/Widgets/Ruler.cs index b31611451b..5f303d11a5 100644 --- a/Pinta.Gui.Widgets/Widgets/Ruler.cs +++ b/Pinta.Gui.Widgets/Widgets/Ruler.cs @@ -324,6 +324,8 @@ private void Draw ( cr.Stroke (); // TODO-GTK3 - cache the ticks + + cr.Dispose (); } private static int GetFontSize ( diff --git a/Pinta.Gui.Widgets/Widgets/StatusBarColorPaletteWidget.cs b/Pinta.Gui.Widgets/Widgets/StatusBarColorPaletteWidget.cs index 630e0925ad..3bb5c95bbf 100644 --- a/Pinta.Gui.Widgets/Widgets/StatusBarColorPaletteWidget.cs +++ b/Pinta.Gui.Widgets/Widgets/StatusBarColorPaletteWidget.cs @@ -156,6 +156,8 @@ private void Draw (Context g) for (int i = 0; i < palette.Count; i++) g.FillRectangle (GetSwatchBounds (i), palette[i]); + + g.Dispose (); } private void DrawSwapIcon (Context g, Color color) diff --git a/Pinta/Dialogs/NewImageDialog.cs b/Pinta/Dialogs/NewImageDialog.cs index a5d71e8fc9..5252687dde 100644 --- a/Pinta/Dialogs/NewImageDialog.cs +++ b/Pinta/Dialogs/NewImageDialog.cs @@ -617,6 +617,8 @@ private void Draw (Cairo.Context cr, int widget_width, int widget_height) cr.DrawRectangle (new RectangleD (r.X - 1, r.Y - 1, r.Width + 2, r.Height + 2), new Cairo.Color (.5, .5, .5), 1); cr.DrawRectangle (new RectangleD (r.X - 2, r.Y - 2, r.Width + 4, r.Height + 4), new Cairo.Color (.8, .8, .8), 1); cr.DrawRectangle (new RectangleD (r.X - 3, r.Y - 3, r.Width + 6, r.Height + 6), new Cairo.Color (.9, .9, .9), 1); + + cr.Dispose (); } private Size GetPreviewSizeForDraw () // Figure out the dimensions of the preview to draw From 4a05180c860fb5c5bc3a20d69e1b28f352794c99 Mon Sep 17 00:00:00 2001 From: Cameron White Date: Fri, 8 Nov 2024 21:55:39 -0500 Subject: [PATCH 4/4] Explicitly dispose Cairo contexts. --- Pinta.Core/Actions/EditActions.cs | 8 +++---- Pinta.Core/Actions/LayerActions.cs | 2 +- Pinta.Core/Classes/Document.cs | 20 ++--------------- Pinta.Core/Classes/DocumentLayers.cs | 8 +++---- Pinta.Core/Classes/DocumentSelection.cs | 2 +- Pinta.Core/Classes/Layer.cs | 12 +++++----- Pinta.Core/Extensions/CairoExtensions.cs | 14 ++++++------ Pinta.Core/Extensions/GdkExtensions.cs | 2 +- Pinta.Core/HistoryItems/PasteHistoryItem.cs | 2 +- Pinta.Core/ImageFormats/GdkPixbufFormat.cs | 2 +- Pinta.Core/ImageFormats/OraFormat.cs | 2 +- Pinta.Core/Managers/LivePreviewManager.cs | 4 ++-- Pinta.Core/Managers/WorkspaceManager.cs | 4 ++-- Pinta.Effects/Effects/CloudsEffect.cs | 2 +- .../Widgets/Canvas/CanvasRenderer.cs | 2 +- .../Widgets/PointPickerGraphic.cs | 2 +- Pinta.Resources/ResourceManager.cs | 2 +- .../Editable/EditEngines/BaseEditEngine.cs | 2 +- Pinta.Tools/Tools/CloneStampTool.cs | 4 ++-- Pinta.Tools/Tools/EraserTool.cs | 4 ++-- Pinta.Tools/Tools/FreeformShapeTool.cs | 4 ++-- Pinta.Tools/Tools/GradientTool.cs | 4 ++-- Pinta.Tools/Tools/LassoSelectTool.cs | 4 ++-- Pinta.Tools/Tools/MoveSelectedTool.cs | 22 +++++++++---------- Pinta.Tools/Tools/PaintBrushTool.cs | 6 ++--- Pinta.Tools/Tools/PaintBucketTool.cs | 14 ++++++------ Pinta.Tools/Tools/PencilTool.cs | 2 +- Pinta.Tools/Tools/RecolorTool.cs | 2 +- Pinta.Tools/Tools/TextTool.cs | 4 ++-- Pinta.Tools/Tools/ZoomTool.cs | 2 +- Pinta/Actions/Edit/PasteAction.cs | 2 +- tests/Pinta.Core.Tests/Utilities.cs | 2 +- tests/Pinta.Effects.Tests/Utilities.cs | 2 +- tests/PintaBenchmarks/Utilities/TestData.cs | 2 +- 34 files changed, 78 insertions(+), 94 deletions(-) diff --git a/Pinta.Core/Actions/EditActions.cs b/Pinta.Core/Actions/EditActions.cs index 13e94876a0..2bc8f7f5bd 100644 --- a/Pinta.Core/Actions/EditActions.cs +++ b/Pinta.Core/Actions/EditActions.cs @@ -201,7 +201,7 @@ private void HandlePintaCoreActionsEditFillSelectionActivated (object sender, Ev ImageSurface old = doc.Layers.CurrentUserLayer.Surface.Clone (); - Context g = new (doc.Layers.CurrentUserLayer.Surface); + using Context g = new (doc.Layers.CurrentUserLayer.Surface); g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; @@ -247,7 +247,7 @@ private void HandlePintaCoreActionsEditEraseSelectionActivated (object sender, E ImageSurface old = doc.Layers.CurrentUserLayer.Surface.Clone (); - Context g = new (doc.Layers.CurrentUserLayer.Surface); + using Context g = new (doc.Layers.CurrentUserLayer.Surface); g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; @@ -302,7 +302,7 @@ private void HandlerPintaCoreActionsEditCopyActivated (object sender, EventArgs ImageSurface dest = CairoExtensions.CreateImageSurface (Format.Argb32, rect.Width, rect.Height); - Context g = new (dest); + using Context g = new (dest); g.SetSourceSurface (src, -rect.X, -rect.Y); g.Paint (); @@ -324,7 +324,7 @@ private void HandlerPintaCoreActionsEditCopyMergedActivated (object sender, Even // Copy it to a correctly sized surface ImageSurface dest = CairoExtensions.CreateImageSurface (Format.Argb32, rect.Width, rect.Height); - Context g = new (dest); + using Context g = new (dest); g.SetSourceSurface (src, -rect.X, -rect.Y); g.Paint (); diff --git a/Pinta.Core/Actions/LayerActions.cs b/Pinta.Core/Actions/LayerActions.cs index 8b693faa12..944905040d 100644 --- a/Pinta.Core/Actions/LayerActions.cs +++ b/Pinta.Core/Actions/LayerActions.cs @@ -217,7 +217,7 @@ private void HandlePintaCoreActionsLayersImportFromFileActivated (object sender, using Gio.FileInputStream fs = file.Read (null); try { GdkPixbuf.Pixbuf bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when an error is thrown - Cairo.Context context = new (layer.Surface); + using Cairo.Context context = new (layer.Surface); context.DrawPixbuf (bg, PointD.Zero); } finally { fs.Close (null); diff --git a/Pinta.Core/Classes/Document.cs b/Pinta.Core/Classes/Document.cs index 2b06d47b0a..e1068342fc 100644 --- a/Pinta.Core/Classes/Document.cs +++ b/Pinta.Core/Classes/Document.cs @@ -197,14 +197,6 @@ public Context CreateClippedContext () return g; } - public Context CreateClippedContext (bool antialias) - { - Context g = new (Layers.CurrentUserLayer.Surface); - Selection.Clip (g); - g.Antialias = antialias ? Antialias.Subpixel : Antialias.None; - return g; - } - public Context CreateClippedToolContext () { Context g = new (Layers.ToolLayer.Surface); @@ -212,14 +204,6 @@ public Context CreateClippedToolContext () return g; } - public Context CreateClippedToolContext (bool antialias) - { - Context g = new (Layers.ToolLayer.Surface); - Selection.Clip (g); - g.Antialias = antialias ? Antialias.Subpixel : Antialias.None; - return g; - } - public void FinishSelection () { // We don't have an uncommitted layer, abort @@ -232,7 +216,7 @@ public void FinishSelection () Layer layer = Layers.SelectionLayer; - Context g = new (Layers.CurrentUserLayer.Surface); + using Context g = new (Layers.CurrentUserLayer.Surface); selection.Clip (g); layer.DrawWithOperator (g, Operator.Source, opacity: 1.0, transform: true); @@ -270,7 +254,7 @@ public ColorBgra GetComputedPixel (PointI position) 1, 1); - Context g = new (dst); + using Context g = new (dst); foreach (var layer in Layers.GetLayersToPaint ()) { diff --git a/Pinta.Core/Classes/DocumentLayers.cs b/Pinta.Core/Classes/DocumentLayers.cs index 4f10cadc0b..a196222391 100644 --- a/Pinta.Core/Classes/DocumentLayers.cs +++ b/Pinta.Core/Classes/DocumentLayers.cs @@ -206,7 +206,7 @@ public UserLayer DuplicateCurrentLayer () // {0} is the name of the source layer. Example: "Layer 3 copy". UserLayer layer = CreateLayer (Translations.GetString ("{0} copy", source.Name)); - Context g = new (layer.Surface); + using Context g = new (layer.Surface); g.SetSourceSurface (source.Surface, 0, 0); g.Paint (); @@ -254,7 +254,7 @@ public ImageSurface GetClippedLayer (int index) { ImageSurface surf = CairoExtensions.CreateImageSurface (Format.Argb32, document.ImageSize.Width, document.ImageSize.Height); - Context g = new (surf); + using Context g = new (surf); document.Selection.Clip (g); g.SetSourceSurface (user_layers[index].Surface, 0, 0); @@ -271,7 +271,7 @@ internal ImageSurface GetFlattenedImage (bool clip_to_selection = false) // Create a new image surface ImageSurface surf = CairoExtensions.CreateImageSurface (Format.Argb32, document.ImageSize.Width, document.ImageSize.Height); - Context g = new (surf); + using Context g = new (surf); if (clip_to_selection) document.Selection.Clip (g); @@ -350,7 +350,7 @@ public void MergeCurrentLayerDown () UserLayer dest = user_layers[CurrentUserLayerIndex - 1]; // Blend the layers - Context g = new (dest.Surface); + using Context g = new (dest.Surface); source.Draw (g); DeleteCurrentLayer (); diff --git a/Pinta.Core/Classes/DocumentSelection.cs b/Pinta.Core/Classes/DocumentSelection.cs index b2d2db88bd..aac1bee7fb 100644 --- a/Pinta.Core/Classes/DocumentSelection.cs +++ b/Pinta.Core/Classes/DocumentSelection.cs @@ -62,7 +62,7 @@ public bool Visible { public Path SelectionPath { get { if (selection_path == null) { - Context g = new (owning_document.Layers.CurrentUserLayer.Surface); + using Context g = new (owning_document.Layers.CurrentUserLayer.Surface); selection_path = g.CreatePolygonPath (ConvertToPolygonSet (SelectionPolygons)); } diff --git a/Pinta.Core/Classes/Layer.cs b/Pinta.Core/Classes/Layer.cs index ed77e5475b..924f9afda9 100644 --- a/Pinta.Core/Classes/Layer.cs +++ b/Pinta.Core/Classes/Layer.cs @@ -97,7 +97,7 @@ public void FlipHorizontal () Surface.Width, Surface.Height); - Context g = new (dest); + using Context g = new (dest); g.SetMatrix (CairoExtensions.CreateMatrix (-1, 0, 0, 1, Surface.Width, 0)); g.SetSourceSurface (Surface, 0, 0); @@ -114,7 +114,7 @@ public void FlipVertical () Surface.Width, Surface.Height); - Context g = new (dest); + using Context g = new (dest); g.SetMatrix (CairoExtensions.CreateMatrix (1, 0, 0, -1, 0, Surface.Height)); g.SetSourceSurface (Surface, 0, 0); @@ -183,7 +183,7 @@ public virtual void ApplyTransform ( new_size.Width, new_size.Height); - Context g = new (dest); + using Context g = new (dest); g.Transform (xform); g.SetSourceSurface (Surface, 0, 0); @@ -215,7 +215,7 @@ public virtual void Resize (Size newSize, ResamplingMode resamplingMode) newSize.Width, newSize.Height); - Context g = new (dest); + using Context g = new (dest); g.Scale (newSize.Width / (double) Surface.Width, newSize.Height / (double) Surface.Height); g.SetSourceSurface (Surface, resamplingMode); @@ -238,7 +238,7 @@ public virtual void ResizeCanvas (Size newSize, Anchor anchor) PointD anchorPoint = GetAnchorPoint (delta, anchor); - Context g = new (dest); + using Context g = new (dest); g.SetSourceSurface (Surface, anchorPoint.X, anchorPoint.Y); g.Paint (); @@ -267,7 +267,7 @@ public virtual void Crop (RectangleI rect, Path? selection) rect.Width, rect.Height); - Context g = new (dest); + using Context g = new (dest); // Move the selected content to the upper left g.Translate (-rect.X, -rect.Y); diff --git a/Pinta.Core/Extensions/CairoExtensions.cs b/Pinta.Core/Extensions/CairoExtensions.cs index 8c31ec6cf2..3b2b76d161 100644 --- a/Pinta.Core/Extensions/CairoExtensions.cs +++ b/Pinta.Core/Extensions/CairoExtensions.cs @@ -628,7 +628,7 @@ public static ImageSurface Clone (this ImageSurface surf) surf.Width, surf.Height); - Context g = new (newsurf); + using Context g = new (newsurf); g.SetSourceSurface (surf, 0, 0); g.Paint (); @@ -639,14 +639,14 @@ public static ImageSurface Clone (this ImageSurface surf) public static Path Clone (this Path path) { Document doc = PintaCore.Workspace.ActiveDocument; - Context g = new (doc.Layers.CurrentUserLayer.Surface); + using Context g = new (doc.Layers.CurrentUserLayer.Surface); g.AppendPath (path); return g.CopyPath (); } public static void Clear (this ImageSurface surface) { - Context g = new (surface) { Operator = Operator.Clear }; + using Context g = new (surface) { Operator = Operator.Clear }; g.Paint (); } @@ -689,7 +689,7 @@ public static RectangleD PathExtents (this Context context) public static RectangleI GetBounds (this Path path) { Document doc = PintaCore.Workspace.ActiveDocument; - Context g = new (doc.Layers.CurrentUserLayer.Surface); + using Context g = new (doc.Layers.CurrentUserLayer.Surface); g.AppendPath (path); return g.PathExtents ().ToInt (); } @@ -1175,7 +1175,7 @@ public static ImageSurface CreateTransparentBackgroundSurface (int size) ImageSurface surface = CreateImageSurface (Format.Argb32, size, size); // Draw the checkerboard - Context g = new (surface); + using Context g = new (surface); // Fill white g.FillRectangle (new RectangleD (0, 0, size, size), new Color (1, 1, 1)); @@ -1856,7 +1856,7 @@ public static ImageSurface CreateColorSwatch ( Color color) { ImageSurface surf = CreateImageSurface (Cairo.Format.Argb32, size, size); - Context g = new (surf); + using Context g = new (surf); g.FillRectangle (new RectangleD (0, 0, size, size), color); g.DrawRectangle (new RectangleD (0, 0, size, size), new Color (0, 0, 0), 1); @@ -1867,7 +1867,7 @@ public static ImageSurface CreateColorSwatch ( public static ImageSurface CreateTransparentColorSwatch (int size, bool drawBorder) { ImageSurface surface = CreateTransparentBackgroundSurface (size); - Context g = new (surface); + using Context g = new (surface); if (drawBorder) g.DrawRectangle (new RectangleD (0, 0, size, size), new Color (0, 0, 0), 1); diff --git a/Pinta.Core/Extensions/GdkExtensions.cs b/Pinta.Core/Extensions/GdkExtensions.cs index 8aa434265d..e9f066cb00 100644 --- a/Pinta.Core/Extensions/GdkExtensions.cs +++ b/Pinta.Core/Extensions/GdkExtensions.cs @@ -140,7 +140,7 @@ public static Gdk.Texture CreateIconWithShape ( shapeY = imgToShapeY - iconBBox.Top; var i = CairoExtensions.CreateImageSurface (Cairo.Format.Argb32, iconBBox.Width, iconBBox.Height); - var g = new Cairo.Context (i); + using Cairo.Context g = new (i); // Don't show shape if shapeWidth less than 3, if (shapeWidth > 3) { int diam = Math.Max (1, shapeWidth - 2); diff --git a/Pinta.Core/HistoryItems/PasteHistoryItem.cs b/Pinta.Core/HistoryItems/PasteHistoryItem.cs index 49901992d7..255cfe721c 100644 --- a/Pinta.Core/HistoryItems/PasteHistoryItem.cs +++ b/Pinta.Core/HistoryItems/PasteHistoryItem.cs @@ -50,7 +50,7 @@ public override void Redo () doc.Layers.CreateSelectionLayer (); doc.Layers.ShowSelectionLayer = true; - var g = new Cairo.Context (doc.Layers.SelectionLayer.Surface); + using Cairo.Context g = new (doc.Layers.SelectionLayer.Surface); g.SetSourceSurface (paste_image, 0, 0); g.Paint (); diff --git a/Pinta.Core/ImageFormats/GdkPixbufFormat.cs b/Pinta.Core/ImageFormats/GdkPixbufFormat.cs index 37bab912ea..a6924e699d 100644 --- a/Pinta.Core/ImageFormats/GdkPixbufFormat.cs +++ b/Pinta.Core/ImageFormats/GdkPixbufFormat.cs @@ -49,7 +49,7 @@ public Document Import (Gio.File file) Layer layer = newDocument.Layers.AddNewLayer (file.GetDisplayName ()); - Cairo.Context g = new (layer.Surface); + using Cairo.Context g = new (layer.Surface); g.DrawPixbuf (effectiveBuffer, PointD.Zero); diff --git a/Pinta.Core/ImageFormats/OraFormat.cs b/Pinta.Core/ImageFormats/OraFormat.cs index a790633f2f..921dc50799 100644 --- a/Pinta.Core/ImageFormats/OraFormat.cs +++ b/Pinta.Core/ImageFormats/OraFormat.cs @@ -110,7 +110,7 @@ public Document Import (Gio.File file) layer.BlendMode = StandardToBlendMode (GetAttribute (layerElement, "composite-op", "svg:src-over")); Pixbuf pb = Pixbuf.NewFromFile (tmp_file)!; // NRT: only nullable when an error is thrown - Context g = new (layer.Surface); + using Context g = new (layer.Surface); g.DrawPixbuf (pb, (PointD) position); try { diff --git a/Pinta.Core/Managers/LivePreviewManager.cs b/Pinta.Core/Managers/LivePreviewManager.cs index bd18f69f6b..d420b3c812 100644 --- a/Pinta.Core/Managers/LivePreviewManager.cs +++ b/Pinta.Core/Managers/LivePreviewManager.cs @@ -110,7 +110,7 @@ public async void Start (BaseEffect effect) history_item.TakeSnapshotOfLayer (doc.Layers.CurrentUserLayerIndex); // Paint the pre-effect layer surface into into the working surface. - Cairo.Context ctx = new (LivePreviewSurface); + using Cairo.Context ctx = new (LivePreviewSurface); layer.Draw (ctx, layer.Surface, 1); if (effect.EffectData != null) @@ -206,7 +206,7 @@ void HandleApply () { Debug.WriteLine ("LivePreviewManager.HandleApply()"); - Cairo.Context ctx = new (layer.Surface); + using Cairo.Context ctx = new (layer.Surface); ctx.Save (); workspace.ActiveDocument.Selection.Clip (ctx); diff --git a/Pinta.Core/Managers/WorkspaceManager.cs b/Pinta.Core/Managers/WorkspaceManager.cs index 01b85d5bfa..600de37e27 100644 --- a/Pinta.Core/Managers/WorkspaceManager.cs +++ b/Pinta.Core/Managers/WorkspaceManager.cs @@ -145,7 +145,7 @@ public static Document NewDocument ( Layer background = doc.Layers.AddNewLayer (Translations.GetString ("Background")); if (backgroundColor.A != 0) { - Context g = new (background.Surface); + using Context g = new (background.Surface); g.SetSourceColor (backgroundColor); g.Paint (); } @@ -300,7 +300,7 @@ public Document NewDocumentFromImage (ActionManager actions, Cairo.ImageSurface new Size (image.Width, image.Height), new Color (0, 0, 0, 0)); - Context g = new (doc.Layers[0].Surface); + using Context g = new (doc.Layers[0].Surface); g.SetSourceSurface (image, 0, 0); g.Paint (); diff --git a/Pinta.Effects/Effects/CloudsEffect.cs b/Pinta.Effects/Effects/CloudsEffect.cs index dd96bc7ac0..b2d3347adc 100644 --- a/Pinta.Effects/Effects/CloudsEffect.cs +++ b/Pinta.Effects/Effects/CloudsEffect.cs @@ -138,7 +138,7 @@ protected override void Render ( // Have to lock because effect renderer is multithreaded lock (render_lock) { - Context g = new (dst); + using Context g = new (dst); // - Clear any previous render from the destination // - Copy the source to the destination diff --git a/Pinta.Gui.Widgets/Widgets/Canvas/CanvasRenderer.cs b/Pinta.Gui.Widgets/Widgets/Canvas/CanvasRenderer.cs index 62d5744f19..d95299b736 100644 --- a/Pinta.Gui.Widgets/Widgets/Canvas/CanvasRenderer.cs +++ b/Pinta.Gui.Widgets/Widgets/Canvas/CanvasRenderer.cs @@ -68,7 +68,7 @@ public void Render ( RectangleD r = new RectangleI (offset, dst.GetBounds ().Size).ToDouble (); bool is_one_to_one = scale_factor.Ratio == 1; - Cairo.Context g = new (dst); + using Cairo.Context g = new (dst); // Create the transparent checkerboard background g.Translate (-offset.X, -offset.Y); diff --git a/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs b/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs index 33ad9e155b..01e446df6b 100644 --- a/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs +++ b/Pinta.Gui.Widgets/Widgets/PointPickerGraphic.cs @@ -77,7 +77,7 @@ private void UpdateThumbnail () thumbnail = CairoExtensions.CreateImageSurface (Format.Argb32, bounds.Width, bounds.Height); - var g = new Context (thumbnail); + using Context g = new (thumbnail); g.Scale (scalex, scaley); foreach (var layer in doc.Layers.GetLayersToPaint ()) diff --git a/Pinta.Resources/ResourceManager.cs b/Pinta.Resources/ResourceManager.cs index 709762e191..b49da5cf8c 100644 --- a/Pinta.Resources/ResourceManager.cs +++ b/Pinta.Resources/ResourceManager.cs @@ -131,7 +131,7 @@ private static bool HasResource (Assembly asm, string name) private static Texture CreateMissingImage (int size) { var surf = new Cairo.ImageSurface (Cairo.Format.Argb32, size, size); - var g = new Cairo.Context (surf); + using Cairo.Context g = new (surf); g.SetSourceRgb (1, 1, 1); g.Rectangle (0, 0, size, size); g.Fill (); diff --git a/Pinta.Tools/Editable/EditEngines/BaseEditEngine.cs b/Pinta.Tools/Editable/EditEngines/BaseEditEngine.cs index 8071747216..29055b8f2f 100644 --- a/Pinta.Tools/Editable/EditEngines/BaseEditEngine.cs +++ b/Pinta.Tools/Editable/EditEngines/BaseEditEngine.cs @@ -1151,7 +1151,7 @@ protected RectangleD DrawShape (ShapeEngine engine, Layer l, bool drawCP, bool d Document doc = workspace.ActiveDocument; - var g = new Context (l.Surface); + using Context g = new (l.Surface); g.AppendPath (doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip (); diff --git a/Pinta.Tools/Tools/CloneStampTool.cs b/Pinta.Tools/Tools/CloneStampTool.cs index 038d85b1b6..feba146b10 100644 --- a/Pinta.Tools/Tools/CloneStampTool.cs +++ b/Pinta.Tools/Tools/CloneStampTool.cs @@ -101,7 +101,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) return; } - var g = document.CreateClippedToolContext (); + using Cairo.Context g = document.CreateClippedToolContext (); g.Antialias = UseAntialiasing ? Cairo.Antialias.Subpixel : Cairo.Antialias.None; g.MoveTo (last_point.Value.X, last_point.Value.Y); @@ -124,7 +124,7 @@ protected override void OnMouseUp (Document document, ToolMouseEventArgs e) { painting = false; - var g = new Cairo.Context (document.Layers.CurrentUserLayer.Surface); + using Cairo.Context g = new (document.Layers.CurrentUserLayer.Surface); g.SetSourceSurface (document.Layers.ToolLayer.Surface, 0, 0); g.Paint (); diff --git a/Pinta.Tools/Tools/EraserTool.cs b/Pinta.Tools/Tools/EraserTool.cs index a4fa4dffc1..a943bf2400 100644 --- a/Pinta.Tools/Tools/EraserTool.cs +++ b/Pinta.Tools/Tools/EraserTool.cs @@ -95,7 +95,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) if (document.Workspace.PointInCanvas (new_pointd)) surface_modified = true; - var g = document.CreateClippedContext (); + using Context g = document.CreateClippedContext (); var last_pointd = (PointD) last_point.Value; switch (eraser_type) { case EraserType.Normal: @@ -144,7 +144,7 @@ private static ImageSurface CopySurfacePart (ImageSurface surf, RectangleI dest_ { var tmp_surface = CairoExtensions.CreateImageSurface (Format.Argb32, dest_rect.Width, dest_rect.Height); - var g = new Context (tmp_surface) { Operator = Operator.Source }; + using Context g = new (tmp_surface) { Operator = Operator.Source }; g.SetSourceSurface (surf, -dest_rect.Left, -dest_rect.Top); g.Rectangle (new RectangleD (0, 0, dest_rect.Width, dest_rect.Height)); diff --git a/Pinta.Tools/Tools/FreeformShapeTool.cs b/Pinta.Tools/Tools/FreeformShapeTool.cs index a2140e3ee2..162c3d975f 100644 --- a/Pinta.Tools/Tools/FreeformShapeTool.cs +++ b/Pinta.Tools/Tools/FreeformShapeTool.cs @@ -112,7 +112,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) document.Layers.ToolLayer.Clear (); - var g = document.CreateClippedToolContext (); + using Context g = document.CreateClippedToolContext (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.SetDashFromString (dash_pattern, BrushWidth); @@ -156,7 +156,7 @@ protected override void OnMouseUp (Document document, ToolMouseEventArgs e) document.Layers.ToolLayer.Clear (); document.Layers.ToolLayer.Hidden = true; - Context g = document.CreateClippedContext (); + using Context g = document.CreateClippedContext (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.SetDashFromString (dash_pattern, BrushWidth); diff --git a/Pinta.Tools/Tools/GradientTool.cs b/Pinta.Tools/Tools/GradientTool.cs index 788445dfde..8c99ac273e 100644 --- a/Pinta.Tools/Tools/GradientTool.cs +++ b/Pinta.Tools/Tools/GradientTool.cs @@ -125,7 +125,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) // Initialize the scratch layer with the (original) current layer, if any blending is required. if (gr.AlphaOnly || (gr.AlphaBlending && (gr.StartColor.A != 255 || gr.EndColor.A != 255))) { - var g = new Context (scratch_layer); + using Context g = new (scratch_layer); document.Selection.Clip (g); g.SetSourceSurface (undo_surface!, 0, 0); g.Operator = Operator.Source; @@ -136,7 +136,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) gr.Render (scratch_layer, selection_bounds_array); // Transfer the result back to the current layer. - var context = document.CreateClippedContext (); + using Context context = document.CreateClippedContext (); context.SetSourceSurface (scratch_layer, 0, 0); context.Operator = Operator.Source; context.Paint (); diff --git a/Pinta.Tools/Tools/LassoSelectTool.cs b/Pinta.Tools/Tools/LassoSelectTool.cs index 9965f76919..1bbaab1db2 100644 --- a/Pinta.Tools/Tools/LassoSelectTool.cs +++ b/Pinta.Tools/Tools/LassoSelectTool.cs @@ -90,7 +90,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) var surf = document.Layers.SelectionLayer.Surface; - var g = new Context (surf) { + using Context g = new (surf) { Antialias = Antialias.Subpixel }; @@ -120,7 +120,7 @@ protected override void OnMouseUp (Document document, ToolMouseEventArgs e) { var surf = document.Layers.SelectionLayer.Surface; - var g = new Context (surf); + using Context g = new (surf); if (path != null) { g.AppendPath (path); path = null; diff --git a/Pinta.Tools/Tools/MoveSelectedTool.cs b/Pinta.Tools/Tools/MoveSelectedTool.cs index fcdb7566cd..c5ec247c30 100644 --- a/Pinta.Tools/Tools/MoveSelectedTool.cs +++ b/Pinta.Tools/Tools/MoveSelectedTool.cs @@ -85,20 +85,20 @@ protected override void OnStartTransform (Document document) document.Layers.SelectionLayer.Opacity = document.Layers.CurrentUserLayer.Opacity; document.Layers.SelectionLayer.Hidden = document.Layers.CurrentUserLayer.Hidden; - var g = new Context (document.Layers.SelectionLayer.Surface); - g.AppendPath (document.Selection.SelectionPath); - g.FillRule = FillRule.EvenOdd; - g.SetSourceSurface (document.Layers.CurrentUserLayer.Surface, 0, 0); - g.Clip (); - g.Paint (); + using Context selection_ctx = new (document.Layers.SelectionLayer.Surface); + selection_ctx.AppendPath (document.Selection.SelectionPath); + selection_ctx.FillRule = FillRule.EvenOdd; + selection_ctx.SetSourceSurface (document.Layers.CurrentUserLayer.Surface, 0, 0); + selection_ctx.Clip (); + selection_ctx.Paint (); var surf = document.Layers.CurrentUserLayer.Surface; - g = new Context (surf); - g.AppendPath (document.Selection.SelectionPath); - g.FillRule = FillRule.EvenOdd; - g.Operator = Cairo.Operator.Clear; - g.Fill (); + using Context surf_ctx = new (surf); + surf_ctx.AppendPath (document.Selection.SelectionPath); + surf_ctx.FillRule = FillRule.EvenOdd; + surf_ctx.Operator = Cairo.Operator.Clear; + surf_ctx.Fill (); } document.Workspace.Invalidate (); diff --git a/Pinta.Tools/Tools/PaintBrushTool.cs b/Pinta.Tools/Tools/PaintBrushTool.cs index 3056acccb9..3ca7cd176c 100644 --- a/Pinta.Tools/Tools/PaintBrushTool.cs +++ b/Pinta.Tools/Tools/PaintBrushTool.cs @@ -124,7 +124,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) surface_modified = true; var surf = document.Layers.ToolLayer.Surface; - var g = document.CreateClippedToolContext (); + using Context g = document.CreateClippedToolContext (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.LineWidth = BrushWidth; @@ -148,9 +148,9 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) protected override void OnMouseUp (Document document, ToolMouseEventArgs e) { - var gDest = new Context (document.Layers.CurrentUserLayer.Surface); + using Context g = new (document.Layers.CurrentUserLayer.Surface); - document.Layers.ToolLayer.Draw (gDest); + document.Layers.ToolLayer.Draw (g); document.Layers.ToolLayer.Hidden = true; diff --git a/Pinta.Tools/Tools/PaintBucketTool.cs b/Pinta.Tools/Tools/PaintBucketTool.cs index 9473fada93..f10dea6878 100644 --- a/Pinta.Tools/Tools/PaintBucketTool.cs +++ b/Pinta.Tools/Tools/PaintBucketTool.cs @@ -63,11 +63,11 @@ protected override void OnFillRegionComputed (Document document, BitMask stencil { var surf = document.Layers.ToolLayer.Surface; - var g = new Context (surf) { + using Context tool_layer_ctx = new (surf) { Operator = Operator.Source }; - g.SetSourceSurface (document.Layers.CurrentUserLayer.Surface, 0, 0); - g.Paint (); + tool_layer_ctx.SetSourceSurface (document.Layers.CurrentUserLayer.Surface, 0, 0); + tool_layer_ctx.Paint (); var hist = new SimpleHistoryItem (Icon, Name); hist.TakeSnapshotOfLayer (document.Layers.CurrentUserLayer); @@ -91,10 +91,10 @@ protected override void OnFillRegionComputed (Document document, BitMask stencil // Transfer the temp layer to the real one, // respecting any selection area - g = document.CreateClippedContext (); - g.Operator = Operator.Source; - g.SetSourceSurface (surf, 0, 0); - g.Paint (); + using Context layer_ctx = document.CreateClippedContext (); + layer_ctx.Operator = Operator.Source; + layer_ctx.SetSourceSurface (surf, 0, 0); + layer_ctx.Paint (); document.Layers.ToolLayer.Clear (); document.History.PushNewItem (hist); diff --git a/Pinta.Tools/Tools/PencilTool.cs b/Pinta.Tools/Tools/PencilTool.cs index 95e710f2bf..0d534016b0 100644 --- a/Pinta.Tools/Tools/PencilTool.cs +++ b/Pinta.Tools/Tools/PencilTool.cs @@ -126,7 +126,7 @@ private void Draw (Document document, ToolMouseEventArgs e, Color tool_color, bo if (document.Workspace.PointInCanvas (e.PointDouble)) surface_modified = true; - var g = document.CreateClippedContext (); + using Context g = document.CreateClippedContext (); g.Antialias = Antialias.None; diff --git a/Pinta.Tools/Tools/RecolorTool.cs b/Pinta.Tools/Tools/RecolorTool.cs index a41e1be8bc..855ae86254 100644 --- a/Pinta.Tools/Tools/RecolorTool.cs +++ b/Pinta.Tools/Tools/RecolorTool.cs @@ -143,7 +143,7 @@ protected override void OnMouseMove (Document document, ToolMouseEventArgs e) tmp_layer.MarkDirty (); - var g = document.CreateClippedContext (); + using Context g = document.CreateClippedContext (); g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None; g.MoveTo (last_point.Value.X, last_point.Value.Y); diff --git a/Pinta.Tools/Tools/TextTool.cs b/Pinta.Tools/Tools/TextTool.cs index 61aa84fb01..18a953e812 100644 --- a/Pinta.Tools/Tools/TextTool.cs +++ b/Pinta.Tools/Tools/TextTool.cs @@ -981,7 +981,7 @@ private void RedrawText (bool showCursor, bool useTextLayer) ClearTextLayer (); } - Cairo.Context g = new (surf); + using Cairo.Context g = new (surf); var options = new Cairo.FontOptions (); @@ -1015,7 +1015,7 @@ private void RedrawText (bool showCursor, bool useTextLayer) //Fill in background if (BackgroundFill) { - Cairo.Context g2 = new (surf); + using Cairo.Context g2 = new (surf); selection?.Clip (g2); g2.FillRectangle (CurrentTextLayout.GetLayoutBounds ().ToDouble (), palette.SecondaryColor); diff --git a/Pinta.Tools/Tools/ZoomTool.cs b/Pinta.Tools/Tools/ZoomTool.cs index ef71efd19e..6728789dee 100644 --- a/Pinta.Tools/Tools/ZoomTool.cs +++ b/Pinta.Tools/Tools/ZoomTool.cs @@ -154,7 +154,7 @@ private void UpdateRectangle (Document document, PointD point) document.Layers.ToolLayer.Clear (); document.Layers.ToolLayer.Hidden = false; - var g = new Context (document.Layers.ToolLayer.Surface); + using Context g = new (document.Layers.ToolLayer.Surface); var dirty = g.FillRectangle (r, new Cairo.Color (0.7, 0.8, 0.9, 0.4)); document.Workspace.Invalidate (last_dirty.ToInt ()); diff --git a/Pinta/Actions/Edit/PasteAction.cs b/Pinta/Actions/Edit/PasteAction.cs index d6888732de..30854af0c6 100644 --- a/Pinta/Actions/Edit/PasteAction.cs +++ b/Pinta/Actions/Edit/PasteAction.cs @@ -179,7 +179,7 @@ public static async void Paste ( Math.Max (doc.ImageSize.Height, cb_image.Height)); doc.Layers.ShowSelectionLayer = true; - Cairo.Context g = new (doc.Layers.SelectionLayer.Surface); + using Cairo.Context g = new (doc.Layers.SelectionLayer.Surface); g.SetSourceSurface (cb_image, 0, 0); g.Paint (); diff --git a/tests/Pinta.Core.Tests/Utilities.cs b/tests/Pinta.Core.Tests/Utilities.cs index dcdd1f0091..0b918aa285 100644 --- a/tests/Pinta.Core.Tests/Utilities.cs +++ b/tests/Pinta.Core.Tests/Utilities.cs @@ -103,7 +103,7 @@ public static ImageSurface LoadImage (string imageFilePath) try { var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when error is thrown. var surf = CairoExtensions.CreateImageSurface (Format.Argb32, bg.Width, bg.Height); - var context = new Cairo.Context (surf); + using var context = new Cairo.Context (surf); context.DrawPixbuf (bg, PointD.Zero); return surf; } finally { diff --git a/tests/Pinta.Effects.Tests/Utilities.cs b/tests/Pinta.Effects.Tests/Utilities.cs index be44eaab20..6c2cfb34f1 100644 --- a/tests/Pinta.Effects.Tests/Utilities.cs +++ b/tests/Pinta.Effects.Tests/Utilities.cs @@ -35,7 +35,7 @@ public static ImageSurface LoadImage (string image_name) try { var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when error is thrown. var surf = CairoExtensions.CreateImageSurface (Format.Argb32, bg.Width, bg.Height); - Context context = new (surf); + using Context context = new (surf); context.DrawPixbuf (bg, 0, 0); return surf; } finally { diff --git a/tests/PintaBenchmarks/Utilities/TestData.cs b/tests/PintaBenchmarks/Utilities/TestData.cs index 3033549ff0..423f8bfd20 100644 --- a/tests/PintaBenchmarks/Utilities/TestData.cs +++ b/tests/PintaBenchmarks/Utilities/TestData.cs @@ -19,7 +19,7 @@ public static ImageSurface Get2000PixelImage () try { var bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when error is thrown. var surf = CairoExtensions.CreateImageSurface (Format.Argb32, bg.Width, bg.Height); - var context = new Cairo.Context (surf); + using var context = new Cairo.Context (surf); context.DrawPixbuf (bg, 0, 0); return surf; } finally {