From 8ec9e88cdae4febf9ca9ff9d575b9add0a19409d Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Thu, 24 Aug 2017 16:36:08 -0400 Subject: Enable multi-threading of cpu intensive tasks when using Skia pipelines Test: CtsUiRenderingTestCases Change-Id: Ifa36371f55d3f2d78faf0a23fb283c904ff1af5f --- libs/hwui/renderthread/CacheManager.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libs/hwui/renderthread/CacheManager.cpp') diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp index f6b23e1a0723..0572a8d0afac 100644 --- a/libs/hwui/renderthread/CacheManager.cpp +++ b/libs/hwui/renderthread/CacheManager.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -73,6 +74,29 @@ void CacheManager::updateContextCacheSizes() { mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes); } +class CacheManager::SkiaTaskProcessor : public TaskProcessor, public SkExecutor { +public: + explicit SkiaTaskProcessor(TaskManager* taskManager) : TaskProcessor(taskManager) {} + + // This is really a Task but that doesn't really work when Future<> + // expects to be able to get/set a value + struct SkiaTask : public Task { + std::function func; + }; + + virtual void add(std::function func) override { + sp task(new SkiaTask()); + task->func = func; + TaskProcessor::add(task); + } + + virtual void onProcess(const sp >& task) override { + SkiaTask* t = static_cast(task.get()); + t->func(); + task->setResult(true); + } +}; + void CacheManager::configureContext(GrContextOptions* contextOptions) { contextOptions->fAllowPathMaskCaching = true; @@ -95,6 +119,13 @@ void CacheManager::configureContext(GrContextOptions* contextOptions) { // Skia's implementation doesn't provide a mechanism to resize the font cache due to // the potential cost of recreating the glyphs. contextOptions->fGlyphCacheTextureMaximumBytes = fontCacheMB * 1024 * 1024; + + if (mTaskManager.canRunTasks()) { + if (!mTaskProcessor.get()) { + mTaskProcessor = new SkiaTaskProcessor(&mTaskManager); + } + contextOptions->fExecutor = mTaskProcessor.get(); + } } void CacheManager::trimMemory(TrimMemoryMode mode) { -- cgit v1.2.3