From 458d111917e520ac944f6541169990db164f6ccb Mon Sep 17 00:00:00 2001 From: linghaoSu Date: Tue, 22 Feb 2022 00:15:04 +0800 Subject: [PATCH 1/2] fix text dirty rect considered when text in host --- src/canvas/Layer.ts | 4 ++-- src/canvas/graphic.ts | 2 +- src/graphic/Displayable.ts | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/canvas/Layer.ts b/src/canvas/Layer.ts index 100ea80b9..ed6dbb162 100644 --- a/src/canvas/Layer.ts +++ b/src/canvas/Layer.ts @@ -269,7 +269,7 @@ export default class Layer extends Eventful { * if it's currently on the canvas and needs repaint this frame * or not painted this frame. */ - const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true); + const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true, true); const prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint) ? el.getPrevPaintRect() : null; @@ -311,7 +311,7 @@ export default class Layer extends Eventful { * rect if and only if it's not painted this frame and was * previously painted on the canvas. */ - const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true); + const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true, true); if (el && (!shouldPaint || !el.__zr) && el.__isRendered) { // el was removed const prevRect = el.getPrevPaintRect(); diff --git a/src/canvas/graphic.ts b/src/canvas/graphic.ts index fb3a145eb..c65c77dad 100644 --- a/src/canvas/graphic.ts +++ b/src/canvas/graphic.ts @@ -615,7 +615,7 @@ export function brush( ) { const m = el.transform; - if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) { + if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false, false)) { // Needs to mark el rendered. // Or this element will always been rendered in progressive rendering. // But other dirty bit should not be cleared, otherwise it cause the shape diff --git a/src/graphic/Displayable.ts b/src/graphic/Displayable.ts index 20223e889..c613a48b3 100644 --- a/src/graphic/Displayable.ts +++ b/src/graphic/Displayable.ts @@ -195,7 +195,8 @@ class Displayable extends Ele viewWidth: number, viewHeight: number, considerClipPath: boolean, - considerAncestors: boolean + considerAncestors: boolean, + considerHostTarget: boolean ) { const m = this.transform; if ( @@ -234,6 +235,23 @@ class Displayable extends Ele } } + // consider host target + if ( + considerAncestors + && considerHostTarget + && this.parent + && this.parent.__hostTarget + ) { + let hostTarget = this.parent.__hostTarget; + let parent = hostTarget; + while (parent) { + if (parent.ignore) { + return false; + } + parent = parent.parent; + } + } + return true; } From 5963bfa91d66177161c0e4c9bb2fb97bb1935a1f Mon Sep 17 00:00:00 2001 From: linghaoSu Date: Mon, 28 Feb 2022 22:19:40 +0800 Subject: [PATCH 2/2] treat host target as special parent --- src/canvas/Layer.ts | 4 ++-- src/canvas/graphic.ts | 2 +- src/graphic/Displayable.ts | 30 ++++++------------------------ 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/canvas/Layer.ts b/src/canvas/Layer.ts index ed6dbb162..100ea80b9 100644 --- a/src/canvas/Layer.ts +++ b/src/canvas/Layer.ts @@ -269,7 +269,7 @@ export default class Layer extends Eventful { * if it's currently on the canvas and needs repaint this frame * or not painted this frame. */ - const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true, true); + const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true); const prevRect = el.__isRendered && ((el.__dirty & REDRAW_BIT) || !shouldPaint) ? el.getPrevPaintRect() : null; @@ -311,7 +311,7 @@ export default class Layer extends Eventful { * rect if and only if it's not painted this frame and was * previously painted on the canvas. */ - const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true, true); + const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true); if (el && (!shouldPaint || !el.__zr) && el.__isRendered) { // el was removed const prevRect = el.getPrevPaintRect(); diff --git a/src/canvas/graphic.ts b/src/canvas/graphic.ts index c65c77dad..fb3a145eb 100644 --- a/src/canvas/graphic.ts +++ b/src/canvas/graphic.ts @@ -615,7 +615,7 @@ export function brush( ) { const m = el.transform; - if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false, false)) { + if (!el.shouldBePainted(scope.viewWidth, scope.viewHeight, false, false)) { // Needs to mark el rendered. // Or this element will always been rendered in progressive rendering. // But other dirty bit should not be cleared, otherwise it cause the shape diff --git a/src/graphic/Displayable.ts b/src/graphic/Displayable.ts index c613a48b3..b6990e4ee 100644 --- a/src/graphic/Displayable.ts +++ b/src/graphic/Displayable.ts @@ -195,8 +195,7 @@ class Displayable extends Ele viewWidth: number, viewHeight: number, considerClipPath: boolean, - considerAncestors: boolean, - considerHostTarget: boolean + considerAncestors: boolean ) { const m = this.transform; if ( @@ -225,30 +224,13 @@ class Displayable extends Ele } } - if (considerAncestors && this.parent) { - let parent = this.parent; - while (parent) { - if (parent.ignore) { + if (considerAncestors) { + let node: Element = this; + while (node) { + if (node.ignore) { return false; } - parent = parent.parent; - } - } - - // consider host target - if ( - considerAncestors - && considerHostTarget - && this.parent - && this.parent.__hostTarget - ) { - let hostTarget = this.parent.__hostTarget; - let parent = hostTarget; - while (parent) { - if (parent.ignore) { - return false; - } - parent = parent.parent; + node = node.parent || node.__hostTarget; } }