[canvaskit] Add frame duration and docs
Also clean up some more findMarkedCTM references. Change-Id: I29a52e1157691c86992e70a3774b984e5383e3ee Reviewed-on: https://skia-review.googlesource.com/c/skia/+/482005 Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Yegor Jbanov <yjbanov@google.com>
This commit is contained in:
parent
3374bcb68a
commit
44c81d1492
@ -9,10 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Breaking
|
||||
- `Canvas.drawVertices` and `Canvas.drawPatch` treat the default blend mode differently.
|
||||
See https://bugs.chromium.org/p/skia/issues/detail?id=12662.
|
||||
- `Canvas.markCTM` and `Canvas.findMarkedCTM` have been removed. They were effectively no-ops.
|
||||
|
||||
### Added
|
||||
- Rough implementation of `measureText` to Canvas2D emulation layer. For accurate numbers, clients
|
||||
should use a real shaping library, like SkParagraph.
|
||||
- `AnimatedImage.currentFrameDuration` has been added, as well as some clarifying documentation.
|
||||
|
||||
## [0.31.0] - 2021-11-16
|
||||
|
||||
|
@ -896,6 +896,7 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
|
||||
class_<SkAnimatedImage>("AnimatedImage")
|
||||
.smart_ptr<sk_sp<SkAnimatedImage>>("sk_sp<AnimatedImage>")
|
||||
.function("currentFrameDuration", &SkAnimatedImage::currentFrameDuration)
|
||||
.function("decodeNextFrame", &SkAnimatedImage::decodeNextFrame)
|
||||
.function("getFrameCount", &SkAnimatedImage::getFrameCount)
|
||||
.function("getRepetitionCount", &SkAnimatedImage::getRepetitionCount)
|
||||
|
@ -249,7 +249,6 @@ var CanvasKit = {
|
||||
drawText: function() {},
|
||||
drawTextBlob: function() {},
|
||||
drawVertices: function() {},
|
||||
findMarkedCTM: function() {},
|
||||
getLocalToDevice: function() {},
|
||||
getTotalMatrix: function() {},
|
||||
readPixels: function() {},
|
||||
@ -292,7 +291,6 @@ var CanvasKit = {
|
||||
_drawSimpleText: function() {},
|
||||
_drawTextBlob: function() {},
|
||||
_drawVertices: function() {},
|
||||
_findMarkedCTM: function() {},
|
||||
_getLocalToDevice: function() {},
|
||||
_getTotalMatrix: function() {},
|
||||
_readPixels: function() {},
|
||||
|
@ -769,17 +769,6 @@ CanvasKit.onRuntimeInitialized = function() {
|
||||
return copy4x4MatrixFromWasm(_scratch4x4MatrixPtr);
|
||||
};
|
||||
|
||||
// findMarkedCTM returns a 4x4 matrix, or null if a matrix was not found at
|
||||
// the provided marker.
|
||||
CanvasKit.Canvas.prototype.findMarkedCTM = function(marker) {
|
||||
// _getLocalToDevice will copy the values into the pointer.
|
||||
var found = this._findMarkedCTM(marker, _scratch4x4MatrixPtr);
|
||||
if (!found) {
|
||||
return null;
|
||||
}
|
||||
return copy4x4MatrixFromWasm(_scratch4x4MatrixPtr);
|
||||
};
|
||||
|
||||
// getTotalMatrix returns the current matrix as a 3x3 matrix.
|
||||
CanvasKit.Canvas.prototype.getTotalMatrix = function() {
|
||||
// _getTotalMatrix will copy the values into the pointer.
|
||||
|
@ -65,6 +65,7 @@ function animatedImageTests(CK: CanvasKit) {
|
||||
const r = img.getRepetitionCount(); // $ExpectType number
|
||||
const h = img.height(); // $ExpectType number
|
||||
const still = img.makeImageAtCurrentFrame(); // $ExpectType Image | null
|
||||
const ms = img.currentFrameDuration(); // $ExpectType number
|
||||
img.reset();
|
||||
const w = img.width(); // $ExpectType number
|
||||
}
|
||||
|
10
modules/canvaskit/npm_build/types/index.d.ts
vendored
10
modules/canvaskit/npm_build/types/index.d.ts
vendored
@ -303,6 +303,9 @@ export interface CanvasKit {
|
||||
/**
|
||||
* Decodes the given bytes into an animated image. Returns null if the bytes were invalid.
|
||||
* The passed in bytes will be copied into the WASM heap, so the caller can dispose of them.
|
||||
*
|
||||
* The returned AnimatedImage will be "pointing to" the first frame, i.e. currentFrameDuration
|
||||
* and makeImageAtCurrentFrame will be referring to the first frame.
|
||||
* @param bytes
|
||||
*/
|
||||
MakeAnimatedImageFromEncoded(bytes: Uint8Array | ArrayBuffer): AnimatedImage | null;
|
||||
@ -1015,7 +1018,12 @@ export interface SkSLUniform {
|
||||
*/
|
||||
export interface AnimatedImage extends EmbindObject<AnimatedImage> {
|
||||
/**
|
||||
* Decodes the next frame. Returns -1 when the animation is on the last frame.
|
||||
* Returns the length of the current frame in ms.
|
||||
*/
|
||||
currentFrameDuration(): number;
|
||||
/**
|
||||
* Decodes the next frame. Returns the length of that new frame in ms.
|
||||
* Returns -1 when the animation is on the last frame.
|
||||
*/
|
||||
decodeNextFrame(): number;
|
||||
|
||||
|
@ -172,6 +172,7 @@ describe('Core canvas behavior', () => {
|
||||
expect(aImg.width()).toEqual(320);
|
||||
expect(aImg.height()).toEqual(240);
|
||||
expect(aImg.getFrameCount()).toEqual(60);
|
||||
expect(aImg.currentFrameDuration()).toEqual(60);
|
||||
|
||||
const drawCurrentFrame = function(x, y) {
|
||||
let img = aImg.makeImageAtCurrentFrame();
|
||||
|
Loading…
Reference in New Issue
Block a user