2018-09-20 21:39:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-09-18 20:18:17 +00:00
|
|
|
#include "include/android/SkAnimatedImage.h"
|
|
|
|
#include "include/codec/SkAndroidCodec.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkBlurTypes.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
2019-09-12 15:11:25 +00:00
|
|
|
#include "include/core/SkColorFilter.h"
|
2020-05-26 17:10:20 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkEncodedImageFormat.h"
|
|
|
|
#include "include/core/SkImage.h"
|
2019-10-29 13:55:39 +00:00
|
|
|
#include "include/core/SkImageFilter.h"
|
2021-11-11 16:20:49 +00:00
|
|
|
#include "include/core/SkImageGenerator.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
2020-02-22 16:14:57 +00:00
|
|
|
#include "include/core/SkM44.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPathEffect.h"
|
|
|
|
#include "include/core/SkPathMeasure.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
2019-09-03 16:59:06 +00:00
|
|
|
#include "include/core/SkRRect.h"
|
2020-12-11 19:51:36 +00:00
|
|
|
#include "include/core/SkSamplingOptions.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkStrokeRec.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTextBlob.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/core/SkVertices.h"
|
|
|
|
#include "include/effects/SkCornerPathEffect.h"
|
|
|
|
#include "include/effects/SkDashPathEffect.h"
|
|
|
|
#include "include/effects/SkDiscretePathEffect.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
2019-10-29 13:55:39 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2020-10-15 17:09:02 +00:00
|
|
|
#include "include/effects/SkPerlinNoiseShader.h"
|
2020-01-02 16:55:24 +00:00
|
|
|
#include "include/effects/SkRuntimeEffect.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkTrimPathEffect.h"
|
2021-01-07 16:14:13 +00:00
|
|
|
#include "include/private/SkShadowFlags.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkParsePath.h"
|
|
|
|
#include "include/utils/SkShadowUtils.h"
|
2021-04-27 21:46:41 +00:00
|
|
|
#include "modules/skparagraph/include/Paragraph.h"
|
2020-05-04 18:59:49 +00:00
|
|
|
#include "src/core/SkPathPriv.h"
|
2019-11-25 18:45:28 +00:00
|
|
|
#include "src/core/SkResourceCache.h"
|
2020-08-27 16:44:07 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
2019-12-30 20:02:30 +00:00
|
|
|
#include "src/sksl/SkSLCompiler.h"
|
2018-11-03 11:51:19 +00:00
|
|
|
|
2020-03-26 13:27:48 +00:00
|
|
|
#include "modules/canvaskit/WasmCommon.h"
|
2018-09-20 21:39:31 +00:00
|
|
|
#include <emscripten.h>
|
|
|
|
#include <emscripten/bind.h>
|
2021-11-11 16:20:49 +00:00
|
|
|
#include <emscripten/html5.h>
|
2019-01-03 19:27:27 +00:00
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-08-27 16:44:07 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/gl/GrGLInterface.h"
|
|
|
|
#include "include/gpu/gl/GrGLTypes.h"
|
2021-11-11 16:20:49 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2021-06-03 12:02:03 +00:00
|
|
|
#include "src/gpu/gl/GrGLDefines.h"
|
2019-03-11 20:11:58 +00:00
|
|
|
|
2021-08-25 17:13:09 +00:00
|
|
|
#include "webgl/webgl1.h"
|
2018-10-11 12:51:55 +00:00
|
|
|
#endif
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
#ifndef SK_NO_FONTS
|
|
|
|
#include "include/core/SkFont.h"
|
2021-04-28 12:53:23 +00:00
|
|
|
#include "include/core/SkFontMetrics.h"
|
2020-01-06 13:10:05 +00:00
|
|
|
#include "include/core/SkFontMgr.h"
|
|
|
|
#include "include/core/SkFontTypes.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SK_INCLUDE_PATHOPS
|
|
|
|
#include "include/pathops/SkPathOps.h"
|
|
|
|
#endif
|
|
|
|
|
2019-09-26 17:20:50 +00:00
|
|
|
#ifndef SK_NO_FONTS
|
2021-03-23 22:02:32 +00:00
|
|
|
sk_sp<SkFontMgr> SkFontMgr_New_Custom_Data(sk_sp<SkData>* datas, int n);
|
2019-09-26 17:20:50 +00:00
|
|
|
#endif
|
|
|
|
|
2020-04-02 19:24:15 +00:00
|
|
|
struct OptionalMatrix : SkMatrix {
|
2021-05-26 17:40:22 +00:00
|
|
|
OptionalMatrix(WASMPointerF32 mPtr) {
|
2020-04-02 19:24:15 +00:00
|
|
|
if (mPtr) {
|
|
|
|
const SkScalar* nineMatrixValues = reinterpret_cast<const SkScalar*>(mPtr);
|
|
|
|
this->set9(nineMatrixValues);
|
|
|
|
}
|
|
|
|
}
|
2019-03-08 15:04:28 +00:00
|
|
|
};
|
|
|
|
|
2021-05-26 17:40:22 +00:00
|
|
|
SkColor4f ptrToSkColor4f(WASMPointerF32 cPtr) {
|
2020-05-04 20:46:17 +00:00
|
|
|
float* fourFloats = reinterpret_cast<float*>(cPtr);
|
2020-06-02 20:15:23 +00:00
|
|
|
SkColor4f color;
|
|
|
|
memcpy(&color, fourFloats, 4 * sizeof(float));
|
2020-03-26 13:27:48 +00:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:40:22 +00:00
|
|
|
SkRRect ptrToSkRRect(WASMPointerF32 fPtr) {
|
2020-09-03 11:57:12 +00:00
|
|
|
// 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).
|
|
|
|
const SkScalar* twelveFloats = reinterpret_cast<const SkScalar*>(fPtr);
|
|
|
|
const SkRect rect = reinterpret_cast<const SkRect*>(twelveFloats)[0];
|
|
|
|
const SkVector* radiiValues = reinterpret_cast<const SkVector*>(twelveFloats + 4);
|
|
|
|
|
|
|
|
SkRRect rr;
|
|
|
|
rr.setRectRadii(rect, radiiValues);
|
|
|
|
return rr;
|
|
|
|
}
|
|
|
|
|
2020-02-21 22:15:22 +00:00
|
|
|
// Surface creation structs and helpers
|
2019-03-08 15:04:28 +00:00
|
|
|
struct SimpleImageInfo {
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
SkColorType colorType;
|
|
|
|
SkAlphaType alphaType;
|
2020-05-26 17:10:20 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace;
|
2019-03-08 15:04:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkImageInfo toSkImageInfo(const SimpleImageInfo& sii) {
|
2020-05-26 17:10:20 +00:00
|
|
|
return SkImageInfo::Make(sii.width, sii.height, sii.colorType, sii.alphaType, sii.colorSpace);
|
2019-03-08 15:04:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2020-05-26 17:10:20 +00:00
|
|
|
|
|
|
|
// Set the pixel format based on the colortype.
|
|
|
|
// These degrees of freedom are removed from canvaskit only to keep the interface simpler.
|
|
|
|
struct ColorSettings {
|
|
|
|
ColorSettings(sk_sp<SkColorSpace> colorSpace) {
|
|
|
|
if (colorSpace == nullptr || colorSpace->isSRGB()) {
|
|
|
|
colorType = kRGBA_8888_SkColorType;
|
2021-08-25 17:13:09 +00:00
|
|
|
pixFormat = GR_GL_RGBA8;
|
2020-05-26 17:10:20 +00:00
|
|
|
} else {
|
|
|
|
colorType = kRGBA_F16_SkColorType;
|
2021-08-25 17:13:09 +00:00
|
|
|
pixFormat = GR_GL_RGBA16F;
|
2020-05-26 17:10:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
SkColorType colorType;
|
|
|
|
GrGLenum pixFormat;
|
|
|
|
};
|
|
|
|
|
2021-08-25 17:13:09 +00:00
|
|
|
sk_sp<GrDirectContext> MakeGrContext()
|
2019-03-08 15:04:28 +00:00
|
|
|
{
|
2021-08-25 17:13:09 +00:00
|
|
|
// We assume that any calls we make to GL for the remainder of this function will go to the
|
|
|
|
// desired WebGL Context.
|
|
|
|
// setup interface.
|
2019-03-08 15:04:28 +00:00
|
|
|
auto interface = GrGLMakeNativeInterface();
|
2020-10-15 15:13:24 +00:00
|
|
|
// setup context
|
|
|
|
return GrDirectContext::MakeGL(interface);
|
2019-03-08 15:04:28 +00:00
|
|
|
}
|
2018-09-20 21:39:31 +00:00
|
|
|
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrDirectContext> dContext, int width, int height,
|
2020-06-19 15:45:57 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace) {
|
|
|
|
// WebGL should already be clearing the color and stencil buffers, but do it again here to
|
|
|
|
// ensure Skia receives them in the expected state.
|
2021-08-25 17:13:09 +00:00
|
|
|
emscripten_glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
emscripten_glClearColor(0, 0, 0, 0);
|
|
|
|
emscripten_glClearStencil(0);
|
|
|
|
emscripten_glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
dContext->resetContext(kRenderTarget_GrGLBackendState | kMisc_GrGLBackendState);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2020-06-19 15:45:57 +00:00
|
|
|
// The on-screen canvas is FBO 0. Wrap it in a Skia render target so Skia can render to it.
|
2018-09-20 21:39:31 +00:00
|
|
|
GrGLFramebufferInfo info;
|
2020-06-19 15:45:57 +00:00
|
|
|
info.fFBOID = 0;
|
|
|
|
|
|
|
|
GrGLint sampleCnt;
|
2021-08-25 17:13:09 +00:00
|
|
|
emscripten_glGetIntegerv(GL_SAMPLES, &sampleCnt);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2019-11-15 16:02:15 +00:00
|
|
|
GrGLint stencil;
|
2021-08-25 17:13:09 +00:00
|
|
|
emscripten_glGetIntegerv(GL_STENCIL_BITS, &stencil);
|
2019-11-15 16:02:15 +00:00
|
|
|
|
2020-05-26 17:10:20 +00:00
|
|
|
const auto colorSettings = ColorSettings(colorSpace);
|
|
|
|
info.fFormat = colorSettings.pixFormat;
|
2020-06-19 15:45:57 +00:00
|
|
|
GrBackendRenderTarget target(width, height, sampleCnt, stencil, info);
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(dContext.get(), target,
|
2020-05-26 17:10:20 +00:00
|
|
|
kBottomLeft_GrSurfaceOrigin, colorSettings.colorType, colorSpace, nullptr));
|
2018-09-20 21:39:31 +00:00
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, int width, int height) {
|
2019-03-08 15:04:28 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(width, height, SkAlphaType::kPremul_SkAlphaType);
|
2018-11-03 11:51:19 +00:00
|
|
|
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
|
2019-03-08 15:04:28 +00:00
|
|
|
SkBudgeted::kYes,
|
|
|
|
info, 0,
|
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
|
|
|
nullptr, true));
|
|
|
|
return surface;
|
2018-09-20 21:39:31 +00:00
|
|
|
}
|
|
|
|
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, SimpleImageInfo sii) {
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
|
2019-03-08 15:04:28 +00:00
|
|
|
SkBudgeted::kYes,
|
|
|
|
toSkImageInfo(sii), 0,
|
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
|
|
|
nullptr, true));
|
|
|
|
return surface;
|
2018-12-07 15:09:11 +00:00
|
|
|
}
|
2019-03-08 15:04:28 +00:00
|
|
|
#endif
|
2018-12-07 15:09:11 +00:00
|
|
|
|
2018-11-30 19:05:58 +00:00
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
//========================================================================================
|
|
|
|
// Path things
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
// All these Apply* methods are simple wrappers to avoid returning an object.
|
|
|
|
// The default WASM bindings produce code that will leak if a return value
|
|
|
|
// isn't assigned to a JS variable and has delete() called on it.
|
|
|
|
// These Apply methods, combined with the smarter binding code allow for chainable
|
|
|
|
// commands that don't leak if the return value is ignored (i.e. when used intuitively).
|
|
|
|
void ApplyAddPath(SkPath& orig, const SkPath& newPath,
|
|
|
|
SkScalar scaleX, SkScalar skewX, SkScalar transX,
|
|
|
|
SkScalar skewY, SkScalar scaleY, SkScalar transY,
|
2018-11-20 17:51:16 +00:00
|
|
|
SkScalar pers0, SkScalar pers1, SkScalar pers2,
|
|
|
|
bool extendPath) {
|
2018-09-20 21:39:31 +00:00
|
|
|
SkMatrix m = SkMatrix::MakeAll(scaleX, skewX , transX,
|
|
|
|
skewY , scaleY, transY,
|
|
|
|
pers0 , pers1 , pers2);
|
2018-11-20 17:51:16 +00:00
|
|
|
orig.addPath(newPath, m, extendPath ? SkPath::kExtend_AddPathMode :
|
|
|
|
SkPath::kAppend_AddPathMode);
|
2018-09-20 21:39:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 20:46:17 +00:00
|
|
|
void ApplyArcToTangent(SkPath& p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
|
2018-09-20 21:39:31 +00:00
|
|
|
SkScalar radius) {
|
|
|
|
p.arcTo(x1, y1, x2, y2, radius);
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:36:52 +00:00
|
|
|
void ApplyArcToArcSize(SkPath& orig, SkScalar rx, SkScalar ry, SkScalar xAxisRotate,
|
|
|
|
bool useSmallArc, bool ccw, SkScalar x, SkScalar y) {
|
2019-08-26 19:48:09 +00:00
|
|
|
auto arcSize = useSmallArc ? SkPath::ArcSize::kSmall_ArcSize : SkPath::ArcSize::kLarge_ArcSize;
|
2019-11-22 18:34:02 +00:00
|
|
|
auto sweep = ccw ? SkPathDirection::kCCW : SkPathDirection::kCW;
|
2019-08-26 19:48:09 +00:00
|
|
|
orig.arcTo(rx, ry, xAxisRotate, arcSize, sweep, x, y);
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:36:52 +00:00
|
|
|
void ApplyRArcToArcSize(SkPath& orig, SkScalar rx, SkScalar ry, SkScalar xAxisRotate,
|
|
|
|
bool useSmallArc, bool ccw, SkScalar dx, SkScalar dy) {
|
|
|
|
auto arcSize = useSmallArc ? SkPath::ArcSize::kSmall_ArcSize : SkPath::ArcSize::kLarge_ArcSize;
|
2019-11-22 18:34:02 +00:00
|
|
|
auto sweep = ccw ? SkPathDirection::kCCW : SkPathDirection::kCW;
|
2019-11-01 18:36:52 +00:00
|
|
|
orig.rArcTo(rx, ry, xAxisRotate, arcSize, sweep, dx, dy);
|
|
|
|
}
|
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
void ApplyClose(SkPath& p) {
|
|
|
|
p.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplyConicTo(SkPath& p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
|
|
|
|
SkScalar w) {
|
|
|
|
p.conicTo(x1, y1, x2, y2, w);
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:36:52 +00:00
|
|
|
void ApplyRConicTo(SkPath& p, SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2,
|
|
|
|
SkScalar w) {
|
|
|
|
p.rConicTo(dx1, dy1, dx2, dy2, w);
|
|
|
|
}
|
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
void ApplyCubicTo(SkPath& p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
|
|
|
|
SkScalar x3, SkScalar y3) {
|
|
|
|
p.cubicTo(x1, y1, x2, y2, x3, y3);
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:36:52 +00:00
|
|
|
void ApplyRCubicTo(SkPath& p, SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2,
|
|
|
|
SkScalar dx3, SkScalar dy3) {
|
|
|
|
p.rCubicTo(dx1, dy1, dx2, dy2, dx3, dy3);
|
|
|
|
}
|
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
void ApplyLineTo(SkPath& p, SkScalar x, SkScalar y) {
|
|
|
|
p.lineTo(x, y);
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:36:52 +00:00
|
|
|
void ApplyRLineTo(SkPath& p, SkScalar dx, SkScalar dy) {
|
|
|
|
p.rLineTo(dx, dy);
|
|
|
|
}
|
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
void ApplyMoveTo(SkPath& p, SkScalar x, SkScalar y) {
|
|
|
|
p.moveTo(x, y);
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:36:52 +00:00
|
|
|
void ApplyRMoveTo(SkPath& p, SkScalar dx, SkScalar dy) {
|
|
|
|
p.rMoveTo(dx, dy);
|
|
|
|
}
|
|
|
|
|
2019-01-07 16:08:55 +00:00
|
|
|
void ApplyReset(SkPath& p) {
|
|
|
|
p.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplyRewind(SkPath& p) {
|
|
|
|
p.rewind();
|
|
|
|
}
|
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
void ApplyQuadTo(SkPath& p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
|
|
|
|
p.quadTo(x1, y1, x2, y2);
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:36:52 +00:00
|
|
|
void ApplyRQuadTo(SkPath& p, SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2) {
|
|
|
|
p.rQuadTo(dx1, dy1, dx2, dy2);
|
|
|
|
}
|
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
void ApplyTransform(SkPath& orig,
|
|
|
|
SkScalar scaleX, SkScalar skewX, SkScalar transX,
|
|
|
|
SkScalar skewY, SkScalar scaleY, SkScalar transY,
|
|
|
|
SkScalar pers0, SkScalar pers1, SkScalar pers2) {
|
|
|
|
SkMatrix m = SkMatrix::MakeAll(scaleX, skewX , transX,
|
|
|
|
skewY , scaleY, transY,
|
|
|
|
pers0 , pers1 , pers2);
|
|
|
|
orig.transform(m);
|
|
|
|
}
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
#ifdef SK_INCLUDE_PATHOPS
|
|
|
|
bool ApplySimplify(SkPath& path) {
|
2018-11-03 11:51:19 +00:00
|
|
|
return Simplify(path, &path);
|
|
|
|
}
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
bool ApplyPathOp(SkPath& pathOne, const SkPath& pathTwo, SkPathOp op) {
|
2018-11-03 11:51:19 +00:00
|
|
|
return Op(pathOne, pathTwo, op, &pathOne);
|
|
|
|
}
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
SkPathOrNull MakePathFromOp(const SkPath& pathOne, const SkPath& pathTwo, SkPathOp op) {
|
|
|
|
SkPath out;
|
|
|
|
if (Op(pathOne, pathTwo, op, &out)) {
|
|
|
|
return emscripten::val(out);
|
|
|
|
}
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
2021-07-21 14:00:28 +00:00
|
|
|
|
|
|
|
SkPathOrNull MakeAsWinding(const SkPath& self) {
|
|
|
|
SkPath out;
|
|
|
|
if (AsWinding(self, &out)) {
|
|
|
|
return emscripten::val(out);
|
|
|
|
}
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
2020-01-06 13:10:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
JSString ToSVGString(const SkPath& path) {
|
2018-11-03 11:51:19 +00:00
|
|
|
SkString s;
|
|
|
|
SkParsePath::ToSVGString(path, &s);
|
|
|
|
return emscripten::val(s.c_str());
|
|
|
|
}
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
SkPathOrNull MakePathFromSVGString(std::string str) {
|
2018-12-17 21:01:36 +00:00
|
|
|
SkPath path;
|
|
|
|
if (SkParsePath::FromSVGString(str.c_str(), &path)) {
|
|
|
|
return emscripten::val(path);
|
|
|
|
}
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
SkPath CopyPath(const SkPath& a) {
|
2018-09-20 21:39:31 +00:00
|
|
|
SkPath copy(a);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
bool Equals(const SkPath& a, const SkPath& b) {
|
2018-09-20 21:39:31 +00:00
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
2019-01-07 16:08:55 +00:00
|
|
|
// =================================================================================
|
|
|
|
// Creating/Exporting Paths with cmd arrays
|
|
|
|
// =================================================================================
|
|
|
|
|
|
|
|
static const int MOVE = 0;
|
|
|
|
static const int LINE = 1;
|
|
|
|
static const int QUAD = 2;
|
|
|
|
static const int CONIC = 3;
|
|
|
|
static const int CUBIC = 4;
|
|
|
|
static const int CLOSE = 5;
|
|
|
|
|
2021-06-02 14:29:11 +00:00
|
|
|
Float32Array ToCmds(const SkPath& path) {
|
|
|
|
std::vector<SkScalar> cmds;
|
2020-05-04 18:59:49 +00:00
|
|
|
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
|
2019-01-07 16:08:55 +00:00
|
|
|
switch (verb) {
|
2020-05-04 18:59:49 +00:00
|
|
|
case SkPathVerb::kMove:
|
2021-06-02 14:29:11 +00:00
|
|
|
cmds.insert(cmds.end(), {MOVE, pts[0].x(), pts[0].y()});
|
2019-01-07 16:08:55 +00:00
|
|
|
break;
|
2020-05-04 18:59:49 +00:00
|
|
|
case SkPathVerb::kLine:
|
2021-06-02 14:29:11 +00:00
|
|
|
cmds.insert(cmds.end(), {LINE, pts[1].x(), pts[1].y()});
|
2019-01-07 16:08:55 +00:00
|
|
|
break;
|
2020-05-04 18:59:49 +00:00
|
|
|
case SkPathVerb::kQuad:
|
2021-06-02 14:29:11 +00:00
|
|
|
cmds.insert(cmds.end(), {QUAD, pts[1].x(), pts[1].y(), pts[2].x(), pts[2].y()});
|
2019-01-07 16:08:55 +00:00
|
|
|
break;
|
2020-05-04 18:59:49 +00:00
|
|
|
case SkPathVerb::kConic:
|
2021-06-02 14:29:11 +00:00
|
|
|
cmds.insert(cmds.end(), {CONIC,
|
2019-01-07 16:08:55 +00:00
|
|
|
pts[1].x(), pts[1].y(),
|
2021-06-02 14:29:11 +00:00
|
|
|
pts[2].x(), pts[2].y(), *w});
|
2019-01-07 16:08:55 +00:00
|
|
|
break;
|
2020-05-04 18:59:49 +00:00
|
|
|
case SkPathVerb::kCubic:
|
2021-06-02 14:29:11 +00:00
|
|
|
cmds.insert(cmds.end(), {CUBIC,
|
2019-01-07 16:08:55 +00:00
|
|
|
pts[1].x(), pts[1].y(),
|
|
|
|
pts[2].x(), pts[2].y(),
|
2021-06-02 14:29:11 +00:00
|
|
|
pts[3].x(), pts[3].y()});
|
2019-01-07 16:08:55 +00:00
|
|
|
break;
|
2020-05-04 18:59:49 +00:00
|
|
|
case SkPathVerb::kClose:
|
2021-06-02 14:29:11 +00:00
|
|
|
cmds.push_back(CLOSE);
|
2019-01-07 16:08:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-04 18:59:49 +00:00
|
|
|
}
|
2021-06-02 14:29:11 +00:00
|
|
|
return MakeTypedArray(cmds.size(), (const float*)cmds.data());
|
2019-01-07 16:08:55 +00:00
|
|
|
}
|
|
|
|
|
2021-05-26 17:40:22 +00:00
|
|
|
SkPathOrNull MakePathFromCmds(WASMPointerF32 cptr, int numCmds) {
|
2019-01-07 16:08:55 +00:00
|
|
|
const auto* cmds = reinterpret_cast<const float*>(cptr);
|
|
|
|
SkPath path;
|
|
|
|
float x1, y1, x2, y2, x3, y3;
|
|
|
|
|
|
|
|
// if there are not enough arguments, bail with the path we've constructed so far.
|
|
|
|
#define CHECK_NUM_ARGS(n) \
|
|
|
|
if ((i + n) > numCmds) { \
|
|
|
|
SkDebugf("Not enough args to match the verbs. Saw %d commands\n", numCmds); \
|
|
|
|
return emscripten::val::null(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < numCmds;){
|
|
|
|
switch (sk_float_floor2int(cmds[i++])) {
|
|
|
|
case MOVE:
|
|
|
|
CHECK_NUM_ARGS(2);
|
|
|
|
x1 = cmds[i++], y1 = cmds[i++];
|
|
|
|
path.moveTo(x1, y1);
|
|
|
|
break;
|
|
|
|
case LINE:
|
|
|
|
CHECK_NUM_ARGS(2);
|
|
|
|
x1 = cmds[i++], y1 = cmds[i++];
|
|
|
|
path.lineTo(x1, y1);
|
|
|
|
break;
|
|
|
|
case QUAD:
|
|
|
|
CHECK_NUM_ARGS(4);
|
|
|
|
x1 = cmds[i++], y1 = cmds[i++];
|
|
|
|
x2 = cmds[i++], y2 = cmds[i++];
|
|
|
|
path.quadTo(x1, y1, x2, y2);
|
|
|
|
break;
|
|
|
|
case CONIC:
|
|
|
|
CHECK_NUM_ARGS(5);
|
|
|
|
x1 = cmds[i++], y1 = cmds[i++];
|
|
|
|
x2 = cmds[i++], y2 = cmds[i++];
|
|
|
|
x3 = cmds[i++]; // weight
|
|
|
|
path.conicTo(x1, y1, x2, y2, x3);
|
|
|
|
break;
|
|
|
|
case CUBIC:
|
|
|
|
CHECK_NUM_ARGS(6);
|
|
|
|
x1 = cmds[i++], y1 = cmds[i++];
|
|
|
|
x2 = cmds[i++], y2 = cmds[i++];
|
|
|
|
x3 = cmds[i++], y3 = cmds[i++];
|
|
|
|
path.cubicTo(x1, y1, x2, y2, x3, y3);
|
|
|
|
break;
|
|
|
|
case CLOSE:
|
|
|
|
path.close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkDebugf(" path: UNKNOWN command %f, aborting dump...\n", cmds[i-1]);
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK_NUM_ARGS
|
|
|
|
|
|
|
|
return emscripten::val(path);
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:40:22 +00:00
|
|
|
void PathAddVerbsPointsWeights(SkPath& path, WASMPointerU8 verbsPtr, int numVerbs,
|
|
|
|
WASMPointerF32 ptsPtr, int numPts,
|
|
|
|
WASMPointerF32 wtsPtr, int numWts) {
|
2020-06-23 20:58:10 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
#define CHECK_NUM_POINTS(n) \
|
|
|
|
if ((ptIdx + n) > numPts) { \
|
|
|
|
SkDebugf("Not enough points to match the verbs. Saw %d points\n", numPts); \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
#define CHECK_NUM_WEIGHTS(n) \
|
|
|
|
if ((wtIdx + n) > numWts) { \
|
|
|
|
SkDebugf("Not enough weights to match the verbs. Saw %d weights\n", numWts); \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
|
|
|
path.incReserve(numPts);
|
|
|
|
int ptIdx = 0;
|
|
|
|
int wtIdx = 0;
|
|
|
|
for (int v = 0; v < numVerbs; ++v) {
|
|
|
|
switch (verbs[v]) {
|
|
|
|
case MOVE:
|
|
|
|
CHECK_NUM_POINTS(2);
|
|
|
|
path.moveTo(pts[ptIdx], pts[ptIdx+1]);
|
|
|
|
ptIdx += 2;
|
|
|
|
break;
|
|
|
|
case LINE:
|
|
|
|
CHECK_NUM_POINTS(2);
|
|
|
|
path.lineTo(pts[ptIdx], pts[ptIdx+1]);
|
|
|
|
ptIdx += 2;
|
|
|
|
break;
|
|
|
|
case QUAD:
|
|
|
|
CHECK_NUM_POINTS(4);
|
|
|
|
path.quadTo(pts[ptIdx], pts[ptIdx+1], pts[ptIdx+2], pts[ptIdx+3]);
|
|
|
|
ptIdx += 4;
|
|
|
|
break;
|
|
|
|
case CONIC:
|
|
|
|
CHECK_NUM_POINTS(4);
|
|
|
|
CHECK_NUM_WEIGHTS(1);
|
|
|
|
path.conicTo(pts[ptIdx], pts[ptIdx+1], pts[ptIdx+2], pts[ptIdx+3],
|
|
|
|
weights[wtIdx]);
|
|
|
|
ptIdx += 4;
|
|
|
|
wtIdx++;
|
|
|
|
break;
|
|
|
|
case CUBIC:
|
|
|
|
CHECK_NUM_POINTS(6);
|
|
|
|
path.cubicTo(pts[ptIdx ], pts[ptIdx+1],
|
|
|
|
pts[ptIdx+2], pts[ptIdx+3],
|
|
|
|
pts[ptIdx+4], pts[ptIdx+5]);
|
|
|
|
ptIdx += 6;
|
|
|
|
break;
|
|
|
|
case CLOSE:
|
|
|
|
path.close();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef CHECK_NUM_POINTS
|
|
|
|
#undef CHECK_NUM_WEIGHTS
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:40:22 +00:00
|
|
|
SkPath MakePathFromVerbsPointsWeights(WASMPointerU8 verbsPtr, int numVerbs,
|
|
|
|
WASMPointerF32 ptsPtr, int numPts,
|
|
|
|
WASMPointerF32 wtsPtr, int numWts) {
|
2020-06-23 20:58:10 +00:00
|
|
|
SkPath path;
|
|
|
|
PathAddVerbsPointsWeights(path, verbsPtr, numVerbs, ptsPtr, numPts, wtsPtr, numWts);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-11-03 11:51:19 +00:00
|
|
|
//========================================================================================
|
|
|
|
// Path Effects
|
|
|
|
//========================================================================================
|
|
|
|
|
|
|
|
bool ApplyDash(SkPath& path, SkScalar on, SkScalar off, SkScalar phase) {
|
|
|
|
SkScalar intervals[] = { on, off };
|
|
|
|
auto pe = SkDashPathEffect::Make(intervals, 2, phase);
|
|
|
|
if (!pe) {
|
|
|
|
SkDebugf("Invalid args to dash()\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
|
|
|
|
if (pe->filterPath(&path, path, &rec, nullptr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkDebugf("Could not make dashed path\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ApplyTrim(SkPath& path, SkScalar startT, SkScalar stopT, bool isComplement) {
|
|
|
|
auto mode = isComplement ? SkTrimPathEffect::Mode::kInverted : SkTrimPathEffect::Mode::kNormal;
|
|
|
|
auto pe = SkTrimPathEffect::Make(startT, stopT, mode);
|
|
|
|
if (!pe) {
|
|
|
|
SkDebugf("Invalid args to trim(): startT and stopT must be in [0,1]\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SkStrokeRec rec(SkStrokeRec::InitStyle::kHairline_InitStyle);
|
|
|
|
if (pe->filterPath(&path, path, &rec, nullptr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkDebugf("Could not trim path\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct StrokeOpts {
|
2018-11-26 16:47:54 +00:00
|
|
|
// Default values are set in interface.js which allows clients
|
2018-11-03 11:51:19 +00:00
|
|
|
// to set any number of them. Otherwise, the binding code complains if
|
|
|
|
// any are omitted.
|
|
|
|
SkScalar width;
|
|
|
|
SkScalar miter_limit;
|
|
|
|
SkPaint::Join join;
|
|
|
|
SkPaint::Cap cap;
|
2018-12-07 18:03:08 +00:00
|
|
|
float precision;
|
2018-11-03 11:51:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool ApplyStroke(SkPath& path, StrokeOpts opts) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeCap(opts.cap);
|
|
|
|
p.setStrokeJoin(opts.join);
|
|
|
|
p.setStrokeWidth(opts.width);
|
|
|
|
p.setStrokeMiter(opts.miter_limit);
|
|
|
|
|
2018-12-07 18:03:08 +00:00
|
|
|
return p.getFillPath(path, &path, nullptr, opts.precision);
|
2018-11-03 11:51:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 20:46:17 +00:00
|
|
|
// This function is private, we call it in interface.js
|
2021-05-26 17:40:22 +00:00
|
|
|
void computeTonalColors(WASMPointerF32 cPtrAmbi, WASMPointerF32 cPtrSpot) {
|
2020-05-04 20:46:17 +00:00
|
|
|
// 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);
|
|
|
|
SkColor4f ambiColor = { ambiFloats[0], ambiFloats[1], ambiFloats[2], ambiFloats[3]};
|
|
|
|
SkColor4f spotColor = { spotFloats[0], spotFloats[1], spotFloats[2], spotFloats[3]};
|
2019-09-11 19:23:00 +00:00
|
|
|
|
2020-05-04 20:46:17 +00:00
|
|
|
// This function takes SkColor
|
|
|
|
SkColor resultAmbi, resultSpot;
|
2020-03-26 13:27:48 +00:00
|
|
|
SkShadowUtils::ComputeTonalColors(
|
2020-05-04 20:46:17 +00:00
|
|
|
ambiColor.toSkColor(), spotColor.toSkColor(),
|
|
|
|
&resultAmbi, &resultSpot);
|
|
|
|
|
|
|
|
// Convert back to color4f
|
|
|
|
const SkColor4f ambi4f = SkColor4f::FromColor(resultAmbi);
|
|
|
|
const SkColor4f spot4f = SkColor4f::FromColor(resultSpot);
|
|
|
|
|
|
|
|
// Re-use the caller's allocated memory to hold the result.
|
|
|
|
memcpy(ambiFloats, ambi4f.vec(), 4 * sizeof(SkScalar));
|
|
|
|
memcpy(spotFloats, spot4f.vec(), 4 * sizeof(SkScalar));
|
2019-09-11 19:23:00 +00:00
|
|
|
}
|
|
|
|
|
2021-02-03 21:12:09 +00:00
|
|
|
#ifdef SK_INCLUDE_RUNTIME_EFFECT
|
|
|
|
struct RuntimeEffectUniform {
|
|
|
|
int columns;
|
|
|
|
int rows;
|
|
|
|
int slot; // the index into the uniforms array that this uniform begins.
|
2021-04-08 18:51:29 +00:00
|
|
|
bool isInteger;
|
2021-02-03 21:12:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RuntimeEffectUniform fromUniform(const SkRuntimeEffect::Uniform& u) {
|
|
|
|
RuntimeEffectUniform su;
|
2021-04-08 18:51:29 +00:00
|
|
|
su.rows = u.count; // arrayLength
|
|
|
|
su.columns = 1;
|
|
|
|
su.isInteger = false;
|
|
|
|
using Type = SkRuntimeEffect::Uniform::Type;
|
2021-02-03 21:12:09 +00:00
|
|
|
switch (u.type) {
|
2021-04-08 18:51:29 +00:00
|
|
|
case Type::kFloat: break;
|
|
|
|
case Type::kFloat2: su.columns = 2; break;
|
|
|
|
case Type::kFloat3: su.columns = 3; break;
|
|
|
|
case Type::kFloat4: su.columns = 4; break;
|
|
|
|
case Type::kFloat2x2: su.columns = 2; su.rows *= 2; break;
|
|
|
|
case Type::kFloat3x3: su.columns = 3; su.rows *= 3; break;
|
|
|
|
case Type::kFloat4x4: su.columns = 4; su.rows *= 4; break;
|
|
|
|
case Type::kInt: su.isInteger = true; break;
|
|
|
|
case Type::kInt2: su.columns = 2; su.isInteger = true; break;
|
|
|
|
case Type::kInt3: su.columns = 3; su.isInteger = true; break;
|
|
|
|
case Type::kInt4: su.columns = 4; su.isInteger = true; break;
|
2021-02-03 21:12:09 +00:00
|
|
|
}
|
|
|
|
su.slot = u.offset / sizeof(float);
|
|
|
|
return su;
|
|
|
|
}
|
2021-04-08 18:51:29 +00:00
|
|
|
|
|
|
|
void castUniforms(void* data, size_t dataLen, const SkRuntimeEffect& effect) {
|
|
|
|
if (dataLen != effect.uniformSize()) {
|
|
|
|
// Incorrect number of uniforms. Our code below could read/write off the end of the buffer.
|
|
|
|
// However, shader creation is going to fail anyway, so just do nothing.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float* fltData = reinterpret_cast<float*>(data);
|
|
|
|
for (const auto& u : effect.uniforms()) {
|
|
|
|
RuntimeEffectUniform reu = fromUniform(u);
|
|
|
|
if (reu.isInteger) {
|
|
|
|
// The SkSL is expecting integers in the uniform data
|
|
|
|
for (int i = 0; i < reu.columns * reu.rows; ++i) {
|
|
|
|
int numAsInt = static_cast<int>(fltData[reu.slot + i]);
|
|
|
|
fltData[reu.slot + i] = SkBits2Float(numAsInt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-03 21:12:09 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-03 16:59:06 +00:00
|
|
|
// These objects have private destructors / delete methods - I don't think
|
2018-11-03 11:51:19 +00:00
|
|
|
// we need to do anything other than tell emscripten to do nothing.
|
2018-09-20 21:39:31 +00:00
|
|
|
namespace emscripten {
|
|
|
|
namespace internal {
|
|
|
|
template<typename ClassType>
|
2021-11-11 16:20:49 +00:00
|
|
|
void raw_destructor(ClassType*);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2019-11-20 19:17:53 +00:00
|
|
|
template<>
|
2021-11-11 16:20:49 +00:00
|
|
|
void raw_destructor<SkContourMeasure>(SkContourMeasure* ptr) {
|
2019-11-20 19:17:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:35:13 +00:00
|
|
|
template<>
|
2021-11-11 16:20:49 +00:00
|
|
|
void raw_destructor<SkVertices>(SkVertices* ptr) {
|
2018-12-12 15:35:13 +00:00
|
|
|
}
|
|
|
|
|
2019-09-26 17:20:50 +00:00
|
|
|
#ifndef SK_NO_FONTS
|
2018-11-03 11:51:19 +00:00
|
|
|
template<>
|
2021-11-11 16:20:49 +00:00
|
|
|
void raw_destructor<SkTextBlob>(SkTextBlob* ptr) {
|
2018-11-03 11:51:19 +00:00
|
|
|
}
|
2019-01-14 13:36:08 +00:00
|
|
|
|
|
|
|
template<>
|
2021-11-11 16:20:49 +00:00
|
|
|
void raw_destructor<SkTypeface>(SkTypeface* ptr) {
|
2019-01-14 13:36:08 +00:00
|
|
|
}
|
2019-09-26 17:20:50 +00:00
|
|
|
#endif
|
2018-09-20 21:39:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 20:38:42 +00:00
|
|
|
// toBytes returns a Uint8Array that has a copy of the data in the given SkData.
|
|
|
|
Uint8Array toBytes(sk_sp<SkData> data) {
|
|
|
|
// By making the copy using the JS transliteration, we don't risk the SkData object being
|
|
|
|
// cleaned up before we make the copy.
|
|
|
|
return emscripten::val(
|
|
|
|
// https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-views
|
|
|
|
typed_memory_view(data->size(), data->bytes())
|
|
|
|
).call<Uint8Array>("slice"); // slice with no args makes a copy of the memory view.
|
|
|
|
}
|
|
|
|
|
2021-11-11 16:20:49 +00:00
|
|
|
#ifdef SK_GL
|
2021-06-03 12:02:03 +00:00
|
|
|
// We need to call into the JS side of things to free webGL contexts. This object will be called
|
|
|
|
// with _setTextureCleanup after CanvasKit loads. The object will have one attribute,
|
|
|
|
// a function called deleteTexture that takes two ints.
|
|
|
|
JSObject textureCleanup = emscripten::val::null();
|
|
|
|
|
|
|
|
struct TextureReleaseContext {
|
2021-11-10 12:52:05 +00:00
|
|
|
// This refers to which webgl context, i.e. which surface, owns the texture. We need this
|
|
|
|
// to route the deleteTexture to the right context.
|
2021-06-03 12:02:03 +00:00
|
|
|
uint32_t webglHandle;
|
2021-11-10 12:52:05 +00:00
|
|
|
// This refers to the index of the texture in the complete list of textures.
|
2021-06-03 12:02:03 +00:00
|
|
|
uint32_t texHandle;
|
|
|
|
};
|
|
|
|
|
|
|
|
void deleteJSTexture(SkImage::ReleaseContext rc) {
|
|
|
|
auto ctx = reinterpret_cast<TextureReleaseContext*>(rc);
|
|
|
|
textureCleanup.call<void>("deleteTexture", ctx->webglHandle, ctx->texHandle);
|
|
|
|
delete ctx;
|
|
|
|
}
|
|
|
|
|
2021-11-11 16:20:49 +00:00
|
|
|
class WebGLTextureImageGenerator : public SkImageGenerator {
|
|
|
|
public:
|
2021-11-12 14:09:34 +00:00
|
|
|
WebGLTextureImageGenerator(SkImageInfo ii, JSObject callbackObj):
|
|
|
|
SkImageGenerator(ii),
|
2021-11-11 16:20:49 +00:00
|
|
|
fCallback(callbackObj) {}
|
|
|
|
|
|
|
|
~WebGLTextureImageGenerator() {
|
2021-11-12 14:09:34 +00:00
|
|
|
// This cleans up the associated TextureSource that is used to make the texture
|
2021-11-11 16:20:49 +00:00
|
|
|
// (i.e. "makeTexture" below). We expect this destructor to be called when the
|
|
|
|
// SkImage that this Generator belongs to is destroyed.
|
|
|
|
fCallback.call<void>("freeSrc");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
GrSurfaceProxyView onGenerateTexture(GrRecordingContext* ctx,
|
|
|
|
const SkImageInfo& info,
|
|
|
|
const SkIPoint& origin,
|
|
|
|
GrMipmapped mipMapped,
|
|
|
|
GrImageTexGenPolicy texGenPolicy) {
|
|
|
|
if (ctx->backend() != GrBackendApi::kOpenGL) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
GrGLTextureInfo glInfo;
|
|
|
|
glInfo.fID = fCallback.call<uint32_t>("makeTexture");
|
|
|
|
// The format and target should match how we make the texture on the JS side
|
|
|
|
// See the implementation of the makeTexture function.
|
|
|
|
glInfo.fFormat = GR_GL_RGBA8;
|
|
|
|
glInfo.fTarget = GR_GL_TEXTURE_2D;
|
|
|
|
|
|
|
|
static constexpr auto kMipmapped = GrMipmapped::kNo;
|
|
|
|
GrBackendTexture backendTexture(info.width(), info.height(), kMipmapped, glInfo);
|
|
|
|
|
|
|
|
const GrBackendFormat& format = backendTexture.getBackendFormat();
|
|
|
|
const GrColorType colorType = SkColorTypeToGrColorType(info.colorType());
|
|
|
|
if (!ctx->priv().caps()->areColorTypeAndFormatCompatible(colorType, format)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t webGLCtx = emscripten_webgl_get_current_context();
|
|
|
|
auto releaseCtx = new TextureReleaseContext{webGLCtx, glInfo.fID};
|
|
|
|
auto cleanupCallback = GrRefCntedCallback::Make(deleteJSTexture, releaseCtx);
|
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> proxy = ctx->priv().proxyProvider()->wrapBackendTexture(
|
|
|
|
backendTexture,
|
|
|
|
kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kYes,
|
|
|
|
kRead_GrIOType,
|
|
|
|
std::move(cleanupCallback));
|
|
|
|
if (!proxy) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
static constexpr auto kOrigin = kTopLeft_GrSurfaceOrigin;
|
|
|
|
GrSwizzle swizzle = ctx->priv().caps()->getReadSwizzle(format, colorType);
|
|
|
|
return GrSurfaceProxyView(std::move(proxy), kOrigin, swizzle);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSObject fCallback;
|
|
|
|
};
|
|
|
|
|
|
|
|
// callbackObj has two functions in it, one to create a texture "makeTexture" and one to clean up
|
|
|
|
// the underlying texture source "freeSrc". This way, we can create WebGL textures for each
|
|
|
|
// surface/WebGLContext that the image is used on (we cannot share WebGLTextures across contexts).
|
2021-11-12 14:09:34 +00:00
|
|
|
sk_sp<SkImage> MakeImageFromGenerator(SimpleImageInfo ii, JSObject callbackObj) {
|
|
|
|
auto gen = std::make_unique<WebGLTextureImageGenerator>(toSkImageInfo(ii), callbackObj);
|
2021-11-11 16:20:49 +00:00
|
|
|
return SkImage::MakeFromGenerator(std::move(gen));
|
|
|
|
}
|
|
|
|
#endif // SK_GL
|
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
EMSCRIPTEN_BINDINGS(Skia) {
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2021-08-25 17:13:09 +00:00
|
|
|
function("_MakeGrContext", &MakeGrContext);
|
|
|
|
function("_MakeOnScreenGLSurface", &MakeOnScreenGLSurface);
|
|
|
|
function("_MakeRenderTargetWH", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, int, int)>(&MakeRenderTarget));
|
|
|
|
function("_MakeRenderTargetII", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, SimpleImageInfo)>(&MakeRenderTarget));
|
2019-03-08 15:04:28 +00:00
|
|
|
|
2018-10-16 14:15:01 +00:00
|
|
|
constant("gpu", true);
|
2018-11-20 19:07:42 +00:00
|
|
|
#endif
|
2019-11-25 18:45:28 +00:00
|
|
|
function("getDecodeCacheLimitBytes", &SkResourceCache::GetTotalByteLimit);
|
|
|
|
function("setDecodeCacheLimitBytes", &SkResourceCache::SetTotalByteLimit);
|
|
|
|
function("getDecodeCacheUsedBytes" , &SkResourceCache::GetTotalBytesUsed);
|
|
|
|
|
2020-05-04 20:46:17 +00:00
|
|
|
function("_computeTonalColors", &computeTonalColors);
|
2021-05-26 17:40:22 +00:00
|
|
|
function("_decodeAnimatedImage", optional_override([](WASMPointerU8 iptr,
|
2019-09-18 20:18:17 +00:00
|
|
|
size_t length)->sk_sp<SkAnimatedImage> {
|
|
|
|
uint8_t* imgData = reinterpret_cast<uint8_t*>(iptr);
|
2020-12-03 19:17:31 +00:00
|
|
|
auto bytes = SkData::MakeFromMalloc(imgData, length);
|
2020-12-15 20:52:39 +00:00
|
|
|
auto aCodec = SkAndroidCodec::MakeFromData(std::move(bytes));
|
2020-12-03 19:17:31 +00:00
|
|
|
if (nullptr == aCodec) {
|
2019-09-18 20:18:17 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-12-03 19:17:31 +00:00
|
|
|
|
|
|
|
return SkAnimatedImage::Make(std::move(aCodec));
|
2019-09-18 20:18:17 +00:00
|
|
|
}), allow_raw_pointers());
|
2021-05-26 17:40:22 +00:00
|
|
|
function("_decodeImage", optional_override([](WASMPointerU8 iptr,
|
2018-12-03 17:31:04 +00:00
|
|
|
size_t length)->sk_sp<SkImage> {
|
|
|
|
uint8_t* imgData = reinterpret_cast<uint8_t*>(iptr);
|
2019-02-28 21:05:09 +00:00
|
|
|
sk_sp<SkData> bytes = SkData::MakeFromMalloc(imgData, length);
|
|
|
|
return SkImage::MakeFromEncoded(std::move(bytes));
|
2018-12-03 17:31:04 +00:00
|
|
|
}), allow_raw_pointers());
|
2018-11-20 19:07:42 +00:00
|
|
|
|
2020-03-18 13:53:55 +00:00
|
|
|
// These won't be called directly, there are corresponding JS helpers to deal with arrays.
|
2018-12-04 18:57:36 +00:00
|
|
|
function("_MakeImage", optional_override([](SimpleImageInfo ii,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU8 pPtr, int plen,
|
2018-12-04 18:57:36 +00:00
|
|
|
size_t rowBytes)->sk_sp<SkImage> {
|
|
|
|
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
|
|
|
|
SkImageInfo info = toSkImageInfo(ii);
|
|
|
|
sk_sp<SkData> pixelData = SkData::MakeFromMalloc(pixels, plen);
|
|
|
|
|
|
|
|
return SkImage::MakeRasterData(info, pixelData, rowBytes);
|
|
|
|
}), allow_raw_pointers());
|
2020-06-11 12:44:20 +00:00
|
|
|
|
2021-01-13 19:16:58 +00:00
|
|
|
function("_getShadowLocalBounds", optional_override([](
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 ctmPtr, const SkPath& path,
|
|
|
|
WASMPointerF32 zPlaneParamPtr, WASMPointerF32 lightPosPtr,
|
|
|
|
SkScalar lightRadius, uint32_t flags, WASMPointerF32 outPtr) -> bool {
|
2021-01-21 16:11:59 +00:00
|
|
|
SkMatrix ctm;
|
|
|
|
const SkScalar* nineMatrixValues = reinterpret_cast<const SkScalar*>(ctmPtr);
|
|
|
|
ctm.set9(nineMatrixValues);
|
2021-02-02 13:26:48 +00:00
|
|
|
const SkVector3* zPlaneParams = reinterpret_cast<const SkVector3*>(zPlaneParamPtr);
|
|
|
|
const SkVector3* lightPos = reinterpret_cast<const SkVector3*>(lightPosPtr);
|
2021-01-13 19:16:58 +00:00
|
|
|
SkRect* outputBounds = reinterpret_cast<SkRect*>(outPtr);
|
2021-02-02 13:26:48 +00:00
|
|
|
return SkShadowUtils::GetLocalBounds(ctm, path, *zPlaneParams, *lightPos, lightRadius,
|
2021-01-13 19:16:58 +00:00
|
|
|
flags, outputBounds);
|
|
|
|
}));
|
|
|
|
|
2020-01-14 13:39:09 +00:00
|
|
|
#ifdef SK_SERIALIZE_SKP
|
2021-05-26 17:40:22 +00:00
|
|
|
function("_MakePicture", optional_override([](WASMPointerU8 dPtr,
|
|
|
|
size_t bytes)->sk_sp<SkPicture> {
|
2020-01-14 13:39:09 +00:00
|
|
|
uint8_t* d = reinterpret_cast<uint8_t*>(dPtr);
|
|
|
|
sk_sp<SkData> data = SkData::MakeFromMalloc(d, bytes);
|
|
|
|
|
|
|
|
return SkPicture::MakeFromData(data.get(), nullptr);
|
|
|
|
}), allow_raw_pointers());
|
|
|
|
#endif
|
2018-11-29 20:07:02 +00:00
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2020-10-15 15:13:24 +00:00
|
|
|
class_<GrDirectContext>("GrDirectContext")
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
.smart_ptr<sk_sp<GrDirectContext>>("sk_sp<GrDirectContext>")
|
|
|
|
.function("getResourceCacheLimitBytes",
|
|
|
|
optional_override([](GrDirectContext& self)->size_t {
|
2019-03-22 19:41:36 +00:00
|
|
|
int maxResources = 0;// ignored
|
|
|
|
size_t currMax = 0;
|
|
|
|
self.getResourceCacheLimits(&maxResources, &currMax);
|
|
|
|
return currMax;
|
|
|
|
}))
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
.function("getResourceCacheUsageBytes",
|
|
|
|
optional_override([](GrDirectContext& self)->size_t {
|
2019-03-22 19:41:36 +00:00
|
|
|
int usedResources = 0;// ignored
|
|
|
|
size_t currUsage = 0;
|
|
|
|
self.getResourceCacheUsage(&usedResources, &currUsage);
|
|
|
|
return currUsage;
|
|
|
|
}))
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
.function("releaseResourcesAndAbandonContext",
|
|
|
|
&GrDirectContext::releaseResourcesAndAbandonContext)
|
|
|
|
.function("setResourceCacheLimitBytes",
|
|
|
|
optional_override([](GrDirectContext& self, size_t maxResourceBytes)->void {
|
2019-03-22 19:41:36 +00:00
|
|
|
int maxResources = 0;
|
|
|
|
size_t currMax = 0; // ignored
|
|
|
|
self.getResourceCacheLimits(&maxResources, &currMax);
|
|
|
|
self.setResourceCacheLimits(maxResources, maxResourceBytes);
|
|
|
|
}));
|
2021-06-03 12:02:03 +00:00
|
|
|
|
|
|
|
// This allows us to give the C++ code a JS callback to delete textures that
|
|
|
|
// have been passed in via makeImageFromTexture and makeImageFromTextureSource.
|
|
|
|
function("_setTextureCleanup", optional_override([](JSObject callbackObj)->void {
|
|
|
|
textureCleanup = callbackObj;
|
|
|
|
}));
|
2019-03-08 15:04:28 +00:00
|
|
|
#endif
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkAnimatedImage>("AnimatedImage")
|
|
|
|
.smart_ptr<sk_sp<SkAnimatedImage>>("sk_sp<AnimatedImage>")
|
2019-11-08 14:55:15 +00:00
|
|
|
.function("decodeNextFrame", &SkAnimatedImage::decodeNextFrame)
|
|
|
|
.function("getFrameCount", &SkAnimatedImage::getFrameCount)
|
2019-09-18 20:18:17 +00:00
|
|
|
.function("getRepetitionCount", &SkAnimatedImage::getRepetitionCount)
|
2019-11-08 14:55:15 +00:00
|
|
|
.function("height", optional_override([](SkAnimatedImage& self)->int32_t {
|
2020-11-05 14:47:51 +00:00
|
|
|
// getBounds returns an SkRect, but internally, the width and height are ints.
|
|
|
|
return SkScalarFloorToInt(self.getBounds().height());
|
2019-11-08 14:55:15 +00:00
|
|
|
}))
|
2020-09-15 13:22:36 +00:00
|
|
|
.function("makeImageAtCurrentFrame", &SkAnimatedImage::getCurrentFrame)
|
2019-11-08 14:55:15 +00:00
|
|
|
.function("reset", &SkAnimatedImage::reset)
|
|
|
|
.function("width", optional_override([](SkAnimatedImage& self)->int32_t {
|
2020-11-05 14:47:51 +00:00
|
|
|
return SkScalarFloorToInt(self.getBounds().width());
|
2019-11-08 14:55:15 +00:00
|
|
|
}));
|
2019-09-18 20:18:17 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkCanvas>("Canvas")
|
2018-09-20 21:39:31 +00:00
|
|
|
.constructor<>()
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_clear", optional_override([](SkCanvas& self, WASMPointerF32 cPtr) {
|
2020-06-03 15:19:49 +00:00
|
|
|
self.clear(ptrToSkColor4f(cPtr));
|
2020-03-26 13:27:48 +00:00
|
|
|
}))
|
2018-11-29 20:07:02 +00:00
|
|
|
.function("clipPath", select_overload<void (const SkPath&, SkClipOp, bool)>(&SkCanvas::clipPath))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_clipRRect", optional_override([](SkCanvas& self, WASMPointerF32 fPtr, SkClipOp op, bool doAntiAlias) {
|
2020-09-03 11:57:12 +00:00
|
|
|
self.clipRRect(ptrToSkRRect(fPtr), op, doAntiAlias);
|
2019-10-22 13:43:34 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_clipRect", optional_override([](SkCanvas& self, WASMPointerF32 fPtr, SkClipOp op, bool doAntiAlias) {
|
2020-09-03 14:02:10 +00:00
|
|
|
const SkRect* rect = reinterpret_cast<const SkRect*>(fPtr);
|
|
|
|
self.clipRect(*rect, op, doAntiAlias);
|
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_concat", optional_override([](SkCanvas& self, WASMPointerF32 mPtr) {
|
2020-04-06 17:52:15 +00:00
|
|
|
//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);
|
2018-12-04 18:57:36 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawArc", optional_override([](SkCanvas& self, WASMPointerF32 fPtr,
|
2020-09-03 14:02:10 +00:00
|
|
|
SkScalar startAngle, SkScalar sweepAngle,
|
|
|
|
bool useCenter, const SkPaint& paint) {
|
|
|
|
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
|
|
|
|
self.drawArc(*oval, startAngle, sweepAngle, useCenter, paint);
|
|
|
|
}))
|
2021-03-25 17:13:23 +00:00
|
|
|
.function("_drawAtlasOptions", optional_override([](SkCanvas& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
const sk_sp<SkImage>& atlas, WASMPointerF32 xptr,
|
|
|
|
WASMPointerF32 rptr, WASMPointerU32 cptr, int count,
|
2021-03-25 17:13:23 +00:00
|
|
|
SkBlendMode mode, SkFilterMode filter, SkMipmapMode mipmap,
|
|
|
|
const SkPaint* paint)->void {
|
2019-03-29 14:39:52 +00:00
|
|
|
const SkRSXform* dstXforms = reinterpret_cast<const SkRSXform*>(xptr);
|
|
|
|
const SkRect* srcRects = reinterpret_cast<const SkRect*>(rptr);
|
|
|
|
const SkColor* colors = nullptr;
|
|
|
|
if (cptr) {
|
|
|
|
colors = reinterpret_cast<const SkColor*>(cptr);
|
|
|
|
}
|
2021-03-25 17:13:23 +00:00
|
|
|
SkSamplingOptions sampling(filter, mipmap);
|
|
|
|
self.drawAtlas(atlas.get(), dstXforms, srcRects, colors, count, mode, sampling,
|
|
|
|
nullptr, paint);
|
|
|
|
}), allow_raw_pointers())
|
|
|
|
.function("_drawAtlasCubic", optional_override([](SkCanvas& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
const sk_sp<SkImage>& atlas, WASMPointerF32 xptr,
|
|
|
|
WASMPointerF32 rptr, WASMPointerU32 cptr, int count,
|
2021-03-25 17:13:23 +00:00
|
|
|
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);
|
|
|
|
const SkColor* colors = nullptr;
|
|
|
|
if (cptr) {
|
|
|
|
colors = reinterpret_cast<const SkColor*>(cptr);
|
|
|
|
}
|
|
|
|
SkSamplingOptions sampling({B, C});
|
2021-01-25 16:37:10 +00:00
|
|
|
self.drawAtlas(atlas.get(), dstXforms, srcRects, colors, count, mode, sampling,
|
|
|
|
nullptr, paint);
|
2019-03-29 14:39:52 +00:00
|
|
|
}), allow_raw_pointers())
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawCircle", select_overload<void (SkScalar, SkScalar, SkScalar, const SkPaint& paint)>(&SkCanvas::drawCircle))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawColor", optional_override([](SkCanvas& self, WASMPointerF32 cPtr) {
|
2020-06-03 15:19:49 +00:00
|
|
|
self.drawColor(ptrToSkColor4f(cPtr));
|
2020-03-26 13:27:48 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawColor", optional_override([](SkCanvas& self, WASMPointerF32 cPtr, SkBlendMode mode) {
|
2020-06-03 15:19:49 +00:00
|
|
|
self.drawColor(ptrToSkColor4f(cPtr), mode);
|
2020-03-26 13:27:48 +00:00
|
|
|
}))
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawColorInt", optional_override([](SkCanvas& self, SkColor color, SkBlendMode mode) {
|
2020-06-02 20:15:23 +00:00
|
|
|
self.drawColor(color, mode);
|
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawDRRect", optional_override([](SkCanvas& self, WASMPointerF32 outerPtr,
|
|
|
|
WASMPointerF32 innerPtr, const SkPaint& paint) {
|
2020-09-03 11:57:12 +00:00
|
|
|
self.drawDRRect(ptrToSkRRect(outerPtr), ptrToSkRRect(innerPtr), paint);
|
2019-09-03 16:59:06 +00:00
|
|
|
}))
|
2021-04-14 18:49:35 +00:00
|
|
|
.function("_drawGlyphs", optional_override([](SkCanvas& self,
|
|
|
|
int count,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU16 glyphs,
|
|
|
|
WASMPointerF32 positions,
|
2021-04-14 18:49:35 +00:00
|
|
|
float x, float y,
|
|
|
|
const SkFont& font,
|
|
|
|
const SkPaint& paint)->void {
|
|
|
|
self.drawGlyphs(count,
|
|
|
|
reinterpret_cast<const uint16_t*>(glyphs),
|
|
|
|
reinterpret_cast<const SkPoint*>(positions),
|
|
|
|
{x, y}, font, paint);
|
|
|
|
}))
|
2021-01-29 17:27:49 +00:00
|
|
|
// TODO: deprecate this version, and require sampling
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawImage", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
|
2021-01-29 17:27:49 +00:00
|
|
|
SkScalar x, SkScalar y, const SkPaint* paint) {
|
2021-07-12 20:23:04 +00:00
|
|
|
self.drawImage(image.get(), x, y, SkSamplingOptions(), paint);
|
2021-01-29 17:27:49 +00:00
|
|
|
}), allow_raw_pointers())
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawImageCubic", optional_override([](SkCanvas& self, const sk_sp<SkImage>& img,
|
2020-12-16 21:00:55 +00:00
|
|
|
SkScalar left, SkScalar top,
|
|
|
|
float B, float C, // See SkSamplingOptions.h for docs.
|
|
|
|
const SkPaint* paint)->void {
|
|
|
|
self.drawImage(img.get(), left, top, SkSamplingOptions({B, C}), paint);
|
|
|
|
}), allow_raw_pointers())
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawImageOptions", optional_override([](SkCanvas& self, const sk_sp<SkImage>& img,
|
2020-12-16 21:00:55 +00:00
|
|
|
SkScalar left, SkScalar top,
|
|
|
|
SkFilterMode filter, SkMipmapMode mipmap,
|
|
|
|
const SkPaint* paint)->void {
|
|
|
|
self.drawImage(img.get(), left, top, {filter, mipmap}, paint);
|
|
|
|
}), allow_raw_pointers())
|
|
|
|
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_drawImageNine", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU32 centerPtr, WASMPointerF32 dstPtr,
|
2020-12-17 14:58:32 +00:00
|
|
|
SkFilterMode filter, const SkPaint* paint)->void {
|
2020-09-03 14:02:10 +00:00
|
|
|
const SkIRect* center = reinterpret_cast<const SkIRect*>(centerPtr);
|
|
|
|
const SkRect* dst = reinterpret_cast<const SkRect*>(dstPtr);
|
|
|
|
|
2020-12-17 14:58:32 +00:00
|
|
|
self.drawImageNine(image.get(), *center, *dst, filter, paint);
|
2019-11-11 15:06:08 +00:00
|
|
|
}), allow_raw_pointers())
|
2021-01-29 17:27:49 +00:00
|
|
|
// TODO: deprecate this version, and require sampling
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_drawImageRect", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 srcPtr, WASMPointerF32 dstPtr,
|
2020-09-03 14:02:10 +00:00
|
|
|
const SkPaint* paint, bool fastSample)->void {
|
|
|
|
const SkRect* src = reinterpret_cast<const SkRect*>(srcPtr);
|
|
|
|
const SkRect* dst = reinterpret_cast<const SkRect*>(dstPtr);
|
2021-07-12 20:23:04 +00:00
|
|
|
self.drawImageRect(image, *src, *dst, SkSamplingOptions(), paint,
|
2020-09-03 14:02:10 +00:00
|
|
|
fastSample ? SkCanvas::kFast_SrcRectConstraint:
|
2018-12-03 17:31:04 +00:00
|
|
|
SkCanvas::kStrict_SrcRectConstraint);
|
|
|
|
}), allow_raw_pointers())
|
2020-12-16 21:00:55 +00:00
|
|
|
.function("_drawImageRectCubic", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 srcPtr, WASMPointerF32 dstPtr,
|
2020-12-16 21:00:55 +00:00
|
|
|
float B, float C, // See SkSamplingOptions.h for docs.
|
|
|
|
const SkPaint* paint)->void {
|
|
|
|
const SkRect* src = reinterpret_cast<const SkRect*>(srcPtr);
|
|
|
|
const SkRect* dst = reinterpret_cast<const SkRect*>(dstPtr);
|
Reland "Add new virts, hide old ones"
This reverts commit 8f924ac0ce63806886b7297e8be554984a6e7ce5.
Reason for revert: suppressions landed for fuchsia images to rebaseline
Original change's description:
> Revert "Add new virts, hide old ones"
>
> This reverts commit c56e2e5aa65dd129e5927224d2f6c1f82edff74e.
>
> Reason for revert: suspected of breaking chrome roll
>
> Original change's description:
> > Add new virts, hide old ones
> >
> > Add virtuals for the draw methods that now take sampling/filtermode.
> >
> > drawImage
> > drawImageRect
> > drawImageLattice
> > drawAtlas
> >
> > Add a flag that can remove the older virtuals, once each client has
> > stopped overriding them. In that situation, the older public methods
> > will simplify extract the sampling from the paint, and call the new
> > public methods.
> >
> > Bug: skia:11105, skia:7650
> > Change-Id: I8b0029727295caa983e8148fc743a55cfbecd043
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347022
> > Commit-Queue: Mike Reed <reed@google.com>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,fmalita@chromium.org,reed@google.com
>
> Change-Id: I0a90952c11a180d918126ea06a630f4a0bf9b49b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:11105
> Bug: skia:7650
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348194
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Derek Sollenberger <djsollen@google.com>
TBR=djsollen@google.com,bsalomon@google.com,fmalita@chromium.org,reed@google.com
# Not skipping CQ checks because this is a reland.
Bug: skia:11105
Bug: skia:7650
Change-Id: Ia2b4537a2d330460b7554278d2c05075cf27162a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348876
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-12-30 14:22:42 +00:00
|
|
|
auto constraint = SkCanvas::kStrict_SrcRectConstraint; // TODO: get from caller
|
|
|
|
self.drawImageRect(image.get(), *src, *dst, SkSamplingOptions({B, C}), paint, constraint);
|
2020-12-16 21:00:55 +00:00
|
|
|
}), allow_raw_pointers())
|
|
|
|
.function("_drawImageRectOptions", optional_override([](SkCanvas& self, const sk_sp<SkImage>& image,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 srcPtr, WASMPointerF32 dstPtr,
|
2020-12-16 21:00:55 +00:00
|
|
|
SkFilterMode filter, SkMipmapMode mipmap,
|
|
|
|
const SkPaint* paint)->void {
|
|
|
|
const SkRect* src = reinterpret_cast<const SkRect*>(srcPtr);
|
|
|
|
const SkRect* dst = reinterpret_cast<const SkRect*>(dstPtr);
|
Reland "Add new virts, hide old ones"
This reverts commit 8f924ac0ce63806886b7297e8be554984a6e7ce5.
Reason for revert: suppressions landed for fuchsia images to rebaseline
Original change's description:
> Revert "Add new virts, hide old ones"
>
> This reverts commit c56e2e5aa65dd129e5927224d2f6c1f82edff74e.
>
> Reason for revert: suspected of breaking chrome roll
>
> Original change's description:
> > Add new virts, hide old ones
> >
> > Add virtuals for the draw methods that now take sampling/filtermode.
> >
> > drawImage
> > drawImageRect
> > drawImageLattice
> > drawAtlas
> >
> > Add a flag that can remove the older virtuals, once each client has
> > stopped overriding them. In that situation, the older public methods
> > will simplify extract the sampling from the paint, and call the new
> > public methods.
> >
> > Bug: skia:11105, skia:7650
> > Change-Id: I8b0029727295caa983e8148fc743a55cfbecd043
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347022
> > Commit-Queue: Mike Reed <reed@google.com>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,fmalita@chromium.org,reed@google.com
>
> Change-Id: I0a90952c11a180d918126ea06a630f4a0bf9b49b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:11105
> Bug: skia:7650
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348194
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Derek Sollenberger <djsollen@google.com>
TBR=djsollen@google.com,bsalomon@google.com,fmalita@chromium.org,reed@google.com
# Not skipping CQ checks because this is a reland.
Bug: skia:11105
Bug: skia:7650
Change-Id: Ia2b4537a2d330460b7554278d2c05075cf27162a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348876
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-12-30 14:22:42 +00:00
|
|
|
auto constraint = SkCanvas::kStrict_SrcRectConstraint; // TODO: get from caller
|
|
|
|
self.drawImageRect(image.get(), *src, *dst, {filter, mipmap}, paint, constraint);
|
2020-12-16 21:00:55 +00:00
|
|
|
}), allow_raw_pointers())
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawLine", select_overload<void (SkScalar, SkScalar, SkScalar, SkScalar, const SkPaint&)>(&SkCanvas::drawLine))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawOval", optional_override([](SkCanvas& self, WASMPointerF32 fPtr,
|
2020-09-09 15:23:19 +00:00
|
|
|
const SkPaint& paint)->void {
|
2020-09-03 14:02:10 +00:00
|
|
|
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
|
|
|
|
self.drawOval(*oval, paint);
|
|
|
|
}))
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawPaint", &SkCanvas::drawPaint)
|
2019-10-03 15:22:08 +00:00
|
|
|
#ifdef SK_INCLUDE_PARAGRAPH
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawParagraph", optional_override([](SkCanvas& self, skia::textlayout::Paragraph* p,
|
2020-09-03 14:02:10 +00:00
|
|
|
SkScalar x, SkScalar y) {
|
2019-10-03 15:22:08 +00:00
|
|
|
p->paint(&self, x, y);
|
|
|
|
}), allow_raw_pointers())
|
|
|
|
#endif
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawPath", &SkCanvas::drawPath)
|
2021-03-29 20:38:01 +00:00
|
|
|
.function("_drawPatch", optional_override([](SkCanvas& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 cubics,
|
|
|
|
WASMPointerU32 colors,
|
|
|
|
WASMPointerF32 texs,
|
2021-03-29 20:38:01 +00:00
|
|
|
SkBlendMode mode,
|
|
|
|
const SkPaint& paint)->void {
|
|
|
|
self.drawPatch(reinterpret_cast<const SkPoint*>(cubics),
|
|
|
|
reinterpret_cast<const SkColor*>(colors),
|
|
|
|
reinterpret_cast<const SkPoint*>(texs),
|
|
|
|
mode, paint);
|
|
|
|
}))
|
2019-04-05 17:00:01 +00:00
|
|
|
// Of note, picture is *not* what is colloquially thought of as a "picture", what we call
|
|
|
|
// a bitmap. An SkPicture is a series of draw commands.
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawPicture", select_overload<void (const sk_sp<SkPicture>&)>(&SkCanvas::drawPicture))
|
2019-11-11 15:06:08 +00:00
|
|
|
.function("_drawPoints", optional_override([](SkCanvas& self, SkCanvas::PointMode mode,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 pptr,
|
2020-09-09 15:23:19 +00:00
|
|
|
int count, SkPaint& paint)->void {
|
2019-11-11 15:06:08 +00:00
|
|
|
const SkPoint* pts = reinterpret_cast<const SkPoint*>(pptr);
|
|
|
|
self.drawPoints(mode, count, pts, paint);
|
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawRRect",optional_override([](SkCanvas& self, WASMPointerF32 fPtr, const SkPaint& paint) {
|
2020-09-03 11:57:12 +00:00
|
|
|
self.drawRRect(ptrToSkRRect(fPtr), paint);
|
2019-09-03 16:59:06 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawRect", optional_override([](SkCanvas& self, WASMPointerF32 fPtr,
|
2020-09-09 15:23:19 +00:00
|
|
|
const SkPaint& paint)->void {
|
2020-09-03 14:02:10 +00:00
|
|
|
const SkRect* rect = reinterpret_cast<const SkRect*>(fPtr);
|
|
|
|
self.drawRect(*rect, paint);
|
|
|
|
}))
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawRect4f", optional_override([](SkCanvas& self, SkScalar left, SkScalar top,
|
2020-09-03 12:31:52 +00:00
|
|
|
SkScalar right, SkScalar bottom,
|
2020-09-09 15:23:19 +00:00
|
|
|
const SkPaint& paint)->void {
|
2020-09-03 12:31:52 +00:00
|
|
|
const SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
|
|
|
|
self.drawRect(rect, paint);
|
|
|
|
}))
|
2020-05-04 20:46:17 +00:00
|
|
|
.function("_drawShadow", optional_override([](SkCanvas& self, const SkPath& path,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 zPlaneParamPtr,
|
|
|
|
WASMPointerF32 lightPosPtr,
|
2021-02-02 13:26:48 +00:00
|
|
|
SkScalar lightRadius,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 ambientColorPtr,
|
|
|
|
WASMPointerF32 spotColorPtr,
|
2018-11-27 18:26:59 +00:00
|
|
|
uint32_t flags) {
|
2021-02-02 13:26:48 +00:00
|
|
|
const SkVector3* zPlaneParams = reinterpret_cast<const SkVector3*>(zPlaneParamPtr);
|
|
|
|
const SkVector3* lightPos = reinterpret_cast<const SkVector3*>(lightPosPtr);
|
|
|
|
|
|
|
|
SkShadowUtils::DrawShadow(&self, path, *zPlaneParams, *lightPos, lightRadius,
|
2020-05-04 20:46:17 +00:00
|
|
|
ptrToSkColor4f(ambientColorPtr).toSkColor(),
|
|
|
|
ptrToSkColor4f(spotColorPtr).toSkColor(),
|
|
|
|
flags);
|
2018-11-27 18:26:59 +00:00
|
|
|
}))
|
2019-09-26 17:20:50 +00:00
|
|
|
#ifndef SK_NO_FONTS
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_drawSimpleText", optional_override([](SkCanvas& self, WASMPointerU8 sptr,
|
2019-01-14 13:36:08 +00:00
|
|
|
size_t len, SkScalar x, SkScalar y, const SkFont& font,
|
|
|
|
const SkPaint& paint) {
|
|
|
|
const char* str = reinterpret_cast<const char*>(sptr);
|
|
|
|
|
|
|
|
self.drawSimpleText(str, len, SkTextEncoding::kUTF8, x, y, font, paint);
|
2018-09-20 21:39:31 +00:00
|
|
|
}))
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawTextBlob", select_overload<void (const sk_sp<SkTextBlob>&, SkScalar, SkScalar, const SkPaint&)>(&SkCanvas::drawTextBlob))
|
2019-09-26 17:20:50 +00:00
|
|
|
#endif
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_drawVertices", select_overload<void (const sk_sp<SkVertices>&, SkBlendMode, const SkPaint&)>(&SkCanvas::drawVertices))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_findMarkedCTM", optional_override([](SkCanvas& self, std::string marker, WASMPointerF32 mPtr) -> bool {
|
2020-09-29 21:58:21 +00:00
|
|
|
SkScalar* sixteenMatrixValues = reinterpret_cast<SkScalar*>(mPtr);
|
|
|
|
if (!sixteenMatrixValues) {
|
|
|
|
return false; // matrix cannot be null
|
|
|
|
}
|
|
|
|
SkM44 m;
|
|
|
|
if (self.findMarkedCTM(marker.c_str(), &m)) {
|
|
|
|
m.getRowMajor(sixteenMatrixValues);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}))
|
|
|
|
// 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.
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_getLocalToDevice", optional_override([](const SkCanvas& self, WASMPointerF32 mPtr) {
|
2020-09-29 21:58:21 +00:00
|
|
|
SkScalar* sixteenMatrixValues = reinterpret_cast<SkScalar*>(mPtr);
|
|
|
|
if (!sixteenMatrixValues) {
|
|
|
|
return; // matrix cannot be null
|
|
|
|
}
|
|
|
|
SkM44 m = self.getLocalToDevice();
|
|
|
|
m.getRowMajor(sixteenMatrixValues);
|
|
|
|
}))
|
2019-08-26 19:48:09 +00:00
|
|
|
.function("getSaveCount", &SkCanvas::getSaveCount)
|
2020-04-02 19:24:15 +00:00
|
|
|
// 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.
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_getTotalMatrix", optional_override([](const SkCanvas& self, WASMPointerU8 mPtr) {
|
2020-04-02 19:24:15 +00:00
|
|
|
SkScalar* nineMatrixValues = reinterpret_cast<SkScalar*>(mPtr);
|
|
|
|
if (!nineMatrixValues) {
|
|
|
|
return; // matrix cannot be null
|
|
|
|
}
|
2018-12-07 15:09:11 +00:00
|
|
|
SkMatrix m = self.getTotalMatrix();
|
2020-04-02 19:24:15 +00:00
|
|
|
m.get9(nineMatrixValues);
|
2018-12-07 15:09:11 +00:00
|
|
|
}))
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_makeSurface", optional_override([](SkCanvas& self, SimpleImageInfo sii)->sk_sp<SkSurface> {
|
2019-03-08 15:04:28 +00:00
|
|
|
return self.makeSurface(toSkImageInfo(sii), nullptr);
|
|
|
|
}), allow_raw_pointers())
|
2020-05-06 20:22:33 +00:00
|
|
|
.function("markCTM", optional_override([](SkCanvas& self, std::string marker) {
|
|
|
|
self.markCTM(marker.c_str());
|
|
|
|
}))
|
2020-11-12 14:11:47 +00:00
|
|
|
|
2018-12-04 18:57:36 +00:00
|
|
|
.function("_readPixels", optional_override([](SkCanvas& self, SimpleImageInfo di,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU8 pPtr,
|
2018-12-04 18:57:36 +00:00
|
|
|
size_t dstRowBytes, int srcX, int srcY) {
|
|
|
|
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
|
|
|
|
SkImageInfo dstInfo = toSkImageInfo(di);
|
|
|
|
|
|
|
|
return self.readPixels(dstInfo, pixels, dstRowBytes, srcX, srcY);
|
|
|
|
}))
|
2018-11-29 20:07:02 +00:00
|
|
|
.function("restore", &SkCanvas::restore)
|
2019-03-06 13:25:36 +00:00
|
|
|
.function("restoreToCount", &SkCanvas::restoreToCount)
|
2018-11-03 11:51:19 +00:00
|
|
|
.function("rotate", select_overload<void (SkScalar, SkScalar, SkScalar)>(&SkCanvas::rotate))
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("save", &SkCanvas::save)
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_saveLayer", optional_override([](SkCanvas& self, const SkPaint* p, WASMPointerF32 fPtr,
|
2020-09-03 14:02:10 +00:00
|
|
|
const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags flags)->int {
|
|
|
|
SkRect* bounds = reinterpret_cast<SkRect*>(fPtr);
|
|
|
|
return self.saveLayer(SkCanvas::SaveLayerRec(bounds, p, backdrop, flags));
|
2020-03-17 16:49:19 +00:00
|
|
|
}), allow_raw_pointers())
|
2020-11-03 22:08:34 +00:00
|
|
|
.function("saveLayerPaint", optional_override([](SkCanvas& self, const SkPaint p)->int {
|
|
|
|
return self.saveLayer(SkCanvas::SaveLayerRec(nullptr, &p, 0));
|
|
|
|
}))
|
2018-10-19 18:34:34 +00:00
|
|
|
.function("scale", &SkCanvas::scale)
|
|
|
|
.function("skew", &SkCanvas::skew)
|
2018-12-04 18:57:36 +00:00
|
|
|
.function("translate", &SkCanvas::translate)
|
|
|
|
.function("_writePixels", optional_override([](SkCanvas& self, SimpleImageInfo di,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU8 pPtr,
|
2018-12-04 18:57:36 +00:00
|
|
|
size_t srcRowBytes, int dstX, int dstY) {
|
|
|
|
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
|
|
|
|
SkImageInfo dstInfo = toSkImageInfo(di);
|
|
|
|
|
|
|
|
return self.writePixels(dstInfo, pixels, srcRowBytes, dstX, dstY);
|
2019-10-03 15:22:08 +00:00
|
|
|
}));
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkColorFilter>("ColorFilter")
|
|
|
|
.smart_ptr<sk_sp<SkColorFilter>>("sk_sp<ColorFilter>>")
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_MakeBlend", optional_override([](WASMPointerF32 cPtr, SkBlendMode mode)->sk_sp<SkColorFilter> {
|
2020-05-04 20:46:17 +00:00
|
|
|
return SkColorFilters::Blend(ptrToSkColor4f(cPtr).toSkColor(), mode);
|
2020-03-26 13:27:48 +00:00
|
|
|
}))
|
2019-09-12 15:11:25 +00:00
|
|
|
.class_function("MakeCompose", &SkColorFilters::Compose)
|
|
|
|
.class_function("MakeLerp", &SkColorFilters::Lerp)
|
|
|
|
.class_function("MakeLinearToSRGBGamma", &SkColorFilters::LinearToSRGBGamma)
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_makeMatrix", optional_override([](WASMPointerF32 fPtr) {
|
2019-09-12 15:11:25 +00:00
|
|
|
float* twentyFloats = reinterpret_cast<float*>(fPtr);
|
|
|
|
return SkColorFilters::Matrix(twentyFloats);
|
|
|
|
}))
|
|
|
|
.class_function("MakeSRGBToLinearGamma", &SkColorFilters::SRGBToLinearGamma);
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkContourMeasureIter>("ContourMeasureIter")
|
2019-11-20 19:17:53 +00:00
|
|
|
.constructor<const SkPath&, bool, SkScalar>()
|
|
|
|
.function("next", &SkContourMeasureIter::next);
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkContourMeasure>("ContourMeasure")
|
|
|
|
.smart_ptr<sk_sp<SkContourMeasure>>("sk_sp<ContourMeasure>>")
|
2021-02-02 15:21:24 +00:00
|
|
|
.function("_getPosTan", optional_override([](SkContourMeasure& self,
|
|
|
|
SkScalar distance,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 oPtr) -> void {
|
2021-02-02 15:21:24 +00:00
|
|
|
SkPoint* pointAndVector = reinterpret_cast<SkPoint*>(oPtr);
|
|
|
|
if (!self.getPosTan(distance, pointAndVector, pointAndVector + 1)) {
|
2019-11-20 19:17:53 +00:00
|
|
|
SkDebugf("zero-length path in getPosTan\n");
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
.function("getSegment", optional_override([](SkContourMeasure& self, SkScalar startD,
|
|
|
|
SkScalar stopD, bool startWithMoveTo) -> SkPath {
|
|
|
|
SkPath p;
|
|
|
|
bool ok = self.getSegment(startD, stopD, &p, startWithMoveTo);
|
|
|
|
if (ok) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return SkPath();
|
|
|
|
}))
|
|
|
|
.function("isClosed", &SkContourMeasure::isClosed)
|
|
|
|
.function("length", &SkContourMeasure::length);
|
|
|
|
|
2019-09-26 17:20:50 +00:00
|
|
|
#ifndef SK_NO_FONTS
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkFont>("Font")
|
2019-01-02 20:13:57 +00:00
|
|
|
.constructor<>()
|
|
|
|
.constructor<sk_sp<SkTypeface>>()
|
|
|
|
.constructor<sk_sp<SkTypeface>, SkScalar>()
|
|
|
|
.constructor<sk_sp<SkTypeface>, SkScalar, SkScalar, SkScalar>()
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_getGlyphWidthBounds", optional_override([](SkFont& self, WASMPointerU16 gPtr,
|
|
|
|
int numGlyphs, WASMPointerF32 wPtr,
|
|
|
|
WASMPointerF32 rPtr,
|
2020-09-25 14:52:16 +00:00
|
|
|
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.
|
|
|
|
SkRect* outputRects = reinterpret_cast<SkRect*>(rPtr);
|
|
|
|
SkScalar* outputWidths = reinterpret_cast<SkScalar*>(wPtr);
|
|
|
|
self.getWidthsBounds(glyphs, numGlyphs, outputWidths, outputRects, paint);
|
|
|
|
}), allow_raw_pointers())
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_getGlyphIDs", optional_override([](SkFont& self, WASMPointerU8 sptr,
|
2020-09-25 14:52:16 +00:00
|
|
|
size_t strLen, size_t expectedCodePoints,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU16 iPtr) -> int {
|
2020-09-25 14:52:16 +00:00
|
|
|
char* str = reinterpret_cast<char*>(sptr);
|
|
|
|
SkGlyphID* glyphIDs = reinterpret_cast<SkGlyphID*>(iPtr);
|
|
|
|
|
|
|
|
int actualCodePoints = self.textToGlyphs(str, strLen, SkTextEncoding::kUTF8,
|
|
|
|
glyphIDs, expectedCodePoints);
|
|
|
|
return actualCodePoints;
|
|
|
|
}))
|
2021-04-19 17:20:51 +00:00
|
|
|
.function("getMetrics", optional_override([](SkFont& self) -> JSObject {
|
|
|
|
SkFontMetrics fm;
|
|
|
|
self.getMetrics(&fm);
|
|
|
|
|
|
|
|
JSObject j = emscripten::val::object();
|
|
|
|
j.set("ascent", fm.fAscent);
|
|
|
|
j.set("descent", fm.fDescent);
|
|
|
|
j.set("leading", fm.fLeading);
|
|
|
|
if (!(fm.fFlags & SkFontMetrics::kBoundsInvalid_Flag)) {
|
|
|
|
const float rect[] = {
|
|
|
|
fm.fXMin, fm.fTop, fm.fXMax, fm.fBottom
|
|
|
|
};
|
2021-05-18 17:52:19 +00:00
|
|
|
j.set("bounds", MakeTypedArray(4, rect));
|
2021-04-19 17:20:51 +00:00
|
|
|
}
|
|
|
|
return j;
|
|
|
|
}))
|
2021-06-02 12:38:04 +00:00
|
|
|
.function("_getGlyphIntercepts", optional_override([](SkFont& self,
|
|
|
|
WASMPointerU16 gPtr, size_t numGlyphs, bool ownGlyphs,
|
|
|
|
WASMPointerF32 pPtr, size_t numPos, bool ownPos,
|
2021-06-02 14:29:11 +00:00
|
|
|
float top, float bottom) -> Float32Array {
|
2021-06-02 12:38:04 +00:00
|
|
|
JSSpan<uint16_t> glyphs(gPtr, numGlyphs, ownGlyphs);
|
|
|
|
JSSpan<float> pos (pPtr, numPos, ownPos);
|
2021-05-15 00:55:58 +00:00
|
|
|
if (glyphs.size() > (pos.size() >> 1)) {
|
|
|
|
return emscripten::val("Not enough x,y position pairs for glyphs");
|
|
|
|
}
|
|
|
|
auto sects = self.getIntercepts(glyphs.data(), SkToInt(glyphs.size()),
|
|
|
|
(const SkPoint*)pos.data(), top, bottom);
|
2021-05-18 17:52:19 +00:00
|
|
|
return MakeTypedArray(sects.size(), (const float*)sects.data());
|
2021-05-15 00:55:58 +00:00
|
|
|
}), allow_raw_pointers())
|
2019-01-02 20:13:57 +00:00
|
|
|
.function("getScaleX", &SkFont::getScaleX)
|
|
|
|
.function("getSize", &SkFont::getSize)
|
|
|
|
.function("getSkewX", &SkFont::getSkewX)
|
2021-05-09 18:02:58 +00:00
|
|
|
.function("isEmbolden", &SkFont::isEmbolden)
|
2019-01-02 20:13:57 +00:00
|
|
|
.function("getTypeface", &SkFont::getTypeface, allow_raw_pointers())
|
2020-05-07 20:25:41 +00:00
|
|
|
.function("setEdging", &SkFont::setEdging)
|
|
|
|
.function("setEmbeddedBitmaps", &SkFont::setEmbeddedBitmaps)
|
2020-02-28 13:09:08 +00:00
|
|
|
.function("setHinting", &SkFont::setHinting)
|
|
|
|
.function("setLinearMetrics", &SkFont::setLinearMetrics)
|
2019-01-02 20:13:57 +00:00
|
|
|
.function("setScaleX", &SkFont::setScaleX)
|
|
|
|
.function("setSize", &SkFont::setSize)
|
|
|
|
.function("setSkewX", &SkFont::setSkewX)
|
2021-05-09 18:02:58 +00:00
|
|
|
.function("setEmbolden", &SkFont::setEmbolden)
|
2020-02-28 13:09:08 +00:00
|
|
|
.function("setSubpixel", &SkFont::setSubpixel)
|
2019-01-02 20:13:57 +00:00
|
|
|
.function("setTypeface", &SkFont::setTypeface, allow_raw_pointers());
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkFontMgr>("FontMgr")
|
|
|
|
.smart_ptr<sk_sp<SkFontMgr>>("sk_sp<FontMgr>")
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_fromData", optional_override([](WASMPointerU32 dPtr,
|
|
|
|
WASMPointerU32 sPtr,
|
2019-09-26 17:20:50 +00:00
|
|
|
int numFonts)->sk_sp<SkFontMgr> {
|
|
|
|
auto datas = reinterpret_cast<const uint8_t**>(dPtr);
|
|
|
|
auto sizes = reinterpret_cast<const size_t*>(sPtr);
|
|
|
|
|
2021-03-23 22:02:32 +00:00
|
|
|
std::unique_ptr<sk_sp<SkData>[]> skdatas(new sk_sp<SkData>[numFonts]);
|
|
|
|
for (int i = 0; i < numFonts; ++i) {
|
|
|
|
skdatas[i] = SkData::MakeFromMalloc(datas[i], sizes[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SkFontMgr_New_Custom_Data(skdatas.get(), numFonts);
|
2019-09-26 17:20:50 +00:00
|
|
|
}), allow_raw_pointers())
|
2020-01-15 18:49:53 +00:00
|
|
|
.function("countFamilies", &SkFontMgr::countFamilies)
|
|
|
|
.function("getFamilyName", optional_override([](SkFontMgr& self, int index)->JSString {
|
|
|
|
if (index < 0 || index >= self.countFamilies()) {
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
|
|
|
SkString s;
|
|
|
|
self.getFamilyName(index, &s);
|
|
|
|
return emscripten::val(s.c_str());
|
|
|
|
}))
|
2018-12-12 15:35:13 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
.function("dumpFamilies", optional_override([](SkFontMgr& self) {
|
|
|
|
int numFam = self.countFamilies();
|
2019-09-26 17:20:50 +00:00
|
|
|
SkDebugf("There are %d font families\n", numFam);
|
2018-12-12 15:35:13 +00:00
|
|
|
for (int i = 0 ; i< numFam; i++) {
|
|
|
|
SkString s;
|
|
|
|
self.getFamilyName(i, &s);
|
2019-09-26 17:20:50 +00:00
|
|
|
SkDebugf("\t%s\n", s.c_str());
|
2018-12-12 15:35:13 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
#endif
|
|
|
|
.function("_makeTypefaceFromData", optional_override([](SkFontMgr& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU8 fPtr,
|
2018-12-12 15:35:13 +00:00
|
|
|
int flen)->sk_sp<SkTypeface> {
|
|
|
|
uint8_t* font = reinterpret_cast<uint8_t*>(fPtr);
|
|
|
|
sk_sp<SkData> fontData = SkData::MakeFromMalloc(font, flen);
|
|
|
|
|
|
|
|
return self.makeFromData(fontData);
|
|
|
|
}), allow_raw_pointers());
|
2020-05-07 20:25:41 +00:00
|
|
|
#endif // SK_NO_FONTS
|
2018-12-12 15:35:13 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkImage>("Image")
|
|
|
|
.smart_ptr<sk_sp<SkImage>>("sk_sp<Image>")
|
2021-11-11 16:20:49 +00:00
|
|
|
#if SK_GL
|
|
|
|
.class_function("_makeFromGenerator", &MakeImageFromGenerator)
|
|
|
|
#endif
|
2020-11-18 16:23:15 +00:00
|
|
|
// Note that this needs to be cleaned up with delete().
|
|
|
|
.function("getColorSpace", optional_override([](sk_sp<SkImage> self)->sk_sp<SkColorSpace> {
|
|
|
|
return self->imageInfo().refColorSpace();
|
|
|
|
}), allow_raw_pointers())
|
|
|
|
.function("getImageInfo", optional_override([](sk_sp<SkImage> self)->JSObject {
|
|
|
|
// We cannot return a SimpleImageInfo because the colorspace object would be leaked.
|
|
|
|
JSObject result = emscripten::val::object();
|
|
|
|
SkImageInfo ii = self->imageInfo();
|
|
|
|
result.set("alphaType", ii.alphaType());
|
|
|
|
result.set("colorType", ii.colorType());
|
|
|
|
result.set("height", ii.height());
|
|
|
|
result.set("width", ii.width());
|
|
|
|
return result;
|
|
|
|
}))
|
2018-12-03 17:31:04 +00:00
|
|
|
.function("height", &SkImage::height)
|
2021-02-16 20:38:42 +00:00
|
|
|
.function("encodeToBytes", optional_override([](sk_sp<SkImage> self) -> Uint8Array {
|
|
|
|
sk_sp<SkData> data = self->encodeToData();
|
|
|
|
if (!data) {
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
|
|
|
return toBytes(data);
|
|
|
|
}))
|
|
|
|
.function("encodeToBytes", optional_override([](sk_sp<SkImage> self,
|
|
|
|
SkEncodedImageFormat fmt, int quality) -> Uint8Array {
|
|
|
|
sk_sp<SkData> data = self->encodeToData(fmt, quality);
|
|
|
|
if (!data) {
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
|
|
|
return toBytes(data);
|
|
|
|
}))
|
2020-12-11 19:51:36 +00:00
|
|
|
.function("makeCopyWithDefaultMipmaps", optional_override([](sk_sp<SkImage> self)->sk_sp<SkImage> {
|
|
|
|
return self->withDefaultMipmaps();
|
|
|
|
}))
|
|
|
|
.function("_makeShaderCubic", optional_override([](sk_sp<SkImage> self,
|
2019-04-04 13:28:53 +00:00
|
|
|
SkTileMode tx, SkTileMode ty,
|
2020-12-16 21:00:55 +00:00
|
|
|
float B, float C, // See SkSamplingOptions.h for docs.
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 mPtr)->sk_sp<SkShader> {
|
2020-12-11 19:51:36 +00:00
|
|
|
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,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 mPtr)->sk_sp<SkShader> {
|
2020-12-11 19:51:36 +00:00
|
|
|
return self->makeShader(tx, ty, {filter, mipmap}, OptionalMatrix(mPtr));
|
2019-05-06 17:04:03 +00:00
|
|
|
}), allow_raw_pointers())
|
|
|
|
.function("_readPixels", optional_override([](sk_sp<SkImage> self,
|
2021-05-26 17:40:22 +00:00
|
|
|
SimpleImageInfo sii, WASMPointerU8 pPtr,
|
2019-05-06 17:04:03 +00:00
|
|
|
size_t dstRowBytes, int srcX, int srcY)->bool {
|
|
|
|
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
|
|
|
|
SkImageInfo ii = toSkImageInfo(sii);
|
2020-09-03 14:02:10 +00:00
|
|
|
// TODO(adlai) Migrate CanvasKit API to require DirectContext arg here.
|
2020-08-27 16:44:07 +00:00
|
|
|
GrDirectContext* dContext = nullptr;
|
|
|
|
#ifdef SK_GL
|
|
|
|
dContext = GrAsDirectContext(as_IB(self.get())->context());
|
|
|
|
#endif
|
|
|
|
return self->readPixels(dContext, ii, pixels, dstRowBytes, srcX, srcY);
|
2020-12-11 19:51:36 +00:00
|
|
|
}), allow_raw_pointers())
|
|
|
|
.function("width", &SkImage::width);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkImageFilter>("ImageFilter")
|
|
|
|
.smart_ptr<sk_sp<SkImageFilter>>("sk_sp<ImageFilter>")
|
2019-10-29 13:55:39 +00:00
|
|
|
.class_function("MakeBlur", optional_override([](SkScalar sigmaX, SkScalar sigmaY,
|
|
|
|
SkTileMode tileMode, sk_sp<SkImageFilter> input)->sk_sp<SkImageFilter> {
|
|
|
|
return SkImageFilters::Blur(sigmaX, sigmaY, tileMode, input);
|
|
|
|
}))
|
|
|
|
.class_function("MakeColorFilter", optional_override([](sk_sp<SkColorFilter> cf,
|
2020-09-03 14:02:10 +00:00
|
|
|
sk_sp<SkImageFilter> input)->sk_sp<SkImageFilter> {
|
2019-10-29 13:55:39 +00:00
|
|
|
return SkImageFilters::ColorFilter(cf, input);
|
|
|
|
}))
|
2019-11-15 19:13:20 +00:00
|
|
|
.class_function("MakeCompose", &SkImageFilters::Compose)
|
2021-07-20 13:52:27 +00:00
|
|
|
.class_function("_MakeMatrixTransformCubic",
|
|
|
|
optional_override([](WASMPointerF32 mPtr, float B, float C,
|
|
|
|
sk_sp<SkImageFilter> input)->sk_sp<SkImageFilter> {
|
2020-04-02 19:24:15 +00:00
|
|
|
OptionalMatrix matr(mPtr);
|
2021-07-20 13:52:27 +00:00
|
|
|
return SkImageFilters::MatrixTransform(matr, SkSamplingOptions({B, C}), input);
|
|
|
|
}))
|
|
|
|
.class_function("_MakeMatrixTransformOptions",
|
|
|
|
optional_override([](WASMPointerF32 mPtr, SkFilterMode fm, SkMipmapMode mm,
|
|
|
|
sk_sp<SkImageFilter> input)->sk_sp<SkImageFilter> {
|
|
|
|
OptionalMatrix matr(mPtr);
|
|
|
|
return SkImageFilters::MatrixTransform(matr, SkSamplingOptions(fm, mm), input);
|
2019-11-15 19:13:20 +00:00
|
|
|
}));
|
2019-10-29 13:55:39 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkMaskFilter>("MaskFilter")
|
|
|
|
.smart_ptr<sk_sp<SkMaskFilter>>("sk_sp<MaskFilter>")
|
2019-10-29 13:55:39 +00:00
|
|
|
.class_function("MakeBlur", optional_override([](SkBlurStyle style, SkScalar sigma, bool respectCTM)->sk_sp<SkMaskFilter> {
|
|
|
|
// Adds a little helper because emscripten doesn't expose default params.
|
|
|
|
return SkMaskFilter::MakeBlur(style, sigma, respectCTM);
|
|
|
|
}), allow_raw_pointers());
|
2018-11-27 18:26:59 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkPaint>("Paint")
|
2018-09-20 21:39:31 +00:00
|
|
|
.constructor<>()
|
|
|
|
.function("copy", optional_override([](const SkPaint& self)->SkPaint {
|
|
|
|
SkPaint p(self);
|
|
|
|
return p;
|
|
|
|
}))
|
2020-05-04 20:46:17 +00:00
|
|
|
// provide an allocated place to put the returned color
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_getColor", optional_override([](SkPaint& self, WASMPointerF32 cPtr)->void {
|
2020-05-04 20:46:17 +00:00
|
|
|
const SkColor4f& c = self.getColor4f();
|
|
|
|
float* fourFloats = reinterpret_cast<float*>(cPtr);
|
|
|
|
memcpy(fourFloats, c.vec(), 4 * sizeof(SkScalar));
|
2020-03-26 13:27:48 +00:00
|
|
|
}))
|
2018-11-26 16:47:54 +00:00
|
|
|
.function("getStrokeCap", &SkPaint::getStrokeCap)
|
|
|
|
.function("getStrokeJoin", &SkPaint::getStrokeJoin)
|
2018-12-03 17:31:04 +00:00
|
|
|
.function("getStrokeMiter", &SkPaint::getStrokeMiter)
|
|
|
|
.function("getStrokeWidth", &SkPaint::getStrokeWidth)
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("setAntiAlias", &SkPaint::setAntiAlias)
|
2020-03-17 16:49:19 +00:00
|
|
|
.function("setAlphaf", &SkPaint::setAlphaf)
|
2018-11-28 17:51:56 +00:00
|
|
|
.function("setBlendMode", &SkPaint::setBlendMode)
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_setColor", optional_override([](SkPaint& self, WASMPointerF32 cPtr,
|
2020-05-26 17:10:20 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace) {
|
|
|
|
self.setColor(ptrToSkColor4f(cPtr), colorSpace.get());
|
2019-05-20 15:47:49 +00:00
|
|
|
}))
|
2020-06-04 12:25:16 +00:00
|
|
|
.function("setColorInt", optional_override([](SkPaint& self, SkColor color) {
|
2020-06-02 20:15:23 +00:00
|
|
|
self.setColor(SkColor4f::FromColor(color), nullptr);
|
|
|
|
}))
|
2020-06-04 12:25:16 +00:00
|
|
|
.function("setColorInt", optional_override([](SkPaint& self, SkColor color,
|
2020-06-02 20:15:23 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace) {
|
|
|
|
self.setColor(SkColor4f::FromColor(color), colorSpace.get());
|
|
|
|
}))
|
2019-09-12 15:11:25 +00:00
|
|
|
.function("setColorFilter", &SkPaint::setColorFilter)
|
2019-10-29 13:55:39 +00:00
|
|
|
.function("setImageFilter", &SkPaint::setImageFilter)
|
2018-11-27 18:26:59 +00:00
|
|
|
.function("setMaskFilter", &SkPaint::setMaskFilter)
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("setPathEffect", &SkPaint::setPathEffect)
|
|
|
|
.function("setShader", &SkPaint::setShader)
|
2018-11-26 16:47:54 +00:00
|
|
|
.function("setStrokeCap", &SkPaint::setStrokeCap)
|
|
|
|
.function("setStrokeJoin", &SkPaint::setStrokeJoin)
|
2018-12-03 17:31:04 +00:00
|
|
|
.function("setStrokeMiter", &SkPaint::setStrokeMiter)
|
|
|
|
.function("setStrokeWidth", &SkPaint::setStrokeWidth)
|
2019-01-14 13:36:08 +00:00
|
|
|
.function("setStyle", &SkPaint::setStyle);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkColorSpace>("ColorSpace")
|
|
|
|
.smart_ptr<sk_sp<SkColorSpace>>("sk_sp<ColorSpace>")
|
2020-05-26 17:10:20 +00:00
|
|
|
.class_function("Equals", optional_override([](sk_sp<SkColorSpace> a, sk_sp<SkColorSpace> b)->bool {
|
|
|
|
return SkColorSpace::Equals(a.get(), b.get());
|
|
|
|
}))
|
|
|
|
// These are private because they are to be called once in interface.js to
|
|
|
|
// avoid clients having to delete the returned objects.
|
|
|
|
.class_function("_MakeSRGB", &SkColorSpace::MakeSRGB)
|
|
|
|
.class_function("_MakeDisplayP3", optional_override([]()->sk_sp<SkColorSpace> {
|
|
|
|
return SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDisplayP3);
|
|
|
|
}))
|
|
|
|
.class_function("_MakeAdobeRGB", optional_override([]()->sk_sp<SkColorSpace> {
|
|
|
|
return SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, SkNamedGamut::kAdobeRGB);
|
|
|
|
}));
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkPathEffect>("PathEffect")
|
|
|
|
.smart_ptr<sk_sp<SkPathEffect>>("sk_sp<PathEffect>")
|
2020-02-04 19:18:38 +00:00
|
|
|
.class_function("MakeCorner", &SkCornerPathEffect::Make)
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_MakeDash", optional_override([](WASMPointerF32 cptr, int count,
|
2020-03-18 13:53:55 +00:00
|
|
|
SkScalar phase)->sk_sp<SkPathEffect> {
|
|
|
|
const float* intervals = reinterpret_cast<const float*>(cptr);
|
|
|
|
return SkDashPathEffect::Make(intervals, count, phase);
|
|
|
|
}), allow_raw_pointers())
|
2020-02-04 19:18:38 +00:00
|
|
|
.class_function("MakeDiscrete", &SkDiscretePathEffect::Make);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2020-10-02 12:01:57 +00:00
|
|
|
// TODO(kjlubick, reed) Make SkPath immutable and only creatable via a factory/builder.
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkPath>("Path")
|
2018-09-20 21:39:31 +00:00
|
|
|
.constructor<>()
|
2020-10-09 14:55:06 +00:00
|
|
|
#ifdef SK_INCLUDE_PATHOPS
|
|
|
|
.class_function("MakeFromOp", &MakePathFromOp)
|
|
|
|
#endif
|
|
|
|
.class_function("MakeFromSVGString", &MakePathFromSVGString)
|
2020-06-23 20:58:10 +00:00
|
|
|
.class_function("_MakeFromCmds", &MakePathFromCmds)
|
|
|
|
.class_function("_MakeFromVerbsPointsWeights", &MakePathFromVerbsPointsWeights)
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_addArc", optional_override([](SkPath& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr,
|
2020-09-03 14:02:10 +00:00
|
|
|
SkScalar startAngle, SkScalar sweepAngle)->void {
|
|
|
|
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
|
|
|
|
self.addArc(*oval, startAngle, sweepAngle);
|
|
|
|
}))
|
|
|
|
.function("_addOval", optional_override([](SkPath& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr,
|
2020-09-03 14:02:10 +00:00
|
|
|
bool ccw, unsigned start)->void {
|
|
|
|
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
|
|
|
|
self.addOval(*oval, ccw ? SkPathDirection::kCCW : SkPathDirection::kCW, start);
|
|
|
|
}))
|
2018-09-20 21:39:31 +00:00
|
|
|
// interface.js has 3 overloads of addPath
|
|
|
|
.function("_addPath", &ApplyAddPath)
|
2019-11-11 15:06:08 +00:00
|
|
|
.function("_addPoly", optional_override([](SkPath& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr,
|
2019-11-11 15:06:08 +00:00
|
|
|
int count, bool close)->void {
|
2020-09-03 14:02:10 +00:00
|
|
|
const SkPoint* pts = reinterpret_cast<const SkPoint*>(fPtr);
|
2019-11-11 15:06:08 +00:00
|
|
|
self.addPoly(pts, count, close);
|
|
|
|
}))
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_addRect", optional_override([](SkPath& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr,
|
2020-09-03 14:02:10 +00:00
|
|
|
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,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr,
|
2020-09-03 14:02:10 +00:00
|
|
|
bool ccw)->void {
|
|
|
|
self.addRRect(ptrToSkRRect(fPtr), ccw ? SkPathDirection::kCCW : SkPathDirection::kCW);
|
|
|
|
}))
|
2020-06-23 20:58:10 +00:00
|
|
|
.function("_addVerbsPointsWeights", &PathAddVerbsPointsWeights)
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_arcToOval", optional_override([](SkPath& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr, SkScalar startAngle,
|
2020-09-03 14:02:10 +00:00
|
|
|
SkScalar sweepAngle, bool forceMoveTo)->void {
|
|
|
|
const SkRect* oval = reinterpret_cast<const SkRect*>(fPtr);
|
|
|
|
self.arcTo(*oval, startAngle, sweepAngle, forceMoveTo);
|
|
|
|
}))
|
2020-07-15 20:46:17 +00:00
|
|
|
.function("_arcToRotated", &ApplyArcToArcSize)
|
|
|
|
.function("_arcToTangent", ApplyArcToTangent)
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("_close", &ApplyClose)
|
|
|
|
.function("_conicTo", &ApplyConicTo)
|
2018-11-26 16:47:54 +00:00
|
|
|
.function("countPoints", &SkPath::countPoints)
|
2018-12-07 18:03:08 +00:00
|
|
|
.function("contains", &SkPath::contains)
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("_cubicTo", &ApplyCubicTo)
|
2021-02-02 13:18:11 +00:00
|
|
|
.function("_getPoint", optional_override([](SkPath& self, int index,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 oPtr)->void {
|
2021-02-02 13:18:11 +00:00
|
|
|
SkPoint* output = reinterpret_cast<SkPoint*>(oPtr);
|
|
|
|
*output = self.getPoint(index);
|
|
|
|
}))
|
2018-12-07 18:03:08 +00:00
|
|
|
.function("isEmpty", &SkPath::isEmpty)
|
2018-12-14 21:10:38 +00:00
|
|
|
.function("isVolatile", &SkPath::isVolatile)
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("_lineTo", &ApplyLineTo)
|
|
|
|
.function("_moveTo", &ApplyMoveTo)
|
2019-11-01 18:36:52 +00:00
|
|
|
.function("_quadTo", &ApplyQuadTo)
|
|
|
|
.function("_rArcTo", &ApplyRArcToArcSize)
|
|
|
|
.function("_rConicTo", &ApplyRConicTo)
|
|
|
|
.function("_rCubicTo", &ApplyRCubicTo)
|
|
|
|
.function("_rLineTo", &ApplyRLineTo)
|
|
|
|
.function("_rMoveTo", &ApplyRMoveTo)
|
|
|
|
.function("_rQuadTo", &ApplyRQuadTo)
|
2019-01-07 16:08:55 +00:00
|
|
|
.function("reset", &ApplyReset)
|
|
|
|
.function("rewind", &ApplyRewind)
|
2018-12-14 21:10:38 +00:00
|
|
|
.function("setIsVolatile", &SkPath::setIsVolatile)
|
2018-11-20 17:51:16 +00:00
|
|
|
.function("_transform", select_overload<void(SkPath&, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar)>(&ApplyTransform))
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2018-11-03 11:51:19 +00:00
|
|
|
// PathEffects
|
|
|
|
.function("_dash", &ApplyDash)
|
|
|
|
.function("_trim", &ApplyTrim)
|
|
|
|
.function("_stroke", &ApplyStroke)
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
#ifdef SK_INCLUDE_PATHOPS
|
2018-11-03 11:51:19 +00:00
|
|
|
// PathOps
|
|
|
|
.function("_simplify", &ApplySimplify)
|
|
|
|
.function("_op", &ApplyPathOp)
|
2021-07-21 14:00:28 +00:00
|
|
|
.function("makeAsWinding", &MakeAsWinding)
|
2020-01-06 13:10:05 +00:00
|
|
|
#endif
|
2018-11-03 11:51:19 +00:00
|
|
|
// Exporting
|
|
|
|
.function("toSVGString", &ToSVGString)
|
2019-01-07 16:08:55 +00:00
|
|
|
.function("toCmds", &ToCmds)
|
2018-11-03 11:51:19 +00:00
|
|
|
|
2019-11-26 17:17:17 +00:00
|
|
|
.function("setFillType", select_overload<void(SkPathFillType)>(&SkPath::setFillType))
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("getFillType", &SkPath::getFillType)
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_getBounds", optional_override([](SkPath& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr)->void {
|
2020-09-03 14:02:10 +00:00
|
|
|
SkRect* output = reinterpret_cast<SkRect*>(fPtr);
|
|
|
|
output[0] = self.getBounds();
|
|
|
|
}))
|
2020-10-01 14:55:16 +00:00
|
|
|
.function("_computeTightBounds", optional_override([](SkPath& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr)->void {
|
2020-10-01 14:55:16 +00:00
|
|
|
SkRect* output = reinterpret_cast<SkRect*>(fPtr);
|
|
|
|
output[0] = self.computeTightBounds();
|
|
|
|
}))
|
2018-09-20 21:39:31 +00:00
|
|
|
.function("equals", &Equals)
|
2018-11-26 16:47:54 +00:00
|
|
|
.function("copy", &CopyPath)
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
.function("dump", select_overload<void() const>(&SkPath::dump))
|
|
|
|
.function("dumpHex", select_overload<void() const>(&SkPath::dumpHex))
|
|
|
|
#endif
|
|
|
|
;
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkPictureRecorder>("PictureRecorder")
|
2019-04-05 17:00:01 +00:00
|
|
|
.constructor<>()
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_beginRecording", optional_override([](SkPictureRecorder& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr) -> SkCanvas* {
|
2020-09-03 14:02:10 +00:00
|
|
|
SkRect* bounds = reinterpret_cast<SkRect*>(fPtr);
|
|
|
|
return self.beginRecording(*bounds, nullptr);
|
2019-04-05 17:00:01 +00:00
|
|
|
}), allow_raw_pointers())
|
|
|
|
.function("finishRecordingAsPicture", optional_override([](SkPictureRecorder& self)
|
|
|
|
-> sk_sp<SkPicture> {
|
2020-08-21 17:42:01 +00:00
|
|
|
return self.finishRecordingAsPicture();
|
2019-04-05 17:00:01 +00:00
|
|
|
}), allow_raw_pointers());
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkPicture>("Picture")
|
|
|
|
.smart_ptr<sk_sp<SkPicture>>("sk_sp<Picture>")
|
2020-01-14 13:39:09 +00:00
|
|
|
#ifdef SK_SERIALIZE_SKP
|
2019-04-05 17:00:01 +00:00
|
|
|
// The serialized format of an SkPicture (informally called an "skp"), is not something
|
2020-01-14 13:39:09 +00:00
|
|
|
// that clients should ever rely on. The format may change at anytime and no promises
|
|
|
|
// are made for backwards or forward compatibility.
|
2021-02-16 20:38:42 +00:00
|
|
|
.function("serialize", optional_override([](SkPicture& self) -> Uint8Array {
|
2019-04-05 17:00:01 +00:00
|
|
|
// Emscripten doesn't play well with optional arguments, which we don't
|
|
|
|
// want to expose anyway.
|
2021-02-16 20:38:42 +00:00
|
|
|
sk_sp<SkData> data = self.serialize();
|
|
|
|
if (!data) {
|
|
|
|
return emscripten::val::null();
|
|
|
|
}
|
|
|
|
return toBytes(data);
|
2020-01-06 13:10:05 +00:00
|
|
|
}), allow_raw_pointers())
|
|
|
|
#endif
|
|
|
|
;
|
2019-04-05 17:00:01 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkShader>("Shader")
|
|
|
|
.smart_ptr<sk_sp<SkShader>>("sk_sp<Shader>")
|
2020-10-15 17:07:33 +00:00
|
|
|
.class_function("MakeBlend", select_overload<sk_sp<SkShader>(SkBlendMode, sk_sp<SkShader>, sk_sp<SkShader>)>(&SkShaders::Blend))
|
|
|
|
.class_function("_MakeColor",
|
2021-05-26 17:40:22 +00:00
|
|
|
optional_override([](WASMPointerF32 cPtr, sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
|
2020-05-26 17:10:20 +00:00
|
|
|
return SkShaders::Color(ptrToSkColor4f(cPtr), colorSpace);
|
2020-03-26 13:27:48 +00:00
|
|
|
})
|
|
|
|
)
|
2020-10-15 17:09:02 +00:00
|
|
|
.class_function("MakeFractalNoise", optional_override([](
|
|
|
|
SkScalar baseFreqX, SkScalar baseFreqY,
|
|
|
|
int numOctaves, SkScalar seed,
|
|
|
|
int tileW, int tileH)->sk_sp<SkShader> {
|
|
|
|
// if tileSize is empty (e.g. tileW <= 0 or tileH <= 0, it will be ignored.
|
|
|
|
SkISize tileSize = SkISize::Make(tileW, tileH);
|
|
|
|
return SkPerlinNoiseShader::MakeFractalNoise(baseFreqX, baseFreqY,
|
|
|
|
numOctaves, seed, &tileSize);
|
|
|
|
}))
|
2020-10-15 17:07:33 +00:00
|
|
|
// Here and in other gradient functions, cPtr is a pointer to an array of data
|
|
|
|
// 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.
|
2021-02-02 13:18:11 +00:00
|
|
|
.class_function("_MakeLinearGradient", optional_override([](
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fourFloatsPtr,
|
|
|
|
WASMPointerF32 cPtr, SkColorType colorType,
|
|
|
|
WASMPointerF32 pPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
int count, SkTileMode mode, uint32_t flags,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 mPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
|
2021-02-02 13:18:11 +00:00
|
|
|
const SkPoint* points = reinterpret_cast<const SkPoint*>(fourFloatsPtr);
|
2020-10-15 17:07:33 +00:00
|
|
|
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
|
|
|
|
OptionalMatrix localMatrix(mPtr);
|
|
|
|
|
|
|
|
if (colorType == SkColorType::kRGBA_F32_SkColorType) {
|
|
|
|
const SkColor4f* colors = reinterpret_cast<const SkColor4f*>(cPtr);
|
|
|
|
return SkGradientShader::MakeLinear(points, colors, colorSpace, positions, count,
|
|
|
|
mode, flags, &localMatrix);
|
|
|
|
} else if (colorType == SkColorType::kRGBA_8888_SkColorType) {
|
|
|
|
const SkColor* colors = reinterpret_cast<const SkColor*>(cPtr);
|
|
|
|
return SkGradientShader::MakeLinear(points, colors, positions, count,
|
|
|
|
mode, flags, &localMatrix);
|
|
|
|
}
|
|
|
|
SkDebugf("%d is not an accepted colorType\n", colorType);
|
|
|
|
return nullptr;
|
|
|
|
}), allow_raw_pointers())
|
2021-02-02 13:18:11 +00:00
|
|
|
.class_function("_MakeRadialGradient", optional_override([](
|
|
|
|
SkScalar cx, SkScalar cy, SkScalar radius,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 cPtr, SkColorType colorType,
|
|
|
|
WASMPointerF32 pPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
int count, SkTileMode mode, uint32_t flags,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 mPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
|
|
|
|
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
|
|
|
|
OptionalMatrix localMatrix(mPtr);
|
|
|
|
if (colorType == SkColorType::kRGBA_F32_SkColorType) {
|
|
|
|
const SkColor4f* colors = reinterpret_cast<const SkColor4f*>(cPtr);
|
2021-02-02 13:18:11 +00:00
|
|
|
return SkGradientShader::MakeRadial({cx, cy}, radius, colors, colorSpace,
|
|
|
|
positions, count, mode, flags, &localMatrix);
|
2020-10-15 17:07:33 +00:00
|
|
|
} else if (colorType == SkColorType::kRGBA_8888_SkColorType) {
|
|
|
|
const SkColor* colors = reinterpret_cast<const SkColor*>(cPtr);
|
2021-02-02 13:18:11 +00:00
|
|
|
return SkGradientShader::MakeRadial({cx, cy}, radius, colors, positions,
|
|
|
|
count, mode, flags, &localMatrix);
|
2020-10-15 17:07:33 +00:00
|
|
|
}
|
|
|
|
SkDebugf("%d is not an accepted colorType\n", colorType);
|
|
|
|
return nullptr;
|
|
|
|
}), allow_raw_pointers())
|
|
|
|
.class_function("_MakeSweepGradient", optional_override([](SkScalar cx, SkScalar cy,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 cPtr, SkColorType colorType,
|
|
|
|
WASMPointerF32 pPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
int count, SkTileMode mode,
|
|
|
|
SkScalar startAngle, SkScalar endAngle,
|
|
|
|
uint32_t flags,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 mPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
|
|
|
|
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
|
|
|
|
OptionalMatrix localMatrix(mPtr);
|
|
|
|
if (colorType == SkColorType::kRGBA_F32_SkColorType) {
|
|
|
|
const SkColor4f* colors = reinterpret_cast<const SkColor4f*>(cPtr);
|
|
|
|
return SkGradientShader::MakeSweep(cx, cy, colors, colorSpace, positions, count,
|
|
|
|
mode, startAngle, endAngle, flags,
|
|
|
|
&localMatrix);
|
|
|
|
} else if (colorType == SkColorType::kRGBA_8888_SkColorType) {
|
|
|
|
const SkColor* colors = reinterpret_cast<const SkColor*>(cPtr);
|
|
|
|
return SkGradientShader::MakeSweep(cx, cy, colors, positions, count,
|
|
|
|
mode, startAngle, endAngle, flags,
|
|
|
|
&localMatrix);
|
|
|
|
}
|
|
|
|
SkDebugf("%d is not an accepted colorType\n", colorType);
|
|
|
|
return nullptr;
|
|
|
|
}), allow_raw_pointers())
|
2020-10-15 17:09:02 +00:00
|
|
|
.class_function("MakeTurbulence", optional_override([](
|
|
|
|
SkScalar baseFreqX, SkScalar baseFreqY,
|
|
|
|
int numOctaves, SkScalar seed,
|
|
|
|
int tileW, int tileH)->sk_sp<SkShader> {
|
|
|
|
// if tileSize is empty (e.g. tileW <= 0 or tileH <= 0, it will be ignored.
|
|
|
|
SkISize tileSize = SkISize::Make(tileW, tileH);
|
|
|
|
return SkPerlinNoiseShader::MakeTurbulence(baseFreqX, baseFreqY,
|
|
|
|
numOctaves, seed, &tileSize);
|
|
|
|
}))
|
2020-10-15 17:07:33 +00:00
|
|
|
.class_function("_MakeTwoPointConicalGradient", optional_override([](
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fourFloatsPtr,
|
2021-02-02 13:18:11 +00:00
|
|
|
SkScalar startRadius, SkScalar endRadius,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 cPtr, SkColorType colorType,
|
|
|
|
WASMPointerF32 pPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
int count, SkTileMode mode, uint32_t flags,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 mPtr,
|
2020-10-15 17:07:33 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace)->sk_sp<SkShader> {
|
2021-02-02 13:18:11 +00:00
|
|
|
const SkPoint* startAndEnd = reinterpret_cast<const SkPoint*>(fourFloatsPtr);
|
2020-10-15 17:07:33 +00:00
|
|
|
const SkScalar* positions = reinterpret_cast<const SkScalar*>(pPtr);
|
|
|
|
OptionalMatrix localMatrix(mPtr);
|
|
|
|
|
|
|
|
if (colorType == SkColorType::kRGBA_F32_SkColorType) {
|
|
|
|
const SkColor4f* colors = reinterpret_cast<const SkColor4f*>(cPtr);
|
2021-02-02 13:18:11 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(startAndEnd[0], startRadius,
|
|
|
|
startAndEnd[1], endRadius,
|
2020-10-15 17:07:33 +00:00
|
|
|
colors, colorSpace, positions, count, mode,
|
|
|
|
flags, &localMatrix);
|
|
|
|
} else if (colorType == SkColorType::kRGBA_8888_SkColorType) {
|
|
|
|
const SkColor* colors = reinterpret_cast<const SkColor*>(cPtr);
|
2021-02-02 13:18:11 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(startAndEnd[0], startRadius,
|
|
|
|
startAndEnd[1], endRadius,
|
2020-10-15 17:07:33 +00:00
|
|
|
colors, positions, count, mode,
|
|
|
|
flags, &localMatrix);
|
|
|
|
}
|
|
|
|
SkDebugf("%d is not an accepted colorType\n", colorType);
|
|
|
|
return nullptr;
|
|
|
|
}), allow_raw_pointers());
|
2018-11-03 11:51:19 +00:00
|
|
|
|
2020-01-06 13:11:52 +00:00
|
|
|
#ifdef SK_INCLUDE_RUNTIME_EFFECT
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkRuntimeEffect>("RuntimeEffect")
|
|
|
|
.smart_ptr<sk_sp<SkRuntimeEffect>>("sk_sp<RuntimeEffect>")
|
2021-02-03 16:26:12 +00:00
|
|
|
.class_function("_Make", optional_override([](std::string sksl,
|
|
|
|
emscripten::val errHandler
|
|
|
|
)->sk_sp<SkRuntimeEffect> {
|
2019-12-06 18:55:58 +00:00
|
|
|
SkString s(sksl.c_str(), sksl.length());
|
2021-04-21 15:30:11 +00:00
|
|
|
auto [effect, errorText] = SkRuntimeEffect::MakeForShader(s);
|
2020-01-02 20:11:41 +00:00
|
|
|
if (!effect) {
|
2021-02-03 16:26:12 +00:00
|
|
|
errHandler.call<void>("onError", val(errorText.c_str()));
|
2020-02-22 12:37:33 +00:00
|
|
|
return nullptr;
|
2020-01-02 20:11:41 +00:00
|
|
|
}
|
|
|
|
return effect;
|
2019-12-06 18:55:58 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_makeShader", optional_override([](SkRuntimeEffect& self, WASMPointerF32 fPtr, size_t fLen, bool isOpaque,
|
|
|
|
WASMPointerF32 mPtr)->sk_sp<SkShader> {
|
2020-02-22 12:37:33 +00:00
|
|
|
void* inputData = reinterpret_cast<void*>(fPtr);
|
2021-04-08 18:51:29 +00:00
|
|
|
castUniforms(inputData, fLen, self);
|
2020-02-22 12:37:33 +00:00
|
|
|
sk_sp<SkData> inputs = SkData::MakeFromMalloc(inputData, fLen);
|
|
|
|
|
2020-04-02 19:24:15 +00:00
|
|
|
OptionalMatrix localMatrix(mPtr);
|
|
|
|
return self.makeShader(inputs, nullptr, 0, &localMatrix, isOpaque);
|
2020-02-22 12:37:33 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_makeShaderWithChildren", optional_override([](SkRuntimeEffect& self, WASMPointerF32 fPtr, size_t fLen, bool isOpaque,
|
|
|
|
WASMPointerU32 cPtrs, size_t cLen,
|
|
|
|
WASMPointerF32 mPtr)->sk_sp<SkShader> {
|
2020-02-22 12:37:33 +00:00
|
|
|
void* inputData = reinterpret_cast<void*>(fPtr);
|
2021-04-08 18:51:29 +00:00
|
|
|
castUniforms(inputData, fLen, self);
|
2020-02-22 12:37:33 +00:00
|
|
|
sk_sp<SkData> inputs = SkData::MakeFromMalloc(inputData, fLen);
|
|
|
|
|
|
|
|
sk_sp<SkShader>* children = new sk_sp<SkShader>[cLen];
|
|
|
|
SkShader** childrenPtrs = reinterpret_cast<SkShader**>(cPtrs);
|
|
|
|
for (size_t i = 0; i < cLen; i++) {
|
|
|
|
// This bare pointer was already part of an sk_sp (owned outside of here),
|
|
|
|
// so we want to ref the new sk_sp so makeShader doesn't clean it up.
|
|
|
|
children[i] = sk_ref_sp<SkShader>(childrenPtrs[i]);
|
|
|
|
}
|
2020-04-02 19:24:15 +00:00
|
|
|
OptionalMatrix localMatrix(mPtr);
|
|
|
|
auto s = self.makeShader(inputs, children, cLen, &localMatrix, isOpaque);
|
2020-02-22 12:37:33 +00:00
|
|
|
delete[] children;
|
|
|
|
return s;
|
2021-02-03 21:12:09 +00:00
|
|
|
}))
|
|
|
|
.function("getUniformCount", optional_override([](SkRuntimeEffect& self)->int {
|
2021-11-10 19:29:10 +00:00
|
|
|
return self.uniforms().size();
|
2021-02-03 21:12:09 +00:00
|
|
|
}))
|
|
|
|
.function("getUniformFloatCount", optional_override([](SkRuntimeEffect& self)->int {
|
|
|
|
return self.uniformSize() / sizeof(float);
|
|
|
|
}))
|
|
|
|
.function("getUniformName", optional_override([](SkRuntimeEffect& self, int i)->JSString {
|
|
|
|
auto it = self.uniforms().begin() + i;
|
|
|
|
return emscripten::val(it->name.c_str());
|
|
|
|
}))
|
|
|
|
.function("getUniform", optional_override([](SkRuntimeEffect& self, int i)->RuntimeEffectUniform {
|
|
|
|
auto it = self.uniforms().begin() + i;
|
|
|
|
RuntimeEffectUniform su = fromUniform(*it);
|
|
|
|
return su;
|
2019-12-06 18:55:58 +00:00
|
|
|
}));
|
2021-02-03 21:12:09 +00:00
|
|
|
|
|
|
|
value_object<RuntimeEffectUniform>("RuntimeEffectUniform")
|
2021-04-08 18:51:29 +00:00
|
|
|
.field("columns", &RuntimeEffectUniform::columns)
|
|
|
|
.field("rows", &RuntimeEffectUniform::rows)
|
|
|
|
.field("slot", &RuntimeEffectUniform::slot)
|
|
|
|
.field("isInteger", &RuntimeEffectUniform::isInteger);
|
2021-02-23 14:40:07 +00:00
|
|
|
|
|
|
|
constant("rt_effect", true);
|
2020-01-06 13:11:52 +00:00
|
|
|
#endif
|
2019-12-06 18:55:58 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkSurface>("Surface")
|
|
|
|
.smart_ptr<sk_sp<SkSurface>>("sk_sp<Surface>")
|
2020-11-11 21:48:30 +00:00
|
|
|
.class_function("_makeRasterDirect", optional_override([](const SimpleImageInfo ii,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerU8 pPtr,
|
2020-11-11 21:48:30 +00:00
|
|
|
size_t rowBytes)->sk_sp<SkSurface> {
|
|
|
|
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
|
|
|
|
SkImageInfo imageInfo = toSkImageInfo(ii);
|
|
|
|
return SkSurface::MakeRasterDirect(imageInfo, pixels, rowBytes, nullptr);
|
|
|
|
}), allow_raw_pointers())
|
2020-10-06 18:54:58 +00:00
|
|
|
.function("_flush", optional_override([](SkSurface& self) {
|
2020-10-06 14:07:38 +00:00
|
|
|
self.flushAndSubmit(false);
|
|
|
|
}))
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_getCanvas", &SkSurface::getCanvas, allow_raw_pointers())
|
2020-05-26 17:10:20 +00:00
|
|
|
.function("imageInfo", optional_override([](SkSurface& self)->SimpleImageInfo {
|
|
|
|
const auto& ii = self.imageInfo();
|
|
|
|
return {ii.width(), ii.height(), ii.colorType(), ii.alphaType(), ii.refColorSpace()};
|
|
|
|
}))
|
2019-03-08 15:04:28 +00:00
|
|
|
.function("height", &SkSurface::height)
|
2021-06-03 12:02:03 +00:00
|
|
|
#ifdef SK_GL
|
|
|
|
.function("_makeImageFromTexture", optional_override([](SkSurface& self,
|
|
|
|
uint32_t webglHandle, uint32_t texHandle,
|
|
|
|
SimpleImageInfo ii)->sk_sp<SkImage> {
|
|
|
|
auto releaseCtx = new TextureReleaseContext{webglHandle, texHandle};
|
|
|
|
GrGLTextureInfo gti = {GR_GL_TEXTURE_2D, texHandle,
|
|
|
|
GR_GL_RGBA8}; // TODO(kjlubick) look at ii for this
|
|
|
|
GrBackendTexture gbt(ii.width, ii.height, GrMipmapped::kNo, gti);
|
|
|
|
auto dContext = GrAsDirectContext(self.getCanvas()->recordingContext());
|
|
|
|
|
|
|
|
return SkImage::MakeFromTexture(
|
|
|
|
dContext,
|
|
|
|
gbt,
|
|
|
|
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
|
|
|
|
ii.colorType,
|
|
|
|
ii.alphaType,
|
|
|
|
ii.colorSpace,
|
|
|
|
deleteJSTexture,
|
|
|
|
releaseCtx);
|
|
|
|
}))
|
|
|
|
#endif
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("_makeImageSnapshot", optional_override([](SkSurface& self, WASMPointerU32 iPtr)->sk_sp<SkImage> {
|
2020-09-03 14:02:10 +00:00
|
|
|
SkIRect* bounds = reinterpret_cast<SkIRect*>(iPtr);
|
|
|
|
if (!bounds) {
|
|
|
|
return self.makeImageSnapshot();
|
|
|
|
}
|
|
|
|
return self.makeImageSnapshot(*bounds);
|
|
|
|
}))
|
2021-08-25 17:13:09 +00:00
|
|
|
.function("_makeSurface", optional_override([](SkSurface& self, SimpleImageInfo sii)->sk_sp<SkSurface> {
|
2019-03-08 15:04:28 +00:00
|
|
|
return self.makeSurface(toSkImageInfo(sii));
|
|
|
|
}), allow_raw_pointers())
|
2020-06-23 14:07:45 +00:00
|
|
|
#ifdef SK_GL
|
2020-07-17 14:28:36 +00:00
|
|
|
.function("reportBackendTypeIsGPU", optional_override([](SkSurface& self) -> bool {
|
2020-09-15 14:41:36 +00:00
|
|
|
return self.getCanvas()->recordingContext() != nullptr;
|
2020-06-23 14:07:45 +00:00
|
|
|
}))
|
2020-06-19 15:45:57 +00:00
|
|
|
.function("sampleCnt", optional_override([](SkSurface& self)->int {
|
|
|
|
auto backendRT = self.getBackendRenderTarget(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
return (backendRT.isValid()) ? backendRT.sampleCnt() : 0;
|
|
|
|
}))
|
2020-06-23 14:07:45 +00:00
|
|
|
#else
|
2020-07-17 14:28:36 +00:00
|
|
|
.function("reportBackendTypeIsGPU", optional_override([](SkSurface& self) -> bool {
|
|
|
|
return false;
|
2020-06-23 14:07:45 +00:00
|
|
|
}))
|
|
|
|
#endif
|
|
|
|
.function("width", &SkSurface::width);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2019-09-26 17:20:50 +00:00
|
|
|
#ifndef SK_NO_FONTS
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkTextBlob>("TextBlob")
|
|
|
|
.smart_ptr<sk_sp<SkTextBlob>>("sk_sp<TextBlob>")
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_MakeFromRSXform", optional_override([](WASMPointerU8 sptr,
|
2019-03-15 19:36:29 +00:00
|
|
|
size_t strBtyes,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 xptr,
|
2020-03-10 14:44:04 +00:00
|
|
|
const SkFont& font)->sk_sp<SkTextBlob> {
|
2019-03-15 19:36:29 +00:00
|
|
|
const char* str = reinterpret_cast<const char*>(sptr);
|
|
|
|
const SkRSXform* xforms = reinterpret_cast<const SkRSXform*>(xptr);
|
|
|
|
|
2020-03-10 14:44:04 +00:00
|
|
|
return SkTextBlob::MakeFromRSXform(str, strBtyes, xforms, font, SkTextEncoding::kUTF8);
|
2019-03-15 19:36:29 +00:00
|
|
|
}), allow_raw_pointers())
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_MakeFromRSXformGlyphs", optional_override([](WASMPointerU16 gPtr,
|
2020-09-25 14:52:16 +00:00
|
|
|
size_t byteLen,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 xptr,
|
2020-09-25 14:52:16 +00:00
|
|
|
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())
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_MakeFromText", optional_override([](WASMPointerU8 sptr,
|
2020-03-10 14:44:04 +00:00
|
|
|
size_t len, const SkFont& font)->sk_sp<SkTextBlob> {
|
2019-01-14 13:36:08 +00:00
|
|
|
const char* str = reinterpret_cast<const char*>(sptr);
|
2020-03-10 14:44:04 +00:00
|
|
|
return SkTextBlob::MakeFromText(str, len, font, SkTextEncoding::kUTF8);
|
2020-09-25 14:52:16 +00:00
|
|
|
}), allow_raw_pointers())
|
2021-05-26 17:40:22 +00:00
|
|
|
.class_function("_MakeFromGlyphs", optional_override([](WASMPointerU16 gPtr,
|
2020-09-25 14:52:16 +00:00
|
|
|
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);
|
2019-01-14 13:36:08 +00:00
|
|
|
}), allow_raw_pointers());
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkTypeface>("Typeface")
|
2021-06-25 18:06:42 +00:00
|
|
|
.smart_ptr<sk_sp<SkTypeface>>("sk_sp<Typeface>")
|
|
|
|
.class_function("_MakeFreeTypeFaceFromData", optional_override([](WASMPointerU8 fPtr,
|
|
|
|
int flen)->sk_sp<SkTypeface> {
|
|
|
|
uint8_t* font = reinterpret_cast<uint8_t*>(fPtr);
|
|
|
|
sk_sp<SkData> fontData = SkData::MakeFromMalloc(font, flen);
|
|
|
|
|
|
|
|
return SkFontMgr::RefDefault()->makeFromData(fontData);
|
2021-06-25 18:08:39 +00:00
|
|
|
}), allow_raw_pointers())
|
|
|
|
.function("_getGlyphIDs", optional_override([](SkTypeface& self, WASMPointerU8 sptr,
|
|
|
|
size_t strLen, size_t expectedCodePoints,
|
|
|
|
WASMPointerU16 iPtr) -> int {
|
|
|
|
char* str = reinterpret_cast<char*>(sptr);
|
|
|
|
SkGlyphID* glyphIDs = reinterpret_cast<SkGlyphID*>(iPtr);
|
|
|
|
|
|
|
|
int actualCodePoints = self.textToGlyphs(str, strLen, SkTextEncoding::kUTF8,
|
|
|
|
glyphIDs, expectedCodePoints);
|
|
|
|
return actualCodePoints;
|
|
|
|
}));
|
2019-09-26 17:20:50 +00:00
|
|
|
#endif
|
2018-12-12 15:35:13 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkVertices>("Vertices")
|
|
|
|
.smart_ptr<sk_sp<SkVertices>>("sk_sp<Vertices>")
|
2020-09-03 14:02:10 +00:00
|
|
|
.function("_bounds", optional_override([](SkVertices& self,
|
2021-05-26 17:40:22 +00:00
|
|
|
WASMPointerF32 fPtr)->void {
|
2020-09-03 14:02:10 +00:00
|
|
|
SkRect* output = reinterpret_cast<SkRect*>(fPtr);
|
|
|
|
output[0] = self.bounds();
|
|
|
|
}))
|
2020-03-13 00:33:21 +00:00
|
|
|
.function("uniqueID", &SkVertices::uniqueID);
|
2018-11-03 11:51:19 +00:00
|
|
|
|
2019-06-03 18:38:05 +00:00
|
|
|
// Not intended to be called directly by clients
|
2020-10-07 20:09:22 +00:00
|
|
|
class_<SkVertices::Builder>("_VerticesBuilder")
|
2019-06-03 18:38:05 +00:00
|
|
|
.constructor<SkVertices::VertexMode, int, int, uint32_t>()
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("colors", optional_override([](SkVertices::Builder& self)->WASMPointerF32{
|
2019-06-03 18:38:05 +00:00
|
|
|
// Emscripten won't let us return bare pointers, but we can return ints just fine.
|
2021-05-26 17:40:22 +00:00
|
|
|
return reinterpret_cast<WASMPointerF32>(self.colors());
|
2019-06-03 18:38:05 +00:00
|
|
|
}))
|
|
|
|
.function("detach", &SkVertices::Builder::detach)
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("indices", optional_override([](SkVertices::Builder& self)->WASMPointerU16{
|
2019-06-03 18:38:05 +00:00
|
|
|
// Emscripten won't let us return bare pointers, but we can return ints just fine.
|
2021-05-26 17:40:22 +00:00
|
|
|
return reinterpret_cast<WASMPointerU16>(self.indices());
|
2019-06-03 18:38:05 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("positions", optional_override([](SkVertices::Builder& self)->WASMPointerF32{
|
2019-06-03 18:38:05 +00:00
|
|
|
// Emscripten won't let us return bare pointers, but we can return ints just fine.
|
2021-05-26 17:40:22 +00:00
|
|
|
return reinterpret_cast<WASMPointerF32>(self.positions());
|
2019-06-03 18:38:05 +00:00
|
|
|
}))
|
2021-05-26 17:40:22 +00:00
|
|
|
.function("texCoords", optional_override([](SkVertices::Builder& self)->WASMPointerF32{
|
2019-06-03 18:38:05 +00:00
|
|
|
// Emscripten won't let us return bare pointers, but we can return ints just fine.
|
2021-05-26 17:40:22 +00:00
|
|
|
return reinterpret_cast<WASMPointerF32>(self.texCoords());
|
2019-06-03 18:38:05 +00:00
|
|
|
}));
|
|
|
|
|
2018-11-30 19:05:58 +00:00
|
|
|
enum_<SkAlphaType>("AlphaType")
|
|
|
|
.value("Opaque", SkAlphaType::kOpaque_SkAlphaType)
|
|
|
|
.value("Premul", SkAlphaType::kPremul_SkAlphaType)
|
|
|
|
.value("Unpremul", SkAlphaType::kUnpremul_SkAlphaType);
|
2018-11-03 11:51:19 +00:00
|
|
|
|
|
|
|
enum_<SkBlendMode>("BlendMode")
|
|
|
|
.value("Clear", SkBlendMode::kClear)
|
|
|
|
.value("Src", SkBlendMode::kSrc)
|
|
|
|
.value("Dst", SkBlendMode::kDst)
|
|
|
|
.value("SrcOver", SkBlendMode::kSrcOver)
|
|
|
|
.value("DstOver", SkBlendMode::kDstOver)
|
|
|
|
.value("SrcIn", SkBlendMode::kSrcIn)
|
|
|
|
.value("DstIn", SkBlendMode::kDstIn)
|
|
|
|
.value("SrcOut", SkBlendMode::kSrcOut)
|
|
|
|
.value("DstOut", SkBlendMode::kDstOut)
|
|
|
|
.value("SrcATop", SkBlendMode::kSrcATop)
|
|
|
|
.value("DstATop", SkBlendMode::kDstATop)
|
|
|
|
.value("Xor", SkBlendMode::kXor)
|
|
|
|
.value("Plus", SkBlendMode::kPlus)
|
|
|
|
.value("Modulate", SkBlendMode::kModulate)
|
|
|
|
.value("Screen", SkBlendMode::kScreen)
|
|
|
|
.value("Overlay", SkBlendMode::kOverlay)
|
|
|
|
.value("Darken", SkBlendMode::kDarken)
|
|
|
|
.value("Lighten", SkBlendMode::kLighten)
|
|
|
|
.value("ColorDodge", SkBlendMode::kColorDodge)
|
|
|
|
.value("ColorBurn", SkBlendMode::kColorBurn)
|
|
|
|
.value("HardLight", SkBlendMode::kHardLight)
|
|
|
|
.value("SoftLight", SkBlendMode::kSoftLight)
|
|
|
|
.value("Difference", SkBlendMode::kDifference)
|
|
|
|
.value("Exclusion", SkBlendMode::kExclusion)
|
|
|
|
.value("Multiply", SkBlendMode::kMultiply)
|
|
|
|
.value("Hue", SkBlendMode::kHue)
|
|
|
|
.value("Saturation", SkBlendMode::kSaturation)
|
|
|
|
.value("Color", SkBlendMode::kColor)
|
|
|
|
.value("Luminosity", SkBlendMode::kLuminosity);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2018-11-27 18:26:59 +00:00
|
|
|
enum_<SkBlurStyle>("BlurStyle")
|
|
|
|
.value("Normal", SkBlurStyle::kNormal_SkBlurStyle)
|
|
|
|
.value("Solid", SkBlurStyle::kSolid_SkBlurStyle)
|
|
|
|
.value("Outer", SkBlurStyle::kOuter_SkBlurStyle)
|
|
|
|
.value("Inner", SkBlurStyle::kInner_SkBlurStyle);
|
2018-09-20 21:39:31 +00:00
|
|
|
|
2018-11-29 20:07:02 +00:00
|
|
|
enum_<SkClipOp>("ClipOp")
|
|
|
|
.value("Difference", SkClipOp::kDifference)
|
|
|
|
.value("Intersect", SkClipOp::kIntersect);
|
|
|
|
|
2018-11-30 19:05:58 +00:00
|
|
|
enum_<SkColorType>("ColorType")
|
|
|
|
.value("Alpha_8", SkColorType::kAlpha_8_SkColorType)
|
|
|
|
.value("RGB_565", SkColorType::kRGB_565_SkColorType)
|
|
|
|
.value("RGBA_8888", SkColorType::kRGBA_8888_SkColorType)
|
|
|
|
.value("BGRA_8888", SkColorType::kBGRA_8888_SkColorType)
|
|
|
|
.value("RGBA_1010102", SkColorType::kRGBA_1010102_SkColorType)
|
|
|
|
.value("RGB_101010x", SkColorType::kRGB_101010x_SkColorType)
|
|
|
|
.value("Gray_8", SkColorType::kGray_8_SkColorType)
|
|
|
|
.value("RGBA_F16", SkColorType::kRGBA_F16_SkColorType)
|
2020-09-15 13:23:29 +00:00
|
|
|
.value("RGBA_F32", SkColorType::kRGBA_F32_SkColorType);
|
2018-11-30 19:05:58 +00:00
|
|
|
|
2019-11-26 17:17:17 +00:00
|
|
|
enum_<SkPathFillType>("FillType")
|
|
|
|
.value("Winding", SkPathFillType::kWinding)
|
2020-03-10 14:44:04 +00:00
|
|
|
.value("EvenOdd", SkPathFillType::kEvenOdd);
|
2018-11-03 11:51:19 +00:00
|
|
|
|
2020-12-11 19:51:36 +00:00
|
|
|
enum_<SkFilterMode>("FilterMode")
|
|
|
|
.value("Nearest", SkFilterMode::kNearest)
|
|
|
|
.value("Linear", SkFilterMode::kLinear);
|
|
|
|
|
2020-03-10 14:44:04 +00:00
|
|
|
// Only used to control the encode function.
|
2020-03-18 13:15:17 +00:00
|
|
|
// TODO(kjlubick): compile these out when the appropriate encoder is disabled.
|
2018-11-27 18:26:59 +00:00
|
|
|
enum_<SkEncodedImageFormat>("ImageFormat")
|
|
|
|
.value("PNG", SkEncodedImageFormat::kPNG)
|
2020-03-18 13:15:17 +00:00
|
|
|
.value("JPEG", SkEncodedImageFormat::kJPEG)
|
|
|
|
.value("WEBP", SkEncodedImageFormat::kWEBP);
|
2018-11-27 18:26:59 +00:00
|
|
|
|
2020-12-11 19:51:36 +00:00
|
|
|
enum_<SkMipmapMode>("MipmapMode")
|
|
|
|
.value("None", SkMipmapMode::kNone)
|
|
|
|
.value("Nearest", SkMipmapMode::kNearest)
|
|
|
|
.value("Linear", SkMipmapMode::kLinear);
|
|
|
|
|
2018-11-27 18:26:59 +00:00
|
|
|
enum_<SkPaint::Style>("PaintStyle")
|
|
|
|
.value("Fill", SkPaint::Style::kFill_Style)
|
2020-03-10 14:44:04 +00:00
|
|
|
.value("Stroke", SkPaint::Style::kStroke_Style);
|
2018-11-27 18:26:59 +00:00
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
#ifdef SK_INCLUDE_PATHOPS
|
2018-11-03 11:51:19 +00:00
|
|
|
enum_<SkPathOp>("PathOp")
|
|
|
|
.value("Difference", SkPathOp::kDifference_SkPathOp)
|
|
|
|
.value("Intersect", SkPathOp::kIntersect_SkPathOp)
|
|
|
|
.value("Union", SkPathOp::kUnion_SkPathOp)
|
|
|
|
.value("XOR", SkPathOp::kXOR_SkPathOp)
|
|
|
|
.value("ReverseDifference", SkPathOp::kReverseDifference_SkPathOp);
|
2020-01-06 13:10:05 +00:00
|
|
|
#endif
|
2018-11-03 11:51:19 +00:00
|
|
|
|
2019-11-11 15:06:08 +00:00
|
|
|
enum_<SkCanvas::PointMode>("PointMode")
|
|
|
|
.value("Points", SkCanvas::PointMode::kPoints_PointMode)
|
|
|
|
.value("Lines", SkCanvas::PointMode::kLines_PointMode)
|
|
|
|
.value("Polygon", SkCanvas::PointMode::kPolygon_PointMode);
|
|
|
|
|
2018-11-26 16:47:54 +00:00
|
|
|
enum_<SkPaint::Cap>("StrokeCap")
|
|
|
|
.value("Butt", SkPaint::Cap::kButt_Cap)
|
|
|
|
.value("Round", SkPaint::Cap::kRound_Cap)
|
|
|
|
.value("Square", SkPaint::Cap::kSquare_Cap);
|
|
|
|
|
|
|
|
enum_<SkPaint::Join>("StrokeJoin")
|
|
|
|
.value("Miter", SkPaint::Join::kMiter_Join)
|
|
|
|
.value("Round", SkPaint::Join::kRound_Join)
|
|
|
|
.value("Bevel", SkPaint::Join::kBevel_Join);
|
|
|
|
|
2020-02-28 13:09:08 +00:00
|
|
|
#ifndef SK_NO_FONTS
|
|
|
|
enum_<SkFontHinting>("FontHinting")
|
|
|
|
.value("None", SkFontHinting::kNone)
|
|
|
|
.value("Slight", SkFontHinting::kSlight)
|
|
|
|
.value("Normal", SkFontHinting::kNormal)
|
|
|
|
.value("Full", SkFontHinting::kFull);
|
2020-05-07 20:25:41 +00:00
|
|
|
|
|
|
|
enum_<SkFont::Edging>("FontEdging")
|
|
|
|
#ifndef CANVASKIT_NO_ALIAS_FONT
|
|
|
|
.value("Alias", SkFont::Edging::kAlias)
|
|
|
|
#endif
|
|
|
|
.value("AntiAlias", SkFont::Edging::kAntiAlias)
|
|
|
|
.value("SubpixelAntiAlias", SkFont::Edging::kSubpixelAntiAlias);
|
2020-02-28 13:09:08 +00:00
|
|
|
#endif
|
2018-11-26 16:47:54 +00:00
|
|
|
|
2019-04-03 20:51:47 +00:00
|
|
|
enum_<SkTileMode>("TileMode")
|
|
|
|
.value("Clamp", SkTileMode::kClamp)
|
|
|
|
.value("Repeat", SkTileMode::kRepeat)
|
|
|
|
.value("Mirror", SkTileMode::kMirror)
|
|
|
|
.value("Decal", SkTileMode::kDecal);
|
2018-11-03 11:51:19 +00:00
|
|
|
|
|
|
|
enum_<SkVertices::VertexMode>("VertexMode")
|
|
|
|
.value("Triangles", SkVertices::VertexMode::kTriangles_VertexMode)
|
|
|
|
.value("TrianglesStrip", SkVertices::VertexMode::kTriangleStrip_VertexMode)
|
2018-11-26 16:47:54 +00:00
|
|
|
.value("TriangleFan", SkVertices::VertexMode::kTriangleFan_VertexMode);
|
2018-11-03 11:51:19 +00:00
|
|
|
|
2018-09-20 21:39:31 +00:00
|
|
|
// A value object is much simpler than a class - it is returned as a JS
|
|
|
|
// object and does not require delete().
|
2020-02-21 22:15:22 +00:00
|
|
|
// https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#value-types
|
2020-02-28 19:26:38 +00:00
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
value_object<SimpleImageInfo>("ImageInfo")
|
2020-05-26 17:10:20 +00:00
|
|
|
.field("width", &SimpleImageInfo::width)
|
|
|
|
.field("height", &SimpleImageInfo::height)
|
|
|
|
.field("colorType", &SimpleImageInfo::colorType)
|
|
|
|
.field("alphaType", &SimpleImageInfo::alphaType)
|
|
|
|
.field("colorSpace", &SimpleImageInfo::colorSpace);
|
2018-11-30 19:05:58 +00:00
|
|
|
|
2019-01-14 13:36:08 +00:00
|
|
|
value_object<StrokeOpts>("StrokeOpts")
|
|
|
|
.field("width", &StrokeOpts::width)
|
|
|
|
.field("miter_limit", &StrokeOpts::miter_limit)
|
|
|
|
.field("join", &StrokeOpts::join)
|
|
|
|
.field("cap", &StrokeOpts::cap)
|
|
|
|
.field("precision", &StrokeOpts::precision);
|
|
|
|
|
2019-01-07 16:08:55 +00:00
|
|
|
constant("MOVE_VERB", MOVE);
|
|
|
|
constant("LINE_VERB", LINE);
|
|
|
|
constant("QUAD_VERB", QUAD);
|
|
|
|
constant("CONIC_VERB", CONIC);
|
|
|
|
constant("CUBIC_VERB", CUBIC);
|
|
|
|
constant("CLOSE_VERB", CLOSE);
|
2019-10-29 14:48:26 +00:00
|
|
|
|
2019-12-17 21:05:02 +00:00
|
|
|
constant("SaveLayerInitWithPrevious", (int)SkCanvas::SaveLayerFlagsSet::kInitWithPrevious_SaveLayerFlag);
|
|
|
|
constant("SaveLayerF16ColorType", (int)SkCanvas::SaveLayerFlagsSet::kF16ColorType);
|
2019-10-29 14:48:26 +00:00
|
|
|
|
2021-01-07 16:14:13 +00:00
|
|
|
constant("ShadowTransparentOccluder", (int)SkShadowFlags::kTransparentOccluder_ShadowFlag);
|
|
|
|
constant("ShadowGeometricOnly", (int)SkShadowFlags::kGeometricOnly_ShadowFlag);
|
|
|
|
constant("ShadowDirectionalLight", (int)SkShadowFlags::kDirectionalLight_ShadowFlag);
|
2021-04-27 21:46:41 +00:00
|
|
|
|
2021-04-30 15:12:01 +00:00
|
|
|
constant("_GlyphRunFlags_isWhiteSpace", (int)skia::textlayout::Paragraph::kWhiteSpace_VisitorFlag);
|
2018-09-20 21:39:31 +00:00
|
|
|
}
|