Browse Source

Dirty flag for structure changes

Michael Ragazzon 6 years ago
parent
commit
fdf6f5305f

+ 5 - 0
Include/Rocket/Core/Element.h

@@ -684,6 +684,8 @@ private:
 	void DirtyStackingContext();
 
 	void DirtyStructure();
+	void DirtyParentStructure();
+	void UpdateStructure();
 
 	void DirtyTransformState(bool perspective_changed, bool transform_changed, bool parent_transform_changed);
 	void UpdateTransformState();
@@ -772,6 +774,9 @@ private:
 	ElementList stacking_context;
 	bool stacking_context_dirty;
 
+	bool structure_dirty;
+	bool parent_structure_dirty;
+
 	PropertyNameList dirty_properties;
 	bool all_properties_dirty;
 

+ 2 - 1
Samples/basic/animation/src/main.cpp

@@ -137,7 +137,8 @@ public:
 		  Avoid dirtying em's: 27.5
 		  Restructuring update loop: 34.5  [f9892a9]
 		  Element constructor, remove geometry database, remove update() from Context::render: 38.0  [1aab59e]
-		  Replace Dictionary with unordered_flat_map: 40.0
+		  Replace Dictionary with unordered_flat_map: 40.0  [b04b4e5]
+		  Dirty flag for structure changes: 43.0
 		
 		*/
 		

+ 30 - 10
Source/Core/Element.cpp

@@ -115,6 +115,9 @@ transform_state(), transform_state_perspective_dirty(true), transform_state_tran
 	local_stacking_context_forced = false;
 	stacking_context_dirty = false;
 
+	structure_dirty = false;
+	parent_structure_dirty = false;
+
 	all_properties_dirty = true;
 
 	font_face_handle = NULL;
@@ -174,14 +177,16 @@ void Element::Update()
 
 	OnUpdate();
 
+	UpdateStructure();
+
 	style->UpdateDefinition();
 	scroll->Update();
 
-	UpdateDirtyProperties();
-
 	UpdateAnimation();
 	AdvanceAnimations();
 
+	UpdateDirtyProperties();
+
 	UpdateTransformState();
 
 	for (size_t i = 0; i < active_children.size(); i++)
@@ -2343,18 +2348,33 @@ void Element::DirtyStructure()
 {
 	// Clear the cached owner document
 	owner_document = NULL;
-	
-	// Inform all children that the structure is dirty
-	for (size_t i = 0; i < children.size(); ++i)
+	structure_dirty = true;
+}
+
+void Element::DirtyParentStructure()
+{
+	owner_document = NULL;
+	parent_structure_dirty = true;
+}
+
+void Element::UpdateStructure()
+{
+	if (parent_structure_dirty)
 	{
-		const ElementDefinition* element_definition = children[i]->GetStyle()->GetDefinition();
-		if (element_definition != NULL &&
-			element_definition->IsStructurallyVolatile())
+		// If children depend on structured selectors, they may need to be updated
+		const ElementDefinition* element_definition = GetStyle()->GetDefinition();
+		if (element_definition != NULL && element_definition->IsStructurallyVolatile())
 		{
-			children[i]->GetStyle()->DirtyDefinition();
+			GetStyle()->DirtyDefinition();
 		}
+	}
+	if (structure_dirty || parent_structure_dirty)
+	{
+		for (size_t i = 0; i < children.size(); ++i)
+			children[i]->DirtyParentStructure();
 
-		children[i]->DirtyStructure();
+		structure_dirty = false;
+		parent_structure_dirty = false;
 	}
 }
 

+ 0 - 5
Source/Core/ElementStyle.cpp

@@ -75,11 +75,6 @@ ElementStyle::~ElementStyle()
 // Returns the element's definition, updating if necessary.
 const ElementDefinition* ElementStyle::GetDefinition()
 {
-	//if (definition_dirty)
-	//{
-	//	UpdateDefinition();
-	//}
-
 	return definition;
 }