Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize code size by adding an internal API UIRenderer._markForUpdateRenderData #18253

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cocos/2d/assembler/graphics/webgl/graphics-assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const graphicsAssembler: IAssembler = {
},

end (graphics: Graphics): void {
graphics.markForUpdateRenderData();
graphics._markForUpdateRenderData();
},

_expandStroke (graphics: Graphics): void {
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/radial-filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export const radialFilled: IAssembler = {
updateUVs (sprite: Sprite) {
const renderData = sprite.renderData!;
renderData.vertDirty = true;
sprite.markForUpdateRenderData();
sprite._markForUpdateRenderData();
},

// fill color here
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/tiled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const tiled: IAssembler = {
const renderData = sprite.renderData;
if (!renderData) return;
renderData.vertDirty = true;
sprite.markForUpdateRenderData();
sprite._markForUpdateRenderData();
},

fillBuffers (sprite: Sprite, renderer: IBatcher) {
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/components/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ export class Graphics extends UIRenderer {
}
}

this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand Down Expand Up @@ -589,7 +589,7 @@ export class Graphics extends UIRenderer {

this._isDrawing = true;
this._isNeedUploadData = true;
(this._assembler as IAssembler).stroke!(this);
(this._assembler as IAssembler).stroke(this);
}

/**
Expand All @@ -606,7 +606,7 @@ export class Graphics extends UIRenderer {

this._isDrawing = true;
this._isNeedUploadData = true;
(this._assembler as IAssembler).fill!(this);
(this._assembler as IAssembler).fill(this);
}

private _updateMtlForGraphics (): void {
Expand Down
46 changes: 23 additions & 23 deletions cocos/2d/components/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
}

this._string = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -249,7 +249,7 @@
}

this._horizontalAlign = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -270,7 +270,7 @@
}

this._verticalAlign = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand Down Expand Up @@ -304,7 +304,7 @@
}

this._fontSize = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -324,7 +324,7 @@
}

this._lineHeight = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -334,7 +334,7 @@
* @zh
* 文本字符之间的间距。仅在使用 BMFont 位图字体时生效。
*/
@visible(function (this: Label) {

Check warning on line 337 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return !this._isSystemFontUsed && this._font instanceof BitmapFont;
})
@displayOrder(9)
Expand All @@ -347,7 +347,7 @@
}

this._spacingX = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -368,7 +368,7 @@
}

this._overflow = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -388,7 +388,7 @@
}

this._enableWrapText = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand Down Expand Up @@ -422,7 +422,7 @@
this.font = null;
}
this._flushAssembler();
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -433,7 +433,7 @@
* 文本字体名称, 只在 useSystemFont 属性为 true 的时候生效。
*/
@displayOrder(13)
@visible(function (this: Label) { return this._isSystemFontUsed; })

Check warning on line 436 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
get fontFamily (): string {
return this._fontFamily;
}
Expand All @@ -443,7 +443,7 @@
}

this._fontFamily = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -455,7 +455,7 @@
*/
@type(Font)
@displayOrder(13)
@visible(function (this: Label) { return !this._isSystemFontUsed; })

Check warning on line 458 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
get font (): Font | null {
// return this._N$file;
return this._font;
Expand Down Expand Up @@ -529,7 +529,7 @@
}

this._isBold = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -549,7 +549,7 @@
}

this._isItalic = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -569,14 +569,14 @@
}

this._isUnderline = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
* @en The height of underline.
* @zh 下划线高度。
*/
@visible(function (this: Label) { return this._isUnderline; })

