diff --git a/.gitignore b/.gitignore index 244bd6eda0b..6e8750507a3 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,5 @@ gl-out node_modules tools/lottiecap/filmstrip.png -_esy \ No newline at end of file +_esy +/_ReSharper.Caches diff --git a/DEPS b/DEPS index b045771107e..fd0457d5174 100644 --- a/DEPS +++ b/DEPS @@ -6,7 +6,7 @@ deps = { "third_party/externals/angle2" : "https://chromium.googlesource.com/angle/angle.git@b001528ffa00e7c15a5002124f707570e59a5697", "third_party/externals/dng_sdk" : "https://android.googlesource.com/platform/external/dng_sdk.git@96443b262250c390b0caefbf3eed8463ba35ecae", "third_party/externals/expat" : "https://android.googlesource.com/platform/external/expat.git@android-6.0.1_r55", - "third_party/externals/freetype" : "https://skia.googlesource.com/third_party/freetype2.git@fa6da7bf6dcbcfa22d2464259ad1cccee3233189", + "third_party/externals/freetype" : "https://skia.googlesource.com/third_party/freetype2.git@VER-2-10-1", "third_party/externals/googletest" : "https://android.googlesource.com/platform/external/googletest@dd43b9998e9a44a579a7aba6c1309407d1a5ed95", "third_party/externals/harfbuzz" : "https://skia.googlesource.com/third_party/harfbuzz.git@1.4.2", "third_party/externals/icu" : "https://chromium.googlesource.com/chromium/deps/icu.git@ec9c1133693148470ffe2e5e53576998e3650c1d", diff --git a/gm/cgm.c b/gm/cgm.c index 569c9f5052b..abfded74ea0 100644 --- a/gm/cgm.c +++ b/gm/cgm.c @@ -10,6 +10,7 @@ #include "sk_canvas.h" #include "sk_data.h" +#include "sk_general.h" #include "sk_image.h" #include "sk_paint.h" #include "sk_shader.h" diff --git a/gn/BUILD.gn b/gn/BUILD.gn index c3e5425e3c8..1dfabb45d28 100644 --- a/gn/BUILD.gn +++ b/gn/BUILD.gn @@ -14,10 +14,9 @@ declare_args() { malloc = "" - enable_bitcode = false - if (is_tvos || is_watchos) { - enable_bitcode = true - } + enable_bitcode = + (is_tvos || is_watchos) && + (target_cpu == "arm" || target_cpu == "arm64") } if (is_ios) { @@ -60,12 +59,8 @@ config("default") { "NOMINMAX", ] - if (msvc == 2015) { - _include_dirs = [ "$win_vc/include" ] - } else { # 2017 - _include_dirs = [ "$win_vc/Tools/MSVC/$win_toolchain_version/include" ] - } - _include_dirs += [ + _include_dirs = [ + "$win_vc/Tools/MSVC/$win_toolchain_version/include", "$win_sdk/Include/$win_sdk_version/shared", "$win_sdk/Include/$win_sdk_version/ucrt", "$win_sdk/Include/$win_sdk_version/um", @@ -83,24 +78,16 @@ config("default") { include_dirs = _include_dirs } + _is_store = "" + if (is_winrt) { + _is_store = "/store" + } + lib_dirs = [ "$win_sdk/Lib/$win_sdk_version/ucrt/$target_cpu", "$win_sdk/Lib/$win_sdk_version/um/$target_cpu", + "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu$_is_store", ] - if (msvc == 2015) { - if (target_cpu == "x86") { - lib_dirs += [ "$win_vc/lib" ] - } else { - lib_dirs += [ "$win_vc/lib/amd64" ] - } - } else { # 2017 - _is_store = "" - if (is_winrt) { - _is_store = "/store" - } - lib_dirs += - [ "$win_vc/Tools/MSVC/$win_toolchain_version/lib/$target_cpu$_is_store" ] - } } else { cflags += [ "-fstrict-aliasing", @@ -216,8 +203,12 @@ config("default") { } else if (target_cpu == "x64") { _target = "x86_64" } - if (is_watchos && _target == "armv7") { - _target = "armv7k" + if (is_watchos) { + if (target_cpu == "arm") { + _target = "armv7k" + } else if (target_cpu == "arm64") { + _target = "arm64_32" + } } asmflags += [ "-isysroot", diff --git a/gn/BUILDCONFIG.gn b/gn/BUILDCONFIG.gn index 8d099eeeb64..2f98e0b2aaa 100644 --- a/gn/BUILDCONFIG.gn +++ b/gn/BUILDCONFIG.gn @@ -28,6 +28,7 @@ declare_args() { cxx = "c++" win_sdk = "C:/Program Files (x86)/Windows Kits/10" + min_win_sdk_version = "10.0.10240.0" win_sdk_version = "" win_vc = "" @@ -140,62 +141,18 @@ if (is_android) { } } -msvc = "" if (is_win) { - # By default we look for 2017 (Pro & Community), then 2015. If MSVC is installed in a + # By default we look for 2017 (Enterprise, Pro, and Community), then 2015. If MSVC is installed in a # non-default location, you can set win_vc to inform us where it is. - vc_2017_ent_default = - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC" - vc_2017_pro_default = - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC" - vc_2017_com_default = - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC" - vc_2017_bt_default = - "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC" - vc_2015_default = "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC" if (win_vc == "") { - if ("True" == exec_script("//gn/checkdir.py", - [ "$vc_2017_ent_default" ], - "trim string")) { - win_vc = vc_2017_ent_default - msvc = 2017 - } else if ("True" == exec_script("//gn/checkdir.py", - [ "$vc_2017_pro_default" ], - "trim string")) { - win_vc = vc_2017_pro_default - msvc = 2017 - } else if ("True" == exec_script("//gn/checkdir.py", - [ "$vc_2017_com_default" ], - "trim string")) { - win_vc = vc_2017_com_default - msvc = 2017 - } else if ("True" == exec_script("//gn/checkdir.py", - [ "$vc_2017_bt_default" ], - "trim string")) { - win_vc = vc_2017_bt_default - msvc = 2017 - } else if ("True" == exec_script("//gn/checkdir.py", - [ "$vc_2015_default" ], - "trim string")) { - win_vc = vc_2015_default - msvc = 2015 - } + win_vc = exec_script("//gn/find_msvc.py", [], "trim string") } assert(win_vc != "") # Could not find VC installation. Set win_vc to your VC directory. - - if (msvc == "") { - if ("True" == - exec_script("//gn/checkdir.py", [ "$win_vc/Tools" ], "trim string")) { - msvc = 2017 - } else { - msvc = 2015 - } - } } if (is_win) { - if (msvc == 2017 && win_toolchain_version == "") { + if (win_toolchain_version == "") { win_toolchain_version = exec_script("//gn/highest_version_dir.py", [ "$win_vc/Tools/MSVC", @@ -208,6 +165,7 @@ if (is_win) { [ "$win_sdk/Include", "[0-9]{2}\.[0-9]\.[0-9]{5}\.[0-9]", + min_win_sdk_version ], "trim string") } diff --git a/gn/find_msvc.py b/gn/find_msvc.py new file mode 100644 index 00000000000..864db094a3a --- /dev/null +++ b/gn/find_msvc.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# Copyright 2019 Google Inc. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import sys + +''' +Look for the first match in the format + C:\\Program Files (x86)\\Microsoft Visual Studio\\${RELEASE}\\${VERSION}\\VC +''' +def find_msvc(): + if sys.platform.startswith('win'): + default_dir = r'C:\Program Files (x86)\Microsoft Visual Studio' + for release in ['2019', '2017']: + for version in ['Enterprise', 'Professional', 'Community', 'BuildTools']: + path = os.path.join(default_dir, release, version, 'VC') + if os.path.isdir(path): + return path + return None + +if __name__ == '__main__': + result = find_msvc() + if result: + sys.stdout.write(result + '\n') diff --git a/gn/lowest_version_dir.py b/gn/lowest_version_dir.py index b493d7f1458..b835faa460a 100644 --- a/gn/lowest_version_dir.py +++ b/gn/lowest_version_dir.py @@ -11,5 +11,12 @@ dirpath = sys.argv[1] regex = re.compile(sys.argv[2]) +minimum = sys.argv[3] -print sorted(filter(regex.match, os.listdir(dirpath)))[0] +matches = sorted(filter(regex.match, os.listdir(dirpath))) +for match in matches: + if (match >= minimum): + path = os.path.join(dirpath, match) + if os.path.isdir(path): + print match + break diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn index cd1def114dd..355d8f5a471 100644 --- a/gn/toolchain/BUILD.gn +++ b/gn/toolchain/BUILD.gn @@ -41,15 +41,7 @@ if (host_os == "win") { toolchain("msvc") { lib_dir_switch = "/LIBPATH:" - if (msvc == 2015) { - if (target_cpu == "x86") { - bin = "$win_vc/bin" - } else { - bin = "$win_vc/bin/amd64" - } - } else { - bin = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu" - } + bin = "$win_vc/Tools/MSVC/$win_toolchain_version/bin/HostX64/$target_cpu" if (target_cpu == "x64") { _target = "amd64" @@ -57,10 +49,9 @@ toolchain("msvc") { _target = "amd64_" + target_cpu } if (is_winrt) { - _target += " uwp 10.0.10240.0 -vcvars_ver=14.1" - } else { - _target += " 8.1 -vcvars_ver=14.1" + _target += " uwp" } + _target += " " + win_sdk_version + " -vcvars_ver=14.2" _vcvarsall = "$win_vc/Auxiliary/Build/vcvarsall.bat" env_setup = "cmd /c set __VSCMD_ARG_NO_LOGO=1 && set VSCMD_START_DIR=%CD% && \"$_vcvarsall\" $_target && " diff --git a/include/c/sk_bitmap.h b/include/c/sk_bitmap.h index c0bd7386611..40063495461 100644 --- a/include/c/sk_bitmap.h +++ b/include/c/sk_bitmap.h @@ -33,7 +33,6 @@ SK_C_API uint16_t sk_bitmap_get_addr_16(sk_bitmap_t* cbitmap, int x, int y); SK_C_API uint32_t sk_bitmap_get_addr_32(sk_bitmap_t* cbitmap, int x, int y); SK_C_API void* sk_bitmap_get_addr(sk_bitmap_t* cbitmap, int x, int y); SK_C_API sk_color_t sk_bitmap_get_pixel_color(sk_bitmap_t* cbitmap, int x, int y); -SK_C_API sk_pmcolor_t sk_bitmap_get_index8_color(sk_bitmap_t* cbitmap, int x, int y); SK_C_API void sk_bitmap_set_pixel_color(sk_bitmap_t* cbitmap, int x, int y, sk_color_t color); SK_C_API bool sk_bitmap_ready_to_draw(sk_bitmap_t* cbitmap); SK_C_API void sk_bitmap_get_pixel_colors(sk_bitmap_t* cbitmap, sk_color_t* colors); diff --git a/include/c/sk_canvas.h b/include/c/sk_canvas.h index 50392d2cfec..089b243c700 100644 --- a/include/c/sk_canvas.h +++ b/include/c/sk_canvas.h @@ -70,7 +70,13 @@ SK_C_API void sk_canvas_draw_bitmap_lattice(sk_canvas_t* t, const sk_bitmap_t* b SK_C_API void sk_canvas_draw_image_lattice(sk_canvas_t* t, 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_bitmap_nine(sk_canvas_t* t, const sk_bitmap_t* bitmap, const sk_irect_t* center, const sk_rect_t* dst, const sk_paint_t* paint); SK_C_API void sk_canvas_draw_image_nine(sk_canvas_t* t, 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_vertices(sk_canvas_t* ccanvas, sk_vertices_t* vertices, sk_blendmode_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_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); SK_C_API sk_nodraw_canvas_t* sk_nodraw_canvas_new(int width, int height); SK_C_API void sk_nodraw_canvas_destroy(sk_nodraw_canvas_t*); diff --git a/include/c/sk_colorspace.h b/include/c/sk_colorspace.h index 4682b4683ca..866d76f7bd0 100644 --- a/include/c/sk_colorspace.h +++ b/include/c/sk_colorspace.h @@ -14,6 +14,8 @@ SK_C_PLUS_PLUS_BEGIN_GUARD +// sk_colorspace_t + SK_C_API void sk_colorspace_unref(sk_colorspace_t* cColorSpace); SK_C_API sk_colorspace_t* sk_colorspace_new_srgb(void); SK_C_API sk_colorspace_t* sk_colorspace_new_srgb_linear(void); @@ -38,6 +40,12 @@ SK_C_API bool sk_colorspaceprimaries_to_xyzd50(const sk_colorspaceprimaries_t* p SK_C_API void sk_colorspace_transfer_fn_invert(const sk_colorspace_transfer_fn_t* transfer, sk_colorspace_transfer_fn_t* inverted); SK_C_API float sk_colorspace_transfer_fn_transform(const sk_colorspace_transfer_fn_t* transfer, float x); +// sk_color4f_t + +SK_C_API sk_color_t sk_color4f_to_color(const sk_color4f_t* color4f); +SK_C_API void sk_color4f_from_color(sk_color_t color, sk_color4f_t* color4f); +SK_C_API void sk_color4f_pin(const sk_color4f_t* color4f, sk_color4f_t* pinned); + SK_C_PLUS_PLUS_END_GUARD #endif diff --git a/include/c/sk_image.h b/include/c/sk_image.h index 818c5f46bba..037061cd90e 100644 --- a/include/c/sk_image.h +++ b/include/c/sk_image.h @@ -25,7 +25,9 @@ SK_C_API sk_image_t* sk_image_new_from_adopted_texture(gr_context_t* context, co SK_C_API sk_image_t* sk_image_new_from_picture(sk_picture_t* picture, const sk_isize_t* dimensions, const sk_matrix_t* matrix, const sk_paint_t* paint); SK_C_API sk_image_t* sk_image_make_subset(const sk_image_t* cimage, const sk_irect_t* subset); +SK_C_API sk_image_t* sk_image_make_texture_image(const sk_image_t* cimage, gr_context_t* context, sk_colorspace_t* colorspace); SK_C_API sk_image_t* sk_image_make_non_texture_image(const sk_image_t* cimage); +SK_C_API sk_image_t* sk_image_make_raster_image(const sk_image_t* cimage); SK_C_API sk_image_t* sk_image_make_with_filter(const sk_image_t* cimage, const sk_imagefilter_t* filter, const sk_irect_t* subset, const sk_irect_t* clipBounds, sk_irect_t* outSubset, sk_ipoint_t* outOffset); SK_C_API void sk_image_ref(const sk_image_t*); @@ -41,6 +43,7 @@ SK_C_API sk_shader_t* sk_image_make_shader(const sk_image_t*, sk_shader_tilemode 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_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, sk_filter_quality_t quality, sk_image_caching_hint_t cachingHint); diff --git a/include/c/sk_matrix.h b/include/c/sk_matrix.h index a361dd25273..3293e09fe65 100644 --- a/include/c/sk_matrix.h +++ b/include/c/sk_matrix.h @@ -59,6 +59,7 @@ SK_C_API void sk_matrix44_as_col_major (sk_matrix44_t* matrix, float* dst); SK_C_API void sk_matrix44_as_row_major (sk_matrix44_t* matrix, float* dst); SK_C_API void sk_matrix44_set_col_major (sk_matrix44_t* matrix, float* dst); SK_C_API void sk_matrix44_set_row_major (sk_matrix44_t* matrix, float* dst); +SK_C_API void sk_matrix44_set_3x3_row_major (sk_matrix44_t* matrix, float* dst); SK_C_API void sk_matrix44_set_translate (sk_matrix44_t* matrix, float dx, float dy, float dz); SK_C_API void sk_matrix44_pre_translate (sk_matrix44_t* matrix, float dx, float dy, float dz); SK_C_API void sk_matrix44_post_translate (sk_matrix44_t* matrix, float dx, float dy, float dz); diff --git a/include/c/sk_path.h b/include/c/sk_path.h index 6284fe50004..9c297fce2da 100644 --- a/include/c/sk_path.h +++ b/include/c/sk_path.h @@ -45,6 +45,7 @@ SK_C_API void sk_path_add_arc(sk_path_t* cpath, const sk_rect_t* crect, float st SK_C_API sk_path_filltype_t sk_path_get_filltype(sk_path_t*); SK_C_API void sk_path_set_filltype(sk_path_t*, sk_path_filltype_t); SK_C_API void sk_path_transform(sk_path_t* cpath, const sk_matrix_t* cmatrix); +SK_C_API void sk_path_transform_to_dest(sk_path_t* cpath, const sk_matrix_t* cmatrix, sk_path_t* destination); SK_C_API sk_path_t* sk_path_clone(const sk_path_t* cpath); SK_C_API void sk_path_add_path_offset (sk_path_t* cpath, sk_path_t* other, float dx, float dy, sk_path_add_mode_t add_mode); SK_C_API void sk_path_add_path_matrix (sk_path_t* cpath, sk_path_t* other, sk_matrix_t *matrix, sk_path_add_mode_t add_mode); diff --git a/include/c/sk_pixmap.h b/include/c/sk_pixmap.h index 46a2bd14f0a..a910d3de65c 100644 --- a/include/c/sk_pixmap.h +++ b/include/c/sk_pixmap.h @@ -29,6 +29,7 @@ SK_C_API bool sk_pixmap_read_pixels(const sk_pixmap_t* cpixmap, const sk_imagein SK_C_API bool sk_pixmap_scale_pixels(const sk_pixmap_t* cpixmap, const sk_pixmap_t* dst, sk_filter_quality_t quality); SK_C_API bool sk_pixmap_extract_subset(const sk_pixmap_t* cpixmap, sk_pixmap_t* result, const sk_irect_t* subset); SK_C_API bool sk_pixmap_erase_color(const sk_pixmap_t* cpixmap, sk_color_t color, const sk_irect_t* subset); +SK_C_API bool sk_pixmap_erase_color4f(const sk_pixmap_t* cpixmap, const sk_color4f_t* color, const sk_irect_t* subset); SK_C_API sk_color_t sk_color_unpremultiply(const sk_pmcolor_t pmcolor); SK_C_API sk_pmcolor_t sk_color_premultiply(const sk_color_t color); @@ -38,9 +39,9 @@ SK_C_API void sk_color_get_bit_shift(int* a, int* r, int* g, int* b); SK_C_API void sk_swizzle_swap_rb(uint32_t* dest, const uint32_t* src, int count); -SK_C_API bool sk_webpencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_webpencoder_options_t options); -SK_C_API bool sk_jpegencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_jpegencoder_options_t options); -SK_C_API bool sk_pngencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_pngencoder_options_t options); +SK_C_API bool sk_webpencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, const sk_webpencoder_options_t* options); +SK_C_API bool sk_jpegencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, const sk_jpegencoder_options_t* options); +SK_C_API bool sk_pngencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, const sk_pngencoder_options_t* options); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_region.h b/include/c/sk_region.h index f4a95a9393d..60abcd00d9d 100755 --- a/include/c/sk_region.h +++ b/include/c/sk_region.h @@ -15,19 +15,54 @@ SK_C_PLUS_PLUS_BEGIN_GUARD +// sk_region_t + SK_C_API sk_region_t* sk_region_new(void); -SK_C_API sk_region_t* sk_region_new2(const sk_region_t* region); -SK_C_API void sk_region_delete(sk_region_t* cpath); -SK_C_API void sk_region_contains(sk_region_t* r, const sk_region_t* region); -SK_C_API void sk_region_contains2(sk_region_t* r, int x, int y); -SK_C_API bool sk_region_intersects_rect(sk_region_t* r, const sk_irect_t* rect); -SK_C_API bool sk_region_intersects(sk_region_t* r, const sk_region_t* src); -SK_C_API bool sk_region_set_path(sk_region_t* dst, const sk_path_t* t, const sk_region_t* clip); -SK_C_API bool sk_region_set_rect(sk_region_t* dst, const sk_irect_t* rect); +SK_C_API void sk_region_delete(sk_region_t* r); +SK_C_API bool sk_region_is_empty(const sk_region_t* r); +SK_C_API bool sk_region_is_rect(const sk_region_t* r); +SK_C_API bool sk_region_is_complex(const sk_region_t* r); +SK_C_API void sk_region_get_bounds(const sk_region_t* r, sk_irect_t* rect); +SK_C_API bool sk_region_get_boundary_path(const sk_region_t* r, sk_path_t* path); +SK_C_API bool sk_region_set_empty(sk_region_t* r); +SK_C_API bool sk_region_set_rect(sk_region_t* r, const sk_irect_t* rect); +SK_C_API bool sk_region_set_rects(sk_region_t* r, const sk_irect_t* rects, int count); SK_C_API bool sk_region_set_region(sk_region_t* r, const sk_region_t* region); -SK_C_API bool sk_region_op(sk_region_t* dst, int left, int top, int right, int bottom, sk_region_op_t op); -SK_C_API bool sk_region_op2(sk_region_t* dst, sk_region_t* src, sk_region_op_t op); -SK_C_API void sk_region_get_bounds(sk_region_t* r, sk_irect_t* rect); +SK_C_API bool sk_region_set_path(sk_region_t* r, const sk_path_t* t, const sk_region_t* clip); +SK_C_API bool sk_region_intersects_rect(const sk_region_t* r, const sk_irect_t* rect); +SK_C_API bool sk_region_intersects(const sk_region_t* r, const sk_region_t* src); +SK_C_API bool sk_region_contains_point(const sk_region_t* r, int x, int y); +SK_C_API bool sk_region_contains_rect(const sk_region_t* r, const sk_irect_t* rect); +SK_C_API bool sk_region_contains(const sk_region_t* r, const sk_region_t* region); +SK_C_API bool sk_region_quick_contains(const sk_region_t* r, const sk_irect_t* rect); +SK_C_API bool sk_region_quick_reject_rect(const sk_region_t* r, const sk_irect_t* rect); +SK_C_API bool sk_region_quick_reject(const sk_region_t* r, const sk_region_t* region); +SK_C_API void sk_region_translate(sk_region_t* r, int x, int y); +SK_C_API bool sk_region_op_rect(sk_region_t* r, const sk_irect_t* rect, sk_region_op_t op); +SK_C_API bool sk_region_op(sk_region_t* r, const sk_region_t* region, sk_region_op_t op); + +// sk_region_iterator_t + +SK_C_API sk_region_iterator_t* sk_region_iterator_new(const sk_region_t* region); +SK_C_API void sk_region_iterator_delete(sk_region_iterator_t* iter); +SK_C_API bool sk_region_iterator_rewind(sk_region_iterator_t* iter); +SK_C_API bool sk_region_iterator_done(const sk_region_iterator_t* iter); +SK_C_API void sk_region_iterator_next(sk_region_iterator_t* iter); +SK_C_API void sk_region_iterator_rect(const sk_region_iterator_t* iter, sk_irect_t* rect); + +// sk_region_cliperator_t + +SK_C_API sk_region_cliperator_t* sk_region_cliperator_new(const sk_region_t* region, const sk_irect_t* clip); +SK_C_API void sk_region_cliperator_delete(sk_region_cliperator_t* iter); +SK_C_API bool sk_region_cliperator_done(sk_region_cliperator_t* iter); +SK_C_API void sk_region_cliperator_next(sk_region_cliperator_t* iter); +SK_C_API void sk_region_cliperator_rect(const sk_region_cliperator_t* iter, sk_irect_t* rect); + +// sk_region_spanerator_t + +SK_C_API sk_region_spanerator_t* sk_region_spanerator_new(const sk_region_t* region, int y, int left, int right); +SK_C_API void sk_region_spanerator_delete(sk_region_spanerator_t* iter); +SK_C_API bool sk_region_spanerator_next(sk_region_spanerator_t* iter, int* left, int* right); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_shader.h b/include/c/sk_shader.h index a0ee3342c9b..74c4823781d 100644 --- a/include/c/sk_shader.h +++ b/include/c/sk_shader.h @@ -14,71 +14,38 @@ SK_C_PLUS_PLUS_BEGIN_GUARD -SK_C_API void sk_shader_ref(sk_shader_t*); -SK_C_API void sk_shader_unref(sk_shader_t*); -SK_C_API sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t points[2], - const sk_color_t colors[], - const float colorPos[], - int colorCount, - sk_shader_tilemode_t tileMode, - const sk_matrix_t* localMatrix); -SK_C_API sk_shader_t* sk_shader_new_radial_gradient(const sk_point_t* center, - float radius, - const sk_color_t colors[], - const float colorPos[], - int colorCount, - sk_shader_tilemode_t tileMode, - const sk_matrix_t* localMatrix); -SK_C_API sk_shader_t* sk_shader_new_sweep_gradient(const sk_point_t* center, - const sk_color_t colors[], - const float colorPos[], - int colorCount, - sk_shader_tilemode_t tileMode, - float startAngle, - float endAngle, - const sk_matrix_t* localMatrix); -SK_C_API sk_shader_t* sk_shader_new_two_point_conical_gradient( - const sk_point_t* start, - float startRadius, - const sk_point_t* end, - float endRadius, - const sk_color_t colors[], - const float colorPos[], - int colorCount, - sk_shader_tilemode_t tileMode, - const sk_matrix_t* localMatrix); +// SkShader + +SK_C_API void sk_shader_ref(sk_shader_t* shader); +SK_C_API void sk_shader_unref(sk_shader_t* shader); +SK_C_API sk_shader_t* sk_shader_with_local_matrix(const sk_shader_t* shader, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_with_color_filter(const sk_shader_t* shader, const sk_colorfilter_t* filter); + +// SkShaders + SK_C_API sk_shader_t* sk_shader_new_empty(void); SK_C_API sk_shader_t* sk_shader_new_color(sk_color_t color); -SK_C_API sk_shader_t* sk_shader_new_bitmap(const sk_bitmap_t* src, - sk_shader_tilemode_t tmx, - sk_shader_tilemode_t tmy, - const sk_matrix_t* localMatrix); -SK_C_API sk_shader_t* sk_shader_new_picture(sk_picture_t* src, - sk_shader_tilemode_t tmx, - sk_shader_tilemode_t tmy, - const sk_matrix_t* localMatrix, - const sk_rect_t* tile); -SK_C_API sk_shader_t* sk_shader_new_local_matrix(sk_shader_t* proxy, const sk_matrix_t* localMatrix); -SK_C_API sk_shader_t* sk_shader_new_color_filter(sk_shader_t* proxy, sk_colorfilter_t* filter); -SK_C_API sk_shader_t* sk_shader_new_perlin_noise_fractal_noise( - float baseFrequencyX, - float baseFrequencyY, - int numOctaves, - float seed, - const sk_isize_t* tileSize); -SK_C_API sk_shader_t* sk_shader_new_perlin_noise_turbulence( - float baseFrequencyX, - float baseFrequencyY, - int numOctaves, - float seed, - const sk_isize_t* tileSize); -SK_C_API sk_shader_t* sk_shader_new_compose( - sk_shader_t* shaderA, - sk_shader_t* shaderB); -SK_C_API sk_shader_t* sk_shader_new_compose_with_mode( - sk_shader_t* shaderA, - sk_shader_t* shaderB, - sk_blendmode_t mode); +SK_C_API sk_shader_t* sk_shader_new_color4f(const sk_color4f_t* color, const sk_colorspace_t* colorspace); +SK_C_API sk_shader_t* sk_shader_new_compose(const sk_shader_t* shaderA, const sk_shader_t* shaderB, sk_blendmode_t mode); +SK_C_API sk_shader_t* sk_shader_new_bitmap(const sk_bitmap_t* src, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_picture(sk_picture_t* src, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, const sk_matrix_t* localMatrix, const sk_rect_t* tile); + +// SkGradientShader + +SK_C_API sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t points[2], const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_linear_gradient_color4f(const sk_point_t points[2], const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_radial_gradient(const sk_point_t* center, float radius, const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_radial_gradient_color4f(const sk_point_t* center, float radius, const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_sweep_gradient(const sk_point_t* center, const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, float startAngle, float endAngle, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_sweep_gradient_color4f(const sk_point_t* center, const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, float startAngle, float endAngle, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_two_point_conical_gradient(const sk_point_t* start, float startRadius, const sk_point_t* end, float endRadius, const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix); +SK_C_API sk_shader_t* sk_shader_new_two_point_conical_gradient_color4f(const sk_point_t* start, float startRadius, const sk_point_t* end, float endRadius, const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix); + +// SkPerlinNoiseShader + +SK_C_API sk_shader_t* sk_shader_new_perlin_noise_fractal_noise(float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, const sk_isize_t* tileSize); +SK_C_API sk_shader_t* sk_shader_new_perlin_noise_turbulence(float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, const sk_isize_t* tileSize); +SK_C_API sk_shader_t* sk_shader_new_perlin_noise_improved_noise(float baseFrequencyX, float baseFrequencyY, int numOctaves, float z); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_svg.h b/include/c/sk_svg.h index f0e384423e9..f67c4ff37c3 100644 --- a/include/c/sk_svg.h +++ b/include/c/sk_svg.h @@ -14,7 +14,8 @@ SK_C_PLUS_PLUS_BEGIN_GUARD -SK_C_API sk_canvas_t* sk_svgcanvas_create(const sk_rect_t* bounds, sk_xmlwriter_t* writer); +SK_C_API sk_canvas_t* sk_svgcanvas_create_with_stream(const sk_rect_t* bounds, sk_wstream_t* stream); +SK_C_API sk_canvas_t* sk_svgcanvas_create_with_writer(const sk_rect_t* bounds, sk_xmlwriter_t* writer); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_textblob.h b/include/c/sk_textblob.h index f583abe980b..7e86712363c 100644 --- a/include/c/sk_textblob.h +++ b/include/c/sk_textblob.h @@ -22,9 +22,9 @@ SK_C_API void sk_textblob_get_bounds(const sk_textblob_t* blob, sk_rect_t* bound SK_C_API sk_textblob_builder_t* sk_textblob_builder_new(); SK_C_API void sk_textblob_builder_delete(sk_textblob_builder_t* builder); SK_C_API sk_textblob_t* sk_textblob_builder_make(sk_textblob_builder_t* builder); -SK_C_API void sk_textblob_builder_alloc_run_text(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float x, float y, int textByteCount, const sk_string_t* lang, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer); -SK_C_API void sk_textblob_builder_alloc_run_text_pos_h(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float y, int textByteCount, const sk_string_t* lang, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer); -SK_C_API void sk_textblob_builder_alloc_run_text_pos(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, int textByteCount, const sk_string_t* lang, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer); +SK_C_API void sk_textblob_builder_alloc_run_text(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float x, float y, int textByteCount, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer); +SK_C_API void sk_textblob_builder_alloc_run_text_pos_h(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float y, int textByteCount, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer); +SK_C_API void sk_textblob_builder_alloc_run_text_pos(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, int textByteCount, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_typeface.h b/include/c/sk_typeface.h index 82a5a742f5c..4aa408a5f88 100644 --- a/include/c/sk_typeface.h +++ b/include/c/sk_typeface.h @@ -30,10 +30,13 @@ SK_C_API sk_fontstyle_t* sk_typeface_get_fontstyle(sk_typeface_t* typeface); SK_C_API int sk_typeface_get_font_weight(sk_typeface_t* typeface); SK_C_API int sk_typeface_get_font_width(sk_typeface_t* typeface); SK_C_API sk_font_style_slant_t sk_typeface_get_font_slant(sk_typeface_t* typeface); +SK_C_API int sk_typeface_count_glyphs(sk_typeface_t* typeface); SK_C_API int sk_typeface_count_tables(sk_typeface_t* typeface); SK_C_API int sk_typeface_get_table_tags(sk_typeface_t* typeface, sk_font_table_tag_t tags[]); SK_C_API size_t sk_typeface_get_table_size(sk_typeface_t* typeface, sk_font_table_tag_t tag); SK_C_API size_t sk_typeface_get_table_data(sk_typeface_t* typeface, sk_font_table_tag_t tag, size_t offset, size_t length, void* data); +SK_C_API bool sk_typeface_is_fixed_pitch(sk_typeface_t* typeface); +SK_C_API bool sk_typeface_get_kerning_pair_adjustments(sk_typeface_t* typeface, const uint16_t* glyphs, int count, int32_t* adjustments); // font manager diff --git a/include/c/sk_types.h b/include/c/sk_types.h index fa24d1ce0dd..81c25f1b88a 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -55,6 +55,13 @@ typedef uint32_t sk_pmcolor_t; #define sk_color_get_g(c) (((c) >> 8) & 0xFF) #define sk_color_get_b(c) (((c) >> 0) & 0xFF) +typedef struct sk_color4f_t { + float fR; + float fG; + float fB; + float fA; +} sk_color4f_t; + typedef enum { UNKNOWN_SK_COLORTYPE = 0, ALPHA_8_SK_COLORTYPE, @@ -85,6 +92,7 @@ typedef enum { } sk_pixelgeometry_t; typedef enum { + NONE_SK_SURFACE_PROPS_FLAGS = 0, USE_DEVICE_INDEPENDENT_FONTS_SK_SURFACE_PROPS_FLAGS = 1 << 0, } sk_surfaceprops_flags_t; @@ -111,61 +119,10 @@ typedef struct sk_rect_t { float bottom; } sk_rect_t; -/** - The sk_matrix_t struct holds a 3x3 perspective matrix for - transforming coordinates: - - (X,Y) = T[M]((x,y)) - X = (M[0] * x + M[1] * y + M[2]) / (M[6] * x + M[7] * y + M[8]); - Y = (M[3] * x + M[4] * y + M[5]) / (M[6] * x + M[7] * y + M[8]); - - Therefore, the identity matrix is - - sk_matrix_t identity = {{1, 0, 0, - 0, 1, 0, - 0, 0, 1}}; - - A matrix that scales by sx and sy is: - - sk_matrix_t scale = {{sx, 0, 0, - 0, sy, 0, - 0, 0, 1}}; - - A matrix that translates by tx and ty is: - - sk_matrix_t translate = {{1, 0, tx, - 0, 1, ty, - 0, 0, 1}}; - - A matrix that rotates around the origin by A radians: - - sk_matrix_t rotate = {{cos(A), -sin(A), 0, - sin(A), cos(A), 0, - 0, 0, 1}}; - - Two matrixes can be concatinated by: - - void concat_matrices(sk_matrix_t* dst, - const sk_matrix_t* matrixU, - const sk_matrix_t* matrixV) { - const float* u = matrixU->mat; - const float* v = matrixV->mat; - sk_matrix_t result = {{ - u[0] * v[0] + u[1] * v[3] + u[2] * v[6], - u[0] * v[1] + u[1] * v[4] + u[2] * v[7], - u[0] * v[2] + u[1] * v[5] + u[2] * v[8], - u[3] * v[0] + u[4] * v[3] + u[5] * v[6], - u[3] * v[1] + u[4] * v[4] + u[5] * v[7], - u[3] * v[2] + u[4] * v[5] + u[5] * v[8], - u[6] * v[0] + u[7] * v[3] + u[8] * v[6], - u[6] * v[1] + u[7] * v[4] + u[8] * v[7], - u[6] * v[2] + u[7] * v[5] + u[8] * v[8] - }}; - *dst = result; - } -*/ typedef struct sk_matrix_t { - float mat[9]; + float scaleX, skewX, transX; + float skewY, scaleY, transY; + float persp0, persp1, persp2; } sk_matrix_t; typedef struct sk_matrix44_t sk_matrix44_t; @@ -175,7 +132,7 @@ typedef enum { TRANSLATE_SK_MATRIX44_TYPE_MASK = 0x01, SCALE_SK_MATRIX44_TYPE_MASK = 0x02, AFFINE_SK_MATRIX44_TYPE_MASK = 0x04, - PERSPECTIVE_SK_MATRIX44_TYPE_MASK = 0x08 + PERSPECTIVE_SK_MATRIX44_TYPE_MASK = 0x08 } sk_matrix44_type_mask_t; /** @@ -251,6 +208,9 @@ typedef struct sk_surface_t sk_surface_t; clipping areas for drawing. */ typedef struct sk_region_t sk_region_t; +typedef struct sk_region_iterator_t sk_region_iterator_t; +typedef struct sk_region_cliperator_t sk_region_cliperator_t; +typedef struct sk_region_spanerator_t sk_region_spanerator_t; typedef enum { CLEAR_SK_BLENDMODE, @@ -293,8 +253,8 @@ typedef struct sk_point3_t { } sk_point3_t; typedef struct sk_ipoint_t { - float x; - float y; + int32_t x; + int32_t y; } sk_ipoint_t; typedef struct sk_size_t { @@ -303,8 +263,8 @@ typedef struct sk_size_t { } sk_size_t; typedef struct sk_isize_t { - float w; - float h; + int32_t w; + int32_t h; } sk_isize_t; typedef struct sk_fontmetrics_t { @@ -379,9 +339,9 @@ typedef struct sk_wstream_dynamicmemorystream_t sk_wstream_dynamicmemorystream_t typedef struct sk_document_t sk_document_t; typedef enum { - UTF8_ENCODING, - UTF16_ENCODING, - UTF32_ENCODING + UTF8_SK_ENCODING, + UTF16_SK_ENCODING, + UTF32_SK_ENCODING } sk_encoding_t; typedef enum { @@ -424,6 +384,7 @@ typedef enum { } sk_filter_quality_t; typedef enum { + HAS_NONE_SK_CROP_RECT_FLAG = 0x00, HAS_LEFT_SK_CROP_RECT_FLAG = 0x01, HAS_TOP_SK_CROP_RECT_FLAG = 0x02, HAS_WIDTH_SK_CROP_RECT_FLAG = 0x04, @@ -570,7 +531,7 @@ typedef enum { INVERTED_SK_PATH_EFFECT_TRIM_MODE, } sk_path_effect_trim_mode_t; -typedef struct sk_path_effect_t sk_path_effect_t; +typedef struct sk_path_effect_t sk_path_effect_t; typedef enum { BUTT_SK_STROKE_CAP, @@ -662,11 +623,6 @@ typedef struct sk_mask_t { sk_mask_format_t fFormat; } sk_mask_t; -typedef enum { - NONE_GR_CONTEXT_FLUSHBITS = 0, - DISCARD_GR_CONTEXT_FLUSHBITS = 0x2, -} gr_context_flushbits_t; - typedef intptr_t gr_backendobject_t; typedef struct gr_backendrendertarget_t gr_backendrendertarget_t; @@ -753,6 +709,7 @@ typedef enum { } sk_image_caching_hint_t; typedef enum { + NONE_SK_BITMAP_ALLOC_FLAGS = 0, ZERO_PIXELS_SK_BITMAP_ALLOC_FLAGS = 1 << 0, } sk_bitmap_allocflags_t; @@ -781,12 +738,6 @@ typedef struct sk_document_pdf_metadata_t { int fEncodingQuality; } sk_document_pdf_metadata_t; -typedef enum { - SRGB_SK_COLORSPACE_NAMED, - ADOBE_RGB_SK_COLORSPACE_NAMED, - SRGB_LINEAR_SK_COLORSPACE_NAMED, -} sk_colorspace_named_t; - typedef struct sk_imageinfo_t { sk_colorspace_t* colorspace; int32_t width; @@ -891,8 +842,8 @@ typedef enum { PAETH_SK_PNGENCODER_FILTER_FLAGS = 0x80, ALL_SK_PNGENCODER_FILTER_FLAGS = NONE_SK_PNGENCODER_FILTER_FLAGS | SUB_SK_PNGENCODER_FILTER_FLAGS | - UP_SK_PNGENCODER_FILTER_FLAGS | - AVG_SK_PNGENCODER_FILTER_FLAGS | + UP_SK_PNGENCODER_FILTER_FLAGS | + AVG_SK_PNGENCODER_FILTER_FLAGS | PAETH_SK_PNGENCODER_FILTER_FLAGS, } sk_pngencoder_filterflags_t; @@ -959,6 +910,13 @@ typedef struct sk_textblob_builder_runbuffer_t { void* clusters; } sk_textblob_builder_runbuffer_t; +typedef struct { + float fSCos; + float fSSin; + float fTX; + float fTY; +} sk_rsxform_t; + SK_C_PLUS_PLUS_END_GUARD #endif diff --git a/src/c/sk_canvas.cpp b/src/c/sk_canvas.cpp index f33f1799b66..f6871a1d9d7 100644 --- a/src/c/sk_canvas.cpp +++ b/src/c/sk_canvas.cpp @@ -258,10 +258,34 @@ void sk_canvas_draw_image_nine(sk_canvas_t* ccanvas, const sk_image_t* image, co AsCanvas(ccanvas)->drawImageNine(AsImage(image), *AsIRect(center), *AsRect(dst), AsPaint(paint)); } -void sk_canvas_draw_vertices(sk_canvas_t* ccanvas, sk_vertices_t* vertices, sk_blendmode_t mode, const sk_paint_t* paint) { +void sk_canvas_draw_vertices(sk_canvas_t* ccanvas, const sk_vertices_t* vertices, sk_blendmode_t mode, const sk_paint_t* paint) { AsCanvas(ccanvas)->drawVertices(AsVertices(vertices), (SkBlendMode)mode, *AsPaint(paint)); } +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) { + AsCanvas(ccanvas)->drawArc(*AsRect(oval), startAngle, sweepAngle, useCenter, *AsPaint(paint)); +} + +void sk_canvas_draw_drrect(sk_canvas_t* ccanvas, const sk_rrect_t* outer, const sk_rrect_t* inner, const sk_paint_t* paint) { + 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_rect_t* cullRect, const sk_paint_t* paint) { + AsCanvas(ccanvas)->drawAtlas(AsImage(atlas), AsRSXform(xform), AsRect(tex), colors, count, (SkBlendMode)mode, AsRect(cullRect), AsPaint(paint)); +} + +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) { + AsCanvas(ccanvas)->drawPatch(AsPoint(cubics), colors, AsPoint(texCoords), (SkBlendMode)mode, *AsPaint(paint)); +} + +bool sk_canvas_is_clip_empty(sk_canvas_t* ccanvas) { + return AsCanvas(ccanvas)->isClipEmpty(); +} + +bool sk_canvas_is_clip_rect(sk_canvas_t* ccanvas) { + return AsCanvas(ccanvas)->isClipRect(); +} + sk_nodraw_canvas_t* sk_nodraw_canvas_new(int width, int height) { return ToNoDrawCanvas(new SkNoDrawCanvas(width, height)); } diff --git a/src/c/sk_colorspace.cpp b/src/c/sk_colorspace.cpp index 8b4d7d4534d..5bed41a1cf1 100644 --- a/src/c/sk_colorspace.cpp +++ b/src/c/sk_colorspace.cpp @@ -13,6 +13,8 @@ #include "sk_types_priv.h" +// sk_colorspace_t + void sk_colorspace_unref(sk_colorspace_t* cColorSpace) { SkSafeUnref(AsColorSpace(cColorSpace)); } @@ -105,3 +107,18 @@ float sk_colorspace_transfer_fn_transform(const sk_colorspace_transfer_fn_t* tra SkColorSpaceTransferFn fn = *AsColorSpaceTransferFn(transfer); return fn(x); } + + +// sk_color4f_t + +sk_color_t sk_color4f_to_color(const sk_color4f_t* color4f) { + return AsColor4f(color4f)->toSkColor(); +} + +void sk_color4f_from_color(sk_color_t color, sk_color4f_t* color4f) { + *color4f = ToColor4f(SkColor4f::FromColor(color)); +} + +void sk_color4f_pin(const sk_color4f_t* color4f, sk_color4f_t* pinned) { + *pinned = ToColor4f(AsColor4f(color4f)->pin()); +} diff --git a/src/c/sk_enums.cpp b/src/c/sk_enums.cpp index bc79a585d4e..9555c2c8b8e 100644 --- a/src/c/sk_enums.cpp +++ b/src/c/sk_enums.cpp @@ -42,9 +42,9 @@ #define ASSERT_MSG(SK, C) "ABI changed, you must write a enumeration mapper for " TOSTRING(#SK) " to " TOSTRING(#C) "." // sk_encoding_t -static_assert ((int)SkTypeface::Encoding::kUTF8_Encoding == (int)UTF8_ENCODING, ASSERT_MSG(SkTypeface::Encoding, sk_encoding_t)); -static_assert ((int)SkTypeface::Encoding::kUTF16_Encoding == (int)UTF16_ENCODING, ASSERT_MSG(SkTypeface::Encoding, sk_encoding_t)); -static_assert ((int)SkTypeface::Encoding::kUTF32_Encoding == (int)UTF32_ENCODING, ASSERT_MSG(SkTypeface::Encoding, sk_encoding_t)); +static_assert ((int)SkTypeface::Encoding::kUTF8_Encoding == (int)UTF8_SK_ENCODING, ASSERT_MSG(SkTypeface::Encoding, sk_encoding_t)); +static_assert ((int)SkTypeface::Encoding::kUTF16_Encoding == (int)UTF16_SK_ENCODING, ASSERT_MSG(SkTypeface::Encoding, sk_encoding_t)); +static_assert ((int)SkTypeface::Encoding::kUTF32_Encoding == (int)UTF32_SK_ENCODING, ASSERT_MSG(SkTypeface::Encoding, sk_encoding_t)); // sk_font_style_slant_t static_assert ((int)SkFontStyle::Slant::kUpright_Slant == (int)UPRIGHT_SK_FONT_STYLE_SLANT, ASSERT_MSG(SkFontStyle::Slant, sk_font_style_slant_t)); diff --git a/src/c/sk_image.cpp b/src/c/sk_image.cpp index 712f91e168c..3bd60e08e20 100644 --- a/src/c/sk_image.cpp +++ b/src/c/sk_image.cpp @@ -110,6 +110,10 @@ bool sk_image_is_lazy_generated(const sk_image_t* image) { return AsImage(image)->isLazyGenerated(); } +bool sk_image_is_valid(const sk_image_t* image, gr_context_t* context) { + return AsImage(image)->isValid(AsGrContext(context)); +} + 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) { return AsImage(image)->readPixels(AsImageInfo(dstInfo), dstPixels, dstRowBytes, srcX, srcY, (SkImage::CachingHint)cachingHint); } @@ -138,10 +142,18 @@ sk_image_t* sk_image_make_subset(const sk_image_t* cimage, const sk_irect_t* sub return ToImage(AsImage(cimage)->makeSubset(*AsIRect(subset)).release()); } +sk_image_t* sk_image_make_texture_image(const sk_image_t* cimage, gr_context_t* context, sk_colorspace_t* colorspace) { + return ToImage(AsImage(cimage)->makeTextureImage(AsGrContext(context), AsColorSpace(colorspace)).release()); +} + sk_image_t* sk_image_make_non_texture_image(const sk_image_t* cimage) { return ToImage(AsImage(cimage)->makeNonTextureImage().release()); } +sk_image_t* sk_image_make_raster_image(const sk_image_t* cimage) { + return ToImage(AsImage(cimage)->makeRasterImage().release()); +} + sk_image_t* sk_image_make_with_filter(const sk_image_t* cimage, const sk_imagefilter_t* filter, const sk_irect_t* subset, const sk_irect_t* clipBounds, sk_irect_t* outSubset, sk_ipoint_t* outOffset) { return ToImage(AsImage(cimage)->makeWithFilter(AsImageFilter(filter), *AsIRect(subset), *AsIRect(clipBounds), AsIRect(outSubset), AsIPoint(outOffset)).release()); } diff --git a/src/c/sk_matrix.cpp b/src/c/sk_matrix.cpp index 3dd12523548..7bfd0da04f3 100644 --- a/src/c/sk_matrix.cpp +++ b/src/c/sk_matrix.cpp @@ -197,6 +197,10 @@ void sk_matrix44_set_row_major(sk_matrix44_t* matrix, float* dst) { AsMatrix44(matrix)->setRowMajorf(dst); } +void sk_matrix44_set_3x3_row_major(sk_matrix44_t* matrix, float* dst) { + AsMatrix44(matrix)->set3x3RowMajorf(dst); +} + void sk_matrix44_set_translate(sk_matrix44_t* matrix, float dx, float dy, float dz) { AsMatrix44(matrix)->setTranslate(dx, dy, dz); } diff --git a/src/c/sk_path.cpp b/src/c/sk_path.cpp index aea2cd7436e..d1288cfd5d7 100644 --- a/src/c/sk_path.cpp +++ b/src/c/sk_path.cpp @@ -53,7 +53,11 @@ sk_path_filltype_t sk_path_get_filltype(sk_path_t *cpath) { } void sk_path_transform(sk_path_t* cpath, const sk_matrix_t* cmatrix) { - return AsPath(cpath)->transform(AsMatrix(cmatrix)); + AsPath(cpath)->transform(AsMatrix(cmatrix)); +} + +void sk_path_transform_to_dest(sk_path_t* cpath, const sk_matrix_t* cmatrix, sk_path_t* destination) { + AsPath(cpath)->transform(AsMatrix(cmatrix), AsPath(destination)); } sk_path_t* sk_path_clone(const sk_path_t* cpath) { diff --git a/src/c/sk_pixmap.cpp b/src/c/sk_pixmap.cpp index a43f56e0d4d..ec5f5f31772 100644 --- a/src/c/sk_pixmap.cpp +++ b/src/c/sk_pixmap.cpp @@ -64,10 +64,14 @@ bool sk_pixmap_extract_subset(const sk_pixmap_t* cpixmap, sk_pixmap_t* result, c return AsPixmap(cpixmap)->extractSubset(AsPixmap(result), *AsIRect(subset)); } -bool sk_pixmap_erase_color (const sk_pixmap_t* cpixmap, sk_color_t color, const sk_irect_t* subset) { +bool sk_pixmap_erase_color(const sk_pixmap_t* cpixmap, sk_color_t color, const sk_irect_t* subset) { return AsPixmap(cpixmap)->erase((SkColor)color, *AsIRect(subset)); } +bool sk_pixmap_erase_color4f(const sk_pixmap_t* cpixmap, const sk_color4f_t* color, const sk_irect_t* subset) { + return AsPixmap(cpixmap)->erase(*AsColor4f(color), AsIRect(subset)); +} + sk_color_t sk_color_unpremultiply(const sk_pmcolor_t pmcolor) { return SkUnPreMultiply::PMColorToColor(pmcolor); } @@ -111,14 +115,14 @@ void sk_swizzle_swap_rb(uint32_t* dest, const uint32_t* src, int count) { SkSwapRB(dest, src, count); } -bool sk_webpencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_webpencoder_options_t options) { - return SkWebpEncoder::Encode(AsWStream(dst), *AsPixmap(src), AsWebpEncoderOptions(options)); +bool sk_webpencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, const sk_webpencoder_options_t* options) { + return SkWebpEncoder::Encode(AsWStream(dst), *AsPixmap(src), *AsWebpEncoderOptions(options)); } -bool sk_jpegencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_jpegencoder_options_t options) { - return SkJpegEncoder::Encode(AsWStream(dst), *AsPixmap(src), AsJpegEncoderOptions(options)); +bool sk_jpegencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, const sk_jpegencoder_options_t* options) { + return SkJpegEncoder::Encode(AsWStream(dst), *AsPixmap(src), *AsJpegEncoderOptions(options)); } -bool sk_pngencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_pngencoder_options_t options) { - return SkPngEncoder::Encode(AsWStream(dst), *AsPixmap(src), AsPngEncoderOptions(options)); +bool sk_pngencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, const sk_pngencoder_options_t* options) { + return SkPngEncoder::Encode(AsWStream(dst), *AsPixmap(src), *AsPngEncoderOptions(options)); } diff --git a/src/c/sk_region.cpp b/src/c/sk_region.cpp index ed6247d87cd..b3993cd815b 100644 --- a/src/c/sk_region.cpp +++ b/src/c/sk_region.cpp @@ -12,55 +12,161 @@ #include "sk_region.h" #include "sk_types_priv.h" +// sk_region_t -sk_region_t *sk_region_new() { +sk_region_t* sk_region_new(void) { return ToRegion(new SkRegion()); } -sk_region_t *sk_region_new2(const sk_region_t *region) { - return ToRegion(new SkRegion(*AsRegion(region))); +void sk_region_delete(sk_region_t* r) { + delete AsRegion(r); } -void sk_region_delete(sk_region_t *region) { - delete AsRegion(region); +bool sk_region_is_empty(const sk_region_t* r) { + return AsRegion(r)->isEmpty(); } -void sk_region_contains(sk_region_t *r, const sk_region_t *region) { - AsRegion(r)->contains(*AsRegion(region)); +bool sk_region_is_rect(const sk_region_t* r) { + return AsRegion(r)->isRect(); } -void sk_region_contains2(sk_region_t *r, int x, int y) { - AsRegion(r)->contains(x, y); +bool sk_region_is_complex(const sk_region_t* r) { + return AsRegion(r)->isComplex(); } -bool sk_region_intersects_rect(sk_region_t* r, const sk_irect_t* rect) { +void sk_region_get_bounds(const sk_region_t* r, sk_irect_t* rect) { + *rect = ToIRect(AsRegion(r)->getBounds()); +} + +bool sk_region_get_boundary_path(const sk_region_t* r, sk_path_t* path) { + return AsRegion(r)->getBoundaryPath(AsPath(path)); +} + +bool sk_region_set_empty(sk_region_t* r) { + return AsRegion(r)->setEmpty(); +} + +bool sk_region_set_rect(sk_region_t* r, const sk_irect_t* rect) { + return AsRegion(r)->setRect(*AsIRect(rect)); +} + +bool sk_region_set_rects(sk_region_t* r, const sk_irect_t* rects, int count) { + return AsRegion(r)->setRects(AsIRect(rects), count); +} + +bool sk_region_set_region(sk_region_t* r, const sk_region_t* region) { + return AsRegion(r)->setRegion(*AsRegion(region)); +} + +bool sk_region_set_path(sk_region_t* r, const sk_path_t* t, const sk_region_t* clip) { + return AsRegion(r)->setPath(*AsPath(t), *AsRegion(clip)); +} + +bool sk_region_intersects_rect(const sk_region_t* r, const sk_irect_t* rect) { return AsRegion(r)->intersects(*AsIRect(rect)); } -bool sk_region_intersects(sk_region_t *r, const sk_region_t *src) { +bool sk_region_intersects(const sk_region_t* r, const sk_region_t* src) { return AsRegion(r)->intersects(*AsRegion(src)); } -bool sk_region_set_path(sk_region_t *dst, const sk_path_t *t, const sk_region_t* clip) { - return AsRegion(dst)->setPath(*AsPath(t), *AsRegion(clip)); +bool sk_region_contains_point(const sk_region_t* r, int x, int y) { + return AsRegion(r)->contains(x, y); } -bool sk_region_set_rect(sk_region_t *dst, const sk_irect_t *rect) { - return AsRegion(dst)->setRect(*AsIRect(rect)); +bool sk_region_contains_rect(const sk_region_t* r, const sk_irect_t* rect) { + return AsRegion(r)->contains(*AsIRect(rect)); } -bool sk_region_set_region(sk_region_t* dst, const sk_region_t* region) { - return AsRegion(dst)->setRegion(*AsRegion(region)); +bool sk_region_contains(const sk_region_t* r, const sk_region_t* region) { + return AsRegion(r)->contains(*AsRegion(region)); } -bool sk_region_op(sk_region_t *dst, int left, int top, int right, int bottom, sk_region_op_t op) { - return AsRegion(dst)->op(left, top, right, bottom, (SkRegion::Op)op); +bool sk_region_quick_contains(const sk_region_t* r, const sk_irect_t* rect) { + return AsRegion(r)->quickContains(*AsIRect(rect)); } -bool sk_region_op2(sk_region_t *dst, sk_region_t *src, sk_region_op_t op) { - return AsRegion(dst)->op(*AsRegion(src), (SkRegion::Op)op); +bool sk_region_quick_reject_rect(const sk_region_t* r, const sk_irect_t* rect) { + return AsRegion(r)->quickReject(*AsIRect(rect)); } -void sk_region_get_bounds(sk_region_t* r, sk_irect_t* rect) { - *rect = ToIRect(AsRegion(r)->getBounds()); +bool sk_region_quick_reject(const sk_region_t* r, const sk_region_t* region) { + return AsRegion(r)->quickReject(*AsRegion(region)); +} + +void sk_region_translate(sk_region_t* r, int x, int y) { + AsRegion(r)->translate(x, y); +} + +bool sk_region_op_rect(sk_region_t* r, const sk_irect_t* rect, sk_region_op_t op) { + return AsRegion(r)->op(*AsIRect(rect), (SkRegion::Op)op); +} + +bool sk_region_op(sk_region_t* r, const sk_region_t* region, sk_region_op_t op) { + return AsRegion(r)->op(*AsRegion(region), (SkRegion::Op)op); +} + + +// sk_region_iterator_t + +sk_region_iterator_t* sk_region_iterator_new(const sk_region_t* region) { + return ToRegionIterator(new SkRegion::Iterator(*AsRegion(region))); +} + +void sk_region_iterator_delete(sk_region_iterator_t* iter) { + delete AsRegionIterator(iter); +} + +bool sk_region_iterator_rewind(sk_region_iterator_t* iter) { + return AsRegionIterator(iter)->rewind(); +} + +bool sk_region_iterator_done(const sk_region_iterator_t* iter) { + return AsRegionIterator(iter)->done(); +} + +void sk_region_iterator_next(sk_region_iterator_t* iter) { + AsRegionIterator(iter)->next(); +} + +void sk_region_iterator_rect(const sk_region_iterator_t* iter, sk_irect_t* rect) { + *rect = ToIRect(AsRegionIterator(iter)->rect()); +} + + +// sk_region_cliperator_t + +sk_region_cliperator_t* sk_region_cliperator_new(const sk_region_t* region, const sk_irect_t* clip) { + return ToRegionCliperator(new SkRegion::Cliperator(*AsRegion(region), *AsIRect(clip))); +} + +void sk_region_cliperator_delete(sk_region_cliperator_t* iter) { + delete AsRegionCliperator(iter); +} + +bool sk_region_cliperator_done(sk_region_cliperator_t* iter) { + return AsRegionCliperator(iter)->done(); +} + +void sk_region_cliperator_next(sk_region_cliperator_t* iter) { + AsRegionCliperator(iter)->next(); +} + +void sk_region_cliperator_rect(const sk_region_cliperator_t* iter, sk_irect_t* rect) { + *rect = ToIRect(AsRegionCliperator(iter)->rect()); +} + + +// sk_region_spanerator_t + +sk_region_spanerator_t* sk_region_spanerator_new(const sk_region_t* region, int y, int left, int right) { + return ToRegionSpanerator(new SkRegion::Spanerator(*AsRegion(region), y, left, right)); +} + +void sk_region_spanerator_delete(sk_region_spanerator_t* iter) { + delete AsRegionSpanerator(iter); +} + +bool sk_region_spanerator_next(sk_region_spanerator_t* iter, int* left, int* right) { + return AsRegionSpanerator(iter)->next(left, right); } diff --git a/src/c/sk_shader.cpp b/src/c/sk_shader.cpp index e8efdaca010..4bec829e1a9 100644 --- a/src/c/sk_shader.cpp +++ b/src/c/sk_shader.cpp @@ -17,7 +17,27 @@ #include "sk_types_priv.h" -sk_shader_t* sk_shader_new_empty() { +// SkShader + +void sk_shader_ref(sk_shader_t* shader){ + SkSafeRef(AsShader(shader)); +} + +void sk_shader_unref(sk_shader_t* shader){ + SkSafeUnref(AsShader(shader)); +} + +sk_shader_t* sk_shader_with_local_matrix(const sk_shader_t* shader, const sk_matrix_t* localMatrix) { + return ToShader(AsShader(shader)->makeWithLocalMatrix(AsMatrix(localMatrix)).release()); +} + +sk_shader_t* sk_shader_with_color_filter(const sk_shader_t* shader, const sk_colorfilter_t* filter) { + return ToShader(AsShader(shader)->makeWithColorFilter(sk_ref_sp(AsColorFilter(filter))).release()); +} + +// SkShaders + +sk_shader_t* sk_shader_new_empty(void) { return ToShader(SkShader::MakeEmptyShader().release()); } @@ -25,92 +45,96 @@ sk_shader_t* sk_shader_new_color(sk_color_t color) { return ToShader(SkShader::MakeColorShader(color).release()); } +sk_shader_t* sk_shader_new_color4f(const sk_color4f_t* color, const sk_colorspace_t* colorspace) { + return ToShader(SkShader::MakeColorShader(*AsColor4f(color), sk_ref_sp(AsColorSpace(colorspace))).release()); +} + +sk_shader_t* sk_shader_new_compose(const sk_shader_t* shaderA, const sk_shader_t* shaderB, sk_blendmode_t mode) { + return ToShader(SkShader::MakeComposeShader(sk_ref_sp(AsShader(shaderA)), sk_ref_sp(AsShader(shaderB)), (SkBlendMode)mode).release()); +} + sk_shader_t* sk_shader_new_bitmap(const sk_bitmap_t* src, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, const sk_matrix_t* localMatrix) { SkMatrix m; - if (localMatrix) { + if (localMatrix) m = AsMatrix(localMatrix); - } - return ToShader(SkShader::MakeBitmapShader( - *AsBitmap(src), (SkShader::TileMode)tmx, (SkShader::TileMode)tmy, localMatrix ? &m : nullptr).release()); + return ToShader(SkShader::MakeBitmapShader(*AsBitmap(src), (SkShader::TileMode)tmx, (SkShader::TileMode)tmy, localMatrix ? &m : nullptr).release()); } sk_shader_t* sk_shader_new_picture(sk_picture_t* src, sk_shader_tilemode_t tmx, sk_shader_tilemode_t tmy, const sk_matrix_t* localMatrix, const sk_rect_t* tile) { SkMatrix m; - if (localMatrix) { + if (localMatrix) m = AsMatrix(localMatrix); - } - return ToShader(SkShader::MakePictureShader( - sk_ref_sp(AsPicture(src)), (SkShader::TileMode)tmx, (SkShader::TileMode)tmy, localMatrix ? &m : nullptr, AsRect(tile)).release()); + return ToShader(SkShader::MakePictureShader(sk_ref_sp(AsPicture(src)), (SkShader::TileMode)tmx, (SkShader::TileMode)tmy, localMatrix ? &m : nullptr, AsRect(tile)).release()); } -sk_shader_t* sk_shader_new_color_filter(sk_shader_t* proxy, sk_colorfilter_t* filter) { - return ToShader(AsShader(proxy)->makeWithColorFilter(sk_ref_sp(AsColorFilter(filter))).release()); -} +// SkGradientShader -sk_shader_t* sk_shader_new_local_matrix(sk_shader_t* proxy, const sk_matrix_t* localMatrix) { - return ToShader(AsShader(proxy)->makeWithLocalMatrix(AsMatrix(localMatrix)).release()); +sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t points[2], const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix) { + SkMatrix m; + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeLinear(AsPoint(points), colors, colorPos, colorCount, (SkShader::TileMode)tileMode, 0, localMatrix ? &m : nullptr).release()); } -sk_shader_t* sk_shader_new_perlin_noise_fractal_noise(float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, const sk_isize_t* ctileSize) { - return ToShader(SkPerlinNoiseShader::MakeFractalNoise( - baseFrequencyX, baseFrequencyY, numOctaves, seed, AsISize(ctileSize)).release()); +sk_shader_t* sk_shader_new_linear_gradient_color4f(const sk_point_t points[2], const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix) { + SkMatrix m; + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeLinear(AsPoint(points), AsColor4f(colors), sk_ref_sp(AsColorSpace(colorspace)), colorPos, colorCount, (SkShader::TileMode)tileMode, 0, localMatrix ? &m : nullptr).release()); } -sk_shader_t* sk_shader_new_perlin_noise_turbulence(float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, const sk_isize_t* ctileSize) { - return ToShader(SkPerlinNoiseShader::MakeTurbulence( - baseFrequencyX, baseFrequencyY, numOctaves, seed, AsISize(ctileSize)).release()); +sk_shader_t* sk_shader_new_radial_gradient(const sk_point_t* center, float radius, const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix) { + SkMatrix m; + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeRadial(*AsPoint(center), (SkScalar)radius, colors, colorPos, colorCount, (SkShader::TileMode)tileMode, 0, localMatrix ? &m : nullptr).release()); } -sk_shader_t* sk_shader_new_compose(sk_shader_t* shaderA, sk_shader_t* shaderB) { - return ToShader(SkShader::MakeComposeShader( - sk_ref_sp(AsShader(shaderA)), sk_ref_sp(AsShader(shaderB)), SkBlendMode::kSrcOver).release()); +sk_shader_t* sk_shader_new_radial_gradient_color4f(const sk_point_t* center, float radius, const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix) { + SkMatrix m; + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeRadial(*AsPoint(center), (SkScalar)radius, AsColor4f(colors), sk_ref_sp(AsColorSpace(colorspace)), colorPos, colorCount, (SkShader::TileMode)tileMode, 0, localMatrix ? &m : nullptr).release()); } -sk_shader_t* sk_shader_new_compose_with_mode(sk_shader_t* shaderA, sk_shader_t* shaderB, sk_blendmode_t cmode) { - return ToShader(SkShader::MakeComposeShader( - sk_ref_sp(AsShader(shaderA)), sk_ref_sp(AsShader(shaderB)), (SkBlendMode)cmode).release()); +sk_shader_t* sk_shader_new_sweep_gradient(const sk_point_t* center, const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, float startAngle, float endAngle, const sk_matrix_t* localMatrix) { + SkMatrix m; + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeSweep(center->x, center->y, colors, colorPos, colorCount, (SkShader::TileMode)tileMode, startAngle, endAngle, 0, localMatrix ? &m : nullptr).release()); } -void sk_shader_ref(sk_shader_t* cshader) { - SkSafeRef(AsShader(cshader)); +sk_shader_t* sk_shader_new_sweep_gradient_color4f(const sk_point_t* center, const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, float startAngle, float endAngle, const sk_matrix_t* localMatrix) { + SkMatrix m; + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeSweep(center->x, center->y, AsColor4f(colors), sk_ref_sp(AsColorSpace(colorspace)), colorPos, colorCount, (SkShader::TileMode)tileMode, startAngle, endAngle, 0, localMatrix ? &m : nullptr).release()); } -void sk_shader_unref(sk_shader_t* cshader) { - SkSafeUnref(AsShader(cshader)); +sk_shader_t* sk_shader_new_two_point_conical_gradient(const sk_point_t* start, float startRadius, const sk_point_t* end, float endRadius, const sk_color_t colors[], const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix) { + SkMatrix m; + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeTwoPointConical(*AsPoint(start), startRadius, *AsPoint(end), endRadius, colors, colorPos, colorCount, (SkShader::TileMode)tileMode, 0, localMatrix ? &m : nullptr).release()); } -sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t pts[2], const sk_color_t* colors, const float* colorPos, int colorCount, sk_shader_tilemode_t cmode, const sk_matrix_t* cmatrix) { +sk_shader_t* sk_shader_new_two_point_conical_gradient_color4f(const sk_point_t* start, float startRadius, const sk_point_t* end, float endRadius, const sk_color4f_t* colors, const sk_colorspace_t* colorspace, const float colorPos[], int colorCount, sk_shader_tilemode_t tileMode, const sk_matrix_t* localMatrix) { SkMatrix m; - if (cmatrix) { - m = AsMatrix(cmatrix); - } - return ToShader(SkGradientShader::MakeLinear( - AsPoint(pts), colors, colorPos, colorCount, (SkShader::TileMode)cmode, 0, cmatrix ? &m : nullptr).release()); + if (localMatrix) + m = AsMatrix(localMatrix); + return ToShader(SkGradientShader::MakeTwoPointConical(*AsPoint(start), startRadius, *AsPoint(end), endRadius, AsColor4f(colors), sk_ref_sp(AsColorSpace(colorspace)), colorPos, colorCount, (SkShader::TileMode)tileMode, 0, localMatrix ? &m : nullptr).release()); } -sk_shader_t* sk_shader_new_radial_gradient(const sk_point_t* ccenter, float radius, const sk_color_t* colors, const float* colorPos, int colorCount, sk_shader_tilemode_t cmode, const sk_matrix_t* cmatrix) { - SkMatrix m; - if (cmatrix) { - m = AsMatrix(cmatrix); - } - return ToShader(SkGradientShader::MakeRadial( - *AsPoint(ccenter), (SkScalar)radius, colors, colorPos, colorCount, (SkShader::TileMode)cmode, 0, cmatrix ? &m : nullptr).release()); +// SkPerlinNoiseShader + +sk_shader_t* sk_shader_new_perlin_noise_fractal_noise(float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, const sk_isize_t* tileSize) { + return ToShader(SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, AsISize(tileSize)).release()); } -sk_shader_t* sk_shader_new_sweep_gradient(const sk_point_t* ccenter, const sk_color_t* colors, const float* colorPos, int colorCount, sk_shader_tilemode_t cmode, float startAngle, float endAngle, const sk_matrix_t* cmatrix) { - SkMatrix m; - if (cmatrix) { - m = AsMatrix(cmatrix); - } - return ToShader(SkGradientShader::MakeSweep( - ccenter->x, ccenter->y, colors, colorPos, colorCount, (SkShader::TileMode)cmode, startAngle, endAngle, 0, cmatrix ? &m : nullptr).release()); +sk_shader_t* sk_shader_new_perlin_noise_turbulence(float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, const sk_isize_t* tileSize) { + return ToShader(SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, AsISize(tileSize)).release()); } -sk_shader_t* sk_shader_new_two_point_conical_gradient(const sk_point_t* start, float startRadius, const sk_point_t* end, float endRadius, const sk_color_t* colors, const float* colorPos, int colorCount, sk_shader_tilemode_t cmode, const sk_matrix_t* cmatrix) { - SkMatrix m; - if (cmatrix) { - m = AsMatrix(cmatrix); - } - return ToShader(SkGradientShader::MakeTwoPointConical( - *AsPoint(start), startRadius, *AsPoint(end), endRadius, colors, colorPos, colorCount, (SkShader::TileMode)cmode, 0, cmatrix ? &m : nullptr).release()); +sk_shader_t* sk_shader_new_perlin_noise_improved_noise(float baseFrequencyX, float baseFrequencyY, int numOctaves, float z) { + return ToShader(SkPerlinNoiseShader::MakeImprovedNoise(baseFrequencyX, baseFrequencyY, numOctaves, z).release()); } diff --git a/src/c/sk_structs.cpp b/src/c/sk_structs.cpp index 2c52a544da8..a035dd8a4cf 100644 --- a/src/c/sk_structs.cpp +++ b/src/c/sk_structs.cpp @@ -23,6 +23,7 @@ #include "SkDocument.h" #include "SkHighContrastFilter.h" #include "SkTextBlob.h" +#include "SkRSXform.h" #if SK_SUPPORT_GPU #include "GrTypes.h" @@ -61,6 +62,8 @@ static_assert (sizeof (sk_pngencoder_options_t) == sizeof (SkPngEncoder::Options static_assert (sizeof (sk_jpegencoder_options_t) == sizeof (SkJpegEncoder::Options), ASSERT_MSG(SkJpegEncoder::Options, sk_jpegencoder_options_t)); static_assert (sizeof (sk_webpencoder_options_t) == sizeof (SkWebpEncoder::Options), ASSERT_MSG(SkWebpEncoder::Options, sk_webpencoder_options_t)); static_assert (sizeof (sk_textblob_builder_runbuffer_t) == sizeof (SkTextBlobBuilder::RunBuffer), ASSERT_MSG(SkTextBlobBuilder::RunBuffer, sk_textblob_builder_runbuffer_t)); +static_assert (sizeof (sk_rsxform_t) == sizeof (SkRSXform), ASSERT_MSG(SkRSXform, sk_rsxform_t)); +static_assert (sizeof (sk_color4f_t) == sizeof (SkColor4f), ASSERT_MSG(SkColor4f, sk_color4f_t)); #if SK_SUPPORT_GPU static_assert (sizeof (gr_gl_framebufferinfo_t) == sizeof (GrGLFramebufferInfo), ASSERT_MSG(GrGLFramebufferInfo, gr_gl_framebufferinfo_t)); diff --git a/src/c/sk_svg.cpp b/src/c/sk_svg.cpp index 01799b87990..929208eaa04 100644 --- a/src/c/sk_svg.cpp +++ b/src/c/sk_svg.cpp @@ -15,6 +15,10 @@ ////////////////////////////////////////////////////////////////////////////////////////////////// -sk_canvas_t* sk_svgcanvas_create(const sk_rect_t* bounds, sk_xmlwriter_t* writer) { +sk_canvas_t* sk_svgcanvas_create_with_stream(const sk_rect_t* bounds, sk_wstream_t* stream) { + return ToCanvas(SkSVGCanvas::Make(*AsRect(bounds), AsWStream(stream)).release()); +} + +sk_canvas_t* sk_svgcanvas_create_with_writer(const sk_rect_t* bounds, sk_xmlwriter_t* writer) { return ToCanvas(SkSVGCanvas::Make(*AsRect(bounds), AsXMLWriter(writer)).release()); } diff --git a/src/c/sk_textblob.cpp b/src/c/sk_textblob.cpp index c239e1c00a1..4b9bd097422 100644 --- a/src/c/sk_textblob.cpp +++ b/src/c/sk_textblob.cpp @@ -43,14 +43,14 @@ sk_textblob_t* sk_textblob_builder_make(sk_textblob_builder_t* builder) { return ToTextBlob(AsTextBlobBuilder(builder)->make().release()); } -void sk_textblob_builder_alloc_run_text(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float x, float y, int textByteCount, const sk_string_t* lang, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer) { - *runbuffer = ToTextBlobBuilderRunBuffer(AsTextBlobBuilder(builder)->allocRunText(AsPaint(*font), count, x, y, textByteCount, *AsString(lang), AsRect(bounds))); +void sk_textblob_builder_alloc_run_text(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float x, float y, int textByteCount, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer) { + *runbuffer = ToTextBlobBuilderRunBuffer(AsTextBlobBuilder(builder)->allocRunText(AsPaint(*font), count, x, y, textByteCount, SkString(), AsRect(bounds))); } -void sk_textblob_builder_alloc_run_text_pos_h(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float y, int textByteCount, const sk_string_t* lang, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer) { - *runbuffer = ToTextBlobBuilderRunBuffer(AsTextBlobBuilder(builder)->allocRunTextPosH(AsPaint(*font), count, y, textByteCount, *AsString(lang), AsRect(bounds))); +void sk_textblob_builder_alloc_run_text_pos_h(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, float y, int textByteCount, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer) { + *runbuffer = ToTextBlobBuilderRunBuffer(AsTextBlobBuilder(builder)->allocRunTextPosH(AsPaint(*font), count, y, textByteCount, SkString(), AsRect(bounds))); } -void sk_textblob_builder_alloc_run_text_pos(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, int textByteCount, const sk_string_t* lang, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer) { - *runbuffer = ToTextBlobBuilderRunBuffer(AsTextBlobBuilder(builder)->allocRunTextPos(AsPaint(*font), count, textByteCount, *AsString(lang), AsRect(bounds))); +void sk_textblob_builder_alloc_run_text_pos(sk_textblob_builder_t* builder, const sk_paint_t* font, int count, int textByteCount, const sk_rect_t* bounds, sk_textblob_builder_runbuffer_t* runbuffer) { + *runbuffer = ToTextBlobBuilderRunBuffer(AsTextBlobBuilder(builder)->allocRunTextPos(AsPaint(*font), count, textByteCount, SkString(), AsRect(bounds))); } diff --git a/src/c/sk_typeface.cpp b/src/c/sk_typeface.cpp index a245a1b73c6..918ddaac98c 100644 --- a/src/c/sk_typeface.cpp +++ b/src/c/sk_typeface.cpp @@ -82,6 +82,10 @@ sk_font_style_slant_t sk_typeface_get_font_slant(sk_typeface_t* typeface) { return (sk_font_style_slant_t)AsTypeface(typeface)->fontStyle().slant(); } +int sk_typeface_count_glyphs(sk_typeface_t* typeface) { + return AsTypeface(typeface)->countGlyphs(); +} + int sk_typeface_count_tables(sk_typeface_t* typeface) { return AsTypeface(typeface)->countTables(); } @@ -98,6 +102,14 @@ size_t sk_typeface_get_table_data(sk_typeface_t* typeface, sk_font_table_tag_t t return AsTypeface(typeface)->getTableData(tag, offset, length, data); } +bool sk_typeface_is_fixed_pitch(sk_typeface_t* typeface) { + return AsTypeface(typeface)->isFixedPitch(); +} + +bool sk_typeface_get_kerning_pair_adjustments(sk_typeface_t* typeface, const uint16_t* glyphs, int count, int32_t* adjustments) { + return AsTypeface(typeface)->getKerningPairAdjustments(glyphs, count, adjustments); +} + // font manager diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h index f2b8d6a1ea4..5cefedfd463 100644 --- a/src/c/sk_types_priv.h +++ b/src/c/sk_types_priv.h @@ -110,6 +110,7 @@ DEF_CLASS_MAP(GrContext, gr_context_t, GrContext) DEF_CLASS_MAP(GrBackendTexture, gr_backendtexture_t, GrBackendTexture) DEF_CLASS_MAP(GrBackendRenderTarget, gr_backendrendertarget_t, GrBackendRenderTarget) +DEF_STRUCT_MAP(SkColor4f, sk_color4f_t, Color4f) DEF_STRUCT_MAP(SkColorSpacePrimaries, sk_colorspaceprimaries_t, ColorSpacePrimaries) DEF_STRUCT_MAP(SkColorSpaceTransferFn, sk_colorspace_transfer_fn_t, ColorSpaceTransferFn) DEF_STRUCT_MAP(SkHighContrastConfig, sk_highcontrastconfig_t, HighContrastConfig) @@ -120,6 +121,7 @@ DEF_STRUCT_MAP(SkMask, sk_mask_t, Mask) DEF_STRUCT_MAP(SkPoint, sk_point_t, Point) DEF_STRUCT_MAP(SkPoint3, sk_point3_t, Point3) DEF_STRUCT_MAP(SkRect, sk_rect_t, Rect) +DEF_STRUCT_MAP(SkRSXform, sk_rsxform_t, RSXform) DEF_STRUCT_MAP(SkSize, sk_size_t, Size) DEF_STRUCT_MAP(GrGLTextureInfo, gr_gl_textureinfo_t, GrGLTextureInfo) @@ -149,6 +151,11 @@ DEF_MAP(SkPath::RawIter, sk_path_rawiterator_t, PathRawIter) #include "SkPngEncoder.h" DEF_MAP(SkPngEncoder::Options, sk_pngencoder_options_t, PngEncoderOptions) +#include "SkRegion.h" +DEF_MAP(SkRegion::Iterator, sk_region_iterator_t, RegionIterator) +DEF_MAP(SkRegion::Cliperator, sk_region_cliperator_t, RegionCliperator) +DEF_MAP(SkRegion::Spanerator, sk_region_spanerator_t, RegionSpanerator) + #include "SkTime.h" DEF_MAP(SkTime::DateTime, sk_time_datetime_t, TimeDateTime) @@ -158,13 +165,21 @@ DEF_MAP(SkWebpEncoder::Options, sk_webpencoder_options_t, WebpEncoderOptions) #include "SkMatrix.h" static inline SkMatrix AsMatrix(const sk_matrix_t* matrix) { return SkMatrix::MakeAll( - matrix->mat[0], matrix->mat[1], matrix->mat[2], - matrix->mat[3], matrix->mat[4], matrix->mat[5], - matrix->mat[6], matrix->mat[7], matrix->mat[8]); + matrix->scaleX, matrix->skewX, matrix->transX, + matrix->skewY, matrix->scaleY, matrix->transY, + matrix->persp0, matrix->persp1, matrix->persp2); } static inline sk_matrix_t ToMatrix(const SkMatrix* matrix) { sk_matrix_t m; - matrix->get9(m.mat); + m.scaleX = matrix->get(SkMatrix::kMScaleX); + m.skewX = matrix->get(SkMatrix::kMSkewX); + m.transX = matrix->get(SkMatrix::kMTransX); + m.skewY = matrix->get(SkMatrix::kMSkewY); + m.scaleY = matrix->get(SkMatrix::kMScaleY); + m.transY = matrix->get(SkMatrix::kMTransY); + m.persp0 = matrix->get(SkMatrix::kMPersp0); + m.persp1 = matrix->get(SkMatrix::kMPersp1); + m.persp2 = matrix->get(SkMatrix::kMPersp2); return m; } diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp index 4b350c4ec4b..f5ba6426de5 100644 --- a/src/codec/SkSwizzler.cpp +++ b/src/codec/SkSwizzler.cpp @@ -1206,11 +1206,31 @@ int SkSwizzler::onSetSampleX(int sampleX) { SkASSERT(sampleX > 0); fSampleX = sampleX; - fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); + int frameSampleX = sampleX; + if (fSrcWidth < fDstWidth) { + // Although SkSampledCodec adjusted sampleX so that it will never be + // larger than the width of the image (or subset, if applicable), it + // doesn't account for the width of a subset frame (i.e. gif). As a + // result, get_start_coord(sampleX) could result in fSrcOffsetUnits + // being wider than fSrcWidth. Compute a sampling rate based on the + // frame width to ensure that fSrcOffsetUnits is sensible. + frameSampleX = fSrcWidth / fSwizzleWidth; + } + fSrcOffsetUnits = (get_start_coord(frameSampleX) + fSrcOffset) * fSrcBPP; + + if (fDstOffsetBytes > 0) { + const size_t dstSwizzleBytes = fSwizzleWidth * fDstBPP; + const size_t dstAllocatedBytes = fAllocatedWidth * fDstBPP; + if (fDstOffsetBytes + dstSwizzleBytes > dstAllocatedBytes) { + SkASSERT(dstSwizzleBytes <= dstAllocatedBytes); + fDstOffsetBytes = dstAllocatedBytes - dstSwizzleBytes; + } + } + // The optimized swizzler functions do not support sampling. Sampled swizzles // are already fast because they skip pixels. We haven't seen a situation // where speeding up sampling has a significant impact on total decode time. diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h index 75be040fd43..e543af5f7b0 100644 --- a/src/ports/SkTypeface_win_dw.h +++ b/src/ports/SkTypeface_win_dw.h @@ -64,6 +64,10 @@ class DWriteFontTypeface : public SkTypeface { if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { SkASSERT_RELEASE(nullptr == fFactory2.get()); } + + if (fDWriteFontFace1 && fDWriteFontFace1->IsMonospacedFont()) { + this->setIsFixedPitch(true); + } } public: diff --git a/src/xamarin/SkiaKeeper.c b/src/xamarin/SkiaKeeper.c index f9bd4845411..348849bff30 100644 --- a/src/xamarin/SkiaKeeper.c +++ b/src/xamarin/SkiaKeeper.c @@ -80,7 +80,7 @@ void** KeepSkiaCSymbols (void) (void*)sk_stream_asset_destroy, (void*)sk_string_new_empty, (void*)sk_surface_new_null, - (void*)sk_svgcanvas_create, + (void*)sk_svgcanvas_create_with_stream, (void*)sk_typeface_unref, (void*)sk_textblob_ref, (void*)sk_xmlstreamwriter_new, diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index a89cacdb6b6..97b48def1f0 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -334,7 +334,7 @@ bool SkXPSDevice::endSheet() { } static HRESULT subset_typeface(SkXPSDevice::TypefaceUse* current) { -#if SK_BUILD_FOR_WINRT +#if SK_BUILD_FOR_WINRT || SK_BUILD_FOR_NANOSERVER return E_UNEXPECTED; #else //CreateFontPackage wants unsigned short. diff --git a/tests/CTest.cpp b/tests/CTest.cpp index 2116ffd9c11..a881e3ce612 100644 --- a/tests/CTest.cpp +++ b/tests/CTest.cpp @@ -8,6 +8,7 @@ #include "Test.h" #include "sk_canvas.h" #include "sk_paint.h" +#include "sk_general.h" #include "sk_shader.h" #include "sk_surface.h" #include "sk_types.h" diff --git a/tools/git-sync-deps b/tools/git-sync-deps index fe5c48f7992..26bfcbc230b 100755 --- a/tools/git-sync-deps +++ b/tools/git-sync-deps @@ -102,7 +102,7 @@ def is_git_toplevel(git, directory): def status(directory, checkoutable): def truncate(s, length): return s if len(s) <= length else s[:(length - 3)] + '...' - dlen = 36 + dlen = 86 directory = truncate(directory, dlen) checkoutable = truncate(checkoutable, 40) sys.stdout.write('%-*s @ %s\n' % (dlen, directory, checkoutable))