Bug 202574 - Implement [Transferable] property of OffscreenCanvas
Summary: Implement [Transferable] property of OffscreenCanvas
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Lord
URL:
Keywords: InRadar
Depends on: 202573 205385
Blocks: 183720 202797
  Show dependency treegraph
 
Reported: 2019-10-04 01:44 PDT by Chris Lord
Modified: 2020-01-28 16:55 PST (History)
24 users (show)

See Also:


Attachments
Patch (36.50 KB, patch)
2019-10-10 04:09 PDT, Chris Lord
no flags Details | Formatted Diff | Diff
Patch (41.60 KB, patch)
2019-12-16 02:30 PST, Chris Lord
no flags Details | Formatted Diff | Diff
Patch (42.05 KB, patch)
2019-12-18 04:19 PST, Chris Lord
no flags Details | Formatted Diff | Diff
Patch (40.18 KB, patch)
2019-12-18 05:38 PST, Chris Lord
no flags Details | Formatted Diff | Diff
Patch (39.05 KB, patch)
2020-01-28 03:00 PST, Chris Lord
no flags Details | Formatted Diff | Diff
again (6.55 KB, patch)
2020-01-28 06:36 PST, Antti Koivisto
no flags Details | Formatted Diff | Diff
Patch (40.20 KB, patch)
2020-01-28 08:54 PST, Chris Lord
no flags Details | Formatted Diff | Diff
Patch (40.20 KB, patch)
2020-01-28 09:20 PST, Chris Lord
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 Chris Lord 2019-10-10 04:09:11 PDT
Created attachment 380630 [details]
Patch
Comment 2 Chris Lord 2019-12-16 02:30:09 PST
Created attachment 385745 [details]
Patch
Comment 3 Sam Weinig 2019-12-16 11:27:51 PST
Comment on attachment 385745 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=385745&action=review

> Source/WebCore/html/OffscreenCanvas.cpp:284
> +    return std::unique_ptr<DetachedOffscreenCanvas>(new DetachedOffscreenCanvas(takeImageBuffer(), size(), originClean()));

Please use makeUnique<>
Comment 4 Ryosuke Niwa 2019-12-16 13:41:48 PST
Comment on attachment 385745 [details]
Patch

r- due to build failures.
Comment 5 Chris Lord 2019-12-18 04:19:00 PST
Created attachment 385954 [details]
Patch
Comment 6 Chris Lord 2019-12-18 04:25:56 PST
argh, I think I've missed some OffscreenCanvas guards, will fix...
Comment 7 Chris Lord 2019-12-18 05:38:13 PST
Created attachment 385965 [details]
Patch
Comment 8 Chris Lord 2019-12-18 06:10:05 PST
I don't think the style test will pass without reformatting a not-trivial amount of the affected file - note, my additions are in keeping with what's in the file already.
Comment 9 Chris Lord 2020-01-28 03:00:16 PST
Created attachment 388978 [details]
Patch
Comment 10 Antti Koivisto 2020-01-28 06:26:54 PST
Comment on attachment 388978 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=388978&action=review

> Source/WebCore/bindings/js/SerializedScriptValue.cpp:3153
> +#if ENABLE(OFFSCREEN_CANVAS)
> +                { },
> +#endif
>  #if ENABLE(WEBASSEMBLY)
>                  nullptr,
>  #endif

Maybe CloneDeserializer could have default argument values to avoid these?

