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

Commit c4a05e18 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Cleanup initialization of GrContext.

Update GrContext options and setup the cache sizes to be based on
the size of the display and not the current default value of 255MB.

Test: atest librenderengine_test
Bug: 183391755
Change-Id: I5be8d6fc54c31f0e2d1c44968284ad772866d6ab
parent 7f56cf87
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public:
    bool cleanupPostRender(CleanupMode mode) override;
    int getContextPriority() override;
    bool supportsBackgroundBlur() override { return mBlurFilter != nullptr; }
    void onPrimaryDisplaySizeChanged(ui::Size size) override {}

    EGLDisplay getEGLDisplay() const { return mEGLDisplay; }
    // Creates an output image for rendering to
+4 −0
Original line number Diff line number Diff line
@@ -153,6 +153,10 @@ public:
    virtual bool supportsProtectedContent() const = 0;
    virtual bool useProtectedContext(bool useProtectedContext) = 0;

    // Notify RenderEngine of changes to the dimensions of the primary display
    // so that it can configure its internal caches accordingly.
    virtual void onPrimaryDisplaySizeChanged(ui::Size size) = 0;

    // Renders layers for a particular display via GPU composition. This method
    // should be called for every display that needs to be rendered via the GPU.
    // @param display The display-wide settings that should be applied prior to
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public:
    MOCK_METHOD0(cleanFramebufferCache, void());
    MOCK_METHOD0(getContextPriority, int());
    MOCK_METHOD0(supportsBackgroundBlur, bool());
    MOCK_METHOD1(onPrimaryDisplaySizeChanged, void(ui::Size));
};

} // namespace mock
+23 −1
Original line number Diff line number Diff line
@@ -294,12 +294,13 @@ SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGL
        mPlaceholderSurface(placeholder),
        mProtectedEGLContext(protectedContext),
        mProtectedPlaceholderSurface(protectedPlaceholder),
        mDefaultPixelFormat(static_cast<PixelFormat>(args.pixelFormat)),
        mUseColorManagement(args.useColorManagement) {
    sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
    LOG_ALWAYS_FATAL_IF(!glInterface.get());

    GrContextOptions options;
    options.fPreferExternalImagesOverES3 = true;
    options.fDisableDriverCorrectnessWorkarounds = true;
    options.fDisableDistanceFieldPaths = true;
    options.fPersistentCache = &mSkSLCacheMonitor;
    mGrContext = GrDirectContext::MakeGL(glInterface, options);
@@ -1186,6 +1187,27 @@ int SkiaGLRenderEngine::getContextPriority() {
    return value;
}

void SkiaGLRenderEngine::onPrimaryDisplaySizeChanged(ui::Size size) {
    // This cache multiplier was selected based on review of cache sizes relative
    // to the screen resolution. Looking at the worst case memory needed by blur (~1.5x),
    // shadows (~1x), and general data structures (e.g. vertex buffers) we selected this as a
    // conservative default based on that analysis.
    const float SURFACE_SIZE_MULTIPLIER = 3.5f * bytesPerPixel(mDefaultPixelFormat);
    const int maxResourceBytes = size.width * size.height * SURFACE_SIZE_MULTIPLIER;

    // start by resizing the current context
    auto grContext = mInProtectedContext ? mProtectedGrContext : mGrContext;
    grContext->setResourceCacheLimit(maxResourceBytes);

    // if it is possible to switch contexts then we will resize the other context
    if (useProtectedContext(!mInProtectedContext)) {
        grContext = mInProtectedContext ? mProtectedGrContext : mGrContext;
        grContext->setResourceCacheLimit(maxResourceBytes);
        // reset back to the initial context that was active when this method was called
        useProtectedContext(!mInProtectedContext);
    }
}

void SkiaGLRenderEngine::dump(std::string& result) {
    const gl::GLExtensions& extensions = gl::GLExtensions::getInstance();

+2 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public:
    bool useProtectedContext(bool useProtectedContext) override;
    bool supportsBackgroundBlur() override { return mBlurFilter != nullptr; }
    void assertShadersCompiled(int numShaders) override;
    void onPrimaryDisplaySizeChanged(ui::Size size) override;

protected:
    void dump(std::string& result) override;
@@ -109,6 +110,7 @@ private:
    EGLSurface mProtectedPlaceholderSurface;
    BlurFilter* mBlurFilter = nullptr;

    const PixelFormat mDefaultPixelFormat;
    const bool mUseColorManagement;

    // Cache of GL textures that we'll store per GraphicBuffer ID
Loading