Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly convert between SkM44 and sk_matrix44_t #120

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions include/c/sk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ typedef struct {

// row major
typedef struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
// name: m<row><col>
float m00, m01, m02, m03; // row 0
float m10, m11, m12, m13; // row 1
float m20, m21, m22, m23; // row 2
float m30, m31, m32, m33; // row 3
} sk_matrix44_t;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/c/sk_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void sk_canvas_reset_matrix(sk_canvas_t* ccanvas) {
}

void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix) {
AsCanvas(ccanvas)->setMatrix(AsM44(cmatrix));
AsCanvas(ccanvas)->setMatrix(*AsM44(cmatrix));
}

void sk_canvas_get_matrix(sk_canvas_t* ccanvas, sk_matrix44_t* cmatrix) {
Expand Down Expand Up @@ -138,7 +138,7 @@ void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) {
}

void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix44_t* cmatrix) {
AsCanvas(ccanvas)->concat(AsM44(cmatrix));
AsCanvas(ccanvas)->concat(*AsM44(cmatrix));
}

bool sk_canvas_quick_reject(sk_canvas_t* ccanvas, const sk_rect_t* crect) {
Expand Down
1 change: 1 addition & 0 deletions src/c/sk_structs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static_assert (sizeof (sk_cubic_resampler_t) == sizeof (SkCubicResampler), ASSER
static_assert (sizeof (sk_sampling_options_t) == sizeof (SkSamplingOptions), ASSERT_MSG(SkSamplingOptions, sk_sampling_options_t));
static_assert (sizeof (sk_runtimeeffect_uniform_t) == sizeof (SkRuntimeEffect::Uniform), ASSERT_MSG(SkRuntimeEffect::Uniform, sk_runtimeeffect_uniform_t));
static_assert (sizeof (sk_runtimeeffect_child_t) == sizeof (SkRuntimeEffect::Child), ASSERT_MSG(SkRuntimeEffect::Child, sk_runtimeeffect_child_t));
static_assert (sizeof (sk_matrix44_t) == sizeof (SkM44), ASSERT_MSG(SkM44, sk_matrix44_t));

static_assert (sizeof (skottie_animation_builder_stats_t) == sizeof (skottie::Animation::Builder::Stats), ASSERT_MSG(skottie::Animation::Builder::Stats, skottie_animation_builder_stats_t));

Expand Down
58 changes: 1 addition & 57 deletions src/c/sk_types_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ DEF_CLASS_MAP(SkTraceMemoryDump, sk_tracememorydump_t, TraceMemoryDump)
DEF_CLASS_MAP(SkTypeface, sk_typeface_t, Typeface)
DEF_CLASS_MAP(SkVertices, sk_vertices_t, Vertices)
DEF_CLASS_MAP(SkWStream, sk_wstream_t, WStream)
DEF_CLASS_MAP(SkM44, sk_matrix44_t, M44)

DEF_CLASS_MAP(GrDirectContext, gr_direct_context_t, GrDirectContext)
DEF_CLASS_MAP(GrRecordingContext, gr_recording_context_t, GrRecordingContext)
Expand Down Expand Up @@ -245,63 +246,6 @@ static inline sk_matrix_t ToMatrix(const SkMatrix& matrix) {
return m;
}

#include "include/core/SkM44.h"
static inline SkM44 AsM44(const sk_matrix44_t* matrix) {
return SkM44(
matrix->m00, matrix->m01, matrix->m02, matrix->m03,
matrix->m10, matrix->m11, matrix->m12, matrix->m13,
matrix->m20, matrix->m21, matrix->m22, matrix->m23,
matrix->m30, matrix->m31, matrix->m32, matrix->m33);
}
static inline sk_matrix44_t ToM44(const SkM44* matrix) {
sk_matrix44_t m;
// row 0
m.m00 = matrix->rc(0, 0);
m.m01 = matrix->rc(0, 1);
m.m02 = matrix->rc(0, 2);
m.m03 = matrix->rc(0, 3);
// row 1
m.m10 = matrix->rc(1, 0);
m.m11 = matrix->rc(1, 1);
m.m12 = matrix->rc(1, 2);
m.m13 = matrix->rc(1, 3);
// row 2
m.m20 = matrix->rc(2, 0);
m.m21 = matrix->rc(2, 1);
m.m22 = matrix->rc(2, 2);
m.m23 = matrix->rc(2, 3);
// row 3
m.m30 = matrix->rc(3, 0);
m.m31 = matrix->rc(3, 1);
m.m32 = matrix->rc(3, 2);
m.m33 = matrix->rc(3, 3);
return m;
}
static inline sk_matrix44_t ToM44(const SkM44& matrix) {
sk_matrix44_t m;
// row 0
m.m00 = matrix.rc(0, 0);
m.m01 = matrix.rc(0, 1);
m.m02 = matrix.rc(0, 2);
m.m03 = matrix.rc(0, 3);
// row 1
m.m10 = matrix.rc(1, 0);
m.m11 = matrix.rc(1, 1);
m.m12 = matrix.rc(1, 2);
m.m13 = matrix.rc(1, 3);
// row 2
m.m20 = matrix.rc(2, 0);
m.m21 = matrix.rc(2, 1);
m.m22 = matrix.rc(2, 2);
m.m23 = matrix.rc(2, 3);
// row 3
m.m30 = matrix.rc(3, 0);
m.m31 = matrix.rc(3, 1);
m.m32 = matrix.rc(3, 2);
m.m33 = matrix.rc(3, 3);
return m;
}

#include "include/core/SkImageInfo.h"
static inline SkImageInfo AsImageInfo(const sk_imageinfo_t* info) {
return SkImageInfo::Make(
Expand Down
Loading