summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread/CacheManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/renderthread/CacheManager.cpp')
-rw-r--r--libs/hwui/renderthread/CacheManager.cpp51
1 files changed, 22 insertions, 29 deletions
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp
index 1b638c12ac7b..1e5877356e8d 100644
--- a/libs/hwui/renderthread/CacheManager.cpp
+++ b/libs/hwui/renderthread/CacheManager.cpp
@@ -16,19 +16,21 @@
#include "CacheManager.h"
+#include "DeviceInfo.h"
#include "Layer.h"
#include "Properties.h"
#include "RenderThread.h"
+#include "pipeline/skia/ATraceMemoryDump.h"
#include "pipeline/skia/ShaderCache.h"
#include "pipeline/skia/SkiaMemoryTracer.h"
#include "renderstate/RenderState.h"
#include "thread/CommonPool.h"
+#include <utils/Trace.h>
#include <GrContextOptions.h>
#include <SkExecutor.h>
#include <SkGraphics.h>
#include <SkMathPriv.h>
-#include <gui/Surface.h>
#include <math.h>
#include <set>
@@ -43,8 +45,8 @@ namespace renderthread {
#define SURFACE_SIZE_MULTIPLIER (12.0f * 4.0f)
#define BACKGROUND_RETENTION_PERCENTAGE (0.5f)
-CacheManager::CacheManager(const DisplayInfo& display)
- : mMaxSurfaceArea(display.w * display.h)
+CacheManager::CacheManager()
+ : mMaxSurfaceArea(DeviceInfo::getWidth() * DeviceInfo::getHeight())
, mMaxResourceBytes(mMaxSurfaceArea * SURFACE_SIZE_MULTIPLIER)
, mBackgroundResourceBytes(mMaxResourceBytes * BACKGROUND_RETENTION_PERCENTAGE)
// This sets the maximum size for a single texture atlas in the GPU font cache. If
@@ -53,14 +55,10 @@ CacheManager::CacheManager(const DisplayInfo& display)
, mMaxGpuFontAtlasBytes(GrNextSizePow2(mMaxSurfaceArea))
// This sets the maximum size of the CPU font cache to be at least the same size as the
// total number of GPU font caches (i.e. 4 separate GPU atlases).
- , mMaxCpuFontCacheBytes(std::max(mMaxGpuFontAtlasBytes*4, SkGraphics::GetFontCacheLimit()))
+ , mMaxCpuFontCacheBytes(
+ std::max(mMaxGpuFontAtlasBytes * 4, SkGraphics::GetFontCacheLimit()))
, mBackgroundCpuFontCacheBytes(mMaxCpuFontCacheBytes * BACKGROUND_RETENTION_PERCENTAGE) {
-
SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
-
- mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(
- mMaxSurfaceArea / 2,
- skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface);
}
void CacheManager::reset(sk_sp<GrContext> context) {
@@ -70,17 +68,13 @@ void CacheManager::reset(sk_sp<GrContext> context) {
if (context) {
mGrContext = std::move(context);
- mGrContext->getResourceCacheLimits(&mMaxResources, nullptr);
- mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
+ mGrContext->setResourceCacheLimit(mMaxResourceBytes);
}
}
void CacheManager::destroy() {
// cleanup any caches here as the GrContext is about to go away...
mGrContext.reset(nullptr);
- mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(
- mMaxSurfaceArea / 2,
- skiapipeline::VectorDrawableAtlas::StorageMode::disallowSharedSurface);
}
class CommonPoolExecutor : public SkExecutor {
@@ -111,7 +105,6 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
switch (mode) {
case TrimMemoryMode::Complete:
- mVectorDrawableAtlas = new skiapipeline::VectorDrawableAtlas(mMaxSurfaceArea / 2);
mGrContext->freeGpuResources();
SkGraphics::PurgeAllCaches();
break;
@@ -120,8 +113,8 @@ void CacheManager::trimMemory(TrimMemoryMode mode) {
// limits between the background and max amounts. This causes the unlocked resources
// that have persistent data to be purged in LRU order.
mGrContext->purgeUnlockedResources(true);
- mGrContext->setResourceCacheLimits(mMaxResources, mBackgroundResourceBytes);
- mGrContext->setResourceCacheLimits(mMaxResources, mMaxResourceBytes);
+ mGrContext->setResourceCacheLimit(mBackgroundResourceBytes);
+ mGrContext->setResourceCacheLimit(mMaxResourceBytes);
SkGraphics::SetFontCacheLimit(mBackgroundCpuFontCacheBytes);
SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
break;
@@ -140,16 +133,6 @@ void CacheManager::trimStaleResources() {
mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30));
}
-sp<skiapipeline::VectorDrawableAtlas> CacheManager::acquireVectorDrawableAtlas() {
- LOG_ALWAYS_FATAL_IF(mVectorDrawableAtlas.get() == nullptr);
- LOG_ALWAYS_FATAL_IF(mGrContext == nullptr);
-
- /**
- * TODO: define memory conditions where we clear the cache (e.g. surface->reset())
- */
- return mVectorDrawableAtlas;
-}
-
void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) {
if (!mGrContext) {
log.appendFormat("No valid cache instance.\n");
@@ -178,8 +161,6 @@ void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState)
log.appendFormat("Other 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);
if (renderState) {
if (renderState->mActiveLayers.size() > 0) {
@@ -205,6 +186,18 @@ void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState)
gpuTracer.logTotals(log);
}
+void CacheManager::onFrameCompleted() {
+ if (ATRACE_ENABLED()) {
+ static skiapipeline::ATraceMemoryDump tracer;
+ tracer.startFrame();
+ SkGraphics::DumpMemoryStatistics(&tracer);
+ if (mGrContext) {
+ mGrContext->dumpMemoryStatistics(&tracer);
+ }
+ tracer.logTraces();
+ }
+}
+
} /* namespace renderthread */
} /* namespace uirenderer */
} /* namespace android */