Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e068c01 authored by Chris Craik's avatar Chris Craik
Browse files

Early kickoff of shadow tasks

bug:26562703

Change-Id: I7cdf18f2c662380bd31c7ffeefd5c3f569e5c1c6
parent d38308e4
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -663,13 +663,7 @@ static void renderShadow(BakedOpRenderer& renderer, const BakedOpState& state, f
}

void BakedOpDispatcher::onShadowOp(BakedOpRenderer& renderer, const ShadowOp& op, const BakedOpState& state) {
    TessellationCache::vertexBuffer_pair_t buffers;
    renderer.caches().tessellationCache.getShadowBuffers(&state.computedState.transform,
            op.localClipRect, op.casterAlpha >= 1.0f, op.casterPath,
            &op.shadowMatrixXY, &op.shadowMatrixZ,
            op.lightCenter, renderer.getLightInfo().lightRadius,
            buffers);

    TessellationCache::vertexBuffer_pair_t buffers = *(op.shadowTask->getResult());
    renderShadow(renderer, state, op.casterAlpha, buffers.first, buffers.second);
}

+3 −5
Original line number Diff line number Diff line
@@ -45,13 +45,11 @@ public:
     * Position agnostic shadow lighting info. Used with all shadow ops in scene.
     */
    struct LightInfo {
        LightInfo() : LightInfo(0, 0, 0) {}
        LightInfo(float lightRadius, uint8_t ambientShadowAlpha,
        LightInfo() : LightInfo(0, 0) {}
        LightInfo(uint8_t ambientShadowAlpha,
                uint8_t spotShadowAlpha)
                : lightRadius(lightRadius)
                , ambientShadowAlpha(ambientShadowAlpha)
                : ambientShadowAlpha(ambientShadowAlpha)
                , spotShadowAlpha(spotShadowAlpha) {}
        float lightRadius;
        uint8_t ambientShadowAlpha;
        uint8_t spotShadowAlpha;
    };
+5 −10
Original line number Diff line number Diff line
@@ -63,16 +63,11 @@ ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& s
    }
}

ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot) {
    transform = *snapshot.transform;

    // Since the op doesn't have known bounds, we conservatively set the mapped bounds
    // to the current clipRect, and clipSideFlags to Full.
    clipState = snapshot.mutateClipArea().serializeClip(allocator);
    LOG_ALWAYS_FATAL_IF(!clipState, "clipState required");
    clippedBounds = clipState->rect;
    clipSideFlags = OpClipSideFlags::Full;
}
ResolvedRenderState::ResolvedRenderState(LinearAllocator& allocator, Snapshot& snapshot)
        : transform(*snapshot.transform)
        , clipState(snapshot.mutateClipArea().serializeClip(allocator))
        , clippedBounds(clipState->rect)
        , clipSideFlags(OpClipSideFlags::Full) {}

ResolvedRenderState::ResolvedRenderState(const ClipRect* viewportRect, const Rect& dstRect)
        : transform(Matrix4::identity())
