Skip to content

Commit

Permalink
Added sk_drawable
Browse files Browse the repository at this point in the history
  • Loading branch information
charlenni committed Dec 20, 2018
1 parent 949376a commit a6212f1
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 34 deletions.
2 changes: 2 additions & 0 deletions gn/core.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ skia_core_sources = [
"$_include/c/sk_colortable.h",
"$_include/c/sk_data.h",
"$_include/c/sk_document.h",
"$_include/c/sk_drawable.h",
"$_include/c/sk_image.h",
"$_include/c/sk_imagefilter.h",
"$_include/c/sk_mask.h",
Expand Down Expand Up @@ -46,6 +47,7 @@ skia_core_sources = [
"$_src/c/sk_colortable.cpp",
"$_src/c/sk_data.cpp",
"$_src/c/sk_document.cpp",
"$_src/c/sk_drawable.cpp",
"$_src/c/sk_enums.cpp",
"$_src/c/sk_image.cpp",
"$_src/c/sk_imagefilter.cpp",
Expand Down
27 changes: 27 additions & 0 deletions include/c/sk_drawable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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_drawable_DEFINED
#define sk_drawable_DEFINED

#include "sk_types.h"

SK_C_PLUS_PLUS_BEGIN_GUARD

typedef struct sk_drawable_t sk_drawable_t;

SK_C_API void sk_drawable_unref (sk_drawable_t*);
SK_C_API uint32_t sk_drawable_get_generation_id (sk_drawable_t*);
SK_C_API void sk_drawable_get_bounds (sk_drawable_t*, sk_rect_t*);
SK_C_API void sk_drawable_draw (sk_drawable_t*, sk_canvas_t*, const sk_matrix_t*);
SK_C_API sk_picture_t* sk_drawable_new_picture_snapshot(sk_drawable_t*);
SK_C_API void sk_drawable_notify_drawing_changed (sk_drawable_t*);

SK_C_PLUS_PLUS_END_GUARD

#endif
1 change: 1 addition & 0 deletions include/c/sk_picture.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SK_C_API sk_picture_recorder_t* sk_picture_recorder_new(void);
SK_C_API void sk_picture_recorder_delete(sk_picture_recorder_t*);
SK_C_API sk_canvas_t* sk_picture_recorder_begin_recording(sk_picture_recorder_t*, const sk_rect_t*);
SK_C_API sk_picture_t* sk_picture_recorder_end_recording(sk_picture_recorder_t*);
SK_C_API sk_drawable_t* sk_picture_recorder_end_recording_as_drawable(sk_picture_recorder_t*);
SK_C_API sk_canvas_t* sk_picture_get_recording_canvas(sk_picture_recorder_t* crec);

SK_C_API void sk_picture_ref(sk_picture_t*);
Expand Down
5 changes: 0 additions & 5 deletions include/xamarin/sk_manageddrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ SK_X_API void sk_manageddrawable_destroy (sk_manageddrawable_t*);
SK_X_API void sk_manageddrawable_set_delegates (const sk_manageddrawable_draw_delegate pDraw,
const sk_manageddrawable_getBounds_delegate pGetBounds,
const sk_manageddrawable_newPictureSnapshot_delegate pNewPictureSnapshot);
SK_X_API uint32_t sk_manageddrawable_get_generation_id (sk_manageddrawable_t*);
SK_X_API void sk_manageddrawable_get_bounds (sk_manageddrawable_t*, sk_rect_t*);
SK_X_API void sk_manageddrawable_draw (sk_manageddrawable_t*, sk_canvas_t*, const sk_matrix_t*);
SK_X_API sk_picture_t* sk_manageddrawable_new_picture_snapshot(sk_manageddrawable_t*);
SK_X_API void sk_manageddrawable_notify_drawing_changed (sk_manageddrawable_t*);

SK_C_PLUS_PLUS_END_GUARD

Expand Down
44 changes: 44 additions & 0 deletions src/c/sk_drawable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.
*/

#include "SkDrawable.h"

#include "sk_drawable.h"
#include "sk_picture.h"
#include "sk_types_priv.h"


void sk_drawable_unref(sk_drawable_t* drawable)
{
SkSafeUnref(AsDrawable(drawable));
}

uint32_t sk_drawable_get_generation_id(sk_drawable_t* d)
{
return AsDrawable(d)->getGenerationID();
}

void sk_drawable_get_bounds(sk_drawable_t* d, sk_rect_t* rect)
{
*rect = ToRect(AsDrawable(d)->getBounds());
}

void sk_drawable_draw(sk_drawable_t* d, sk_canvas_t* c, const sk_matrix_t* matrix)
{
AsDrawable(d)->draw(AsCanvas(c), &AsMatrix(matrix));
}

sk_picture_t* sk_drawable_new_picture_snapshot(sk_drawable_t* d)
{
return ToPicture(AsDrawable(d)->newPictureSnapshot());
}

void sk_drawable_notify_drawing_changed(sk_drawable_t* d)
{
AsDrawable(d)->notifyDrawingChanged();
}
5 changes: 5 additions & 0 deletions src/c/sk_picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "SkPicture.h"
#include "SkPictureRecorder.h"
#include "SkDrawable.h"

#include "sk_picture.h"

Expand All @@ -30,6 +31,10 @@ sk_picture_t* sk_picture_recorder_end_recording(sk_picture_recorder_t* crec) {
return ToPicture(AsPictureRecorder(crec)->finishRecordingAsPicture().release());
}

sk_drawable_t* sk_picture_recorder_end_recording_as_drawable(sk_picture_recorder_t* crec) {
return ToDrawable(AsPictureRecorder(crec)->finishRecordingAsDrawable().release());
}

sk_canvas_t* sk_picture_get_recording_canvas(sk_picture_recorder_t* crec) {
return ToCanvas(AsPictureRecorder(crec)->getRecordingCanvas());
}
Expand Down
2 changes: 2 additions & 0 deletions src/xamarin/SkiaKeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sk_colortable.h"
#include "sk_data.h"
#include "sk_document.h"
#include "sk_drawable.h"
#include "sk_image.h"
#include "sk_imagefilter.h"
#include "sk_mask.h"
Expand Down Expand Up @@ -60,6 +61,7 @@ void** KeepSkiaCSymbols (void)
(void*)sk_colortable_unref,
(void*)sk_data_new_empty,
(void*)sk_document_unref,
(void*)sk_drawable_unref,
(void*)sk_image_ref,
(void*)sk_imagefilter_croprect_new,
(void*)sk_mask_alloc_image,
Expand Down
32 changes: 3 additions & 29 deletions src/xamarin/sk_manageddrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "sk_picture.h"
#include "sk_types_priv.h"

/* This is a C wrapper araound the C++ class, so that it is possible
/* This is a C wrapper around the C++ class, so that it is possible
to access the C++ from C#. */

static sk_manageddrawable_draw_delegate gDraw;
Expand All @@ -34,7 +34,7 @@ static inline const sk_manageddrawable_t* ToManagedDrawable(const SkManagedDrawa
return reinterpret_cast<const sk_manageddrawable_t*>(drawable);
}

void dDraw(SkManagedDrawable* managedDrawable, SkCanvas* canvas)
void dDraw(SkManagedDrawable* managedDrawable, SkCanvas* canvas)
{
gDraw(ToManagedDrawable(managedDrawable), ToCanvas(canvas));
}
Expand All @@ -49,8 +49,7 @@ SkPicture* dNewPictureSnapshot(SkManagedDrawable* managedDrawable)
return AsPicture(gNewPictureSnapshot(ToManagedDrawable(managedDrawable)));
}

sk_manageddrawable_t* sk_manageddrawable_new()
{
sk_manageddrawable_t* sk_manageddrawable_new() {
return ToManagedDrawable(new SkManagedDrawable());
}

Expand All @@ -69,28 +68,3 @@ void sk_manageddrawable_set_delegates(const sk_manageddrawable_draw_delegate pDr

SkManagedDrawable::setDelegates(dDraw, dGetBounds, dNewPictureSnapshot);
}

uint32_t sk_manageddrawable_get_generation_id(sk_manageddrawable_t* d)
{
return AsManagedDrawable(d)->getGenerationID();
}

void sk_manageddrawable_get_bounds(sk_manageddrawable_t* d, sk_rect_t* rect)
{
*rect = ToRect(AsManagedDrawable(d)->getBounds());
}

void sk_manageddrawable_draw(sk_manageddrawable_t* d, sk_canvas_t* c, const sk_matrix_t* matrix)
{
AsManagedDrawable(d)->draw(AsCanvas(c), &AsMatrix(matrix));
}

sk_picture_t* sk_manageddrawable_new_picture_snapshot(sk_manageddrawable_t* d)
{
return ToPicture(AsManagedDrawable(d)->newPictureSnapshot());
}

void sk_manageddrawable_notify_drawing_changed(sk_manageddrawable_t* d)
{
AsManagedDrawable(d)->notifyDrawingChanged();
}

0 comments on commit a6212f1

Please sign in to comment.