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

Commit 3622482c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Change texture transformation group to have elliptical round rects"...

Merge "Change texture transformation group to have elliptical round rects" into sc-dev am: 5be123bd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/14535572

Change-Id: I77c56f5087082ad9204c0419eafc24285d953682
parents fea16bdb 5be123bd
Loading
Loading
Loading
Loading
+31 −17
Original line number Diff line number Diff line
@@ -37,10 +37,6 @@ const auto kScaleAndTranslate = mat4(0.7f, 0.f, 0.f, 0.f,
                                     0.f,  0.7f, 0.f, 0.f,
                                     0.f,   0.f, 1.f, 0.f,
                                   67.3f, 52.2f, 0.f, 1.f);
const auto kScaleYOnly = mat4(1.f,   0.f, 0.f, 0.f,
                              0.f,  0.7f, 0.f, 0.f,
                              0.f,   0.f, 1.f, 0.f,
                              0.f,   0.f, 0.f, 1.f);
// clang-format on
// When setting layer.sourceDataspace, whether it matches the destination or not determines whether
// a color correction effect is added to the shader.
@@ -188,35 +184,53 @@ static void drawBlurLayers(SkiaRenderEngine* renderengine, const DisplaySettings
    }
}

static void drawTextureScaleLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display,
// The unique feature of these layers is that the boundary is slightly smaller than the rounded
// rect crop, so the rounded edges intersect that boundary and require a different clipping method.
static void drawClippedLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display,
                              const std::shared_ptr<ExternalTexture>& dstTexture,
                              const std::shared_ptr<ExternalTexture>& srcTexture) {
    const Rect& displayRect = display.physicalDisplay;
    FloatRect rect(0, 0, displayRect.width(), displayRect.height());
    FloatRect rect(0, 0, displayRect.width(), displayRect.height() - 20); // boundary is smaller

    // clang-format off
    const auto symmetric = mat4(0.9f, 0.f,  0.f, 0.f,
                                0.f,  0.9f, 0.f, 0.f,
                                0.f,  0.f,  1.f, 0.f,
                                8.8f, 8.1f, 0.f, 1.f);
    const auto asymmetric = mat4(0.9f, 0.f,  0.f, 0.f,
                                 0.f,  0.7f, 0.f, 0.f,
                                 0.f,  0.f,  1.f, 0.f,
                                 8.8f, 8.1f, 0.f, 1.f);

    // clang-format on
    LayerSettings layer{
            .geometry =
                    Geometry{
                            .boundaries = rect,
                            .roundedCornersCrop = rect,
                            .positionTransform = kScaleAndTranslate,
                            .roundedCornersRadius = 300,
                            .roundedCornersRadius = 27, // larger than the 20 above.
                            .roundedCornersCrop =
                                    FloatRect(0, 0, displayRect.width(), displayRect.height()),
                    },
            .source = PixelSource{.buffer =
                                          Buffer{
                                                  .buffer = srcTexture,
                                                  .isOpaque = 0,
                                                  .maxLuminanceNits = 1000.f,
                                                  .textureTransform = kScaleYOnly,
                                          }},
            .sourceDataspace = kOtherDataSpace,
    };

    auto layers = std::vector<const LayerSettings*>{&layer};
    for (auto transform : {symmetric, asymmetric}) {
        layer.geometry.positionTransform = transform;
        // In real use, I saw alpha of 1.0 and 0.999, probably a mistake, but cache both shaders.
        for (float alpha : {0.5f, 1.f}) {
            layer.alpha = alpha,
            renderengine->drawLayers(display, layers, dstTexture, kUseFrameBufferCache,
                                     base::unique_fd(), nullptr);
        }
    }
}

//
// The collection of shaders cached here were found by using perfetto to record shader compiles
@@ -293,7 +307,7 @@ void Cache::primeShaderCache(SkiaRenderEngine* renderengine) {
        drawImageLayers(renderengine, display, dstTexture, externalTexture);

        // Draw layers for b/185569240.
        drawTextureScaleLayers(renderengine, display, dstTexture, externalTexture);
        drawClippedLayers(renderengine, display, dstTexture, externalTexture);

        const nsecs_t timeAfter = systemTime();
        const float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6;