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

Commit 2d45c98f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Cache shaders for layers that appear during certain app opens" into sc-dev am: b751ed62

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

Change-Id: I767cde0f0bfffa7cd12ee96de5c6528107ce4246
parents 095ffbc6 b751ed62
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -37,12 +37,17 @@ 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 choosing dataspaces below, whether the match the destination or not determined whether
// a color correction effect is added to the shader. There may be other additional shader details
// for particular color spaces.
// TODO(b/184842383) figure out which color related shaders are necessary
constexpr auto kDestDataSpace = ui::Dataspace::SRGB;
constexpr auto kOtherDataSpace = ui::Dataspace::DISPLAY_P3;
} // namespace

static void drawShadowLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display,
@@ -182,6 +187,37 @@ static void drawBlurLayers(SkiaRenderEngine* renderengine, const DisplaySettings
    }
}

static void drawTextureScaleLayers(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());
    LayerSettings layer{
            .geometry =
                    Geometry{
                            .boundaries = rect,
                            .roundedCornersCrop = rect,
                            .positionTransform = kScaleAndTranslate,
                            .roundedCornersRadius = 300,
                    },
            .source = PixelSource{.buffer =
                                          Buffer{
                                                  .buffer = srcTexture,
                                                  .maxMasteringLuminance = 1000.f,
                                                  .maxContentLuminance = 1000.f,
                                                  .textureTransform = kScaleYOnly,
                                          }},
            .sourceDataspace = kOtherDataSpace,
    };

    auto layers = std::vector<const LayerSettings*>{&layer};
    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
// during actions that involve RenderEngine, logging the layer settings, and the shader code
@@ -250,6 +286,9 @@ void Cache::primeShaderCache(SkiaRenderEngine* renderengine) {
    // between 6 and 8 will occur in real uses.
    drawImageLayers(renderengine, display, dstTexture, externalTexture);

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

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