Commit Graph

25 Commits

Author SHA1 Message Date
Kevin Lubick
7ce380e967 [canvaskit] Remove deprecated MakeTypefaceFromData and RefDefault
Change-Id: I0072fa5c11834a6250f2f5b9290ecea0d30f2128
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/462177
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
2021-10-21 16:45:42 +00:00
Harry Terkelsen
1cb3f3666c Don't free the locale pointer in a paragraph style.
The locale is malloc'ed using `cacheOrCopyString`, which should never
be explicitly freed.

Change-Id: I6a911c52f1f485b34fad86303a1f4be199195858
Cq-Include-Trybots: luci.skia.skia.primary:Test-Debian10-EMCC-GCE-CPU-AVX2-wasm-Release-All-CanvasKit,Test-Debian10-EMCC-GCE-GPU-AVX2-wasm-Release-All-CanvasKit
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/459835
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2021-10-15 22:14:34 +00:00
Harry Terkelsen
e5d23f0b1f [canvaskit] Fix incorrect malloc for text style shadows
Change-Id: Id0de9a3a557dc712d947a80f0bc7333122773870
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/416687
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2021-06-16 12:34:06 +00:00
Mike Reed
c48c3e5d57 Try new factory for ShapedLines
Known hacks for now:
- only default typeface
- only ascii support

Fonts have several limitations for now.

SkParagraph (our temporary backend) wants a fontmgr up front,
rather than just relying on the typefaces in its styles. This makes it
hard to inter-op with our JS api. Not a long-term problem, as this
backend is short-term. The hacky work-around is just to pass NULL for
the typeface for now.

