1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "gpu/config/skia_limits.h" 6 7 #include <inttypes.h> 8 9 #include "base/system/sys_info.h" 10 #include "build/build_config.h" 11 12 namespace gpu { 13 DetermineGrCacheLimitsFromAvailableMemory(size_t * max_resource_cache_bytes,size_t * max_glyph_cache_texture_bytes)14void DetermineGrCacheLimitsFromAvailableMemory( 15 size_t* max_resource_cache_bytes, 16 size_t* max_glyph_cache_texture_bytes) { 17 // Default limits. 18 constexpr size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024; 19 constexpr size_t kMaxDefaultGlyphCacheTextureBytes = 2048 * 1024 * 4; 20 21 *max_resource_cache_bytes = kMaxGaneshResourceCacheBytes; 22 *max_glyph_cache_texture_bytes = kMaxDefaultGlyphCacheTextureBytes; 23 24 // We can't call AmountOfPhysicalMemory under NACL, so leave the default. 25 #if !defined(OS_NACL) 26 // The limit of the bytes allocated toward GPU resources in the GrContext's 27 // GPU cache. 28 #if defined(OS_FUCHSIA) 29 // Reduce protected budget on fuchsia due to https://fxb/36620. 30 constexpr size_t kMaxLowEndGaneshResourceCacheBytes = 24 * 1024 * 1024; 31 #else 32 constexpr size_t kMaxLowEndGaneshResourceCacheBytes = 48 * 1024 * 1024; 33 #endif // defined(OS_FUCHSIA) 34 constexpr size_t kMaxHighEndGaneshResourceCacheBytes = 256 * 1024 * 1024; 35 // Limits for glyph cache textures. 36 constexpr size_t kMaxLowEndGlyphCacheTextureBytes = 1024 * 512 * 4; 37 // High-end / low-end memory cutoffs. 38 constexpr int64_t kHighEndMemoryThreshold = 4096LL * 1024 * 1024; 39 40 if (base::SysInfo::IsLowEndDevice()) { 41 *max_resource_cache_bytes = kMaxLowEndGaneshResourceCacheBytes; 42 *max_glyph_cache_texture_bytes = kMaxLowEndGlyphCacheTextureBytes; 43 } else if (base::SysInfo::AmountOfPhysicalMemory() >= 44 kHighEndMemoryThreshold) { 45 *max_resource_cache_bytes = kMaxHighEndGaneshResourceCacheBytes; 46 } 47 #endif 48 } 49 DefaultGrCacheLimitsForTests(size_t * max_resource_cache_bytes,size_t * max_glyph_cache_texture_bytes)50void DefaultGrCacheLimitsForTests(size_t* max_resource_cache_bytes, 51 size_t* max_glyph_cache_texture_bytes) { 52 constexpr size_t kDefaultGlyphCacheTextureBytes = 2048 * 1024 * 4; 53 constexpr size_t kDefaultGaneshResourceCacheBytes = 96 * 1024 * 1024; 54 *max_resource_cache_bytes = kDefaultGaneshResourceCacheBytes; 55 *max_glyph_cache_texture_bytes = kDefaultGlyphCacheTextureBytes; 56 } 57 58 } // namespace gpu 59