[canvaskit] Exposed SkPath::arc. Exposed SkEncodedImageFormat enum. Exposed SkImage::encodeToData overload with arguments
These changes expose the arc function for SkPath. The ApplyAddArc function is a copy from the PathKit bindings. Also exposed the PNG and JPEG formats from the SkEncodedImageFormat enum and the SkImage::encodeToData overload that accepts format and quality options. The direct binding of encodeToData was replaced with a pre-js wrapper that calls the appropriate private overload We are working on a PostCSS conic gradient polyfill plugin and want to use the CanvasKit to generate it. Problem is - it lacks the arc function that technically exists but isn't exposed. And it would be really great to have encodeToData with options since generated PNGs are quite large. More details on the issue can be found here: https://github.com/jonathantneal/postcss-conic-gradient/issues/10 R=kjlubick@google.com Bug: skia: Change-Id: I3f1dc88ad308369fe62004080bcc196c4fbbf742 Reviewed-on: https://skia-review.googlesource.com/c/171046 Reviewed-by: Kevin Lubick <kjlubick@google.com> Commit-Queue: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
parent
3da725065a
commit
3e11933765
1
AUTHORS
1
AUTHORS
@ -51,3 +51,4 @@ Adobe Systems Incorporated <*@adobe.com>
|
||||
Yandex LLC <*@yandex-team.ru>
|
||||
Kaloyan Donev <kdonev@gmail.com>
|
||||
Yong-Hwan Baek <meisterdevhwan@gmail.com>
|
||||
Alexander Khovansky <alx.khovansky@gmail.com>
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "SkDashPathEffect.h"
|
||||
#include "SkData.h"
|
||||
#include "SkDiscretePathEffect.h"
|
||||
#include "SkEncodedImageFormat.h"
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkFontMgrPriv.h"
|
||||
#include "SkGradientShader.h"
|
||||
@ -160,6 +161,15 @@ void ApplyAddPath(SkPath& orig, const SkPath& newPath,
|
||||
orig.addPath(newPath, m);
|
||||
}
|
||||
|
||||
void ApplyAddArc(SkPath& path, SkScalar x, SkScalar y, SkScalar radius,
|
||||
SkScalar startAngle, SkScalar endAngle, bool ccw) {
|
||||
SkPath temp;
|
||||
SkRect bounds = SkRect::MakeLTRB(x-radius, y-radius, x+radius, y+radius);
|
||||
const auto sweep = SkRadiansToDegrees(endAngle - startAngle) - 360 * ccw;
|
||||
temp.addArc(bounds, SkRadiansToDegrees(startAngle), sweep);
|
||||
path.addPath(temp, SkPath::kExtend_AddPathMode);
|
||||
}
|
||||
|
||||
void ApplyArcTo(SkPath& p, SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
|
||||
SkScalar radius) {
|
||||
p.arcTo(x1, y1, x2, y2, radius);
|
||||
@ -452,7 +462,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
|
||||
class_<SkImage>("SkImage")
|
||||
.smart_ptr<sk_sp<SkImage>>("sk_sp<SkImage>")
|
||||
.function("encodeToData", select_overload<sk_sp<SkData>()const>(&SkImage::encodeToData));
|
||||
.function("_encodeToData", select_overload<sk_sp<SkData>()const>(&SkImage::encodeToData))
|
||||
.function("_encodeToDataWithFormat", select_overload<sk_sp<SkData>(SkEncodedImageFormat encodedImageFormat, int quality)const>(&SkImage::encodeToData));
|
||||
|
||||
class_<SkPaint>("SkPaint")
|
||||
.constructor<>()
|
||||
@ -486,6 +497,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
.constructor<const SkPath&>()
|
||||
// interface.js has 3 overloads of addPath
|
||||
.function("_addPath", &ApplyAddPath)
|
||||
.function("_arc", &ApplyAddArc)
|
||||
.function("_arcTo", &ApplyArcTo)
|
||||
.function("_close", &ApplyClose)
|
||||
.function("_conicTo", &ApplyConicTo)
|
||||
@ -608,6 +620,10 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
.value("TrianglesStrip", SkVertices::VertexMode::kTriangleStrip_VertexMode)
|
||||
.value("TriangleFan", SkVertices::VertexMode::kTriangleFan_VertexMode);
|
||||
|
||||
enum_<SkEncodedImageFormat>("ImageFormat")
|
||||
.value("PNG", SkEncodedImageFormat::kPNG)
|
||||
.value("JPEG", SkEncodedImageFormat::kJPEG);
|
||||
|
||||
|
||||
// A value object is much simpler than a class - it is returned as a JS
|
||||
// object and does not require delete().
|
||||
|
@ -85,7 +85,9 @@ var CanvasKit = {
|
||||
},
|
||||
|
||||
SkImage: {
|
||||
encodeToData: function() {},
|
||||
// private API
|
||||
_encodeToData: function() {},
|
||||
_encodeToDataWithFormat: function() {},
|
||||
},
|
||||
|
||||
SkPath: {
|
||||
@ -93,6 +95,7 @@ var CanvasKit = {
|
||||
|
||||
// private API
|
||||
_addPath: function() {},
|
||||
_arc: function() {},
|
||||
_arcTo: function() {},
|
||||
_close: function() {},
|
||||
_conicTo: function() {},
|
||||
@ -174,6 +177,11 @@ var CanvasKit = {
|
||||
INVERSE_EVENODD: {},
|
||||
},
|
||||
|
||||
ImageFormat: {
|
||||
PNG: {},
|
||||
JPEG: {},
|
||||
},
|
||||
|
||||
// Things Enscriptem adds for us
|
||||
|
||||
/** Represents the heap of the WASM code
|
||||
@ -206,6 +214,7 @@ var CanvasKit = {
|
||||
// It's not enough to declare them above, because closure can still erase them
|
||||
// unless they go on the prototype.
|
||||
CanvasKit.SkPath.prototype.addPath = function() {};
|
||||
CanvasKit.SkPath.prototype.arc = function() {};
|
||||
CanvasKit.SkPath.prototype.arcTo = function() {};
|
||||
CanvasKit.SkPath.prototype.close = function() {};
|
||||
CanvasKit.SkPath.prototype.conicTo = function() {};
|
||||
@ -226,6 +235,8 @@ CanvasKit.SkSurface.prototype.dispose = function() {};
|
||||
|
||||
CanvasKit.SkVertices.prototype.applyBones = function() {};
|
||||
|
||||
CanvasKit.SkImage.prototype.encodeToData = function() {};
|
||||
|
||||
// Define StrokeOpts object
|
||||
var StrokeOpts = {};
|
||||
StrokeOpts.prototype.width;
|
||||
|
@ -40,6 +40,11 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
CanvasKit.SkPath.prototype.arc = function(x, y, radius, startAngle, endAngle, ccw) {
|
||||
this._arc(x, y, radius, startAngle, endAngle, !!ccw);
|
||||
return this;
|
||||
};
|
||||
|
||||
CanvasKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {
|
||||
this._arcTo(x1, y1, x2, y2, radius);
|
||||
return this;
|
||||
@ -153,6 +158,19 @@
|
||||
return vert;
|
||||
}
|
||||
|
||||
CanvasKit.SkImage.prototype.encodeToData = function() {
|
||||
if (arguments.length === 0) {
|
||||
return this._encodeToData();
|
||||
}
|
||||
|
||||
if (arguments.length === 2) {
|
||||
var a = arguments;
|
||||
return this._encodeToDataWithFormat(a[0], a[1]);
|
||||
}
|
||||
|
||||
throw 'encodeToData expected to take 0 or 2 arguments. Got ' + arguments.length;
|
||||
}
|
||||
|
||||
// Run through the JS files that are added at compile time.
|
||||
if (CanvasKit._extraInitializations) {
|
||||
CanvasKit._extraInitializations.forEach(function(init) {
|
||||
|
Loading…
Reference in New Issue
Block a user