Procházet zdrojové kódy

Refactor: Move the box shadow generation into a separate file

Michael Ragazzon před 2 roky
rodič
revize
ae8f2a4a5e

+ 2 - 0
CMake/FileList.cmake

@@ -56,6 +56,7 @@ set(Core_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutline.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutline.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadow.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadow.h
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryBackgroundBorder.h
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryBackgroundBorder.h
+    ${PROJECT_SOURCE_DIR}/Source/Core/GeometryBoxShadow.h
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryDatabase.h
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryDatabase.h
     ${PROJECT_SOURCE_DIR}/Source/Core/IdNameMap.h
     ${PROJECT_SOURCE_DIR}/Source/Core/IdNameMap.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/BlockContainer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/BlockContainer.h
@@ -324,6 +325,7 @@ set(Core_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEngineInterface.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEngineInterface.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Geometry.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Geometry.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryBackgroundBorder.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryBackgroundBorder.cpp
+    ${PROJECT_SOURCE_DIR}/Source/Core/GeometryBoxShadow.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryDatabase.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryDatabase.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryUtilities.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryUtilities.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/BlockContainer.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Layout/BlockContainer.cpp

+ 9 - 202
Source/Core/ElementBackgroundBorder.cpp

@@ -33,6 +33,7 @@
 #include "../../Include/RmlUi/Core/DecorationTypes.h"
 #include "../../Include/RmlUi/Core/DecorationTypes.h"
 #include "../../Include/RmlUi/Core/Element.h"
 #include "../../Include/RmlUi/Core/Element.h"
 #include "../../Include/RmlUi/Core/GeometryUtilities.h"
 #include "../../Include/RmlUi/Core/GeometryUtilities.h"
+#include "GeometryBoxShadow.h"
 
 
 namespace Rml {
 namespace Rml {
 
 
@@ -147,214 +148,20 @@ void ElementBackgroundBorder::GenerateGeometry(Element* element)
 
 
 	if (has_box_shadow)
 	if (has_box_shadow)
 	{
 	{
+		Geometry& background_border_geometry = *GetGeometry(BackgroundType::BackgroundBorder);
+
 		const Property* p_box_shadow = element->GetLocalProperty(PropertyId::BoxShadow);
 		const Property* p_box_shadow = element->GetLocalProperty(PropertyId::BoxShadow);
 		RMLUI_ASSERT(p_box_shadow->value.GetType() == Variant::BOXSHADOWLIST);
 		RMLUI_ASSERT(p_box_shadow->value.GetType() == Variant::BOXSHADOWLIST);
 		BoxShadowList shadow_list = p_box_shadow->value.Get<BoxShadowList>();
 		BoxShadowList shadow_list = p_box_shadow->value.Get<BoxShadowList>();
 
 
-		GenerateBoxShadow(element, std::move(shadow_list), border_radius, computed.opacity());
-	}
-}
-
-void ElementBackgroundBorder::GenerateBoxShadow(Element* element, BoxShadowList shadow_list, const Vector4f border_radius, const float opacity)
-{
-	// Find the box-shadow texture dimension and offset required to cover all box-shadows and element boxes combined.
-	Vector2f element_offset_in_texture;
-	Vector2i texture_dimensions;
-
-	// Resolve all lengths to px units.
-	for (BoxShadow& shadow : shadow_list)
-	{
-		shadow.blur_radius = NumericValue(element->ResolveLength(shadow.blur_radius), Unit::PX);
-		shadow.spread_distance = NumericValue(element->ResolveLength(shadow.spread_distance), Unit::PX);
-		shadow.offset_x = NumericValue(element->ResolveLength(shadow.offset_x), Unit::PX);
-		shadow.offset_y = NumericValue(element->ResolveLength(shadow.offset_y), Unit::PX);
-	}
-
-	{
-		Vector2f extend_min;
-		Vector2f extend_max;
-
-		// Extend the render-texture to encompass box-shadow blur and spread.
-		for (const BoxShadow& shadow : shadow_list)
-		{
-			if (!shadow.inset)
-			{
-				const float extend = 1.5f * shadow.blur_radius.number + shadow.spread_distance.number;
-				const Vector2f offset = {shadow.offset_x.number, shadow.offset_y.number};
-				extend_min = Math::Min(extend_min, offset - Vector2f(extend));
-				extend_max = Math::Max(extend_max, offset + Vector2f(extend));
-			}
-		}
-
-		Rectanglef texture_region;
+		// Generate the geometry for the box-shadow texture.
+		Background& shadow_background = GetOrCreateBackground(BackgroundType::BoxShadow);
+		Geometry& shadow_geometry = shadow_background.geometry;
+		Texture& shadow_texture = shadow_background.texture;
 
 
-		// Extend the render-texture further to cover all the element's boxes.
-		for (int i = 0; i < element->GetNumBoxes(); i++)
-		{
-			Vector2f offset;
-			const Box& box = element->GetBox(i, offset);
-			texture_region.Join(Rectanglef::FromPositionSize(offset, box.GetSize(BoxArea::Border)));
-		}
-
-		texture_region.ExtendTopLeft(-extend_min);
-		texture_region.ExtendBottomRight(extend_max);
-		Math::ExpandToPixelGrid(texture_region);
-
-		element_offset_in_texture = -texture_region.TopLeft();
-		texture_dimensions = Vector2i(texture_region.Size());
+		GeometryBoxShadow::Generate(shadow_geometry, shadow_texture, element, background_border_geometry, std::move(shadow_list), border_radius,
+			computed.opacity());
 	}
 	}
-
-	Geometry& background_border_geometry = *GetGeometry(BackgroundType::BackgroundBorder);
-
-	// Callback for generating the box-shadow texture. Using a callback ensures that the texture can be regenerated at any time, for example if the
-	// device loses its GPU context and the client calls Rml::ReleaseTextures().
-	auto p_callback = [&background_border_geometry, element, border_radius, texture_dimensions, element_offset_in_texture, shadow_list](
-						  RenderInterface* render_interface, const String& /*name*/, TextureHandle& out_handle, Vector2i& out_dimensions) -> bool {
-		Context* context = element->GetContext();
-		if (!context)
-		{
-			RMLUI_ERROR;
-			return false;
-		}
-
-		Geometry geometry_padding;        // Render geometry for inner box-shadow.
-		Geometry geometry_padding_border; // Clipping mask for outer box-shadow.
-
-		bool has_inner_shadow = false;
-		bool has_outer_shadow = false;
-		for (const BoxShadow& shadow : shadow_list)
-		{
-			if (shadow.inset)
-				has_inner_shadow = true;
-			else
-				has_outer_shadow = true;
-		}
-
-		// Generate the geometry for all the element's boxes and extend the render-texture further to cover all of them.
-		for (int i = 0; i < element->GetNumBoxes(); i++)
-		{
-			Vector2f offset;
-			const Box& box = element->GetBox(i, offset);
-
-			if (has_inner_shadow)
-				GeometryUtilities::GenerateBackground(&geometry_padding, box, offset, border_radius, Colourb(255), BoxArea::Padding);
-			if (has_outer_shadow)
-				GeometryUtilities::GenerateBackground(&geometry_padding_border, box, offset, border_radius, Colourb(255), BoxArea::Border);
-		}
-
-		RenderManager& render_manager = context->GetRenderManager();
-		const RenderState initial_render_state = render_manager.GetState();
-		render_manager.ResetState();
-		render_manager.SetScissorRegion(Rectanglei::FromSize(texture_dimensions));
-
-		render_interface->PushLayer(LayerFill::Clear);
-
-		background_border_geometry.Render(element_offset_in_texture);
-
-		for (int shadow_index = (int)shadow_list.size() - 1; shadow_index >= 0; shadow_index--)
-		{
-			const BoxShadow& shadow = shadow_list[shadow_index];
-			const Vector2f shadow_offset = {shadow.offset_x.number, shadow.offset_y.number};
-			const bool inset = shadow.inset;
-			const float spread_distance = shadow.spread_distance.number;
-			const float blur_radius = shadow.blur_radius.number;
-
-			Vector4f spread_radii = border_radius;
-			for (int i = 0; i < 4; i++)
-			{
-				float& radius = spread_radii[i];
-				float spread_factor = (inset ? -1.f : 1.f);
-				if (radius < spread_distance)
-				{
-					const float ratio_minus_one = (radius / spread_distance) - 1.f;
-					spread_factor *= 1.f + ratio_minus_one * ratio_minus_one * ratio_minus_one;
-				}
-				radius = Math::Max(radius + spread_factor * spread_distance, 0.f);
-			}
-
-			Geometry shadow_geometry;
-
-			// Generate the shadow geometry. For outer box-shadows it is rendered normally, while for inner box-shadows it is used as a clipping mask.
-			for (int i = 0; i < element->GetNumBoxes(); i++)
-			{
-				Vector2f offset;
-				Box box = element->GetBox(i, offset);
-				const float signed_spread_distance = (inset ? -spread_distance : spread_distance);
-				offset -= Vector2f(signed_spread_distance);
-
-				for (int j = 0; j < Box::num_edges; j++)
-				{
-					BoxEdge edge = (BoxEdge)j;
-					const float new_size = box.GetEdge(BoxArea::Padding, edge) + signed_spread_distance;
-					box.SetEdge(BoxArea::Padding, edge, new_size);
-				}
-
-				GeometryUtilities::GenerateBackground(&shadow_geometry, box, offset, spread_radii, shadow.color,
-					inset ? BoxArea::Padding : BoxArea::Border);
-			}
-
-			CompiledFilterHandle blur = {};
-			if (blur_radius > 0.5f)
-			{
-				blur = render_interface->CompileFilter("blur", Dictionary{{"radius", Variant(blur_radius)}});
-				if (blur)
-					render_interface->PushLayer(LayerFill::Clear);
-			}
-
-			if (inset)
-			{
-				render_manager.SetClipMask(ClipMaskOperation::SetInverse, &shadow_geometry, shadow_offset + element_offset_in_texture);
-
-				for (Rml::Vertex& vertex : geometry_padding.GetVertices())
-					vertex.colour = shadow.color;
-
-				geometry_padding.Release();
-				geometry_padding.Render(element_offset_in_texture);
-
-				render_manager.SetClipMask(ClipMaskOperation::Set, &geometry_padding, element_offset_in_texture);
-			}
-			else
-			{
-				render_manager.SetClipMask(ClipMaskOperation::SetInverse, &geometry_padding_border, element_offset_in_texture);
-				shadow_geometry.Render(shadow_offset + element_offset_in_texture);
-			}
-
-			if (blur)
-			{
-				render_interface->PopLayer(BlendMode::Blend, {blur});
-				render_interface->ReleaseCompiledFilter(blur);
-			}
-		}
-
-		TextureHandle shadow_texture = render_interface->SaveLayerAsTexture(texture_dimensions);
-		if (!shadow_texture)
-			return false;
-
-		render_interface->PopLayer(BlendMode::Discard, {});
-
-		render_manager.SetState(initial_render_state);
-
-		out_dimensions = texture_dimensions;
-		out_handle = shadow_texture;
-
-		return true;
-	};
-
-	// Generate the geometry for the box-shadow texture.
-	Background& shadow_background = GetOrCreateBackground(BackgroundType::BoxShadow);
-	Geometry& shadow_geometry = shadow_background.geometry;
-	Texture& shadow_texture = shadow_background.texture;
-	RMLUI_ASSERT(!shadow_geometry);
-
-	Vector<Vertex>& vertices = shadow_geometry.GetVertices();
-	Vector<int>& indices = shadow_geometry.GetIndices();
-	vertices.resize(4);
-	indices.resize(6);
-	const byte alpha = byte(opacity * 255.f);
-	GeometryUtilities::GenerateQuad(vertices.data(), indices.data(), -element_offset_in_texture, Vector2f(texture_dimensions), Colourb(255, alpha));
-
-	shadow_texture.Set("box-shadow", p_callback);
-	shadow_geometry.SetTexture(&shadow_texture);
 }
 }
 
 
 } // namespace Rml
 } // namespace Rml

