Skip to content
Merged

Release #2115

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
12 changes: 12 additions & 0 deletions packages/g-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @antv/g-canvas

## 2.2.0

### Minor Changes

- 00d08e9: refactor: remove legacy code

### Patch Changes

- Updated dependencies [00d08e9]
- Updated dependencies [8df267d]
- @antv/g-lite@2.7.0

## 2.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "2.1.0",
"version": "2.2.0",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import type {
DisplayObject,
FederatedEvent,
RBushNodeAABB,
RenderingPlugin,
RBush,
RenderingPluginContext,
ContextService,
CanvasContext,
GlobalRuntime,
ParsedBaseStyleProps,
CSSRGB,
} from '@antv/g-lite';
import {
AABB,
CanvasEvent,
CustomEvent,
ElementEvent,
Shape,
Node,
} from '@antv/g-lite';
import { AABB, CanvasEvent, CustomEvent, Shape, Node } from '@antv/g-lite';
import { mat4, vec3 } from 'gl-matrix';
import { isNil } from '@antv/util';
import type { CanvasRendererPluginOptions } from './interfaces';
Expand Down Expand Up @@ -49,17 +39,10 @@ export class CanvasRendererPlugin implements RenderingPlugin {

private pathGeneratorFactory: Plugin['context']['pathGeneratorFactory'];

/**
* RBush used in dirty rectangle rendering
*/
private rBush: RBush<RBushNodeAABB>;

constructor(
private canvasRendererPluginOptions: CanvasRendererPluginOptions, // private styleRendererFactory: Record<Shape, StyleRenderer>,
) {}

private removedRBushNodeAABBs: RBushNodeAABB[] = [];

private renderQueue: DisplayObject[] = [];

#renderState: RenderState = {
Expand Down Expand Up @@ -90,7 +73,6 @@ export class CanvasRendererPlugin implements RenderingPlugin {
camera,
renderingService,
renderingContext,
rBushRoot,
// @ts-ignore
pathGeneratorFactory,
} = this.context;
Expand All @@ -100,42 +82,14 @@ export class CanvasRendererPlugin implements RenderingPlugin {
config.renderer.getConfig().enableDirtyCheck = false;
config.renderer.getConfig().enableDirtyRectangleRendering = false;

this.rBush = rBushRoot;
this.pathGeneratorFactory = pathGeneratorFactory;

const contextService =
context.contextService as ContextService<CanvasRenderingContext2D>;

const canvas = renderingContext.root.ownerDocument.defaultView;

const handleUnmounted = (e: FederatedEvent) => {
const object = e.target as DisplayObject;

// remove r-bush node
// @ts-ignore
const { rBushNode } = object;

if (rBushNode?.aabb) {
// save removed aabbs for dirty-rectangle rendering later
this.removedRBushNodeAABBs.push(rBushNode.aabb);
}
};

const handleCulled = (e: FederatedEvent) => {
const object = e.target as DisplayObject;
// @ts-ignore
const { rBushNode } = object;

if (rBushNode.aabb) {
// save removed aabbs for dirty-rectangle rendering later
this.removedRBushNodeAABBs.push(rBushNode.aabb);
}
};

renderingService.hooks.init.tap(CanvasRendererPlugin.tag, () => {
canvas.addEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
canvas.addEventListener(ElementEvent.CULLED, handleCulled);

// clear fullscreen
const dpr = contextService.getDPR();
const { width, height } = config;
Expand All @@ -151,10 +105,7 @@ export class CanvasRendererPlugin implements RenderingPlugin {
});

renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, () => {
canvas.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
canvas.removeEventListener(ElementEvent.CULLED, handleCulled);
this.renderQueue = [];
this.removedRBushNodeAABBs = [];
this.#renderState = {
restoreStack: [],
prevObject: null,
Expand Down Expand Up @@ -286,25 +237,12 @@ export class CanvasRendererPlugin implements RenderingPlugin {
renderByZIndex(renderingContext.root, context);
}
// console.timeEnd('renderByZIndex');

this.removedRBushNodeAABBs = [];
} else {
// console.log('canvas renderer next...', this.renderQueue);
// merge removed AABB
const dirtyRenderBounds = this.safeMergeAABB(
this.mergeDirtyAABBs(this.renderQueue),
...this.removedRBushNodeAABBs.map(({ minX, minY, maxX, maxY }) => {
const aabb = new AABB();
aabb.setMinMax(
// vec3.fromValues(minX, minY, 0),
// vec3.fromValues(maxX, maxY, 0),
[minX, minY, 0],
[maxX, maxY, 0],
);
return aabb;
}),
);
this.removedRBushNodeAABBs = [];

if (AABB.isEmpty(dirtyRenderBounds)) {
this.renderQueue = [];
Expand Down Expand Up @@ -374,7 +312,15 @@ export class CanvasRendererPlugin implements RenderingPlugin {
}

// search objects intersect with dirty rectangle
const dirtyObjects = this.searchDirtyObjects(dirtyRenderBounds);
const [minX, minY] = dirtyRenderBounds.getMin();
const [maxX, maxY] = dirtyRenderBounds.getMax();
const dirtyObjects =
renderingContext.root.ownerDocument.elementsFromBBox(
minX,
minY,
maxX,
maxY,
);

// do rendering
dirtyObjects
Expand Down Expand Up @@ -712,20 +658,6 @@ export class CanvasRendererPlugin implements RenderingPlugin {
return aabb;
}

private searchDirtyObjects(dirtyRectangle: AABB): DisplayObject[] {
// search in r-tree, get all affected nodes
const [minX, minY] = dirtyRectangle.getMin();
const [maxX, maxY] = dirtyRectangle.getMax();
const rBushNodes = this.rBush.search({
minX,
minY,
maxX,
maxY,
});

return rBushNodes.map(({ displayObject }) => displayObject);
}

private saveDirtyAABB(object: DisplayObject) {
const { renderable } = object;
if (!renderable.dirtyRenderBounds) {
Expand Down
9 changes: 9 additions & 0 deletions packages/g-canvaskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @antv/g-canvaskit

## 1.1.1

### Patch Changes

- Updated dependencies [00d08e9]
- Updated dependencies [8df267d]
- @antv/g-canvas@2.2.0
- @antv/g-lite@2.7.0

## 1.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvaskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvaskit",
"version": "1.1.0",
"version": "1.1.1",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-lite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-lite

## 2.7.0

### Minor Changes

- 00d08e9: refactor: remove legacy code
- 8df267d: feat: add experimental api `setAttributes`

## 2.6.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lite",
"version": "2.6.0",
"version": "2.7.0",
"description": "A core module for rendering engine implements DOM API.",
"keywords": [
"antv",
Expand Down
23 changes: 0 additions & 23 deletions packages/g-lite/src/components/RBushNode.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/g-lite/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './Cullable';
export * from './Geometry';
export * from './RBushNode';
export * from './Renderable';
export * from './Sortable';
export * from './Transform';
4 changes: 4 additions & 0 deletions packages/g-lite/src/css/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export interface PropertyParseOptions {
forceUpdateGeometry: boolean;
usedAttributes: string[];
memoize: boolean;
/**
* @experimental
*/
skipDispatchAttrModifiedEvent?: boolean;
}

export interface StyleValueRegistry {
Expand Down
48 changes: 48 additions & 0 deletions packages/g-lite/src/display-objects/DisplayObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,43 @@ export class DisplayObject<
}
}

/**
* batch update attributes without attributeChangedCallback, for performance
* use with caution
* @param attributes
* @param parseOptions
* @experimental
*/
setAttributes(
attributes: Partial<StyleProps>,
parseOptions: Partial<PropertyParseOptions> = {},
) {
const { skipDispatchAttrModifiedEvent = false } = parseOptions;
let oldAttributes;
let oldParsedValues;
if (!skipDispatchAttrModifiedEvent) {
oldAttributes = { ...this.attributes };
oldParsedValues = { ...this.parsedStyle };
}
runtime.styleValueRegistry.processProperties(
this as unknown as DisplayObject,
attributes,
parseOptions,
);
// redraw at next frame
this.dirty();
if (!skipDispatchAttrModifiedEvent) {
for (const key in attributes) {
this.dispatchAttrModifiedEvent(
key,
oldAttributes[key],
attributes[key],
oldParsedValues[key as string],
);
}
}
}

/**
* called when attributes get changed or initialized
*/
Expand All @@ -297,6 +334,17 @@ export class DisplayObject<
// redraw at next frame
this.dirty();

// return;

this.dispatchAttrModifiedEvent(name, oldValue, value, oldParsedValue);
}

private dispatchAttrModifiedEvent<Key extends keyof StyleProps>(
name: Key,
oldValue: StyleProps[Key],
value: StyleProps[Key],
oldParsedValue: ParsedStyleProps[keyof ParsedStyleProps],
) {
const newParsedValue = this.parsedStyle[name as string];
if (this.isConnected) {
attrModifiedEvent.relatedNode = this as IElement;
Expand Down
9 changes: 0 additions & 9 deletions packages/g-lite/src/dom/Element.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
Cullable,
Geometry,
RBushNode,
Renderable,
Sortable,
Transform,
Expand Down Expand Up @@ -139,14 +138,6 @@ export class Element<
dirtyReason: undefined,
};

/**
* @deprecated Legacy property for RBush spatial indexing.
* Will be removed in future versions.
*/
rBushNode: RBushNode = {
aabb: undefined,
};

/**
* used with `getElementById()`
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id
Expand Down
8 changes: 8 additions & 0 deletions packages/g-lottie-player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @antv/g-lottie-player

## 1.1.1

### Patch Changes

- Updated dependencies [00d08e9]
- Updated dependencies [8df267d]
- @antv/g-lite@2.7.0

## 1.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lottie-player/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lottie-player",
"version": "1.1.0",
"version": "1.1.1",
"description": "A lottie player for G",
"keywords": [
"antv",
Expand Down
Loading
Loading