• C
    Ensure that Scene::toImage renders texture backed images. (#6636) · 20c805c9
    Chinmay Garde 提交于
    TL;DR: Offscreen surface is created on the render thread and device to host
    transfer performed there before task completion on the UI thread.
    
    While attempting to snapshot layer trees, the engine was attempting to use the
    IO thread context. The reasoning was that this would be safe to do because any
    textures uploaded to the GPU as a result of async texture upload would have
    originated from this context and hence the handles would be valid in either
    context. As it turns out, while the handles are valid, Skia does not support
    this use-case because cross-context images transfer ownership of the image from
    one context to another. So, when we made the hop from the UI thread to the IO
    thread (for snapshotting), if either the UI or GPU threads released the last
    reference to the texture backed image, the image would be invalid. This led to
    such images being absent from the layer tree snapshot.
    
    Simply referencing the images as they are being used on the IO thread is not
    sufficient because accessing images on one context after their ownership has
    already been transferred to another is not safe behavior (from Skia's
    perspective, the handles are still valid in the sharegroup).
    
    To work around these issues, it was decided that an offscreen render target
    would be created on the render thread. The color attachment of this render
    target could then be transferred as a cross context image to the IO thread for
    the device to host tranfer.
    
    Again, this is currently not quite possible because the only way to create
    cross context images is from encoded data. Till Skia exposes the functionality
    to create cross-context images from textures in one context, we do a device to
    host transfer on the GPU thread. The side effect of this is that this is now
    part of the frame workload (image compression, which dominate the wall time,
    is still done of the IO thread).
    
    A minor side effect of this patch is that the GPU latch needs to be waited on
    before the UI thread tasks can be completed before shell initialization.
    20c805c9
engine.h 5.3 KB