Add SkFloat2Bits and Region stub

Bug: skia:
Change-Id: I5ab9a4d42e9eec6563499a09e08ed8b183ac91b2
Reviewed-on: https://skia-review.googlesource.com/141426
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
diff --git a/experimental/wasm/compile.sh b/experimental/wasm/compile.sh
index d2e7098..cb89019 100755
--- a/experimental/wasm/compile.sh
+++ b/experimental/wasm/compile.sh
@@ -27,10 +27,14 @@
 em++ -Oz -std=c++14 \
 -Iinclude/config \
 -Iinclude/core \
--Iinclude/private \
+-Iinclude/gpu \
 -Iinclude/pathops \
+-Iinclude/private \
 -Iinclude/utils \
 -Isrc/core \
+-Isrc/gpu \
+-Isrc/shaders \
+-Isrc/opts \
 --bind \
 -s WASM=1 \
 -s NO_EXIT_RUNTIME=1 \
@@ -39,15 +43,27 @@
 --shell-file $HTML_SHELL \
 -o out/wasm/pathkit.html \
 experimental/wasm/wasm_main.cpp \
+src/core/SkAnalyticEdge.cpp \
 src/core/SkArenaAlloc.cpp \
+src/core/SkBlitter.cpp \
+src/core/SkCoverageDelta.cpp \
+src/core/SkEdge.cpp \
+src/core/SkEdgeBuilder.cpp \
+src/core/SkEdgeClipper.cpp \
+src/core/SkFDot6Constants.cpp \
 src/core/SkGeometry.cpp \
+src/core/SkLineClipper.cpp \
 src/core/SkMallocPixelRef.cpp \
 src/core/SkMath.cpp \
 src/core/SkMatrix.cpp \
+src/core/SkOpts.cpp \
 src/core/SkPath.cpp \
 src/core/SkPathRef.cpp \
 src/core/SkPoint.cpp \
 src/core/SkRect.cpp \
+src/core/SkRegion.cpp \
+src/core/SkRegion_path.cpp \
+src/core/SkScan_Path.cpp \
 src/core/SkStream.cpp \
 src/core/SkString.cpp \
 src/core/SkStringUtils.cpp \
diff --git a/experimental/wasm/shell.html b/experimental/wasm/shell.html
index 8557241..f38429c 100644
--- a/experimental/wasm/shell.html
+++ b/experimental/wasm/shell.html
@@ -424,6 +424,40 @@
         document.getElementById('svg').appendChild(newPath);
 
         android2.delete();
+
+        // ===========================================================
+
+        let float = Module.SkBits2Float(parseInt("0x3f2aaaab"));
+        Module.print('SkBits2Float(0x3f2aaaab) = 0.666667', float);
+
+        p1 = new Module.SkPath();
+        p1.moveTo(0,60);
+        p1.lineTo(40,60);
+        p1.lineTo(20,80);
+        p1.close();
+        p2 = new Module.SkPath();
+        p2.moveTo(20,60);
+        p2.lineTo(60,60);
+        p2.lineTo(40,80);
+        p2.close();
+
+        let rgnA = new Module.SkRegion();
+        let rgnB = new Module.SkRegion();
+        let openClip = new Module.SkRegion();
+        let rgnOut = new Module.SkRegion();
+        openClip.setRect(-16000, -16000, 16000, 16000);
+        rgnA.setPath(p1, openClip);
+        rgnB.setPath(p2, openClip);
+        rgnOut.opRegionAB(rgnA, rgnB, Module.RegionOp.INTERSECT);
+        let pathOut = Module.GetBoundaryPathFromRegion(rgnOut);
+
+        p1.delete();
+        p2.delete();
+        rgnA.delete();
+        rgnB.delete();
+        openClip.delete();
+        rgnOut.delete();
+        pathOut.delete();
       }
     </script>
     <script type='text/javascript'>
