Extend drawAtlas with optional sampling parameter
Change-Id: Id26f0d9ca5381da807b072c8b59745f2afd8df60
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386860
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Yegor Jbanov <yjbanov@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/modules/canvaskit/interface.js b/modules/canvaskit/interface.js
index f261e0e..65a0549 100644
--- a/modules/canvaskit/interface.js
+++ b/modules/canvaskit/interface.js
@@ -479,7 +479,8 @@
// a Flat Float32Array of float colors or a 2d Array of Float32Array(4) (deprecated)
// TODO(kjlubick) remove Builders - no longer needed now that Malloc is a thing.
CanvasKit.Canvas.prototype.drawAtlas = function(atlas, srcRects, dstXforms, paint,
- /*optional*/ blendMode, colors) {
+ /* optional */ blendMode, /* optional */ colors,
+ /* optional */ sampling) {
if (!atlas || !paint || !srcRects || !dstXforms) {
Debug('Doing nothing since missing a required input');
return;
@@ -523,7 +524,28 @@
}
}
- this._drawAtlas(atlas, dstXformPtr, srcRectPtr, colorPtr, count, blendMode, paint);
+ // We require one of these:
+ // 1. sampling is null (we default to linear/none)
+ // 2. sampling.B and sampling.C --> CubicResampler
+ // 3. sampling.filter [and sampling.mipmap] --> FilterOptions
+ //
+ // Thus if all fields are available, we will choose cubic (since we search for B,C first)
+
+ if (sampling && ('B' in sampling) && ('C' in sampling)) {
+ this._drawAtlasCubic(atlas, dstXformPtr, srcRectPtr, colorPtr, count, blendMode,
+ sampling['B'], sampling['C'], paint);
+ } else {
+ let filter = CanvasKit.FilterMode.Linear;
+ let mipmap = CanvasKit.MipmapMode.None;
+ if (sampling) {
+ filter = sampling['filter']; // 'filter' is a required field
+ if ('mipmap' in sampling) { // 'mipmap' is optional
+ mipmap = sampling['mipmap'];
+ }
+ }
+ this._drawAtlasOptions(atlas, dstXformPtr, srcRectPtr, colorPtr, count, blendMode,
+ filter, mipmap, paint);
+ }
if (srcRectPtr && !srcRects.build) {
freeArraysThatAreNotMallocedByUsers(srcRectPtr, srcRects);