[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / tiles / image_decode_cache_utils.cc
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.
4
5 #ifndef CC_TILES_IMAGE_DECODE_CACHE_UTILS_CC_
6 #define CC_TILES_IMAGE_DECODE_CACHE_UTILS_CC_
7
8 #include "cc/tiles/image_decode_cache_utils.h"
9
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"
15
16 #if !BUILDFLAG(IS_ANDROID)
17 #include "base/system/sys_info.h"
18 #endif
19
20 namespace cc {
21
22 // static
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:
28       return false;
29     case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
30       return true;
31   }
32   NOTREACHED();
33   return false;
34 }
35
36 // static
37 size_t ImageDecodeCacheUtils::GetWorkingSetBytesForImageDecode(
38     bool for_renderer) {
39   size_t decoded_image_working_set_budget_bytes = 128 * 1024 * 1024;
40 #if !BUILDFLAG(IS_ANDROID)
41   if (for_renderer) {
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;
51     }
52   }
53 #endif  // !BUILDFLAG(IS_ANDROID)
54   return decoded_image_working_set_budget_bytes;
55 }
56
57 }  // namespace cc
58
59 #endif  // CC_TILES_IMAGE_DECODE_CACHE_UTILS_CC_