[canvaskit] Introduce self-documenting pointer types

Change-Id: I72dfe6098dae699d85cf87b6432e27cf845c832d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/412659
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Kevin Lubick 2021-05-26 13:40:22 -04:00
parent e9f1989c38
commit 95d599c0a0
6 changed files with 165 additions and 175 deletions

View File

@ -12,6 +12,7 @@
#include <emscripten/bind.h>
#include "include/core/SkColor.h"
#include "include/core/SkSpan.h"
#include "include/private/SkMalloc.h"
using namespace emscripten;
@ -26,6 +27,18 @@ using Uint16Array = emscripten::val;
using Uint32Array = emscripten::val;
using Float32Array = emscripten::val;
// If we are using C++ and EMSCRIPTEN_BINDINGS, we can't have primitive pointers in our function
// type signatures. (this gives an error message like "Cannot call foo due to unbound
// types Pi, Pf"). But, we can just pretend they are numbers and cast them to be pointers and
// the compiler is happy.
// These types refer to the TypedArray that the JS interface wrote into or will read out of.
// This doesn't stop us from using these as different types; e.g. a float* can be treated as an
// SkPoint* in some APIs.
using WASMPointerF32 = uintptr_t;
using WASMPointerU8 = uintptr_t;
using WASMPointerU16 = uintptr_t;
using WASMPointerU32 = uintptr_t;
#define SPECIALIZE_JSARRAYTYPE(type, name) \
template <> struct JSArrayType<type> { \
static constexpr const char* const gName = name; \

View File

@ -85,7 +85,7 @@ sk_sp<SkFontMgr> SkFontMgr_New_Custom_Data(sk_sp<SkData>* datas, int n);
#endif
struct OptionalMatrix : SkMatrix {
OptionalMatrix(uintptr_t mPtr) {
OptionalMatrix(WASMPointerF32 mPtr) {
if (mPtr) {
const SkScalar* nineMatrixValues = reinterpret_cast<const SkScalar*>(mPtr);
this->set9(nineMatrixValues);
@ -93,14 +93,14 @@ struct OptionalMatrix : SkMatrix {
}
};
SkColor4f ptrToSkColor4f(uintptr_t /* float* */ cPtr) {
SkColor4f ptrToSkColor4f(WASMPointerF32 cPtr) {
float* fourFloats = reinterpret_cast<float*>(cPtr);
SkColor4f color;
memcpy(&color, fourFloats, 4 * sizeof(float));
return color;
}
SkRRect ptrToSkRRect(uintptr_t /* float* */ fPtr) {
SkRRect ptrToSkRRect(WASMPointerF32 fPtr) {
// In order, these floats should be 4 floats for the rectangle
// (left, top, right, bottom) and then 8 floats for the radii
// (upper left, upper right, lower right, lower left).
@ -399,17 +399,7 @@ JSArray ToCmds(const SkPath& path) {
return cmds;
}
// This type signature is a mess, but it's necessary. See, we can't use "bind" (EMSCRIPTEN_BINDINGS)
// and pointers to primitive types (Only bound types like SkPoint). We could if we used
// cwrap (see https://becominghuman.ai/passing-and-returning-webassembly-array-parameters-a0f572c65d97)
// but that requires us to stick to C code and, AFAIK, doesn't allow us to return nice things like
// SkPath or SkOpBuilder.
//
// So, basically, if we are using C++ and EMSCRIPTEN_BINDINGS, we can't have primitive pointers
// in our function type signatures. (this gives an error message like "Cannot call foo due to unbound
// types Pi, Pf"). But, we can just pretend they are numbers and cast them to be pointers and
// the compiler is happy.
SkPathOrNull MakePathFromCmds(uintptr_t /* float* */ cptr, int numCmds) {
SkPathOrNull MakePathFromCmds(WASMPointerF32 cptr, int numCmds) {
const auto* cmds = reinterpret_cast<const float*>(cptr);
SkPath path;
float x1, y1, x2, y2, x3, y3;
@ -467,9 +457,9 @@ SkPathOrNull MakePathFromCmds(uintptr_t /* float* */ cptr, int numCmds) {
return emscripten::val(path);
}
void PathAddVerbsPointsWeights(SkPath& path, uintptr_t /* uint8_t* */ verbsPtr, int numVerbs,
uintptr_t /* float* */ ptsPtr, int numPts,
uintptr_t /* float* */ wtsPtr, int numWts) {
void PathAddVerbsPointsWeights(SkPath& path, WASMPointerU8 verbsPtr, int numVerbs,
WASMPointerF32 ptsPtr, int numPts,
WASMPointerF32 wtsPtr, int numWts) {
const uint8_t* verbs = reinterpret_cast<const uint8_t*>(verbsPtr);
const float* pts = reinterpret_cast<const float*>(ptsPtr);
const float* weights = reinterpret_cast<const float*>(wtsPtr);
@ -529,9 +519,9 @@ void PathAddVerbsPointsWeights(SkPath& path, uintptr_t /* uint8_t* */ verbsPtr,
#undef CHECK_NUM_WEIGHTS
}
SkPath MakePathFromVerbsPointsWeights(uintptr_t /* uint8_t* */ verbsPtr, int numVerbs,
uintptr_t ptsPtr, int numPts,
uintptr_t wtsPtr, int numWts) {
SkPath MakePathFromVerbsPointsWeights(WASMPointerU8 verbsPtr, int numVerbs,
WASMPointerF32 ptsPtr, int numPts,
WASMPointerF32 wtsPtr, int numWts) {
SkPath path;
PathAddVerbsPointsWeights(path, verbsPtr, numVerbs, ptsPtr, numPts, wtsPtr, numWts);
return path;
@ -594,7 +584,7 @@ bool ApplyStroke(SkPath& path, StrokeOpts opts) {
}
// This function is private, we call it in interface.js
void computeTonalColors(uintptr_t cPtrAmbi /* float * */, uintptr_t cPtrSpot /* float * */) {
void computeTonalColors(WASMPointerF32 cPtrAmbi, WASMPointerF32 cPtrSpot) {
// private methods accepting colors take pointers to floats already copied into wasm memory.
float* ambiFloats = reinterpret_cast<float*>(cPtrAmbi);
float* spotFloats = reinterpret_cast<float*>(cPtrSpot);
@ -705,17 +695,6 @@ Uint8Array toBytes(sk_sp<SkData> data) {
).call<Uint8Array>("slice"); // slice with no args makes a copy of the memory view.
}
// Some signatures below have uintptr_t instead of a pointer to a primitive
// type (e.g. SkScalar). This is necessary because we can't use "bind" (EMSCRIPTEN_BINDINGS)
// and pointers to primitive types (Only bound types like SkPoint). We could if we used
// cwrap (see https://becominghuman.ai/passing-and-returning-webassembly-array-parameters-a0f572c65d97)
// but that requires us to stick to C code and, AFAIK, doesn't allow us to return nice things like
// SkPath or SkCanvas.
//
// So, basically, if we are using C++ and EMSCRIPTEN_BINDINGS, we can't have primitive pointers
// in our function type signatures. (this gives an error message like "Cannot call foo due to unbound
// types Pi, Pf"). But, we can just pretend they are numbers and cast them to be pointers and
// the compiler is happy.
EMSCRIPTEN_BINDINGS(Skia) {
#ifdef SK_GL
function("currentContext", &emscripten_webgl_get_current_context);
@ -732,7 +711,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
function("getDecodeCacheUsedBytes" , &SkResourceCache::GetTotalBytesUsed);
function("_computeTonalColors", &computeTonalColors);
function("_decodeAnimatedImage", optional_override([](uintptr_t /* uint8_t* */ iptr,
function("_decodeAnimatedImage", optional_override([](WASMPointerU8 iptr,
size_t length)->sk_sp<SkAnimatedImage> {
uint8_t* imgData = reinterpret_cast<uint8_t*>(iptr);
auto bytes = SkData::MakeFromMalloc(imgData, length);
@ -743,7 +722,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
return SkAnimatedImage::Make(std::move(aCodec));
}), allow_raw_pointers());
function("_decodeImage", optional_override([](uintptr_t /* uint8_t* */ iptr,
function("_decodeImage", optional_override([](WASMPointerU8 iptr,
size_t length)->sk_sp<SkImage> {
uint8_t* imgData = reinterpret_cast<uint8_t*>(iptr);
sk_sp<SkData> bytes = SkData::MakeFromMalloc(imgData, length);
@ -752,7 +731,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
// These won't be called directly, there are corresponding JS helpers to deal with arrays.
function("_MakeImage", optional_override([](SimpleImageInfo ii,
uintptr_t /* uint8_t* */ pPtr, int plen,
WASMPointerU8 pPtr, int plen,
size_t rowBytes)->sk_sp<SkImage> {
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
SkImageInfo info = toSkImageInfo(ii);
@ -762,9 +741,9 @@ EMSCRIPTEN_BINDINGS(Skia) {
}), allow_raw_pointers());
function("_getShadowLocalBounds", optional_override([](
uintptr_t /* float* */ ctmPtr, const SkPath& path,
uintptr_t /* float* */ zPlaneParamPtr, uintptr_t /* float* */ lightPosPtr,
SkScalar lightRadius, uint32_t flags, uintptr_t /* SkRect* */ outPtr) -> bool {
WASMPointerF32 ctmPtr, const SkPath& path,
WASMPointerF32 zPlaneParamPtr, WASMPointerF32 lightPosPtr,
SkScalar lightRadius, uint32_t flags, WASMPointerF32 outPtr) -> bool {
SkMatrix ctm;
const SkScalar* nineMatrixValues = reinterpret_cast<const SkScalar*>(ctmPtr);
ctm.set9(nineMatrixValues);
@ -776,8 +755,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
}));
#ifdef SK_SERIALIZE_SKP
function("_MakePicture", optional_override([](uintptr_t /* unint8_t* */ dPtr,
size_t bytes)->sk_sp<SkPicture> {
function("_MakePicture", optional_override([](WASMPointerU8 dPtr,
size_t bytes)->sk_sp<SkPicture> {
uint8_t* d = reinterpret_cast<uint8_t*>(dPtr);
sk_sp<SkData> data = SkData::MakeFromMalloc(d, bytes);
@ -830,32 +809,32 @@ EMSCRIPTEN_BINDINGS(Skia) {
class_<SkCanvas>("Canvas")
.constructor<>()
.function("_clear", optional_override([](SkCanvas& self, uintptr_t /* float* */ cPtr) {
.function("_clear", optional_override([](SkCanvas& self, WASMPointerF32 cPtr) {
self.clear(ptrToSkColor4f(cPtr));
}))
.function("clipPath", select_overload<void (const SkPath&, SkClipOp, bool)>(&SkCanvas::clipPath))
.function("_clipRRect", optional_override([](SkCanvas& self, uintptr_t /* float* */ fPtr, SkClipOp op, bool doAntiAlias) {
.function("_clipRRect", optional_override([](SkCanvas& self, WASMPointerF32 fPtr, SkClipOp op, bool doAntiAlias) {
self.clipRRect(ptrToSkRRect(fPtr), op, doAntiAlias);
}))
.function("_clipRect", optional_override([](SkCanvas& self, uintptr_t /* float* */ fPtr, SkClipOp op, bool doAntiAlias) {
.function("_clipRect", optional_override([](SkCanvas& self, WASMPointerF32 fPtr, SkClipOp op, bool doAntiAlias) {
const SkRect* rect = reinterpret_cast<const SkRect*>(fPtr);
self.clipRect(*rect, op, doAntiAlias);
}))
.function("_concat", optional_override([](SkCanvas& self, uintptr_t /* SkScalar* */ mPtr) {
.function("_concat", optional_override([](SkCanvas& self, WASMPointerF32 mPtr) {
//TODO(skbug.com/10108): make the JS side be column major.
const SkScalar* sixteenMatrixValues = reinterpret_cast<const SkScalar*>(mPtr);
SkM44 m = SkM44::RowMajor(sixteenMatrixValues);
self.concat(m);
}))
.function("_drawArc", optional_override([](SkCanvas& self, uintptr_t /* float* */ fPtr,
.function("_drawArc", optional_override([](SkCanvas& self, WASMPointerF32 fPtr,
SkScalar startAngle, SkScalar sweepAngle,
bool useCenter, const SkPaint& paint) {
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
self.drawArc(*oval, startAngle, sweepAngle, useCenter, paint);
}))
.function("_drawAtlasOptions", optional_override([](SkCanvas& self,
const sk_sp<SkImage>& atlas, uintptr_t /* SkRSXform* */ xptr,
uintptr_t /* SkRect* */ rptr, uintptr_t /* SkColor* */ cptr, int count,
const sk_sp<SkImage>& atlas, WASMPointerF32 xptr,
WASMPointerF32 rptr, WASMPointerU32 cptr, int count,
SkBlendMode mode, SkFilterMode filter, SkMipmapMode mipmap,
const SkPaint* paint)->void {
const SkRSXform* dstXforms = reinterpret_cast<const SkRSXform*>(xptr);
@ -869,8 +848,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
nullptr, paint);
}), allow_raw_pointers())
.function("_drawAtlasCubic", optional_override([](SkCanvas& self,
const sk_sp<SkImage>& atlas, uintptr_t /* SkRSXform* */ xptr,
uintptr_t /* SkRect* */ rptr, uintptr_t /* SkColor* */ cptr, int count,
const sk_sp<SkImage>& atlas, WASMPointerF32 xptr,
WASMPointerF32 rptr, WASMPointerU32 cptr, int count,
SkBlendMode mode, float B, float C, const SkPaint* paint)->void {
const SkRSXform* dstXforms = reinterpret_cast<const SkRSXform*>(xptr);
const SkRect* srcRects = reinterpret_cast<const SkRect*>(rptr);
@ -883,10 +862,10 @@ EMSCRIPTEN_BINDINGS(Skia) {
nullptr, paint);
}), allow_raw_pointers())
.function("drawCircle", select_overload<void (SkScalar, SkScalar, SkScalar, const SkPaint& paint)>(&SkCanvas::drawCircle))
.function("_drawColor", optional_override([](SkCanvas& self, uintptr_t /* float* */ cPtr) {
.function("_drawColor", optional_override([](SkCanvas& self, WASMPointerF32 cPtr) {
self.drawColor(ptrToSkColor4f(cPtr));
}))
.function("_drawColor", optional_override([](SkCanvas& self, uintptr_t /* float* */ cPtr, SkBlendMode mode) {
.function("_drawColor", optional_override([](SkCanvas& self, WASMPointerF32 cPtr, SkBlendMode mode) {
self.drawColor(ptrToSkColor4f(cPtr), mode);
}))
.function("drawColorInt", optional_override([](SkCanvas& self, SkColor color) {
@ -895,14 +874,14 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("drawColorInt", optional_override([](SkCanvas& self, SkColor color, SkBlendMode mode) {
self.drawColor(color, mode);
}))
.function("_drawDRRect", optional_override([](SkCanvas& self, uintptr_t /* float* */ outerPtr,
uintptr_t /* float* */ innerPtr, const SkPaint& paint) {
.function("_drawDRRect", optional_override([](SkCanvas& self, WASMPointerF32 outerPtr,
WASMPointerF32 innerPtr, const SkPaint& paint) {
self.drawDRRect(ptrToSkRRect(outerPtr), ptrToSkRRect(innerPtr), paint);
}))
.function("_drawGlyphs", optional_override([](SkCanvas& self,
int count,
uintptr_t /* uint16_t* */ glyphs,
uintptr_t /* SkPoint* */ positions,
WASMPointerU16 glyphs,
WASMPointerF32 positions,
float x, float y,
const SkFont& font,
const SkPaint& paint)->void {
@ -939,7 +918,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
}), allow_raw_pointers())
.function("_drawImageNine", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
uintptr_t /* int* */ centerPtr, uintptr_t /* float* */ dstPtr,
WASMPointerU32 centerPtr, WASMPointerF32 dstPtr,
SkFilterMode filter, const SkPaint* paint)->void {
const SkIRect* center = reinterpret_cast<const SkIRect*>(centerPtr);
const SkRect* dst = reinterpret_cast<const SkRect*>(dstPtr);
@ -948,7 +927,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
}), allow_raw_pointers())
// TODO: deprecate this version, and require sampling
.function("_drawImageRect", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
uintptr_t /* float* */ srcPtr, uintptr_t /* float* */ dstPtr,
WASMPointerF32 srcPtr, WASMPointerF32 dstPtr,
const SkPaint* paint, bool fastSample)->void {
const SkRect* src = reinterpret_cast<const SkRect*>(srcPtr);
const SkRect* dst = reinterpret_cast<const SkRect*>(dstPtr);
@ -959,7 +938,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
SkCanvas::kStrict_SrcRectConstraint);
}), allow_raw_pointers())
.function("_drawImageRectCubic", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
uintptr_t /* float* */ srcPtr, uintptr_t /* float* */ dstPtr,
WASMPointerF32 srcPtr, WASMPointerF32 dstPtr,
float B, float C, // See SkSamplingOptions.h for docs.
const SkPaint* paint)->void {
const SkRect* src = reinterpret_cast<const SkRect*>(srcPtr);
@ -968,7 +947,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
self.drawImageRect(image.get(), *src, *dst, SkSamplingOptions({B, C}), paint, constraint);
}), allow_raw_pointers())
.function("_drawImageRectOptions", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
uintptr_t /* float* */ srcPtr, uintptr_t /* float* */ dstPtr,
WASMPointerF32 srcPtr, WASMPointerF32 dstPtr,
SkFilterMode filter, SkMipmapMode mipmap,
const SkPaint* paint)->void {
const SkRect* src = reinterpret_cast<const SkRect*>(srcPtr);
@ -977,7 +956,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
self.drawImageRect(image.get(), *src, *dst, {filter, mipmap}, paint, constraint);
}), allow_raw_pointers())
.function("drawLine", select_overload<void (SkScalar, SkScalar, SkScalar, SkScalar, const SkPaint&)>(&SkCanvas::drawLine))
.function("_drawOval", optional_override([](SkCanvas& self, uintptr_t /* float* */ fPtr,
.function("_drawOval", optional_override([](SkCanvas& self, WASMPointerF32 fPtr,
const SkPaint& paint)->void {
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
self.drawOval(*oval, paint);
@ -991,9 +970,9 @@ EMSCRIPTEN_BINDINGS(Skia) {
#endif
.function("drawPath", &SkCanvas::drawPath)
.function("_drawPatch", optional_override([](SkCanvas& self,
uintptr_t /* SkPoint* */ cubics,
uintptr_t /* SkColor* */ colors,
uintptr_t /* SkPoint* */ texs,
WASMPointerF32 cubics,
WASMPointerU32 colors,
WASMPointerF32 texs,
SkBlendMode mode,
const SkPaint& paint)->void {
self.drawPatch(reinterpret_cast<const SkPoint*>(cubics),
@ -1005,15 +984,15 @@ EMSCRIPTEN_BINDINGS(Skia) {
// a bitmap. An SkPicture is a series of draw commands.
.function("drawPicture", select_overload<void (const sk_sp<SkPicture>&)>(&SkCanvas::drawPicture))
.function("_drawPoints", optional_override([](SkCanvas& self, SkCanvas::PointMode mode,
uintptr_t /* SkPoint* */ pptr,
WASMPointerF32 pptr,
int count, SkPaint& paint)->void {
const SkPoint* pts = reinterpret_cast<const SkPoint*>(pptr);
self.drawPoints(mode, count, pts, paint);
}))
.function("_drawRRect",optional_override([](SkCanvas& self, uintptr_t /* float* */ fPtr, const SkPaint& paint) {
.function("_drawRRect",optional_override([](SkCanvas& self, WASMPointerF32 fPtr, const SkPaint& paint) {
self.drawRRect(ptrToSkRRect(fPtr), paint);
}))
.function("_drawRect", optional_override([](SkCanvas& self, uintptr_t /* float* */ fPtr,
.function("_drawRect", optional_override([](SkCanvas& self, WASMPointerF32 fPtr,
const SkPaint& paint)->void {
const SkRect* rect = reinterpret_cast<const SkRect*>(fPtr);
self.drawRect(*rect, paint);
@ -1025,11 +1004,11 @@ EMSCRIPTEN_BINDINGS(Skia) {
self.drawRect(rect, paint);
}))
.function("_drawShadow", optional_override([](SkCanvas& self, const SkPath& path,
uintptr_t /* float* */ zPlaneParamPtr,
uintptr_t /* float* */ lightPosPtr,
WASMPointerF32 zPlaneParamPtr,
WASMPointerF32 lightPosPtr,
SkScalar lightRadius,
uintptr_t /* float* */ ambientColorPtr,
uintptr_t /* float* */ spotColorPtr,
WASMPointerF32 ambientColorPtr,
WASMPointerF32 spotColorPtr,
uint32_t flags) {
const SkVector3* zPlaneParams = reinterpret_cast<const SkVector3*>(zPlaneParamPtr);
const SkVector3* lightPos = reinterpret_cast<const SkVector3*>(lightPosPtr);
@ -1040,7 +1019,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
flags);
}))
#ifndef SK_NO_FONTS
.function("_drawSimpleText", optional_override([](SkCanvas& self, uintptr_t /* char* */ sptr,
.function("_drawSimpleText", optional_override([](SkCanvas& self, WASMPointerU8 sptr,
size_t len, SkScalar x, SkScalar y, const SkFont& font,
const SkPaint& paint) {
const char* str = reinterpret_cast<const char*>(sptr);
@ -1050,7 +1029,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("drawTextBlob", select_overload<void (const sk_sp<SkTextBlob>&, SkScalar, SkScalar, const SkPaint&)>(&SkCanvas::drawTextBlob))
#endif
.function("drawVertices", select_overload<void (const sk_sp<SkVertices>&, SkBlendMode, const SkPaint&)>(&SkCanvas::drawVertices))
.function("_findMarkedCTM", optional_override([](SkCanvas& self, std::string marker, uintptr_t /* SkScalar* */ mPtr) -> bool {
.function("_findMarkedCTM", optional_override([](SkCanvas& self, std::string marker, WASMPointerF32 mPtr) -> bool {
SkScalar* sixteenMatrixValues = reinterpret_cast<SkScalar*>(mPtr);
if (!sixteenMatrixValues) {
return false; // matrix cannot be null
@ -1065,7 +1044,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
// 4x4 matrix functions
// Just like with getTotalMatrix, we allocate the buffer for the 16 floats to go in from
// interface.js, so it can also free them when its done.
.function("_getLocalToDevice", optional_override([](const SkCanvas& self, uintptr_t /* SkScalar* */ mPtr) {
.function("_getLocalToDevice", optional_override([](const SkCanvas& self, WASMPointerF32 mPtr) {
SkScalar* sixteenMatrixValues = reinterpret_cast<SkScalar*>(mPtr);
if (!sixteenMatrixValues) {
return; // matrix cannot be null
@ -1077,7 +1056,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
// We allocate room for the matrix from the JS side and free it there so as to not have
// an awkward moment where we malloc something here and "just know" to free it on the
// JS side.
.function("_getTotalMatrix", optional_override([](const SkCanvas& self, uintptr_t /* uint8_t* */ mPtr) {
.function("_getTotalMatrix", optional_override([](const SkCanvas& self, WASMPointerU8 mPtr) {
SkScalar* nineMatrixValues = reinterpret_cast<SkScalar*>(mPtr);
if (!nineMatrixValues) {
return; // matrix cannot be null
@ -1093,7 +1072,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
}))
.function("_readPixels", optional_override([](SkCanvas& self, SimpleImageInfo di,
uintptr_t /* uint8_t* */ pPtr,
WASMPointerU8 pPtr,
size_t dstRowBytes, int srcX, int srcY) {
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
SkImageInfo dstInfo = toSkImageInfo(di);
@ -1104,7 +1083,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("restoreToCount", &SkCanvas::restoreToCount)
.function("rotate", select_overload<void (SkScalar, SkScalar, SkScalar)>(&SkCanvas::rotate))
.function("save", &SkCanvas::save)
.function("_saveLayer", optional_override([](SkCanvas& self, const SkPaint* p, uintptr_t /* float* */ fPtr,
.function("_saveLayer", optional_override([](SkCanvas& self, const SkPaint* p, WASMPointerF32 fPtr,
const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags flags)->int {
SkRect* bounds = reinterpret_cast<SkRect*>(fPtr);
return self.saveLayer(SkCanvas::SaveLayerRec(bounds, p, backdrop, flags));
@ -1116,7 +1095,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("skew", &SkCanvas::skew)
.function("translate", &SkCanvas::translate)
.function("_writePixels", optional_override([](SkCanvas& self, SimpleImageInfo di,
uintptr_t /* uint8_t* */ pPtr,
WASMPointerU8 pPtr,
size_t srcRowBytes, int dstX, int dstY) {
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
SkImageInfo dstInfo = toSkImageInfo(di);
@ -1126,13 +1105,13 @@ EMSCRIPTEN_BINDINGS(Skia) {
class_<SkColorFilter>("ColorFilter")
.smart_ptr<sk_sp<SkColorFilter>>("sk_sp<ColorFilter>>")
.class_function("_MakeBlend", optional_override([](uintptr_t /* float* */ cPtr, SkBlendMode mode)->sk_sp<SkColorFilter> {
.class_function("_MakeBlend", optional_override([](WASMPointerF32 cPtr, SkBlendMode mode)->sk_sp<SkColorFilter> {
return SkColorFilters::Blend(ptrToSkColor4f(cPtr).toSkColor(), mode);
}))
.class_function("MakeCompose", &SkColorFilters::Compose)
.class_function("MakeLerp", &SkColorFilters::Lerp)
.class_function("MakeLinearToSRGBGamma", &SkColorFilters::LinearToSRGBGamma)
.class_function("_makeMatrix", optional_override([](uintptr_t /* float* */ fPtr) {
.class_function("_makeMatrix", optional_override([](WASMPointerF32 fPtr) {
float* twentyFloats = reinterpret_cast<float*>(fPtr);
return SkColorFilters::Matrix(twentyFloats);
}))
@ -1146,7 +1125,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
.smart_ptr<sk_sp<SkContourMeasure>>("sk_sp<ContourMeasure>>")
.function("_getPosTan", optional_override([](SkContourMeasure& self,
SkScalar distance,
uintptr_t /* SkPoint* */ oPtr) -> void {
WASMPointerF32 oPtr) -> void {
SkPoint* pointAndVector = reinterpret_cast<SkPoint*>(oPtr);
if (!self.getPosTan(distance, pointAndVector, pointAndVector + 1)) {
SkDebugf("zero-length path in getPosTan\n");
@ -1170,9 +1149,9 @@ EMSCRIPTEN_BINDINGS(Skia) {
.constructor<sk_sp<SkTypeface>>()
.constructor<sk_sp<SkTypeface>, SkScalar>()
.constructor<sk_sp<SkTypeface>, SkScalar, SkScalar, SkScalar>()
.function("_getGlyphWidthBounds", optional_override([](SkFont& self, uintptr_t /* SkGlyphID* */ gPtr,
int numGlyphs, uintptr_t /* float* */ wPtr,
uintptr_t /* float* */ rPtr,
.function("_getGlyphWidthBounds", optional_override([](SkFont& self, WASMPointerU16 gPtr,
int numGlyphs, WASMPointerF32 wPtr,
WASMPointerF32 rPtr,
SkPaint* paint) {
const SkGlyphID* glyphs = reinterpret_cast<const SkGlyphID*>(gPtr);
// On the JS side only one of these is set at a time for easier ergonomics.
@ -1180,9 +1159,9 @@ EMSCRIPTEN_BINDINGS(Skia) {
SkScalar* outputWidths = reinterpret_cast<SkScalar*>(wPtr);
self.getWidthsBounds(glyphs, numGlyphs, outputWidths, outputRects, paint);
}), allow_raw_pointers())
.function("_getGlyphIDs", optional_override([](SkFont& self, uintptr_t /* char* */ sptr,
.function("_getGlyphIDs", optional_override([](SkFont& self, WASMPointerU8 sptr,
size_t strLen, size_t expectedCodePoints,
uintptr_t /* SkGlyphID* */ iPtr) -> int {
WASMPointerU16 iPtr) -> int {
char* str = reinterpret_cast<char*>(sptr);
SkGlyphID* glyphIDs = reinterpret_cast<SkGlyphID*>(iPtr);
@ -1237,8 +1216,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
class_<SkFontMgr>("FontMgr")
.smart_ptr<sk_sp<SkFontMgr>>("sk_sp<FontMgr>")
.class_function("_fromData", optional_override([](uintptr_t /* uint8_t** */ dPtr,
uintptr_t /* size_t* */ sPtr,
.class_function("_fromData", optional_override([](WASMPointerU32 dPtr,
WASMPointerU32 sPtr,
int numFonts)->sk_sp<SkFontMgr> {
auto datas = reinterpret_cast<const uint8_t**>(dPtr);
auto sizes = reinterpret_cast<const size_t*>(sPtr);
@ -1272,7 +1251,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
}))
#endif
.function("_makeTypefaceFromData", optional_override([](SkFontMgr& self,
uintptr_t /* uint8_t* */ fPtr,
WASMPointerU8 fPtr,
int flen)->sk_sp<SkTypeface> {
uint8_t* font = reinterpret_cast<uint8_t*>(fPtr);
sk_sp<SkData> fontData = SkData::MakeFromMalloc(font, flen);
@ -1319,17 +1298,17 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("_makeShaderCubic", optional_override([](sk_sp<SkImage> self,
SkTileMode tx, SkTileMode ty,
float B, float C, // See SkSamplingOptions.h for docs.
uintptr_t /* SkScalar* */ mPtr)->sk_sp<SkShader> {
WASMPointerF32 mPtr)->sk_sp<SkShader> {
return self->makeShader(tx, ty, SkSamplingOptions({B, C}), OptionalMatrix(mPtr));
}), allow_raw_pointers())
.function("_makeShaderOptions", optional_override([](sk_sp<SkImage> self,
SkTileMode tx, SkTileMode ty,
SkFilterMode filter, SkMipmapMode mipmap,
uintptr_t /* SkScalar* */ mPtr)->sk_sp<SkShader> {
WASMPointerF32 mPtr)->sk_sp<SkShader> {
return self->makeShader(tx, ty, {filter, mipmap}, OptionalMatrix(mPtr));
}), allow_raw_pointers())
.function("_readPixels", optional_override([](sk_sp<SkImage> self,
SimpleImageInfo sii, uintptr_t /* uint8_t* */ pPtr,
SimpleImageInfo sii, WASMPointerU8 pPtr,
size_t dstRowBytes, int srcX, int srcY)->bool {
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
SkImageInfo ii = toSkImageInfo(sii);
@ -1353,7 +1332,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
return SkImageFilters::ColorFilter(cf, input);
}))
.class_function("MakeCompose", &SkImageFilters::Compose)
.class_function("_MakeMatrixTransform", optional_override([](uintptr_t /* SkScalar* */ mPtr, SkFilterQuality fq,
.class_function("_MakeMatrixTransform", optional_override([](WASMPointerF32 mPtr, SkFilterQuality fq,
sk_sp<SkImageFilter> input)->sk_sp<SkImageFilter> {
OptionalMatrix matr(mPtr);
// TODO(kjlubick): pass in sampling directly from client
@ -1376,7 +1355,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
}))
.function("getBlendMode", &SkPaint::getBlendMode)
// provide an allocated place to put the returned color
.function("_getColor", optional_override([](SkPaint& self, uintptr_t /* float* */ cPtr)->void {
.function("_getColor", optional_override([](SkPaint& self, WASMPointerF32 cPtr)->void {
const SkColor4f& c = self.getColor4f();
float* fourFloats = reinterpret_cast<float*>(cPtr);
memcpy(fourFloats, c.vec(), 4 * sizeof(SkScalar));
@ -1389,7 +1368,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("setAntiAlias", &SkPaint::setAntiAlias)
.function("setAlphaf", &SkPaint::setAlphaf)
.function("setBlendMode", &SkPaint::setBlendMode)
.function("_setColor", optional_override([](SkPaint& self, uintptr_t /* float* */ cPtr,
.function("_setColor", optional_override([](SkPaint& self, WASMPointerF32 cPtr,
sk_sp<SkColorSpace> colorSpace) {
self.setColor(ptrToSkColor4f(cPtr), colorSpace.get());
}))
@ -1430,7 +1409,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
class_<SkPathEffect>("PathEffect")
.smart_ptr<sk_sp<SkPathEffect>>("sk_sp<PathEffect>")
.class_function("MakeCorner", &SkCornerPathEffect::Make)
.class_function("_MakeDash", optional_override([](uintptr_t /* float* */ cptr, int count,
.class_function("_MakeDash", optional_override([](WASMPointerF32 cptr, int count,
SkScalar phase)->sk_sp<SkPathEffect> {
const float* intervals = reinterpret_cast<const float*>(cptr);
return SkDashPathEffect::Make(intervals, count, phase);
@ -1447,13 +1426,13 @@ EMSCRIPTEN_BINDINGS(Skia) {
.class_function("_MakeFromCmds", &MakePathFromCmds)
.class_function("_MakeFromVerbsPointsWeights", &MakePathFromVerbsPointsWeights)
.function("_addArc", optional_override([](SkPath& self,
uintptr_t /* float* */ fPtr,
WASMPointerF32 fPtr,
SkScalar startAngle, SkScalar sweepAngle)->void {
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
self.addArc(*oval, startAngle, sweepAngle);
}))
.function("_addOval", optional_override([](SkPath& self,
uintptr_t /* float* */ fPtr,
WASMPointerF32 fPtr,
bool ccw, unsigned start)->void {
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
self.addOval(*oval, ccw ? SkPathDirection::kCCW : SkPathDirection::kCW, start);
@ -1461,25 +1440,25 @@ EMSCRIPTEN_BINDINGS(Skia) {
// interface.js has 3 overloads of addPath
.function("_addPath", &ApplyAddPath)
.function("_addPoly", optional_override([](SkPath& self,
uintptr_t /* SkPoint* */ fPtr,
WASMPointerF32 fPtr,
int count, bool close)->void {
const SkPoint* pts = reinterpret_cast<const SkPoint*>(fPtr);
self.addPoly(pts, count, close);
}))
.function("_addRect", optional_override([](SkPath& self,
uintptr_t /* float* */ fPtr,
WASMPointerF32 fPtr,
bool ccw)->void {
const SkRect* rect = reinterpret_cast<const SkRect*>(fPtr);
self.addRect(*rect, ccw ? SkPathDirection::kCCW : SkPathDirection::kCW);
}))
.function("_addRRect", optional_override([](SkPath& self,
uintptr_t /* float* */ fPtr,
WASMPointerF32 fPtr,
bool ccw)->void {
self.addRRect(ptrToSkRRect(fPtr), ccw ? SkPathDirection::kCCW : SkPathDirection::kCW);
}))
.function("_addVerbsPointsWeights", &PathAddVerbsPointsWeights)
.function("_arcToOval", optional_override([](SkPath& self,
uintptr_t /* float* */ fPtr, SkScalar startAngle,
WASMPointerF32 fPtr, SkScalar startAngle,
SkScalar sweepAngle, bool forceMoveTo)->void {
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
self.arcTo(*oval, startAngle, sweepAngle, forceMoveTo);
@ -1492,7 +1471,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("contains", &SkPath::contains)
.function("_cubicTo", &ApplyCubicTo)
.function("_getPoint", optional_override([](SkPath& self, int index,
uintptr_t /* float* */ oPtr)->void {
WASMPointerF32 oPtr)->void {
SkPoint* output = reinterpret_cast<SkPoint*>(oPtr);
*output = self.getPoint(index);
}))
@ -1529,12 +1508,12 @@ EMSCRIPTEN_BINDINGS(Skia) {
.function("setFillType", select_overload<void(SkPathFillType)>(&SkPath::setFillType))
.function("getFillType", &SkPath::getFillType)
.function("_getBounds", optional_override([](SkPath& self,
uintptr_t /* float* */ fPtr)->void {
WASMPointerF32 fPtr)->void {
SkRect* output = reinterpret_cast<SkRect*>(fPtr);
output[0] = self.getBounds();
}))
.function("_computeTightBounds", optional_override([](SkPath& self,
uintptr_t /* float* */ fPtr)->void {
WASMPointerF32 fPtr)->void {
SkRect* output = reinterpret_cast<SkRect*>(fPtr);
output[0] = self.computeTightBounds();
}))
@ -1549,7 +1528,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
class_<SkPictureRecorder>("PictureRecorder")
.constructor<>()
.function("_beginRecording", optional_override([](SkPictureRecorder& self,
uintptr_t /* float* */ fPtr) -> SkCanvas* {
WASMPointerF32 fPtr) -> SkCanvas* {
SkRect* bounds = reinterpret_cast<SkRect*>(fPtr);
return self.beginRecording(*bounds, nullptr);
}), allow_raw_pointers())
@ -1580,7 +1559,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
.smart_ptr<sk_sp<SkShader>>("sk_sp<Shader>")
.class_function("MakeBlend", select_overload<sk_sp<SkShader>(SkBlendMode, sk_sp<SkShader>, sk_sp<SkShader>)>(&SkShaders::Blend))
.class_function("_MakeColor",
optional_override([](uintptr_t /* float* */ cPtr, sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
optional_override([](WASMPointerF32 cPtr, sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
return SkShaders::Color(ptrToSkColor4f(cPtr), colorSpace);
})
)
@ -1598,11 +1577,11 @@ EMSCRIPTEN_BINDINGS(Skia) {
// representing colors. whether this is an array of SkColor or SkColor4f is indicated
// by the colorType argument. Only RGBA_8888 and RGBA_F32 are accepted.
.class_function("_MakeLinearGradient", optional_override([](
uintptr_t /* SkPoint* */ fourFloatsPtr,
uintptr_t cPtr, SkColorType colorType,
uintptr_t /* SkScalar* */ pPtr,
WASMPointerF32 fourFloatsPtr,
WASMPointerF32 cPtr, SkColorType colorType,
WASMPointerF32 pPtr,
int count, SkTileMode mode, uint32_t flags,
uintptr_t /* SkScalar* */ mPtr,
WASMPointerF32 mPtr,
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
const SkPoint* points = reinterpret_cast<const SkPoint*>(fourFloatsPtr);
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
@ -1622,10 +1601,10 @@ EMSCRIPTEN_BINDINGS(Skia) {
}), allow_raw_pointers())
.class_function("_MakeRadialGradient", optional_override([](
SkScalar cx, SkScalar cy, SkScalar radius,
uintptr_t cPtr, SkColorType colorType,
uintptr_t /* SkScalar* */ pPtr,
WASMPointerF32 cPtr, SkColorType colorType,
WASMPointerF32 pPtr,
int count, SkTileMode mode, uint32_t flags,
uintptr_t /* SkScalar* */ mPtr,
WASMPointerF32 mPtr,
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
OptionalMatrix localMatrix(mPtr);
@ -1642,12 +1621,12 @@ EMSCRIPTEN_BINDINGS(Skia) {
return nullptr;
}), allow_raw_pointers())
.class_function("_MakeSweepGradient", optional_override([](SkScalar cx, SkScalar cy,
uintptr_t cPtr, SkColorType colorType,
uintptr_t /* SkScalar* */ pPtr,
WASMPointerF32 cPtr, SkColorType colorType,
WASMPointerF32 pPtr,
int count, SkTileMode mode,
SkScalar startAngle, SkScalar endAngle,
uint32_t flags,
uintptr_t /* SkScalar* */ mPtr,
WASMPointerF32 mPtr,
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
OptionalMatrix localMatrix(mPtr);
@ -1675,12 +1654,12 @@ EMSCRIPTEN_BINDINGS(Skia) {
numOctaves, seed, &tileSize);
}))
.class_function("_MakeTwoPointConicalGradient", optional_override([](
uintptr_t /* SkPoint* */ fourFloatsPtr,
WASMPointerF32 fourFloatsPtr,
SkScalar startRadius, SkScalar endRadius,
uintptr_t cPtr, SkColorType colorType,
uintptr_t /* SkScalar* */ pPtr,
WASMPointerF32 cPtr, SkColorType colorType,
WASMPointerF32 pPtr,
int count, SkTileMode mode, uint32_t flags,
uintptr_t /* SkScalar* */ mPtr,
WASMPointerF32 mPtr,
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
const SkPoint* startAndEnd = reinterpret_cast<const SkPoint*>(fourFloatsPtr);
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
@ -1717,8 +1696,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
}
return effect;
}))
.function("_makeShader", optional_override([](SkRuntimeEffect& self, uintptr_t fPtr, size_t fLen, bool isOpaque,
uintptr_t /* SkScalar* */ mPtr)->sk_sp<SkShader> {
.function("_makeShader", optional_override([](SkRuntimeEffect& self, WASMPointerF32 fPtr, size_t fLen, bool isOpaque,
WASMPointerF32 mPtr)->sk_sp<SkShader> {
void* inputData = reinterpret_cast<void*>(fPtr);
castUniforms(inputData, fLen, self);
sk_sp<SkData> inputs = SkData::MakeFromMalloc(inputData, fLen);
@ -1726,9 +1705,9 @@ EMSCRIPTEN_BINDINGS(Skia) {
OptionalMatrix localMatrix(mPtr);
return self.makeShader(inputs, nullptr, 0, &localMatrix, isOpaque);
}))
.function("_makeShaderWithChildren", optional_override([](SkRuntimeEffect& self, uintptr_t fPtr, size_t fLen, bool isOpaque,
uintptr_t /** SkShader*[] */cPtrs, size_t cLen,
uintptr_t /* SkScalar* */ mPtr)->sk_sp<SkShader> {
.function("_makeShaderWithChildren", optional_override([](SkRuntimeEffect& self, WASMPointerF32 fPtr, size_t fLen, bool isOpaque,
WASMPointerU32 cPtrs, size_t cLen,
WASMPointerF32 mPtr)->sk_sp<SkShader> {
void* inputData = reinterpret_cast<void*>(fPtr);
castUniforms(inputData, fLen, self);
sk_sp<SkData> inputs = SkData::MakeFromMalloc(inputData, fLen);
@ -1773,7 +1752,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
class_<SkSurface>("Surface")
.smart_ptr<sk_sp<SkSurface>>("sk_sp<Surface>")
.class_function("_makeRasterDirect", optional_override([](const SimpleImageInfo ii,
uintptr_t /* uint8_t* */ pPtr,
WASMPointerU8 pPtr,
size_t rowBytes)->sk_sp<SkSurface> {
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
SkImageInfo imageInfo = toSkImageInfo(ii);
@ -1788,7 +1767,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
return {ii.width(), ii.height(), ii.colorType(), ii.alphaType(), ii.refColorSpace()};
}))
.function("height", &SkSurface::height)
.function("_makeImageSnapshot", optional_override([](SkSurface& self, uintptr_t /* int* */ iPtr)->sk_sp<SkImage> {
.function("_makeImageSnapshot", optional_override([](SkSurface& self, WASMPointerU32 iPtr)->sk_sp<SkImage> {
SkIRect* bounds = reinterpret_cast<SkIRect*>(iPtr);
if (!bounds) {
return self.makeImageSnapshot();
@ -1816,30 +1795,30 @@ EMSCRIPTEN_BINDINGS(Skia) {
#ifndef SK_NO_FONTS
class_<SkTextBlob>("TextBlob")
.smart_ptr<sk_sp<SkTextBlob>>("sk_sp<TextBlob>")
.class_function("_MakeFromRSXform", optional_override([](uintptr_t /* char* */ sptr,
.class_function("_MakeFromRSXform", optional_override([](WASMPointerU8 sptr,
size_t strBtyes,
uintptr_t /* SkRSXform* */ xptr,
WASMPointerF32 xptr,
const SkFont& font)->sk_sp<SkTextBlob> {
const char* str = reinterpret_cast<const char*>(sptr);
const SkRSXform* xforms = reinterpret_cast<const SkRSXform*>(xptr);
return SkTextBlob::MakeFromRSXform(str, strBtyes, xforms, font, SkTextEncoding::kUTF8);
}), allow_raw_pointers())
.class_function("_MakeFromRSXformGlyphs", optional_override([](uintptr_t /* SkGlyphID* */ gPtr,
.class_function("_MakeFromRSXformGlyphs", optional_override([](WASMPointerU16 gPtr,
size_t byteLen,
uintptr_t /* SkRSXform* */ xptr,
WASMPointerF32 xptr,
const SkFont& font)->sk_sp<SkTextBlob> {
const SkGlyphID* glyphs = reinterpret_cast<const SkGlyphID*>(gPtr);
const SkRSXform* xforms = reinterpret_cast<const SkRSXform*>(xptr);
return SkTextBlob::MakeFromRSXform(glyphs, byteLen, xforms, font, SkTextEncoding::kGlyphID);
}), allow_raw_pointers())
.class_function("_MakeFromText", optional_override([](uintptr_t /* char* */ sptr,
.class_function("_MakeFromText", optional_override([](WASMPointerU8 sptr,
size_t len, const SkFont& font)->sk_sp<SkTextBlob> {
const char* str = reinterpret_cast<const char*>(sptr);
return SkTextBlob::MakeFromText(str, len, font, SkTextEncoding::kUTF8);
}), allow_raw_pointers())
.class_function("_MakeFromGlyphs", optional_override([](uintptr_t /* SkGlyphID* */ gPtr,
.class_function("_MakeFromGlyphs", optional_override([](WASMPointerU16 gPtr,
size_t byteLen, const SkFont& font)->sk_sp<SkTextBlob> {
const SkGlyphID* glyphs = reinterpret_cast<const SkGlyphID*>(gPtr);
return SkTextBlob::MakeFromText(glyphs, byteLen, font, SkTextEncoding::kGlyphID);
@ -1852,7 +1831,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
class_<SkVertices>("Vertices")
.smart_ptr<sk_sp<SkVertices>>("sk_sp<Vertices>")
.function("_bounds", optional_override([](SkVertices& self,
uintptr_t /* float* */ fPtr)->void {
WASMPointerF32 fPtr)->void {
SkRect* output = reinterpret_cast<SkRect*>(fPtr);
output[0] = self.bounds();
}))
@ -1861,22 +1840,22 @@ EMSCRIPTEN_BINDINGS(Skia) {
// Not intended to be called directly by clients
class_<SkVertices::Builder>("_VerticesBuilder")
.constructor<SkVertices::VertexMode, int, int, uint32_t>()
.function("colors", optional_override([](SkVertices::Builder& self)->uintptr_t /* SkColor* */{
.function("colors", optional_override([](SkVertices::Builder& self)->WASMPointerF32{
// Emscripten won't let us return bare pointers, but we can return ints just fine.
return reinterpret_cast<uintptr_t>(self.colors());
return reinterpret_cast<WASMPointerF32>(self.colors());
}))
.function("detach", &SkVertices::Builder::detach)
.function("indices", optional_override([](SkVertices::Builder& self)->uintptr_t /* uint16_t* */{
.function("indices", optional_override([](SkVertices::Builder& self)->WASMPointerU16{
// Emscripten won't let us return bare pointers, but we can return ints just fine.
return reinterpret_cast<uintptr_t>(self.indices());
return reinterpret_cast<WASMPointerU16>(self.indices());
}))
.function("positions", optional_override([](SkVertices::Builder& self)->uintptr_t /* SkPoint* */{
.function("positions", optional_override([](SkVertices::Builder& self)->WASMPointerF32{
// Emscripten won't let us return bare pointers, but we can return ints just fine.
return reinterpret_cast<uintptr_t>(self.positions());
return reinterpret_cast<WASMPointerF32>(self.positions());
}))
.function("texCoords", optional_override([](SkVertices::Builder& self)->uintptr_t /* SkPoint* */{
.function("texCoords", optional_override([](SkVertices::Builder& self)->WASMPointerF32{
// Emscripten won't let us return bare pointers, but we can return ints just fine.
return reinterpret_cast<uintptr_t>(self.texCoords());
return reinterpret_cast<WASMPointerF32>(self.texCoords());
}));
enum_<SkAlphaType>("AlphaType")

View File

@ -94,7 +94,7 @@ static sk_sp<SkData> getResource(const char* name) {
return it->second;
}
static void LoadResource(std::string name, uintptr_t /* byte* */ bPtr, size_t len) {
static void LoadResource(std::string name, WASMPointerU8 bPtr, size_t len) {
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(bPtr);
auto data = SkData::MakeFromMalloc(bytes, len);
gResources[name] = std::move(data);

View File

@ -28,7 +28,7 @@ using namespace emscripten;
namespace para = skia::textlayout;
SkColor4f toSkColor4f(uintptr_t /* float* */ cPtr) {
SkColor4f toSkColor4f(WASMPointerF32 cPtr) {
float* fourFloats = reinterpret_cast<float*>(cPtr);
SkColor4f color = {fourFloats[0], fourFloats[1], fourFloats[2], fourFloats[3]};
return color;
@ -41,12 +41,12 @@ struct SimpleFontStyle {
};
struct SimpleTextStyle {
uintptr_t /* float* */ colorPtr;
uintptr_t /* float* */ foregroundColorPtr;
uintptr_t /* float* */ backgroundColorPtr;
WASMPointerF32 colorPtr;
WASMPointerF32 foregroundColorPtr;
WASMPointerF32 backgroundColorPtr;
uint8_t decoration;
SkScalar decorationThickness;
uintptr_t /* float* */ decorationColorPtr;
WASMPointerF32 decorationColorPtr;
para::TextDecorationStyle decorationStyle;
para::TextBaseline textBaseline;
SkScalar fontSize;
@ -54,25 +54,25 @@ struct SimpleTextStyle {
SkScalar wordSpacing;
SkScalar heightMultiplier;
bool halfLeading;
uintptr_t /* const char* */ localePtr;
WASMPointerU8 localePtr;
int localeLen;
SimpleFontStyle fontStyle;
uintptr_t /* const char** */ fontFamiliesPtr;
WASMPointerU8 fontFamiliesPtr;
int fontFamiliesLen;
int shadowLen;
uintptr_t /* SkColor4f* */ shadowColorsPtr;
uintptr_t /* SkPoint* */ shadowOffsetsPtr;
uintptr_t /* float* */ shadowBlurRadiiPtr;
WASMPointerF32 shadowColorsPtr;
WASMPointerF32 shadowOffsetsPtr;
WASMPointerF32 shadowBlurRadiiPtr;
int fontFeatureLen;
uintptr_t /* float* */ fontFeatureNamesPtr;
uintptr_t /* float* */ fontFeatureValuesPtr;
WASMPointerF32 fontFeatureNamesPtr;
WASMPointerF32 fontFeatureValuesPtr;
};
struct SimpleStrutStyle {
uintptr_t /* const char** */ fontFamiliesPtr;
WASMPointerU32 fontFamiliesPtr;
int fontFamiliesLen;
SimpleFontStyle fontStyle;
SkScalar fontSize;
@ -209,7 +209,7 @@ para::TextStyle toTextStyle(const SimpleTextStyle& s) {
struct SimpleParagraphStyle {
bool disableHinting;
uintptr_t /* const char* */ ellipsisPtr;
WASMPointerU8 ellipsisPtr;
size_t ellipsisLen;
SkScalar heightMultiplier;
size_t maxLines;
@ -557,7 +557,7 @@ EMSCRIPTEN_BINDINGS(Paragraph) {
}))
.function("_registerFont", optional_override([](para::TypefaceFontProvider& self,
sk_sp<SkTypeface> typeface,
uintptr_t familyPtr) {
WASMPointerU8 familyPtr) {
const char* fPtr = reinterpret_cast<const char*>(familyPtr);
SkString fStr(fPtr);
self.registerTypeface(typeface, fStr);

View File

@ -95,8 +95,8 @@ EMSCRIPTEN_BINDINGS(Particles) {
class_<SkParticleEffect>("ParticleEffect")
.smart_ptr<sk_sp<SkParticleEffect>>("sk_sp<SkParticleEffect>")
.function("draw", &SkParticleEffect::draw, allow_raw_pointers())
.function("_uniformPtr", optional_override([](SkParticleEffect& self)->uintptr_t {
return reinterpret_cast<uintptr_t>(self.uniformData());
.function("_uniformPtr", optional_override([](SkParticleEffect& self)->WASMPointerF32 {
return reinterpret_cast<WASMPointerF32>(self.uniformData());
}))
.function("getUniformCount", optional_override([](SkParticleEffect& self)->int {
auto info = self.uniformInfo();
@ -143,11 +143,10 @@ EMSCRIPTEN_BINDINGS(Particles) {
function("_MakeParticles", optional_override([](std::string json,
size_t assetCount,
uintptr_t /* char** */ nptr,
uintptr_t /* uint8_t** */ dptr,
uintptr_t /* size_t* */ sptr)
WASMPointerU32 nptr,
WASMPointerU32 dptr,
WASMPointerU32 sptr)
->sk_sp<SkParticleEffect> {
// See the comment in canvaskit_bindings.cpp about the use of uintptr_t
static bool didInit = false;
if (!didInit) {
SkParticleEffect::RegisterParticleTypes();

View File

@ -290,7 +290,7 @@ EMSCRIPTEN_BINDINGS(Skottie) {
return std::string(self.version().c_str());
}))
.function("_size", optional_override([](skottie::Animation& self,
uintptr_t /* float* */ oPtr)->void {
WASMPointerF32 oPtr)->void {
SkSize* output = reinterpret_cast<SkSize*>(oPtr);
*output = self.size();
}))
@ -303,7 +303,7 @@ EMSCRIPTEN_BINDINGS(Skottie) {
self.seekFrame(t);
}))
.function("_render", optional_override([](skottie::Animation& self, SkCanvas* canvas,
uintptr_t /* float* */ fPtr)->void {
WASMPointerF32 fPtr)->void {
const SkRect* dst = reinterpret_cast<const SkRect*>(fPtr);
self.render(canvas, dst);
}), allow_raw_pointers());
@ -318,29 +318,29 @@ EMSCRIPTEN_BINDINGS(Skottie) {
.smart_ptr<sk_sp<ManagedAnimation>>("sk_sp<ManagedAnimation>")
.function("version" , &ManagedAnimation::version)
.function("_size", optional_override([](ManagedAnimation& self,
uintptr_t /* float* */ oPtr)->void {
WASMPointerF32 oPtr)->void {
SkSize* output = reinterpret_cast<SkSize*>(oPtr);
*output = self.size();
}))
.function("duration" , &ManagedAnimation::duration)
.function("fps" , &ManagedAnimation::fps)
.function("_render", optional_override([](ManagedAnimation& self, SkCanvas* canvas,
uintptr_t /* float* */ fPtr)->void {
WASMPointerF32 fPtr)->void {
const SkRect* dst = reinterpret_cast<const SkRect*>(fPtr);
self.render(canvas, dst);
}), allow_raw_pointers())
.function("_seek", optional_override([](ManagedAnimation& self, SkScalar t,
uintptr_t /* float* */ fPtr) {
WASMPointerF32 fPtr) {
SkRect* damageRect = reinterpret_cast<SkRect*>(fPtr);
damageRect[0] = self.seek(t);
}))
.function("_seekFrame", optional_override([](ManagedAnimation& self, double frame,
uintptr_t /* float* */ fPtr) {
WASMPointerF32 fPtr) {
SkRect* damageRect = reinterpret_cast<SkRect*>(fPtr);
damageRect[0] = self.seekFrame(frame);
}))
.function("seekFrame" , &ManagedAnimation::seekFrame)
.function("_setColor" , optional_override([](ManagedAnimation& self, const std::string& key, uintptr_t /* float* */ cPtr) {
.function("_setColor" , optional_override([](ManagedAnimation& self, const std::string& key, WASMPointerF32 cPtr) {
float* fourFloats = reinterpret_cast<float*>(cPtr);
SkColor4f color = { fourFloats[0], fourFloats[1], fourFloats[2], fourFloats[3] };
return self.setColor(key, color.toSkColor());
@ -354,14 +354,13 @@ EMSCRIPTEN_BINDINGS(Skottie) {
function("_MakeManagedAnimation", optional_override([](std::string json,
size_t assetCount,
uintptr_t /* char** */ nptr,
uintptr_t /* uint8_t** */ dptr,
uintptr_t /* size_t* */ sptr,
WASMPointerU32 nptr,
WASMPointerU32 dptr,
WASMPointerU32 sptr,
std::string prop_prefix,
emscripten::val soundMap,
emscripten::val logger)
->sk_sp<ManagedAnimation> {
// See the comment in canvaskit_bindings.cpp about the use of uintptr_t
const auto assetNames = reinterpret_cast<char** >(nptr);
const auto assetDatas = reinterpret_cast<uint8_t**>(dptr);
const auto assetSizes = reinterpret_cast<size_t* >(sptr);