Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Include/RmlUi/Core/DecorationTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "NumericValue.h"
#include "Types.h"
#include "Utilities.h"

namespace Rml {

Expand Down Expand Up @@ -65,4 +66,24 @@ inline bool operator!=(const BoxShadow& a, const BoxShadow& b)
}

} // namespace Rml

namespace std {
template <>
struct hash<::Rml::BoxShadow> {
size_t operator()(const ::Rml::BoxShadow& s) const noexcept
{
using namespace ::Rml;
using namespace ::Rml::Utilities;
size_t seed = std::hash<ColourbPremultiplied>{}(s.color);

HashCombine(seed, s.offset_x);
HashCombine(seed, s.offset_y);
HashCombine(seed, s.blur_radius);
HashCombine(seed, s.spread_distance);
HashCombine(seed, s.inset);
return seed;
}
};

} // namespace std
#endif
15 changes: 14 additions & 1 deletion Include/RmlUi/Core/NumericValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,18 @@ inline bool operator!=(const NumericValue& a, const NumericValue& b)
}

} // namespace Rml

namespace std {
template <>
struct hash<::Rml::NumericValue> {
// FIXME: should the hash function NumericValue not care about unit (as long as resolved unit is the same?)
// Or should it be a regular hash combine?
size_t operator()(const ::Rml::NumericValue& v) const noexcept
{
using namespace ::Rml;
size_t h1 = hash<float>{}(v.number);
size_t h2 = hash<Unit>{}(v.unit);
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
}
};
} // namespace std
#endif
29 changes: 28 additions & 1 deletion Include/RmlUi/Core/RenderBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define RMLUI_CORE_RENDERBOX_H

#include "Types.h"
#include "Utilities.h"

namespace Rml {

Expand Down Expand Up @@ -78,11 +79,37 @@ class RenderBox {
};
inline bool operator==(const RenderBox& a, const RenderBox& b)
{
return a.GetFillSize() == b.GetFillSize() && a.GetBorderOffset() == b.GetBorderOffset() && a.GetBorderWidths() == b.GetBorderWidths() && a.GetBorderRadius() == b.GetBorderRadius();
return a.GetFillSize() == b.GetFillSize() && a.GetBorderOffset() == b.GetBorderOffset() && a.GetBorderWidths() == b.GetBorderWidths() &&
a.GetBorderRadius() == b.GetBorderRadius();
}
inline bool operator!=(const RenderBox& a, const RenderBox& b)
{
return !(a == b);
}
} // namespace Rml

namespace std {
template <>
struct hash<::Rml::RenderBox> {

size_t operator()(const ::Rml::RenderBox& box) const noexcept
{
using namespace ::Rml::Utilities;
static auto HashArray4 = [](const ::Rml::Array<float, 4>& arr) -> size_t {
size_t seed = 0;
for (const auto& v : arr)
HashCombine(seed, v);
return seed;
};

size_t seed = 0;
HashCombine(seed, box.GetFillSize());
HashCombine(seed, box.GetBorderOffset());
HashCombine(seed, HashArray4(box.GetBorderRadius()));
HashCombine(seed, HashArray4(box.GetBorderWidths()));
return seed;
}
};
} // namespace std

#endif
86 changes: 0 additions & 86 deletions Include/RmlUi/Core/RenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,83 +38,6 @@
#include "Types.h"
#include "Utilities.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remnant includes and unnecessary changes now. I'm just making a note here to remember to revert these files that no longer have meaningful changes.


namespace Rml {
using RenderBoxList = Vector<RenderBox>;
struct BoxShadowGeometryInfo {
ColourbPremultiplied background_color;
Array<ColourbPremultiplied, 4> border_colors;
CornerSizes border_radius;
Vector2i texture_dimensions;
Vector2f element_offset_in_texture;
RenderBoxList padding_render_boxes;
RenderBoxList border_render_boxes;
BoxShadowList shadow_list;
};
inline bool operator==(const BoxShadowGeometryInfo& a, const BoxShadowGeometryInfo& b)
{
return a.background_color == b.background_color && a.border_colors == b.border_colors && a.border_radius == b.border_radius && a.texture_dimensions == b.texture_dimensions &&
a.element_offset_in_texture == b.element_offset_in_texture && a.padding_render_boxes == b.padding_render_boxes && a.border_render_boxes == b.border_render_boxes && a.shadow_list == b.shadow_list;
}
inline bool operator!=(const BoxShadowGeometryInfo& a, const BoxShadowGeometryInfo& b)
{
return !(a == b);
}
}