Related but different, I haven't yet figured out how to "return" a
JS Typeface object. Something about bare-pointers and sk_sp. I'll figure
it out eventually, but for now I just set the output slot to null
as well. (there's a TODO in the .cpp)

Ascii support

JS strings are UTF16 (afaik). However, our current backend thinks in
terms of UTF8 offsets. Plus, (at the moment) when I try to access the
JS string for C++, it coerces to utf8 (std::string).

We can fix both of these eventually, but for now I'll just test with
ascii input characters, and the API can still work.


Change-Id: I62ca71b0b45d017ac8e3881c06720776dc2d75a1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/405400
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Julia Lavrova <jlavrova@google.com>
2021-05-06 23:01:47 +00:00
Kevin Lubick
4755b0b525 [canvaskit] Add TextHeightBehavior
Bug: skia:11881
Change-Id: I220f5ad43de95324172ee5b6d3d5a975a3f8a166
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/399836
Reviewed-by: Julia Lavrova <jlavrova@google.com>
2021-04-22 18:21:44 +00:00
weiyuhuang
04c82165b1 [canvaskit] Add halfLeading to TextStyle and StrutStyle
- Add halfLeading (introduced in https://skia-review.googlesource.com/c/skia/+/394969) to canvaskit bindings

- Fix wrong initial value of fDescent

Change-Id: I01d522cd5a3761f32426038dce2ab82f24c9c529
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398276
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2021-04-20 20:21:56 +00:00
Kevin Lubick
e7c1a731ff [canvaskit] Remove 2d point arrays from API.
I kept in an array of Color (Float32Array) because it's very convenient
and not worth the hassle of removing.

Change-Id: I34c430c2b5112b6d073b049a81994e946428f21c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340797
Reviewed-by: Nathaniel Nifong <nifong@google.com>
2020-12-07 11:09:49 +00:00
Kevin Lubick
54c1b3dd43 [canvaskit] Remove Sk from nearly all function/type names.
This is a massive breaking change for all existing users of CanvasKit.

It will be (one of the only) changes in 0.19.0 to make the transition
easier.

Suggested reviewing order:
 - index.d.ts (to see type changes). Notice SkPicture still has Sk
   prefix, but no other types do (this felt "right" since Sk is
   part of the name of the type, but I can be swayed on this).
 - canvaskit-wasm-tests.ts
 - tests/*.spec.js
 - interface.js and helper.js
 - html examples
 - markdown files

Change-Id: I3b3d3815df2078f986893df3c70101d6248c117d
Docs-Preview: https://skia.org/?cl=322617
Bug: skia:10717
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322617
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Nathaniel Nifong <nifong@google.com>
2020-10-07 21:01:32 +00:00
Kevin Lubick
c488fd3d01 [canvaskit] Add docs/types for paragraph
The docs on the C++ side are not complete in some areas, so
these docs are incomplete as well.

Bug: skia:10717
Change-Id: I1cbb559ab5c8b3973686b85f420ccd9752eaa24d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322321
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2020-10-06 12:33:46 +00:00
Harry Terkelsen
223ffcdff9 Add more paragraph bindings to CanvasKit
Change-Id: Ib02b6504724e4d7cfa197a3508f8c0b84b4135bf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313146
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Yegor Jbanov <yjbanov@google.com>
Auto-Submit: Harry Terkelsen <het@google.com>
2020-10-04 12:56:57 +00:00
Harry Terkelsen
10f019c506 [CanvasKit] Expose TypefaceFontProvider.
Change-Id: I950a3a4f45b7b4a106299576bc918531054b23f6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307873
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2020-08-04 20:55:21 +00:00
Nathaniel Nifong
e09b314405 Add ParagraphBuilder.pushPaintStyle to allow text to be colors with paints.
Previously one could not color text with paints, even though TextStyle's foregroundColor and
backgroundColor fields are SkPaints. Canvaskit only exposed these as colors in order to allow
SimpleTextStyle to be a value object that would not have to be deleted by the user.

CanvasKit.Paint is a bound SkPaint. I wanted to allow a user to pass a paint to be used
in a text style without alterting SimpleTextStyle's status as a value-object.

So I've added a new bound method, pushPaintStyle which acts just like pushStyle but allows
a foreground and background paint to be supplied which are used to override the existing paints.

The user is responsible for deleting these paints.

Sorry for the kludgy design, if you have got a more elegant way, I'm open to suggestions.

Change-Id: Ib78464171346fe9f717f6d5b9d9428b1d0278498
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307596
Commit-Queue: Nathaniel Nifong <nifong@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Julia Lavrova <jlavrova@google.com>
2020-08-04 13:23:06 +00:00
Kevin Lubick
261333283e [canvaskit] Fix bug with TextStyle color
This updates an existing test and adds a new one to make
sure we don't regress.

Change-Id: If94eb3fb205852750d6fb9483e20c07d88b4da10
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295560
Reviewed-by: Nathaniel Nifong <nifong@google.com>
2020-06-12 15:40:13 +00:00
Kevin Lubick
69e46da716 [canvaskit] Fix infrequent crash in SkFontMgr.FromData
The bug here is very subtle, as is the mitigation.

Quick background on WASM memory, there is an object
called wasmMemory (which might be hoisted into scope for
CanvasKit's pre-js functions), of type WebAssembly.Memory
which is a resizable ArrayBuffer. Emscripten provides the
JS code to initialize this and handle size increases.
Emscripten also provides TypedArray "views" into this buffer.
These are called CanvasKit.HEAPU8, CanvasKit.HEAPF32, etc.

When there is a call to CanvasKit._malloc, wasmMemory may
be resized. If that happens, the previous TypedArray views
become invalid. However, in the same call to _malloc,
emscripten will refresh the views [1]. So, dealing with
CanvasKit.HEAPU8 directly (quick aside, we never expect clients
to mess with these views, only us in our glue JS code
[e.g. interface.js]), should always be safe because if they
were to be invalidated in a call to _malloc, the views would
be refreshed before _malloc continues.

The problem that existed before was when we were passing
CanvasKit.HEAP* as a parameter to a function, in which the
function would call _malloc before using the typed array
parameter:
  //... let us suppose wasmMemory is backed by ArrayBuffer D
  copy1dArray(arr, HEAPU32);
  // The HEAPU32 TypedArray (backed by ArrayBuffer D) is stored
  // to a function parameter "dest"
    function copy1dArray(arr, dest, ptr) {
    // ...
    if (!ptr) {
      ptr = CanvasKit._malloc(arr.length * dest.BYTES_PER_ELEMENT);
      // Suppose _malloc needs to resize wasmMemory and is
      // now backed by ArrayBuffer E.
      // Note: The field CanvasKit.HEAPU32 is correctly backed
      // by ArrayBuffer E, but variable dest still points to a
      // TypedArray backed by ArrayBuffer D.
    }
    // dest.set will fail with a "neutered ArrayBuffer" error
    // because ArrayBuffer D is effectively gone (replaced by E).
    dest.set(arr, ptr / dest.BYTES_PER_ELEMENT);

The fix here is to pass in the field name indicating the TypedArray
view we want to write our data into instead of using the
view itself as the parameter.

[1] e427159553/src/preamble.js (L344)


Change-Id: I46cfb98f8bdf928b61690a5ced034a5961356398
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294516
Reviewed-by: Nathaniel Nifong <nifong@google.com>
2020-06-05 13:32:46 +00:00
Kevin Lubick
6aa3869f76 [canvaskit] Use scratch arrays for colors and matrices
At startup, we allocate a few scratch arrays and then use those
instead of having to malloc and free a bunch of arrays during
runtime.

The benchmark that was added is a bit noisy (probably because
of the garbage collection going on from the created Float32Arrays),
but a few percent faster.

We also don't set the paragraph background/foreground colors to
transparent because we check them being falsey before sending them
over the wire. I noticed that if foreground was transparent black,
no text shows up at all, which was unexpected.

Change-Id: I9f3a590a122d7de222cb5f58ea40e86b2d261c96
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292685
Reviewed-by: Nathaniel Nifong <nifong@google.com>
2020-06-01 15:47:07 +00:00
Nathaniel Nifong
59d299ba3f Record code coverage in canvaskit tests, increase coverage
Fix a bug with paragraph text direction that an incorrect unit test wasn't detecting.

Change-Id: I73418ea8a90da097078d93ddf8692a55488f672f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292366
Commit-Queue: Nathaniel Nifong <nifong@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2020-05-29 15:53:35 +00:00
Kevin Lubick
cf11892ab2 [canvaskit] Do not automatically free things provided by Malloc.
If ever CanvasKit accepts an array as a parameter, if the array
provided was produced by Malloc, CanvasKit will use the pointer
of that array and not free it after.

Change-Id: I4806a48e5e030edd787944f652984ea3516b3022
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292561
Reviewed-by: Nathaniel Nifong <nifong@google.com>
2020-05-28 19:45:52 +00:00
Kevin Lubick
0c8884b6b4 [canvaskit] Fix memory leak in paragraph bindings
This also renames some variables to be consistent.

See https://github.com/flutter/flutter/issues/56938

Change-Id: I0db66fa334d5f5efc1f94fff1a367a32e03611ca
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/289778
Reviewed-by: Nathaniel Nifong <nifong@google.com>
2020-05-14 14:48:21 +00:00
Nathaniel Nifong
1bedbeb081 Pass 4f colors to private functions with float pointers
Change-Id: I4534a246c37870750298d39edcbc869781dc1008
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/286880
Commit-Queue: Nathaniel Nifong <nifong@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2020-05-05 13:17:28 +00:00
Nathaniel Nifong
e5d3254ece Reland "Switch to using a Float32Array (bound as value array) for color."
This is a reland of 4e79b6730d

Original change's description:
> Switch to using a Float32Array (bound as value array) for color.
> 
> Change-Id: I1bcca931954b1399c79f4074a3d57a68847ac785
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276757
> Commit-Queue: Nathaniel Nifong <nifong@google.com>
> Reviewed-by: Kevin Lubick <kjlubick@google.com>

Change-Id: If6b9097b2fcd6b9dbf75c6dd22138e0b2531e70d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/278780
Commit-Queue: Nathaniel Nifong <nifong@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2020-03-26 14:41:29 +00:00
Robert Phillips
cb77eab343 Revert "Switch to using a Float32Array (bound as value array) for color."
This reverts commit 4e79b6730d.

Reason for revert: Bad canvaskit GM images

Original change's description:
> Switch to using a Float32Array (bound as value array) for color.
> 
> Change-Id: I1bcca931954b1399c79f4074a3d57a68847ac785
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276757
> Commit-Queue: Nathaniel Nifong <nifong@google.com>
> Reviewed-by: Kevin Lubick <kjlubick@google.com>

TBR=kjlubick@google.com,nifong@google.com

Change-Id: I2f5e995ccee415a49f813b5ba61c095acbc445b5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/278766
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-03-24 14:20:04 +00:00
Nathaniel Nifong
4e79b6730d Switch to using a Float32Array (bound as value array) for color.
Change-Id: I1bcca931954b1399c79f4074a3d57a68847ac785
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276757
Commit-Queue: Nathaniel Nifong <nifong@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2020-03-24 13:32:55 +00:00
Kevin Lubick
4a5f4f26f6 [canvaskit] Include direction from getRects
Change-Id: Iab27d2c9fa602be0bb1f9125eef0e4271b9d5874
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/255306
Reviewed-by: Julia Lavrova <jlavrova@google.com>
2019-11-20 13:27:22 +00:00
Kevin Lubick
d3b1fe66d6 [CanvasKit] More Paragraph things
Bug: skia:9469
Change-Id: I72a4912b5b6edd2ddde077a558c2c24b68d7df64
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249556
Reviewed-by: Julia Lavrova <jlavrova@google.com>
2019-10-21 15:27:13 +00:00
Kevin Lubick
369f6a5ea2 [canvaskit] Initial addition of SkParagraph
There are more parts of ParagraphStyle and TextStyle, but
this should be a bulk of the components.

Bug: skia:9469
Change-Id: I87fff6700f41cff49ecbee3a1339e84c36699c93
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/244837
Reviewed-by: Julia Lavrova <jlavrova@google.com>
2019-10-03 18:04:55 +00:00