From 7bd6544ce15d3bd58c0ede1bb1f9ebca6264fe3a Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 21:43:42 +1000 Subject: [PATCH] remerge --- BUILD.gn | 4 ++ include/c/sk_types.h | 3 + include/xamarin/SkManagedIDChangeListener.h | 49 ++++++++++++++ .../xamarin/SkManagedIDChangeListenerList.h | 41 ++++++++++++ include/xamarin/sk_managedidchangelistener.h | 35 ++++++++++ .../xamarin/sk_managedidchangelistenerlist.h | 35 ++++++++++ include/xamarin/sk_managedpixelref.h | 2 +- src/c/sk_id_change_listener.cpp | 43 ++++++++++++ src/c/sk_types_priv.h | 5 ++ src/xamarin/SkManagedIDChangeListener.cpp | 30 +++++++++ src/xamarin/SkManagedIDChangeListenerList.cpp | 24 +++++++ src/xamarin/SkiaKeeper.c | 4 ++ src/xamarin/sk_managedidchangelistener.cpp | 59 +++++++++++++++++ .../sk_managedidchangelistenerlist.cpp | 66 +++++++++++++++++++ src/xamarin/sk_managedpixelref.cpp | 12 ++-- 15 files changed, 405 insertions(+), 7 deletions(-) create mode 100644 include/xamarin/SkManagedIDChangeListener.h create mode 100644 include/xamarin/SkManagedIDChangeListenerList.h create mode 100644 include/xamarin/sk_managedidchangelistener.h create mode 100644 include/xamarin/sk_managedidchangelistenerlist.h create mode 100644 src/c/sk_id_change_listener.cpp create mode 100644 src/xamarin/SkManagedIDChangeListener.cpp create mode 100644 src/xamarin/SkManagedIDChangeListenerList.cpp create mode 100644 src/xamarin/sk_managedidchangelistener.cpp create mode 100644 src/xamarin/sk_managedidchangelistenerlist.cpp diff --git a/BUILD.gn b/BUILD.gn index c221acdded0d..c2664deef249 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3089,6 +3089,8 @@ skiasharp_build("SkiaSharp") { sources = [ "src/xamarin/sk_compatpaint.cpp", + "src/xamarin/sk_managedidchangelistener.cpp", + "src/xamarin/sk_managedidchangelistenerlist.cpp", "src/xamarin/sk_manageddrawable.cpp", "src/xamarin/sk_managedallocator.cpp", "src/xamarin/sk_managedpixelref.cpp", @@ -3097,6 +3099,8 @@ skiasharp_build("SkiaSharp") { "src/xamarin/sk_xamarin.cpp", "src/xamarin/SkiaKeeper.c", "src/xamarin/SkCompatPaint.cpp", + "src/xamarin/SkManagedIDChangeListener.cpp", + "src/xamarin/SkManagedIDChangeListenerList.cpp", "src/xamarin/SkManagedDrawable.cpp", "src/xamarin/SkManagedAllocator.cpp", "src/xamarin/SkManagedPixelRef.cpp", diff --git a/include/c/sk_types.h b/include/c/sk_types.h index aaca718bd610..bc4b2694bd5e 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -351,6 +351,9 @@ typedef struct sk_pixelref_t sk_pixelref_t; typedef struct sk_imagefilter_t sk_imagefilter_t; typedef struct sk_imagefilter_croprect_t sk_imagefilter_croprect_t; +typedef struct sk_idchangelistener_t sk_idchangelistener_t; +typedef struct sk_idchangelistenerlist_t sk_idchangelistenerlist_t; + /** A sk_typeface_t pecifies the typeface and intrinsic style of a font. This is used in the paint, along with optionally algorithmic settings like diff --git a/include/xamarin/SkManagedIDChangeListener.h b/include/xamarin/SkManagedIDChangeListener.h new file mode 100644 index 000000000000..49e5c6c4587d --- /dev/null +++ b/include/xamarin/SkManagedIDChangeListener.h @@ -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. + */ + +#ifndef SkManagedIDChangeListener_h +#define SkManagedIDChangeListener_h + +#include "include/private/SkIDChangeListener.h" +#include "include/core/SkTypes.h" + +class SkIDChangeListener; + +class SK_API SkManagedIDChangeListener; + +// delegate declarations + +// managed Allocator +class SkManagedIDChangeListener : public SkIDChangeListener { +public: + SkManagedIDChangeListener(void* context); + + ~SkManagedIDChangeListener() override; + +public: + typedef void (*ChangedProc) (SkManagedIDChangeListener* d, void* context); + typedef void (*DestroyProc) (SkManagedIDChangeListener* d, void* context); + + struct Procs { + ChangedProc fChanged = nullptr; + DestroyProc fDestroy = nullptr; + }; + + static void setProcs(Procs procs); + +protected: + void changed() override; + +private: + void* fContext; + static Procs fProcs; + + typedef SkIDChangeListener INHERITED; +}; + + +#endif diff --git a/include/xamarin/SkManagedIDChangeListenerList.h b/include/xamarin/SkManagedIDChangeListenerList.h new file mode 100644 index 000000000000..cff5b92ec478 --- /dev/null +++ b/include/xamarin/SkManagedIDChangeListenerList.h @@ -0,0 +1,41 @@ +/* + * 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 SkManagedIDChangeListenerList_h +#define SkManagedIDChangeListenerList_h + +#include "include/private/SkIDChangeListener.h" +#include "include/core/SkTypes.h" + +class SK_API SkManagedIDChangeListenerList; + +// delegate declarations + +// managed Allocator +class SkManagedIDChangeListenerList : public SkIDChangeListener::List { +public: + SkManagedIDChangeListenerList(void* context); + + ~SkManagedIDChangeListenerList(); + + typedef void (*DestroyProc)(SkManagedIDChangeListenerList* d, void* context); + + struct Procs { + DestroyProc fDestroy = nullptr; + }; + + static void setProcs(Procs procs); + +private: + void* fContext; + static Procs fProcs; + + typedef SkIDChangeListener::List INHERITED; +}; + + +#endif diff --git a/include/xamarin/sk_managedidchangelistener.h b/include/xamarin/sk_managedidchangelistener.h new file mode 100644 index 000000000000..0ba4f0f2a752 --- /dev/null +++ b/include/xamarin/sk_managedidchangelistener.h @@ -0,0 +1,35 @@ +/* + * Copyright 2014 Google Inc. + * Copyright 2015 Xamarin Inc. + * Copyright 2017 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_managedidchangelistener_DEFINED +#define sk_managedidchangelistener_DEFINED + +#include "sk_xamarin.h" + +#include "include/c/sk_types.h" + +SK_C_PLUS_PLUS_BEGIN_GUARD + +typedef void (*sk_idchangelistener_changed_proc)(sk_idchangelistener_t* d, void* context); +typedef void (*sk_idchangelistener_destroy_proc)(sk_idchangelistener_t* d, void* context); + +typedef struct { + sk_idchangelistener_changed_proc fChanged; + sk_idchangelistener_destroy_proc fDestroy; +} sk_idchangelistener_procs_t; + +SK_X_API sk_idchangelistener_t* sk_managedidchangelistener_new(void* context); +SK_X_API void sk_managedidchangelistener_delete(sk_idchangelistener_t*); +SK_X_API void sk_managedidchangelistener_mark_should_deregister(sk_idchangelistener_t*); +SK_X_API bool sk_managedidchangelistener_should_deregister(sk_idchangelistener_t*); +SK_X_API void sk_managedidchangelistener_set_procs(sk_idchangelistener_procs_t procs); + +SK_C_PLUS_PLUS_END_GUARD + +#endif diff --git a/include/xamarin/sk_managedidchangelistenerlist.h b/include/xamarin/sk_managedidchangelistenerlist.h new file mode 100644 index 000000000000..30eb35008343 --- /dev/null +++ b/include/xamarin/sk_managedidchangelistenerlist.h @@ -0,0 +1,35 @@ +/* + * Copyright 2014 Google Inc. + * Copyright 2015 Xamarin Inc. + * Copyright 2017 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_managedidchangelistenerlist_DEFINED +#define sk_managedidchangelistenerlist_DEFINED + +#include "sk_xamarin.h" + +#include "include/c/sk_types.h" + +SK_C_PLUS_PLUS_BEGIN_GUARD + +typedef void (*sk_idchangelistenerlist_destroy_proc)(sk_idchangelistenerlist_t* d, void* context); + +typedef struct { + sk_idchangelistenerlist_destroy_proc fDestroy; +} sk_idchangelistenerlist_procs_t; + +SK_X_API sk_idchangelistenerlist_t* sk_managedidchangelistenerlist_new(void* context); +SK_X_API void sk_managedidchangelistenerlist_delete(sk_idchangelistenerlist_t*); +SK_X_API void sk_managedidchangelistenerlist_add(sk_idchangelistenerlist_t*, sk_idchangelistener_t*, bool single_threaded); +SK_X_API int32_t sk_managedidchangelistenerlist_count(sk_idchangelistenerlist_t*); +SK_X_API void sk_managedidchangelistenerlist_changed(sk_idchangelistenerlist_t*, bool single_threaded); +SK_X_API void sk_managedidchangelistenerlist_reset(sk_idchangelistenerlist_t*, bool single_threaded); +SK_X_API void sk_managedidchangelistenerlist_set_procs(sk_idchangelistenerlist_procs_t procs); + +SK_C_PLUS_PLUS_END_GUARD + +#endif diff --git a/include/xamarin/sk_managedpixelref.h b/include/xamarin/sk_managedpixelref.h index 726077a9dce3..76f6dc329713 100644 --- a/include/xamarin/sk_managedpixelref.h +++ b/include/xamarin/sk_managedpixelref.h @@ -35,7 +35,7 @@ SK_X_API uint32_t sk_managedpixelref_generation_id(sk_pixelref_t*); SK_X_API void sk_managedpixelref_notify_pixels_changed(sk_pixelref_t*); SK_X_API bool sk_managedpixelref_is_immutable(sk_pixelref_t*); SK_X_API void sk_managedpixelref_set_immutable(sk_pixelref_t*); -//SK_X_API void sk_managedpixelref_add_generation_id_listener(sk_pixelref_t*, sk_id_change_listener_t*); +SK_X_API void sk_managedpixelref_add_generation_id_listener(sk_pixelref_t*, sk_idchangelistener_t*); SK_X_API void sk_managedpixelref_notify_added_to_cache(sk_pixelref_t*); SK_X_API void sk_managedpixelref_set_procs(sk_pixelref_procs_t procs); diff --git a/src/c/sk_id_change_listener.cpp b/src/c/sk_id_change_listener.cpp new file mode 100644 index 000000000000..a36fefbb7f64 --- /dev/null +++ b/src/c/sk_id_change_listener.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2014 Google Inc. + * Copyright 2015 Xamarin Inc. + * Copyright 2017 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_idchangelistener_DEFINED +#define sk_idchangelistener_DEFINED + +#include "include/c/sk_idchangelistener.h" +#include "src/c/sk_types_priv.h" + +static inline SkIDChangeListener* AsSkIDChangeListener(sk_idchangelistener_t* d) { + return reinterpret_cast(d); +} + +static sk_idchangelistener_procs_t gProcs; + +void changed(SkIDChangeListener* d, void* context) { + if (gProcs.fChanged) { + gProcs.fChanged(ToSkIDChangeListener(d), context); + } +} + +sk_idchangelistener_t* sk_idchangelistener_new(void* context) { + return ToSKIDChangeListener(new SkIDChangeListener(context)); +} + +void sk_idchangelistener_delete(sk_idchangelistener_t* d) { delete AsManagedAllocator(d); } + +void sk_idchangelistener_set_procs(sk_idchangelistener_procs_t procs) { + gProcs = procs; + + SkManagedAllocator::Procs p; + p.fAllocPixelRef = allocPixelRef; + + SkManagedAllocator::setProcs(p); +} + +#endif diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h index b49e81fe6159..adea0e07856a 100644 --- a/src/c/sk_types_priv.h +++ b/src/c/sk_types_priv.h @@ -182,6 +182,11 @@ DEF_MAP(SkBitmap::Allocator, sk_bitmapallocator_t, BitmapAllocator) #include "include/effects/SkRuntimeEffect.h" DEF_MAP(SkRuntimeEffect::Uniform, sk_runtimeeffect_uniform_t, RuntimeEffectUniform) + +#include "include/private/SkIDChangeListener.h" +DEF_CLASS_MAP(SkIDChangeListener, sk_idchangelistener_t, SKIDChangeListener) +DEF_MAP(SkIDChangeListener::List, sk_idchangelistenerlist_t, SKIDChangeListenerList) + #include "include/core/SkCanvas.h" DEF_MAP(SkCanvas::Lattice, sk_lattice_t, Lattice) diff --git a/src/xamarin/SkManagedIDChangeListener.cpp b/src/xamarin/SkManagedIDChangeListener.cpp new file mode 100644 index 000000000000..98e754a48c20 --- /dev/null +++ b/src/xamarin/SkManagedIDChangeListener.cpp @@ -0,0 +1,30 @@ +/* + * 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/SkManagedIDChangeListener.h" + +SkManagedIDChangeListener::Procs SkManagedIDChangeListener::fProcs; + +void SkManagedIDChangeListener::setProcs(SkManagedIDChangeListener::Procs procs) { + fProcs = procs; +} + +SkManagedIDChangeListener::SkManagedIDChangeListener(void* context) { + fContext = context; +} + +SkManagedIDChangeListener::~SkManagedIDChangeListener() { + if (fProcs.fDestroy) { + fProcs.fDestroy(this, fContext); + } +} + +void SkManagedIDChangeListener::changed() { + if (fProcs.fChanged) { + fProcs.fChanged(this, fContext); + } +} diff --git a/src/xamarin/SkManagedIDChangeListenerList.cpp b/src/xamarin/SkManagedIDChangeListenerList.cpp new file mode 100644 index 000000000000..531814fe25ed --- /dev/null +++ b/src/xamarin/SkManagedIDChangeListenerList.cpp @@ -0,0 +1,24 @@ +/* + * 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/SkManagedIDChangeListenerList.h" + +SkManagedIDChangeListenerList::Procs SkManagedIDChangeListenerList::fProcs; + +void SkManagedIDChangeListenerList::setProcs(SkManagedIDChangeListenerList::Procs procs) { + fProcs = procs; +} + +SkManagedIDChangeListenerList::SkManagedIDChangeListenerList(void* context) { + fContext = context; +} + +SkManagedIDChangeListenerList::~SkManagedIDChangeListenerList() { + if (fProcs.fDestroy) { + fProcs.fDestroy(this, fContext); + } +} diff --git a/src/xamarin/SkiaKeeper.c b/src/xamarin/SkiaKeeper.c index 56cb5799ad54..c1e0c02f0f16 100644 --- a/src/xamarin/SkiaKeeper.c +++ b/src/xamarin/SkiaKeeper.c @@ -57,6 +57,8 @@ #include "include/xamarin/sk_managedpixelref.h" #include "include/xamarin/sk_manageddrawable.h" #include "include/xamarin/sk_managedtracememorydump.h" +#include "include/xamarin/sk_managedidchangelistener.h" +#include "include/xamarin/sk_managedidchangelistenerlist.h" #include "include/xamarin/sk_compatpaint.h" SK_X_API void** KeepSkiaCSymbols (void); @@ -116,6 +118,8 @@ void** KeepSkiaCSymbols (void) (void*)sk_managedpixelref_new_from_existing, (void*)sk_manageddrawable_new, (void*)sk_managedtracememorydump_new, + (void*)sk_managedidchangelistener_new, + (void*)sk_managedidchangelistenerlist_new, }; return ret; } diff --git a/src/xamarin/sk_managedidchangelistener.cpp b/src/xamarin/sk_managedidchangelistener.cpp new file mode 100644 index 000000000000..782da4cf5549 --- /dev/null +++ b/src/xamarin/sk_managedidchangelistener.cpp @@ -0,0 +1,59 @@ +/* + * 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/sk_managedidchangelistener.h" +#include "include/xamarin/SkManagedIDChangeListener.h" + +#include "src/c/sk_types_priv.h" + +static inline SkManagedIDChangeListener* AsSkManagedIDChangeListener(sk_idchangelistener_t* d) { + return reinterpret_cast(d); +} +static inline sk_idchangelistener_t* ToSkManagedIDChangeListener(SkManagedIDChangeListener* d) { + return reinterpret_cast(d); +} + +static sk_idchangelistener_procs_t gProcs; + +void changed(SkManagedIDChangeListener* d, void* context) { + if (gProcs.fChanged) { + gProcs.fChanged(ToSkManagedIDChangeListener(d), context); + } +} + +void destroy(SkManagedIDChangeListener* d, void* context) { + if (gProcs.fDestroy) { + gProcs.fDestroy(ToSkManagedIDChangeListener(d), context); + } +} + +sk_idchangelistener_t* sk_managedidchangelistener_new(void* context) { + return ToSkManagedIDChangeListener(new SkManagedIDChangeListener(context)); +} + +void sk_managedidchangelistener_delete(sk_idchangelistener_t* d) { + delete AsSkManagedIDChangeListener(d); +} + +void sk_managedidchangelistener_mark_should_deregister(sk_idchangelistener_t* d) { + AsSkManagedIDChangeListener(d)->markShouldDeregister(); +} + +bool sk_managedidchangelistener_should_deregister(sk_idchangelistener_t* d) { + return AsSkManagedIDChangeListener(d)->shouldDeregister(); +} + +void sk_managedidchangelistener_set_procs(sk_idchangelistener_procs_t procs) { + gProcs = procs; + + SkManagedIDChangeListener::Procs p; + p.fChanged = changed; + p.fDestroy = destroy; + + SkManagedIDChangeListener::setProcs(p); +} diff --git a/src/xamarin/sk_managedidchangelistenerlist.cpp b/src/xamarin/sk_managedidchangelistenerlist.cpp new file mode 100644 index 000000000000..59f2d190096c --- /dev/null +++ b/src/xamarin/sk_managedidchangelistenerlist.cpp @@ -0,0 +1,66 @@ +/* + * 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/sk_managedidchangelistener.h" +#include "include/xamarin/SkManagedIDChangeListener.h" + +#include "include/xamarin/sk_managedidchangelistenerlist.h" +#include "include/xamarin/SkManagedIDChangeListenerList.h" + +#include "src/c/sk_types_priv.h" + +static inline SkManagedIDChangeListener* AsSkManagedIDChangeListener(sk_idchangelistener_t* d) { + return reinterpret_cast(d); +} +static inline SkManagedIDChangeListenerList* AsSkManagedIDChangeListenerList(sk_idchangelistenerlist_t* d) { + return reinterpret_cast(d); +} +static inline sk_idchangelistenerlist_t* ToSkManagedIDChangeListenerList(SkManagedIDChangeListenerList* d) { + return reinterpret_cast(d); +} + +static sk_idchangelistenerlist_procs_t gProcs; + +void destroy_List(SkManagedIDChangeListenerList* d, void* context) { + if (gProcs.fDestroy) { + gProcs.fDestroy(ToSkManagedIDChangeListenerList(d), context); + } +} + +sk_idchangelistenerlist_t* sk_managedidchangelistenerlist_new(void* context) { + return ToSkManagedIDChangeListenerList(new SkManagedIDChangeListenerList(context)); +} + +void sk_managedidchangelistenerlist_delete(sk_idchangelistenerlist_t* d) { + delete AsSkManagedIDChangeListenerList(d); +} + +void sk_managedidchangelistenerlist_add(sk_idchangelistenerlist_t* d, sk_idchangelistener_t* listener, bool single_threaded) { + AsSkManagedIDChangeListenerList(d)->add(sk_sp(AsSkManagedIDChangeListener(listener)), + single_threaded); +} + +int32_t sk_managedidchangelistenerlist_count(sk_idchangelistenerlist_t* d) { + return AsSkManagedIDChangeListenerList(d)->count(); +} + +void sk_managedidchangelistenerlist_changed(sk_idchangelistenerlist_t* d, bool single_threaded) { + AsSkManagedIDChangeListenerList(d)->changed(single_threaded); +} + +void sk_managedidchangelistenerlist_reset(sk_idchangelistenerlist_t* d, bool single_threaded) { + AsSkManagedIDChangeListenerList(d)->reset(single_threaded); +} + +void sk_managedidchangelistenerlist_set_procs(sk_idchangelistenerlist_procs_t procs) { + gProcs = procs; + + SkManagedIDChangeListenerList::Procs p; + p.fDestroy = destroy_List; + + SkManagedIDChangeListenerList::setProcs(p); +} diff --git a/src/xamarin/sk_managedpixelref.cpp b/src/xamarin/sk_managedpixelref.cpp index 53a2f3861f80..a81a0c00325f 100644 --- a/src/xamarin/sk_managedpixelref.cpp +++ b/src/xamarin/sk_managedpixelref.cpp @@ -6,7 +6,7 @@ */ #include "include/xamarin/SkManagedPixelRef.h" -#include "include/xamarin/SkManaged_ID_Change_Listener.h" +#include "include/xamarin/SkManagedIDChangeListener.h" #include "include/xamarin/sk_managedpixelref.h" #include "src/c/sk_types_priv.h" @@ -17,8 +17,8 @@ static inline sk_pixelref_t* ToSkPixelRef(SkManagedPixelRef* d) { return reinterpret_cast(d); } -static inline SkManaged_ID_Change_Listener* AsSkManaged_ID_Change_Listener(sk_id_change_listener_t* d) { - return reinterpret_cast(d); +static inline SkManagedIDChangeListener* AsSkManagedIDChangeListener(sk_idchangelistener_t* d) { + return reinterpret_cast(d); } static sk_pixelref_procs_t gProcs; @@ -76,9 +76,9 @@ bool sk_managedpixelref_is_immutable(sk_pixelref_t* d) { void sk_managedpixelref_set_immutable(sk_pixelref_t* d) { AsSkManagedPixelRef(d)->pixelRef->setImmutable(); } -//void sk_managedpixelref_add_generation_id_listener(sk_pixelref_t* d, sk_id_change_listener_t* listener) { -// AsSkManagedPixelRef(d)->pixelRef->addGenIDChangeListener(sk_ref_sp(AsSkManaged_ID_Change_Listener(listener))); -//} +void sk_managedpixelref_add_generation_id_listener(sk_pixelref_t* d, sk_idchangelistener_t* listener) { + AsSkManagedPixelRef(d)->pixelRef->addGenIDChangeListener(sk_ref_sp(AsSkManagedIDChangeListener(listener))); +} void sk_managedpixelref_notify_added_to_cache(sk_pixelref_t* d) { AsSkManagedPixelRef(d)->pixelRef->notifyAddedToCache(); }