OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "blimp/client/feature/compositor/blimp_layer_tree_settings.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 #include "base/macros.h" | |
10 #include "base/strings/string_number_conversions.h" | |
11 #include "base/strings/string_split.h" | |
12 #include "base/sys_info.h" | |
13 #include "cc/base/switches.h" | |
14 #include "cc/trees/layer_tree_settings.h" | |
15 #include "third_party/skia/include/core/SkColor.h" | |
16 #include "ui/gfx/buffer_types.h" | |
17 #include "ui/gl/gl_switches.h" | |
18 | |
19 namespace blimp { | |
20 namespace client { | |
21 | |
22 // TODO(dtrainor): This is temporary to get the compositor up and running. | |
23 // Much of this will either have to be pulled from the server or refactored to | |
24 // share the settings from render_widget_compositor.cc. | |
25 void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings* settings) { | |
26 // For web contents, layer transforms should scale up the contents of layers | |
27 // to keep content always crisp when possible. | |
28 settings->layer_transforms_should_scale_layer_contents = true; | |
29 | |
30 settings->main_frame_before_activation_enabled = false; | |
31 settings->default_tile_size = gfx::Size(256, 256); | |
32 settings->gpu_rasterization_msaa_sample_count = 0; | |
33 settings->gpu_rasterization_forced = false; | |
34 settings->gpu_rasterization_enabled = false; | |
35 settings->can_use_lcd_text = false; | |
36 settings->use_distance_field_text = false; | |
37 #if defined(OS_MACOSX) | |
38 settings->use_zero_copy = true; | |
39 #else | |
40 settings->use_zero_copy = false; | |
41 #endif | |
42 settings->enable_elastic_overscroll = false; | |
43 settings->image_decode_tasks_enabled = false; | |
44 settings->single_thread_proxy_scheduler = false; | |
45 settings->initial_debug_state.show_debug_borders = false; | |
46 settings->initial_debug_state.show_fps_counter = false; | |
47 settings->initial_debug_state.show_layer_animation_bounds_rects = false; | |
48 settings->initial_debug_state.show_paint_rects = false; | |
49 settings->initial_debug_state.show_property_changed_rects = false; | |
50 settings->initial_debug_state.show_surface_damage_rects = false; | |
51 settings->initial_debug_state.show_screen_space_rects = false; | |
52 settings->initial_debug_state.show_replica_screen_space_rects = false; | |
53 settings->initial_debug_state.SetRecordRenderingStats(false); | |
54 | |
55 #if defined(OS_ANDROID) | |
56 if (base::SysInfo::IsLowEndDevice()) | |
57 settings->gpu_rasterization_enabled = false; | |
58 settings->using_synchronous_renderer_compositor = false; | |
59 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; | |
60 settings->scrollbar_fade_delay_ms = 300; | |
61 settings->scrollbar_fade_resize_delay_ms = 2000; | |
62 settings->scrollbar_fade_duration_ms = 300; | |
63 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | |
64 settings->renderer_settings.highp_threshold_min = 2048; | |
65 settings->ignore_root_layer_flings = false; | |
66 bool use_low_memory_policy = base::SysInfo::IsLowEndDevice(); | |
67 if (use_low_memory_policy) { | |
68 // On low-end we want to be very carefull about killing other | |
69 // apps. So initially we use 50% more memory to avoid flickering | |
70 // or raster-on-demand. | |
71 settings->max_memory_for_prepaint_percentage = 67; | |
72 | |
73 settings->renderer_settings.preferred_tile_format = cc::RGBA_4444; | |
74 } else { | |
75 // On other devices we have increased memory excessively to avoid | |
76 // raster-on-demand already, so now we reserve 50% _only_ to avoid | |
77 // raster-on-demand, and use 50% of the memory otherwise. | |
78 settings->max_memory_for_prepaint_percentage = 50; | |
79 } | |
80 settings->renderer_settings.should_clear_root_render_pass = true; | |
81 | |
82 // TODO(danakj): Only do this on low end devices. | |
83 settings->create_low_res_tiling = true; | |
84 | |
85 // TODO(dtrainor): Investigate whether or not we want to use an external | |
86 // source here. | |
87 // settings->use_external_begin_frame_source = true; | |
88 | |
89 #elif !defined(OS_MACOSX) | |
90 settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE; | |
91 settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); | |
92 settings->scrollbar_fade_delay_ms = 500; | |
93 settings->scrollbar_fade_resize_delay_ms = 500; | |
94 settings->scrollbar_fade_duration_ms = 300; | |
95 | |
96 // When pinching in, only show the pinch-viewport overlay scrollbars if the | |
97 // page scale is at least some threshold away from the minimum. i.e. don't | |
98 // show the pinch scrollbars when at minimum scale. | |
99 // TODO(dtrainor): Update this since https://crrev.com/1267603004 landed. | |
100 // settings->scrollbar_show_scale_threshold = 1.05f; | |
101 #endif | |
102 | |
103 // Set the GpuMemoryPolicy. | |
104 cc::ManagedMemoryPolicy memory_policy = settings->memory_policy_; | |
105 memory_policy.bytes_limit_when_visible = 0; | |
106 | |
107 #if defined(OS_ANDROID) | |
108 // We can't query available GPU memory from the system on Android. | |
109 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports | |
110 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports | |
111 // 128MB java heap size). First we estimate physical memory using both. | |
112 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); | |
113 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); | |
114 size_t physical_memory_mb = 0; | |
115 if (dalvik_mb >= 256) | |
116 physical_memory_mb = dalvik_mb * 4; | |
117 else | |
118 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); | |
119 | |
120 // Now we take a default of 1/8th of memory on high-memory devices, | |
121 // and gradually scale that back for low-memory devices (to be nicer | |
122 // to other apps so they don't get killed). Examples: | |
123 // Nexus 4/10(2GB) 256MB (normally 128MB) | |
124 // Droid Razr M(1GB) 114MB (normally 57MB) | |
125 // Galaxy Nexus(1GB) 100MB (normally 50MB) | |
126 // Xoom(1GB) 100MB (normally 50MB) | |
127 // Nexus S(low-end) 8MB (normally 8MB) | |
128 // Note that the compositor now uses only some of this memory for | |
129 // pre-painting and uses the rest only for 'emergencies'. | |
130 if (memory_policy.bytes_limit_when_visible == 0) { | |
131 // NOTE: Non-low-end devices use only 50% of these limits, | |
132 // except during 'emergencies' where 100% can be used. | |
133 if (!base::SysInfo::IsLowEndDevice()) { | |
134 if (physical_memory_mb >= 1536) | |
135 memory_policy.bytes_limit_when_visible = | |
136 physical_memory_mb / 8; // >192MB | |
137 else if (physical_memory_mb >= 1152) | |
138 memory_policy.bytes_limit_when_visible = | |
139 physical_memory_mb / 8; // >144MB | |
140 else if (physical_memory_mb >= 768) | |
141 memory_policy.bytes_limit_when_visible = | |
142 physical_memory_mb / 10; // >76MB | |
143 else | |
144 memory_policy.bytes_limit_when_visible = | |
145 physical_memory_mb / 12; // <64MB | |
146 } else { | |
147 // Low-end devices have 512MB or less memory by definition | |
148 // so we hard code the limit rather than relying on the heuristics | |
149 // above. Low-end devices use 4444 textures so we can use a lower limit. | |
150 memory_policy.bytes_limit_when_visible = 8; | |
151 } | |
152 memory_policy.bytes_limit_when_visible = | |
153 memory_policy.bytes_limit_when_visible * 1024 * 1024; | |
154 // Clamp the observed value to a specific range on Android. | |
155 memory_policy.bytes_limit_when_visible = std::max( | |
156 memory_policy.bytes_limit_when_visible, | |
157 static_cast<size_t>(8 * 1024 * 1024)); | |
158 memory_policy.bytes_limit_when_visible = | |
159 std::min(memory_policy.bytes_limit_when_visible, | |
160 static_cast<size_t>(256 * 1024 * 1024)); | |
161 } | |
162 memory_policy.priority_cutoff_when_visible = | |
163 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; | |
164 #else | |
165 // Ignore what the system said and give all clients the same maximum | |
166 // allocation on desktop platforms. | |
167 memory_policy.bytes_limit_when_visible = 512 * 1024 * 1024; | |
168 memory_policy.priority_cutoff_when_visible = | |
169 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | |
170 #endif | |
171 } | |
172 | |
173 } // namespace client | |
174 } // namespace blimp | |
OLD | NEW |