From ec8d84cbe71d56241814a495a93c2cf45bb5e347 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 30 Jun 2022 21:07:18 +1000 Subject: [PATCH 01/12] add png chunk reader, expose more of codec and bitmap --- BUILD.gn | 4 ++ include/c/sk_bitmap.h | 7 +++ include/c/sk_codec.h | 5 +- include/c/sk_types.h | 10 ++++ include/xamarin/SkManaged_Png_Chunk_Reader.h | 47 ++++++++++++++++++ include/xamarin/sk_managed_png_chunk_reader.h | 33 +++++++++++++ src/c/sk_bitmap.cpp | 29 +++++++++++ src/c/sk_codec.cpp | 12 +++-- src/c/sk_types_priv.h | 1 + src/xamarin/SkManaged_Png_Chunk_Reader.cpp | 29 +++++++++++ src/xamarin/SkiaKeeper.c | 6 +++ src/xamarin/sk_managed_png_chunk_reader.cpp | 49 +++++++++++++++++++ 12 files changed, 226 insertions(+), 6 deletions(-) create mode 100644 include/xamarin/SkManaged_Png_Chunk_Reader.h create mode 100644 include/xamarin/sk_managed_png_chunk_reader.h create mode 100644 src/xamarin/SkManaged_Png_Chunk_Reader.cpp create mode 100644 src/xamarin/sk_managed_png_chunk_reader.cpp diff --git a/BUILD.gn b/BUILD.gn index 61facb7a1957..b81d4b2fd140 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3088,12 +3088,16 @@ skiasharp_build("SkiaSharp") { ] sources = [ + // placed here to help seperate in PR + "src/xamarin/sk_managed_png_chunk_reader.cpp", "src/xamarin/sk_compatpaint.cpp", "src/xamarin/sk_manageddrawable.cpp", "src/xamarin/sk_managedstream.cpp", "src/xamarin/sk_managedtracememorydump.cpp", "src/xamarin/sk_xamarin.cpp", "src/xamarin/SkiaKeeper.c", + // placed here to help seperate in PR + "src/xamarin/SkManaged_Png_Chunk_Reader.cpp", "src/xamarin/SkCompatPaint.cpp", "src/xamarin/SkManagedDrawable.cpp", "src/xamarin/SkManagedStream.cpp", diff --git a/include/c/sk_bitmap.h b/include/c/sk_bitmap.h index bf019a05e8ad..c7fb3e8eae0b 100644 --- a/include/c/sk_bitmap.h +++ b/include/c/sk_bitmap.h @@ -17,9 +17,11 @@ SK_C_PLUS_PLUS_BEGIN_GUARD SK_C_API void sk_bitmap_destructor(sk_bitmap_t* cbitmap); SK_C_API sk_bitmap_t* sk_bitmap_new(void); SK_C_API void sk_bitmap_get_info(sk_bitmap_t* cbitmap, sk_imageinfo_t* info); +SK_C_API bool sk_bitmap_set_info(sk_bitmap_t* cbitmap, const sk_imageinfo_t* requestedInfo, size_t rowBytes); SK_C_API void* sk_bitmap_get_pixels(sk_bitmap_t* cbitmap, size_t* length); SK_C_API size_t sk_bitmap_get_row_bytes(sk_bitmap_t* cbitmap); SK_C_API size_t sk_bitmap_get_byte_count(sk_bitmap_t* cbitmap); +SK_C_API uint32_t sk_bitmap_get_generation_id(sk_bitmap_t* cbitmap); SK_C_API void sk_bitmap_reset(sk_bitmap_t* cbitmap); SK_C_API bool sk_bitmap_is_null(sk_bitmap_t* cbitmap); SK_C_API bool sk_bitmap_is_immutable(sk_bitmap_t* cbitmap); @@ -32,7 +34,12 @@ 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 bool sk_bitmap_ready_to_draw(sk_bitmap_t* cbitmap); +SK_C_API bool sk_bitmap_compute_is_opaque(sk_bitmap_t* cbitmap); +SK_C_API const sk_pixmap_t* sk_bitmap_get_pixmap(sk_bitmap_t* cbitmap); SK_C_API void sk_bitmap_get_pixel_colors(sk_bitmap_t* cbitmap, sk_color_t* colors); +SK_C_API bool sk_bitmap_read_pixels_imageinfo(sk_bitmap_t* cbitmap, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t rowBytes, int x, int y); +SK_C_API bool sk_bitmap_read_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y); +SK_C_API bool sk_bitmap_write_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y); SK_C_API bool sk_bitmap_install_pixels(sk_bitmap_t* cbitmap, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_bitmap_release_proc releaseProc, void* context); SK_C_API bool sk_bitmap_install_pixels_with_pixmap(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap); SK_C_API bool sk_bitmap_install_mask_pixels(sk_bitmap_t* cbitmap, const sk_mask_t* cmask); diff --git a/include/c/sk_codec.h b/include/c/sk_codec.h index 75201447b3b8..10694eb760c4 100644 --- a/include/c/sk_codec.h +++ b/include/c/sk_codec.h @@ -16,11 +16,12 @@ SK_C_PLUS_PLUS_BEGIN_GUARD SK_C_API size_t sk_codec_min_buffered_bytes_needed(void); -SK_C_API sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result); -SK_C_API sk_codec_t* sk_codec_new_from_data(sk_data_t* data); +SK_C_API sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy); +SK_C_API sk_codec_t* sk_codec_new_from_data(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader); SK_C_API void sk_codec_destroy(sk_codec_t* codec); SK_C_API void sk_codec_get_info(sk_codec_t* codec, sk_imageinfo_t* info); SK_C_API sk_encodedorigin_t sk_codec_get_origin(sk_codec_t* codec); +SK_C_API void sk_codec_get_dimensions(sk_codec_t* codec, sk_isize_t* dimensions); SK_C_API void sk_codec_get_scaled_dimensions(sk_codec_t* codec, float desiredScale, sk_isize_t* dimensions); SK_C_API bool sk_codec_get_valid_subset(sk_codec_t* codec, sk_irect_t* desiredSubset); SK_C_API sk_encoded_image_format_t sk_codec_get_encoded_format(sk_codec_t* codec); diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 289ecaee92ee..9fb45b70074d 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -344,6 +344,8 @@ typedef struct sk_string_t sk_string_t; */ typedef struct sk_bitmap_t sk_bitmap_t; typedef struct sk_pixmap_t sk_pixmap_t; +// placed here to help seperate in PR +typedef struct sk_png_chunk_reader_t sk_png_chunk_reader_t; typedef struct sk_colorfilter_t sk_colorfilter_t; typedef struct sk_imagefilter_t sk_imagefilter_t; typedef struct sk_imagefilter_croprect_t sk_imagefilter_croprect_t; @@ -472,6 +474,14 @@ typedef enum { HEIF_SK_ENCODED_FORMAT, } sk_encoded_image_format_t; +/** + * Enum describing selection policy. + */ +typedef enum { + kPreferStillImage, + kPreferAnimation, +} sk_codec_selection_policy_t; + typedef enum { TOP_LEFT_SK_ENCODED_ORIGIN = 1, // Default TOP_RIGHT_SK_ENCODED_ORIGIN = 2, // Reflected across y-axis diff --git a/include/xamarin/SkManaged_Png_Chunk_Reader.h b/include/xamarin/SkManaged_Png_Chunk_Reader.h new file mode 100644 index 000000000000..1bbc0c211970 --- /dev/null +++ b/include/xamarin/SkManaged_Png_Chunk_Reader.h @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Microsoft Corporation. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkManaged_Png_Chunk_Reader_h +#define SkManaged_Png_Chunk_Reader_h + +#include "include/core/SkPngChunkReader.h" +#include "include/core/SkTypes.h" + +class SK_API SkManaged_Png_Chunk_Reader; + +// delegate declarations + +// managed _Png_Chunk_Reader +class SkManaged_Png_Chunk_Reader : public SkPngChunkReader { +public: + SkManaged_Png_Chunk_Reader(void* context); + + ~SkManaged_Png_Chunk_Reader() override; + +public: + typedef bool (*ReadChunkProc) (SkManaged_Png_Chunk_Reader* d, void* context, const char* tag, const void* data, size_t length); + typedef void (*DestroyProc) (SkManaged_Png_Chunk_Reader* d, void* context); + + struct Procs { + ReadChunkProc fReadChunk = nullptr; + DestroyProc fDestroy = nullptr; + }; + + static void setProcs(Procs procs); + +protected: + bool readChunk(const char tag[], const void* data, size_t length) override; + +private: + void* fContext; + static Procs fProcs; + + typedef SkPngChunkReader INHERITED; +}; + + +#endif diff --git a/include/xamarin/sk_managed_png_chunk_reader.h b/include/xamarin/sk_managed_png_chunk_reader.h new file mode 100644 index 000000000000..5c05e74097bf --- /dev/null +++ b/include/xamarin/sk_managed_png_chunk_reader.h @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Microsoft Corporation. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef sk_managed_png_chunk_reader_DEFINED +#define sk_managed_png_chunk_reader_DEFINED + +#include "sk_xamarin.h" + +#include "include/c/sk_types.h" + +SK_C_PLUS_PLUS_BEGIN_GUARD + +typedef struct sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_t; + +typedef bool (*sk_managed_png_chunk_reader_read_chunk_proc) (sk_managed_png_chunk_reader_t* d, void* context, const char tag[], const void* data, size_t length); +typedef void (*sk_managed_png_chunk_reader_destroy_proc) (sk_managed_png_chunk_reader_t* d, void* context); + +typedef struct { + sk_managed_png_chunk_reader_read_chunk_proc fReadChunk; + sk_managed_png_chunk_reader_destroy_proc fDestroy; +} sk_managed_png_chunk_reader_procs_t; + +SK_X_API sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context); +SK_X_API void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t*); +SK_X_API void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs); + +SK_C_PLUS_PLUS_END_GUARD + +#endif diff --git a/src/c/sk_bitmap.cpp b/src/c/sk_bitmap.cpp index 7e6d84270a4f..3da7201b24b7 100644 --- a/src/c/sk_bitmap.cpp +++ b/src/c/sk_bitmap.cpp @@ -31,6 +31,10 @@ void sk_bitmap_get_info(sk_bitmap_t* cbitmap, sk_imageinfo_t* info) { *info = ToImageInfo(AsBitmap(cbitmap)->info()); } +bool sk_bitmap_set_info(sk_bitmap_t* cbitmap, const sk_imageinfo_t* requestedInfo, size_t rowBytes) { + return AsBitmap(cbitmap)->setInfo(AsImageInfo(requestedInfo), rowBytes); +} + void* sk_bitmap_get_pixels(sk_bitmap_t* cbitmap, size_t* length) { SkBitmap* bmp = AsBitmap(cbitmap); *length = bmp->computeByteSize(); @@ -45,6 +49,10 @@ size_t sk_bitmap_get_byte_count(sk_bitmap_t* cbitmap) { return AsBitmap(cbitmap)->computeByteSize(); } +uint32_t sk_bitmap_get_generation_id(sk_bitmap_t* cbitmap) { + return AsBitmap(cbitmap)->getGenerationID(); +} + void sk_bitmap_reset(sk_bitmap_t* cbitmap) { AsBitmap(cbitmap)->reset(); } @@ -93,6 +101,15 @@ bool sk_bitmap_ready_to_draw(sk_bitmap_t* cbitmap) { return AsBitmap(cbitmap)->readyToDraw(); } +bool sk_bitmap_compute_is_opaque(sk_bitmap_t* cbitmap) { + return SkBitmap::ComputeIsOpaque(*AsBitmap(cbitmap)); +} + +const sk_pixmap_t* sk_bitmap_get_pixmap(sk_bitmap_t* cbitmap) { + const SkPixmap& pixmap = AsBitmap(cbitmap)->pixmap(); + return ToPixmap(&pixmap); +} + void sk_bitmap_get_pixel_colors(sk_bitmap_t* cbitmap, sk_color_t* colors) { SkBitmap* bmp = AsBitmap(cbitmap); int w = bmp->width(); @@ -105,6 +122,18 @@ void sk_bitmap_get_pixel_colors(sk_bitmap_t* cbitmap, sk_color_t* colors) { } } +bool sk_bitmap_read_pixels_imageinfo(sk_bitmap_t* cbitmap, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t rowBytes, int x, int y) { + return AsBitmap(cbitmap)->readPixels(AsImageInfo(dstInfo), dstPixels, rowBytes, x, y); +} + +bool sk_bitmap_read_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y) { + return AsBitmap(cbitmap)->readPixels(*AsPixmap(cpixmap), x, y); +} + +bool sk_bitmap_write_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y) { + return AsBitmap(cbitmap)->writePixels(*AsPixmap(cpixmap), x, y); +} + bool sk_bitmap_install_pixels(sk_bitmap_t* cbitmap, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_bitmap_release_proc releaseProc, void* context) { return AsBitmap(cbitmap)->installPixels(AsImageInfo(cinfo), pixels, rowBytes, releaseProc, context); } diff --git a/src/c/sk_codec.cpp b/src/c/sk_codec.cpp index d2bb62f7f867..30e8111881f8 100644 --- a/src/c/sk_codec.cpp +++ b/src/c/sk_codec.cpp @@ -17,13 +17,13 @@ size_t sk_codec_min_buffered_bytes_needed(void) { return SkCodec::MinBufferedBytesNeeded(); } -sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result) { +sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy) { std::unique_ptr skstream(AsStream(stream)); - return ToCodec(SkCodec::MakeFromStream(std::move(skstream), (SkCodec::Result*)result).release()); + return ToCodec(SkCodec::MakeFromStream(std::move(skstream), (SkCodec::Result*)result, AsPngChunkReader(chunk_reader), (SkCodec::SelectionPolicy)policy).release()); } -sk_codec_t* sk_codec_new_from_data(sk_data_t* data) { - return ToCodec(SkCodec::MakeFromData(sk_ref_sp(AsData(data))).release()); +sk_codec_t* sk_codec_new_from_data(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader) { + return ToCodec(SkCodec::MakeFromData(sk_ref_sp(AsData(data)), AsPngChunkReader(chunk_reader)).release()); } void sk_codec_destroy(sk_codec_t* codec) { @@ -42,6 +42,10 @@ void sk_codec_get_scaled_dimensions(sk_codec_t* codec, float desiredScale, sk_is *dimensions = ToISize(AsCodec(codec)->getScaledDimensions(desiredScale)); } +void sk_codec_get_dimensions(sk_codec_t* codec, sk_isize_t* dimensions) { + *dimensions = ToISize(AsCodec(codec)->dimensions()); +} + bool sk_codec_get_valid_subset(sk_codec_t* codec, sk_irect_t* desiredSubset) { return AsCodec(codec)->getValidSubset(AsIRect(desiredSubset)); } diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h index af460d8994d0..abbfb8f22256 100644 --- a/src/c/sk_types_priv.h +++ b/src/c/sk_types_priv.h @@ -127,6 +127,7 @@ DEF_CLASS_MAP(SkPathMeasure, sk_pathmeasure_t, PathMeasure) DEF_CLASS_MAP(SkPicture, sk_picture_t, Picture) DEF_CLASS_MAP(SkPictureRecorder, sk_picture_recorder_t, PictureRecorder) DEF_CLASS_MAP(SkPixmap, sk_pixmap_t, Pixmap) +DEF_CLASS_MAP(SkPngChunkReader, sk_png_chunk_reader_t, PngChunkReader) DEF_CLASS_MAP(SkRegion, sk_region_t, Region) DEF_CLASS_MAP(SkRRect, sk_rrect_t, RRect) DEF_CLASS_MAP(SkRuntimeEffect, sk_runtimeeffect_t, RuntimeEffect) diff --git a/src/xamarin/SkManaged_Png_Chunk_Reader.cpp b/src/xamarin/SkManaged_Png_Chunk_Reader.cpp new file mode 100644 index 000000000000..e4ccfea34cd3 --- /dev/null +++ b/src/xamarin/SkManaged_Png_Chunk_Reader.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2022 Microsoft Corporation. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "include/xamarin/SkManaged_Png_Chunk_Reader.h" + +SkManaged_Png_Chunk_Reader::Procs SkManaged_Png_Chunk_Reader::fProcs; + +void SkManaged_Png_Chunk_Reader::setProcs(SkManaged_Png_Chunk_Reader::Procs procs) { + fProcs = procs; +} + +SkManaged_Png_Chunk_Reader::SkManaged_Png_Chunk_Reader(void* context) { + fContext = context; +} + +SkManaged_Png_Chunk_Reader::~SkManaged_Png_Chunk_Reader() { + if (fProcs.fDestroy) { + fProcs.fDestroy(this, fContext); + } +} + +bool SkManaged_Png_Chunk_Reader::readChunk(const char tag[], const void* data, size_t length) { + if (!fProcs.fReadChunk) return false; + return fProcs.fReadChunk(this, fContext, tag, data, length); +} diff --git a/src/xamarin/SkiaKeeper.c b/src/xamarin/SkiaKeeper.c index 67f482881e68..12f7860d1c8b 100644 --- a/src/xamarin/SkiaKeeper.c +++ b/src/xamarin/SkiaKeeper.c @@ -53,6 +53,8 @@ // Xamarin #include "include/xamarin/sk_managedstream.h" #include "include/xamarin/sk_manageddrawable.h" +// placed here to help seperate in PR +#include "include/xamarin/sk_managed_png_chunk_reader.h" #include "include/xamarin/sk_managedtracememorydump.h" #include "include/xamarin/sk_compatpaint.h" @@ -68,6 +70,8 @@ void** KeepSkiaCSymbols (void) (void*)sk_bitmap_new, (void*)sk_canvas_destroy, (void*)sk_codec_min_buffered_bytes_needed, + (void*)sk_codec_new_from_data, + (void*)sk_codec_new_from_stream, (void*)sk_colorfilter_unref, (void*)sk_colorspace_unref, (void*)sk_colortable_unref, @@ -108,6 +112,8 @@ void** KeepSkiaCSymbols (void) (void*)sk_compatpaint_new, (void*)sk_managedstream_new, (void*)sk_manageddrawable_new, + // placed here to help seperate in pr + (void*)sk_managed_png_chunk_reader_new, (void*)sk_managedtracememorydump_new, }; return ret; diff --git a/src/xamarin/sk_managed_png_chunk_reader.cpp b/src/xamarin/sk_managed_png_chunk_reader.cpp new file mode 100644 index 000000000000..972bf9f1660e --- /dev/null +++ b/src/xamarin/sk_managed_png_chunk_reader.cpp @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Microsoft Corporation. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "include/xamarin/SkManaged_Png_Chunk_Reader.h" + +#include "include/xamarin/sk_managed_png_chunk_reader.h" +#include "src/c/sk_types_priv.h" + +static inline SkManaged_Png_Chunk_Reader* AsManaged_Png_Chunk_Reader(sk_managed_png_chunk_reader_t* d) { + return reinterpret_cast(d); +} +static inline sk_managed_png_chunk_reader_t* ToManaged_Png_Chunk_Reader(SkManaged_Png_Chunk_Reader* d) { + return reinterpret_cast(d); +} + +static sk_managed_png_chunk_reader_procs_t gProcs; + +bool readChunk(SkManaged_Png_Chunk_Reader* d, void* context, const char tag[], const void* data, size_t length) { + if (!gProcs.fReadChunk) return false; + return gProcs.fReadChunk(ToManaged_Png_Chunk_Reader(d), context, tag, data, length); +} + +void destroy(SkManaged_Png_Chunk_Reader* d, void* context) { + if (gProcs.fDestroy) { + gProcs.fDestroy(ToManaged_Png_Chunk_Reader(d), context); + } +} + +sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) { + return ToManaged_Png_Chunk_Reader(new SkManaged_Png_Chunk_Reader(context)); +} + +void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t* d) { + delete AsManaged_Png_Chunk_Reader(d); +} + +void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) { + gProcs = procs; + + SkManaged_Png_Chunk_Reader::Procs p; + p.fReadChunk = readChunk; + p.fDestroy = destroy; + + SkManaged_Png_Chunk_Reader::setProcs(p); +} From 7223d032775edc51fca67b9d8c7b2e4a8f50372b Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 1 Jul 2022 00:07:46 +1000 Subject: [PATCH 02/12] replace // with # --- BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index b81d4b2fd140..14fd21fd4bf8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3088,7 +3088,7 @@ skiasharp_build("SkiaSharp") { ] sources = [ - // placed here to help seperate in PR + # placed here to help seperate in PR "src/xamarin/sk_managed_png_chunk_reader.cpp", "src/xamarin/sk_compatpaint.cpp", "src/xamarin/sk_manageddrawable.cpp", @@ -3096,7 +3096,7 @@ skiasharp_build("SkiaSharp") { "src/xamarin/sk_managedtracememorydump.cpp", "src/xamarin/sk_xamarin.cpp", "src/xamarin/SkiaKeeper.c", - // placed here to help seperate in PR + # placed here to help seperate in PR "src/xamarin/SkManaged_Png_Chunk_Reader.cpp", "src/xamarin/SkCompatPaint.cpp", "src/xamarin/SkManagedDrawable.cpp", From 99d4501c1bdd31ca47881aec75bca47a53113e2a Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 1 Jul 2022 12:33:20 +1000 Subject: [PATCH 03/12] remove seperation comments --- BUILD.gn | 2 -- include/c/sk_types.h | 1 - src/xamarin/SkiaKeeper.c | 2 -- 3 files changed, 5 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 14fd21fd4bf8..1f676d6a0f6f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3088,7 +3088,6 @@ skiasharp_build("SkiaSharp") { ] sources = [ - # placed here to help seperate in PR "src/xamarin/sk_managed_png_chunk_reader.cpp", "src/xamarin/sk_compatpaint.cpp", "src/xamarin/sk_manageddrawable.cpp", @@ -3096,7 +3095,6 @@ skiasharp_build("SkiaSharp") { "src/xamarin/sk_managedtracememorydump.cpp", "src/xamarin/sk_xamarin.cpp", "src/xamarin/SkiaKeeper.c", - # placed here to help seperate in PR "src/xamarin/SkManaged_Png_Chunk_Reader.cpp", "src/xamarin/SkCompatPaint.cpp", "src/xamarin/SkManagedDrawable.cpp", diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 9fb45b70074d..0638903756dc 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -344,7 +344,6 @@ typedef struct sk_string_t sk_string_t; */ typedef struct sk_bitmap_t sk_bitmap_t; typedef struct sk_pixmap_t sk_pixmap_t; -// placed here to help seperate in PR typedef struct sk_png_chunk_reader_t sk_png_chunk_reader_t; typedef struct sk_colorfilter_t sk_colorfilter_t; typedef struct sk_imagefilter_t sk_imagefilter_t; diff --git a/src/xamarin/SkiaKeeper.c b/src/xamarin/SkiaKeeper.c index 12f7860d1c8b..3439b9b6aee9 100644 --- a/src/xamarin/SkiaKeeper.c +++ b/src/xamarin/SkiaKeeper.c @@ -53,7 +53,6 @@ // Xamarin #include "include/xamarin/sk_managedstream.h" #include "include/xamarin/sk_manageddrawable.h" -// placed here to help seperate in PR #include "include/xamarin/sk_managed_png_chunk_reader.h" #include "include/xamarin/sk_managedtracememorydump.h" #include "include/xamarin/sk_compatpaint.h" @@ -112,7 +111,6 @@ void** KeepSkiaCSymbols (void) (void*)sk_compatpaint_new, (void*)sk_managedstream_new, (void*)sk_manageddrawable_new, - // placed here to help seperate in pr (void*)sk_managed_png_chunk_reader_new, (void*)sk_managedtracememorydump_new, }; From 4d840a0c5107e67ddd765222a869af28ff4295d0 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 1 Jul 2022 12:42:08 +1000 Subject: [PATCH 04/12] move get_dimensions to C# land --- include/c/sk_codec.h | 1 - src/c/sk_codec.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/include/c/sk_codec.h b/include/c/sk_codec.h index 10694eb760c4..28c44ce5f747 100644 --- a/include/c/sk_codec.h +++ b/include/c/sk_codec.h @@ -21,7 +21,6 @@ SK_C_API sk_codec_t* sk_codec_new_from_data(sk_data_t* data, sk_png_chunk_reader SK_C_API void sk_codec_destroy(sk_codec_t* codec); SK_C_API void sk_codec_get_info(sk_codec_t* codec, sk_imageinfo_t* info); SK_C_API sk_encodedorigin_t sk_codec_get_origin(sk_codec_t* codec); -SK_C_API void sk_codec_get_dimensions(sk_codec_t* codec, sk_isize_t* dimensions); SK_C_API void sk_codec_get_scaled_dimensions(sk_codec_t* codec, float desiredScale, sk_isize_t* dimensions); SK_C_API bool sk_codec_get_valid_subset(sk_codec_t* codec, sk_irect_t* desiredSubset); SK_C_API sk_encoded_image_format_t sk_codec_get_encoded_format(sk_codec_t* codec); diff --git a/src/c/sk_codec.cpp b/src/c/sk_codec.cpp index 30e8111881f8..e507f3ea29e1 100644 --- a/src/c/sk_codec.cpp +++ b/src/c/sk_codec.cpp @@ -42,10 +42,6 @@ void sk_codec_get_scaled_dimensions(sk_codec_t* codec, float desiredScale, sk_is *dimensions = ToISize(AsCodec(codec)->getScaledDimensions(desiredScale)); } -void sk_codec_get_dimensions(sk_codec_t* codec, sk_isize_t* dimensions) { - *dimensions = ToISize(AsCodec(codec)->dimensions()); -} - bool sk_codec_get_valid_subset(sk_codec_t* codec, sk_irect_t* desiredSubset) { return AsCodec(codec)->getValidSubset(AsIRect(desiredSubset)); } From 6609362ab0b8bfbe4a1ccc2855733acd768a1445 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 1 Jul 2022 12:42:20 +1000 Subject: [PATCH 05/12] apply suggestion --- src/xamarin/SkManaged_Png_Chunk_Reader.cpp | 5 ++--- src/xamarin/sk_managed_png_chunk_reader.cpp | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/xamarin/SkManaged_Png_Chunk_Reader.cpp b/src/xamarin/SkManaged_Png_Chunk_Reader.cpp index e4ccfea34cd3..987608c7a2e5 100644 --- a/src/xamarin/SkManaged_Png_Chunk_Reader.cpp +++ b/src/xamarin/SkManaged_Png_Chunk_Reader.cpp @@ -18,9 +18,8 @@ SkManaged_Png_Chunk_Reader::SkManaged_Png_Chunk_Reader(void* context) { } SkManaged_Png_Chunk_Reader::~SkManaged_Png_Chunk_Reader() { - if (fProcs.fDestroy) { - fProcs.fDestroy(this, fContext); - } + if (!fProcs.fDestroy) return; + fProcs.fDestroy(this, fContext); } bool SkManaged_Png_Chunk_Reader::readChunk(const char tag[], const void* data, size_t length) { diff --git a/src/xamarin/sk_managed_png_chunk_reader.cpp b/src/xamarin/sk_managed_png_chunk_reader.cpp index 972bf9f1660e..13706b19c557 100644 --- a/src/xamarin/sk_managed_png_chunk_reader.cpp +++ b/src/xamarin/sk_managed_png_chunk_reader.cpp @@ -25,9 +25,8 @@ bool readChunk(SkManaged_Png_Chunk_Reader* d, void* context, const char tag[], c } void destroy(SkManaged_Png_Chunk_Reader* d, void* context) { - if (gProcs.fDestroy) { - gProcs.fDestroy(ToManaged_Png_Chunk_Reader(d), context); - } + if (!gProcs.fDestroy) return; + gProcs.fDestroy(ToManaged_Png_Chunk_Reader(d), context); } sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) { From f07800cb66c6a2f00596bb399132ca54c2fae23a Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 1 Jul 2022 12:53:24 +1000 Subject: [PATCH 06/12] original C api must be kept --- include/c/sk_codec.h | 6 ++++-- src/c/sk_codec.cpp | 13 +++++++++++-- src/xamarin/SkiaKeeper.c | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/c/sk_codec.h b/include/c/sk_codec.h index 28c44ce5f747..e9ddebd0600a 100644 --- a/include/c/sk_codec.h +++ b/include/c/sk_codec.h @@ -16,8 +16,10 @@ SK_C_PLUS_PLUS_BEGIN_GUARD SK_C_API size_t sk_codec_min_buffered_bytes_needed(void); -SK_C_API sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy); -SK_C_API sk_codec_t* sk_codec_new_from_data(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader); +SK_C_API sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result); +SK_C_API sk_codec_t* sk_codec_new_from_data(sk_data_t* data); +SK_C_API sk_codec_t* sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy); +SK_C_API sk_codec_t* sk_codec_new_from_data_with_png_chunk_reader(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader); SK_C_API void sk_codec_destroy(sk_codec_t* codec); SK_C_API void sk_codec_get_info(sk_codec_t* codec, sk_imageinfo_t* info); SK_C_API sk_encodedorigin_t sk_codec_get_origin(sk_codec_t* codec); diff --git a/src/c/sk_codec.cpp b/src/c/sk_codec.cpp index e507f3ea29e1..b1415625cf6e 100644 --- a/src/c/sk_codec.cpp +++ b/src/c/sk_codec.cpp @@ -17,12 +17,21 @@ size_t sk_codec_min_buffered_bytes_needed(void) { return SkCodec::MinBufferedBytesNeeded(); } -sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy) { +sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result) { + std::unique_ptr skstream(AsStream(stream)); + return ToCodec(SkCodec::MakeFromStream(std::move(skstream), (SkCodec::Result*)result).release()); +} + +sk_codec_t* sk_codec_new_from_data(sk_data_t* data) { + return ToCodec(SkCodec::MakeFromData(sk_ref_sp(AsData(data))).release()); +} + +sk_codec_t* sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy) { std::unique_ptr skstream(AsStream(stream)); return ToCodec(SkCodec::MakeFromStream(std::move(skstream), (SkCodec::Result*)result, AsPngChunkReader(chunk_reader), (SkCodec::SelectionPolicy)policy).release()); } -sk_codec_t* sk_codec_new_from_data(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader) { +sk_codec_t* sk_codec_new_from_data_with_png_chunk_reader(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader) { return ToCodec(SkCodec::MakeFromData(sk_ref_sp(AsData(data)), AsPngChunkReader(chunk_reader)).release()); } diff --git a/src/xamarin/SkiaKeeper.c b/src/xamarin/SkiaKeeper.c index 3439b9b6aee9..53788dfe5201 100644 --- a/src/xamarin/SkiaKeeper.c +++ b/src/xamarin/SkiaKeeper.c @@ -71,6 +71,8 @@ void** KeepSkiaCSymbols (void) (void*)sk_codec_min_buffered_bytes_needed, (void*)sk_codec_new_from_data, (void*)sk_codec_new_from_stream, + (void*)sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy, + (void*)sk_codec_new_from_data_with_png_chunk_reader, (void*)sk_colorfilter_unref, (void*)sk_colorspace_unref, (void*)sk_colortable_unref, From 56e7c4271b44d1698257511a99b5f04580c8889b Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 1 Jul 2022 14:02:38 +1000 Subject: [PATCH 07/12] move read_pixels to C# land --- include/c/sk_bitmap.h | 2 -- src/c/sk_bitmap.cpp | 8 -------- 2 files changed, 10 deletions(-) diff --git a/include/c/sk_bitmap.h b/include/c/sk_bitmap.h index c7fb3e8eae0b..752bd25babf5 100644 --- a/include/c/sk_bitmap.h +++ b/include/c/sk_bitmap.h @@ -37,8 +37,6 @@ SK_C_API bool sk_bitmap_ready_to_draw(sk_bitmap_t* cbitmap); SK_C_API bool sk_bitmap_compute_is_opaque(sk_bitmap_t* cbitmap); SK_C_API const sk_pixmap_t* sk_bitmap_get_pixmap(sk_bitmap_t* cbitmap); SK_C_API void sk_bitmap_get_pixel_colors(sk_bitmap_t* cbitmap, sk_color_t* colors); -SK_C_API bool sk_bitmap_read_pixels_imageinfo(sk_bitmap_t* cbitmap, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t rowBytes, int x, int y); -SK_C_API bool sk_bitmap_read_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y); SK_C_API bool sk_bitmap_write_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y); SK_C_API bool sk_bitmap_install_pixels(sk_bitmap_t* cbitmap, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_bitmap_release_proc releaseProc, void* context); SK_C_API bool sk_bitmap_install_pixels_with_pixmap(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap); diff --git a/src/c/sk_bitmap.cpp b/src/c/sk_bitmap.cpp index 3da7201b24b7..4d301921235b 100644 --- a/src/c/sk_bitmap.cpp +++ b/src/c/sk_bitmap.cpp @@ -122,14 +122,6 @@ void sk_bitmap_get_pixel_colors(sk_bitmap_t* cbitmap, sk_color_t* colors) { } } -bool sk_bitmap_read_pixels_imageinfo(sk_bitmap_t* cbitmap, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t rowBytes, int x, int y) { - return AsBitmap(cbitmap)->readPixels(AsImageInfo(dstInfo), dstPixels, rowBytes, x, y); -} - -bool sk_bitmap_read_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y) { - return AsBitmap(cbitmap)->readPixels(*AsPixmap(cpixmap), x, y); -} - bool sk_bitmap_write_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y) { return AsBitmap(cbitmap)->writePixels(*AsPixmap(cpixmap), x, y); } From f17efc64f6136d5777c46390e54d5166f2854390 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 20:48:16 +1000 Subject: [PATCH 08/12] rename to match naming convention --- BUILD.gn | 4 +- ...unk_Reader.h => SkManagedPngChunkReader.h} | 16 +++---- ...nk_reader.h => sk_managedpngchunkreader.h} | 0 src/xamarin/SkManagedPngChunkReader.cpp | 28 +++++++++++ src/xamarin/SkManaged_Png_Chunk_Reader.cpp | 28 ----------- src/xamarin/sk_managed_png_chunk_reader.cpp | 48 ------------------- src/xamarin/sk_managedpngchunkreader.cpp | 48 +++++++++++++++++++ 7 files changed, 86 insertions(+), 86 deletions(-) rename include/xamarin/{SkManaged_Png_Chunk_Reader.h => SkManagedPngChunkReader.h} (57%) rename include/xamarin/{sk_managed_png_chunk_reader.h => sk_managedpngchunkreader.h} (100%) create mode 100644 src/xamarin/SkManagedPngChunkReader.cpp delete mode 100644 src/xamarin/SkManaged_Png_Chunk_Reader.cpp delete mode 100644 src/xamarin/sk_managed_png_chunk_reader.cpp create mode 100644 src/xamarin/sk_managedpngchunkreader.cpp diff --git a/BUILD.gn b/BUILD.gn index 1f676d6a0f6f..6f28508971ef 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3088,14 +3088,14 @@ skiasharp_build("SkiaSharp") { ] sources = [ - "src/xamarin/sk_managed_png_chunk_reader.cpp", + "src/xamarin/sk_managedpngchunkreader.cpp", "src/xamarin/sk_compatpaint.cpp", "src/xamarin/sk_manageddrawable.cpp", "src/xamarin/sk_managedstream.cpp", "src/xamarin/sk_managedtracememorydump.cpp", "src/xamarin/sk_xamarin.cpp", "src/xamarin/SkiaKeeper.c", - "src/xamarin/SkManaged_Png_Chunk_Reader.cpp", + "src/xamarin/SkManagedPngChunkReader.cpp", "src/xamarin/SkCompatPaint.cpp", "src/xamarin/SkManagedDrawable.cpp", "src/xamarin/SkManagedStream.cpp", diff --git a/include/xamarin/SkManaged_Png_Chunk_Reader.h b/include/xamarin/SkManagedPngChunkReader.h similarity index 57% rename from include/xamarin/SkManaged_Png_Chunk_Reader.h rename to include/xamarin/SkManagedPngChunkReader.h index 1bbc0c211970..a86ed4923995 100644 --- a/include/xamarin/SkManaged_Png_Chunk_Reader.h +++ b/include/xamarin/SkManagedPngChunkReader.h @@ -5,26 +5,26 @@ * found in the LICENSE file. */ -#ifndef SkManaged_Png_Chunk_Reader_h -#define SkManaged_Png_Chunk_Reader_h +#ifndef SkManagedPngChunkReader_h +#define SkManagedPngChunkReader_h #include "include/core/SkPngChunkReader.h" #include "include/core/SkTypes.h" -class SK_API SkManaged_Png_Chunk_Reader; +class SK_API SkManagedPngChunkReader; // delegate declarations // managed _Png_Chunk_Reader -class SkManaged_Png_Chunk_Reader : public SkPngChunkReader { +class SkManagedPngChunkReader : public SkPngChunkReader { public: - SkManaged_Png_Chunk_Reader(void* context); + SkManagedPngChunkReader(void* context); - ~SkManaged_Png_Chunk_Reader() override; + ~SkManagedPngChunkReader() override; public: - typedef bool (*ReadChunkProc) (SkManaged_Png_Chunk_Reader* d, void* context, const char* tag, const void* data, size_t length); - typedef void (*DestroyProc) (SkManaged_Png_Chunk_Reader* d, void* context); + typedef bool (*ReadChunkProc) (SkManagedPngChunkReader* d, void* context, const char* tag, const void* data, size_t length); + typedef void (*DestroyProc) (SkManagedPngChunkReader* d, void* context); struct Procs { ReadChunkProc fReadChunk = nullptr; diff --git a/include/xamarin/sk_managed_png_chunk_reader.h b/include/xamarin/sk_managedpngchunkreader.h similarity index 100% rename from include/xamarin/sk_managed_png_chunk_reader.h rename to include/xamarin/sk_managedpngchunkreader.h diff --git a/src/xamarin/SkManagedPngChunkReader.cpp b/src/xamarin/SkManagedPngChunkReader.cpp new file mode 100644 index 000000000000..b319b22070a7 --- /dev/null +++ b/src/xamarin/SkManagedPngChunkReader.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2022 Microsoft Corporation. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "include/xamarin/SkManagedPngChunkReader.h" + +SkManagedPngChunkReader::Procs SkManagedPngChunkReader::fProcs; + +void SkManagedPngChunkReader::setProcs(SkManagedPngChunkReader::Procs procs) { + fProcs = procs; +} + +SkManagedPngChunkReader::SkManagedPngChunkReader(void* context) { + fContext = context; +} + +SkManagedPngChunkReader::~SkManagedPngChunkReader() { + if (!fProcs.fDestroy) return; + fProcs.fDestroy(this, fContext); +} + +bool SkManagedPngChunkReader::readChunk(const char tag[], const void* data, size_t length) { + if (!fProcs.fReadChunk) return false; + return fProcs.fReadChunk(this, fContext, tag, data, length); +} diff --git a/src/xamarin/SkManaged_Png_Chunk_Reader.cpp b/src/xamarin/SkManaged_Png_Chunk_Reader.cpp deleted file mode 100644 index 987608c7a2e5..000000000000 --- a/src/xamarin/SkManaged_Png_Chunk_Reader.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2022 Microsoft Corporation. All rights reserved. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "include/xamarin/SkManaged_Png_Chunk_Reader.h" - -SkManaged_Png_Chunk_Reader::Procs SkManaged_Png_Chunk_Reader::fProcs; - -void SkManaged_Png_Chunk_Reader::setProcs(SkManaged_Png_Chunk_Reader::Procs procs) { - fProcs = procs; -} - -SkManaged_Png_Chunk_Reader::SkManaged_Png_Chunk_Reader(void* context) { - fContext = context; -} - -SkManaged_Png_Chunk_Reader::~SkManaged_Png_Chunk_Reader() { - if (!fProcs.fDestroy) return; - fProcs.fDestroy(this, fContext); -} - -bool SkManaged_Png_Chunk_Reader::readChunk(const char tag[], const void* data, size_t length) { - if (!fProcs.fReadChunk) return false; - return fProcs.fReadChunk(this, fContext, tag, data, length); -} diff --git a/src/xamarin/sk_managed_png_chunk_reader.cpp b/src/xamarin/sk_managed_png_chunk_reader.cpp deleted file mode 100644 index 13706b19c557..000000000000 --- a/src/xamarin/sk_managed_png_chunk_reader.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2022 Microsoft Corporation. All rights reserved. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "include/xamarin/SkManaged_Png_Chunk_Reader.h" - -#include "include/xamarin/sk_managed_png_chunk_reader.h" -#include "src/c/sk_types_priv.h" - -static inline SkManaged_Png_Chunk_Reader* AsManaged_Png_Chunk_Reader(sk_managed_png_chunk_reader_t* d) { - return reinterpret_cast(d); -} -static inline sk_managed_png_chunk_reader_t* ToManaged_Png_Chunk_Reader(SkManaged_Png_Chunk_Reader* d) { - return reinterpret_cast(d); -} - -static sk_managed_png_chunk_reader_procs_t gProcs; - -bool readChunk(SkManaged_Png_Chunk_Reader* d, void* context, const char tag[], const void* data, size_t length) { - if (!gProcs.fReadChunk) return false; - return gProcs.fReadChunk(ToManaged_Png_Chunk_Reader(d), context, tag, data, length); -} - -void destroy(SkManaged_Png_Chunk_Reader* d, void* context) { - if (!gProcs.fDestroy) return; - gProcs.fDestroy(ToManaged_Png_Chunk_Reader(d), context); -} - -sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) { - return ToManaged_Png_Chunk_Reader(new SkManaged_Png_Chunk_Reader(context)); -} - -void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t* d) { - delete AsManaged_Png_Chunk_Reader(d); -} - -void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) { - gProcs = procs; - - SkManaged_Png_Chunk_Reader::Procs p; - p.fReadChunk = readChunk; - p.fDestroy = destroy; - - SkManaged_Png_Chunk_Reader::setProcs(p); -} diff --git a/src/xamarin/sk_managedpngchunkreader.cpp b/src/xamarin/sk_managedpngchunkreader.cpp new file mode 100644 index 000000000000..acd9fe1317aa --- /dev/null +++ b/src/xamarin/sk_managedpngchunkreader.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Microsoft Corporation. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "include/xamarin/SkManagedPngChunkReader.h" + +#include "include/xamarin/sk_managedpngchunkreader.h" +#include "src/c/sk_types_priv.h" + +static inline SkManagedPngChunkReader* AsManagedPngChunkReader(sk_managed_png_chunk_reader_t* d) { + return reinterpret_cast(d); +} +static inline sk_managed_png_chunk_reader_t* ToManagedPngChunkReader(SkManagedPngChunkReader* d) { + return reinterpret_cast(d); +} + +static sk_managed_png_chunk_reader_procs_t gProcs; + +bool readChunk(SkManagedPngChunkReader* d, void* context, const char tag[], const void* data, size_t length) { + if (!gProcs.fReadChunk) return false; + return gProcs.fReadChunk(ToManagedPngChunkReader(d), context, tag, data, length); +} + +void destroy(SkManagedPngChunkReader* d, void* context) { + if (!gProcs.fDestroy) return; + gProcs.fDestroy(ToManagedPngChunkReader(d), context); +} + +sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) { + return ToManagedPngChunkReader(new SkManagedPngChunkReader(context)); +} + +void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t* d) { + delete AsManagedPngChunkReader(d); +} + +void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) { + gProcs = procs; + + SkManagedPngChunkReader::Procs p; + p.fReadChunk = readChunk; + p.fDestroy = destroy; + + SkManagedPngChunkReader::setProcs(p); +} From a5e40b9178c2113afce767d3fbc08191224fd7d3 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 21:22:03 +1000 Subject: [PATCH 09/12] rename to match naming convention --- include/c/sk_types.h | 4 ++-- include/codec/SkCodec.h | 6 +++--- src/codec/SkCodec.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 0638903756dc..5646ed79a303 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -477,8 +477,8 @@ typedef enum { * Enum describing selection policy. */ typedef enum { - kPreferStillImage, - kPreferAnimation, + PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY, + PREFER_ANIMATION_SK_CODEC_SELECTION_POLICY, } sk_codec_selection_policy_t; typedef enum { diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index 8b1fc3bdcf47..facac90b4d39 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -121,12 +121,12 @@ class SK_API SkCodec : SkNoncopyable { * If the container format contains both still images and image sequences, * SkCodec should choose one of the still images. This is the default. */ - kPreferStillImage, + PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY, /** * If the container format contains both still images and image sequences, * SkCodec should choose one of the image sequences for animation. */ - kPreferAnimation, + PREFER_ANIMATION_SK_CODEC_SELECTION_POLICY, }; /** @@ -166,7 +166,7 @@ class SK_API SkCodec : SkNoncopyable { static std::unique_ptr MakeFromStream( std::unique_ptr, Result* = nullptr, SkPngChunkReader* = nullptr, - SelectionPolicy selectionPolicy = SelectionPolicy::kPreferStillImage); + SelectionPolicy selectionPolicy = SelectionPolicy::PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY); /** * If this data represents an encoded image that we know how to decode, diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index f51efe46b63a..be42f96a33b7 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -76,8 +76,8 @@ std::unique_ptr SkCodec::MakeFromStream( return nullptr; } - if (selectionPolicy != SelectionPolicy::kPreferStillImage - && selectionPolicy != SelectionPolicy::kPreferAnimation) { + if (selectionPolicy != SelectionPolicy::PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY + && selectionPolicy != SelectionPolicy::PREFER_ANIMATION_SK_CODEC_SELECTION_POLICY) { *outResult = kInvalidParameters; return nullptr; } From 8daaac19292bcce3b8f849cd450ee8b997928050 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 8 Jul 2022 13:52:53 +1000 Subject: [PATCH 10/12] rename to match --- include/c/sk_codec.h | 4 ++-- include/c/sk_types.h | 2 +- include/xamarin/SkManagedPngChunkReader.h | 1 - include/xamarin/sk_managedpngchunkreader.h | 22 +++++++++++----------- src/c/sk_codec.cpp | 4 ++-- src/c/sk_types_priv.h | 2 +- src/xamarin/SkiaKeeper.c | 8 ++++---- src/xamarin/sk_managedpngchunkreader.cpp | 14 +++++++------- 8 files changed, 28 insertions(+), 29 deletions(-) diff --git a/include/c/sk_codec.h b/include/c/sk_codec.h index e9ddebd0600a..d1fb4bfa65c3 100644 --- a/include/c/sk_codec.h +++ b/include/c/sk_codec.h @@ -18,8 +18,8 @@ SK_C_API size_t sk_codec_min_buffered_bytes_needed(void); SK_C_API sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result); SK_C_API sk_codec_t* sk_codec_new_from_data(sk_data_t* data); -SK_C_API sk_codec_t* sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy); -SK_C_API sk_codec_t* sk_codec_new_from_data_with_png_chunk_reader(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader); +SK_C_API sk_codec_t* sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_pngchunkreader_t* chunk_reader, sk_codec_selection_policy_t policy); +SK_C_API sk_codec_t* sk_codec_new_from_data_with_pngchunkreader(sk_data_t* data, sk_pngchunkreader_t* chunk_reader); SK_C_API void sk_codec_destroy(sk_codec_t* codec); SK_C_API void sk_codec_get_info(sk_codec_t* codec, sk_imageinfo_t* info); SK_C_API sk_encodedorigin_t sk_codec_get_origin(sk_codec_t* codec); diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 5646ed79a303..95b92756d9f4 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -344,7 +344,7 @@ typedef struct sk_string_t sk_string_t; */ typedef struct sk_bitmap_t sk_bitmap_t; typedef struct sk_pixmap_t sk_pixmap_t; -typedef struct sk_png_chunk_reader_t sk_png_chunk_reader_t; +typedef struct sk_pngchunkreader_t sk_pngchunkreader_t; typedef struct sk_colorfilter_t sk_colorfilter_t; typedef struct sk_imagefilter_t sk_imagefilter_t; typedef struct sk_imagefilter_croprect_t sk_imagefilter_croprect_t; diff --git a/include/xamarin/SkManagedPngChunkReader.h b/include/xamarin/SkManagedPngChunkReader.h index a86ed4923995..b3b3d8804e9a 100644 --- a/include/xamarin/SkManagedPngChunkReader.h +++ b/include/xamarin/SkManagedPngChunkReader.h @@ -15,7 +15,6 @@ class SK_API SkManagedPngChunkReader; // delegate declarations -// managed _Png_Chunk_Reader class SkManagedPngChunkReader : public SkPngChunkReader { public: SkManagedPngChunkReader(void* context); diff --git a/include/xamarin/sk_managedpngchunkreader.h b/include/xamarin/sk_managedpngchunkreader.h index 5c05e74097bf..851891754817 100644 --- a/include/xamarin/sk_managedpngchunkreader.h +++ b/include/xamarin/sk_managedpngchunkreader.h @@ -5,8 +5,8 @@ * found in the LICENSE file. */ -#ifndef sk_managed_png_chunk_reader_DEFINED -#define sk_managed_png_chunk_reader_DEFINED +#ifndef sk_managedpngchunkreader_DEFINED +#define sk_managedpngchunkreader_DEFINED #include "sk_xamarin.h" @@ -14,19 +14,19 @@ SK_C_PLUS_PLUS_BEGIN_GUARD -typedef struct sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_t; +typedef struct sk_managedpngchunkreader_t sk_managedpngchunkreader_t; -typedef bool (*sk_managed_png_chunk_reader_read_chunk_proc) (sk_managed_png_chunk_reader_t* d, void* context, const char tag[], const void* data, size_t length); -typedef void (*sk_managed_png_chunk_reader_destroy_proc) (sk_managed_png_chunk_reader_t* d, void* context); +typedef bool (*sk_managedpngchunkreader_read_chunk_proc) (sk_managedpngchunkreader_t* d, void* context, const char tag[], const void* data, size_t length); +typedef void (*sk_managedpngchunkreader_destroy_proc) (sk_managedpngchunkreader_t* d, void* context); typedef struct { - sk_managed_png_chunk_reader_read_chunk_proc fReadChunk; - sk_managed_png_chunk_reader_destroy_proc fDestroy; -} sk_managed_png_chunk_reader_procs_t; + sk_managedpngchunkreader_read_chunk_proc fReadChunk; + sk_managedpngchunkreader_destroy_proc fDestroy; +} sk_managedpngchunkreader_procs_t; -SK_X_API sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context); -SK_X_API void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t*); -SK_X_API void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs); +SK_X_API sk_managedpngchunkreader_t* sk_managedpngchunkreader_new(void* context); +SK_X_API void sk_managedpngchunkreader_delete(sk_managedpngchunkreader_t*); +SK_X_API void sk_managedpngchunkreader_set_procs(sk_managedpngchunkreader_procs_t procs); SK_C_PLUS_PLUS_END_GUARD diff --git a/src/c/sk_codec.cpp b/src/c/sk_codec.cpp index b1415625cf6e..f8d4f849760d 100644 --- a/src/c/sk_codec.cpp +++ b/src/c/sk_codec.cpp @@ -26,12 +26,12 @@ sk_codec_t* sk_codec_new_from_data(sk_data_t* data) { return ToCodec(SkCodec::MakeFromData(sk_ref_sp(AsData(data))).release()); } -sk_codec_t* sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy) { +sk_codec_t* sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_pngchunkreader_t* chunk_reader, sk_codec_selection_policy_t policy) { std::unique_ptr skstream(AsStream(stream)); return ToCodec(SkCodec::MakeFromStream(std::move(skstream), (SkCodec::Result*)result, AsPngChunkReader(chunk_reader), (SkCodec::SelectionPolicy)policy).release()); } -sk_codec_t* sk_codec_new_from_data_with_png_chunk_reader(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader) { +sk_codec_t* sk_codec_new_from_data_with_pngchunkreader(sk_data_t* data, sk_pngchunkreader_t* chunk_reader) { return ToCodec(SkCodec::MakeFromData(sk_ref_sp(AsData(data)), AsPngChunkReader(chunk_reader)).release()); } diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h index abbfb8f22256..8eb58f667a86 100644 --- a/src/c/sk_types_priv.h +++ b/src/c/sk_types_priv.h @@ -127,7 +127,7 @@ DEF_CLASS_MAP(SkPathMeasure, sk_pathmeasure_t, PathMeasure) DEF_CLASS_MAP(SkPicture, sk_picture_t, Picture) DEF_CLASS_MAP(SkPictureRecorder, sk_picture_recorder_t, PictureRecorder) DEF_CLASS_MAP(SkPixmap, sk_pixmap_t, Pixmap) -DEF_CLASS_MAP(SkPngChunkReader, sk_png_chunk_reader_t, PngChunkReader) +DEF_CLASS_MAP(SkPngChunkReader, sk_pngchunkreader_t, PngChunkReader) DEF_CLASS_MAP(SkRegion, sk_region_t, Region) DEF_CLASS_MAP(SkRRect, sk_rrect_t, RRect) DEF_CLASS_MAP(SkRuntimeEffect, sk_runtimeeffect_t, RuntimeEffect) diff --git a/src/xamarin/SkiaKeeper.c b/src/xamarin/SkiaKeeper.c index 53788dfe5201..6c34702d2c0f 100644 --- a/src/xamarin/SkiaKeeper.c +++ b/src/xamarin/SkiaKeeper.c @@ -53,7 +53,7 @@ // Xamarin #include "include/xamarin/sk_managedstream.h" #include "include/xamarin/sk_manageddrawable.h" -#include "include/xamarin/sk_managed_png_chunk_reader.h" +#include "include/xamarin/sk_managedpngchunkreader.h" #include "include/xamarin/sk_managedtracememorydump.h" #include "include/xamarin/sk_compatpaint.h" @@ -71,8 +71,8 @@ void** KeepSkiaCSymbols (void) (void*)sk_codec_min_buffered_bytes_needed, (void*)sk_codec_new_from_data, (void*)sk_codec_new_from_stream, - (void*)sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy, - (void*)sk_codec_new_from_data_with_png_chunk_reader, + (void*)sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy, + (void*)sk_codec_new_from_data_with_pngchunkreader, (void*)sk_colorfilter_unref, (void*)sk_colorspace_unref, (void*)sk_colortable_unref, @@ -113,7 +113,7 @@ void** KeepSkiaCSymbols (void) (void*)sk_compatpaint_new, (void*)sk_managedstream_new, (void*)sk_manageddrawable_new, - (void*)sk_managed_png_chunk_reader_new, + (void*)sk_managedpngchunkreader_new, (void*)sk_managedtracememorydump_new, }; return ret; diff --git a/src/xamarin/sk_managedpngchunkreader.cpp b/src/xamarin/sk_managedpngchunkreader.cpp index acd9fe1317aa..41abfee87f3c 100644 --- a/src/xamarin/sk_managedpngchunkreader.cpp +++ b/src/xamarin/sk_managedpngchunkreader.cpp @@ -10,14 +10,14 @@ #include "include/xamarin/sk_managedpngchunkreader.h" #include "src/c/sk_types_priv.h" -static inline SkManagedPngChunkReader* AsManagedPngChunkReader(sk_managed_png_chunk_reader_t* d) { +static inline SkManagedPngChunkReader* AsManagedPngChunkReader(sk_managedpngchunkreader_t* d) { return reinterpret_cast(d); } -static inline sk_managed_png_chunk_reader_t* ToManagedPngChunkReader(SkManagedPngChunkReader* d) { - return reinterpret_cast(d); +static inline sk_managedpngchunkreader_t* ToManagedPngChunkReader(SkManagedPngChunkReader* d) { + return reinterpret_cast(d); } -static sk_managed_png_chunk_reader_procs_t gProcs; +static sk_managedpngchunkreader_procs_t gProcs; bool readChunk(SkManagedPngChunkReader* d, void* context, const char tag[], const void* data, size_t length) { if (!gProcs.fReadChunk) return false; @@ -29,15 +29,15 @@ void destroy(SkManagedPngChunkReader* d, void* context) { gProcs.fDestroy(ToManagedPngChunkReader(d), context); } -sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) { +sk_managedpngchunkreader_t* sk_managedpngchunkreader_new(void* context) { return ToManagedPngChunkReader(new SkManagedPngChunkReader(context)); } -void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t* d) { +void sk_managedpngchunkreader_delete(sk_managedpngchunkreader_t* d) { delete AsManagedPngChunkReader(d); } -void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) { +void sk_managedpngchunkreader_set_procs(sk_managedpngchunkreader_procs_t procs) { gProcs = procs; SkManagedPngChunkReader::Procs p; From 9a34bcacfa1bfd424b09cfd1d52b6ecc6580a24c Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 00:32:48 +1000 Subject: [PATCH 11/12] undo renamed skia selection policy --- include/codec/SkCodec.h | 6 +++--- src/codec/SkCodec.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index facac90b4d39..8b1fc3bdcf47 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -121,12 +121,12 @@ class SK_API SkCodec : SkNoncopyable { * If the container format contains both still images and image sequences, * SkCodec should choose one of the still images. This is the default. */ - PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY, + kPreferStillImage, /** * If the container format contains both still images and image sequences, * SkCodec should choose one of the image sequences for animation. */ - PREFER_ANIMATION_SK_CODEC_SELECTION_POLICY, + kPreferAnimation, }; /** @@ -166,7 +166,7 @@ class SK_API SkCodec : SkNoncopyable { static std::unique_ptr MakeFromStream( std::unique_ptr, Result* = nullptr, SkPngChunkReader* = nullptr, - SelectionPolicy selectionPolicy = SelectionPolicy::PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY); + SelectionPolicy selectionPolicy = SelectionPolicy::kPreferStillImage); /** * If this data represents an encoded image that we know how to decode, diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index be42f96a33b7..f51efe46b63a 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -76,8 +76,8 @@ std::unique_ptr SkCodec::MakeFromStream( return nullptr; } - if (selectionPolicy != SelectionPolicy::PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY - && selectionPolicy != SelectionPolicy::PREFER_ANIMATION_SK_CODEC_SELECTION_POLICY) { + if (selectionPolicy != SelectionPolicy::kPreferStillImage + && selectionPolicy != SelectionPolicy::kPreferAnimation) { *outResult = kInvalidParameters; return nullptr; } From e08263f522f85e3648d9df05f2aed63bf8aa845c Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Tue, 12 Jul 2022 15:30:55 +1000 Subject: [PATCH 12/12] add enum guard --- src/c/sk_enums.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/c/sk_enums.cpp b/src/c/sk_enums.cpp index 4505ac8a8dcb..8b19a27b0586 100644 --- a/src/c/sk_enums.cpp +++ b/src/c/sk_enums.cpp @@ -249,6 +249,10 @@ static_assert ((int)SkCodec::ZeroInitialized::kNo_ZeroInitialized == (int)NO_ static_assert ((int)SkCodec::SkScanlineOrder::kTopDown_SkScanlineOrder == (int)TOP_DOWN_SK_CODEC_SCANLINE_ORDER, ASSERT_MSG(SkCodec::SkScanlineOrder, sk_codec_scanline_order_t)); static_assert ((int)SkCodec::SkScanlineOrder::kBottomUp_SkScanlineOrder == (int)BOTTOM_UP_SK_CODEC_SCANLINE_ORDER, ASSERT_MSG(SkCodec::SkScanlineOrder, sk_codec_scanline_order_t)); +// sk_codec_selection_policy_t +static_assert ((int)SkCodec::SelectionPolicy::kPreferStillImage == (int)PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY, ASSERT_MSG(SkCodec::SelectionPolicy, sk_codec_selection_policy_t)); +static_assert ((int)SkCodec::SelectionPolicy::kPreferAnimation == (int)PREFER_ANIMATION_SK_CODEC_SELECTION_POLICY, ASSERT_MSG(SkCodec::SelectionPolicy, sk_codec_selection_policy_t)); + // sk_codecanimation_disposalmethod_t static_assert ((int)SkCodecAnimation::DisposalMethod::kKeep == (int)KEEP_SK_CODEC_ANIMATION_DISPOSAL_METHOD, ASSERT_MSG(SkCodec::SkScanlineOrder, sk_codecanimation_disposalmethod_t)); static_assert ((int)SkCodecAnimation::DisposalMethod::kRestoreBGColor == (int)RESTORE_BG_COLOR_SK_CODEC_ANIMATION_DISPOSAL_METHOD, ASSERT_MSG(SkCodec::SkScanlineOrder, sk_codecanimation_disposalmethod_t));