Skip to content

Commit

Permalink
remerge
Browse files Browse the repository at this point in the history
  • Loading branch information
mgood7123 committed Jul 9, 2022
1 parent 9a7aedc commit 7bd6544
Show file tree
Hide file tree
Showing 15 changed files with 405 additions and 7 deletions.
4 changes: 4 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions include/c/sk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions include/xamarin/SkManagedIDChangeListener.h
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions include/xamarin/SkManagedIDChangeListenerList.h
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions include/xamarin/sk_managedidchangelistener.h
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions include/xamarin/sk_managedidchangelistenerlist.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion include/xamarin/sk_managedpixelref.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
43 changes: 43 additions & 0 deletions src/c/sk_id_change_listener.cpp
Original file line number Diff line number Diff line change
@@ -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<SkIDChangeListener*>(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
5 changes: 5 additions & 0 deletions src/c/sk_types_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
30 changes: 30 additions & 0 deletions src/xamarin/SkManagedIDChangeListener.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
24 changes: 24 additions & 0 deletions src/xamarin/SkManagedIDChangeListenerList.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions src/xamarin/SkiaKeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
59 changes: 59 additions & 0 deletions src/xamarin/sk_managedidchangelistener.cpp
Original file line number Diff line number Diff line change
@@ -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<SkManagedIDChangeListener*>(d);
}
static inline sk_idchangelistener_t* ToSkManagedIDChangeListener(SkManagedIDChangeListener* d) {
return reinterpret_cast<sk_idchangelistener_t*>(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);
}
Loading

0 comments on commit 7bd6544

Please sign in to comment.