Commit 290deb11 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Migrate tint caching to ResourceManager

This patch moves the responsibility of tracking which tints are used
in a frame to the ResourceManager. When a tinted resource is requested
the ResourceManager tracks it instead of the TabListSceneLayer. When
a frame is finalized, the CompositorView passes a signal to the
ResourceManager to clear out any tinted resources that were not used
in that frame.

Bug: 1111772
Change-Id: I6f71aca94f1f05d413a4b3d0e83c39f11c4b7594
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2334992Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795434}
parent a479469e
...@@ -299,6 +299,8 @@ void CompositorView::SetSceneLayer(JNIEnv* env, ...@@ -299,6 +299,8 @@ void CompositorView::SetSceneLayer(JNIEnv* env,
void CompositorView::FinalizeLayers(JNIEnv* env, void CompositorView::FinalizeLayers(JNIEnv* env,
const JavaParamRef<jobject>& jobj) { const JavaParamRef<jobject>& jobj) {
if (GetResourceManager())
GetResourceManager()->OnFrameUpdatesFinished();
#if !defined(OFFICIAL_BUILD) #if !defined(OFFICIAL_BUILD)
TRACE_EVENT0("compositor", "CompositorView::FinalizeLayers"); TRACE_EVENT0("compositor", "CompositorView::FinalizeLayers");
#endif #endif
......
...@@ -42,8 +42,6 @@ void TabListSceneLayer::BeginBuildingFrame(JNIEnv* env, ...@@ -42,8 +42,6 @@ void TabListSceneLayer::BeginBuildingFrame(JNIEnv* env,
// matches PutTabLayer call order. // matches PutTabLayer call order.
for (auto tab : tab_map_) for (auto tab : tab_map_)
tab.second->layer()->RemoveFromParent(); tab.second->layer()->RemoveFromParent();
used_tints_.clear();
} }
void TabListSceneLayer::FinishBuildingFrame(JNIEnv* env, void TabListSceneLayer::FinishBuildingFrame(JNIEnv* env,
...@@ -57,8 +55,6 @@ void TabListSceneLayer::FinishBuildingFrame(JNIEnv* env, ...@@ -57,8 +55,6 @@ void TabListSceneLayer::FinishBuildingFrame(JNIEnv* env,
++it; ++it;
} }
visible_tabs_this_frame_.clear(); visible_tabs_this_frame_.clear();
DCHECK(resource_manager_);
resource_manager_->RemoveUnusedTints(used_tints_);
} }
void TabListSceneLayer::UpdateLayer( void TabListSceneLayer::UpdateLayer(
...@@ -149,13 +145,6 @@ void TabListSceneLayer::PutTabLayer( ...@@ -149,13 +145,6 @@ void TabListSceneLayer::PutTabLayer(
own_tree_->AddChild(layer->layer()); own_tree_->AddChild(layer->layer());
visible_tabs_this_frame_.insert(id); visible_tabs_this_frame_.insert(id);
// Add the tints for the border asset and close icon to the list that was
// used for this frame.
used_tints_.insert(toolbar_background_color);
used_tints_.insert(close_button_color);
used_tints_.insert(default_theme_color);
used_tints_.insert(toolbar_textbox_background_color);
DCHECK(layer); DCHECK(layer);
if (layer) { if (layer) {
std::vector<int> tab_ids; std::vector<int> tab_ids;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <unordered_set>
#include "base/macros.h" #include "base/macros.h"
#include "cc/layers/layer.h" #include "cc/layers/layer.h"
...@@ -121,9 +120,6 @@ class TabListSceneLayer : public SceneLayer { ...@@ -121,9 +120,6 @@ class TabListSceneLayer : public SceneLayer {
SkColor GetBackgroundColor() override; SkColor GetBackgroundColor() override;
private: private:
// The set of tint colors that were used for a frame.
std::unordered_set<int> used_tints_;
typedef std::map<int, scoped_refptr<TabLayer>> TabMap; typedef std::map<int, scoped_refptr<TabLayer>> TabMap;
TabMap tab_map_; TabMap tab_map_;
std::set<int> visible_tabs_this_frame_; std::set<int> visible_tabs_this_frame_;
......
...@@ -49,11 +49,6 @@ class UI_ANDROID_EXPORT ResourceManager { ...@@ -49,11 +49,6 @@ class UI_ANDROID_EXPORT ResourceManager {
virtual Resource* GetStaticResourceWithTint(int res_id, virtual Resource* GetStaticResourceWithTint(int res_id,
SkColor tint_color) = 0; SkColor tint_color) = 0;
// Remove tints that were unused in the current frame being built. This
// function takes a set |used_tints| and removes all the tints not in the set
// from the cache.
virtual void RemoveUnusedTints(const std::unordered_set<int>& used_tints) = 0;
// Trigger asynchronous loading of the resource specified by |res_type| and // Trigger asynchronous loading of the resource specified by |res_type| and
// |res_id|, if it has not yet been loaded. // |res_id|, if it has not yet been loaded.
virtual void PreloadResource(AndroidResourceType res_type, int res_id) = 0; virtual void PreloadResource(AndroidResourceType res_type, int res_id) = 0;
...@@ -65,6 +60,9 @@ class UI_ANDROID_EXPORT ResourceManager { ...@@ -65,6 +60,9 @@ class UI_ANDROID_EXPORT ResourceManager {
: 0; : 0;
} }
// A notification that all updates have finished for the current frame.
virtual void OnFrameUpdatesFinished() = 0;
protected: protected:
virtual ~ResourceManager() {} virtual ~ResourceManager() {}
}; };
......
...@@ -117,12 +117,11 @@ Resource* ResourceManagerImpl::GetResource(AndroidResourceType res_type, ...@@ -117,12 +117,11 @@ Resource* ResourceManagerImpl::GetResource(AndroidResourceType res_type,
return item->second.get(); return item->second.get();
} }
void ResourceManagerImpl::RemoveUnusedTints( void ResourceManagerImpl::RemoveUnusedTints() {
const std::unordered_set<int>& used_tints) {
// Iterate over the currently cached tints and remove ones that were not // Iterate over the currently cached tints and remove ones that were not
// used as defined in |used_tints|. // used as defined in |used_tints|.
for (auto it = tinted_resources_.cbegin(); it != tinted_resources_.cend();) { for (auto it = tinted_resources_.cbegin(); it != tinted_resources_.cend();) {
if (used_tints.find(it->first) == used_tints.end()) { if (used_tints_.find(it->first) == used_tints_.end()) {
it = tinted_resources_.erase(it); it = tinted_resources_.erase(it);
} else { } else {
++it; ++it;
...@@ -130,11 +129,18 @@ void ResourceManagerImpl::RemoveUnusedTints( ...@@ -130,11 +129,18 @@ void ResourceManagerImpl::RemoveUnusedTints(
} }
} }
void ResourceManagerImpl::OnFrameUpdatesFinished() {
RemoveUnusedTints();
used_tints_.clear();
}
Resource* ResourceManagerImpl::GetStaticResourceWithTint(int res_id, Resource* ResourceManagerImpl::GetStaticResourceWithTint(int res_id,
SkColor tint_color) { SkColor tint_color) {
if (tinted_resources_.find(tint_color) == tinted_resources_.end()) { if (tinted_resources_.find(tint_color) == tinted_resources_.end()) {
tinted_resources_[tint_color] = std::make_unique<ResourceMap>(); tinted_resources_[tint_color] = std::make_unique<ResourceMap>();
} }
used_tints_.insert(tint_color);
ResourceMap* resource_map = tinted_resources_[tint_color].get(); ResourceMap* resource_map = tinted_resources_[tint_color].get();
// If the resource is already cached, use it. // If the resource is already cached, use it.
......
...@@ -39,8 +39,8 @@ class UI_ANDROID_EXPORT ResourceManagerImpl ...@@ -39,8 +39,8 @@ class UI_ANDROID_EXPORT ResourceManagerImpl
Resource* GetResource(AndroidResourceType res_type, int res_id) override; Resource* GetResource(AndroidResourceType res_type, int res_id) override;
Resource* GetStaticResourceWithTint( Resource* GetStaticResourceWithTint(
int res_id, SkColor tint_color) override; int res_id, SkColor tint_color) override;
void RemoveUnusedTints(const std::unordered_set<int>& used_tints) override;
void PreloadResource(AndroidResourceType res_type, int res_id) override; void PreloadResource(AndroidResourceType res_type, int res_id) override;
void OnFrameUpdatesFinished() override;
// Called from Java // Called from Java
// ---------------------------------------------------------- // ----------------------------------------------------------
...@@ -73,6 +73,11 @@ class UI_ANDROID_EXPORT ResourceManagerImpl ...@@ -73,6 +73,11 @@ class UI_ANDROID_EXPORT ResourceManagerImpl
virtual void RequestResourceFromJava(AndroidResourceType res_type, virtual void RequestResourceFromJava(AndroidResourceType res_type,
int res_id); int res_id);
// Remove tints that were unused in the current frame being built. This
// function takes a set |used_tints| and removes all the tints not in the set
// from the cache.
void RemoveUnusedTints();
using ResourceMap = std::unordered_map<int, std::unique_ptr<Resource>>; using ResourceMap = std::unordered_map<int, std::unique_ptr<Resource>>;
using TintedResourceMap = using TintedResourceMap =
std::unordered_map<SkColor, std::unique_ptr<ResourceMap>>; std::unordered_map<SkColor, std::unique_ptr<ResourceMap>>;
...@@ -81,6 +86,9 @@ class UI_ANDROID_EXPORT ResourceManagerImpl ...@@ -81,6 +86,9 @@ class UI_ANDROID_EXPORT ResourceManagerImpl
ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT];
TintedResourceMap tinted_resources_; TintedResourceMap tinted_resources_;
// The set of tints that are used for resources in the current frame.
std::unordered_set<int> used_tints_;
base::android::ScopedJavaGlobalRef<jobject> java_obj_; base::android::ScopedJavaGlobalRef<jobject> java_obj_;
DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl); DISALLOW_COPY_AND_ASSIGN(ResourceManagerImpl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment