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