Make tree id sequence in LayerTreeHost thread-safe.

LayerTreeHost instances can exists in multiple threads. e.g. Aura with
--single-process. So this CL makes the sequence thread-safe.

In addition, this CL removes unused s_num_layer_tree_instances.

Review URL: https://codereview.chromium.org/57713004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233047 0039d316-1c4b-4281-b951-d872f2087c98
parent f125f922
......@@ -11,10 +11,12 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/lazy_instance.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "cc/animation/animation_registrar.h"
#include "cc/animation/layer_animation_controller.h"
#include "cc/base/math_util.h"
......@@ -41,7 +43,14 @@
#include "ui/gfx/size_conversions.h"
namespace {
static int s_num_layer_tree_instances;
static base::LazyInstance<base::Lock>::Leaky
s_next_tree_id_lock = LAZY_INSTANCE_INITIALIZER;
inline int GetNextTreeId() {
static int s_next_tree_id = 1;
base::AutoLock lock(s_next_tree_id_lock.Get());
return s_next_tree_id++;
}
}
namespace cc {
......@@ -89,10 +98,6 @@ UIResourceRequest& UIResourceRequest::operator=(
UIResourceRequest::~UIResourceRequest() {}
bool LayerTreeHost::AnyLayerTreeHostInstanceExists() {
return s_num_layer_tree_instances > 0;
}
scoped_ptr<LayerTreeHost> LayerTreeHost::Create(
LayerTreeHostClient* client,
SharedBitmapManager* manager,
......@@ -105,8 +110,6 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::Create(
return layer_tree_host.Pass();
}
static int s_next_tree_id = 1;
LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client,
SharedBitmapManager* manager,
const LayerTreeSettings& settings)
......@@ -135,12 +138,11 @@ LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client,
partial_texture_update_requests_(0),
in_paint_layer_contents_(false),
total_frames_used_for_lcd_text_metrics_(0),
tree_id_(s_next_tree_id++),
tree_id_(GetNextTreeId()),
next_commit_forces_redraw_(false),
shared_bitmap_manager_(manager) {
if (settings_.accelerated_animation_enabled)
animation_registrar_ = AnimationRegistrar::Create();
s_num_layer_tree_instances++;
rendering_stats_instrumentation_->set_record_rendering_stats(
debug_state_.RecordRenderingStats());
}
......@@ -182,8 +184,6 @@ LayerTreeHost::~LayerTreeHost() {
proxy_->Stop();
}
s_num_layer_tree_instances--;
if (root_layer_.get()) {
// The layer tree must be destroyed before the layer tree host. We've
// made a contract with our animation controllers that the registrar
......
......@@ -121,9 +121,6 @@ class CC_EXPORT LayerTreeHost {
void SetLayerTreeHostClientReady();
// Returns true if any LayerTreeHost is alive.
static bool AnyLayerTreeHostInstanceExists();
void set_needs_filter_context() { needs_filter_context_ = true; }
bool needs_offscreen_context() const {
return needs_filter_context_;
......
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