Commit f1d1ac7f authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Change global variables referencing LayoutObjects to Persistents

Change global variables referencing LayoutObjects to Persistents in anticipation of oilpanization of LayoutObjects.
Because global variables need to be added to the GC root set.

Bug: 1030176
Change-Id: Ie0ab6e52052f0819172aa0ff6ff9926f167566a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2297038Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788514}
parent ee80a51c
......@@ -92,13 +92,23 @@ ASSERT_SIZE(LayoutBlock, SameSizeAsLayoutBlock);
// keeping track of containing blocks at that time is complicated (we are in
// the middle of recomputing the style so we can't rely on any of its
// information), which is why it's easier to just update it for every layout.
static TrackedDescendantsMap* g_positioned_descendants_map = nullptr;
static TrackedContainerMap* g_positioned_container_map = nullptr;
TrackedDescendantsMap& GetPositionedDescendantsMap() {
DEFINE_STATIC_LOCAL(TrackedDescendantsMap, map, ());
return map;
}
TrackedContainerMap& GetPositionedContainerMap() {
DEFINE_STATIC_LOCAL(TrackedContainerMap, map, ());
return map;
}
// This map keeps track of the descendants whose 'height' is percentage
// associated with a containing block. Like |gPositionedDescendantsMap|, it is
// also recomputed for every layout (see the comment above about why).
static TrackedDescendantsMap* g_percent_height_descendants_map = nullptr;
static TrackedDescendantsMap& GetPercentHeightDescendantsMap() {
DEFINE_STATIC_LOCAL(TrackedDescendantsMap, map, ());
return map;
}
LayoutBlock::LayoutBlock(ContainerNode* node)
: LayoutBox(node),
......@@ -123,16 +133,16 @@ LayoutBlock::LayoutBlock(ContainerNode* node)
void LayoutBlock::RemoveFromGlobalMaps() {
if (HasPositionedObjects()) {
std::unique_ptr<TrackedLayoutBoxListHashSet> descendants =
g_positioned_descendants_map->Take(this);
GetPositionedDescendantsMap().Take(this);
DCHECK(!descendants->IsEmpty());
for (LayoutBox* descendant : *descendants) {
DCHECK_EQ(g_positioned_container_map->at(descendant), this);
g_positioned_container_map->erase(descendant);
DCHECK_EQ(GetPositionedContainerMap().at(descendant), this);
GetPositionedContainerMap().erase(descendant);
}
}
if (HasPercentHeightDescendants()) {
std::unique_ptr<TrackedLayoutBoxListHashSet> descendants =
g_percent_height_descendants_map->Take(this);
GetPercentHeightDescendantsMap().Take(this);
DCHECK(!descendants->IsEmpty());
for (LayoutBox* descendant : *descendants) {
DCHECK_EQ(descendant->PercentHeightContainer(), this);
......@@ -947,8 +957,7 @@ void LayoutBlock::PaintObject(const PaintInfo& paint_info,
}
TrackedLayoutBoxListHashSet* LayoutBlock::PositionedObjectsInternal() const {
return g_positioned_descendants_map ? g_positioned_descendants_map->at(this)
: nullptr;
return GetPositionedDescendantsMap().at(this);
}
void LayoutBlock::InsertPositionedObject(LayoutBox* o) {
......@@ -957,29 +966,23 @@ void LayoutBlock::InsertPositionedObject(LayoutBox* o) {
o->ClearOverrideContainingBlockContentSize();
if (g_positioned_container_map) {
auto container_map_it = g_positioned_container_map->find(o);
if (container_map_it != g_positioned_container_map->end()) {
if (container_map_it->value == this) {
DCHECK(HasPositionedObjects());
DCHECK(PositionedObjects()->Contains(o));
PositionedObjects()->AppendOrMoveToLast(o);
return;
}
RemovePositionedObject(o);
auto container_map_it = GetPositionedContainerMap().find(o);
if (container_map_it != GetPositionedContainerMap().end()) {
if (container_map_it->value == this) {
DCHECK(HasPositionedObjects());
DCHECK(PositionedObjects()->Contains(o));
PositionedObjects()->AppendOrMoveToLast(o);
return;
}
} else {
g_positioned_container_map = new TrackedContainerMap;
RemovePositionedObject(o);
}
g_positioned_container_map->Set(o, this);
GetPositionedContainerMap().Set(o, this);
if (!g_positioned_descendants_map)
g_positioned_descendants_map = new TrackedDescendantsMap;
TrackedLayoutBoxListHashSet* descendant_set =
g_positioned_descendants_map->at(this);
GetPositionedDescendantsMap().at(this);
if (!descendant_set) {
descendant_set = new TrackedLayoutBoxListHashSet;
g_positioned_descendants_map->Set(this, base::WrapUnique(descendant_set));
GetPositionedDescendantsMap().Set(this, base::WrapUnique(descendant_set));
}
descendant_set->insert(o);
......@@ -987,20 +990,17 @@ void LayoutBlock::InsertPositionedObject(LayoutBox* o) {
}
void LayoutBlock::RemovePositionedObject(LayoutBox* o) {
if (!g_positioned_container_map)
return;
LayoutBlock* container = g_positioned_container_map->Take(o);
LayoutBlock* container = GetPositionedContainerMap().Take(o);
if (!container)
return;
TrackedLayoutBoxListHashSet* positioned_descendants =
g_positioned_descendants_map->at(container);
GetPositionedDescendantsMap().at(container);
DCHECK(positioned_descendants);
DCHECK(positioned_descendants->Contains(o));
positioned_descendants->erase(o);
if (positioned_descendants->IsEmpty()) {
g_positioned_descendants_map->erase(container);
GetPositionedDescendantsMap().erase(container);
container->has_positioned_objects_ = false;
}
}
......@@ -1083,12 +1083,12 @@ void LayoutBlock::RemovePositionedObjects(
}
for (auto* object : dead_objects) {
DCHECK_EQ(g_positioned_container_map->at(object), this);
DCHECK_EQ(GetPositionedContainerMap().at(object), this);
positioned_descendants->erase(object);
g_positioned_container_map->erase(object);
GetPositionedContainerMap().erase(object);
}
if (positioned_descendants->IsEmpty()) {
g_positioned_descendants_map->erase(this);
GetPositionedDescendantsMap().erase(this);
has_positioned_objects_ = false;
}
}
......@@ -1122,14 +1122,12 @@ void LayoutBlock::AddPercentHeightDescendant(LayoutBox* descendant) {
cb = cb->ContainingBlock();
}
if (!g_percent_height_descendants_map)
g_percent_height_descendants_map = new TrackedDescendantsMap;
TrackedLayoutBoxListHashSet* descendant_set =
g_percent_height_descendants_map->at(this);
GetPercentHeightDescendantsMap().at(this);
if (!descendant_set) {
descendant_set = new TrackedLayoutBoxListHashSet;
g_percent_height_descendants_map->Set(this,
base::WrapUnique(descendant_set));
GetPercentHeightDescendantsMap().Set(this,
base::WrapUnique(descendant_set));
}
descendant_set->insert(descendant);
......@@ -1141,7 +1139,7 @@ void LayoutBlock::RemovePercentHeightDescendant(LayoutBox* descendant) {
descendants->erase(descendant);
descendant->SetPercentHeightContainer(nullptr);
if (descendants->IsEmpty()) {
g_percent_height_descendants_map->erase(this);
GetPercentHeightDescendantsMap().erase(this);
has_percent_height_descendants_ = false;
}
}
......@@ -1149,9 +1147,7 @@ void LayoutBlock::RemovePercentHeightDescendant(LayoutBox* descendant) {
TrackedLayoutBoxListHashSet* LayoutBlock::PercentHeightDescendantsInternal()
const {
return g_percent_height_descendants_map
? g_percent_height_descendants_map->at(this)
: nullptr;
return GetPercentHeightDescendantsMap().at(this);
}
void LayoutBlock::DirtyForLayoutFromPercentageHeightDescendants(
......@@ -2256,9 +2252,6 @@ bool LayoutBlock::TryLayoutDoingPositionedMovementOnly() {
#if DCHECK_IS_ON()
void LayoutBlock::CheckPositionedObjectsNeedLayout() {
if (!g_positioned_descendants_map)
return;
if (LayoutBlockedByDisplayLock(DisplayLockLifecycleTarget::kChildren))
return;
......
......@@ -79,7 +79,10 @@ PaintLayer* FindFirstStickyBetween(LayoutObject* from, LayoutObject* to) {
// is the next pointer associated with the key.
typedef HashMap<const LayoutBoxModelObject*, LayoutBoxModelObject*>
ContinuationMap;
static ContinuationMap* g_continuation_map = nullptr;
static ContinuationMap& GetContinuationMap() {
DEFINE_STATIC_LOCAL(ContinuationMap, map, ());
return map;
}
void LayoutBoxModelObject::ContentChanged(ContentChangeType change_type) {
if (!HasLayer())
......@@ -1243,18 +1246,15 @@ LayoutUnit LayoutBoxModelObject::ContainingBlockLogicalWidthForContent() const {
}
LayoutBoxModelObject* LayoutBoxModelObject::Continuation() const {
return (!g_continuation_map) ? nullptr : g_continuation_map->at(this);
return GetContinuationMap().at(this);
}
void LayoutBoxModelObject::SetContinuation(LayoutBoxModelObject* continuation) {
if (continuation) {
DCHECK(continuation->IsLayoutInline() || continuation->IsLayoutBlockFlow());
if (!g_continuation_map)
g_continuation_map = new ContinuationMap;
g_continuation_map->Set(this, continuation);
GetContinuationMap().Set(this, continuation);
} else {
if (g_continuation_map)
g_continuation_map->erase(this);
GetContinuationMap().erase(this);
}
}
......
......@@ -92,7 +92,10 @@ ASSERT_SIZE(LayoutText, SameSizeAsLayoutText);
class SecureTextTimer;
typedef HashMap<LayoutText*, SecureTextTimer*> SecureTextTimerMap;
static SecureTextTimerMap* g_secure_text_timers = nullptr;
static SecureTextTimerMap& GetSecureTextTimers() {
DEFINE_STATIC_LOCAL(SecureTextTimerMap, map, ());
return map;
}
class SecureTextTimer final : public TimerBase {
public:
......@@ -115,7 +118,7 @@ class SecureTextTimer final : public TimerBase {
private:
void Fired() override {
DCHECK(g_secure_text_timers->Contains(layout_text_));
DCHECK(GetSecureTextTimers().Contains(layout_text_));
// Forcing setting text as it may be masked later
layout_text_->ForceSetText(layout_text_->GetText().Impl());
}
......@@ -254,8 +257,7 @@ void LayoutText::RemoveAndDestroyTextBoxes() {
}
void LayoutText::WillBeDestroyed() {
if (SecureTextTimer* secure_text_timer =
g_secure_text_timers ? g_secure_text_timers->Take(this) : nullptr)
if (SecureTextTimer* secure_text_timer = GetSecureTextTimers().Take(this))
delete secure_text_timer;
if (node_id_ != kInvalidDOMNodeId) {
......@@ -1920,8 +1922,7 @@ void LayoutText::SecureText(UChar mask) {
int last_typed_character_offset_to_reveal = -1;
UChar revealed_text;
SecureTextTimer* secure_text_timer =
g_secure_text_timers ? g_secure_text_timers->at(this) : nullptr;
SecureTextTimer* secure_text_timer = GetSecureTextTimers().at(this);
if (secure_text_timer && secure_text_timer->IsActive()) {
last_typed_character_offset_to_reveal =
secure_text_timer->LastTypedCharacterOffset();
......@@ -2484,13 +2485,10 @@ bool LayoutText::IsAfterNonCollapsedCharacter(unsigned text_offset) const {
void LayoutText::MomentarilyRevealLastTypedCharacter(
unsigned last_typed_character_offset) {
if (!g_secure_text_timers)
g_secure_text_timers = new SecureTextTimerMap;
SecureTextTimer* secure_text_timer = g_secure_text_timers->at(this);
SecureTextTimer* secure_text_timer = GetSecureTextTimers().at(this);
if (!secure_text_timer) {
secure_text_timer = new SecureTextTimer(this);
g_secure_text_timers->insert(this, secure_text_timer);
GetSecureTextTimers().insert(this, secure_text_timer);
}
secure_text_timer->RestartWithNewText(last_typed_character_offset);
}
......
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