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

Commit 7e100e91 authored by Stan Iliev's avatar Stan Iliev
Browse files

Improve layer rendering quality

Increase filter quality when rendering a layer into the frame
buffer from kNone_SkFilterQuality to kLow_SkFilterQuality.
This visibly improves the quality if the layer is scaled.
For example the circle shutter button in camera app looks
better in pressed state (there is no jagged edge).

Test: Ran camera app
Bug: 72144993
Change-Id: I138d930a25301a369876d76a2cd322df0324f0f2
parent 4a022b84
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ void RenderNodeDrawable::forceDraw(SkCanvas* canvas) {

static bool layerNeedsPaint(const LayerProperties& properties, float alphaMultiplier,
                            SkPaint* paint) {
    paint->setFilterQuality(kLow_SkFilterQuality);
    if (alphaMultiplier < 1.0f || properties.alpha() < 255 ||
        properties.xferMode() != SkBlendMode::kSrcOver || properties.colorFilter() != nullptr) {
        paint->setAlpha(properties.alpha() * alphaMultiplier);
@@ -200,18 +201,15 @@ void RenderNodeDrawable::drawContent(SkCanvas* canvas) const {
        // composing a hardware layer
        if (renderNode->getLayerSurface() && mComposeLayer) {
            SkASSERT(properties.effectiveLayerType() == LayerType::RenderLayer);
            SkPaint* paint = nullptr;
            SkPaint tmpPaint;
            if (layerNeedsPaint(layerProperties, alphaMultiplier, &tmpPaint)) {
                paint = &tmpPaint;
            }
            SkPaint paint;
            layerNeedsPaint(layerProperties, alphaMultiplier, &paint);

            // surfaces for layers are created on LAYER_SIZE boundaries (which are >= layer size) so
            // we need to restrict the portion of the surface drawn to the size of the renderNode.
            SkASSERT(renderNode->getLayerSurface()->width() >= bounds.width());
            SkASSERT(renderNode->getLayerSurface()->height() >= bounds.height());
            canvas->drawImageRect(renderNode->getLayerSurface()->makeImageSnapshot().get(),
                                  bounds, bounds, paint);
                    bounds, bounds, &paint);

            if (!renderNode->getSkiaLayer()->hasRenderedSinceRepaint) {
                renderNode->getSkiaLayer()->hasRenderedSinceRepaint = true;
+34 −0
Original line number Diff line number Diff line
@@ -1046,6 +1046,40 @@ TEST(RenderNodeDrawable, renderNode) {
    EXPECT_EQ(2, canvas.mDrawCounter);
}

// Verify that layers are composed with kLow_SkFilterQuality filter quality.
RENDERTHREAD_SKIA_PIPELINE_TEST(RenderNodeDrawable, layerComposeQuality) {
    static const int CANVAS_WIDTH = 1;
    static const int CANVAS_HEIGHT = 1;
    static const int LAYER_WIDTH = 1;
    static const int LAYER_HEIGHT = 1;
    class FrameTestCanvas : public TestCanvasBase {
    public:
        FrameTestCanvas() : TestCanvasBase(CANVAS_WIDTH, CANVAS_HEIGHT) {}
        void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
                const SkPaint* paint, SrcRectConstraint constraint) override {
            mDrawCounter++;
            EXPECT_EQ(kLow_SkFilterQuality, paint->getFilterQuality());
        }
    };

    auto layerNode = TestUtils::createSkiaNode(
            0, 0, LAYER_WIDTH, LAYER_HEIGHT,
            [](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
                canvas.drawPaint(SkPaint());
            });

    layerNode->animatorProperties().mutateLayerProperties().setType(LayerType::RenderLayer);
    layerNode->setLayerSurface(SkSurface::MakeRasterN32Premul(LAYER_WIDTH, LAYER_HEIGHT));

    FrameTestCanvas canvas;
    RenderNodeDrawable drawable(layerNode.get(), &canvas, true);
    canvas.drawDrawable(&drawable);
    EXPECT_EQ(1, canvas.mDrawCounter);  //make sure the layer was composed

    // clean up layer pointer, so we can safely destruct RenderNode
    layerNode->setLayerSurface(nullptr);
}

TEST(ReorderBarrierDrawable, testShadowMatrix) {
    static const int CANVAS_WIDTH = 100;
    static const int CANVAS_HEIGHT = 100;