| Nathaniel Nifong | e5d3254 | 2020-03-26 09:27:48 -0400 | [diff] [blame^] | 1 | /* |
| 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 | |
| 15 | using namespace emscripten; |
| 16 | |
| 17 | // Self-documenting types |
| 18 | using JSArray = emscripten::val; |
| 19 | using JSObject = emscripten::val; |
| 20 | using JSString = emscripten::val; |
| 21 | using SkPathOrNull = emscripten::val; |
| 22 | using Uint8Array = emscripten::val; |
| 23 | using 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. |
| 28 | struct 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 |