diff --git a/experimental/wasm/wasm_main.cpp b/experimental/wasm/wasm_main.cpp
index a2876d9..ab68b79 100644
--- a/experimental/wasm/wasm_main.cpp
+++ b/experimental/wasm/wasm_main.cpp
@@ -5,10 +5,12 @@
  * found in the LICENSE file.
  */
 
+#include "SkFloatBits.h"
 #include "SkFloatingPoint.h"
 #include "SkParsePath.h"
 #include "SkPath.h"
 #include "SkPathOps.h"
+#include "SkRegion.h"
 #include "SkString.h"
 
 #include <emscripten/emscripten.h>
@@ -309,6 +311,16 @@
     return retVal;
 }
 
+//========================================================================================
+// Region things
+//========================================================================================
+
+SkPath GetBoundaryPathFromRegion(SkRegion region) {
+    SkPath p;
+    region.getBoundaryPath(&p);
+    return p;
+}
+
 // Binds the classes to the JS
 EMSCRIPTEN_BINDINGS(skia) {
     class_<SkPath>("SkPath")
@@ -322,15 +334,30 @@
             select_overload<void(SkScalar, SkScalar, SkScalar, SkScalar)>(&SkPath::quadTo))
         .function("cubicTo",
             select_overload<void(SkScalar, SkScalar, SkScalar, SkScalar, SkScalar, SkScalar)>(&SkPath::cubicTo))
-        .function("close", &SkPath::close);
+        .function("close", &SkPath::close)
         // Uncomment below for debugging.
-        //.function("dump", select_overload<void() const>(&SkPath::dump));
+        .function("dump", select_overload<void() const>(&SkPath::dump));
 
     class_<SkOpBuilder>("SkOpBuilder")
         .constructor<>()
 
         .function("add", &SkOpBuilder::add);
 
+    class_<SkRegion>("SkRegion")
+        .constructor<>()
+
+        .function("setRect",
+            select_overload<bool(int32_t, int32_t, int32_t, int32_t)>(&SkRegion::setRect))
+        .function("setPath", &SkRegion::setPath)
+        .function("opLTRB",
+            select_overload<bool(int32_t, int32_t, int32_t, int32_t, SkRegion::Op)>(&SkRegion::op))
+        .function("opRegion",
+            select_overload<bool(const SkRegion&, SkRegion::Op)>(&SkRegion::op))
+        .function("opRegionAB",
+            select_overload<bool(const SkRegion&, const SkRegion&, SkRegion::Op)>(&SkRegion::op))
+        ;
+
+
     // Without this, module._ToPath2D (yes with an underscore)
     // would be exposed, but be unable to correctly handle the SkPath type.
     function("ToPath2D", &ToPath2D);
@@ -347,6 +374,10 @@
     function("ApplyPathOp", &ApplyPathOp);
     function("ResolveBuilder", &ResolveBuilder);
 
+    function("SkBits2Float", &SkBits2Float);
+
+    function("GetBoundaryPathFromRegion", &GetBoundaryPathFromRegion);
+
     enum_<SkPathOp>("PathOp")
         .value("DIFFERENCE",         SkPathOp::kDifference_SkPathOp)
         .value("INTERSECT",          SkPathOp::kIntersect_SkPathOp)
@@ -354,6 +385,14 @@
         .value("XOR",                SkPathOp::kXOR_SkPathOp)
         .value("REVERSE_DIFFERENCE", SkPathOp::kReverseDifference_SkPathOp);
 
+    enum_<SkRegion::Op>("RegionOp")
+        .value("DIFFERENCE",         SkRegion::Op::kDifference_Op)
+        .value("INTERSECT",          SkRegion::Op::kIntersect_Op)
+        .value("UNION",              SkRegion::Op::kUnion_Op)
+        .value("XOR",                SkRegion::Op::kXOR_Op)
+        .value("REVERSE_DIFFERENCE", SkRegion::Op::kReverseDifference_Op)
+        .value("REPLACE",            SkRegion::Op::kReplace_Op);
+
     constant("MOVE_VERB",  MOVE);
     constant("LINE_VERB",  LINE);
     constant("QUAD_VERB",  QUAD);