blob: a6b043311070b205cc4d671fea47b0351d8c6a61 [file] [log] [blame]
Khushala4e236f2018-06-01 03:00:461// Copyright 2018 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 "content/common/skia_utils.h"
6
7#include "base/command_line.h"
8#include "base/strings/string_number_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:039#include "base/system/sys_info.h"
Khushala4e236f2018-06-01 03:00:4610#include "base/trace_event/memory_dump_manager.h"
11#include "build/build_config.h"
12#include "content/public/common/content_switches.h"
13#include "skia/ext/event_tracer_impl.h"
14#include "skia/ext/skia_memory_dump_provider.h"
15#include "third_party/skia/include/core/SkGraphics.h"
16
17namespace content {
18namespace {
19
20// Maximum allocation size allowed for image scaling filters that
21// require pre-scaling. Skia will fallback to a filter that doesn't
22// require pre-scaling if the default filter would require an
23// allocation that exceeds this limit.
24const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024;
25
26} // namespace
27
28void InitializeSkia() {
29 // Make sure that any switches used here are propagated to the renderer and
30 // GPU processes.
31 const base::CommandLine& cmd = *base::CommandLine::ForCurrentProcess();
32 if (!cmd.HasSwitch(switches::kDisableSkiaRuntimeOpts)) {
33 SkGraphics::Init();
34 }
35
36 const int kMB = 1024 * 1024;
37 size_t font_cache_limit;
38#if defined(OS_ANDROID)
39 font_cache_limit = base::SysInfo::IsLowEndDevice() ? kMB : 8 * kMB;
40 SkGraphics::SetFontCacheLimit(font_cache_limit);
41#else
42 if (cmd.HasSwitch(switches::kSkiaFontCacheLimitMb)) {
43 if (base::StringToSizeT(
44 cmd.GetSwitchValueASCII(switches::kSkiaFontCacheLimitMb),
45 &font_cache_limit)) {
46 SkGraphics::SetFontCacheLimit(font_cache_limit * kMB);
47 }
48 }
49
50 size_t resource_cache_limit;
51 if (cmd.HasSwitch(switches::kSkiaResourceCacheLimitMb)) {
52 if (base::StringToSizeT(
53 cmd.GetSwitchValueASCII(switches::kSkiaResourceCacheLimitMb),
54 &resource_cache_limit)) {
55 SkGraphics::SetResourceCacheTotalByteLimit(resource_cache_limit * kMB);
56 }
57 }
58#endif
59
60 InitSkiaEventTracer();
61 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
62 skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr);
63
64 SkGraphics::SetResourceCacheSingleAllocationByteLimit(
65 kImageCacheSingleAllocationByteLimit);
66}
67
68} // namespace content