mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #2292 from paulkaplan/use-bitmap-video
Use bitmap skin for video preview
This commit is contained in:
commit
9b7a9770d7
1 changed files with 11 additions and 17 deletions
|
@ -21,12 +21,6 @@ class Video {
|
||||||
*/
|
*/
|
||||||
this._skinId = -1;
|
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
|
* Id for a drawable using the video's skin that will render as a video
|
||||||
* preview.
|
* preview.
|
||||||
|
@ -141,8 +135,8 @@ class Video {
|
||||||
}
|
}
|
||||||
|
|
||||||
_disablePreview () {
|
_disablePreview () {
|
||||||
if (this._skin) {
|
if (this._skinId !== -1) {
|
||||||
this._skin.clear();
|
this.runtime.renderer.updateBitmapSkin(this._skinId, new ImageData(...Video.DIMENSIONS), 1);
|
||||||
this.runtime.renderer.updateDrawableProperties(this._drawable, {visible: false});
|
this.runtime.renderer.updateDrawableProperties(this._drawable, {visible: false});
|
||||||
}
|
}
|
||||||
this._renderPreviewFrame = null;
|
this._renderPreviewFrame = null;
|
||||||
|
@ -152,9 +146,8 @@ class Video {
|
||||||
const {renderer} = this.runtime;
|
const {renderer} = this.runtime;
|
||||||
if (!renderer) return;
|
if (!renderer) return;
|
||||||
|
|
||||||
if (this._skinId === -1 && this._skin === null && this._drawable === -1) {
|
if (this._skinId === -1 && this._drawable === -1) {
|
||||||
this._skinId = renderer.createPenSkin();
|
this._skinId = renderer.createBitmapSkin(new ImageData(...Video.DIMENSIONS), 1);
|
||||||
this._skin = renderer._allSkins[this._skinId];
|
|
||||||
this._drawable = renderer.createDrawable(StageLayering.VIDEO_LAYER);
|
this._drawable = renderer.createDrawable(StageLayering.VIDEO_LAYER);
|
||||||
renderer.updateDrawableProperties(this._drawable, {
|
renderer.updateDrawableProperties(this._drawable, {
|
||||||
skinId: this._skinId
|
skinId: this._skinId
|
||||||
|
@ -176,16 +169,17 @@ class Video {
|
||||||
|
|
||||||
this._renderPreviewTimeout = setTimeout(this._renderPreviewFrame, this.runtime.currentStepTime);
|
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) {
|
if (!imageData) {
|
||||||
this._skin.clear();
|
renderer.updateBitmapSkin(this._skinId, new ImageData(...Video.DIMENSIONS), 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const xOffset = Video.DIMENSIONS[0] / -2;
|
renderer.updateBitmapSkin(this._skinId, imageData, 1);
|
||||||
const yOffset = Video.DIMENSIONS[1] / 2;
|
|
||||||
this._skin.drawStamp(canvas, xOffset, yOffset);
|
|
||||||
this.runtime.requestRedraw();
|
this.runtime.requestRedraw();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue