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

Commit 2fc978ff authored by Ana Krulec's avatar Ana Krulec Committed by Android (Google) Code Review
Browse files

Merge "Caching images and textures for threaded Skia RE"

parents ea5d5a9c dfec8f5f
Loading
Loading
Loading
Loading
+20 −3
Original line number Original line Diff line number Diff line
@@ -51,11 +51,28 @@ std::unique_ptr<RenderEngine> RenderEngine::create(const RenderEngineCreationArg
            return renderengine::threaded::RenderEngineThreaded::create(
            return renderengine::threaded::RenderEngineThreaded::create(
                    [args]() { return android::renderengine::gl::GLESRenderEngine::create(args); });
                    [args]() { return android::renderengine::gl::GLESRenderEngine::create(args); });
        case RenderEngineType::SKIA_GL:
        case RenderEngineType::SKIA_GL:
            ALOGD("RenderEngine with SkiaGL Backend");
            return renderengine::skia::SkiaGLRenderEngine::create(args);
            return renderengine::skia::SkiaGLRenderEngine::create(args);
        case RenderEngineType::SKIA_GL_THREADED:
        case RenderEngineType::SKIA_GL_THREADED: {
            return renderengine::threaded::RenderEngineThreaded::create([args]() {
            // These need to be recreated, since they are a constant reference, and we need to
                return android::renderengine::skia::SkiaGLRenderEngine::create(args);
            // let SkiaRE know that it's running as threaded, and all GL operation will happen on
            // the same thread.
            RenderEngineCreationArgs skiaArgs =
                    RenderEngineCreationArgs::Builder()
                            .setPixelFormat(args.pixelFormat)
                            .setImageCacheSize(args.imageCacheSize)
                            .setUseColorManagerment(args.useColorManagement)
                            .setEnableProtectedContext(args.enableProtectedContext)
                            .setPrecacheToneMapperShaderOnly(args.precacheToneMapperShaderOnly)
                            .setSupportsBackgroundBlur(args.supportsBackgroundBlur)
                            .setContextPriority(args.contextPriority)
                            .setRenderEngineType(RenderEngineType::SKIA_GL_THREADED)
                            .build();
            ALOGD("Threaded RenderEngine with SkiaGL Backend");
            return renderengine::threaded::RenderEngineThreaded::create([skiaArgs]() {
                return android::renderengine::skia::SkiaGLRenderEngine::create(skiaArgs);
            });
            });
        }
        case RenderEngineType::GLES:
        case RenderEngineType::GLES:
        default:
        default:
            ALOGD("RenderEngine with GLES Backend");
            ALOGD("RenderEngine with GLES Backend");
+1 −0
Original line number Original line Diff line number Diff line
@@ -746,6 +746,7 @@ void GLESRenderEngine::bindExternalTextureBuffer(uint32_t texName, const sp<Grap
}
}


void GLESRenderEngine::cacheExternalTextureBuffer(const sp<GraphicBuffer>& buffer) {
void GLESRenderEngine::cacheExternalTextureBuffer(const sp<GraphicBuffer>& buffer) {
    ATRACE_CALL();
    mImageManager->cacheAsync(buffer, nullptr);
    mImageManager->cacheAsync(buffer, nullptr);
}
}


+27 −1
Original line number Original line Diff line number Diff line
@@ -267,7 +267,8 @@ SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGL
        mPlaceholderSurface(placeholder),
        mPlaceholderSurface(placeholder),
        mProtectedEGLContext(protectedContext),
        mProtectedEGLContext(protectedContext),
        mProtectedPlaceholderSurface(protectedPlaceholder),
        mProtectedPlaceholderSurface(protectedPlaceholder),
        mUseColorManagement(args.useColorManagement) {
        mUseColorManagement(args.useColorManagement),
        mRenderEngineType(args.renderEngineType) {
    sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
    sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface());
    LOG_ALWAYS_FATAL_IF(!glInterface.get());
    LOG_ALWAYS_FATAL_IF(!glInterface.get());


@@ -453,7 +454,30 @@ static bool needsLinearEffect(const mat4& colorTransform, ui::Dataspace sourceDa
    return colorTransform != mat4() || needsToneMapping(sourceDataspace, destinationDataspace);
    return colorTransform != mat4() || needsToneMapping(sourceDataspace, destinationDataspace);
}
}


void SkiaGLRenderEngine::cacheExternalTextureBuffer(const sp<GraphicBuffer>& buffer) {
    // Only run this if RE is running on its own thread. This way the access to GL
    // operations is guaranteed to be happening on the same thread.
    if (mRenderEngineType != RenderEngineType::SKIA_GL_THREADED) {
        return;
    }
    ATRACE_CALL();

    std::lock_guard<std::mutex> lock(mRenderingMutex);
    auto iter = mTextureCache.find(buffer->getId());
    if (iter != mTextureCache.end()) {
        ALOGV("Texture already exists in cache.");
        return;
    } else {
        std::shared_ptr<AutoBackendTexture::LocalRef> imageTextureRef =
                std::make_shared<AutoBackendTexture::LocalRef>();
        imageTextureRef->setTexture(
                new AutoBackendTexture(mGrContext.get(), buffer->toAHardwareBuffer(), false));
        mTextureCache.insert({buffer->getId(), imageTextureRef});
    }
}

