Răsfoiți Sursa

Use move semantics for texture callbacks

Michael Ragazzon 2 ani în urmă
părinte
comite
bdf560880a

+ 1 - 1
Include/RmlUi/Core/Texture.h

@@ -63,7 +63,7 @@ public:
 	/// Set a callback function for generating the texture on first use. The texture is never added to the global cache.
 	/// @param[in] name The name of the texture.
 	/// @param[in] callback The callback function which generates the data of the texture, see TextureCallback.
-	void Set(const String& name, const TextureCallback& callback);
+	void Set(const String& name, TextureCallback&& callback);
 
 	/// Returns the texture's source name. This is usually the name of the file the texture was loaded from.
 	/// @return The name of the this texture's source. This will be the empty string if this texture is not loaded.

+ 1 - 1
Source/Core/FontEngineDefault/FontFaceLayer.cpp

@@ -171,7 +171,7 @@ bool FontFaceLayer::Generate(const FontFaceHandleDefault* handle, const FontFace
 			};
 
 			Texture texture;
-			texture.Set("font-face-layer", texture_callback);
+			texture.Set("font-face-layer", std::move(texture_callback));
 			textures.push_back(texture);
 		}
 	}

+ 2 - 2
Source/Core/Texture.cpp

@@ -37,10 +37,10 @@ void Texture::Set(const String& source, const String& source_path)
 	resource = TextureDatabase::Fetch(source, source_path);
 }
 
-void Texture::Set(const String& name, const TextureCallback& callback)
+void Texture::Set(const String& name, TextureCallback&& callback)
 {
 	resource = MakeShared<TextureResource>();
-	resource->Set(name, callback);
+	resource->Set(name, std::move(callback));
 }
 
 const String& Texture::GetSource() const

+ 2 - 2
Source/Core/TextureResource.cpp

@@ -48,11 +48,11 @@ void TextureResource::Set(const String& _source)
 	source = _source;
 }
 
-void TextureResource::Set(const String& name, const TextureCallback& callback)
+void TextureResource::Set(const String& name, TextureCallback&& callback)
 {
 	Reset();
 	source = name;
-	texture_callback = MakeUnique<TextureCallback>(callback);
+	texture_callback = MakeUnique<TextureCallback>(std::move(callback));
 	TextureDatabase::AddCallbackTexture(this);
 }
 

+ 1 - 1
Source/Core/TextureResource.h

@@ -52,7 +52,7 @@ public:
 
 	/// Clear any existing data and set a callback function for loading the data.
 	/// Texture loading is delayed until the texture is accessed by a specific render interface.
-	void Set(const String& name, const TextureCallback& callback);
+	void Set(const String& name, TextureCallback&& callback);
 
 	/// Returns the resource's underlying texture handle.
 	TextureHandle GetHandle();

+ 3 - 3
Source/Lottie/ElementLottie.cpp

@@ -225,8 +225,8 @@ void ElementLottie::UpdateTexture()
 	}
 
 	// Callback for generating texture.
-	auto p_callback = [this, next_frame](RenderInterface* render_interface, const String& /*name*/, TextureHandle& out_handle,
-						  Vector2i& out_dimensions) -> bool {
+	auto texture_callback = [this, next_frame](RenderInterface* render_interface, const String& /*name*/, TextureHandle& out_handle,
+								Vector2i& out_dimensions) -> bool {
 		RMLUI_ASSERT(animation);
 
 		const size_t bytes_per_line = 4 * render_dimensions.x;
@@ -259,7 +259,7 @@ void ElementLottie::UpdateTexture()
 		return true;
 	};
 
-	texture.Set("lottie", p_callback);
+	texture.Set("lottie", std::move(texture_callback));
 	geometry.SetTexture(&texture);
 	prev_animation_frame = next_frame;
 	texture_size_dirty = false;

+ 3 - 2
Source/SVG/ElementSVG.cpp

@@ -194,7 +194,8 @@ void ElementSVG::UpdateTexture()
 		return;
 
 	// Callback for generating texture.
-	auto p_callback = [this](RenderInterface* render_interface, const String& /*name*/, TextureHandle& out_handle, Vector2i& out_dimensions) -> bool {
+	auto texture_callback = [this](RenderInterface* render_interface, const String& /*name*/, TextureHandle& out_handle,
+								Vector2i& out_dimensions) -> bool {
 		RMLUI_ASSERT(svg_document);
 		lunasvg::Bitmap bitmap = svg_document->renderToBitmap(render_dimensions.x, render_dimensions.y);
 		if (!bitmap.valid() || !bitmap.data())
@@ -205,7 +206,7 @@ void ElementSVG::UpdateTexture()
 		return true;
 	};
 
-	texture.Set("svg", p_callback);
+	texture.Set("svg", std::move(texture_callback));
 	geometry.SetTexture(&texture);
 	texture_dirty = false;
 }