Are you thinking only of touch / gesture / wheel input, or would this also include other types of scroll-triggering input (keyboard, scrollbar dragging, etc.) that cc has never handled?
If the goal is just to avoid code duplication, it seems like that could be achieved without sending the event to a different thread. Couldn't Blink and CC have a shared dependency on the input logic?
We already need to add the right layer of abstraction for sharing bubbling and scrolling logic in order to implement scroll customization.
We can't have "one type of data structure in one place," as scrolling can be implemented in main thread JS, UIWorker JS, or in CC, at minimum.
2015-02-23 17:43 GMT-08:00 Alexandre Elias <ael...@google.com>:
> 2) The new DistributeScroll APIs. To address this, I would rely on the fact
> that the main thread is blocked during commit, therefore we can both run JS
> and modify the CC impl scrolling state during that interval. CC impl code
> would taking care of bubbling and railing, and make synchronous calls across
> the Blink API to distribute individual scroll deltas to JS. This may sound
> a bit odd at first, but I see nothing fundamentally evil about this idea --
> we just need to ban all use of thread-locals in Blink, which seems to be
> already almost the case from a quick grep.
I think this is the part that is most unclear to me. If I look at the
larger picture of things that Blink and cc duplicate, I see scrolling,
animation, and hit testing.
Even if I just look at scrolling, it's not clear to me how that code
could only run during commit. Are you implying that the commit needs
to block before running main thread raf and animations (losing some
parallelism). How do you handle Javascript scrolling?
The other unclear part is that you mention that you want a single
instance of this data, but you also mention "making synchronous calls
to distribute scroll deltas". Is the idea that this new data
structure would be authoritative about scrolls and Blink would just be
told what its scroll positions are?
Why do you feel so strongly about one instance of the data vs some
shared (more coarse) data structure that could be synchronized, but
operated on independently?
For the hit testing model, I pictured that
both the main thread and the compositor thread have different
instances of the same display list type, and hit testing could operate
on that. I think that avoids the pitfalls of the animation curve
issues that you are worried about.
I'm all for unifying input code, particularly as it relates to scrolling.However, I'm still not convinced that forcing all (user) scrolls through impl-thread data structures is strictly necessary. Yes, it might require some state synchronization to ensure consistent treatment on both threads, but I'm not sure that's an unreasonable burden when we already have to maintain parallel trees.Several questions I have about this approach are
- Will this prevent frame-synchronized JS scroll listener dispatch for a given scroll event? Or would (can?) we run the scroll listeners during the commit phase?
> 2. Would this prevent the feasibility of JS injecting a scroll event into the proposed scroll customization pipeline?
It shouldn't affect the feasibility of the proposals in that doc, that's what I was referring to in my point 2) in my first email.
So left implicit in my proposal that we maintain the main-thread mirror instance of the state that can be written to by Javascript, with the same SyncedProperty reconciliation that exists today. So we would only lose some parallelism in the case of scroll gestures (where I would argue it's not useful).
> 3. Are we OK blocking the compositor thread during a commit while we have to execute arbitrarily expensive scroll customization JS (or scroll listener JS)?
Yes, on the premise that scrolling is by far the most important thing that's being made asynchronous on the compositor thread, and we gave up that asynchronicity already. The only remaining incremental benefit would be to avoid janking CSS animations that happen to be running at the same time as the scroll, but that seems like a really small benefit.