template<> struct std::hash<Rml::BoxShadowGeometryInfo> {
std::size_t operator()(const Rml::BoxShadowGeometryInfo& in) const noexcept {
using namespace Rml;
using namespace Rml::Utilities;
using namespace std;
size_t result = size_t(849128392);

HashCombine(result, reinterpret_cast<const uint32_t&>(in.background_color));
for (const auto& v : in.border_colors) {
HashCombine(result, reinterpret_cast<const uint32_t&>(v));
}

for (const auto& v : in.border_radius) {
HashCombine(result, v);
}
HashCombine(result, in.texture_dimensions.x);
HashCombine(result, in.texture_dimensions.y);
HashCombine(result, in.element_offset_in_texture.x);
HashCombine(result, in.element_offset_in_texture.y);

static const auto fn_hash_render_box = [](size_t& result, const RenderBox& v) {
HashCombine(result, v.GetFillSize().x);
HashCombine(result, v.GetFillSize().y);
HashCombine(result, v.GetBorderOffset().x);
HashCombine(result, v.GetBorderOffset().y);
for (const auto& w : v.GetBorderRadius()) {
HashCombine(result, w);
}
for (const auto& w : v.GetBorderWidths()) {
HashCombine(result, w);
}
};
for (const auto& v : in.padding_render_boxes) {
fn_hash_render_box(result, v);
}
for (const auto& v : in.border_render_boxes) {
fn_hash_render_box(result, v);
}
for (const auto& v : in.shadow_list) {
HashCombine(result, v.blur_radius.number);
HashCombine(result, v.blur_radius.unit);
HashCombine(result, reinterpret_cast<const uint32_t&>(v.color));
HashCombine(result, v.inset);
HashCombine(result, v.offset_x.number);
HashCombine(result, v.offset_x.unit);
HashCombine(result, v.offset_y.number);
HashCombine(result, v.offset_y.unit);
HashCombine(result, v.spread_distance.number);
HashCombine(result, v.spread_distance.unit);
}
return result;
}
};

namespace Rml {
class Geometry;
class CompiledFilter;
Expand Down Expand Up @@ -180,8 +103,6 @@ class RMLUICORE_API RenderManager : NonCopyMoveable {
Texture LoadTexture(const String& source, const String& document_path = String());
CallbackTexture MakeCallbackTexture(CallbackTextureFunction callback);

SharedPtr<CallbackTexture> FindOrMakeBoxShadowCallbackTexture(const BoxShadowGeometryInfo& geometry_info, CallbackTextureFunction callback);

CompiledFilter CompileFilter(const String& name, const Dictionary& parameters);
CompiledShader CompileShader(const String& name, const Dictionary& parameters);

Expand Down Expand Up @@ -214,11 +135,6 @@ class RMLUICORE_API RenderManager : NonCopyMoveable {
void ReleaseResource(const CompiledFilter& filter);
void ReleaseResource(const CompiledShader& shader);

// TODO: better way to autonomously release the box shadow cache?
// References are needed to texture, and we need to be able to ref count it.
// Another possibility is making a custom SharedPtr<> class and allow us to manually reduce ref counts.
void CleanupDeadBoxShadowCache();

struct GeometryData {
Mesh mesh;
CompiledGeometryHandle handle = {};
Expand All @@ -229,8 +145,6 @@ class RMLUICORE_API RenderManager : NonCopyMoveable {
StableVector<GeometryData> geometry_list;
UniquePtr<TextureDatabase> texture_database;

UnorderedMap<BoxShadowGeometryInfo, SharedPtr<CallbackTexture>> box_shadow_cache;

int compiled_filter_count = 0;
int compiled_shader_count = 0;

Expand Down
33 changes: 33 additions & 0 deletions Include/RmlUi/Core/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,39 @@ struct hash<::Rml::FamilyId> {
return h(static_cast<utype>(t));
}
};
template <>
struct hash<::Rml::Vector2i> {
size_t operator()(const ::Rml::Vector2i& v) const noexcept
{
size_t h1 = std::hash<int>{}(v.x);
size_t h2 = std::hash<int>{}(v.y);
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
}
};
template <>
struct hash<::Rml::Vector2f> {
size_t operator()(const ::Rml::Vector2f& v) const noexcept
{
size_t h1 = hash<float>{}(v.x);
size_t h2 = hash<float>{}(v.y);
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
}
};
template <>
struct hash<::Rml::Colourb> {
size_t operator()(const ::Rml::Colourb& v) const noexcept
{
return static_cast<size_t>(hash<uint32_t>{}(reinterpret_cast<const uint32_t&>(v)));
}
};
template <>
struct hash<::Rml::ColourbPremultiplied> {
size_t operator()(const ::Rml::ColourbPremultiplied& v) const noexcept
{
return static_cast<size_t>(hash<uint32_t>{}(reinterpret_cast<const uint32_t&>(v)));
}
};

} // namespace std

#endif
12 changes: 12 additions & 0 deletions Include/RmlUi/Core/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,16 @@ inline bool Any(Units units)
}

} // namespace Rml
namespace std {
// Hash specialization for enum class types (required on some older compilers)
template <>
struct hash<::Rml::Unit> {
using utype = ::std::underlying_type_t<::Rml::Unit>;
size_t operator()(const ::Rml::Unit& t) const noexcept
{
::std::hash<utype> h;
return h(static_cast<utype>(t));
}
};
} // namespace std
#endif
Loading
Loading