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

Commit 76800c89 authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Automerger Merge Worker
Browse files

Merge "Enable RenderEngine context switching to be async." into sc-dev am:...

Merge "Enable RenderEngine context switching to be async." into sc-dev am: b6d444ff am: d461f7ee

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

Change-Id: I181621f34ab15f6fbaebdfa48a7da99263323194
parents dea1865e d461f7ee
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -1028,20 +1028,17 @@ bool GLESRenderEngine::supportsProtectedContent() const {
    return mProtectedEGLContext != EGL_NO_CONTEXT;
}

bool GLESRenderEngine::useProtectedContext(bool useProtectedContext) {
    if (useProtectedContext == mInProtectedContext) {
        return true;
    }
    if (useProtectedContext && mProtectedEGLContext == EGL_NO_CONTEXT) {
        return false;
void GLESRenderEngine::useProtectedContext(bool useProtectedContext) {
    if (useProtectedContext == mInProtectedContext ||
        (useProtectedContext && !supportsProtectedContent())) {
        return;
    }

    const EGLSurface surface = useProtectedContext ? mProtectedStubSurface : mStubSurface;
    const EGLContext context = useProtectedContext ? mProtectedEGLContext : mEGLContext;
    const bool success = eglMakeCurrent(mEGLDisplay, surface, surface, context) == EGL_TRUE;
    if (success) {
    if (eglMakeCurrent(mEGLDisplay, surface, surface, context) == EGL_TRUE) {
        mInProtectedContext = useProtectedContext;
    }
    return success;
}
EGLImageKHR GLESRenderEngine::createFramebufferImageIfNeeded(ANativeWindowBuffer* nativeBuffer,
                                                             bool isProtected,
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public:
    void deleteTextures(size_t count, uint32_t const* names) override;
    bool isProtected() const override { return mInProtectedContext; }
    bool supportsProtectedContent() const override;
    bool useProtectedContext(bool useProtectedContext) override;
    void useProtectedContext(bool useProtectedContext) override;
    status_t drawLayers(const DisplaySettings& display,
                        const std::vector<const LayerSettings*>& layers,
                        const std::shared_ptr<ExternalTexture>& buffer,
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ public:
    virtual bool supportsProtectedContent() const = 0;

    // Attempt to switch RenderEngine into and out of protectedContext mode
    virtual bool useProtectedContext(bool useProtectedContext) = 0;
    virtual void useProtectedContext(bool useProtectedContext) = 0;

    // Notify RenderEngine of changes to the dimensions of the active display
    // so that it can configure its internal caches accordingly.
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public:
    MOCK_CONST_METHOD0(getMaxViewportDims, size_t());
    MOCK_CONST_METHOD0(isProtected, bool());
    MOCK_CONST_METHOD0(supportsProtectedContent, bool());
    MOCK_METHOD1(useProtectedContext, bool(bool));
    MOCK_METHOD1(useProtectedContext, void(bool));
    MOCK_METHOD0(cleanupPostRender, void());
    MOCK_CONST_METHOD0(canSkipPostRenderCleanup, bool());
    MOCK_METHOD6(drawLayers,
+11 −12
Original line number Diff line number Diff line
@@ -320,7 +320,8 @@ SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGL
    options.fReducedShaderVariations = true;
    options.fPersistentCache = &mSkSLCacheMonitor;
    mGrContext = GrDirectContext::MakeGL(glInterface, options);
    if (useProtectedContext(true)) {
    if (supportsProtectedContent()) {
        useProtectedContext(true);
        mProtectedGrContext = GrDirectContext::MakeGL(glInterface, options);
        useProtectedContext(false);
    }
@@ -373,12 +374,10 @@ GrDirectContext* SkiaGLRenderEngine::getActiveGrContext() const {
    return mInProtectedContext ? mProtectedGrContext.get() : mGrContext.get();
}

bool SkiaGLRenderEngine::useProtectedContext(bool useProtectedContext) {
    if (useProtectedContext == mInProtectedContext) {
        return true;
    }
    if (useProtectedContext && !supportsProtectedContent()) {
        return false;
void SkiaGLRenderEngine::useProtectedContext(bool useProtectedContext) {
    if (useProtectedContext == mInProtectedContext ||
        (useProtectedContext && !supportsProtectedContent())) {
        return;
    }

    // release any scratch resources before switching into a new mode
@@ -389,9 +388,8 @@ bool SkiaGLRenderEngine::useProtectedContext(bool useProtectedContext) {
    const EGLSurface surface =
            useProtectedContext ? mProtectedPlaceholderSurface : mPlaceholderSurface;
    const EGLContext context = useProtectedContext ? mProtectedEGLContext : mEGLContext;
    const bool success = eglMakeCurrent(mEGLDisplay, surface, surface, context) == EGL_TRUE;

    if (success) {
    if (eglMakeCurrent(mEGLDisplay, surface, surface, context) == EGL_TRUE) {
        mInProtectedContext = useProtectedContext;
        // given that we are sharing the same thread between two GrContexts we need to
        // make sure that the thread state is reset when switching between the two.
@@ -399,7 +397,6 @@ bool SkiaGLRenderEngine::useProtectedContext(bool useProtectedContext) {
            getActiveGrContext()->resetContext();
        }
    }
    return success;
}

base::unique_fd SkiaGLRenderEngine::flush() {
@@ -1413,10 +1410,12 @@ void SkiaGLRenderEngine::onActiveDisplaySizeChanged(ui::Size size) {
    getActiveGrContext()->setResourceCacheLimit(maxResourceBytes);

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

Loading