mac: Fix multi-video flickering

Note the two following conditions:
1. The contents of an AVSampleBufferDisplayLayer will not necessarily
   update in sync with the rest of the CALayer tree. This is because
   its contents are updated using -[AVSampleBufferDisplayLayer
   enqueueSampleBuffer:], not -[CALayer setContents:]. The latter will
   respect the current CATransaction, the former, by design, does not.
2. When constructing the CALayer tree, it is not known for certain
   from what cc::Layer or from what video stream a given CALayer
   is getting its contents. There will be times when the CALayer tree
   gets jumbled, and one/some/many CALayers re-use a CALayer that is
   from completely different content. (Ordinarily we want to re-use
   the CALayer corresponding to the same layer or tile as the previous

The jumbling in 2 above is an efficiency but not correctness issue
because tree updates are atomic. If we mis-match CALayers, then we'll
just update more state in more CALayers than perhaps we otherwise

Except that because of 1 above, it is a correctness issue, because tree
updates are only mostly atomic.

Work around this by only using AVSampleBufferDisplayLayer if there is
exactly one single video element on screen. I would think this to be
the common case, but in the absence of UMAs for this, I can't say for

A more suitable long-term fix to this and to many other problems is to
actually plumb the layer (and quad) id down to the CALayer tree.

Bug: 923427
Change-Id: Idbc9068d9abce82aa78286874effdb7f776cde43
Commit-Queue: ccameron <>
Reviewed-by: Sidney San Martín <>
Cr-Commit-Position: refs/heads/master@{#631813}
2 files changed