Skip to content

Conversation

paulkaplan
Copy link
Contributor

Resolves

What Github issue does this resolve (please include link)?

Resolves scratchfoundation/scratch-gui#4888

Proposed Changes

Describe what this Pull Request does

Use the BitmapSkin type for the video layer instead of the PenSkin, because the PenSkin cannot have the ghost effect applied to it due to using premultiplied alpha blending modes.

This is the solution I wanted to implement #2291, but was concerned with the performance of silhouette updates. I was concerned that the bitmap skin was too slow to update because updating the silhouette required a slow canvas -> ImageData conversion. After more digging, it turns out, we are actually already doing that conversion in the video motion extension in a similarly timed loop, and so we can take advantage of the caching mechanism in the VideoProvider and request the cached ImageData. sometimes the extension loop freshens the cache, sometimes this preview updater loop does, but either way it only gets done once every 30ms, which is as good as we are going to get performance-wise since the extension requires ImageData for computation.

So no fancy silhouette deferral is needed! Although i did look into that also... we can talk about framebuffers later... @cwillisf

Reason for Changes

Explain why these changes should be made

We were using private APIs, and public APIs in unexpected ways, to get the result we wanted from the renderer. Now just use the public APIs in totally expected ways. :)

Test Coverage

Please show how you have added tests to cover your changes

To test manually, add the video extension and see how adjusting the transparency displays correct colors. Turning transparency up to 100 should make you completely disappear.

Copy link
Contributor

@cwillisf cwillisf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made one suggestion but it's more of a detail; if there's no time to implement the change then I think it's fine to make that a followup later. Otherwise, this looks great! Thanks for digging in and being so thorough!

Comment on lines -24 to -29
/**
* The Scratch Renderer Skin object.
* @type {Skin}
*/
this._skin = null;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

if (!canvas) {
this._skin.clear();
if (!imageData) {
renderer.updateBitmapSkin(this._skinId, new ImageData(...Video.DIMENSIONS), 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to cache and reuse this "empty frame" ImageData to reduce garbage collection load.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Done!

@paulkaplan paulkaplan merged commit 9b7a977 into scratchfoundation:develop Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Video transparency in video sensing doesn't go all the way invisible
3 participants