diff options
author | Derek Sollenberger <djsollen@google.com> | 2017-08-24 16:36:08 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2017-09-08 10:24:27 -0400 |
commit | 8ec9e88cdae4febf9ca9ff9d575b9add0a19409d (patch) | |
tree | d3e6bd5ec21d5d92d1e4c61830e2b84dd88e9d6f /libs/hwui/renderthread/CacheManager.cpp | |
parent | 10c41c2727aa5566ff6aed0c4709657c6517c855 (diff) |
Enable multi-threading of cpu intensive tasks when using Skia pipelines
Test: CtsUiRenderingTestCases
Change-Id: Ifa36371f55d3f2d78faf0a23fb283c904ff1af5f
Diffstat (limited to 'libs/hwui/renderthread/CacheManager.cpp')
-rw-r--r-- | libs/hwui/renderthread/CacheManager.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
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 <gui/Surface.h> #include <GrContextOptions.h> +#include <SkExecutor.h> #include <math.h> #include <set> @@ -73,6 +74,29 @@ void CacheManager::updateContextCacheSizes() { mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes); } +class CacheManager::SkiaTaskProcessor : public TaskProcessor<bool>, public SkExecutor { +public: + explicit SkiaTaskProcessor(TaskManager* taskManager) : TaskProcessor<bool>(taskManager) {} + + // This is really a Task<void> but that doesn't really work when Future<> + // expects to be able to get/set a value + struct SkiaTask : public Task<bool> { + std::function<void()> func; + }; + + virtual void add(std::function<void(void)> func) override { + sp<SkiaTask> task(new SkiaTask()); + task->func = func; + TaskProcessor<bool>::add(task); + } + + virtual void onProcess(const sp<Task<bool> >& task) override { + SkiaTask* t = static_cast<SkiaTask*>(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) { |