+ 0 - 1
Source/Core/ElementBackgroundBorder.h

@@ -57,7 +57,6 @@ private:
 	Background& GetOrCreateBackground(BackgroundType type);
 	Background& GetOrCreateBackground(BackgroundType type);
 
 
 	void GenerateGeometry(Element* element);
 	void GenerateGeometry(Element* element);
-	void GenerateBoxShadow(Element* element, BoxShadowList shadow_list, const Vector4f border_radius, const float opacity);
 
 
 	bool background_dirty = false;
 	bool background_dirty = false;
 	bool border_dirty = false;
 	bool border_dirty = false;

+ 241 - 0
Source/Core/GeometryBoxShadow.cpp

@@ -0,0 +1,241 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019-2023 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "GeometryBoxShadow.h"
+#include "../../Include/RmlUi/Core/Box.h"
+#include "../../Include/RmlUi/Core/Context.h"
+#include "../../Include/RmlUi/Core/DecorationTypes.h"
+#include "../../Include/RmlUi/Core/Element.h"
+#include "../../Include/RmlUi/Core/Geometry.h"
+#include "../../Include/RmlUi/Core/GeometryUtilities.h"
+#include "../../Include/RmlUi/Core/Math.h"
+#include "../../Include/RmlUi/Core/RenderInterface.h"
+#include "../../Include/RmlUi/Core/RenderManager.h"
+#include "../../Include/RmlUi/Core/Texture.h"
+
+namespace Rml {
+
+void GeometryBoxShadow::Generate(Geometry& out_shadow_geometry, Texture& out_shadow_texture, Element* element, Geometry& background_border_geometry,
+	BoxShadowList shadow_list, const Vector4f border_radius, const float opacity)
+{
+	// Find the box-shadow texture dimension and offset required to cover all box-shadows and element boxes combined.
+	Vector2f element_offset_in_texture;
+	Vector2i texture_dimensions;
+
+	// Resolve all lengths to px units.
+	for (BoxShadow& shadow : shadow_list)
+	{
+		shadow.blur_radius = NumericValue(element->ResolveLength(shadow.blur_radius), Unit::PX);
+		shadow.spread_distance = NumericValue(element->ResolveLength(shadow.spread_distance), Unit::PX);
+		shadow.offset_x = NumericValue(element->ResolveLength(shadow.offset_x), Unit::PX);
+		shadow.offset_y = NumericValue(element->ResolveLength(shadow.offset_y), Unit::PX);
+	}
+
+	{
+		Vector2f extend_min;
+		Vector2f extend_max;
+
+		// Extend the render-texture to encompass box-shadow blur and spread.
+		for (const BoxShadow& shadow : shadow_list)
+		{
+			if (!shadow.inset)
+			{
+				const float extend = 1.5f * shadow.blur_radius.number + shadow.spread_distance.number;
+				const Vector2f offset = {shadow.offset_x.number, shadow.offset_y.number};
+				extend_min = Math::Min(extend_min, offset - Vector2f(extend));
+				extend_max = Math::Max(extend_max, offset + Vector2f(extend));
+			}
+		}
+
+		Rectanglef texture_region;
+
+		// Extend the render-texture further to cover all the element's boxes.
+		for (int i = 0; i < element->GetNumBoxes(); i++)
+		{
+			Vector2f offset;
+			const Box& box = element->GetBox(i, offset);
+			texture_region.Join(Rectanglef::FromPositionSize(offset, box.GetSize(BoxArea::Border)));
+		}
+
+		texture_region.ExtendTopLeft(-extend_min);
+		texture_region.ExtendBottomRight(extend_max);
+		Math::ExpandToPixelGrid(texture_region);
+
+		element_offset_in_texture = -texture_region.TopLeft();
+		texture_dimensions = Vector2i(texture_region.Size());
+	}
+
+	// Callback for generating the box-shadow texture. Using a callback ensures that the texture can be regenerated at any time, for example if the
+	// device loses its GPU context and the client calls Rml::ReleaseTextures().
+	auto texture_callback = [&background_border_geometry, element, border_radius, texture_dimensions, element_offset_in_texture,
+								shadow_list = std::move(shadow_list)](RenderInterface* render_interface, const String& /*name*/,
+								TextureHandle& out_handle, Vector2i& out_dimensions) -> bool {
+		Context* context = element->GetContext();
+		if (!context)
+		{
+			RMLUI_ERROR;
+			return false;
+		}
+
+		Geometry geometry_padding;        // Render geometry for inner box-shadow.
+		Geometry geometry_padding_border; // Clipping mask for outer box-shadow.
+
+		bool has_inner_shadow = false;
+		bool has_outer_shadow = false;
+		for (const BoxShadow& shadow : shadow_list)
+		{
+			if (shadow.inset)
+				has_inner_shadow = true;
+			else
+				has_outer_shadow = true;
+		}
+
+		// Generate the geometry for all the element's boxes and extend the render-texture further to cover all of them.
+		for (int i = 0; i < element->GetNumBoxes(); i++)
+		{
+			Vector2f offset;
+			const Box& box = element->GetBox(i, offset);
+
+			if (has_inner_shadow)
+				GeometryUtilities::GenerateBackground(&geometry_padding, box, offset, border_radius, Colourb(255), BoxArea::Padding);
+			if (has_outer_shadow)
+				GeometryUtilities::GenerateBackground(&geometry_padding_border, box, offset, border_radius, Colourb(255), BoxArea::Border);
+		}
+
+		RenderManager& render_manager = context->GetRenderManager();
+		const RenderState initial_render_state = render_manager.GetState();
+		render_manager.ResetState();
+		render_manager.SetScissorRegion(Rectanglei::FromSize(texture_dimensions));
+
+		render_interface->PushLayer(LayerFill::Clear);
+
+		background_border_geometry.Render(element_offset_in_texture);
+
+		for (int shadow_index = (int)shadow_list.size() - 1; shadow_index >= 0; shadow_index--)
+		{
+			const BoxShadow& shadow = shadow_list[shadow_index];
+			const Vector2f shadow_offset = {shadow.offset_x.number, shadow.offset_y.number};
+			const bool inset = shadow.inset;
+			const float spread_distance = shadow.spread_distance.number;
+			const float blur_radius = shadow.blur_radius.number;
+
+			Vector4f spread_radii = border_radius;
+			for (int i = 0; i < 4; i++)
+			{
+				float& radius = spread_radii[i];
+				float spread_factor = (inset ? -1.f : 1.f);
+				if (radius < spread_distance)
+				{
+					const float ratio_minus_one = (radius / spread_distance) - 1.f;
+					spread_factor *= 1.f + ratio_minus_one * ratio_minus_one * ratio_minus_one;
+				}
+				radius = Math::Max(radius + spread_factor * spread_distance, 0.f);
+			}
+
+			Geometry shadow_geometry;
+
+			// Generate the shadow geometry. For outer box-shadows it is rendered normally, while for inner box-shadows it is used as a clipping mask.
+			for (int i = 0; i < element->GetNumBoxes(); i++)
+			{
+				Vector2f offset;
+				Box box = element->GetBox(i, offset);
+				const float signed_spread_distance = (inset ? -spread_distance : spread_distance);
+				offset -= Vector2f(signed_spread_distance);
+
+				for (int j = 0; j < Box::num_edges; j++)
+				{
+					BoxEdge edge = (BoxEdge)j;
+					const float new_size = box.GetEdge(BoxArea::Padding, edge) + signed_spread_distance;
+					box.SetEdge(BoxArea::Padding, edge, new_size);
+				}
+
+				GeometryUtilities::GenerateBackground(&shadow_geometry, box, offset, spread_radii, shadow.color,
+					inset ? BoxArea::Padding : BoxArea::Border);
+			}
+
+			CompiledFilterHandle blur = {};
+			if (blur_radius > 0.5f)
+			{
+				blur = render_interface->CompileFilter("blur", Dictionary{{"radius", Variant(blur_radius)}});
+				if (blur)
+					render_interface->PushLayer(LayerFill::Clear);
+			}
+
+			if (inset)
+			{
+				render_manager.SetClipMask(ClipMaskOperation::SetInverse, &shadow_geometry, shadow_offset + element_offset_in_texture);
+
+				for (Rml::Vertex& vertex : geometry_padding.GetVertices())
+					vertex.colour = shadow.color;
+
+				geometry_padding.Release();
+				geometry_padding.Render(element_offset_in_texture);
+
+				render_manager.SetClipMask(ClipMaskOperation::Set, &geometry_padding, element_offset_in_texture);
+			}
+			else
+			{
+				render_manager.SetClipMask(ClipMaskOperation::SetInverse, &geometry_padding_border, element_offset_in_texture);
+				shadow_geometry.Render(shadow_offset + element_offset_in_texture);
+			}
+
+			if (blur)
+			{
+				render_interface->PopLayer(BlendMode::Blend, {blur});
+				render_interface->ReleaseCompiledFilter(blur);
+			}
+		}
+
+		TextureHandle shadow_texture = render_interface->SaveLayerAsTexture(texture_dimensions);
+		if (!shadow_texture)
+			return false;
+
+		render_interface->PopLayer(BlendMode::Discard, {});
+
+		render_manager.SetState(initial_render_state);
+
+		out_dimensions = texture_dimensions;
+		out_handle = shadow_texture;
+
+		return true;
+	};
+
+	RMLUI_ASSERT(!out_shadow_geometry);
+
+	Vector<Vertex>& vertices = out_shadow_geometry.GetVertices();
+	Vector<int>& indices = out_shadow_geometry.GetIndices();
+	vertices.resize(4);
+	indices.resize(6);
+	const byte alpha = byte(opacity * 255.f);
+	GeometryUtilities::GenerateQuad(vertices.data(), indices.data(), -element_offset_in_texture, Vector2f(texture_dimensions), Colourb(255, alpha));
+
+	out_shadow_texture.Set("box-shadow", texture_callback);
+	out_shadow_geometry.SetTexture(&out_shadow_texture);
+}
+
+} // namespace Rml

