blob: 892ecc08fa54bb3ea8b921a8e619627a2ee85bb9 [file] [log] [blame]
Nathaniel Nifonge5d32542020-03-26 09:27:48 -04001/*
2 * Copyright 2019 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef WasmCommon_DEFINED
9#define WasmCommon_DEFINED
10
11#include <emscripten.h>
12#include <emscripten/bind.h>
13#include "include/core/SkColor.h"
14
15using namespace emscripten;
16
17// Self-documenting types
18using JSArray = emscripten::val;
19using JSObject = emscripten::val;
20using JSString = emscripten::val;
21using SkPathOrNull = emscripten::val;
22using Uint8Array = emscripten::val;
23using Float32Array = emscripten::val;
24
25// A struct used for binding the TypedArray colors passed to to canvaskit functions.
26// Canvaskit functions returning colors return a Float32Array, which looks the same
27// on the javascript side.
28struct SimpleColor4f {
29 // A sensible but noticeable default value to let you know you've called the
30 // default constructor.
31 float r = 1.0;
32 float g = 0.0;
33 float b = 1.0;
34 float a = 1.0;
35
36 SkColor4f toSkColor4f() const {
37 return SkColor4f({r, g, b, a});
38 };
39 SkColor toSkColor() const {
40 return toSkColor4f().toSkColor();
41 };
42};
43
44#endif