void SkiaGLRenderEngine::unbindExternalTextureBuffer(uint64_t bufferId) {
void SkiaGLRenderEngine::unbindExternalTextureBuffer(uint64_t bufferId) {
    ATRACE_CALL();
    std::lock_guard<std::mutex> lock(mRenderingMutex);
    std::lock_guard<std::mutex> lock(mRenderingMutex);
    mTextureCache.erase(bufferId);
    mTextureCache.erase(bufferId);
    mProtectedTextureCache.erase(bufferId);
    mProtectedTextureCache.erase(bufferId);
@@ -523,11 +547,13 @@ status_t SkiaGLRenderEngine::drawLayers(const DisplaySettings& display,
        auto iter = cache.find(buffer->getId());
        auto iter = cache.find(buffer->getId());
        if (iter != cache.end()) {
        if (iter != cache.end()) {
            ALOGV("Cache hit!");
            ALOGV("Cache hit!");
            ATRACE_NAME("Cache hit");
            surfaceTextureRef = iter->second;
            surfaceTextureRef = iter->second;
        }
        }
    }
    }


    if (surfaceTextureRef == nullptr || surfaceTextureRef->getTexture() == nullptr) {
    if (surfaceTextureRef == nullptr || surfaceTextureRef->getTexture() == nullptr) {
        ATRACE_NAME("Cache miss");
        surfaceTextureRef = std::make_shared<AutoBackendTexture::LocalRef>();
        surfaceTextureRef = std::make_shared<AutoBackendTexture::LocalRef>();
        surfaceTextureRef->setTexture(
        surfaceTextureRef->setTexture(
                new AutoBackendTexture(grContext.get(), buffer->toAHardwareBuffer(), true));
                new AutoBackendTexture(grContext.get(), buffer->toAHardwareBuffer(), true));
+5 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ public:
                       EGLSurface protectedPlaceholder);
                       EGLSurface protectedPlaceholder);
    ~SkiaGLRenderEngine() override EXCLUDES(mRenderingMutex);
    ~SkiaGLRenderEngine() override EXCLUDES(mRenderingMutex);


    void cacheExternalTextureBuffer(const sp<GraphicBuffer>& buffer) override;
    void unbindExternalTextureBuffer(uint64_t bufferId) override;
    void unbindExternalTextureBuffer(uint64_t bufferId) override;
    status_t drawLayers(const DisplaySettings& display,
    status_t drawLayers(const DisplaySettings& display,
                        const std::vector<const LayerSettings*>& layers,
                        const std::vector<const LayerSettings*>& layers,
@@ -128,6 +129,10 @@ private:
    bool mInProtectedContext = false;
    bool mInProtectedContext = false;
    // Object to capture commands send to Skia.
    // Object to capture commands send to Skia.
    std::unique_ptr<SkiaCapture> mCapture;
    std::unique_ptr<SkiaCapture> mCapture;

    // Keep this information as a local variable to determine whether the access of the GL
    // operations is working on the same threads.
    const RenderEngineType mRenderEngineType = RenderEngineType::SKIA_GL;
};
};


} // namespace skia
} // namespace skia
+0 −16
Original line number Original line Diff line number Diff line
@@ -62,22 +62,6 @@ TEST_F(RenderEngineThreadedTest, deleteTextures) {
    mThreadedRE->deleteTextures(1, &texName);
    mThreadedRE->deleteTextures(1, &texName);
}
}


TEST_F(RenderEngineThreadedTest, cacheExternalTextureBuffer_nullptr) {
    EXPECT_CALL(*mRenderEngine, cacheExternalTextureBuffer(Eq(nullptr)));
    mThreadedRE->cacheExternalTextureBuffer(nullptr);
}

TEST_F(RenderEngineThreadedTest, cacheExternalTextureBuffer_withBuffer) {
    sp<GraphicBuffer> buf = new GraphicBuffer();
    EXPECT_CALL(*mRenderEngine, cacheExternalTextureBuffer(buf));
    mThreadedRE->cacheExternalTextureBuffer(buf);
}

TEST_F(RenderEngineThreadedTest, unbindExternalTextureBuffer) {
    EXPECT_CALL(*mRenderEngine, unbindExternalTextureBuffer(0x0));
    mThreadedRE->unbindExternalTextureBuffer(0x0);
}

TEST_F(RenderEngineThreadedTest, getMaxTextureSize_returns20) {
TEST_F(RenderEngineThreadedTest, getMaxTextureSize_returns20) {
    size_t size = 20;
    size_t size = 20;
    EXPECT_CALL(*mRenderEngine, getMaxTextureSize()).WillOnce(Return(size));
    EXPECT_CALL(*mRenderEngine, getMaxTextureSize()).WillOnce(Return(size));
Loading