1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2006 The Android Open Source Project 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "src/core/SkUtils.h" 9cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 10cb93a386Sopenharmony_ci#include <parameters.h> 11cb93a386Sopenharmony_ci#endif 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ciconst char SkHexadecimalDigits::gUpper[16] = 14cb93a386Sopenharmony_ci { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 15cb93a386Sopenharmony_ciconst char SkHexadecimalDigits::gLower[16] = 16cb93a386Sopenharmony_ci { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_ci// vma cache 19cb93a386Sopenharmony_cistatic thread_local bool g_vmaCacheFlag = false; 20cb93a386Sopenharmony_ci 21cb93a386Sopenharmony_cibool SkGetMemoryOptimizedFlag() 22cb93a386Sopenharmony_ci{ 23cb93a386Sopenharmony_ci // global flag for vma cache 24cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 25cb93a386Sopenharmony_ci static bool g_memoryOptimizeFlag = OHOS::system::GetBoolParameter("sys.graphic.vma.opt", false); 26cb93a386Sopenharmony_ci#else 27cb93a386Sopenharmony_ci static bool g_memoryOptimizeFlag = false; 28cb93a386Sopenharmony_ci#endif 29cb93a386Sopenharmony_ci return g_memoryOptimizeFlag; 30cb93a386Sopenharmony_ci} 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_cibool SkGetVmaCacheFlag() 33cb93a386Sopenharmony_ci{ 34cb93a386Sopenharmony_ci if (!SkGetMemoryOptimizedFlag()) { 35cb93a386Sopenharmony_ci return false; 36cb93a386Sopenharmony_ci } 37cb93a386Sopenharmony_ci return g_vmaCacheFlag; 38cb93a386Sopenharmony_ci} 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_civoid SkSetVmaCacheFlag(bool flag) 41cb93a386Sopenharmony_ci{ 42cb93a386Sopenharmony_ci g_vmaCacheFlag = flag; 43cb93a386Sopenharmony_ci} 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 46cb93a386Sopenharmony_ciint GetIntParamWithDefault(int paramValue, int maxValue, int defaultValue) 47cb93a386Sopenharmony_ci{ 48cb93a386Sopenharmony_ci if (paramValue <= 0 || paramValue > maxValue) { 49cb93a386Sopenharmony_ci paramValue = defaultValue; // default value 50cb93a386Sopenharmony_ci } 51cb93a386Sopenharmony_ci return paramValue; 52cb93a386Sopenharmony_ci} 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_cibool GetBoolParamWithFlag(bool paramValue) 55cb93a386Sopenharmony_ci{ 56cb93a386Sopenharmony_ci if (!SkGetMemoryOptimizedFlag()) { 57cb93a386Sopenharmony_ci return false; 58cb93a386Sopenharmony_ci } 59cb93a386Sopenharmony_ci return paramValue; 60cb93a386Sopenharmony_ci} 61cb93a386Sopenharmony_ci#endif 62cb93a386Sopenharmony_ci 63cb93a386Sopenharmony_ciint SkGetVmaBlockSizeMB() 64cb93a386Sopenharmony_ci{ 65cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 66cb93a386Sopenharmony_ci constexpr int DEFAULT_VMA_BLOCK_SIZE = 48; 67cb93a386Sopenharmony_ci#ifdef USE_LARGE_VMA_BLOCK 68cb93a386Sopenharmony_ci constexpr int MAX_VMA_BLOCK_SIZE = 256; 69cb93a386Sopenharmony_ci static int g_vmaBlockSize = GetIntParamWithDefault( 70cb93a386Sopenharmony_ci std::atoi(OHOS::system::GetParameter("sys.graphic.vma.blockSize", "48").c_str()), 71cb93a386Sopenharmony_ci MAX_VMA_BLOCK_SIZE, DEFAULT_VMA_BLOCK_SIZE); 72cb93a386Sopenharmony_ci#else 73cb93a386Sopenharmony_ci static int g_vmaBlockSize = DEFAULT_VMA_BLOCK_SIZE; 74cb93a386Sopenharmony_ci#endif 75cb93a386Sopenharmony_ci#else 76cb93a386Sopenharmony_ci static int g_vmaBlockSize = 4; // default value 77cb93a386Sopenharmony_ci#endif 78cb93a386Sopenharmony_ci return g_vmaBlockSize; 79cb93a386Sopenharmony_ci} 80cb93a386Sopenharmony_ci 81cb93a386Sopenharmony_ciint SkGetNeedCachedMemroySize() 82cb93a386Sopenharmony_ci{ 83cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 84cb93a386Sopenharmony_ci constexpr int MAX_VMA_CACHE_MEMORY_SIZE = 512 * 1024 * 1024; 85cb93a386Sopenharmony_ci constexpr int DEFAULT_VMA_CACHE_MEMORY_SIZE = 9000000; 86cb93a386Sopenharmony_ci static int g_vmaCacheMemorySize = GetIntParamWithDefault( 87cb93a386Sopenharmony_ci std::atoi(OHOS::system::GetParameter("sys.graphic.vma.minCachedSize", "9000000").c_str()), 88cb93a386Sopenharmony_ci MAX_VMA_CACHE_MEMORY_SIZE, DEFAULT_VMA_CACHE_MEMORY_SIZE); 89cb93a386Sopenharmony_ci#else 90cb93a386Sopenharmony_ci static int g_vmaCacheMemorySize = 0; // default value 91cb93a386Sopenharmony_ci#endif 92cb93a386Sopenharmony_ci return g_vmaCacheMemorySize; 93cb93a386Sopenharmony_ci} 94cb93a386Sopenharmony_ci 95cb93a386Sopenharmony_cibool SkGetVmaDefragmentOn() 96cb93a386Sopenharmony_ci{ 97cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 98cb93a386Sopenharmony_ci static bool g_vmaDefragmentFlag = 99cb93a386Sopenharmony_ci GetBoolParamWithFlag(OHOS::system::GetBoolParameter("sys.graphic.vma.defragment", true)); 100cb93a386Sopenharmony_ci return g_vmaDefragmentFlag; 101cb93a386Sopenharmony_ci#else 102cb93a386Sopenharmony_ci return false; 103cb93a386Sopenharmony_ci#endif 104cb93a386Sopenharmony_ci} 105cb93a386Sopenharmony_ci 106cb93a386Sopenharmony_cibool SkGetPreAllocFlag() 107cb93a386Sopenharmony_ci{ 108cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 109cb93a386Sopenharmony_ci static bool g_vmaPreAllocFlag = 110cb93a386Sopenharmony_ci GetBoolParamWithFlag(OHOS::system::GetBoolParameter("sys.graphic.vma.preAlloc", false)); 111cb93a386Sopenharmony_ci return g_vmaPreAllocFlag; 112cb93a386Sopenharmony_ci#else 113cb93a386Sopenharmony_ci return false; 114cb93a386Sopenharmony_ci#endif 115cb93a386Sopenharmony_ci} 116cb93a386Sopenharmony_ci 117cb93a386Sopenharmony_cisize_t SkGetPreAllocDelay() 118cb93a386Sopenharmony_ci{ 119cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 120cb93a386Sopenharmony_ci constexpr int MAX_VMA_PREALLOC_DELAY = 5000; 121cb93a386Sopenharmony_ci constexpr int DEFAULT_VMA_PREALLOC_DELAY = 250; 122cb93a386Sopenharmony_ci static int g_vmaBlockCountMax = GetIntParamWithDefault( 123cb93a386Sopenharmony_ci std::atoi(OHOS::system::GetParameter("sys.graphic.vma.preAllocDelay", "250").c_str()), 124cb93a386Sopenharmony_ci MAX_VMA_PREALLOC_DELAY, DEFAULT_VMA_PREALLOC_DELAY); 125cb93a386Sopenharmony_ci return g_vmaBlockCountMax; 126cb93a386Sopenharmony_ci#else 127cb93a386Sopenharmony_ci return SIZE_MAX; // default value 128cb93a386Sopenharmony_ci#endif 129cb93a386Sopenharmony_ci} 130cb93a386Sopenharmony_ci 131cb93a386Sopenharmony_cisize_t SkGetVmaBlockCountMax() 132cb93a386Sopenharmony_ci{ 133cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 134cb93a386Sopenharmony_ci constexpr int MAX_VMA_BLOCK_COUNT_MAX = 4096; 135cb93a386Sopenharmony_ci constexpr int DEFAULT_VMA_BLOCK_COUNT_MAX = 10; 136cb93a386Sopenharmony_ci static int g_vmaBlockCountMax = GetIntParamWithDefault( 137cb93a386Sopenharmony_ci std::atoi(OHOS::system::GetParameter("sys.graphic.vma.maxBlockCount", "10").c_str()), 138cb93a386Sopenharmony_ci MAX_VMA_BLOCK_COUNT_MAX, DEFAULT_VMA_BLOCK_COUNT_MAX); 139cb93a386Sopenharmony_ci return g_vmaBlockCountMax; 140cb93a386Sopenharmony_ci#else 141cb93a386Sopenharmony_ci return SIZE_MAX; // default value 142cb93a386Sopenharmony_ci#endif 143cb93a386Sopenharmony_ci} 144cb93a386Sopenharmony_ci 145cb93a386Sopenharmony_cibool SkGetVmaDebugFlag() 146cb93a386Sopenharmony_ci{ 147cb93a386Sopenharmony_ci#ifdef NOT_BUILD_FOR_OHOS_SDK 148cb93a386Sopenharmony_ci static bool g_vmaDebugFlag = 149cb93a386Sopenharmony_ci GetBoolParamWithFlag(std::atoi(OHOS::system::GetParameter("sys.graphic.vma.debug", "0").c_str()) != 0); 150cb93a386Sopenharmony_ci return g_vmaDebugFlag; 151cb93a386Sopenharmony_ci#else 152cb93a386Sopenharmony_ci return false; 153cb93a386Sopenharmony_ci#endif 154cb93a386Sopenharmony_ci} 155