From 27e513178ced0b8a988d74de378fdab54b7f8934 Mon Sep 17 00:00:00 2001 From: Mis012 Date: Fri, 1 Sep 2023 16:08:24 +0200 Subject: [PATCH] preserve the pre-skia-update C API for some simple cases This doesn't cover all the API changes, just the most trivial cases for now. the new, incompatible versions of functions were renamed to *_v2 unless otherwise noted all-zero sk_sampling_options_t seems to work as a reasonable default, so in some places where it wasn't passed before that's what we will pass to the C++ API sk_filter_quality_t seems to have no trivial replacement, so it will be ignored. the canvas functions which were changed to matrix44 seemingly didn't need to be, the new ones were renamed to *_m44 enums and structs which had entries added in the middle were reordered so that the new additions are at the end, in order to not change the values assigned to the existing entries. --- include/c/sk_bitmap.h | 3 ++- include/c/sk_canvas.h | 24 +++++++++++------ include/c/sk_image.h | 6 +++-- include/c/sk_types.h | 8 ++++-- include/core/SkColorType.h | 6 +++-- src/c/sk_bitmap.cpp | 12 ++++++++- src/c/sk_canvas.cpp | 54 ++++++++++++++++++++++++++++++++------ src/c/sk_image.cpp | 19 ++++++++++++-- 8 files changed, 106 insertions(+), 26 deletions(-) diff --git a/include/c/sk_bitmap.h b/include/c/sk_bitmap.h index 26e5305df267..b2401725b931 100644 --- a/include/c/sk_bitmap.h +++ b/include/c/sk_bitmap.h @@ -43,7 +43,8 @@ SK_C_API bool sk_bitmap_extract_subset(sk_bitmap_t* cbitmap, sk_bitmap_t* dst, s SK_C_API bool sk_bitmap_extract_alpha(sk_bitmap_t* cbitmap, sk_bitmap_t* dst, const sk_paint_t* paint, sk_ipoint_t* offset); SK_C_API void sk_bitmap_notify_pixels_changed(sk_bitmap_t* cbitmap); SK_C_API void sk_bitmap_swap(sk_bitmap_t* cbitmap, sk_bitmap_t* cother); -SK_C_API sk_shader_t* sk_bitmap_make_shader(sk_bitmap_t* cbitmap, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix); +SK_C_API sk_shader_t* sk_bitmap_make_shader(sk_bitmap_t* cbitmap, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, const sk_matrix_t* cmatrix); +SK_C_API sk_shader_t* sk_bitmap_make_shader_v2(sk_bitmap_t* cbitmap, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_canvas.h b/include/c/sk_canvas.h index 684da11e3dfc..7d96a274ec60 100644 --- a/include/c/sk_canvas.h +++ b/include/c/sk_canvas.h @@ -28,8 +28,10 @@ SK_C_API void sk_canvas_draw_line(sk_canvas_t* ccanvas, float x0, float y0, floa SK_C_API void sk_canvas_draw_simple_text(sk_canvas_t* ccanvas, 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* ccanvas, sk_textblob_t* text, float x, float y, const sk_paint_t* cpaint); SK_C_API void sk_canvas_reset_matrix(sk_canvas_t* ccanvas); -SK_C_API void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix); -SK_C_API void sk_canvas_get_matrix(sk_canvas_t* ccanvas, sk_matrix44_t* cmatrix); +SK_C_API void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix); +SK_C_API void sk_canvas_set_matrix_44(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix); +SK_C_API void sk_canvas_get_matrix(sk_canvas_t* ccanvas, sk_matrix_t* cmatrix); +SK_C_API void sk_canvas_get_matrix_44(sk_canvas_t* ccanvas, sk_matrix44_t* cmatrix); SK_C_API void sk_canvas_draw_round_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, float rx, float ry, const sk_paint_t* cpaint); SK_C_API void sk_canvas_clip_rect_with_operation(sk_canvas_t* ccanvas, const sk_rect_t* crect, sk_clipop_t op, bool doAA); SK_C_API void sk_canvas_clip_path_with_operation(sk_canvas_t* ccanvas, const sk_path_t* cpath, sk_clipop_t op, bool doAA); @@ -44,7 +46,8 @@ SK_C_API void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy); SK_C_API void sk_canvas_rotate_degrees(sk_canvas_t* ccanvas, float degrees); SK_C_API void sk_canvas_rotate_radians(sk_canvas_t* ccanvas, float radians); SK_C_API void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy); -SK_C_API void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix); +SK_C_API void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix); +SK_C_API void sk_canvas_concat_m44(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix); SK_C_API bool sk_canvas_quick_reject(sk_canvas_t* ccanvas, const sk_rect_t* crect); SK_C_API void sk_canvas_clip_region(sk_canvas_t* ccanvas, const sk_region_t* region, sk_clipop_t op); SK_C_API void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint); @@ -54,8 +57,10 @@ SK_C_API void sk_canvas_draw_rrect(sk_canvas_t* ccanvas, const sk_rrect_t* crect SK_C_API void sk_canvas_draw_circle(sk_canvas_t* ccanvas, float cx, float cy, float rad, const sk_paint_t* cpaint); SK_C_API void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint); SK_C_API void sk_canvas_draw_path(sk_canvas_t* ccanvas, const sk_path_t* cpath, const sk_paint_t* cpaint); -SK_C_API void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint); -SK_C_API void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage, const sk_rect_t* csrcR, const sk_rect_t* cdstR, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint); +SK_C_API void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, const sk_paint_t* cpaint); +SK_C_API void sk_canvas_draw_image_v2(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint); +SK_C_API void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage, const sk_rect_t* csrcR, const sk_rect_t* cdstR, const sk_paint_t* cpaint); +SK_C_API void sk_canvas_draw_image_rect_v2(sk_canvas_t* ccanvas, const sk_image_t* cimage, const sk_rect_t* csrcR, const sk_rect_t* cdstR, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint); SK_C_API void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture, const sk_matrix_t* cmatrix, const sk_paint_t* cpaint); SK_C_API void sk_canvas_draw_drawable(sk_canvas_t* ccanvas, sk_drawable_t* cdrawable, const sk_matrix_t* cmatrix); SK_C_API void sk_canvas_flush(sk_canvas_t* ccanvas); @@ -65,12 +70,15 @@ SK_C_API void sk_canvas_draw_annotation(sk_canvas_t* t, const sk_rect_t* rect, c SK_C_API void sk_canvas_draw_url_annotation(sk_canvas_t* t, const sk_rect_t* rect, sk_data_t* value); SK_C_API void sk_canvas_draw_named_destination_annotation(sk_canvas_t* t, const sk_point_t* point, sk_data_t* value); SK_C_API void sk_canvas_draw_link_destination_annotation(sk_canvas_t* t, const sk_rect_t* rect, sk_data_t* value); -SK_C_API void sk_canvas_draw_image_lattice(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_lattice_t* lattice, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint); -SK_C_API void sk_canvas_draw_image_nine(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_irect_t* center, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint); +SK_C_API void sk_canvas_draw_image_lattice(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_lattice_t* lattice, const sk_rect_t* dst, const sk_paint_t* paint); +SK_C_API void sk_canvas_draw_image_lattice_v2(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_lattice_t* lattice, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint); +SK_C_API void sk_canvas_draw_image_nine(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_irect_t* center, const sk_rect_t* dst, const sk_paint_t* paint); +SK_C_API void sk_canvas_draw_image_nine_v2(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_irect_t* center, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint); SK_C_API void sk_canvas_draw_vertices(sk_canvas_t* ccanvas, const sk_vertices_t* vertices, sk_blendmode_t mode, const sk_paint_t* paint); SK_C_API void sk_canvas_draw_arc(sk_canvas_t* ccanvas, const sk_rect_t* oval, float startAngle, float sweepAngle, bool useCenter, const sk_paint_t* paint); SK_C_API void sk_canvas_draw_drrect(sk_canvas_t* ccanvas, const sk_rrect_t* outer, const sk_rrect_t* inner, const sk_paint_t* paint); -SK_C_API void sk_canvas_draw_atlas(sk_canvas_t* ccanvas, const sk_image_t* atlas, const sk_rsxform_t* xform, const sk_rect_t* tex, const sk_color_t* colors, int count, sk_blendmode_t mode, const sk_sampling_options_t* sampling, const sk_rect_t* cullRect, const sk_paint_t* paint); +SK_C_API void sk_canvas_draw_atlas(sk_canvas_t* ccanvas, const sk_image_t* atlas, const sk_rsxform_t* xform, const sk_rect_t* tex, const sk_color_t* colors, int count, sk_blendmode_t mode, const sk_rect_t* cullRect, const sk_paint_t* paint); +SK_C_API void sk_canvas_draw_atlas_v2(sk_canvas_t* ccanvas, const sk_image_t* atlas, const sk_rsxform_t* xform, const sk_rect_t* tex, const sk_color_t* colors, int count, sk_blendmode_t mode, const sk_sampling_options_t* sampling, const sk_rect_t* cullRect, const sk_paint_t* paint); SK_C_API void sk_canvas_draw_patch(sk_canvas_t* ccanvas, const sk_point_t* cubics, const sk_color_t* colors, const sk_point_t* texCoords, sk_blendmode_t mode, const sk_paint_t* paint); SK_C_API bool sk_canvas_is_clip_empty(sk_canvas_t* ccanvas); SK_C_API bool sk_canvas_is_clip_rect(sk_canvas_t* ccanvas); diff --git a/include/c/sk_image.h b/include/c/sk_image.h index 4fa6fbe302c3..e8db40a16864 100644 --- a/include/c/sk_image.h +++ b/include/c/sk_image.h @@ -32,14 +32,16 @@ SK_C_API sk_alphatype_t sk_image_get_alpha_type(const sk_image_t* image); SK_C_API sk_colortype_t sk_image_get_color_type(const sk_image_t* image); SK_C_API sk_colorspace_t* sk_image_get_colorspace(const sk_image_t* image); SK_C_API bool sk_image_is_alpha_only(const sk_image_t* image); -SK_C_API sk_shader_t* sk_image_make_shader(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix); +SK_C_API sk_shader_t* sk_image_make_shader(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, int /*unused*/, const sk_matrix_t* cmatrix); +SK_C_API sk_shader_t* sk_image_make_shader_v2(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix); SK_C_API bool sk_image_peek_pixels(const sk_image_t* image, sk_pixmap_t* pixmap); SK_C_API bool sk_image_is_texture_backed(const sk_image_t* image); SK_C_API bool sk_image_is_lazy_generated(const sk_image_t* image); SK_C_API bool sk_image_is_valid(const sk_image_t* image, gr_recording_context_t* context); SK_C_API bool sk_image_read_pixels(const sk_image_t* image, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, sk_image_caching_hint_t cachingHint); SK_C_API bool sk_image_read_pixels_into_pixmap(const sk_image_t* image, const sk_pixmap_t* dst, int srcX, int srcY, sk_image_caching_hint_t cachingHint); -SK_C_API bool sk_image_scale_pixels(const sk_image_t* image, const sk_pixmap_t* dst, const sk_sampling_options_t* sampling, sk_image_caching_hint_t cachingHint); +SK_C_API bool sk_image_scale_pixels(const sk_image_t* image, const sk_pixmap_t* dst, sk_image_caching_hint_t cachingHint); +SK_C_API bool sk_image_scale_pixels_v2(const sk_image_t* image, const sk_pixmap_t* dst, const sk_sampling_options_t* sampling, sk_image_caching_hint_t cachingHint); SK_C_API sk_data_t* sk_image_ref_encoded(const sk_image_t* cimage); SK_C_API sk_image_t* sk_image_make_subset_raster(const sk_image_t* cimage, const sk_irect_t* subset); SK_C_API sk_image_t* sk_image_make_subset(const sk_image_t* cimage, gr_direct_context_t* context, const sk_irect_t* subset); diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 4aaea2c095ca..424b0fcc85db 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -107,7 +107,6 @@ typedef enum { BGRA_1010102_SK_COLORTYPE, RGB_101010X_SK_COLORTYPE, BGR_101010X_SK_COLORTYPE, - BGR_101010X_XR_SK_COLORTYPE, GRAY_8_SK_COLORTYPE, RGBA_F16_NORM_SK_COLORTYPE, RGBA_F16_SK_COLORTYPE, @@ -122,6 +121,11 @@ typedef enum { R16G16B16A16_UNORM_SK_COLORTYPE, SRGBA_8888_SK_COLORTYPE, R8_UNORM_SK_COLORTYPE, + + // v2 + BGR_101010X_XR_SK_COLORTYPE, + + // v2 READONLY } sk_colortype_t; typedef enum { @@ -836,10 +840,10 @@ typedef struct { int fDuration; bool fFullyReceived; sk_alphatype_t fAlphaType; - bool fHasAlphaWithinBounds; sk_codecanimation_disposalmethod_t fDisposalMethod; sk_codecanimation_blend_t fBlend; sk_irect_t fFrameRect; + bool fHasAlphaWithinBounds; } sk_codec_frameinfo_t; typedef struct sk_svgcanvas_t sk_svgcanvas_t; diff --git a/include/core/SkColorType.h b/include/core/SkColorType.h index a68dc833b49b..41332d9c13f5 100644 --- a/include/core/SkColorType.h +++ b/include/core/SkColorType.h @@ -28,7 +28,6 @@ enum SkColorType : int { kBGRA_1010102_SkColorType, //!< 10 bits for blue, green, red; 2 bits for alpha; in 32-bit word kRGB_101010x_SkColorType, //!< pixel with 10 bits each for red, green, blue; in 32-bit word kBGR_101010x_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word - kBGR_101010x_XR_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word, extended range kGray_8_SkColorType, //!< pixel with grayscale level in 8-bit byte kRGBA_F16Norm_SkColorType, //!< pixel with half floats in [0,1] for red, green, blue, alpha; // in 64-bit word @@ -50,7 +49,10 @@ enum SkColorType : int { kSRGBA_8888_SkColorType, kR8_unorm_SkColorType, - kLastEnum_SkColorType = kR8_unorm_SkColorType, //!< last valid value + //v2 + kBGR_101010x_XR_SkColorType, //!< pixel with 10 bits each for blue, green, red; in 32-bit word, extended range + + kLastEnum_SkColorType = kBGR_101010x_XR_SkColorType, //!< last valid value #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) kN32_SkColorType = kBGRA_8888_SkColorType,//!< native 32-bit BGRA encoding diff --git a/src/c/sk_bitmap.cpp b/src/c/sk_bitmap.cpp index 0e53a9236a8c..d68faf0be70f 100644 --- a/src/c/sk_bitmap.cpp +++ b/src/c/sk_bitmap.cpp @@ -18,6 +18,8 @@ #include "src/c/sk_types_priv.h" +extern "C" const sk_sampling_options_t default_sampling = {}; // TODO: put this in it's own file? + void sk_bitmap_destructor(sk_bitmap_t* cbitmap) { delete AsBitmap(cbitmap); } @@ -144,7 +146,15 @@ void sk_bitmap_swap(sk_bitmap_t* cbitmap, sk_bitmap_t* cother) { AsBitmap(cbitmap)->swap(*AsBitmap(cother)); } -sk_shader_t* sk_bitmap_make_shader(sk_bitmap_t* cbitmap, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix) { +sk_shader_t* sk_bitmap_make_shader(sk_bitmap_t* cbitmap, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, const sk_matrix_t* cmatrix) { + SkMatrix m; + if (cmatrix) { + m = AsMatrix(cmatrix); + } + return ToShader(AsBitmap(cbitmap)->makeShader((SkTileMode)tmx, (SkTileMode)tmy, *AsSamplingOptions(&default_sampling), cmatrix ? &m : nullptr).release()); +} + +sk_shader_t* sk_bitmap_make_shader_v2(sk_bitmap_t* cbitmap, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix) { SkMatrix m; if (cmatrix) { m = AsMatrix(cmatrix); diff --git a/src/c/sk_canvas.cpp b/src/c/sk_canvas.cpp index f0272679b7a0..4a855e4efe38 100644 --- a/src/c/sk_canvas.cpp +++ b/src/c/sk_canvas.cpp @@ -17,6 +17,8 @@ #include "src/c/sk_types_priv.h" +extern const sk_sampling_options_t default_sampling; + void sk_canvas_destroy(sk_canvas_t* ccanvas) { delete AsCanvas(ccanvas); } @@ -73,11 +75,19 @@ void sk_canvas_reset_matrix(sk_canvas_t* ccanvas) { AsCanvas(ccanvas)->resetMatrix(); } -void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix) { +void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) { + AsCanvas(ccanvas)->setMatrix(AsMatrix(cmatrix)); +} + +void sk_canvas_set_matrix_m44(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix) { AsCanvas(ccanvas)->setMatrix(AsM44(cmatrix)); } -void sk_canvas_get_matrix(sk_canvas_t* ccanvas, sk_matrix44_t* cmatrix) { +void sk_canvas_get_total_matrix(sk_canvas_t* ccanvas, sk_matrix_t* cmatrix) { + *cmatrix = ToMatrix((SkMatrix)AsCanvas(ccanvas)->getTotalMatrix()); +} + +void sk_canvas_get_matrix_m44(sk_canvas_t* ccanvas, sk_matrix44_t* cmatrix) { *cmatrix = ToM44(AsCanvas(ccanvas)->getLocalToDevice()); } @@ -137,7 +147,11 @@ void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) { AsCanvas(ccanvas)->skew(sx, sy); } -void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix) { +void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) { + AsCanvas(ccanvas)->concat(AsMatrix(cmatrix)); +} + +void sk_canvas_concat_m44(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix) { AsCanvas(ccanvas)->concat(AsM44(cmatrix)); } @@ -177,11 +191,23 @@ void sk_canvas_draw_path(sk_canvas_t* ccanvas, const sk_path_t* cpath, const sk_ AsCanvas(ccanvas)->drawPath(*AsPath(cpath), *AsPaint(cpaint)); } -void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint) { +void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, const sk_paint_t* cpaint) { + AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, *AsSamplingOptions(&default_sampling), AsPaint(cpaint)); +} + +void sk_canvas_draw_image_v2(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint) { AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, *AsSamplingOptions(sampling), AsPaint(cpaint)); } -void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage, const sk_rect_t* csrcR, const sk_rect_t* cdstR, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint) { +void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage, const sk_rect_t* csrcR, const sk_rect_t* cdstR, const sk_paint_t* cpaint) { + if (csrcR) { + AsCanvas(ccanvas)->drawImageRect(AsImage(cimage), *AsRect(csrcR), *AsRect(cdstR), *AsSamplingOptions(&default_sampling), AsPaint(cpaint), SkCanvas::SrcRectConstraint::kFast_SrcRectConstraint); + } else { + AsCanvas(ccanvas)->drawImageRect(AsImage(cimage), *AsRect(cdstR), *AsSamplingOptions(&default_sampling), AsPaint(cpaint)); + } +} + +void sk_canvas_draw_image_rect_v2(sk_canvas_t* ccanvas, const sk_image_t* cimage, const sk_rect_t* csrcR, const sk_rect_t* cdstR, const sk_sampling_options_t* sampling, const sk_paint_t* cpaint) { if (csrcR) { AsCanvas(ccanvas)->drawImageRect(AsImage(cimage), *AsRect(csrcR), *AsRect(cdstR), *AsSamplingOptions(sampling), AsPaint(cpaint), SkCanvas::SrcRectConstraint::kFast_SrcRectConstraint); } else { @@ -233,11 +259,19 @@ void sk_canvas_draw_link_destination_annotation(sk_canvas_t* t, const sk_rect_t* SkAnnotateLinkToDestination(AsCanvas(t), *AsRect(rect), AsData(value)); } -void sk_canvas_draw_image_lattice(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_lattice_t* lattice, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint) { +void sk_canvas_draw_image_lattice(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_lattice_t* lattice, const sk_rect_t* dst, const sk_paint_t* paint) { + AsCanvas(ccanvas)->drawImageLattice(AsImage(image), *AsLattice(lattice), *AsRect(dst), (SkFilterMode)NEAREST_SK_FILTER_MODE, AsPaint(paint)); +} + +void sk_canvas_draw_image_lattice_v2(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_lattice_t* lattice, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint) { AsCanvas(ccanvas)->drawImageLattice(AsImage(image), *AsLattice(lattice), *AsRect(dst), (SkFilterMode)mode, AsPaint(paint)); } -void sk_canvas_draw_image_nine(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_irect_t* center, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint) { +void sk_canvas_draw_image_nine(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_irect_t* center, const sk_rect_t* dst, const sk_paint_t* paint) { + AsCanvas(ccanvas)->drawImageNine(AsImage(image), *AsIRect(center), *AsRect(dst), (SkFilterMode)NEAREST_SK_FILTER_MODE, AsPaint(paint)); +} + +void sk_canvas_draw_image_nine_v2(sk_canvas_t* ccanvas, const sk_image_t* image, const sk_irect_t* center, const sk_rect_t* dst, sk_filter_mode_t mode, const sk_paint_t* paint) { AsCanvas(ccanvas)->drawImageNine(AsImage(image), *AsIRect(center), *AsRect(dst), (SkFilterMode)mode, AsPaint(paint)); } @@ -253,7 +287,11 @@ void sk_canvas_draw_drrect(sk_canvas_t* ccanvas, const sk_rrect_t* outer, const AsCanvas(ccanvas)->drawDRRect(*AsRRect(outer), *AsRRect(inner), *AsPaint(paint)); } -void sk_canvas_draw_atlas(sk_canvas_t* ccanvas, const sk_image_t* atlas, const sk_rsxform_t* xform, const sk_rect_t* tex, const sk_color_t* colors, int count, sk_blendmode_t mode, const sk_sampling_options_t* sampling, const sk_rect_t* cullRect, const sk_paint_t* paint) { +void sk_canvas_draw_atlas(sk_canvas_t* ccanvas, const sk_image_t* atlas, const sk_rsxform_t* xform, const sk_rect_t* tex, const sk_color_t* colors, int count, sk_blendmode_t mode, const sk_rect_t* cullRect, const sk_paint_t* paint) { + AsCanvas(ccanvas)->drawAtlas(AsImage(atlas), AsRSXform(xform), AsRect(tex), colors, count, (SkBlendMode)mode, *AsSamplingOptions(&default_sampling), AsRect(cullRect), AsPaint(paint)); +} + +void sk_canvas_draw_atlas_v2(sk_canvas_t* ccanvas, const sk_image_t* atlas, const sk_rsxform_t* xform, const sk_rect_t* tex, const sk_color_t* colors, int count, sk_blendmode_t mode, const sk_sampling_options_t* sampling, const sk_rect_t* cullRect, const sk_paint_t* paint) { AsCanvas(ccanvas)->drawAtlas(AsImage(atlas), AsRSXform(xform), AsRect(tex), colors, count, (SkBlendMode)mode, *AsSamplingOptions(sampling), AsRect(cullRect), AsPaint(paint)); } diff --git a/src/c/sk_image.cpp b/src/c/sk_image.cpp index 903217491fab..1958f1e74eba 100644 --- a/src/c/sk_image.cpp +++ b/src/c/sk_image.cpp @@ -15,6 +15,8 @@ #include "src/c/sk_types_priv.h" +extern const sk_sampling_options_t default_sampling; + void sk_image_ref(const sk_image_t* cimage) { AsImage(cimage)->ref(); } @@ -91,7 +93,16 @@ bool sk_image_is_alpha_only(const sk_image_t* image) { return AsImage(image)->isAlphaOnly(); } -sk_shader_t* sk_image_make_shader(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix) { +sk_shader_t* sk_image_make_shader(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_matrix_t* cmatrix) { + SkMatrix m; + if (cmatrix) { + m = AsMatrix(cmatrix); + } + return ToShader(AsImage(image)->makeShader((SkTileMode)tileX, (SkTileMode)tileY, *AsSamplingOptions(&default_sampling), cmatrix ? &m : nullptr).release()); +} + + +sk_shader_t* sk_image_make_shader_v2(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix) { SkMatrix m; if (cmatrix) { m = AsMatrix(cmatrix); @@ -123,7 +134,11 @@ bool sk_image_read_pixels_into_pixmap(const sk_image_t* image, const sk_pixmap_t return AsImage(image)->readPixels(*AsPixmap(dst), srcX, srcY, (SkImage::CachingHint)cachingHint); } -bool sk_image_scale_pixels(const sk_image_t* image, const sk_pixmap_t* dst, const sk_sampling_options_t* sampling, sk_image_caching_hint_t cachingHint) { +bool sk_image_scale_pixels(const sk_image_t* image, const sk_pixmap_t* dst, int /*unused*/, sk_image_caching_hint_t cachingHint) { + return AsImage(image)->scalePixels(*AsPixmap(dst), *AsSamplingOptions(&default_sampling), (SkImage::CachingHint)cachingHint); +} + +bool sk_image_scale_pixels_v2(const sk_image_t* image, const sk_pixmap_t* dst, const sk_sampling_options_t* sampling, sk_image_caching_hint_t cachingHint) { return AsImage(image)->scalePixels(*AsPixmap(dst), *AsSamplingOptions(sampling), (SkImage::CachingHint)cachingHint); }