+28 −19
Original line number Diff line number Diff line
@@ -32,17 +32,11 @@ namespace uirenderer {

FrameBuilder::FrameBuilder(const LayerUpdateQueue& layers, const SkRect& clip,
        uint32_t viewportWidth, uint32_t viewportHeight,
        const std::vector< sp<RenderNode> >& nodes, const Vector3& lightCenter)
        : FrameBuilder(layers, clip, viewportWidth, viewportHeight, nodes, lightCenter,
                Rect(0, 0, 0, 0)) {
}


FrameBuilder::FrameBuilder(const LayerUpdateQueue& layers, const SkRect& clip,
        uint32_t viewportWidth, uint32_t viewportHeight,
        const std::vector< sp<RenderNode> >& nodes, const Vector3& lightCenter,
        const Rect &contentDrawBounds)
        : mCanvasState(*this) {
        const std::vector< sp<RenderNode> >& nodes,
        const LightGeometry& lightGeometry, const Rect &contentDrawBounds, Caches* caches)
        : mCanvasState(*this)
        , mCaches(caches)
        , mLightRadius(lightGeometry.radius) {
    ATRACE_NAME("prepare drawing commands");

    mLayerBuilders.reserve(layers.entries().size());
@@ -54,7 +48,7 @@ FrameBuilder::FrameBuilder(const LayerUpdateQueue& layers, const SkRect& clip,
    mLayerStack.push_back(0);
    mCanvasState.initializeSaveStack(viewportWidth, viewportHeight,
            clip.fLeft, clip.fTop, clip.fRight, clip.fBottom,
            lightCenter);
            lightGeometry.center);

    // Render all layers to be updated, in order. Defer in reverse order, so that they'll be
    // updated in the order they're passed in (mLayerBuilders are issued to Renderer in reverse)
@@ -366,15 +360,30 @@ void FrameBuilder::deferShadow(const RenderNodeOp& casterNodeOp) {
        casterPath = frameAllocatedPath;
    }

    ShadowOp* shadowOp = new (mAllocator) ShadowOp(casterNodeOp, casterAlpha, casterPath,

    if (CC_LIKELY(!mCanvasState.getRenderTargetClipBounds().isEmpty())) {
        Matrix4 shadowMatrixXY(casterNodeOp.localMatrix);
        Matrix4 shadowMatrixZ(casterNodeOp.localMatrix);
        node.applyViewPropertyTransforms(shadowMatrixXY, false);
        node.applyViewPropertyTransforms(shadowMatrixZ, true);

        LOG_ALWAYS_FATAL_IF(!mCaches, "Caches needed for shadows");
        sp<TessellationCache::ShadowTask> task = mCaches->tessellationCache.getShadowTask(
                mCanvasState.currentTransform(),
                mCanvasState.getLocalClipBounds(),
            mCanvasState.currentSnapshot()->getRelativeLightCenter());
                casterAlpha >= 1.0f,
                casterPath,
                &shadowMatrixXY, &shadowMatrixZ,
                mCanvasState.currentSnapshot()->getRelativeLightCenter(),
                mLightRadius);
        ShadowOp* shadowOp = mAllocator.create<ShadowOp>(task, casterAlpha);
        BakedOpState* bakedOpState = BakedOpState::tryShadowOpConstruct(
                mAllocator, *mCanvasState.writableSnapshot(), shadowOp);
        if (CC_LIKELY(bakedOpState)) {
            currentLayer().deferUnmergeableOp(mAllocator, bakedOpState, OpBatchType::Shadow);
        }
    }
}

void FrameBuilder::deferProjectedChildren(const RenderNode& renderNode) {
    const SkPath* projectionReceiverOutline = renderNode.properties().getOutline().getPath();
+18 −4
Original line number Diff line number Diff line
@@ -55,14 +55,24 @@ class Rect;
 */
class FrameBuilder : public CanvasStateClient {
public:
    struct LightGeometry {
        Vector3 center;
        float radius;
    };

    // TODO: remove
    FrameBuilder(const LayerUpdateQueue& layers, const SkRect& clip,
            uint32_t viewportWidth, uint32_t viewportHeight,
            const std::vector< sp<RenderNode> >& nodes, const Vector3& lightCenter);
            const std::vector< sp<RenderNode> >& nodes,
            const LightGeometry& lightGeometry,
            Caches* caches)
            : FrameBuilder(layers, clip, viewportWidth, viewportHeight, nodes, lightGeometry, Rect(), caches) {}

    FrameBuilder(const LayerUpdateQueue& layers, const SkRect& clip,
            uint32_t viewportWidth, uint32_t viewportHeight,
            const std::vector< sp<RenderNode> >& nodes, const Vector3& lightCenter,
            const Rect &contentDrawBounds);
            const std::vector< sp<RenderNode> >& nodes,
            const LightGeometry& lightGeometry,
            const Rect &contentDrawBounds, Caches* caches);

    virtual ~FrameBuilder() {}

@@ -215,7 +225,11 @@ private:

    CanvasState mCanvasState;

    // contains ResolvedOps and Batches
    Caches* mCaches = nullptr;

    float mLightRadius;

    // contains single-frame objects, such as BakedOpStates, LayerBuilders, Batches
    LinearAllocator mAllocator;
};

Loading