Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Libs/cairo-1.0/Internal/ImageSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class ImageSurface
[DllImport(CairoImportResolver.Library, EntryPoint = "cairo_image_surface_create_for_data")]
public static extern SurfaceOwnedHandle CreateForData(IntPtr data, Cairo.Format format, int width, int height, int stride);

[DllImport(CairoImportResolver.Library, EntryPoint = "cairo_image_surface_create_from_png")]
public static extern SurfaceOwnedHandle CreateFromPng(GLib.Internal.NonNullableUtf8StringOwnedHandle filename);

[DllImport(CairoImportResolver.Library, EntryPoint = "cairo_image_surface_get_data")]
public static extern IntPtr GetData(SurfaceHandle handle);

Expand Down
3 changes: 3 additions & 0 deletions src/Libs/cairo-1.0/Internal/Surface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ public partial class Surface

[DllImport(CairoImportResolver.Library, EntryPoint = "cairo_surface_status")]
public static extern Status Status(SurfaceHandle handle);

[DllImport(CairoImportResolver.Library, EntryPoint = "cairo_surface_write_to_png")]
Comment thread
badcel marked this conversation as resolved.
public static extern Status WriteToPng(SurfaceHandle handle, GLib.Internal.NonNullableUtf8StringOwnedHandle filename);
}
6 changes: 6 additions & 0 deletions src/Libs/cairo-1.0/Public/ImageSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public ImageSurface(GLib.Bytes data, Format format, int width, int height, int s
SetUserData(data);
}

public ImageSurface(string filename) :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like the constructor here as it does not make clear that it is valid for png only.

We should at least rename the parameter to filenamePng or similar. But then there would be no way to create other image surfaces from a file name.

On the other hand I like that it's aligned with the rest of the API.

There is still issue: #1506

So to come to a conclusion: Let's start with a regular constructor in this PR and other considerations come later.

What do you think?

base(Internal.ImageSurface.CreateFromPng(GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(filename)))
{
Handle.AddMemoryPressure(GetSizeInBytes());
}

private void SetUserData(GLib.Bytes data)
{
var userDataHandler = new Internal.UserDataHandler(data.Handle);
Expand Down
6 changes: 6 additions & 0 deletions src/Libs/cairo-1.0/Public/Surface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ public void MarkDirty(int x, int y, int width, int height)
? null
: new Device(deviceHandle.OwnedCopy());
}

public Status WriteToPng(string filename)
Comment thread
badcel marked this conversation as resolved.
{
using var filenameNative = GLib.Internal.NonNullableUtf8StringOwnedHandle.Create(filename);
return Internal.Surface.WriteToPng(Handle, filenameNative);
}
}
Loading