1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_TILES_IMAGE_DECODE_CACHE_UTILS_CC_
6 #define CC_TILES_IMAGE_DECODE_CACHE_UTILS_CC_
8 #include "cc/tiles/image_decode_cache_utils.h"
10 #include "base/check.h"
11 #include "cc/paint/paint_flags.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "third_party/skia/include/core/SkImageInfo.h"
14 #include "third_party/skia/include/core/SkPixmap.h"
16 #if !BUILDFLAG(IS_ANDROID)
17 #include "base/system/sys_info.h"
23 bool ImageDecodeCacheUtils::ShouldEvictCaches(
24 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
25 switch (memory_pressure_level) {
26 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
27 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
29 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
37 size_t ImageDecodeCacheUtils::GetWorkingSetBytesForImageDecode(
39 size_t decoded_image_working_set_budget_bytes = 128 * 1024 * 1024;
40 #if !BUILDFLAG(IS_ANDROID)
42 const bool using_low_memory_policy = base::SysInfo::IsLowEndDevice();
43 // If there's over 4GB of RAM, increase the working set size to 256MB for
44 // both gpu and software.
45 const int kImageDecodeMemoryThresholdMB = 4 * 1024;
46 if (using_low_memory_policy) {
47 decoded_image_working_set_budget_bytes = 32 * 1024 * 1024;
48 } else if (base::SysInfo::AmountOfPhysicalMemoryMB() >=
49 kImageDecodeMemoryThresholdMB) {
50 decoded_image_working_set_budget_bytes = 256 * 1024 * 1024;
53 #endif // !BUILDFLAG(IS_ANDROID)
54 return decoded_image_working_set_budget_bytes;
59 #endif // CC_TILES_IMAGE_DECODE_CACHE_UTILS_CC_