1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CACHEMANAGER_H 18 #define CACHEMANAGER_H 19 20 #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration 21 #include <GrContext.h> 22 #endif 23 #include <SkSurface.h> 24 #include <utils/String8.h> 25 #include <vector> 26 27 namespace android { 28 29 class Surface; 30 31 namespace uirenderer { 32 33 class RenderState; 34 35 namespace renderthread { 36 37 class IRenderPipeline; 38 class RenderThread; 39 40 class CacheManager { 41 public: 42 enum class TrimMemoryMode { Complete, UiHidden }; 43 44 #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration 45 void configureContext(GrContextOptions* context, const void* identity, ssize_t size); 46 #endif 47 void trimMemory(TrimMemoryMode mode); 48 void trimStaleResources(); 49 void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr); 50 getCacheSize()51 size_t getCacheSize() const { return mMaxResourceBytes; } getBackgroundCacheSize()52 size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; } 53 void onFrameCompleted(); 54 55 private: 56 friend class RenderThread; 57 58 explicit CacheManager(); 59 60 #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration 61 void reset(sk_sp<GrContext> grContext); 62 #endif 63 void destroy(); 64 65 const size_t mMaxSurfaceArea; 66 #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration 67 sk_sp<GrContext> mGrContext; 68 #endif 69 70 const size_t mMaxResourceBytes; 71 const size_t mBackgroundResourceBytes; 72 73 const size_t mMaxGpuFontAtlasBytes; 74 const size_t mMaxCpuFontCacheBytes; 75 const size_t mBackgroundCpuFontCacheBytes; 76 }; 77 78 } /* namespace renderthread */ 79 } /* namespace uirenderer */ 80 } /* namespace android */ 81 82 #endif /* CACHEMANAGER_H */ 83