OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/browser/browser_view_renderer.h" | 5 #include "android_webview/browser/browser_view_renderer.h" |
6 | 6 |
7 #include "android_webview/browser/browser_view_renderer_client.h" | 7 #include "android_webview/browser/browser_view_renderer_client.h" |
8 #include "android_webview/browser/shared_renderer_state.h" | 8 #include "android_webview/browser/shared_renderer_state.h" |
9 #include "android_webview/common/aw_switches.h" | 9 #include "android_webview/common/aw_switches.h" |
10 #include "android_webview/public/browser/draw_gl.h" | 10 #include "android_webview/public/browser/draw_gl.h" |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "cc/output/compositor_frame.h" | 19 #include "cc/output/compositor_frame.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 23 #include "gpu/command_buffer/service/gpu_switches.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
25 #include "third_party/skia/include/core/SkPicture.h" | 26 #include "third_party/skia/include/core/SkPicture.h" |
26 #include "third_party/skia/include/core/SkPictureRecorder.h" | 27 #include "third_party/skia/include/core/SkPictureRecorder.h" |
27 #include "ui/gfx/vector2d_conversions.h" | 28 #include "ui/gfx/vector2d_conversions.h" |
28 | 29 |
29 using base::android::AttachCurrentThread; | 30 using base::android::AttachCurrentThread; |
30 using base::android::JavaRef; | 31 using base::android::JavaRef; |
31 using base::android::ScopedJavaLocalRef; | 32 using base::android::ScopedJavaLocalRef; |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 using content::SynchronousCompositorMemoryPolicy; | 34 using content::SynchronousCompositorMemoryPolicy; |
34 | 35 |
35 namespace android_webview { | 36 namespace android_webview { |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 const int64 kFallbackTickTimeoutInMilliseconds = 100; | 40 const int64 kFallbackTickTimeoutInMilliseconds = 100; |
40 | 41 |
41 // Used to calculate memory allocation. Determined experimentally. | 42 // Used to calculate memory allocation. Determined experimentally. |
42 const size_t kMemoryMultiplier = 20; | 43 const size_t kMemoryMultiplier = 20; |
43 const size_t kBytesPerPixel = 4; | 44 const size_t kBytesPerPixel = 4; |
44 const size_t kMemoryAllocationStep = 5 * 1024 * 1024; | 45 const size_t kMemoryAllocationStep = 5 * 1024 * 1024; |
| 46 uint64 g_memory_override_in_bytes = 0u; |
45 | 47 |
46 // Used to calculate tile allocation. Determined experimentally. | 48 // Used to calculate tile allocation. Determined experimentally. |
47 const size_t kTileMultiplier = 12; | 49 const size_t kTileMultiplier = 12; |
48 const size_t kTileAllocationStep = 20; | 50 const size_t kTileAllocationStep = 20; |
49 // This will be set by static function CalculateTileMemoryPolicy() during init. | 51 // This will be set by static function CalculateTileMemoryPolicy() during init. |
50 // See AwMainDelegate::BasicStartupComplete. | 52 // See AwMainDelegate::BasicStartupComplete. |
51 size_t g_tile_area; | 53 size_t g_tile_area; |
52 | 54 |
53 class TracedValue : public base::debug::ConvertableToTraceFormat { | 55 class TracedValue : public base::debug::ConvertableToTraceFormat { |
54 public: | 56 public: |
(...skipping 13 matching lines...) Expand all Loading... |
68 virtual ~TracedValue() {} | 70 virtual ~TracedValue() {} |
69 scoped_ptr<base::Value> value_; | 71 scoped_ptr<base::Value> value_; |
70 | 72 |
71 DISALLOW_COPY_AND_ASSIGN(TracedValue); | 73 DISALLOW_COPY_AND_ASSIGN(TracedValue); |
72 }; | 74 }; |
73 | 75 |
74 } // namespace | 76 } // namespace |
75 | 77 |
76 // static | 78 // static |
77 void BrowserViewRenderer::CalculateTileMemoryPolicy(bool use_zero_copy) { | 79 void BrowserViewRenderer::CalculateTileMemoryPolicy(bool use_zero_copy) { |
| 80 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 81 |
| 82 // If the value was overridden on the command line, use the specified value. |
| 83 bool client_hard_limit_bytes_overridden = |
| 84 cl->HasSwitch(switches::kForceGpuMemAvailableMb); |
| 85 if (client_hard_limit_bytes_overridden) { |
| 86 base::StringToUint64( |
| 87 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 88 switches::kForceGpuMemAvailableMb), |
| 89 &g_memory_override_in_bytes); |
| 90 g_memory_override_in_bytes *= 1024 * 1024; |
| 91 } |
| 92 |
78 if (!use_zero_copy) { | 93 if (!use_zero_copy) { |
79 // Use chrome's default tile size, which varies from 256 to 512. | 94 // Use chrome's default tile size, which varies from 256 to 512. |
80 // Be conservative here and use the smallest tile size possible. | 95 // Be conservative here and use the smallest tile size possible. |
81 g_tile_area = 256 * 256; | 96 g_tile_area = 256 * 256; |
82 | 97 |
83 // Also use a high tile limit since there are no file descriptor issues. | 98 // Also use a high tile limit since there are no file descriptor issues. |
84 GlobalTileManager::GetInstance()->SetTileLimit(1000); | 99 GlobalTileManager::GetInstance()->SetTileLimit(1000); |
85 return; | 100 return; |
86 } | 101 } |
87 | 102 |
88 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
89 const char kDefaultTileSize[] = "384"; | 103 const char kDefaultTileSize[] = "384"; |
90 | 104 |
91 if (!cl->HasSwitch(switches::kDefaultTileWidth)) | 105 if (!cl->HasSwitch(switches::kDefaultTileWidth)) |
92 cl->AppendSwitchASCII(switches::kDefaultTileWidth, kDefaultTileSize); | 106 cl->AppendSwitchASCII(switches::kDefaultTileWidth, kDefaultTileSize); |
93 | 107 |
94 if (!cl->HasSwitch(switches::kDefaultTileHeight)) | 108 if (!cl->HasSwitch(switches::kDefaultTileHeight)) |
95 cl->AppendSwitchASCII(switches::kDefaultTileHeight, kDefaultTileSize); | 109 cl->AppendSwitchASCII(switches::kDefaultTileHeight, kDefaultTileSize); |
96 | 110 |
97 size_t tile_size; | 111 size_t tile_size; |
98 base::StringToSizeT(kDefaultTileSize, &tile_size); | 112 base::StringToSizeT(kDefaultTileSize, &tile_size); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 SynchronousCompositorMemoryPolicy | 187 SynchronousCompositorMemoryPolicy |
174 BrowserViewRenderer::CalculateDesiredMemoryPolicy() { | 188 BrowserViewRenderer::CalculateDesiredMemoryPolicy() { |
175 SynchronousCompositorMemoryPolicy policy; | 189 SynchronousCompositorMemoryPolicy policy; |
176 size_t width = last_on_draw_global_visible_rect_.width(); | 190 size_t width = last_on_draw_global_visible_rect_.width(); |
177 size_t height = last_on_draw_global_visible_rect_.height(); | 191 size_t height = last_on_draw_global_visible_rect_.height(); |
178 policy.bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; | 192 policy.bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; |
179 // Round up to a multiple of kMemoryAllocationStep. | 193 // Round up to a multiple of kMemoryAllocationStep. |
180 policy.bytes_limit = | 194 policy.bytes_limit = |
181 (policy.bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; | 195 (policy.bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; |
182 | 196 |
| 197 if (g_memory_override_in_bytes) |
| 198 policy.bytes_limit = static_cast<size_t>(g_memory_override_in_bytes); |
| 199 |
183 size_t tiles = width * height * kTileMultiplier / g_tile_area; | 200 size_t tiles = width * height * kTileMultiplier / g_tile_area; |
184 // Round up to a multiple of kTileAllocationStep. The minimum number of tiles | 201 // Round up to a multiple of kTileAllocationStep. The minimum number of tiles |
185 // is also kTileAllocationStep. | 202 // is also kTileAllocationStep. |
186 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; | 203 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; |
187 policy.num_resources_limit = tiles; | 204 policy.num_resources_limit = tiles; |
188 return policy; | 205 return policy; |
189 } | 206 } |
190 | 207 |
191 // This function updates the cached memory policy in shared renderer state, as | 208 // This function updates the cached memory policy in shared renderer state, as |
192 // well as the tile resource allocation in GlobalTileManager. | 209 // well as the tile resource allocation in GlobalTileManager. |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 base::StringAppendF(&str, | 815 base::StringAppendF(&str, |
799 "surface width height: [%d %d] ", | 816 "surface width height: [%d %d] ", |
800 draw_info->width, | 817 draw_info->width, |
801 draw_info->height); | 818 draw_info->height); |
802 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 819 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
803 } | 820 } |
804 return str; | 821 return str; |
805 } | 822 } |
806 | 823 |
807 } // namespace android_webview | 824 } // namespace android_webview |
OLD | NEW |