Check warning on line 579 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@editable
@displayOrder(18)
get underlineHeight (): number {
Expand All @@ -585,7 +585,7 @@
set underlineHeight (value) {
if (this._underlineHeight === value) return;
this._underlineHeight = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -596,7 +596,7 @@
** 描边效果组件,用于字体描边,只能用于系统字体或 ttf 字体。
**/
@editable
@visible(function (this: Label) { return !(this._font instanceof BitmapFont); })

Check warning on line 599 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(19)
get enableOutline (): boolean {
return this._enableOutline;
Expand All @@ -604,7 +604,7 @@
set enableOutline (value) {
if (this._enableOutline === value) return;
this._enableOutline = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -615,7 +615,7 @@
* 改变描边的颜色。
*/
@editable
@visible(function (this: Label) { return this._enableOutline && !(this._font instanceof BitmapFont); })

Check warning on line 618 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(20)
get outlineColor (): Color {
return this._outlineColor;
Expand All @@ -623,7 +623,7 @@
set outlineColor (value: Readonly<Color>) {
if (this._outlineColor === value) return;
this._outlineColor.set(value);
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -634,7 +634,7 @@
* 改变描边的宽度。
*/
@editable
@visible(function (this: Label) { return this._enableOutline && !(this._font instanceof BitmapFont); })

Check warning on line 637 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(21)
get outlineWidth (): number {
return this._outlineWidth;
Expand All @@ -642,7 +642,7 @@
set outlineWidth (value) {
if (this._outlineWidth === value) return;
this._outlineWidth = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -650,7 +650,7 @@
* @zh 用于给 Label 组件添加阴影效果,只能用于系统字体或 ttf 字体。在缓存模式为 char 时不可用。
*/
@editable
@visible(function (this: Label) { return !(this._font instanceof BitmapFont) && (this.cacheMode !== CacheMode.CHAR); })

Check warning on line 653 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(22)
get enableShadow (): boolean {
return this._enableShadow;
Expand All @@ -658,7 +658,7 @@
set enableShadow (value) {
if (this._enableShadow === value) return;
this._enableShadow = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -669,7 +669,7 @@
* 阴影的颜色。
*/
@editable
@visible(function (this: Label) { return this._enableShadow && !(this._font instanceof BitmapFont) && (this.cacheMode !== CacheMode.CHAR); })

Check warning on line 672 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(23)
get shadowColor (): Color {
return this._shadowColor;
Expand All @@ -677,7 +677,7 @@
set shadowColor (value: Readonly<Color>) {
if (this._shadowColor === value) return;
this._shadowColor.set(value);
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -688,7 +688,7 @@
* 字体与阴影的偏移。
*/
@editable
@visible(function (this: Label) { return this._enableShadow && !(this._font instanceof BitmapFont) && (this.cacheMode !== CacheMode.CHAR); })

Check warning on line 691 in cocos/2d/components/label.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
@displayOrder(24)
get shadowOffset (): Vec2 {
return this._shadowOffset;
Expand All @@ -696,7 +696,7 @@
set shadowOffset (value) {
if (this._shadowOffset === value) return;
this._shadowOffset.set(value);
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand All @@ -715,7 +715,7 @@
set shadowBlur (value) {
if (this._shadowBlur === value) return;
this._shadowBlur = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand Down Expand Up @@ -974,7 +974,7 @@
// Cannot use the base class methods directly because BMFont and CHAR cannot be updated in assambler with just color.
protected _updateColor (): void {
super._updateColor();
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

/**
Expand Down Expand Up @@ -1030,7 +1030,7 @@
}

protected _applyFontTexture (): void {
this.markForUpdateRenderData();
this._markForUpdateRenderData();
const font = this._font;
if (font instanceof BitmapFont) {
const spriteFrame = font.spriteFrame;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/components/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export class Mask extends Component {
public markForUpdateRenderData (enable = true): void {
warnID(9007);
if (this.subComp) {
this.subComp.markForUpdateRenderData(enable);
this.subComp._markForUpdateRenderData(enable);
}
}
/**
Expand Down
16 changes: 8 additions & 8 deletions cocos/2d/components/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class Sprite extends UIRenderer {

const lastSprite = this._spriteFrame;
this._spriteFrame = value;
this.markForUpdateRenderData();
this._markForUpdateRenderData();
this._applySpriteFrame(lastSprite);
if (EDITOR) {
this.node.emit(SpriteEventType.SPRITE_FRAME_CHANGED, this);
Expand Down Expand Up @@ -268,7 +268,7 @@ export class Sprite extends UIRenderer {
if (value === FillType.RADIAL || this._fillType === FillType.RADIAL) {
this.destroyRenderData();
} else if (this.renderData) {
this.markForUpdateRenderData(true);
this._markForUpdateRenderData(true);
}
}

Expand Down Expand Up @@ -298,7 +298,7 @@ export class Sprite extends UIRenderer {
this._fillCenter.x = value.x;
this._fillCenter.y = value.y;
if (this._type === SpriteType.FILLED && this.renderData) {
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}
}

Expand All @@ -325,7 +325,7 @@ export class Sprite extends UIRenderer {
set fillStart (value) {
this._fillStart = clamp(value, 0, 1);
if (this._type === SpriteType.FILLED && this.renderData) {
this.markForUpdateRenderData();
this._markForUpdateRenderData();
this._updateUVs();
}
}
Expand Down Expand Up @@ -353,7 +353,7 @@ export class Sprite extends UIRenderer {
// positive: counterclockwise, negative: clockwise
this._fillRange = clamp(value, -1, 1);
if (this._type === SpriteType.FILLED && this.renderData) {
this.markForUpdateRenderData();
this._markForUpdateRenderData();
this._updateUVs();
}
}
Expand Down Expand Up @@ -386,7 +386,7 @@ export class Sprite extends UIRenderer {
this._isTrimmedMode = value;
if ((this._type === SpriteType.SIMPLE /* || this._type === SpriteType.MESH */)
&& this.renderData) {
this.markForUpdateRenderData(true);
this._markForUpdateRenderData(true);
}
}

Expand Down Expand Up @@ -606,7 +606,7 @@ export class Sprite extends UIRenderer {
if (assembler && assembler.createData) {
const rd = self._renderData = assembler.createData(self);
rd.material = self.getRenderMaterial(0);
self.markForUpdateRenderData();
self._markForUpdateRenderData();
if (self.spriteFrame) {
assembler.updateUVs(self);
}
Expand Down Expand Up @@ -672,7 +672,7 @@ export class Sprite extends UIRenderer {
const material = this.getRenderMaterial(0);
if (spriteFrame) {
if (material) {
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}
}

Expand Down
15 changes: 13 additions & 2 deletions cocos/2d/components/ui-mesh-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class UIMeshRenderer extends Component {

onEnable (): void {
uiRendererManager.addRenderer(this);
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}

onDisable (): void {
Expand Down Expand Up @@ -212,7 +212,7 @@ export class UIMeshRenderer extends Component {
public update (): void {
if (JSB) {
if (this._modelComponent) {
this.markForUpdateRenderData();
this._markForUpdateRenderData();
}
}
this._fitUIRenderQueue();
Expand Down Expand Up @@ -246,6 +246,17 @@ export class UIMeshRenderer extends Component {
*/
// interface
public markForUpdateRenderData (enable = true): void {
this._markForUpdateRenderData(enable);
}

/**
* An internal method that marks the render data of the current component as modified so that the render data is recalculated.
* Adding this method is to minify the function name by `@mangle` since this method is frequently used in the engine.
* To keep the compatibility, the original method is still kept.
* @engineInternal
* @mangle
*/
public _markForUpdateRenderData (enable = true): void {
uiRendererManager.markDirtyRenderer(this);
}

Expand Down
Loading