+ 55 - 0
Source/Core/GeometryBoxShadow.h

@@ -0,0 +1,55 @@
+/*
+ * This source file is part of RmlUi, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://github.com/mikke89/RmlUi
+ *
+ * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
+ * Copyright (c) 2019-2023 The RmlUi Team, and contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef RMLUI_CORE_GEOMETRYBOXSHADOW_H
+#define RMLUI_CORE_GEOMETRYBOXSHADOW_H
+
+#include "../../Include/RmlUi/Core/Types.h"
+
+namespace Rml {
+
+class Geometry;
+struct Texture;
+
+class GeometryBoxShadow {
+public:
+	/// Generate the texture and geometry for a box shadow.
+	/// @param[out] out_shadow_geometry The target geometry.
+	/// @param[out] out_shadow_texture The target texture, assumes pointer stability during the lifetime of the shadow geometry.
+	/// @param[in] element The element to generate the shadow for.
+	/// @param[in] background_border_geometry The geometry of the background and border, assumed to already have been generated. Assumes pointer
+	/// stability during the lifetime of the shadow geometry.
+	/// @param[in] shadow_list The list of box-shadows to generate.
+	/// @param[in] border_radius The border radius of the element.
+	/// @param[in] opacity The opacity of the element.
+	static void Generate(Geometry& out_shadow_geometry, Texture& out_shadow_texture, Element* element, Geometry& background_border_geometry,
+		BoxShadowList shadow_list, Vector4f border_radius, float opacity);
+};
+
+} // namespace Rml
+#endif