Implement CacheManager for the Skia pipelines.
The core of the implementation is complete and provides heuristic
cache sizing based on the size of the surface being used. This CL
will also be used to add the following features in the future...
1) Support Vulkan pipeline reporting on the size of the surface.
2) Complete the VectorDrawableAtlas stub code
3) Automatic purging of stale resources for low memory devices.
Test: hwui_unit_tests (new test added) and CtsUiRendering
Bug: 62260637
Change-Id: Ib85159cca28b646fe249f2190b07f1b7e0f50d8f
diff --git a/libs/hwui/renderthread/CacheManager.h b/libs/hwui/renderthread/CacheManager.h
new file mode 100644
index 0000000..43d58f2
--- /dev/null
+++ b/libs/hwui/renderthread/CacheManager.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CACHEMANAGER_H
+#define CACHEMANAGER_H
+
+#include <GrContext.h>
+#include <SkSurface.h>
+#include <ui/DisplayInfo.h>
+#include <utils/String8.h>
+#include <vector>
+
+namespace android {
+
+class Surface;
+
+namespace uirenderer {
+
+class RenderState;
+
+namespace renderthread {
+
+class IRenderPipeline;
+class RenderThread;
+
+struct VectorDrawableAtlas {
+ sk_sp<SkSurface> surface;
+ bool isNewAtlas = true;
+};
+
+class CacheManager {
+public:
+ enum class TrimMemoryMode {
+ Complete,
+ UiHidden
+ };
+
+ void configureContext(GrContextOptions* context);
+ void trimMemory(TrimMemoryMode mode);
+ void trimStaleResources();
+ void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
+
+ VectorDrawableAtlas* acquireVectorDrawableAtlas();
+ void releaseVectorDrawableAtlas(VectorDrawableAtlas*);
+
+ size_t getCacheSize() const { return mMaxResourceBytes; }
+ size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
+
+private:
+ friend class RenderThread;
+
+ CacheManager(const DisplayInfo& display);
+
+
+ void reset(GrContext* grContext);
+ void destroy();
+ void updateContextCacheSizes();
+
+ const size_t mMaxSurfaceArea;
+ sk_sp<GrContext> mGrContext;
+
+ int mMaxResources = 0;
+ size_t mMaxResourceBytes = 0;
+ size_t mBackgroundResourceBytes = 0;
+
+ struct PipelineProps {
+ const void* pipelineKey = nullptr;
+ size_t surfaceArea = 0;
+ };
+
+ std::unique_ptr<VectorDrawableAtlas> mVectorDrawableAtlas;
+};
+
+} /* namespace renderthread */
+} /* namespace uirenderer */
+} /* namespace android */
+
+#endif /* CACHEMANAGER_H */
+