diff options
Diffstat (limited to 'libs/hwui/renderthread/CacheManager.cpp')
-rw-r--r-- | libs/hwui/renderthread/CacheManager.cpp | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp index 55694d046c2f..907f2d2d398f 100644 --- a/libs/hwui/renderthread/CacheManager.cpp +++ b/libs/hwui/renderthread/CacheManager.cpp @@ -17,11 +17,14 @@ #include "CacheManager.h" #include "Layer.h" +#include "Properties.h" #include "RenderThread.h" +#include "pipeline/skia/ShaderCache.h" #include "renderstate/RenderState.h" -#include <gui/Surface.h> #include <GrContextOptions.h> +#include <SkExecutor.h> +#include <gui/Surface.h> #include <math.h> #include <set> @@ -41,19 +44,22 @@ namespace renderthread { #define FONT_CACHE_MIN_MB (0.5f) #define FONT_CACHE_MAX_MB (4.0f) -CacheManager::CacheManager(const DisplayInfo& display) - : mMaxSurfaceArea(display.w * display.h) { - mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea/2, - skiapipeline::VectorDrawableAtlas::StorageMode::allowSharedSurface); +CacheManager::CacheManager(const DisplayInfo& display) : mMaxSurfaceArea(display.w * display.h) { + mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas( + mMaxSurfaceArea / 2, + skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface); + if (Properties::isSkiaEnabled()) { + skiapipeline::ShaderCache::get().initShaderDiskCache(); + } } -void CacheManager::reset(GrContext* context) { - if (context != mGrContext.get()) { +void CacheManager::reset(sk_sp<GrContext> context) { + if (context != mGrContext) { destroy(); } if (context) { - mGrContext = sk_ref_sp(context); + mGrContext = std::move(context); mGrContext->getResourceCacheLimits(&mMaxResources, nullptr); updateContextCacheSizes(); } @@ -62,7 +68,9 @@ void CacheManager::reset(GrContext* context) { void CacheManager::destroy() { // cleanup any caches here as the GrContext is about to go away... mGrContext.reset(nullptr); - mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea/2); + mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas( + mMaxSurfaceArea / 2, + skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface); } void CacheManager::updateContextCacheSizes() { @@ -72,6 +80,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; @@ -94,6 +125,15 @@ 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(); + } + + contextOptions->fPersistentCache = &skiapipeline::ShaderCache::get(); } void CacheManager::trimMemory(TrimMemoryMode mode) { @@ -105,7 +145,7 @@ void CacheManager::trimMemory(TrimMemoryMode mode) { switch (mode) { case TrimMemoryMode::Complete: - mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea/2); + mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea / 2); mGrContext->freeGpuResources(); break; case TrimMemoryMode::UiHidden: @@ -143,8 +183,8 @@ void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) log.appendFormat("Caches:\n"); log.appendFormat(" Current / Maximum\n"); - log.appendFormat(" VectorDrawableAtlas %6.2f kB / %6.2f kB (entries = %zu)\n", - 0.0f, 0.0f, (size_t)0); + log.appendFormat(" VectorDrawableAtlas %6.2f kB / %6.2f kB (entries = %zu)\n", 0.0f, 0.0f, + (size_t)0); if (renderState) { if (renderState->mActiveLayers.size() > 0) { @@ -153,24 +193,21 @@ void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) size_t layerMemoryTotal = 0; for (std::set<Layer*>::iterator it = renderState->mActiveLayers.begin(); - it != renderState->mActiveLayers.end(); it++) { + it != renderState->mActiveLayers.end(); it++) { const Layer* layer = *it; const char* layerType = layer->getApi() == Layer::Api::OpenGL ? "GlLayer" : "VkLayer"; - log.appendFormat(" %s size %dx%d\n", layerType, - layer->getWidth(), layer->getHeight()); + log.appendFormat(" %s size %dx%d\n", layerType, layer->getWidth(), + layer->getHeight()); layerMemoryTotal += layer->getWidth() * layer->getHeight() * 4; } log.appendFormat(" Layers Total %6.2f kB (numLayers = %zu)\n", layerMemoryTotal / 1024.0f, renderState->mActiveLayers.size()); } - log.appendFormat("Total memory usage:\n"); - log.appendFormat(" %zu bytes, %.2f MB (%.2f MB is purgeable)\n", - bytesCached, bytesCached / 1024.0f / 1024.0f, + log.appendFormat(" %zu bytes, %.2f MB (%.2f MB is purgeable)\n", bytesCached, + bytesCached / 1024.0f / 1024.0f, mGrContext->getResourceCachePurgeableBytes() / 1024.0f / 1024.0f); - - } } /* namespace renderthread */ |