From 5913cae969e8e85a4e156e447033fa9635d1e67f Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 11 Oct 2019 12:32:03 -0400 Subject: [PATCH 1/2] Use bitmap skin for video preview --- src/io/video.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/io/video.js b/src/io/video.js index 2e99e36cc..faef56cd2 100644 --- a/src/io/video.js +++ b/src/io/video.js @@ -21,12 +21,6 @@ class Video { */ this._skinId = -1; - /** - * The Scratch Renderer Skin object. - * @type {Skin} - */ - this._skin = null; - /** * Id for a drawable using the video's skin that will render as a video * preview. @@ -141,8 +135,8 @@ class Video { } _disablePreview () { - if (this._skin) { - this._skin.clear(); + if (this._skinId) { + this.runtime.renderer.updateBitmapSkin(this._skinId, new ImageData(...Video.DIMENSIONS), 1); this.runtime.renderer.updateDrawableProperties(this._drawable, {visible: false}); } this._renderPreviewFrame = null; @@ -152,9 +146,8 @@ class Video { const {renderer} = this.runtime; if (!renderer) return; - if (this._skinId === -1 && this._skin === null && this._drawable === -1) { - this._skinId = renderer.createPenSkin(); - this._skin = renderer._allSkins[this._skinId]; + if (this._skinId === -1 && this._drawable === -1) { + this._skinId = renderer.createBitmapSkin(new ImageData(...Video.DIMENSIONS), 1); this._drawable = renderer.createDrawable(StageLayering.VIDEO_LAYER); renderer.updateDrawableProperties(this._drawable, { skinId: this._skinId @@ -176,16 +169,17 @@ class Video { this._renderPreviewTimeout = setTimeout(this._renderPreviewFrame, this.runtime.currentStepTime); - const canvas = this.getFrame({format: Video.FORMAT_CANVAS}); + const imageData = this.getFrame({ + format: Video.FORMAT_IMAGE_DATA, + cacheTimeout: this.runtime.currentStepTime + }); - if (!canvas) { - this._skin.clear(); + if (!imageData) { + renderer.updateBitmapSkin(this._skinId, new ImageData(...Video.DIMENSIONS), 1); return; } - const xOffset = Video.DIMENSIONS[0] / -2; - const yOffset = Video.DIMENSIONS[1] / 2; - this._skin.drawStamp(canvas, xOffset, yOffset); + renderer.updateBitmapSkin(this._skinId, imageData, 1); this.runtime.requestRedraw(); }; From 94188fc07557ac285b4028479ed88921246ff022 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 14 Oct 2019 12:02:44 -0400 Subject: [PATCH 2/2] Fix tests by more carefully checking for the skin --- src/io/video.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/video.js b/src/io/video.js index faef56cd2..f037b0f9c 100644 --- a/src/io/video.js +++ b/src/io/video.js @@ -135,7 +135,7 @@ class Video { } _disablePreview () { - if (this._skinId) { + if (this._skinId !== -1) { this.runtime.renderer.updateBitmapSkin(this._skinId, new ImageData(...Video.DIMENSIONS), 1); this.runtime.renderer.updateDrawableProperties(this._drawable, {visible: false}); }