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

Commit dc5e0627 authored by David Sodman's avatar David Sodman
Browse files

SF: Add support for screen captures

Add Layer::drawNow to support capturing portions
of the screen in the FE, as this is not tied
to vsync

Test: Compile/Run manually
Merged-Id: I0781d44240ae127a6e70b35282a02cbedfe36fe4
Change-Id: I0781d44240ae127a6e70b35282a02cbedfe36fe4
parent d0d8f5c8
Loading
Loading
Loading
Loading
+26 −10
Original line number Diff line number Diff line
@@ -160,6 +160,8 @@ void BufferLayer::onDraw(const RenderArea& renderArea, const Region& clip,
                         bool useIdentityTransform) const {
    ATRACE_CALL();

    CompositionInfo& compositionInfo = getBE().compositionInfo;

    if (CC_UNLIKELY(mActiveBuffer == 0)) {
        // the texture has not been created yet, this Layer has
        // in fact never been drawn into. This happens frequently with
@@ -241,6 +243,7 @@ void BufferLayer::onDraw(const RenderArea& renderArea, const Region& clip,
        mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
        mTexture.setFiltering(useFiltering);
        mTexture.setMatrix(textureMatrix);
        compositionInfo.re.texture = mTexture;

        engine.setupLayerTexturing(mTexture);
    } else {
@@ -250,6 +253,23 @@ void BufferLayer::onDraw(const RenderArea& renderArea, const Region& clip,
    engine.disableTexturing();
}

void BufferLayer::drawNow(const RenderArea& renderArea, bool useIdentityTransform) const {
    CompositionInfo& compositionInfo = getBE().compositionInfo;
    auto& engine(mFlinger->getRenderEngine());

    draw(renderArea, useIdentityTransform);

    engine.setupLayerTexturing(compositionInfo.re.texture);
    engine.setupLayerBlending(compositionInfo.re.preMultipliedAlpha, compositionInfo.re.opaque,
            false, compositionInfo.re.color);
    engine.setSourceDataSpace(compositionInfo.hwc.dataspace);
    engine.setSourceY410BT2020(compositionInfo.re.Y410BT2020);
    engine.drawMesh(getBE().getMesh());
    engine.disableBlending();
    engine.disableTexturing();
    engine.setSourceY410BT2020(false);
}

void BufferLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
    mConsumer->setReleaseFence(releaseFence);
}
@@ -810,21 +830,17 @@ void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityT
    texCoords[2] = vec2(right, 1.0f - bottom);
    texCoords[3] = vec2(right, 1.0f - top);

    auto& engine(mFlinger->getRenderEngine());
    engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), false /* disableTexture */,
                              getColor());
    engine.setSourceDataSpace(mCurrentState.dataSpace);
    getBE().compositionInfo.re.preMultipliedAlpha = mPremultipliedAlpha;
    getBE().compositionInfo.re.opaque = isOpaque(s);
    getBE().compositionInfo.re.disableTexture = false;
    getBE().compositionInfo.re.color = getColor();
    getBE().compositionInfo.hwc.dataspace = mCurrentState.dataSpace;

    if (mCurrentState.dataSpace == HAL_DATASPACE_BT2020_ITU_PQ &&
        mConsumer->getCurrentApi() == NATIVE_WINDOW_API_MEDIA &&
        getBE().compositionInfo.mBuffer->getPixelFormat() == HAL_PIXEL_FORMAT_RGBA_1010102) {
        engine.setSourceY410BT2020(true);
        getBE().compositionInfo.re.Y410BT2020 = true;
    }

    engine.drawMesh(getBE().mMesh);
    engine.disableBlending();

    engine.setSourceY410BT2020(false);
}

uint32_t BufferLayer::getProducerStickyTransform() const {
+1 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ public:
     */
    void onDraw(const RenderArea& renderArea, const Region& clip,
                bool useIdentityTransform) const override;
    void drawNow(const RenderArea& renderArea, bool useIdentityTransform) const;

    void onLayerDisplayed(const sp<Fence>& releaseFence) override;

+18 −7
Original line number Diff line number Diff line
@@ -46,15 +46,26 @@ void ColorLayer::onDraw(const RenderArea& renderArea, const Region& /* clip */,
                        bool useIdentityTransform) const {
    const State& s(getDrawingState());
    if (s.color.a > 0) {
        Mesh mesh(Mesh::TRIANGLE_FAN, 4, 2);
        computeGeometry(renderArea, mesh, useIdentityTransform);
        computeGeometry(renderArea, getBE().mMesh, useIdentityTransform);
        getBE().compositionInfo.re.preMultipliedAlpha = getPremultipledAlpha();
        getBE().compositionInfo.re.opaque = false;
        getBE().compositionInfo.re.disableTexture = true;
        getBE().compositionInfo.re.color = s.color;
    }
}

void ColorLayer::drawNow(const RenderArea& renderArea, bool useIdentityTransform) const {
    CompositionInfo& compositionInfo = getBE().compositionInfo;
    auto& engine(mFlinger->getRenderEngine());
        engine.setupLayerBlending(getPremultipledAlpha(), false /* opaque */,
                                  true /* disableTexture */, s.color);
        engine.drawMesh(mesh);

    draw(renderArea, useIdentityTransform);

    engine.setupLayerBlending(compositionInfo.re.preMultipliedAlpha, compositionInfo.re.opaque,
            compositionInfo.re.disableTexture, compositionInfo.re.color);
    engine.setSourceDataSpace(compositionInfo.hwc.dataspace);
    engine.drawMesh(getBE().getMesh());
    engine.disableBlending();
}
}

bool ColorLayer::isVisible() const {
    const Layer::State& s(getDrawingState());
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public:
    virtual const char* getTypeId() const { return "ColorLayer"; }
    virtual void onDraw(const RenderArea& renderArea, const Region& clip,
                        bool useIdentityTransform) const;
    void drawNow(const RenderArea& , bool ) const;
    bool isVisible() const override;

    void setPerFrameData(const sp<const DisplayDevice>& displayDevice) override;
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ ContainerLayer::ContainerLayer(SurfaceFlinger* flinger, const sp<Client>& client

void ContainerLayer::onDraw(const RenderArea&, const Region& /* clip */, bool) const {}

void ContainerLayer::drawNow(const RenderArea&, bool) const {}

bool ContainerLayer::isVisible() const {
    return !isHiddenByPolicy();
}
Loading