diff options
author | boliu <boliu@chromium.org> | 2014-10-27 21:06:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-28 04:07:06 +0000 |
commit | 77de0216df77874d43b21233fcb675671cfd0c55 (patch) | |
tree | ccef92d4b66e589b30e15ef8d44882a7ec911319 | |
parent | d239c1bec380fd3efd779e755caf9caf25fe154f (diff) | |
download | chromium_src-77de0216df77874d43b21233fcb675671cfd0c55.zip chromium_src-77de0216df77874d43b21233fcb675671cfd0c55.tar.gz chromium_src-77de0216df77874d43b21233fcb675671cfd0c55.tar.bz2 |
Remove limit on number of resources in cc
This ability was added for Android WebView to limit the number of
gralloc buffers, which has a low limit on the number of allocations.
Android WebView no longer uses gralloc buffers, so no need to keep this
ability.
Use memory limit to limit the staging resource pool for 1-copy
rasterizer.
BUG=426548
Review URL: https://codereview.chromium.org/643993005
Cr-Commit-Position: refs/heads/master@{#301559}
15 files changed, 28 insertions, 584 deletions
diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index 87cd122..0c020af2 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -134,9 +134,6 @@ 'browser/deferred_gpu_command_service.h', 'browser/find_helper.cc', 'browser/find_helper.h', - 'browser/global_tile_manager.cc', - 'browser/global_tile_manager.h', - 'browser/global_tile_manager_client.h', 'browser/hardware_renderer.cc', 'browser/hardware_renderer.h', 'browser/icon_helper.cc', diff --git a/android_webview/android_webview_tests.gypi b/android_webview/android_webview_tests.gypi index 7feab4f..d775cc9 100644 --- a/android_webview/android_webview_tests.gypi +++ b/android_webview/android_webview_tests.gypi @@ -110,7 +110,6 @@ 'sources': [ 'browser/aw_static_cookie_policy_unittest.cc', 'browser/aw_form_database_service_unittest.cc', - 'browser/global_tile_manager_unittest.cc', 'browser/net/android_stream_reader_url_request_job_unittest.cc', 'browser/net/input_stream_reader_unittest.cc', 'lib/main/webview_tests.cc', diff --git a/android_webview/browser/browser_view_renderer.cc b/android_webview/browser/browser_view_renderer.cc index f897b0c..5bf8168 100644 --- a/android_webview/browser/browser_view_renderer.cc +++ b/android_webview/browser/browser_view_renderer.cc @@ -23,8 +23,6 @@ #include "third_party/skia/include/core/SkPictureRecorder.h" #include "ui/gfx/geometry/vector2d_conversions.h" -using content::SynchronousCompositorMemoryPolicy; - namespace android_webview { namespace { @@ -37,13 +35,6 @@ const size_t kBytesPerPixel = 4; const size_t kMemoryAllocationStep = 5 * 1024 * 1024; uint64 g_memory_override_in_bytes = 0u; -// Used to calculate tile allocation. Determined experimentally. -const size_t kTileMultiplier = 12; -const size_t kTileAllocationStep = 20; -// Use chrome's default tile size, which varies from 256 to 512. -// Be conservative here and use the smallest tile size possible. -const size_t kTileArea = 256 * 256; - } // namespace // static @@ -60,10 +51,6 @@ void BrowserViewRenderer::CalculateTileMemoryPolicy() { &g_memory_override_in_bytes); g_memory_override_in_bytes *= 1024 * 1024; } - - // There is no need to limit number of tiles, so use an effectively unlimited - // value as the limit. - GlobalTileManager::GetInstance()->SetTileLimit(10 * 1000 * 1000); } BrowserViewRenderer::BrowserViewRenderer( @@ -131,68 +118,29 @@ void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { if (level < TRIM_MEMORY_BACKGROUND && visible) return; - // Just set the memory limit to 0 and drop all tiles. This will be reset to - // normal levels in the next DrawGL call. - SynchronousCompositorMemoryPolicy zero_policy; - if (memory_policy_ == zero_policy) + // Nothing to drop. + if (!compositor_ || !hardware_enabled_) return; TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); - DCHECK(hardware_enabled_); - DCHECK(compositor_); - RequestMemoryPolicy(zero_policy); - EnforceMemoryPolicyImmediately(zero_policy); + // Just set the memory limit to 0 and drop all tiles. This will be reset to + // normal levels in the next DrawGL call. + compositor_->SetMemoryPolicy(0u); + ForceFakeCompositeSW(); } -SynchronousCompositorMemoryPolicy -BrowserViewRenderer::CalculateDesiredMemoryPolicy() { - SynchronousCompositorMemoryPolicy policy; +size_t BrowserViewRenderer::CalculateDesiredMemoryPolicy() { + if (g_memory_override_in_bytes) + return static_cast<size_t>(g_memory_override_in_bytes); + size_t width = last_on_draw_global_visible_rect_.width(); size_t height = last_on_draw_global_visible_rect_.height(); - policy.bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; + size_t bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; // Round up to a multiple of kMemoryAllocationStep. - policy.bytes_limit = - (policy.bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; - - if (g_memory_override_in_bytes) - policy.bytes_limit = static_cast<size_t>(g_memory_override_in_bytes); - - size_t tiles = width * height * kTileMultiplier / kTileArea; - // Round up to a multiple of kTileAllocationStep. The minimum number of tiles - // is also kTileAllocationStep. - tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; - policy.num_resources_limit = tiles; - return policy; -} - -// This function updates the cached memory policy in shared renderer state, as -// well as the tile resource allocation in GlobalTileManager. -void BrowserViewRenderer::RequestMemoryPolicy( - SynchronousCompositorMemoryPolicy& new_policy) { - DCHECK(compositor_); - GlobalTileManager* manager = GlobalTileManager::GetInstance(); - - // The following line will call BrowserViewRenderer::SetMemoryPolicy(). - manager->RequestTiles(new_policy, tile_manager_key_); -} - -void BrowserViewRenderer::SetMemoryPolicy( - SynchronousCompositorMemoryPolicy new_policy, - bool effective_immediately) { - memory_policy_ = new_policy; - if (effective_immediately) - EnforceMemoryPolicyImmediately(memory_policy_); -} - -void BrowserViewRenderer::EnforceMemoryPolicyImmediately( - SynchronousCompositorMemoryPolicy new_policy) { - compositor_->SetMemoryPolicy(new_policy); - ForceFakeCompositeSW(); -} - -SynchronousCompositorMemoryPolicy BrowserViewRenderer::GetMemoryPolicy() const { - return memory_policy_; + bytes_limit = + (bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; + return bytes_limit; } bool BrowserViewRenderer::OnDraw(jobject java_canvas, @@ -223,9 +171,6 @@ bool BrowserViewRenderer::OnDrawHardware() { if (!hardware_enabled_) { hardware_enabled_ = compositor_->InitializeHwDraw(); - if (hardware_enabled_) { - tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); - } } if (!hardware_enabled_) return false; @@ -253,14 +198,11 @@ bool BrowserViewRenderer::OnDrawHardware() { return false; shared_renderer_state_.SetCompositorFrameOnUI(frame.Pass(), false); - GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); return true; } scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { - SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); - RequestMemoryPolicy(new_policy); - compositor_->SetMemoryPolicy(memory_policy_); + compositor_->SetMemoryPolicy(CalculateDesiredMemoryPolicy()); parent_draw_constraints_ = shared_renderer_state_.GetParentDrawConstraintsOnUI(); @@ -461,12 +403,9 @@ void BrowserViewRenderer::ReleaseHardware() { if (compositor_) { compositor_->ReleaseHwDraw(); - SynchronousCompositorMemoryPolicy zero_policy; - RequestMemoryPolicy(zero_policy); } hardware_enabled_ = false; - GlobalTileManager::GetInstance()->Remove(tile_manager_key_); } bool BrowserViewRenderer::IsVisible() const { @@ -491,11 +430,6 @@ void BrowserViewRenderer::DidDestroyCompositor( content::SynchronousCompositor* compositor) { TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); DCHECK(compositor_); - SynchronousCompositorMemoryPolicy zero_policy; - if (hardware_enabled_) { - RequestMemoryPolicy(zero_policy); - } - DCHECK(memory_policy_ == zero_policy); compositor_ = NULL; } diff --git a/android_webview/browser/browser_view_renderer.h b/android_webview/browser/browser_view_renderer.h index b0852fd..c2d44f1 100644 --- a/android_webview/browser/browser_view_renderer.h +++ b/android_webview/browser/browser_view_renderer.h @@ -5,8 +5,6 @@ #ifndef ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ -#include "android_webview/browser/global_tile_manager.h" -#include "android_webview/browser/global_tile_manager_client.h" #include "android_webview/browser/parent_compositor_draw_constraints.h" #include "android_webview/browser/shared_renderer_state.h" #include "base/android/scoped_java_ref.h" @@ -23,7 +21,6 @@ class SkCanvas; class SkPicture; namespace content { -struct SynchronousCompositorMemoryPolicy; class WebContents; } @@ -54,8 +51,7 @@ class BrowserViewRendererJavaHelper { // Interface for all the WebView-specific content rendering operations. // Provides software and hardware rendering and the Capture Picture API. -class BrowserViewRenderer : public content::SynchronousCompositorClient, - public GlobalTileManagerClient { +class BrowserViewRenderer : public content::SynchronousCompositorClient { public: static void CalculateTileMemoryPolicy(); @@ -108,11 +104,6 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, bool hardware_enabled() const { return hardware_enabled_; } void ReleaseHardware(); - // Set the memory policy in shared renderer state and request the tiles from - // GlobalTileManager. The actually amount of memory allowed by - // GlobalTileManager may not be equal to what's requested in |policy|. - void RequestMemoryPolicy(content::SynchronousCompositorMemoryPolicy& policy); - void TrimMemory(const int level, const bool visible); // SynchronousCompositorClient overrides. @@ -135,13 +126,6 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, gfx::Vector2dF latest_overscroll_delta, gfx::Vector2dF current_fling_velocity) override; - // GlobalTileManagerClient overrides. - virtual content::SynchronousCompositorMemoryPolicy GetMemoryPolicy() - const override; - virtual void SetMemoryPolicy( - content::SynchronousCompositorMemoryPolicy new_policy, - bool effective_immediately) override; - void UpdateParentDrawConstraints(); void DidSkipCommitFrame(); @@ -179,12 +163,9 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, // compositor that are not directly exposed here. void ForceFakeCompositeSW(); - void EnforceMemoryPolicyImmediately( - content::SynchronousCompositorMemoryPolicy policy); - gfx::Vector2d max_scroll_offset() const; - content::SynchronousCompositorMemoryPolicy CalculateDesiredMemoryPolicy(); + size_t CalculateDesiredMemoryPolicy(); // For debug tracing or logging. Return the string representation of this // view renderer's state. std::string ToString() const; @@ -242,9 +223,6 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, // spot over a period of time). gfx::Vector2dF overscroll_rounding_error_; - GlobalTileManager::Key tile_manager_key_; - content::SynchronousCompositorMemoryPolicy memory_policy_; - DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); }; diff --git a/android_webview/browser/global_tile_manager.cc b/android_webview/browser/global_tile_manager.cc deleted file mode 100644 index 200a7ea..0000000 --- a/android_webview/browser/global_tile_manager.cc +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "android_webview/browser/global_tile_manager.h" -#include "android_webview/browser/global_tile_manager_client.h" -#include "base/lazy_instance.h" - -using content::SynchronousCompositorMemoryPolicy; - -namespace android_webview { - -namespace { - -base::LazyInstance<GlobalTileManager>::Leaky g_tile_manager = - LAZY_INSTANCE_INITIALIZER; - -// The soft limit of the number of file descriptors per process is 1024 on -// Android and gralloc buffers may not be the only thing that uses file -// descriptors. For each tile, there is a gralloc buffer backing it, which -// uses 2 FDs. -const size_t kNumTilesLimit = 450; - -} // namespace - -// static -GlobalTileManager* GlobalTileManager::GetInstance() { - return g_tile_manager.Pointer(); -} - -void GlobalTileManager::Remove(Key key) { - DCHECK(sequence_checker_.CalledOnValidSequencedThread()); - DCHECK(mru_list_.end() != key); - - total_allocated_tiles_ -= (*key)->GetMemoryPolicy().num_resources_limit; - mru_list_.erase(key); - DCHECK(IsConsistent()); -} - -size_t GlobalTileManager::Evict(size_t desired_num_tiles, Key key) { - DCHECK(sequence_checker_.CalledOnValidSequencedThread()); - size_t total_evicted_tiles = 0; - - // Evicts from the least recent drawn view, until the disired number of tiles - // can be reclaimed, or until we've evicted all inactive views. - ListType::reverse_iterator it; - for (it = mru_list_.rbegin(); it != mru_list_.rend(); it++) { - // key represents the view that requested the eviction, so we don't need to - // evict the requester itself. And we only evict the inactive views, - // which are all the views after the requester. - if (*it == *key) - break; - - size_t evicted_tiles = (*it)->GetMemoryPolicy().num_resources_limit; - SynchronousCompositorMemoryPolicy zero_policy; - (*it)->SetMemoryPolicy(zero_policy, true); - - total_evicted_tiles += evicted_tiles; - if (total_evicted_tiles >= desired_num_tiles) - break; - } - - return total_evicted_tiles; -} - -void GlobalTileManager::SetTileLimit(size_t num_tiles_limit) { - num_tiles_limit_ = num_tiles_limit; -} - -void GlobalTileManager::RequestTiles( - SynchronousCompositorMemoryPolicy new_policy, - Key key) { - DCHECK(IsConsistent()); - DCHECK(sequence_checker_.CalledOnValidSequencedThread()); - size_t new_num_of_tiles = new_policy.num_resources_limit; - size_t old_num_of_tiles = (*key)->GetMemoryPolicy().num_resources_limit; - size_t num_of_active_views = std::distance(mru_list_.begin(), key) + 1; - size_t tiles_per_view_limit; - if (num_of_active_views == 0) - tiles_per_view_limit = num_tiles_limit_; - else - tiles_per_view_limit = num_tiles_limit_ / num_of_active_views; - new_num_of_tiles = std::min(new_num_of_tiles, tiles_per_view_limit); - size_t new_total_allocated_tiles = - total_allocated_tiles_ - old_num_of_tiles + new_num_of_tiles; - // Has enough tiles to satisfy the request. - if (new_total_allocated_tiles <= num_tiles_limit_) { - total_allocated_tiles_ = new_total_allocated_tiles; - new_policy.num_resources_limit = new_num_of_tiles; - (*key)->SetMemoryPolicy(new_policy, false); - return; - } - - // Does not have enough tiles. Now evict other clients' tiles. - size_t tiles_left = num_tiles_limit_ - total_allocated_tiles_; - - size_t evicted_tiles = - Evict(new_total_allocated_tiles - num_tiles_limit_, key); - if (evicted_tiles >= new_total_allocated_tiles - num_tiles_limit_) { - new_total_allocated_tiles -= evicted_tiles; - total_allocated_tiles_ = new_total_allocated_tiles; - new_policy.num_resources_limit = new_num_of_tiles; - (*key)->SetMemoryPolicy(new_policy, false); - return; - } else { - total_allocated_tiles_ = num_tiles_limit_; - new_policy.num_resources_limit = - tiles_left + old_num_of_tiles + evicted_tiles; - (*key)->SetMemoryPolicy(new_policy, false); - return; - } -} - -GlobalTileManager::Key GlobalTileManager::PushBack( - GlobalTileManagerClient* client) { - DCHECK(sequence_checker_.CalledOnValidSequencedThread()); - DCHECK(mru_list_.end() == - std::find(mru_list_.begin(), mru_list_.end(), client)); - mru_list_.push_back(client); - Key back = mru_list_.end(); - back--; - return back; -} - -void GlobalTileManager::DidUse(Key key) { - DCHECK(sequence_checker_.CalledOnValidSequencedThread()); - DCHECK(mru_list_.end() != key); - - mru_list_.splice(mru_list_.begin(), mru_list_, key); -} - -GlobalTileManager::GlobalTileManager() - : num_tiles_limit_(kNumTilesLimit), total_allocated_tiles_(0) { -} - -GlobalTileManager::~GlobalTileManager() { -} - -bool GlobalTileManager::IsConsistent() const { - size_t total_tiles = 0; - ListType::const_iterator it; - for (it = mru_list_.begin(); it != mru_list_.end(); it++) { - total_tiles += (*it)->GetMemoryPolicy().num_resources_limit; - } - - bool is_consistent = (total_tiles <= num_tiles_limit_ && - total_tiles == total_allocated_tiles_); - - return is_consistent; -} - -} // namespace webview diff --git a/android_webview/browser/global_tile_manager.h b/android_webview/browser/global_tile_manager.h deleted file mode 100644 index bf83e9e..0000000 --- a/android_webview/browser/global_tile_manager.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_ -#define ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_ - -#include <list> -#include "base/basictypes.h" -#include "base/lazy_instance.h" -#include "base/sequence_checker.h" -#include "base/synchronization/lock.h" -#include "content/public/browser/android/synchronous_compositor.h" - -namespace android_webview { - -class GlobalTileManagerClient; - -// A global tile manager that keeps track of the number of tile resources. Each -// tile needs file descriptors (typically 2) and there is a soft limit of 1024 -// file descriptors per Android process. The GlobalTileManager does not keep -// track of how many tiles each individual view is actually using. The purpose -// of GlobalTileManager is to behave gracefully (as in not crashing) when the -// embedder of webview creates a lot of webviews and draw them at the same time. -class GlobalTileManager { - private: - typedef std::list<GlobalTileManagerClient*> ListType; - - public: - typedef ListType::iterator Key; - static GlobalTileManager* GetInstance(); - - void SetTileLimit(size_t num_tiles_limit); - - // Requests the |new_num_of_tiles| from the available global pool. Calls - // GlobalTileManagerClient.SetNumTiles after the manager determines how many - // tiles are available for the client. If the number of tiles left is not - // enough to satisfy the request, the manager will evict tiles allocated to - // other clients. - void RequestTiles(content::SynchronousCompositorMemoryPolicy new_policy, - Key key); - - Key PushBack(GlobalTileManagerClient* client); - - // |key| must be already in manager. Move the tile manager client - // corresponding to |key| to most recent. This function should be called after - // RequestTiles. - void DidUse(Key key); - - void Remove(Key key); - - private: - friend struct base::DefaultLazyInstanceTraits<GlobalTileManager>; - GlobalTileManager(); - ~GlobalTileManager(); - - // Continues evicting the inactive views until freeing up at least amount of - // tiles specified by |desired_num_tiles| to draw a view specified by |key|, - // or until all inactive views have been evicted. Returns the amount of - // memory that was actually evicted. This function is called when a - // request cannot be satisfied. - size_t Evict(size_t desired_num_tiles, Key key); - - // Check that the sum of all client's tiles is equal to - // total_allocated_tiles_. - bool IsConsistent() const; - - size_t num_tiles_limit_; - - size_t total_allocated_tiles_; - ListType mru_list_; - base::SequenceChecker sequence_checker_; - - DISALLOW_COPY_AND_ASSIGN(GlobalTileManager); -}; - -} // namespace android_webview - -#endif // ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_H_ diff --git a/android_webview/browser/global_tile_manager_client.h b/android_webview/browser/global_tile_manager_client.h deleted file mode 100644 index b9cc64e..0000000 --- a/android_webview/browser/global_tile_manager_client.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_CLIENT_H_ -#define ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_CLIENT_H_ - -#include "content/public/browser/android/synchronous_compositor.h" - -namespace android_webview { -// GlobalTileManagerClient requests tile resources from GlobalTileManager. -class GlobalTileManagerClient { - public: - // Get tile memory policy for the client. - virtual content::SynchronousCompositorMemoryPolicy GetMemoryPolicy() - const = 0; - - // Set tile memory policy of the client. When |effective_immediately| is - // true, the client will enforce its tile policy immediately. - virtual void SetMemoryPolicy( - content::SynchronousCompositorMemoryPolicy new_policy, - bool effective_immediately) = 0; - - protected: - virtual ~GlobalTileManagerClient() {} -}; - -} // namespace android_webview - -#endif // ANDROID_WEBVIEW_BROWSER_GLOBAL_TILE_MANAGER_CLIENT_H_ diff --git a/android_webview/browser/global_tile_manager_unittest.cc b/android_webview/browser/global_tile_manager_unittest.cc deleted file mode 100644 index cd7d26e..0000000 --- a/android_webview/browser/global_tile_manager_unittest.cc +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <algorithm> -#include "android_webview/browser/global_tile_manager.h" -#include "android_webview/browser/global_tile_manager_client.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { -// This should be the same as the one defined global_tile_manager.cc -const size_t kNumTilesLimit = 450; -const size_t kDefaultNumTiles = 150; - -} // namespace - -using android_webview::GlobalTileManager; -using android_webview::GlobalTileManagerClient; -using content::SynchronousCompositorMemoryPolicy; -using testing::Test; - -class MockGlobalTileManagerClient : public GlobalTileManagerClient { - public: - virtual SynchronousCompositorMemoryPolicy GetMemoryPolicy() const override { - return memory_policy_; - } - - virtual void SetMemoryPolicy(SynchronousCompositorMemoryPolicy new_policy, - bool effective_immediately) override { - memory_policy_ = new_policy; - } - - MockGlobalTileManagerClient() { - tile_request_.num_resources_limit = kDefaultNumTiles; - key_ = GlobalTileManager::GetInstance()->PushBack(this); - } - - virtual ~MockGlobalTileManagerClient() { - GlobalTileManager::GetInstance()->Remove(key_); - } - - SynchronousCompositorMemoryPolicy GetTileRequest() { return tile_request_; } - GlobalTileManager::Key GetKey() { return key_; } - - private: - SynchronousCompositorMemoryPolicy memory_policy_; - SynchronousCompositorMemoryPolicy tile_request_; - GlobalTileManager::Key key_; -}; - -class GlobalTileManagerTest : public Test { - public: - virtual void SetUp() {} - - GlobalTileManager* manager() { return GlobalTileManager::GetInstance(); } -}; - -TEST_F(GlobalTileManagerTest, RequestTilesUnderLimit) { - MockGlobalTileManagerClient clients[2]; - - for (size_t i = 0; i < 2; i++) { - manager()->RequestTiles(clients[i].GetTileRequest(), clients[i].GetKey()); - manager()->DidUse(clients[i].GetKey()); - - // Ensure clients get what they asked for when the manager is under tile - // limit. - EXPECT_EQ(clients[i].GetMemoryPolicy().num_resources_limit, - kDefaultNumTiles); - } -} - -TEST_F(GlobalTileManagerTest, EvictHappensWhenOverLimit) { - MockGlobalTileManagerClient clients[4]; - - for (size_t i = 0; i < 4; i++) { - manager()->RequestTiles(clients[i].GetTileRequest(), clients[i].GetKey()); - manager()->DidUse(clients[i].GetKey()); - } - - size_t total_tiles = 0; - for (size_t i = 0; i < 4; i++) { - total_tiles += clients[i].GetMemoryPolicy().num_resources_limit; - } - - // Ensure that eviction happened and kept the total number of tiles within - // kNumTilesLimit. - EXPECT_LE(total_tiles, kNumTilesLimit); -} - -TEST_F(GlobalTileManagerTest, RandomizedStressRequests) { - MockGlobalTileManagerClient clients[100]; - size_t index[100]; - for (size_t i = 0; i < 100; i++) { - index[i] = i; - } - - // Fix the seed so that tests are reproducible. - std::srand(1); - // Simulate a random request order of clients. - std::random_shuffle(&index[0], &index[99]); - - for (size_t i = 0; i < 100; i++) { - size_t j = index[i]; - manager()->RequestTiles(clients[j].GetTileRequest(), clients[j].GetKey()); - manager()->DidUse(clients[j].GetKey()); - } - - size_t total_tiles = 0; - for (size_t i = 0; i < 100; i++) { - total_tiles += clients[i].GetMemoryPolicy().num_resources_limit; - } - - // Ensure that eviction happened and kept the total number of tiles within - // kNumTilesLimit. - EXPECT_LE(total_tiles, kNumTilesLimit); -} - -TEST_F(GlobalTileManagerTest, FixedOrderedRequests) { - MockGlobalTileManagerClient clients[10]; - - // 10 clients requesting resources in a fixed order. Do that for 5 rounds. - for (int round = 0; round < 5; round++) { - for (size_t i = 0; i < 10; i++) { - manager()->RequestTiles(clients[i].GetTileRequest(), clients[i].GetKey()); - manager()->DidUse(clients[i].GetKey()); - } - } - - // Ensure that the total tiles are divided evenly among all clients. - for (size_t i = 0; i < 10; i++) { - EXPECT_EQ(clients[i].GetMemoryPolicy().num_resources_limit, - kNumTilesLimit / 10); - } -} - -TEST_F(GlobalTileManagerTest, FixedOrderedRequestsWithInactiveClients) { - MockGlobalTileManagerClient clients[20]; - - // 20 clients request resources. - for (size_t i = 0; i < 20; i++) { - manager()->RequestTiles(clients[i].GetTileRequest(), clients[i].GetKey()); - manager()->DidUse(clients[i].GetKey()); - } - - // Now the last 10 clients become inactive. Only the first 10 clients remain - // active resource requesters. - // 10 clients requesting resources in a fixed order. Do that for 5 rounds. - for (int round = 0; round < 5; round++) { - for (size_t i = 0; i < 10; i++) { - manager()->RequestTiles(clients[i].GetTileRequest(), clients[i].GetKey()); - manager()->DidUse(clients[i].GetKey()); - } - } - - // Ensure that the total tiles are divided evenly among all clients. - for (size_t i = 0; i < 10; i++) { - EXPECT_EQ(clients[i].GetMemoryPolicy().num_resources_limit, - kNumTilesLimit / 10); - } - - // Ensure that the inactive tiles are evicted. - for (size_t i = 11; i < 20; i++) { - EXPECT_EQ(clients[i].GetMemoryPolicy().num_resources_limit, 0u); - } -} diff --git a/content/browser/android/in_process/synchronous_compositor_impl.cc b/content/browser/android/in_process/synchronous_compositor_impl.cc index 702164b..06be5be 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.cc +++ b/content/browser/android/in_process/synchronous_compositor_impl.cc @@ -163,12 +163,11 @@ void SynchronousCompositorImpl::UpdateFrameMetaData( DeliverMessages(); } -void SynchronousCompositorImpl::SetMemoryPolicy( - const SynchronousCompositorMemoryPolicy& policy) { +void SynchronousCompositorImpl::SetMemoryPolicy(size_t bytes_limit) { DCHECK(CalledOnValidThread()); DCHECK(output_surface_); - output_surface_->SetMemoryPolicy(policy); + output_surface_->SetMemoryPolicy(bytes_limit); } void SynchronousCompositorImpl::DidChangeRootLayerScrollOffset() { diff --git a/content/browser/android/in_process/synchronous_compositor_impl.h b/content/browser/android/in_process/synchronous_compositor_impl.h index 03d2796..9b92cef 100644 --- a/content/browser/android/in_process/synchronous_compositor_impl.h +++ b/content/browser/android/in_process/synchronous_compositor_impl.h @@ -63,8 +63,7 @@ class SynchronousCompositorImpl virtual bool DemandDrawSw(SkCanvas* canvas) override; virtual void ReturnResources( const cc::CompositorFrameAck& frame_ack) override; - virtual void SetMemoryPolicy( - const SynchronousCompositorMemoryPolicy& policy) override; + virtual void SetMemoryPolicy(size_t bytes_limit) override; virtual void DidChangeRootLayerScrollOffset() override; // SynchronousCompositorOutputSurfaceDelegate diff --git a/content/browser/android/in_process/synchronous_compositor_output_surface.cc b/content/browser/android/in_process/synchronous_compositor_output_surface.cc index 7b8464b..1c87cc3 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.cc +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.cc @@ -26,6 +26,9 @@ namespace content { namespace { +// Do not limit number of resources, so use an unrealistically high value. +const size_t kNumResourcesLimit = 10 * 1000 * 1000; + void DidActivatePendingTree(int routing_id) { SynchronousCompositorOutputSurfaceDelegate* delegate = SynchronousCompositorImpl::FromRoutingID(routing_id); @@ -268,11 +271,10 @@ void SynchronousCompositorOutputSurface::ReturnResources( ReclaimResources(&frame_ack); } -void SynchronousCompositorOutputSurface::SetMemoryPolicy( - const SynchronousCompositorMemoryPolicy& policy) { +void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { DCHECK(CalledOnValidThread()); - memory_policy_.bytes_limit_when_visible = policy.bytes_limit; - memory_policy_.num_resources_limit = policy.num_resources_limit; + memory_policy_.bytes_limit_when_visible = bytes_limit; + memory_policy_.num_resources_limit = kNumResourcesLimit; if (output_surface_client_) output_surface_client_->SetMemoryPolicy(memory_policy_); diff --git a/content/browser/android/in_process/synchronous_compositor_output_surface.h b/content/browser/android/in_process/synchronous_compositor_output_surface.h index 49c381f..d01d88b 100644 --- a/content/browser/android/in_process/synchronous_compositor_output_surface.h +++ b/content/browser/android/in_process/synchronous_compositor_output_surface.h @@ -83,7 +83,7 @@ class SynchronousCompositorOutputSurface const gfx::Transform& transform_for_tile_priority); void ReturnResources(const cc::CompositorFrameAck& frame_ack); scoped_ptr<cc::CompositorFrame> DemandDrawSw(SkCanvas* canvas); - void SetMemoryPolicy(const SynchronousCompositorMemoryPolicy& policy); + void SetMemoryPolicy(size_t bytes_limit); void GetMessagesToDeliver(ScopedVector<IPC::Message>* messages); private: diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 5415195..c9dcea9 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -51,7 +51,6 @@ 'public/browser/android/external_video_surface_container.h', 'public/browser/android/layer_tree_build_helper.h', 'public/browser/android/synchronous_compositor_client.h', - 'public/browser/android/synchronous_compositor.cc', 'public/browser/android/synchronous_compositor.h', 'public/browser/android/ui_resource_client_android.h', 'public/browser/android/ui_resource_provider.h', diff --git a/content/public/browser/android/synchronous_compositor.cc b/content/public/browser/android/synchronous_compositor.cc deleted file mode 100644 index 25c4dc4..0000000 --- a/content/public/browser/android/synchronous_compositor.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/public/browser/android/synchronous_compositor.h" - -namespace content { - -SynchronousCompositorMemoryPolicy::SynchronousCompositorMemoryPolicy() - : bytes_limit(0), num_resources_limit(0) {} - -bool SynchronousCompositorMemoryPolicy::operator==( - const SynchronousCompositorMemoryPolicy& other) const { - return bytes_limit == other.bytes_limit && - num_resources_limit == other.num_resources_limit; -} - -bool SynchronousCompositorMemoryPolicy::operator!=( - const SynchronousCompositorMemoryPolicy& other) const { - return !(*this == other); -} - -} // namespace content diff --git a/content/public/browser/android/synchronous_compositor.h b/content/public/browser/android/synchronous_compositor.h index 4db367f..69000e5 100644 --- a/content/public/browser/android/synchronous_compositor.h +++ b/content/public/browser/android/synchronous_compositor.h @@ -31,19 +31,6 @@ namespace content { class SynchronousCompositorClient; class WebContents; -struct CONTENT_EXPORT SynchronousCompositorMemoryPolicy { - // Memory limit for rendering and pre-rendering. - size_t bytes_limit; - - // Limit of number of GL resources used for rendering and pre-rendering. - size_t num_resources_limit; - - SynchronousCompositorMemoryPolicy(); - - bool operator==(const SynchronousCompositorMemoryPolicy& other) const; - bool operator!=(const SynchronousCompositorMemoryPolicy& other) const; -}; - // Interface for embedders that wish to direct compositing operations // synchronously under their own control. Only meaningful when the // kEnableSyncrhonousRendererCompositor flag is specified. @@ -99,8 +86,7 @@ class CONTENT_EXPORT SynchronousCompositor { virtual bool DemandDrawSw(SkCanvas* canvas) = 0; // Set the memory limit policy of this compositor. - virtual void SetMemoryPolicy( - const SynchronousCompositorMemoryPolicy& policy) = 0; + virtual void SetMemoryPolicy(size_t bytes_limit) = 0; // Should be called by the embedder after the embedder had modified the // scroll offset of the root layer (as returned by |