Skip to content

Commit 76998f0

Browse files
committed
perf(memory): Reduce memory pressure on shape set fill
1 parent 2a239b1 commit 76998f0

File tree

6 files changed

+115
-2
lines changed

6 files changed

+115
-2
lines changed

src/Uno.UI/UI/Xaml/Shapes/Shape.wasm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ partial void OnFillUpdatedPartial()
8080
switch (fill)
8181
{
8282
case SolidColorBrush scb:
83-
svgElement.SetStyle("fill", scb.ColorWithOpacity.ToHexString());
83+
Uno.UI.Xaml.WindowManagerInterop.SetElementFill(svgElement.HtmlId, scb.ColorWithOpacity);
8484
_fillBrushSubscription.Disposable = null;
8585
break;
8686
case ImageBrush ib:

src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ private struct WindowManagerSetPropertyParams
865865

866866
#endregion
867867

868-
#region SetVisibility
868+
#region SetElementColor
869869

870870
internal static void SetElementColor(IntPtr htmlId, Color color)
871871
{
@@ -898,6 +898,39 @@ private struct WindowManagerSetElementColorParams
898898
}
899899
#endregion
900900

901+
#region SetElementFill
902+
903+
internal static void SetElementFill(IntPtr htmlId, Color color)
904+
{
905+
var colorAsInteger = color.ToCssInteger();
906+
907+
if (UseJavascriptEval)
908+
{
909+
var command = $"Uno.UI.WindowManager.current.setElementFill(\"{htmlId}\", {color});";
910+
WebAssemblyRuntime.InvokeJS(command);
911+
}
912+
else
913+
{
914+
var parms = new WindowManagerSetElementFillParams()
915+
{
916+
HtmlId = htmlId,
917+
Color = colorAsInteger,
918+
};
919+
920+
TSInteropMarshaller.InvokeJS("Uno:setElementFillNative", parms);
921+
}
922+
}
923+
924+
[TSInteropMessage]
925+
[StructLayout(LayoutKind.Sequential, Pack = 4)]
926+
private struct WindowManagerSetElementFillParams
927+
{
928+
public IntPtr HtmlId;
929+
930+
public uint Color;
931+
}
932+
#endregion
933+
901934
#region RemoveView
902935
internal static void RemoveView(IntPtr htmlId, IntPtr childId)
903936
{

src/Uno.UI/WasmScripts/Uno.UI.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ declare namespace Uno.UI {
339339
setElementColorNative(pParam: number): boolean;
340340
private setElementColorInternal;
341341
/**
342+
* Sets the fill property of the specified element
343+
*/
344+
setElementFill(elementId: number, color: number): string;
345+
setElementFillNative(pParam: number): boolean;
346+
private setElementFillInternal;
347+
/**
342348
* Sets the background color property of the specified element
343349
*/
344350
setElementBackgroundColor(pParam: number): boolean;
@@ -1457,6 +1463,11 @@ declare class WindowManagerSetElementColorParams {
14571463
Color: number;
14581464
static unmarshal(pData: number): WindowManagerSetElementColorParams;
14591465
}
1466+
declare class WindowManagerSetElementFillParams {
1467+
HtmlId: number;
1468+
Color: number;
1469+
static unmarshal(pData: number): WindowManagerSetElementFillParams;
1470+
}
14601471
declare class WindowManagerSetElementTransformParams {
14611472
HtmlId: number;
14621473
M11: number;

src/Uno.UI/WasmScripts/Uno.UI.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,22 @@ var Uno;
888888
element.style.setProperty("color", this.numberToCssColor(color));
889889
}
890890
/**
891+
* Sets the fill property of the specified element
892+
*/
893+
setElementFill(elementId, color) {
894+
this.setElementColorInternal(elementId, color);
895+
return "ok";
896+
}
897+
setElementFillNative(pParam) {
898+
const params = WindowManagerSetElementFillParams.unmarshal(pParam);
899+
this.setElementFillInternal(params.HtmlId, params.Color);
900+
return true;
901+
}
902+
setElementFillInternal(elementId, color) {
903+
const element = this.getView(elementId);
904+
element.style.setProperty("fill", this.numberToCssColor(color));
905+
}
906+
/**
891907
* Sets the background color property of the specified element
892908
*/
893909
setElementBackgroundColor(pParam) {
@@ -5352,6 +5368,19 @@ class WindowManagerSetElementColorParams {
53525368
}
53535369
}
53545370
/* TSBindingsGenerator Generated code -- this code is regenerated on each build */
5371+
class WindowManagerSetElementFillParams {
5372+
static unmarshal(pData) {
5373+
const ret = new WindowManagerSetElementFillParams();
5374+
{
5375+
ret.HtmlId = Number(Module.getValue(pData + 0, "*"));
5376+
}
5377+
{
5378+
ret.Color = Module.HEAPU32[(pData + 4) >> 2];
5379+
}
5380+
return ret;
5381+
}
5382+
}
5383+
/* TSBindingsGenerator Generated code -- this code is regenerated on each build */
53555384
class WindowManagerSetElementTransformParams {
53565385
static unmarshal(pData) {
53575386
const ret = new WindowManagerSetElementTransformParams();

src/Uno.UI/ts/WindowManager.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,26 @@ namespace Uno.UI {
736736
element.style.setProperty("color", this.numberToCssColor(color));
737737
}
738738

739+
/**
740+
* Sets the fill property of the specified element
741+
*/
742+
public setElementFill(elementId: number, color: number): string {
743+
this.setElementColorInternal(elementId, color);
744+
return "ok";
745+
}
746+
747+
public setElementFillNative(pParam: number): boolean {
748+
const params = WindowManagerSetElementFillParams.unmarshal(pParam);
749+
this.setElementFillInternal(params.HtmlId, params.Color);
750+
return true;
751+
}
752+
753+
private setElementFillInternal(elementId: number, color: number): void {
754+
const element = this.getView(elementId);
755+
756+
element.style.setProperty("fill", this.numberToCssColor(color));
757+
}
758+
739759
/**
740760
* Sets the background color property of the specified element
741761
*/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* TSBindingsGenerator Generated code -- this code is regenerated on each build */
2+
class WindowManagerSetElementFillParams
3+
{
4+
/* Pack=4 */
5+
public HtmlId : number;
6+
public Color : number;
7+
public static unmarshal(pData:number) : WindowManagerSetElementFillParams
8+
{
9+
const ret = new WindowManagerSetElementFillParams();
10+
11+
{
12+
ret.HtmlId = Number(Module.getValue(pData + 0, "*"));
13+
}
14+
15+
{
16+
ret.Color = Module.HEAPU32[(pData + 4) >> 2];
17+
}
18+
return ret;
19+
}
20+
}

0 commit comments

Comments
 (0)