OpenACG-Group / Cocoa

A general-purposed 2D rendering framework & visual novel engine.
https://openacg-group.github.io
GNU General Public License v3.0
3 stars 1 forks source link

Integrate CanvasKit and paint with it #3

Closed wait1210day closed 1 year ago

wait1210day commented 1 year ago

Track the process of CanvasKit integration.

wait1210day commented 1 year ago

The memory pressure problem is going to be solved in next commit by implementing a CanvasKitTransferContext and some hacks in Skia. Two deserialization modes will be provided when deserializing an SkPicture.

wait1210day commented 1 year ago

The memory pressure problem has been solved in this commit. This commit introduces some new interfaces to integrate CanvasKit with native code, and cache typefaces in JavaScript world. Those changes make us modify Skia's code and compile our own specialized canvaskit.wasm, which contains some new exposed functions. However, it seems that the memory usage still increases very slowly (not caused by typeface cache), which is caused by an unknown reason. We're try to solve this problem in the future.

wait1210day commented 1 year ago

The memory pressure problem has been solved in this commit. This commit introduces some new interfaces to integrate CanvasKit with native code, and cache typefaces in JavaScript world. Those changes make us modify Skia's code and compile our own specialized canvaskit.wasm, which contains some new exposed functions. However, it seems that the memory usage still increases very slowly (not caused by typeface cache), which is caused by an unknown reason. We're try to solve this problem in the future.

After many tests, that problem is completely not a bug. It is caused by a wrong usage of WASM memory. Skia CanvasKit requires us to explicitly delete the objects which are allocated by new or factory objects (see its official documentation). For example:

const paint = new canvaskit.Paint();
paint.delete();
wait1210day commented 1 year ago

CanvasKit has been deprecated.