diff --git a/canvas.go b/canvas.go index 92a7e07..1aa3ab7 100644 --- a/canvas.go +++ b/canvas.go @@ -267,5 +267,5 @@ func (c *Canvas) IsClipRect() bool { // Flush any drawing. func (c *Canvas) Flush() { - skia.CanvasFlush(c.canvas) + c.surface.flush(true) } diff --git a/color_filter.go b/color_filter.go index 6773f0f..0762f65 100644 --- a/color_filter.go +++ b/color_filter.go @@ -90,32 +90,6 @@ func NewHighContrastColorFilter(contrast float32, style InvertStyle, grayscale b })) } -// NewARGBTableColorFilter returns a new ARGB table color filter. Each of a, r, g, and b should be 256 bytes long. If -// shorter than that, they will be expanded to 256 and the new locations will be set to 0. -func NewARGBTableColorFilter(a, r, g, b []byte) *ColorFilter { - if len(a) < 256 { - a1 := make([]byte, 256) - copy(a1, a) - a = a1 - } - if len(r) < 256 { - r1 := make([]byte, 256) - copy(r1, r) - r = r1 - } - if len(g) < 256 { - g1 := make([]byte, 256) - copy(g1, g) - g = g1 - } - if len(b) < 256 { - b1 := make([]byte, 256) - copy(b1, b) - b = b1 - } - return newColorFilter(skia.ColorFilterNewTableARGB(a, r, g, b)) -} - // NewAlphaFilter returns a new ColorFilter that applies an alpha blend. func NewAlphaFilter(alpha float32) *ColorFilter { return NewMatrixColorFilter([]float32{ diff --git a/console_windows.go b/console_windows.go index c5423ae..97d7c2d 100644 --- a/console_windows.go +++ b/console_windows.go @@ -18,9 +18,9 @@ import ( ) var ( - preservedStdin *os.File - preservedStdout *os.File - preservedStderr *os.File + preservedStdin *os.File //nolint:unused // We don't want them garbage collected + preservedStdout *os.File //nolint:unused // We don't want them garbage collected + preservedStderr *os.File //nolint:unused // We don't want them garbage collected ) func attachConsole() { @@ -30,9 +30,9 @@ func attachConsole() { preservedStderr = os.Stderr // Get the existing stdin/stdout/stderr handles. - stdin, _ := syscall.GetStdHandle(syscall.STD_INPUT_HANDLE) - stdout, _ := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE) - stderr, _ := syscall.GetStdHandle(syscall.STD_ERROR_HANDLE) + stdin, _ := syscall.GetStdHandle(syscall.STD_INPUT_HANDLE) //nolint:errcheck // A result of 0 is adequate + stdout, _ := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE) //nolint:errcheck // A result of 0 is adequate + stderr, _ := syscall.GetStdHandle(syscall.STD_ERROR_HANDLE) //nolint:errcheck // A result of 0 is adequate // Attach the console if any of stdin/stdout/stderr are currently unattached, loading the newly-found handles for // the unattached ones. @@ -40,14 +40,14 @@ func attachConsole() { if stdin == 0 || stdout == 0 || stderr == 0 { if w32.AttachConsole(w32.AttachParentProcessID) { if stdin == 0 { - stdin, _ = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE) + stdin, _ = syscall.GetStdHandle(syscall.STD_INPUT_HANDLE) //nolint:errcheck // A result of 0 is adequate } if stdout == 0 { - stdout, _ = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE) + stdout, _ = syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE) //nolint:errcheck // A result of 0 is adequate console = stdout } if stderr == 0 { - stderr, _ = syscall.GetStdHandle(syscall.STD_ERROR_HANDLE) + stderr, _ = syscall.GetStdHandle(syscall.STD_ERROR_HANDLE) //nolint:errcheck // A result of 0 is adequate console = stderr } } @@ -57,7 +57,7 @@ func attachConsole() { if console != 0 { var mode uint32 if err := windows.GetConsoleMode(windows.Handle(console), &mode); err == nil { - windows.SetConsoleMode(windows.Handle(console), mode&^windows.DISABLE_NEWLINE_AUTO_RETURN) + _ = windows.SetConsoleMode(windows.Handle(console), mode&^windows.DISABLE_NEWLINE_AUTO_RETURN) //nolint:errcheck // Don't care } } diff --git a/go.mod b/go.mod index 12e1d63..376cf6c 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/uuid v1.3.1 github.com/grandcat/zeroconf v1.0.0 github.com/richardwilkes/json v0.1.0 - github.com/richardwilkes/toolbox v1.99.1-0.20230919233933-76855faa28f3 + github.com/richardwilkes/toolbox v1.100.0 github.com/yuin/goldmark v1.5.6 golang.org/x/image v0.12.0 golang.org/x/sys v0.12.0 diff --git a/go.sum b/go.sum index 8de579f..dd5686f 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk= github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= github.com/richardwilkes/json v0.1.0 h1:a+ihnd/BqcckTWCOgC80U8dcT5CJrlAHVxMkSDderkw= github.com/richardwilkes/json v0.1.0/go.mod h1:4maPYRzwKz+kN/HWUd1re9kco0eoN6znhPBBqX0p+gk= -github.com/richardwilkes/toolbox v1.99.1-0.20230919233933-76855faa28f3 h1:DHUcHWRmdL9bnals8T+wQ9nyEEKj01Gf+cYHtALhRzY= -github.com/richardwilkes/toolbox v1.99.1-0.20230919233933-76855faa28f3/go.mod h1:D+INXm3TBCdjEEkUJwVju7ZW/6YihAj825d1GjRUtqA= +github.com/richardwilkes/toolbox v1.100.0 h1:xJjGMQ4oqtAwqkok3XyVMn7flF5PbBmPP9n+xqm/WPU= +github.com/richardwilkes/toolbox v1.100.0/go.mod h1:D+INXm3TBCdjEEkUJwVju7ZW/6YihAj825d1GjRUtqA= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= diff --git a/image.go b/image.go index f4c5251..7a403d0 100644 --- a/image.go +++ b/image.go @@ -22,6 +22,7 @@ import ( "github.com/richardwilkes/toolbox/errs" "github.com/richardwilkes/toolbox/softref" "github.com/richardwilkes/toolbox/xio" + "github.com/richardwilkes/toolbox/xmath" "github.com/richardwilkes/unison/internal/skia" ) @@ -102,7 +103,13 @@ func NewImageFromPixels(width, height int, pixels []byte, scale float32) (*Image func NewImageFromDrawing(width, height, ppi int, draw func(*Canvas)) (*Image, error) { scale := float32(ppi) / 72 s := &surface{ - surface: skia.SurfaceMakeRasterN32PreMul(int(float32(width)*scale), int(float32(height)*scale), defaultSurfaceProps()), + surface: skia.SurfaceMakeRasterN32PreMul(&skia.ImageInfo{ + Colorspace: skiaColorspace, + Width: int32(xmath.Ceil(float32(width) * scale)), + Height: int32(xmath.Ceil(float32(height) * scale)), + ColorType: skia.ColorTypeRGBA8888, + AlphaType: skia.AlphaTypeUnPreMul, + }, defaultSurfaceProps()), } c := &Canvas{ canvas: skia.SurfaceGetCanvas(s.surface), @@ -200,30 +207,36 @@ func (img *Image) ToNRGBA() (*image.NRGBA, error) { }, nil } -// ToPNG creates PNG data from the image. -func (img *Image) ToPNG() ([]byte, error) { - return img.encode(PNG, 100) +// ToPNG creates PNG data from the image. 'compressionLevel' should in the range 0-9 and is equivalent to +// the zlib compression level. A typical compression level is 6 and is equivalent to the zlib default. +func (img *Image) ToPNG(compressionLevel int) ([]byte, error) { + data := skia.EncodePNG(nil, img.ref().img, compressionLevel) + if data == nil { + return nil, errs.New("unable to create PNG from image") + } + buffer := make([]byte, skia.DataGetSize(data)) + copy(buffer, ((*[1 << 30]byte)(skia.DataGetData(data)))[:len(buffer)]) + skia.DataUnref(data) + return buffer, nil } // ToJPEG creates JPEG data from the image. quality should be greater than 0 and equal to or less than 100. func (img *Image) ToJPEG(quality int) ([]byte, error) { - return img.encode(JPEG, quality) + data := skia.EncodeJPEG(nil, img.ref().img, quality) + if data == nil { + return nil, errs.New("unable to create JPEG from image") + } + buffer := make([]byte, skia.DataGetSize(data)) + copy(buffer, ((*[1 << 30]byte)(skia.DataGetData(data)))[:len(buffer)]) + skia.DataUnref(data) + return buffer, nil } // ToWebp creates Webp data from the image. quality should be greater than 0 and equal to or less than 100. -func (img *Image) ToWebp(quality int) ([]byte, error) { - return img.encode(WEBP, quality) -} - -func (img *Image) encode(format EncodedImageFormat, quality int) ([]byte, error) { - if quality < 1 { - quality = 1 - } else if quality > 100 { - quality = 100 - } - data := skia.ImageEncodeSpecific(img.ref().img, skia.EncodedImageFormat(format), quality) +func (img *Image) ToWebp(quality float32, lossy bool) ([]byte, error) { + data := skia.EncodeWebp(nil, img.ref().img, quality, lossy) if data == nil { - return nil, errs.Newf("unable to create %s from image", format) + return nil, errs.New("unable to create WEBP from image") } buffer := make([]byte, skia.DataGetSize(data)) copy(buffer, ((*[1 << 30]byte)(skia.DataGetData(data)))[:len(buffer)]) @@ -269,7 +282,7 @@ func (ref *imageRef) contextImg(s *surface) skia.Image { if ctx == nil { i = skia.ImageMakeNonTextureImage(ref.img) } else { - i = skia.ImageMakeTextureImage(ref.img, ctx, false) + i = skia.ImageTextureFromImage(ctx, ref.img, false, true) } if i != nil { m[ref.hash] = i diff --git a/image_filter.go b/image_filter.go index cb40db0..55c2b92 100644 --- a/image_filter.go +++ b/image_filter.go @@ -140,7 +140,7 @@ func NewImageSourceImageFilter(canvas *Canvas, img *Image, srcRect, dstRect Rect // NewImageSourceDefaultImageFilter returns a new image source image filter that uses the default quality and the full // image size. If canvas is not nil, a hardware-accellerated image will be used if possible. -func NewImageSourceDefaultImageFilter(canvas *Canvas, img *Image) *ImageFilter { +func NewImageSourceDefaultImageFilter(canvas *Canvas, img *Image, sampling *SamplingOptions) *ImageFilter { var image skia.Image ref := img.ref() if canvas == nil { @@ -148,17 +148,17 @@ func NewImageSourceDefaultImageFilter(canvas *Canvas, img *Image) *ImageFilter { } else { image = ref.contextImg(canvas.surface) } - return newImageFilter(skia.ImageFilterNewImageSourceDefault(image)) + return newImageFilter(skia.ImageFilterNewImageSourceDefault(image, sampling.skSamplingOptions())) } // NewMagnifierImageFilter returns a new magnifier image filter. input may be nil, in which case the source bitmap will // be used. cropRect may be nil. -func NewMagnifierImageFilter(src Rect, inset float32, input *ImageFilter, cropRect *Rect) *ImageFilter { +func NewMagnifierImageFilter(lensBounds Rect, zoomAmount, inset float32, sampling *SamplingOptions, input *ImageFilter, cropRect *Rect) *ImageFilter { var in skia.ImageFilter if input != nil { in = input.filter } - return newImageFilter(skia.ImageFilterNewMagnifier(src, inset, in, cropRect)) + return newImageFilter(skia.ImageFilterNewMagnifier(lensBounds, zoomAmount, inset, sampling.skSamplingOptions(), in, cropRect)) } // NewMatrixConvolutionImageFilter returns a new matrix convolution image filter. diff --git a/image_format.go b/image_format.go index f78ac9b..b3ab390 100644 --- a/image_format.go +++ b/image_format.go @@ -13,6 +13,8 @@ import ( "net/url" "path" "strings" + + "github.com/richardwilkes/unison/internal/skia" ) // InvalidImageFormatStr is returned for as an error indicator for some methods on EncodedImageFormat. @@ -101,6 +103,7 @@ var ( ) func init() { + skia.RegisterImageCodecs() for i, one := range knownImageFormats { KnownImageFormatFormats[i] = EncodedImageFormat(i) for _, ext := range one.Extensions { diff --git a/internal/skia/libskia_darwin_amd64.a b/internal/skia/libskia_darwin_amd64.a index 3a0264c..0b0a1a8 100644 Binary files a/internal/skia/libskia_darwin_amd64.a and b/internal/skia/libskia_darwin_amd64.a differ diff --git a/internal/skia/libskia_darwin_arm64.a b/internal/skia/libskia_darwin_arm64.a index e3f79f7..a6ad5e8 100644 Binary files a/internal/skia/libskia_darwin_arm64.a and b/internal/skia/libskia_darwin_arm64.a differ diff --git a/internal/skia/libskia_linux.a b/internal/skia/libskia_linux.a index 651639c..b4800aa 100644 Binary files a/internal/skia/libskia_linux.a and b/internal/skia/libskia_linux.a differ diff --git a/internal/skia/sk_capi.h b/internal/skia/sk_capi.h index 56e624a..f09ea51 100644 --- a/internal/skia/sk_capi.h +++ b/internal/skia/sk_capi.h @@ -193,6 +193,7 @@ typedef enum { typedef struct { unsigned int fFBOID; unsigned int fFormat; + bool fProtected; } gr_gl_framebufferinfo_t; // ===== Types from include/gpu/GrDirectContext.h ===== @@ -322,21 +323,22 @@ typedef struct sk_paint_t sk_paint_t; // ===== Types from include/core/SkColorType.h ===== typedef enum { - SK_COLOR_TYPE_UNKNOWN, // uninitialized - SK_COLOR_TYPE_ALPHA_8, // pixel with alpha in 8-bit byte - SK_COLOR_TYPE_RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word - SK_COLOR_TYPE_ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word - SK_COLOR_TYPE_RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word - SK_COLOR_TYPE_RGB_888X, // pixel with 8 bits each for red, green, blue; in 32-bit word - SK_COLOR_TYPE_BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word - SK_COLOR_TYPE_RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word - SK_COLOR_TYPE_BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word - SK_COLOR_TYPE_RGB_101010X, // pixel with 10 bits each for red, green, blue; in 32-bit word - SK_COLOR_TYPE_BGR_101010X, // pixel with 10 bits each for blue, green, red; in 32-bit word - SK_COLOR_TYPE_GRAY_8, // pixel with grayscale level in 8-bit byte - SK_COLOR_TYPE_RGBA_F16_NORM, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word - SK_COLOR_TYPE_RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word - SK_COLOR_TYPE_RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word + SK_COLOR_TYPE_UNKNOWN, // uninitialized + SK_COLOR_TYPE_ALPHA_8, // pixel with alpha in 8-bit byte + SK_COLOR_TYPE_RGB_565, // pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word + SK_COLOR_TYPE_ARGB_4444, // pixel with 4 bits for alpha, red, green, blue; in 16-bit word + SK_COLOR_TYPE_RGBA_8888, // pixel with 8 bits for red, green, blue, alpha; in 32-bit word + SK_COLOR_TYPE_RGB_888X, // pixel with 8 bits each for red, green, blue; in 32-bit word + SK_COLOR_TYPE_BGRA_8888, // pixel with 8 bits for blue, green, red, alpha; in 32-bit word + SK_COLOR_TYPE_RGBA_1010102, // 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word + SK_COLOR_TYPE_BGRA_1010102, // 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word + SK_COLOR_TYPE_RGB_101010X, // pixel with 10 bits each for red, green, blue; in 32-bit word + SK_COLOR_TYPE_BGR_101010X, // pixel with 10 bits each for blue, green, red; in 32-bit word + SK_COLOR_TYPE_BGR_101010X_XR, // pixel with 10 bits each for blue, green, red; in 32-bit word, extended range + SK_COLOR_TYPE_GRAY_8, // pixel with grayscale level in 8-bit byte + SK_COLOR_TYPE_RGBA_F16_NORM, // pixel with half floats in [0,1] for red, green, blue, alpha; in 64-bit word + SK_COLOR_TYPE_RGBA_F16, // pixel with half floats for red, green, blue, alpha; in 64-bit word + SK_COLOR_TYPE_RGBA_F32, // pixel using C float for red, green, blue, alpha; in 128-bit word // The following color types are read-only SK_COLOR_TYPE_R8G8_UNORM, // pixel with a uint8_t for red and green @@ -393,23 +395,6 @@ typedef struct sk_image_filter_t sk_image_filter_t; typedef struct sk_mask_filter_t sk_mask_filter_t; -// ===== Types from include/core/SkEncodedImageFormat.h ===== - -typedef enum { - SK_ENCODED_FORMAT_BMP, - SK_ENCODED_FORMAT_GIF, - SK_ENCODED_FORMAT_ICO, - SK_ENCODED_FORMAT_JPEG, - SK_ENCODED_FORMAT_PNG, - SK_ENCODED_FORMAT_WBMP, - SK_ENCODED_FORMAT_WEBP, - SK_ENCODED_FORMAT_PKM, - SK_ENCODED_FORMAT_KTX, - SK_ENCODED_FORMAT_ASTC, - SK_ENCODED_FORMAT_DNG, - SK_ENCODED_FORMAT_HEIF, -} sk_encoded_image_format_t; - // ===== Types from include/core/SkColorFilter.h ===== typedef struct sk_color_filter_t sk_color_filter_t; @@ -612,12 +597,13 @@ SK_C_API void gr_backendrendertarget_delete(gr_backendrendertarget_t* rendertarg SK_C_API gr_direct_context_t* gr_direct_context_make_gl(const gr_glinterface_t* glInterface); // ===== Functions from include/gpu/GrDirectContext.h ===== -SK_C_API void gr_direct_context_delete(gr_direct_context_t* context); SK_C_API void gr_direct_context_abandon_context(gr_direct_context_t* context); +SK_C_API void gr_direct_context_delete(gr_direct_context_t* context); +SK_C_API void gr_direct_context_flush_and_submit(gr_direct_context_t* context, bool syncCPU); SK_C_API void gr_direct_context_release_resources_and_abandon_context(gr_direct_context_t* context); -SK_C_API void gr_direct_context_unref(const gr_direct_context_t* context); -SK_C_API void gr_direct_context_reset_gl_texture_bindings(gr_direct_context_t* context); SK_C_API void gr_direct_context_reset(gr_direct_context_t* context); +SK_C_API void gr_direct_context_reset_gl_texture_bindings(gr_direct_context_t* context); +SK_C_API void gr_direct_context_unref(const gr_direct_context_t* context); // ===== Functions from include/gpu/gl/GrGLInterface.h ===== SK_C_API const gr_glinterface_t* gr_glinterface_create_native_interface(void); @@ -644,7 +630,6 @@ SK_C_API void sk_canvas_draw_rect(sk_canvas_t* canvas, const sk_rect_t* crect, c SK_C_API void sk_canvas_draw_round_rect(sk_canvas_t* canvas, const sk_rect_t* crect, float rx, float ry, const sk_paint_t* cpaint); SK_C_API void sk_canvas_draw_simple_text(sk_canvas_t* canvas, const void* text, size_t byte_length, sk_text_encoding_t encoding, float x, float y, const sk_font_t* cfont, const sk_paint_t* cpaint); SK_C_API void sk_canvas_draw_text_blob (sk_canvas_t* canvas, sk_text_blob_t* text, float x, float y, const sk_paint_t* paint); -SK_C_API void sk_canvas_flush(sk_canvas_t* canvas); SK_C_API bool sk_canvas_get_local_clip_bounds(sk_canvas_t* canvas, sk_rect_t* cbounds); SK_C_API int sk_canvas_get_save_count(sk_canvas_t* canvas); SK_C_API void sk_canvas_get_total_matrix(sk_canvas_t* canvas, sk_matrix_t* matrix); @@ -671,7 +656,6 @@ SK_C_API sk_color_filter_t* sk_colorfilter_new_high_contrast(const sk_high_contr SK_C_API sk_color_filter_t* sk_colorfilter_new_lighting(sk_color_t mul, sk_color_t add); SK_C_API sk_color_filter_t* sk_colorfilter_new_luma_color(void); SK_C_API sk_color_filter_t* sk_colorfilter_new_mode(sk_color_t c, sk_blend_mode_t mode); -SK_C_API sk_color_filter_t* sk_colorfilter_new_table_argb(const uint8_t tableA[256], const uint8_t tableR[256], const uint8_t tableG[256], const uint8_t tableB[256]); SK_C_API void sk_colorfilter_unref(sk_color_filter_t* filter); // ===== Functions from include/core/SkColorSpace.h ===== @@ -683,6 +667,15 @@ SK_C_API size_t sk_data_get_size(const sk_data_t* data); SK_C_API sk_data_t* sk_data_new_with_copy(const void* src, size_t length); SK_C_API void sk_data_unref(const sk_data_t* data); +// ===== Functions from include/encode/SkJpegEncoder.h ===== +SK_C_API sk_data_t* sk_encode_jpeg(gr_direct_context_t* ctx, const sk_image_t* img, int quality); + +// ===== Functions from include/encode/SkPngEncoder.h ===== +SK_C_API sk_data_t* sk_encode_png(gr_direct_context_t* ctx, const sk_image_t* img, int compressionLevel); + +// ===== Functions from include/encode/SkWebpEncoder.h ===== +SK_C_API sk_data_t* sk_encode_webp(gr_direct_context_t* ctx, const sk_image_t* img, float quality, bool lossy); + // ===== Functions from include/core/SkFont.h ===== SK_C_API void sk_font_delete(sk_font_t* font); SK_C_API float sk_font_get_metrics(const sk_font_t* font, sk_font_metrics_t* metrics); @@ -720,7 +713,6 @@ SK_C_API int sk_fontstyle_get_width(const sk_font_style_t* fs); SK_C_API sk_font_style_t* sk_fontstyle_new(int weight, int width, sk_font_style_slant_t slant); // ===== Functions from include/core/SkImage.h ===== -SK_C_API sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_encoded_image_format_t encoder, int quality); SK_C_API sk_alpha_type_t sk_image_get_alpha_type(const sk_image_t* image); SK_C_API sk_color_type_t sk_image_get_color_type(const sk_image_t* image); SK_C_API sk_color_space_t* sk_image_get_colorspace(const sk_image_t* image); @@ -728,12 +720,14 @@ SK_C_API int sk_image_get_height(const sk_image_t* image); SK_C_API int sk_image_get_width(const sk_image_t* image); SK_C_API sk_image_t* sk_image_make_non_texture_image(const sk_image_t* image); SK_C_API sk_shader_t* sk_image_make_shader(const sk_image_t* image, sk_tile_mode_t tileX, sk_tile_mode_t tileY, const sk_sampling_options_t *samplingOptions, const sk_matrix_t* cmatrix); -SK_C_API sk_image_t* sk_image_make_texture_image(const sk_image_t* image, gr_direct_context_t* context, bool mipmapped); SK_C_API sk_image_t* sk_image_new_from_encoded(sk_data_t* encoded); SK_C_API sk_image_t* sk_image_new_raster_data(const sk_image_info_t* cinfo, sk_data_t* pixels, size_t rowBytes); SK_C_API bool sk_image_read_pixels(const sk_image_t* image, const sk_image_info_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, sk_image_caching_hint_t cachingHint); SK_C_API void sk_image_unref(const sk_image_t* image); +// ===== Functions from include/gpu/ganesh/SkImageGanesh.h ===== +SK_C_API sk_image_t* sk_image_texture_from_image(gr_direct_context_t* ctx, const sk_image_t* image, bool mipmapped, bool budgeted); + // ===== Functions from include/core/SkImageFilter.h ===== SK_C_API sk_image_filter_t* sk_imagefilter_new_arithmetic(float k1, float k2, float k3, float k4, bool enforcePMColor, sk_image_filter_t* background, sk_image_filter_t* foreground, const sk_rect_t* rect); SK_C_API sk_image_filter_t* sk_imagefilter_new_blur(float sigmaX, float sigmaY, sk_tile_mode_t tileMode, sk_image_filter_t* input, const sk_rect_t* rect); @@ -747,8 +741,8 @@ SK_C_API sk_image_filter_t* sk_imagefilter_new_drop_shadow(float dx, float dy, f SK_C_API sk_image_filter_t* sk_imagefilter_new_drop_shadow_only(float dx, float dy, float sigmaX, float sigmaY, sk_color_t color, sk_image_filter_t* input, const sk_rect_t* rect); SK_C_API sk_image_filter_t* sk_imagefilter_new_erode(int radiusX, int radiusY, sk_image_filter_t* input, const sk_rect_t* rect); SK_C_API sk_image_filter_t* sk_imagefilter_new_image_source(sk_image_t* image, const sk_rect_t* srcRect, const sk_rect_t* dstRect, const sk_sampling_options_t* samplingOptions); -SK_C_API sk_image_filter_t* sk_imagefilter_new_image_source_default(sk_image_t* image); -SK_C_API sk_image_filter_t* sk_imagefilter_new_magnifier(const sk_rect_t* src, float inset, sk_image_filter_t* input, const sk_rect_t* rect); +SK_C_API sk_image_filter_t* sk_imagefilter_new_image_source_default(sk_image_t* image, const sk_sampling_options_t* samplingOptions); +SK_C_API sk_image_filter_t* sk_imagefilter_new_magnifier(const sk_rect_t* lensBounds, float zoomAmount, float inset, const sk_sampling_options_t* samplingOptions, sk_image_filter_t* input, const sk_rect_t* rect); SK_C_API sk_image_filter_t* sk_imagefilter_new_matrix_convolution(const sk_isize_t* kernelSize, const float kernel[], float gain, float bias, const sk_ipoint_t* kernelOffset, sk_tile_mode_t tileMode, bool convolveAlpha, sk_image_filter_t* input, const sk_rect_t* rect); SK_C_API sk_image_filter_t* sk_imagefilter_new_matrix_transform(const sk_matrix_t* matrix, const sk_sampling_options_t *samplingOptions, sk_image_filter_t* input); SK_C_API sk_image_filter_t* sk_imagefilter_new_merge(sk_image_filter_t* filters[], int count, const sk_rect_t* rect); @@ -822,10 +816,12 @@ SK_C_API sk_path_t* sk_path_clone(const sk_path_t* cpath); SK_C_API void sk_path_close(sk_path_t* cpath); SK_C_API void sk_path_compute_tight_bounds(const sk_path_t* cpath, sk_rect_t* crect); SK_C_API void sk_path_conic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float w); -SK_C_API bool sk_path_contains (const sk_path_t* cpath, float x, float y); +SK_C_API bool sk_path_contains(const sk_path_t* cpath, float x, float y); +SK_C_API int sk_path_count_points(const sk_path_t* cpath); SK_C_API void sk_path_cubic_to(sk_path_t*, float x0, float y0, float x1, float y1, float x2, float y2); SK_C_API void sk_path_delete(sk_path_t* cpath); SK_C_API void sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect); +SK_C_API int sk_path_get_points(const sk_path_t* cpath, sk_point_t* points, int max); SK_C_API sk_path_fill_type_t sk_path_get_filltype(sk_path_t *cpath); SK_C_API bool sk_path_get_last_point(const sk_path_t* cpath, sk_point_t* point); SK_C_API void sk_path_line_to(sk_path_t *cpath, float x, float y); @@ -887,7 +883,7 @@ SK_C_API size_t sk_string_get_size(const sk_string_t* str); // ===== Functions from include/core/SkSurface.h ===== SK_C_API sk_surface_t* sk_surface_make_raster_direct(const sk_image_info_t *imageInfo, void *pixels, size_t rowBytes, sk_surface_props_t* surfaceProps); -SK_C_API sk_surface_t* sk_surface_make_raster_n32_premul(int width, int height, sk_surface_props_t* surfaceProps); +SK_C_API sk_surface_t* sk_surface_make_raster_n32_premul(const sk_image_info_t *imageInfo, sk_surface_props_t* surfaceProps); SK_C_API sk_image_t* sk_surface_make_image_snapshot(sk_surface_t* surface); SK_C_API sk_canvas_t* sk_surface_get_canvas(sk_surface_t* surface); SK_C_API sk_surface_t* sk_surface_new_backend_render_target(gr_direct_context_t* context, const gr_backendrendertarget_t* target, gr_surface_origin_t origin, sk_color_type_t colorType, sk_color_space_t* colorspace, const sk_surface_props_t* props); @@ -941,6 +937,9 @@ SK_C_API void sk_document_abort(sk_document_t* doc); // ===== Functions from include/docs/SkPDFDocument.h ===== SK_C_API sk_document_t* sk_document_make_pdf(sk_wstream_t* stream, sk_metadata_t* metadata); +// ===== Functions from include/codec/SkCodec.h ===== +SK_C_API void register_image_codecs(); + #ifdef __cplusplus } #endif // __cplusplus diff --git a/internal/skia/skia.go b/internal/skia/skia.go index d99eb16..83e53f9 100644 --- a/internal/skia/skia.go +++ b/internal/skia/skia.go @@ -96,6 +96,7 @@ const ( ColorTypeBGRA1010102 ColorTypeRGB101010X ColorTypeBGR101010X + ColorTypeBGR101010XXR ColorTypeGray8 ColorTypeRGBAF16Norm ColorTypeRGBAF16 @@ -170,8 +171,9 @@ type Matrix struct { } type GLFrameBufferInfo struct { - Fboid uint32 - Format uint32 + Fboid uint32 + Format uint32 + Protected bool } type ImageInfo struct { diff --git a/internal/skia/skia_other.go b/internal/skia/skia_other.go index e6f8b2a..59ccfa8 100644 --- a/internal/skia/skia_other.go +++ b/internal/skia/skia_other.go @@ -96,6 +96,10 @@ func ContextDelete(ctx DirectContext) { C.gr_direct_context_delete(ctx) } +func ContextFlushAndSubmit(ctx DirectContext, syncCPU bool) { + C.gr_direct_context_flush_and_submit(ctx, C.bool(syncCPU)) +} + func ContextResetGLTextureBindings(ctx DirectContext) { C.gr_direct_context_reset_gl_texture_bindings(ctx) } @@ -290,10 +294,6 @@ func CanvasIsClipRect(canvas Canvas) bool { return bool(C.sk_canvas_is_clip_rect(canvas)) } -func CanvasFlush(canvas Canvas) { - C.sk_canvas_flush(canvas) -} - func ColorFilterNewMode(color Color, blendMode BlendMode) ColorFilter { return C.sk_colorfilter_new_mode(C.sk_color_t(color), C.sk_blend_mode_t(blendMode)) } @@ -318,11 +318,6 @@ func ColorFilterNewHighContrast(config *HighContrastConfig) ColorFilter { return C.sk_colorfilter_new_high_contrast((*C.sk_high_contrast_config_t)(unsafe.Pointer(config))) } -func ColorFilterNewTableARGB(a, r, g, b []byte) ColorFilter { - return C.sk_colorfilter_new_table_argb((*C.uint8_t)(unsafe.Pointer(&a[0])), (*C.uint8_t)(unsafe.Pointer(&r[0])), - (*C.uint8_t)(unsafe.Pointer(&g[0])), (*C.uint8_t)(unsafe.Pointer(&b[0]))) -} - func ColorFilterUnref(filter ColorFilter) { C.sk_colorfilter_unref(filter) } @@ -347,6 +342,18 @@ func DataUnref(data Data) { C.sk_data_unref(data) } +func EncodeJPEG(ctx DirectContext, img Image, quality int) Data { + return C.sk_encode_jpeg(ctx, img, C.int(quality)) +} + +func EncodePNG(ctx DirectContext, img Image, compressionLevel int) Data { + return C.sk_encode_png(ctx, img, C.int(compressionLevel)) +} + +func EncodeWebp(ctx DirectContext, img Image, quality float32, lossy bool) Data { + return C.sk_encode_webp(ctx, img, C.float(quality), C.bool(lossy)) +} + func DocumentMakePDF(stream WStream, metadata *MetaData) Document { var md metaData md.set(metadata) @@ -587,8 +594,8 @@ func ImageReadPixels(img Image, info *ImageInfo, pixels []byte, dstRowBytes, src C.size_t(dstRowBytes), C.int(srcX), C.int(srcY), C.sk_image_caching_hint_t(cachingHint))) } -func ImageEncodeSpecific(img Image, format EncodedImageFormat, quality int) Data { - return C.sk_image_encode_specific(img, C.sk_encoded_image_format_t(format), C.int(quality)) +func ImageMakeNonTextureImage(img Image) Image { + return C.sk_image_make_non_texture_image(img) } func ImageMakeShader(img Image, tileModeX, tileModeY TileMode, sampling SamplingOptions, matrix geom.Matrix[float32]) Shader { @@ -596,12 +603,8 @@ func ImageMakeShader(img Image, tileModeX, tileModeY TileMode, sampling Sampling fromGeomMatrix(&matrix)) } -func ImageMakeTextureImage(img Image, ctx DirectContext, mipMapped bool) Image { - return C.sk_image_make_texture_image(img, ctx, C.bool(mipMapped)) -} - -func ImageMakeNonTextureImage(img Image) Image { - return C.sk_image_make_non_texture_image(img) +func ImageTextureFromImage(ctx DirectContext, img Image, mipMapped, budgeted bool) Image { + return C.sk_image_texture_from_image(ctx, img, C.bool(mipMapped), C.bool(budgeted)) } func ImageUnref(img Image) { @@ -645,12 +648,12 @@ func ImageFilterNewImageSource(img Image, srcRect, dstRect geom.Rect[float32], s return C.sk_imagefilter_new_image_source(img, fromGeomRect(&srcRect), fromGeomRect(&dstRect), sampling) } -func ImageFilterNewImageSourceDefault(img Image) ImageFilter { - return C.sk_imagefilter_new_image_source_default(img) +func ImageFilterNewImageSourceDefault(img Image, sampling SamplingOptions) ImageFilter { + return C.sk_imagefilter_new_image_source_default(img, sampling) } -func ImageFilterNewMagnifier(src geom.Rect[float32], inset float32, input ImageFilter, cropRect *geom.Rect[float32]) ImageFilter { - return C.sk_imagefilter_new_magnifier(fromGeomRect(&src), C.float(inset), input, fromGeomRect(cropRect)) +func ImageFilterNewMagnifier(lensBounds geom.Rect[float32], zoomAmount, inset float32, sampling SamplingOptions, input ImageFilter, cropRect *geom.Rect[float32]) ImageFilter { + return C.sk_imagefilter_new_magnifier(fromGeomRect(&lensBounds), C.float(zoomAmount), C.float(inset), sampling, input, fromGeomRect(cropRect)) } func ImageFilterNewMatrixConvolution(size *ISize, kernel []float32, gain, bias float32, offset *IPoint, tileMode TileMode, convolveAlpha bool, input ImageFilter, cropRect *geom.Rect[float32]) ImageFilter { @@ -1109,6 +1112,10 @@ func PathEffectUnref(effect PathEffect) { C.sk_path_effect_unref(effect) } +func RegisterImageCodecs() { + C.register_image_codecs() +} + func ShaderNewColor(color Color) Shader { return C.sk_shader_new_color(C.sk_color_t(color)) } @@ -1191,8 +1198,8 @@ func SurfaceMakeRasterDirect(info *ImageInfo, pixels []byte, rowBytes int, surfa return C.sk_surface_make_raster_direct((*C.sk_image_info_t)(unsafe.Pointer(info)), unsafe.Pointer(&pixels[0]), C.size_t(rowBytes), surfaceProps) } -func SurfaceMakeRasterN32PreMul(width, height int, surfaceProps SurfaceProps) Surface { - return C.sk_surface_make_raster_n32_premul(C.int(width), C.int(height), surfaceProps) +func SurfaceMakeRasterN32PreMul(info *ImageInfo, surfaceProps SurfaceProps) Surface { + return C.sk_surface_make_raster_n32_premul((*C.sk_image_info_t)(unsafe.Pointer(info)), surfaceProps) } func SurfaceNewBackendRenderTarget(ctx DirectContext, backend BackendRenderTarget, origin SurfaceOrigin, colorType ColorType, colorSpace ColorSpace, surfaceProps SurfaceProps) Surface { diff --git a/internal/skia/skia_windows.dll b/internal/skia/skia_windows.dll index 017fb00..b4fbc1d 100644 Binary files a/internal/skia/skia_windows.dll and b/internal/skia/skia_windows.dll differ diff --git a/internal/skia/skia_windows.go b/internal/skia/skia_windows.go index 28d77f4..a5104f0 100644 --- a/internal/skia/skia_windows.go +++ b/internal/skia/skia_windows.go @@ -35,6 +35,7 @@ var ( grBackendRenderTargetDeleteProc *syscall.Proc grContextMakeGLProc *syscall.Proc grContextDeleteProc *syscall.Proc + grContextFlushAndSubmitProc *syscall.Proc grContextResetGLTextureBindings *syscall.Proc grContextReset *syscall.Proc grContextAbandonContextProc *syscall.Proc @@ -80,20 +81,21 @@ var ( skCanvasGetSurfaceProc *syscall.Proc skCanvasIsClipEmptyProc *syscall.Proc skCanvasIsClipRectProc *syscall.Proc - skCanvasFlushProc *syscall.Proc skColorFilterNewModeProc *syscall.Proc skColorFilterNewLightingProc *syscall.Proc skColorFilterNewComposeProc *syscall.Proc skColorFilterNewColorMatrixProc *syscall.Proc skColorFilterNewLumaColorProc *syscall.Proc skColorFilterNewHighContrastProc *syscall.Proc - skColorFilterNewTableARGBProc *syscall.Proc skColorFilterUnrefProc *syscall.Proc skColorSpaceNewSRGBProc *syscall.Proc skDataNewWithCopyProc *syscall.Proc skDataGetSizeProc *syscall.Proc skDataGetDataProc *syscall.Proc skDataUnrefProc *syscall.Proc + skEncodeJPEGProc *syscall.Proc + skEncodePNGProc *syscall.Proc + skEncodeWEBPProc *syscall.Proc skDocumentAbortProc *syscall.Proc skDocumentBeginPageProc *syscall.Proc skDocumentCloseProc *syscall.Proc @@ -148,10 +150,9 @@ var ( skImageGetColorTypeProc *syscall.Proc skImageGetAlphaTypeProc *syscall.Proc skImageReadPixelsProc *syscall.Proc - skImageEncodeSpecificProc *syscall.Proc skImageMakeNonTextureImageProc *syscall.Proc skImageMakeShaderProc *syscall.Proc - skImageMakeTextureImageProc *syscall.Proc + skImageTextureFromImageProc *syscall.Proc skImageUnrefProc *syscall.Proc skImageFilterNewArithmeticProc *syscall.Proc skImageFilterNewBlurProc *syscall.Proc @@ -271,6 +272,7 @@ var ( skPathEffectCreateDashProc *syscall.Proc skPathEffectCreateTrimProc *syscall.Proc skPathEffectUnrefProc *syscall.Proc + skRegisterImageCodecsProc *syscall.Proc skShaderNewColorProc *syscall.Proc skShaderNewBlendProc *syscall.Proc skShaderNewLinearGradientProc *syscall.Proc @@ -337,6 +339,7 @@ func init() { grBackendRenderTargetDeleteProc = skia.MustFindProc("gr_backendrendertarget_delete") grContextMakeGLProc = skia.MustFindProc("gr_direct_context_make_gl") grContextDeleteProc = skia.MustFindProc("gr_direct_context_delete") + grContextFlushAndSubmitProc = skia.MustFindProc("gr_direct_context_flush_and_submit") grContextResetGLTextureBindings = skia.MustFindProc("gr_direct_context_reset_gl_texture_bindings") grContextReset = skia.MustFindProc("gr_direct_context_reset") grContextAbandonContextProc = skia.MustFindProc("gr_direct_context_abandon_context") @@ -382,20 +385,21 @@ func init() { skCanvasGetSurfaceProc = skia.MustFindProc("sk_canvas_get_surface") skCanvasIsClipEmptyProc = skia.MustFindProc("sk_canvas_is_clip_empty") skCanvasIsClipRectProc = skia.MustFindProc("sk_canvas_is_clip_rect") - skCanvasFlushProc = skia.MustFindProc("sk_canvas_flush") skColorFilterNewModeProc = skia.MustFindProc("sk_colorfilter_new_mode") skColorFilterNewLightingProc = skia.MustFindProc("sk_colorfilter_new_lighting") skColorFilterNewComposeProc = skia.MustFindProc("sk_colorfilter_new_compose") skColorFilterNewColorMatrixProc = skia.MustFindProc("sk_colorfilter_new_color_matrix") skColorFilterNewLumaColorProc = skia.MustFindProc("sk_colorfilter_new_luma_color") skColorFilterNewHighContrastProc = skia.MustFindProc("sk_colorfilter_new_high_contrast") - skColorFilterNewTableARGBProc = skia.MustFindProc("sk_colorfilter_new_table_argb") skColorFilterUnrefProc = skia.MustFindProc("sk_colorfilter_unref") skColorSpaceNewSRGBProc = skia.MustFindProc("sk_colorspace_new_srgb") skDataNewWithCopyProc = skia.MustFindProc("sk_data_new_with_copy") skDataGetSizeProc = skia.MustFindProc("sk_data_get_size") skDataGetDataProc = skia.MustFindProc("sk_data_get_data") skDataUnrefProc = skia.MustFindProc("sk_data_unref") + skEncodeJPEGProc = skia.MustFindProc("sk_encode_jpeg") + skEncodePNGProc = skia.MustFindProc("sk_encode_png") + skEncodeWEBPProc = skia.MustFindProc("sk_encode_webp") skDocumentAbortProc = skia.MustFindProc("sk_document_abort") skDocumentBeginPageProc = skia.MustFindProc("sk_document_begin_page") skDocumentCloseProc = skia.MustFindProc("sk_document_close") @@ -450,10 +454,9 @@ func init() { skImageGetColorTypeProc = skia.MustFindProc("sk_image_get_color_type") skImageGetAlphaTypeProc = skia.MustFindProc("sk_image_get_alpha_type") skImageReadPixelsProc = skia.MustFindProc("sk_image_read_pixels") - skImageEncodeSpecificProc = skia.MustFindProc("sk_image_encode_specific") skImageMakeNonTextureImageProc = skia.MustFindProc("sk_image_make_non_texture_image") skImageMakeShaderProc = skia.MustFindProc("sk_image_make_shader") - skImageMakeTextureImageProc = skia.MustFindProc("sk_image_make_texture_image") + skImageTextureFromImageProc = skia.MustFindProc("sk_image_texture_from_image") skImageUnrefProc = skia.MustFindProc("sk_image_unref") skImageFilterNewArithmeticProc = skia.MustFindProc("sk_imagefilter_new_arithmetic") skImageFilterNewBlurProc = skia.MustFindProc("sk_imagefilter_new_blur") @@ -573,6 +576,7 @@ func init() { skPathEffectCreateDashProc = skia.MustFindProc("sk_path_effect_create_dash") skPathEffectCreateTrimProc = skia.MustFindProc("sk_path_effect_create_trim") skPathEffectUnrefProc = skia.MustFindProc("sk_path_effect_unref") + skRegisterImageCodecsProc = skia.MustFindProc("register_image_codecs") skShaderNewColorProc = skia.MustFindProc("sk_shader_new_color") skShaderNewBlendProc = skia.MustFindProc("sk_shader_new_blend") skShaderNewLinearGradientProc = skia.MustFindProc("sk_shader_new_linear_gradient") @@ -679,6 +683,10 @@ func ContextDelete(ctx DirectContext) { grContextDeleteProc.Call(uintptr(ctx)) } +func ContextFlushAndSubmit(ctx DirectContext, syncCPU bool) { + grContextFlushAndSubmitProc.Call(uintptr(ctx), boolToUintptr(syncCPU)) +} + func ContextResetGLTextureBindings(ctx DirectContext) { grContextResetGLTextureBindings.Call(uintptr(ctx)) } @@ -889,10 +897,6 @@ func CanvasIsClipRect(canvas Canvas) bool { return r1 != 0 } -func CanvasFlush(canvas Canvas) { - skCanvasFlushProc.Call(uintptr(canvas)) -} - func ColorFilterNewMode(color Color, blendMode BlendMode) ColorFilter { r1, _, _ := skColorFilterNewModeProc.Call(uintptr(color), uintptr(blendMode)) return ColorFilter(r1) @@ -923,12 +927,6 @@ func ColorFilterNewHighContrast(config *HighContrastConfig) ColorFilter { return ColorFilter(r1) } -func ColorFilterNewTableARGB(a, r, g, b []byte) ColorFilter { - r1, _, _ := skColorFilterNewTableARGBProc.Call(uintptr(unsafe.Pointer(&a[0])), uintptr(unsafe.Pointer(&r[0])), - uintptr(unsafe.Pointer(&g[0])), uintptr(unsafe.Pointer(&b[0]))) - return ColorFilter(r1) -} - func ColorFilterUnref(filter ColorFilter) { skColorFilterUnrefProc.Call(uintptr(filter)) } @@ -957,6 +955,21 @@ func DataUnref(data Data) { skDataUnrefProc.Call(uintptr(data)) } +func EncodeJPEG(ctx DirectContext, img Image, quality int) Data { + r1, _, _ := skEncodeJPEGProc.Call(uintptr(ctx), uintptr(img), uintptr(quality)) + return Data(r1) +} + +func EncodePNG(ctx DirectContext, img Image, compressionLevel int) Data { + r1, _, _ := skEncodePNGProc.Call(uintptr(ctx), uintptr(img), uintptr(compressionLevel)) + return Data(r1) +} + +func EncodeWebp(ctx DirectContext, img Image, quality float32, lossy bool) Data { + r1, _, _ := skEncodeWEBPProc.Call(uintptr(ctx), uintptr(img), uintptr(math.Float32bits(quality)), boolToUintptr(lossy)) + return Data(r1) +} + func DocumentMakePDF(stream WStream, metadata *MetaData) Document { var md metaData md.set(metadata) @@ -1233,9 +1246,9 @@ func ImageReadPixels(img Image, info *ImageInfo, pixels []byte, dstRowBytes, src return r1 != 0 } -func ImageEncodeSpecific(img Image, format EncodedImageFormat, quality int) Data { - r1, _, _ := skImageEncodeSpecificProc.Call(uintptr(img), uintptr(format), uintptr(quality)) - return Data(r1) +func ImageMakeNonTextureImage(img Image) Image { + r1, _, _ := skImageMakeNonTextureImageProc.Call(uintptr(img)) + return Image(r1) } func ImageMakeShader(img Image, tileModeX, tileModeY TileMode, sampling SamplingOptions, matrix geom.Matrix[float32]) Shader { @@ -1244,13 +1257,8 @@ func ImageMakeShader(img Image, tileModeX, tileModeY TileMode, sampling Sampling return Shader(r1) } -func ImageMakeTextureImage(img Image, ctx DirectContext, mipMapped bool) Image { - r1, _, _ := skImageMakeTextureImageProc.Call(uintptr(img), uintptr(ctx), boolToUintptr(mipMapped)) - return Image(r1) -} - -func ImageMakeNonTextureImage(img Image) Image { - r1, _, _ := skImageMakeNonTextureImageProc.Call(uintptr(img)) +func ImageTextureFromImage(ctx DirectContext, img Image, mipMapped, budgeted bool) Image { + r1, _, _ := skImageTextureFromImageProc.Call(uintptr(ctx), uintptr(img), boolToUintptr(mipMapped), boolToUintptr(budgeted)) return Image(r1) } @@ -1308,14 +1316,14 @@ func ImageFilterNewImageSource(img Image, srcRect, dstRect geom.Rect[float32], s return ImageFilter(r1) } -func ImageFilterNewImageSourceDefault(img Image) ImageFilter { - r1, _, _ := skImageFilterNewImageSourceDefaultProc.Call(uintptr(img)) +func ImageFilterNewImageSourceDefault(img Image, sampling SamplingOptions) ImageFilter { + r1, _, _ := skImageFilterNewImageSourceDefaultProc.Call(uintptr(img), uintptr(sampling)) return ImageFilter(r1) } -func ImageFilterNewMagnifier(src geom.Rect[float32], inset float32, input ImageFilter, cropRect *geom.Rect[float32]) ImageFilter { - r1, _, _ := skImageFilterNewMagnifierProc.Call(fromGeomRect(&src), uintptr(math.Float32bits(inset)), - uintptr(input), fromGeomRect(cropRect)) +func ImageFilterNewMagnifier(lensBounds geom.Rect[float32], zoomAmount, inset float32, sampling SamplingOptions, input ImageFilter, cropRect *geom.Rect[float32]) ImageFilter { + r1, _, _ := skImageFilterNewMagnifierProc.Call(fromGeomRect(&lensBounds), uintptr(math.Float32bits(zoomAmount)), + uintptr(math.Float32bits(inset)), uintptr(sampling), uintptr(input), fromGeomRect(cropRect)) return ImageFilter(r1) } @@ -1858,6 +1866,10 @@ func PathEffectUnref(effect PathEffect) { skPathEffectUnrefProc.Call(uintptr(effect)) } +func RegisterImageCodecs() { + skRegisterImageCodecsProc.Call() +} + func ShaderNewColor(color Color) Shader { r1, _, _ := skShaderNewColorProc.Call(uintptr(color)) return Shader(r1) @@ -1956,8 +1968,8 @@ func SurfaceMakeRasterDirect(info *ImageInfo, pixels []byte, rowBytes int, surfa return Surface(r1) } -func SurfaceMakeRasterN32PreMul(width, height int, surfaceProps SurfaceProps) Surface { - r1, _, _ := skSurfaceMakeRasterN32PreMulProc.Call(uintptr(width), uintptr(height), uintptr(surfaceProps)) +func SurfaceMakeRasterN32PreMul(info *ImageInfo, surfaceProps SurfaceProps) Surface { + r1, _, _ := skSurfaceMakeRasterN32PreMulProc.Call(uintptr(unsafe.Pointer(info)), uintptr(surfaceProps)) return Surface(r1) } diff --git a/surface.go b/surface.go index 73cfb77..ae5285c 100644 --- a/surface.go +++ b/surface.go @@ -65,6 +65,12 @@ func (s *surface) prepareCanvas(size Size, _ Rect, scaleX, scaleY float32) (*Can return c, nil } +func (s *surface) flush(syncCPU bool) { + if s != nil && s.surface != nil { + skia.ContextFlushAndSubmit(s.context, syncCPU) + } +} + func (s *surface) partialDispose() { if s.surface != nil { skia.SurfaceUnref(s.surface) diff --git a/window_windows.go b/window_windows.go index 50c4fc3..52219e0 100644 --- a/window_windows.go +++ b/window_windows.go @@ -69,7 +69,7 @@ func (w *Window) convertMouseLocation(x, y float64) Point { return Point{} } -func (w *Window) keyCallbackForGLFW(_ *glfw.Window, key glfw.Key, code int, action glfw.Action, mods glfw.ModifierKey) { +func (w *Window) keyCallbackForGLFW(_ *glfw.Window, key glfw.Key, _ int, action glfw.Action, mods glfw.ModifierKey) { if w.okToProcess() { w.commonKeyCallbackForGLFW(key, action, mods) }