Skip to content

Commit

Permalink
Refactor ElementDecoration to ElementEffects
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Mar 26, 2024
1 parent c93dbc0 commit 37cf4d3
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 79 deletions.
4 changes: 2 additions & 2 deletions CMake/FileList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ set(Core_HDR_FILES
${PROJECT_SOURCE_DIR}/Source/Core/DocumentHeader.h
${PROJECT_SOURCE_DIR}/Source/Core/ElementAnimation.h
${PROJECT_SOURCE_DIR}/Source/Core/ElementBackgroundBorder.h
${PROJECT_SOURCE_DIR}/Source/Core/ElementDecoration.h
${PROJECT_SOURCE_DIR}/Source/Core/ElementDefinition.h
${PROJECT_SOURCE_DIR}/Source/Core/ElementEffects.h
${PROJECT_SOURCE_DIR}/Source/Core/ElementHandle.h
${PROJECT_SOURCE_DIR}/Source/Core/Elements/ElementImage.h
${PROJECT_SOURCE_DIR}/Source/Core/Elements/ElementLabel.h
Expand Down Expand Up @@ -277,9 +277,9 @@ set(Core_SRC_FILES
${PROJECT_SOURCE_DIR}/Source/Core/Element.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementAnimation.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementBackgroundBorder.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementDecoration.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementDefinition.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementDocument.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementEffects.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementHandle.cpp
${PROJECT_SOURCE_DIR}/Source/Core/ElementInstancer.cpp
${PROJECT_SOURCE_DIR}/Source/Core/Elements/ElementForm.cpp
Expand Down
11 changes: 6 additions & 5 deletions Include/RmlUi/Core/EffectSpecification.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ class RMLUICORE_API EffectSpecification {
protected:
~EffectSpecification();

/// Registers a property for the decorator.
/// Registers a property for the effect.
/// @param[in] property_name The name of the new property (how it is specified through RCSS).
/// @param[in] default_value The default value to be used.
/// @return The new property definition, ready to have parsers attached.
PropertyDefinition& RegisterProperty(const String& property_name, const String& default_value);

/// Registers a shorthand property definition. Specify a shorthand name of 'decorator' to parse anonymous decorators.
/// Registers a shorthand property definition. Specify a shorthand name of 'decorator' or 'filter' to parse
/// anonymous decorators or filters, respectively.
/// @param[in] shorthand_name The name to register the new shorthand property under.
/// @param[in] properties A comma-separated list of the properties this definition is shorthand for. The order in which they are specified here is
/// the order in which the values will be processed.
/// @param[in] properties A comma-separated list of the properties this definition is shorthand for. The order in
/// which they are specified here is the order in which the values will be processed.
/// @param[in] type The type of shorthand to declare.
/// @param True if all the property names exist, false otherwise.
/// @return An ID for the new shorthand, or 'Invalid' if the shorthand declaration is invalid.
ShorthandId RegisterShorthand(const String& shorthand_name, const String& property_names, ShorthandType type);

private:
Expand Down
3 changes: 0 additions & 3 deletions Include/RmlUi/Core/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ElementInstancer;
class EventDispatcher;
class EventListener;
class ElementBackgroundBorder;
class ElementDecoration;
class ElementDefinition;
class ElementDocument;
class ElementScroll;
Expand Down Expand Up @@ -578,8 +577,6 @@ class RMLUICORE_API Element : public ScriptInterface, public EnableObserverPtr<E
String GetEventDispatcherSummary() const;
/// Access the element background and border.
ElementBackgroundBorder* GetElementBackgroundBorder() const;
/// Access the element decorators.
ElementDecoration* GetElementDecoration() const;
/// Returns the element's scrollbar functionality.
ElementScroll* GetElementScroll() const;
/// Returns the element's nearest scroll container that can be scrolled, if any.
Expand Down
2 changes: 1 addition & 1 deletion Include/RmlUi/Core/PropertySpecification.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class RMLUICORE_API PropertySpecification {
/// the order in which the values will be processed.
/// @param[in] type The type of shorthand to declare.
/// @param[in] id If 'Invalid' then automatically assigns a new id, otherwise assigns the given id.
/// @param True if all the property names exist, false otherwise.
/// @return An ID for the new shorthand, or 'Invalid' if the shorthand declaration is invalid.
ShorthandId RegisterShorthand(const String& shorthand_name, const String& property_names, ShorthandType type,
ShorthandId id = ShorthandId::Invalid);
/// Returns a shorthand definition.
Expand Down
35 changes: 15 additions & 20 deletions Source/Core/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
#include "DataModel.h"
#include "ElementAnimation.h"
#include "ElementBackgroundBorder.h"
#include "ElementDecoration.h"
#include "ElementDefinition.h"
#include "ElementEffects.h"
#include "ElementStyle.h"
#include "EventDispatcher.h"
#include "EventSpecification.h"
Expand Down Expand Up @@ -92,12 +92,12 @@ static float GetScrollOffsetDelta(ScrollAlignment alignment, float begin_offset,

// Meta objects for element collected in a single struct to reduce memory allocations
struct ElementMeta {
ElementMeta(Element* el) : event_dispatcher(el), style(el), background_border(), decoration(el), scroll(el), computed_values(el) {}
ElementMeta(Element* el) : event_dispatcher(el), style(el), background_border(), effects(el), scroll(el), computed_values(el) {}
SmallUnorderedMap<EventId, EventListener*> attribute_event_listeners;
EventDispatcher event_dispatcher;
ElementStyle style;
ElementBackgroundBorder background_border;
ElementDecoration decoration;
ElementEffects effects;
ElementScroll scroll;
Style::ComputedValues computed_values;
};
Expand Down Expand Up @@ -177,7 +177,7 @@ void Element::Update(float dp_ratio, Vector2f vp_dimensions)
UpdateProperties(dp_ratio, vp_dimensions);
}

meta->decoration.InstanceDecorators();
meta->effects.InstanceEffects();

for (size_t i = 0; i < children.size(); i++)
children[i]->Update(dp_ratio, vp_dimensions);
Expand Down Expand Up @@ -233,13 +233,13 @@ void Element::Render()
// Apply our transform
ElementUtilities::ApplyTransform(*this);

meta->decoration.RenderDecorators(RenderStage::Enter);
meta->effects.RenderEffects(RenderStage::Enter);

// Set up the clipping region for this element.
if (ElementUtilities::SetClippingRegion(this))
{
meta->background_border.Render(this);
meta->decoration.RenderDecorators(RenderStage::Decoration);
meta->effects.RenderEffects(RenderStage::Decoration);

{
RMLUI_ZoneScopedNC("OnRender", 0x228B22);
Expand All @@ -252,7 +252,7 @@ void Element::Render()
for (Element* element : stacking_context)
element->Render();

meta->decoration.RenderDecorators(RenderStage::Exit);
meta->effects.RenderEffects(RenderStage::Exit);
}

ElementPtr Element::Clone() const
Expand Down Expand Up @@ -452,7 +452,7 @@ void Element::SetBox(const Box& box)

meta->background_border.DirtyBackground();
meta->background_border.DirtyBorder();
meta->decoration.DirtyDecoratorsData();
meta->effects.DirtyEffectsData();
}
}

Expand All @@ -464,7 +464,7 @@ void Element::AddBox(const Box& box, Vector2f offset)

meta->background_border.DirtyBackground();
meta->background_border.DirtyBorder();
meta->decoration.DirtyDecoratorsData();
meta->effects.DirtyEffectsData();
}

const Box& Element::GetBox()
Expand Down Expand Up @@ -1553,11 +1553,6 @@ ElementBackgroundBorder* Element::GetElementBackgroundBorder() const
return &meta->background_border;
}

ElementDecoration* Element::GetElementDecoration() const
{
return &meta->decoration;
}

ElementScroll* Element::GetElementScroll() const
{
return &meta->scroll;
Expand Down Expand Up @@ -1795,18 +1790,18 @@ void Element::OnPropertyChange(const PropertyIdSet& changed_properties)
meta->background_border.DirtyBorder();
}

// Dirty the decoration if it's changed.
// Dirty the effects if they've changed.
if (border_radius_changed || filter_or_mask_changed || changed_properties.Contains(PropertyId::Decorator))
{
meta->decoration.DirtyDecorators();
meta->effects.DirtyEffects();
}

// Dirty the decoration data when its visual looks may have changed.
// Dirty the effects data when their visual looks may have changed.
if (border_radius_changed || //
changed_properties.Contains(PropertyId::Opacity) || //
changed_properties.Contains(PropertyId::ImageColor))
{
meta->decoration.DirtyDecoratorsData();
meta->effects.DirtyEffectsData();
}

// Check for `perspective' and `perspective-origin' changes
Expand Down Expand Up @@ -2813,7 +2808,7 @@ void Element::UpdateTransformState()

void Element::OnStyleSheetChangeRecursive()
{
GetElementDecoration()->DirtyDecorators();
meta->effects.DirtyEffects();

OnStyleSheetChange();

Expand All @@ -2825,7 +2820,7 @@ void Element::OnStyleSheetChangeRecursive()

void Element::OnDpRatioChangeRecursive()
{
GetElementDecoration()->DirtyDecorators();
meta->effects.DirtyEffects();
GetStyle()->DirtyPropertiesWithUnits(Unit::DP_SCALABLE_LENGTH);

OnDpRatioChange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
*/

#include "ElementDecoration.h"
#include "ElementEffects.h"
#include "../../Include/RmlUi/Core/ComputedValues.h"
#include "../../Include/RmlUi/Core/Decorator.h"
#include "../../Include/RmlUi/Core/Element.h"
Expand All @@ -38,23 +38,23 @@

namespace Rml {

ElementDecoration::ElementDecoration(Element* _element) : element(_element) {}
ElementEffects::ElementEffects(Element* _element) : element(_element) {}

ElementDecoration::~ElementDecoration()
ElementEffects::~ElementEffects()
{
ReleaseDecorators();
ReleaseEffects();
}

void ElementDecoration::InstanceDecorators()
void ElementEffects::InstanceEffects()
{
if (!decorators_dirty)
if (!effects_dirty)
return;

decorators_dirty = false;
decorators_data_dirty = true;
effects_dirty = false;
effects_data_dirty = true;

RMLUI_ZoneScopedC(0xB22222);
ReleaseDecorators();
ReleaseEffects();

RenderManager* render_manager = element->GetRenderManager();
if (!render_manager)
Expand Down Expand Up @@ -151,11 +151,11 @@ void ElementDecoration::InstanceDecorators()
}
}

void ElementDecoration::ReloadDecoratorsData()
void ElementEffects::ReloadEffectsData()
{
if (decorators_data_dirty)
if (effects_data_dirty)
{
decorators_data_dirty = false;
effects_data_dirty = false;

bool decorator_data_failed = false;
for (DecoratorEntryList* list : {&decorators, &mask_images})
Expand Down Expand Up @@ -190,7 +190,7 @@ void ElementDecoration::ReloadDecoratorsData()
}
}

void ElementDecoration::ReleaseDecorators()
void ElementEffects::ReleaseEffects()
{
for (DecoratorEntryList* list : {&decorators, &mask_images})
{
Expand All @@ -206,10 +206,10 @@ void ElementDecoration::ReleaseDecorators()
backdrop_filters.clear();
}

void ElementDecoration::RenderDecorators(RenderStage render_stage)
void ElementEffects::RenderEffects(RenderStage render_stage)
{
InstanceDecorators();
ReloadDecoratorsData();
InstanceEffects();
ReloadEffectsData();

if (!decorators.empty())
{
Expand Down Expand Up @@ -286,7 +286,7 @@ void ElementDecoration::RenderDecorators(RenderStage render_stage)
// boundaries, which currently only applies to blur and drop-shadow. Alternatively, we could avoid this
// completely if we introduced a render interface API concept of different input and output clipping. That
// is, we set a large input scissor to cover all input data, which can be used e.g. during blurring, and use
// our small border-area-only clipping region for the layers composite output.
// our small border-area-only clipping region for the composite layers output.
ApplyScissorRegionForBackdrop();
render_manager->PushLayer();
const LayerHandle backdrop_temp_layer = render_manager->GetTopLayer();
Expand Down Expand Up @@ -340,14 +340,14 @@ void ElementDecoration::RenderDecorators(RenderStage render_stage)
}
}

void ElementDecoration::DirtyDecorators()
void ElementEffects::DirtyEffects()
{
decorators_dirty = true;
effects_dirty = true;
}

void ElementDecoration::DirtyDecoratorsData()
void ElementEffects::DirtyEffectsData()
{
decorators_data_dirty = true;
effects_data_dirty = true;
}

} // namespace Rml
44 changes: 19 additions & 25 deletions Source/Core/ElementDecoration.h → Source/Core/ElementEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,43 @@
*
*/

#ifndef RMLUI_CORE_ELEMENTDECORATION_H
#define RMLUI_CORE_ELEMENTDECORATION_H
#ifndef RMLUI_CORE_ELEMENTEFFECTS_H
#define RMLUI_CORE_ELEMENTEFFECTS_H

#include "../../Include/RmlUi/Core/CompiledFilterShader.h"
#include "../../Include/RmlUi/Core/Filter.h"
#include "../../Include/RmlUi/Core/Types.h"

namespace Rml {

class Decorator;
class Element;
class Filter;
class CompiledFilter;

enum class RenderStage { Enter, Decoration, Exit };

/**
Manages an elements decorator state
@author Lloyd Weehuizen
Manages and renders an element's effects: decorators, filters, backdrop filters, and mask images.
*/

class ElementDecoration {
class ElementEffects {
public:
ElementDecoration(Element* element);
~ElementDecoration();
ElementEffects(Element* element);
~ElementEffects();

/// Instances decorators if necessary.
void InstanceDecorators();
void InstanceEffects();

/// Renders all appropriate decorators.
void RenderDecorators(RenderStage render_stage);
void RenderEffects(RenderStage render_stage);

/// Mark decorators as dirty and force them to reset themselves.
void DirtyDecorators();
/// Mark the element data of decorators as dirty.
void DirtyDecoratorsData();
// Mark effects as dirty and force them to reset themselves.
void DirtyEffects();
// Mark the element data of effects as dirty.
void DirtyEffectsData();

private:
// Releases existing element data of decorators, and regenerates it.
void ReloadDecoratorsData();
// Releases all existing decorators and frees their data.
void ReleaseDecorators();
// Releases existing element data of effects, and regenerates it.
void ReloadEffectsData();
// Releases all existing effects and their element data.
void ReleaseEffects();

struct DecoratorEntry {
SharedPtr<const Decorator> decorator;
Expand All @@ -85,16 +79,16 @@ class ElementDecoration {

Element* element;

// The list of decorators and filters used by this element from all style rules.
// The list of decorators and filters used by this element.
DecoratorEntryList decorators;
DecoratorEntryList mask_images;
FilterEntryList filters;
FilterEntryList backdrop_filters;

// If set, a full reload is necessary.
bool decorators_dirty = false;
bool effects_dirty = false;
// If set, element data of all decorators need to be regenerated.
bool decorators_data_dirty = false;
bool effects_data_dirty = false;
};

} // namespace Rml
Expand Down
Loading

0 comments on commit 37cf4d3

Please sign in to comment.