> Source/WebCore/bindings/js/SerializedScriptValue.cpp:3574
>      return adoptRef(*new SerializedScriptValue(WTFMove(buffer), blobURLs, nullptr, nullptr, { }
> +#if ENABLE(OFFSCREEN_CANVAS)
> +        , { }
> +#endif
>  #if ENABLE(WEBASSEMBLY)
>          , nullptr
>  #endif

Maybe SerializedScriptValue could have default argument values to avoid these?

> Source/WebCore/bindings/js/SerializedScriptValue.cpp:3589
> +static bool offscreenCanvasesCanDetach(const Vector<RefPtr<OffscreenCanvas>>& offscreenCanvases)

The usual style is to start boolean functions with verb like is/are/has etc., maybe areAllOffscreenCanvasesDetachable or something like that.

> Source/WebCore/bindings/js/SerializedScriptValue.cpp:3596
> +        if (!visited.add(offscreenCanvas.get()))
> +            return false;

What is this test about? Maybe add a comment?
Comment 11 Antti Koivisto 2020-01-28 06:36:17 PST
Created attachment 388986 [details]
again
Comment 12 Antti Koivisto 2020-01-28 06:43:01 PST
Comment on attachment 388986 [details]
again

oops wrong bug
Comment 13 Chris Lord 2020-01-28 08:54:23 PST
Created attachment 389010 [details]
Patch
Comment 14 Chris Lord 2020-01-28 09:20:13 PST
Created attachment 389015 [details]
Patch
Comment 15 WebKit Commit Bot 2020-01-28 14:48:11 PST
Comment on attachment 389015 [details]
Patch

Clearing flags on attachment: 389015

Committed r255315: <https://trac.webkit.org/changeset/255315>
Comment 16 WebKit Commit Bot 2020-01-28 14:48:14 PST
All reviewed patches have been landed.  Closing bug.
Comment 17 Radar WebKit Bug Importer 2020-01-28 14:49:18 PST
<rdar://problem/58970553>
Comment 18 Darin Adler 2020-01-28 16:55:04 PST
Comment on attachment 389015 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=389015&action=review

> Source/WebCore/bindings/js/SerializedScriptValue.cpp:567
>      static SerializationReturnCode serialize(JSGlobalObject* lexicalGlobalObject, JSValue value, Vector<RefPtr<MessagePort>>& messagePorts, Vector<RefPtr<JSC::ArrayBuffer>>& arrayBuffers, const Vector<RefPtr<ImageBitmap>>& imageBitmaps,
> +#if ENABLE(OFFSCREEN_CANVAS)
> +            const Vector<RefPtr<OffscreenCanvas>>& offscreenCanvases,
> +#endif
>  #if ENABLE(WEBASSEMBLY)
>              WasmModuleArray& wasmModules,
>  #endif
>          Vector<String>& blobURLs, Vector<uint8_t>& out, SerializationContext context, ArrayBufferContentsArray& sharedBuffers)

Seems to me that long arguments lists like these with compiler-conditioonal arguments in them are not a great pattern. We should look for something more elegant and easy to read. Maybe a structure would help in some way?

> Source/WebCore/bindings/js/SerializedScriptValue.cpp:969
> +    void dumpOffscreenCanvas(JSObject* obj, SerializationReturnCode& code)

WebKit coding style says use a word here, object, not an abbreviation, obj.

Also, we like to use references for things that can’t be null. Although I guess JavaScript programmers are holdouts on that one?

> Source/WebCore/bindings/js/SerializedScriptValue.cpp:3595
> +    Vector<RefPtr<OffscreenCanvas>> offscreenCanvases;

I’d think Vector<Ref> would be the right type for these vectors. Seems unlikely we need to store nulls in them.

> Source/WebCore/bindings/js/SerializedScriptValue.h:52
> +#if ENABLE(OFFSCREEN_CANVAS)
> +class DetachedOffscreenCanvas;
> +#endif

Two coding style thoughts:

1) I’m not sure it’s worthwhile to put forward declarations inside #if blocks. I think it’s probably a reasonable practice to define them even if they aren’t used.

2) If we are going to put them in #if blocks, then the #if block should be a separate paragraph and not interspersed with other forward declarations. This is the same rule we follow for includes.

> Source/WebCore/html/OffscreenCanvas.cpp:90
> +    if (m_detached)
> +        return 0;

Can we just set m_size to 0 as part of the detaching process? Then we can let width remain a non-virtual function.

> Source/WebCore/html/OffscreenCanvas.cpp:97
> +    if (m_detached)
> +        return 0;

Ditto.