Skip to content

Commit 7bd6544

Browse files
committed
remerge
1 parent 9a7aedc commit 7bd6544

15 files changed

+405
-7
lines changed

BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,6 +3089,8 @@ skiasharp_build("SkiaSharp") {
30893089

30903090
sources = [
30913091
"src/xamarin/sk_compatpaint.cpp",
3092+
"src/xamarin/sk_managedidchangelistener.cpp",
3093+
"src/xamarin/sk_managedidchangelistenerlist.cpp",
30923094
"src/xamarin/sk_manageddrawable.cpp",
30933095
"src/xamarin/sk_managedallocator.cpp",
30943096
"src/xamarin/sk_managedpixelref.cpp",
@@ -3097,6 +3099,8 @@ skiasharp_build("SkiaSharp") {
30973099
"src/xamarin/sk_xamarin.cpp",
30983100
"src/xamarin/SkiaKeeper.c",
30993101
"src/xamarin/SkCompatPaint.cpp",
3102+
"src/xamarin/SkManagedIDChangeListener.cpp",
3103+
"src/xamarin/SkManagedIDChangeListenerList.cpp",
31003104
"src/xamarin/SkManagedDrawable.cpp",
31013105
"src/xamarin/SkManagedAllocator.cpp",
31023106
"src/xamarin/SkManagedPixelRef.cpp",

include/c/sk_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ typedef struct sk_pixelref_t sk_pixelref_t;
351351
typedef struct sk_imagefilter_t sk_imagefilter_t;
352352
typedef struct sk_imagefilter_croprect_t sk_imagefilter_croprect_t;
353353

354+
typedef struct sk_idchangelistener_t sk_idchangelistener_t;
355+
typedef struct sk_idchangelistenerlist_t sk_idchangelistenerlist_t;
356+
354357
/**
355358
A sk_typeface_t pecifies the typeface and intrinsic style of a font.
356359
This is used in the paint, along with optionally algorithmic settings like
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2022 Microsoft Corporation. All rights reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#ifndef SkManagedIDChangeListener_h
9+
#define SkManagedIDChangeListener_h
10+
11+
#include "include/private/SkIDChangeListener.h"
12+
#include "include/core/SkTypes.h"
13+
14+
class SkIDChangeListener;
15+
16+
class SK_API SkManagedIDChangeListener;
17+
18+
// delegate declarations
19+
20+
// managed Allocator
21+
class SkManagedIDChangeListener : public SkIDChangeListener {
22+
public:
23+
SkManagedIDChangeListener(void* context);
24+
25+
~SkManagedIDChangeListener() override;
26+
27+
public:
28+
typedef void (*ChangedProc) (SkManagedIDChangeListener* d, void* context);
29+
typedef void (*DestroyProc) (SkManagedIDChangeListener* d, void* context);
30+
31+
struct Procs {
32+
ChangedProc fChanged = nullptr;
33+
DestroyProc fDestroy = nullptr;
34+
};
35+
36+
static void setProcs(Procs procs);
37+
38+
protected:
39+
void changed() override;
40+
41+
private:
42+
void* fContext;
43+
static Procs fProcs;
44+
45+
typedef SkIDChangeListener INHERITED;
46+
};
47+
48+
49+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2022 Microsoft Corporation. All rights reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#ifndef SkManagedIDChangeListenerList_h
9+
#define SkManagedIDChangeListenerList_h
10+
11+
#include "include/private/SkIDChangeListener.h"
12+
#include "include/core/SkTypes.h"
13+
14+
class SK_API SkManagedIDChangeListenerList;
15+
16+
// delegate declarations
17+
18+
// managed Allocator
19+
class SkManagedIDChangeListenerList : public SkIDChangeListener::List {
20+
public:
21+
SkManagedIDChangeListenerList(void* context);
22+
23+
~SkManagedIDChangeListenerList();
24+
25+
typedef void (*DestroyProc)(SkManagedIDChangeListenerList* d, void* context);
26+
27+
struct Procs {
28+
DestroyProc fDestroy = nullptr;
29+
};
30+
31+
static void setProcs(Procs procs);
32+
33+
private:
34+
void* fContext;
35+
static Procs fProcs;
36+
37+
typedef SkIDChangeListener::List INHERITED;
38+
};
39+
40+
41+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2014 Google Inc.
3+
* Copyright 2015 Xamarin Inc.
4+
* Copyright 2017 Microsoft Corporation. All rights reserved.
5+
*
6+
* Use of this source code is governed by a BSD-style license that can be
7+
* found in the LICENSE file.
8+
*/
9+
10+
#ifndef sk_managedidchangelistener_DEFINED
11+
#define sk_managedidchangelistener_DEFINED
12+
13+
#include "sk_xamarin.h"
14+
15+
#include "include/c/sk_types.h"
16+
17+
SK_C_PLUS_PLUS_BEGIN_GUARD
18+
19+
typedef void (*sk_idchangelistener_changed_proc)(sk_idchangelistener_t* d, void* context);
20+
typedef void (*sk_idchangelistener_destroy_proc)(sk_idchangelistener_t* d, void* context);
21+
22+
typedef struct {
23+
sk_idchangelistener_changed_proc fChanged;
24+
sk_idchangelistener_destroy_proc fDestroy;
25+
} sk_idchangelistener_procs_t;
26+
27+
SK_X_API sk_idchangelistener_t* sk_managedidchangelistener_new(void* context);
28+
SK_X_API void sk_managedidchangelistener_delete(sk_idchangelistener_t*);
29+
SK_X_API void sk_managedidchangelistener_mark_should_deregister(sk_idchangelistener_t*);
30+
SK_X_API bool sk_managedidchangelistener_should_deregister(sk_idchangelistener_t*);
31+
SK_X_API void sk_managedidchangelistener_set_procs(sk_idchangelistener_procs_t procs);
32+
33+
SK_C_PLUS_PLUS_END_GUARD
34+
35+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2014 Google Inc.
3+
* Copyright 2015 Xamarin Inc.
4+
* Copyright 2017 Microsoft Corporation. All rights reserved.
5+
*
6+
* Use of this source code is governed by a BSD-style license that can be
7+
* found in the LICENSE file.
8+
*/
9+
10+
#ifndef sk_managedidchangelistenerlist_DEFINED
11+
#define sk_managedidchangelistenerlist_DEFINED
12+
13+
#include "sk_xamarin.h"
14+
15+
#include "include/c/sk_types.h"
16+
17+
SK_C_PLUS_PLUS_BEGIN_GUARD
18+
19+
typedef void (*sk_idchangelistenerlist_destroy_proc)(sk_idchangelistenerlist_t* d, void* context);
20+
21+
typedef struct {
22+
sk_idchangelistenerlist_destroy_proc fDestroy;
23+
} sk_idchangelistenerlist_procs_t;
24+
25+
SK_X_API sk_idchangelistenerlist_t* sk_managedidchangelistenerlist_new(void* context);
26+
SK_X_API void sk_managedidchangelistenerlist_delete(sk_idchangelistenerlist_t*);
27+
SK_X_API void sk_managedidchangelistenerlist_add(sk_idchangelistenerlist_t*, sk_idchangelistener_t*, bool single_threaded);
28+
SK_X_API int32_t sk_managedidchangelistenerlist_count(sk_idchangelistenerlist_t*);
29+
SK_X_API void sk_managedidchangelistenerlist_changed(sk_idchangelistenerlist_t*, bool single_threaded);
30+
SK_X_API void sk_managedidchangelistenerlist_reset(sk_idchangelistenerlist_t*, bool single_threaded);
31+
SK_X_API void sk_managedidchangelistenerlist_set_procs(sk_idchangelistenerlist_procs_t procs);
32+
33+
SK_C_PLUS_PLUS_END_GUARD
34+
35+
#endif

include/xamarin/sk_managedpixelref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ SK_X_API uint32_t sk_managedpixelref_generation_id(sk_pixelref_t*);
3535
SK_X_API void sk_managedpixelref_notify_pixels_changed(sk_pixelref_t*);
3636
SK_X_API bool sk_managedpixelref_is_immutable(sk_pixelref_t*);
3737
SK_X_API void sk_managedpixelref_set_immutable(sk_pixelref_t*);
38-
//SK_X_API void sk_managedpixelref_add_generation_id_listener(sk_pixelref_t*, sk_id_change_listener_t*);
38+
SK_X_API void sk_managedpixelref_add_generation_id_listener(sk_pixelref_t*, sk_idchangelistener_t*);
3939
SK_X_API void sk_managedpixelref_notify_added_to_cache(sk_pixelref_t*);
4040
SK_X_API void sk_managedpixelref_set_procs(sk_pixelref_procs_t procs);
4141

src/c/sk_id_change_listener.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2014 Google Inc.
3+
* Copyright 2015 Xamarin Inc.
4+
* Copyright 2017 Microsoft Corporation. All rights reserved.
5+
*
6+
* Use of this source code is governed by a BSD-style license that can be
7+
* found in the LICENSE file.
8+
*/
9+
10+
#ifndef sk_idchangelistener_DEFINED
11+
#define sk_idchangelistener_DEFINED
12+
13+
#include "include/c/sk_idchangelistener.h"
14+
#include "src/c/sk_types_priv.h"
15+
16+
static inline SkIDChangeListener* AsSkIDChangeListener(sk_idchangelistener_t* d) {
17+
return reinterpret_cast<SkIDChangeListener*>(d);
18+
}
19+
20+
static sk_idchangelistener_procs_t gProcs;
21+
22+
void changed(SkIDChangeListener* d, void* context) {
23+
if (gProcs.fChanged) {
24+
gProcs.fChanged(ToSkIDChangeListener(d), context);
25+
}
26+
}
27+
28+
sk_idchangelistener_t* sk_idchangelistener_new(void* context) {
29+
return ToSKIDChangeListener(new SkIDChangeListener(context));
30+
}
31+
32+
void sk_idchangelistener_delete(sk_idchangelistener_t* d) { delete AsManagedAllocator(d); }
33+
34+
void sk_idchangelistener_set_procs(sk_idchangelistener_procs_t procs) {
35+
gProcs = procs;
36+
37+
SkManagedAllocator::Procs p;
38+
p.fAllocPixelRef = allocPixelRef;
39+
40+
SkManagedAllocator::setProcs(p);
41+
}
42+
43+
#endif

src/c/sk_types_priv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ DEF_MAP(SkBitmap::Allocator, sk_bitmapallocator_t, BitmapAllocator)
182182
#include "include/effects/SkRuntimeEffect.h"
183183
DEF_MAP(SkRuntimeEffect::Uniform, sk_runtimeeffect_uniform_t, RuntimeEffectUniform)
184184

185+
186+
#include "include/private/SkIDChangeListener.h"
187+
DEF_CLASS_MAP(SkIDChangeListener, sk_idchangelistener_t, SKIDChangeListener)
188+
DEF_MAP(SkIDChangeListener::List, sk_idchangelistenerlist_t, SKIDChangeListenerList)
189+
185190
#include "include/core/SkCanvas.h"
186191
DEF_MAP(SkCanvas::Lattice, sk_lattice_t, Lattice)
187192

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2022 Microsoft Corporation. All rights reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include "include/xamarin/SkManagedIDChangeListener.h"
9+
10+
SkManagedIDChangeListener::Procs SkManagedIDChangeListener::fProcs;
11+
12+
void SkManagedIDChangeListener::setProcs(SkManagedIDChangeListener::Procs procs) {
13+
fProcs = procs;
14+
}
15+
16+
SkManagedIDChangeListener::SkManagedIDChangeListener(void* context) {
17+
fContext = context;
18+
}
19+
20+
SkManagedIDChangeListener::~SkManagedIDChangeListener() {
21+
if (fProcs.fDestroy) {
22+
fProcs.fDestroy(this, fContext);
23+
}
24+
}
25+
26+
void SkManagedIDChangeListener::changed() {
27+
if (fProcs.fChanged) {
28+
fProcs.fChanged(this, fContext);
29+
}
30+
}

0 commit comments

Comments
 (0)