diff --git a/modules/canvaskit/WasmCommon.h b/modules/canvaskit/WasmCommon.h index 00d9e69b6a..cda847f14e 100644 --- a/modules/canvaskit/WasmCommon.h +++ b/modules/canvaskit/WasmCommon.h @@ -12,6 +12,7 @@ #include #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 { \ static constexpr const char* const gName = name; \ diff --git a/modules/canvaskit/canvaskit_bindings.cpp b/modules/canvaskit/canvaskit_bindings.cpp index f949d20cfb..bd1acbb4e2 100644 --- a/modules/canvaskit/canvaskit_bindings.cpp +++ b/modules/canvaskit/canvaskit_bindings.cpp @@ -85,7 +85,7 @@ sk_sp SkFontMgr_New_Custom_Data(sk_sp* datas, int n); #endif struct OptionalMatrix : SkMatrix { - OptionalMatrix(uintptr_t mPtr) { + OptionalMatrix(WASMPointerF32 mPtr) { if (mPtr) { const SkScalar* nineMatrixValues = reinterpret_cast(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(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(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(verbsPtr); const float* pts = reinterpret_cast(ptsPtr); const float* weights = reinterpret_cast(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(cPtrAmbi); float* spotFloats = reinterpret_cast(cPtrSpot); @@ -705,17 +695,6 @@ Uint8Array toBytes(sk_sp data) { ).call("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 { uint8_t* imgData = reinterpret_cast(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 { uint8_t* imgData = reinterpret_cast(iptr); sk_sp 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 { uint8_t* pixels = reinterpret_cast(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(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 { + function("_MakePicture", optional_override([](WASMPointerU8 dPtr, + size_t bytes)->sk_sp { uint8_t* d = reinterpret_cast(dPtr); sk_sp data = SkData::MakeFromMalloc(d, bytes); @@ -830,32 +809,32 @@ EMSCRIPTEN_BINDINGS(Skia) { class_("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(&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(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(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(fPtr); self.drawArc(*oval, startAngle, sweepAngle, useCenter, paint); })) .function("_drawAtlasOptions", optional_override([](SkCanvas& self, - const sk_sp& atlas, uintptr_t /* SkRSXform* */ xptr, - uintptr_t /* SkRect* */ rptr, uintptr_t /* SkColor* */ cptr, int count, + const sk_sp& atlas, WASMPointerF32 xptr, + WASMPointerF32 rptr, WASMPointerU32 cptr, int count, SkBlendMode mode, SkFilterMode filter, SkMipmapMode mipmap, const SkPaint* paint)->void { const SkRSXform* dstXforms = reinterpret_cast(xptr); @@ -869,8 +848,8 @@ EMSCRIPTEN_BINDINGS(Skia) { nullptr, paint); }), allow_raw_pointers()) .function("_drawAtlasCubic", optional_override([](SkCanvas& self, - const sk_sp& atlas, uintptr_t /* SkRSXform* */ xptr, - uintptr_t /* SkRect* */ rptr, uintptr_t /* SkColor* */ cptr, int count, + const sk_sp& atlas, WASMPointerF32 xptr, + WASMPointerF32 rptr, WASMPointerU32 cptr, int count, SkBlendMode mode, float B, float C, const SkPaint* paint)->void { const SkRSXform* dstXforms = reinterpret_cast(xptr); const SkRect* srcRects = reinterpret_cast(rptr); @@ -883,10 +862,10 @@ EMSCRIPTEN_BINDINGS(Skia) { nullptr, paint); }), allow_raw_pointers()) .function("drawCircle", select_overload(&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& image, - uintptr_t /* int* */ centerPtr, uintptr_t /* float* */ dstPtr, + WASMPointerU32 centerPtr, WASMPointerF32 dstPtr, SkFilterMode filter, const SkPaint* paint)->void { const SkIRect* center = reinterpret_cast(centerPtr); const SkRect* dst = reinterpret_cast(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& image, - uintptr_t /* float* */ srcPtr, uintptr_t /* float* */ dstPtr, + WASMPointerF32 srcPtr, WASMPointerF32 dstPtr, const SkPaint* paint, bool fastSample)->void { const SkRect* src = reinterpret_cast(srcPtr); const SkRect* dst = reinterpret_cast(dstPtr); @@ -959,7 +938,7 @@ EMSCRIPTEN_BINDINGS(Skia) { SkCanvas::kStrict_SrcRectConstraint); }), allow_raw_pointers()) .function("_drawImageRectCubic", optional_override([](SkCanvas& self, const sk_sp& 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(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& 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(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(&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(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(cubics), @@ -1005,15 +984,15 @@ EMSCRIPTEN_BINDINGS(Skia) { // a bitmap. An SkPicture is a series of draw commands. .function("drawPicture", select_overload&)>(&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(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(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(zPlaneParamPtr); const SkVector3* lightPos = reinterpret_cast(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(sptr); @@ -1050,7 +1029,7 @@ EMSCRIPTEN_BINDINGS(Skia) { .function("drawTextBlob", select_overload&, SkScalar, SkScalar, const SkPaint&)>(&SkCanvas::drawTextBlob)) #endif .function("drawVertices", select_overload&, 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(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(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(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(pPtr); SkImageInfo dstInfo = toSkImageInfo(di); @@ -1104,7 +1083,7 @@ EMSCRIPTEN_BINDINGS(Skia) { .function("restoreToCount", &SkCanvas::restoreToCount) .function("rotate", select_overload(&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(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(pPtr); SkImageInfo dstInfo = toSkImageInfo(di); @@ -1126,13 +1105,13 @@ EMSCRIPTEN_BINDINGS(Skia) { class_("ColorFilter") .smart_ptr>("sk_sp>") - .class_function("_MakeBlend", optional_override([](uintptr_t /* float* */ cPtr, SkBlendMode mode)->sk_sp { + .class_function("_MakeBlend", optional_override([](WASMPointerF32 cPtr, SkBlendMode mode)->sk_sp { 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(fPtr); return SkColorFilters::Matrix(twentyFloats); })) @@ -1146,7 +1125,7 @@ EMSCRIPTEN_BINDINGS(Skia) { .smart_ptr>("sk_sp>") .function("_getPosTan", optional_override([](SkContourMeasure& self, SkScalar distance, - uintptr_t /* SkPoint* */ oPtr) -> void { + WASMPointerF32 oPtr) -> void { SkPoint* pointAndVector = reinterpret_cast(oPtr); if (!self.getPosTan(distance, pointAndVector, pointAndVector + 1)) { SkDebugf("zero-length path in getPosTan\n"); @@ -1170,9 +1149,9 @@ EMSCRIPTEN_BINDINGS(Skia) { .constructor>() .constructor, SkScalar>() .constructor, 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(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(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(sptr); SkGlyphID* glyphIDs = reinterpret_cast(iPtr); @@ -1237,8 +1216,8 @@ EMSCRIPTEN_BINDINGS(Skia) { class_("FontMgr") .smart_ptr>("sk_sp") - .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 { auto datas = reinterpret_cast(dPtr); auto sizes = reinterpret_cast(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 { uint8_t* font = reinterpret_cast(fPtr); sk_sp fontData = SkData::MakeFromMalloc(font, flen); @@ -1319,17 +1298,17 @@ EMSCRIPTEN_BINDINGS(Skia) { .function("_makeShaderCubic", optional_override([](sk_sp self, SkTileMode tx, SkTileMode ty, float B, float C, // See SkSamplingOptions.h for docs. - uintptr_t /* SkScalar* */ mPtr)->sk_sp { + WASMPointerF32 mPtr)->sk_sp { return self->makeShader(tx, ty, SkSamplingOptions({B, C}), OptionalMatrix(mPtr)); }), allow_raw_pointers()) .function("_makeShaderOptions", optional_override([](sk_sp self, SkTileMode tx, SkTileMode ty, SkFilterMode filter, SkMipmapMode mipmap, - uintptr_t /* SkScalar* */ mPtr)->sk_sp { + WASMPointerF32 mPtr)->sk_sp { return self->makeShader(tx, ty, {filter, mipmap}, OptionalMatrix(mPtr)); }), allow_raw_pointers()) .function("_readPixels", optional_override([](sk_sp 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(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 input)->sk_sp { 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(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 colorSpace) { self.setColor(ptrToSkColor4f(cPtr), colorSpace.get()); })) @@ -1430,7 +1409,7 @@ EMSCRIPTEN_BINDINGS(Skia) { class_("PathEffect") .smart_ptr>("sk_sp") .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 { const float* intervals = reinterpret_cast(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(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(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(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(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(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(oPtr); *output = self.getPoint(index); })) @@ -1529,12 +1508,12 @@ EMSCRIPTEN_BINDINGS(Skia) { .function("setFillType", select_overload(&SkPath::setFillType)) .function("getFillType", &SkPath::getFillType) .function("_getBounds", optional_override([](SkPath& self, - uintptr_t /* float* */ fPtr)->void { + WASMPointerF32 fPtr)->void { SkRect* output = reinterpret_cast(fPtr); output[0] = self.getBounds(); })) .function("_computeTightBounds", optional_override([](SkPath& self, - uintptr_t /* float* */ fPtr)->void { + WASMPointerF32 fPtr)->void { SkRect* output = reinterpret_cast(fPtr); output[0] = self.computeTightBounds(); })) @@ -1549,7 +1528,7 @@ EMSCRIPTEN_BINDINGS(Skia) { class_("PictureRecorder") .constructor<>() .function("_beginRecording", optional_override([](SkPictureRecorder& self, - uintptr_t /* float* */ fPtr) -> SkCanvas* { + WASMPointerF32 fPtr) -> SkCanvas* { SkRect* bounds = reinterpret_cast(fPtr); return self.beginRecording(*bounds, nullptr); }), allow_raw_pointers()) @@ -1580,7 +1559,7 @@ EMSCRIPTEN_BINDINGS(Skia) { .smart_ptr>("sk_sp") .class_function("MakeBlend", select_overload(SkBlendMode, sk_sp, sk_sp)>(&SkShaders::Blend)) .class_function("_MakeColor", - optional_override([](uintptr_t /* float* */ cPtr, sk_sp colorSpace)->sk_sp { + optional_override([](WASMPointerF32 cPtr, sk_sp colorSpace)->sk_sp { 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 colorSpace)->sk_sp { const SkPoint* points = reinterpret_cast(fourFloatsPtr); const SkScalar* positions = reinterpret_cast(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 colorSpace)->sk_sp { const SkScalar* positions = reinterpret_cast(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 colorSpace)->sk_sp { const SkScalar* positions = reinterpret_cast(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 colorSpace)->sk_sp { const SkPoint* startAndEnd = reinterpret_cast(fourFloatsPtr); const SkScalar* positions = reinterpret_cast(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 { + .function("_makeShader", optional_override([](SkRuntimeEffect& self, WASMPointerF32 fPtr, size_t fLen, bool isOpaque, + WASMPointerF32 mPtr)->sk_sp { void* inputData = reinterpret_cast(fPtr); castUniforms(inputData, fLen, self); sk_sp 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 { + .function("_makeShaderWithChildren", optional_override([](SkRuntimeEffect& self, WASMPointerF32 fPtr, size_t fLen, bool isOpaque, + WASMPointerU32 cPtrs, size_t cLen, + WASMPointerF32 mPtr)->sk_sp { void* inputData = reinterpret_cast(fPtr); castUniforms(inputData, fLen, self); sk_sp inputs = SkData::MakeFromMalloc(inputData, fLen); @@ -1773,7 +1752,7 @@ EMSCRIPTEN_BINDINGS(Skia) { class_("Surface") .smart_ptr>("sk_sp") .class_function("_makeRasterDirect", optional_override([](const SimpleImageInfo ii, - uintptr_t /* uint8_t* */ pPtr, + WASMPointerU8 pPtr, size_t rowBytes)->sk_sp { uint8_t* pixels = reinterpret_cast(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 { + .function("_makeImageSnapshot", optional_override([](SkSurface& self, WASMPointerU32 iPtr)->sk_sp { SkIRect* bounds = reinterpret_cast(iPtr); if (!bounds) { return self.makeImageSnapshot(); @@ -1816,30 +1795,30 @@ EMSCRIPTEN_BINDINGS(Skia) { #ifndef SK_NO_FONTS class_("TextBlob") .smart_ptr>("sk_sp") - .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 { const char* str = reinterpret_cast(sptr); const SkRSXform* xforms = reinterpret_cast(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 { const SkGlyphID* glyphs = reinterpret_cast(gPtr); const SkRSXform* xforms = reinterpret_cast(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 { const char* str = reinterpret_cast(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 { const SkGlyphID* glyphs = reinterpret_cast(gPtr); return SkTextBlob::MakeFromText(glyphs, byteLen, font, SkTextEncoding::kGlyphID); @@ -1852,7 +1831,7 @@ EMSCRIPTEN_BINDINGS(Skia) { class_("Vertices") .smart_ptr>("sk_sp") .function("_bounds", optional_override([](SkVertices& self, - uintptr_t /* float* */ fPtr)->void { + WASMPointerF32 fPtr)->void { SkRect* output = reinterpret_cast(fPtr); output[0] = self.bounds(); })) @@ -1861,22 +1840,22 @@ EMSCRIPTEN_BINDINGS(Skia) { // Not intended to be called directly by clients class_("_VerticesBuilder") .constructor() - .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(self.colors()); + return reinterpret_cast(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(self.indices()); + return reinterpret_cast(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(self.positions()); + return reinterpret_cast(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(self.texCoords()); + return reinterpret_cast(self.texCoords()); })); enum_("AlphaType") diff --git a/modules/canvaskit/gm_bindings.cpp b/modules/canvaskit/gm_bindings.cpp index aa22abefc1..25e1b05cde 100644 --- a/modules/canvaskit/gm_bindings.cpp +++ b/modules/canvaskit/gm_bindings.cpp @@ -94,7 +94,7 @@ static sk_sp 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(bPtr); auto data = SkData::MakeFromMalloc(bytes, len); gResources[name] = std::move(data); diff --git a/modules/canvaskit/paragraph_bindings.cpp b/modules/canvaskit/paragraph_bindings.cpp index c8b119d23d..6081297574 100644 --- a/modules/canvaskit/paragraph_bindings.cpp +++ b/modules/canvaskit/paragraph_bindings.cpp @@ -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(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 typeface, - uintptr_t familyPtr) { + WASMPointerU8 familyPtr) { const char* fPtr = reinterpret_cast(familyPtr); SkString fStr(fPtr); self.registerTypeface(typeface, fStr); diff --git a/modules/canvaskit/particles_bindings.cpp b/modules/canvaskit/particles_bindings.cpp index 7ac65898bb..4c1d616760 100644 --- a/modules/canvaskit/particles_bindings.cpp +++ b/modules/canvaskit/particles_bindings.cpp @@ -95,8 +95,8 @@ EMSCRIPTEN_BINDINGS(Particles) { class_("ParticleEffect") .smart_ptr>("sk_sp") .function("draw", &SkParticleEffect::draw, allow_raw_pointers()) - .function("_uniformPtr", optional_override([](SkParticleEffect& self)->uintptr_t { - return reinterpret_cast(self.uniformData()); + .function("_uniformPtr", optional_override([](SkParticleEffect& self)->WASMPointerF32 { + return reinterpret_cast(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 { - // See the comment in canvaskit_bindings.cpp about the use of uintptr_t static bool didInit = false; if (!didInit) { SkParticleEffect::RegisterParticleTypes(); diff --git a/modules/canvaskit/skottie_bindings.cpp b/modules/canvaskit/skottie_bindings.cpp index 038253894e..febf8b8ce4 100644 --- a/modules/canvaskit/skottie_bindings.cpp +++ b/modules/canvaskit/skottie_bindings.cpp @@ -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(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(fPtr); self.render(canvas, dst); }), allow_raw_pointers()); @@ -318,29 +318,29 @@ EMSCRIPTEN_BINDINGS(Skottie) { .smart_ptr>("sk_sp") .function("version" , &ManagedAnimation::version) .function("_size", optional_override([](ManagedAnimation& self, - uintptr_t /* float* */ oPtr)->void { + WASMPointerF32 oPtr)->void { SkSize* output = reinterpret_cast(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(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(fPtr); damageRect[0] = self.seek(t); })) .function("_seekFrame", optional_override([](ManagedAnimation& self, double frame, - uintptr_t /* float* */ fPtr) { + WASMPointerF32 fPtr) { SkRect* damageRect = reinterpret_cast(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(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 { - // See the comment in canvaskit_bindings.cpp about the use of uintptr_t const auto assetNames = reinterpret_cast(nptr); const auto assetDatas = reinterpret_cast(dptr); const auto assetSizes = reinterpret_cast(sptr);