summaryrefslogtreecommitdiffstats
path: root/android_webview/browser
diff options
context:
space:
mode:
authorboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 22:44:43 +0000
committerboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 22:44:43 +0000
commit0552c8ef896c4356f4db85618972dedccd6ad53b (patch)
treed00992f235af190d2bdb9de0a5f72fbfcc1c9917 /android_webview/browser
parent1e7258d60d7ebdb30a27552d900e885922119a2c (diff)
downloadchromium_src-0552c8ef896c4356f4db85618972dedccd6ad53b.zip
chromium_src-0552c8ef896c4356f4db85618972dedccd6ad53b.tar.gz
chromium_src-0552c8ef896c4356f4db85618972dedccd6ad53b.tar.bz2
[Android WebView] First cut memory management
Based on simple algorithm of visible rect x constant. Completely disregards the preferred allocation from based on content of the page. Constants extermined experimentally using current android nexus devices. BUG=286026 Review URL: https://chromiumcodereview.appspot.com/23572023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222372 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/browser')
-rw-r--r--android_webview/browser/in_process_view_renderer.cc55
-rw-r--r--android_webview/browser/in_process_view_renderer.h2
2 files changed, 57 insertions, 0 deletions
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc
index aebf732..07b4d67 100644
--- a/android_webview/browser/in_process_view_renderer.cc
+++ b/android_webview/browser/in_process_view_renderer.cc
@@ -17,10 +17,12 @@
#include "base/debug/trace_event.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "content/public/browser/android/synchronous_compositor.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/content_switches.h"
#include "gpu/command_buffer/service/in_process_command_buffer.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkBitmapDevice.h"
@@ -28,6 +30,7 @@
#include "third_party/skia/include/core/SkGraphics.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/utils/SkCanvasStateUtils.h"
+#include "ui/gfx/android/device_display_info.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/transform.h"
#include "ui/gfx/vector2d_conversions.h"
@@ -143,6 +146,13 @@ AwDrawSWFunctionTable* g_sw_draw_functions = NULL;
const int64 kFallbackTickTimeoutInMilliseconds = 20;
+
+// Used to calculate memory and resource allocation. Determined experimentally.
+size_t g_memory_multiplier = 15;
+const size_t kMaxNumTilesToFillDisplay = 20;
+const size_t kBytesPerPixel = 4;
+const size_t kMemoryAllocationStep = 10 * 1024 * 1024;
+
class ScopedAllowGL {
public:
ScopedAllowGL();
@@ -276,6 +286,39 @@ void InProcessViewRenderer::WebContentsGone() {
compositor_ = NULL;
}
+// static
+void InProcessViewRenderer::CalculateTileMemoryPolicy() {
+ CommandLine* cl = CommandLine::ForCurrentProcess();
+ if (cl->HasSwitch(switches::kTileMemoryMultiplier)) {
+ std::string string_value =
+ cl->GetSwitchValueASCII(switches::kTileMemoryMultiplier);
+ int int_value;
+ if (base::StringToInt(string_value, &int_value) &&
+ int_value >= 2 && int_value <= 50) {
+ g_memory_multiplier = int_value;
+ }
+ }
+
+ if (cl->HasSwitch(switches::kDefaultTileWidth) ||
+ cl->HasSwitch(switches::kDefaultTileHeight)) {
+ return;
+ }
+
+ // TODO(boliu): Should use view context to get the display dimensions, and
+ // pass tile size in a per WebContents setting instead of through command
+ // line switch.
+ gfx::DeviceDisplayInfo info;
+ int default_tile_size = 256;
+
+ if (info.GetDisplayWidth() >= 1080)
+ default_tile_size = 512;
+
+ std::stringstream size;
+ size << default_tile_size;
+ cl->AppendSwitchASCII(switches::kDefaultTileWidth, size.str());
+ cl->AppendSwitchASCII(switches::kDefaultTileHeight, size.str());
+}
+
bool InProcessViewRenderer::RequestProcessGL() {
return client_->RequestDrawGL(NULL);
}
@@ -372,6 +415,18 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
return;
}
+ // Update memory budget. This will no-op in compositor if the policy has not
+ // changed since last draw.
+ content::SynchronousCompositorMemoryPolicy policy;
+ policy.bytes_limit = g_memory_multiplier * kBytesPerPixel *
+ cached_global_visible_rect_.width() *
+ cached_global_visible_rect_.height();
+ // Round up to a multiple of kMemoryAllocationStep.
+ policy.bytes_limit =
+ (policy.bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep;
+ policy.num_resources_limit = kMaxNumTilesToFillDisplay * g_memory_multiplier;
+ compositor_->SetMemoryPolicy(policy);
+
DCHECK(gl_surface_);
gl_surface_->SetBackingFrameBufferObject(
state_restore.framebuffer_binding_ext());
diff --git a/android_webview/browser/in_process_view_renderer.h b/android_webview/browser/in_process_view_renderer.h
index 620f010..a864a39 100644
--- a/android_webview/browser/in_process_view_renderer.h
+++ b/android_webview/browser/in_process_view_renderer.h
@@ -30,6 +30,8 @@ class AwGLSurface;
class InProcessViewRenderer : public BrowserViewRenderer,
public content::SynchronousCompositorClient {
public:
+ static void CalculateTileMemoryPolicy();
+
InProcessViewRenderer(BrowserViewRenderer::Client* client,
JavaHelper* java_helper,
content::WebContents* web_contents);