mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
more performance fixes
This commit is contained in:
parent
4a776910ec
commit
d62645609d
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -261,7 +261,7 @@ export class Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_applyLineJoin(shape: Shape) {
|
_applyLineJoin(shape: Shape) {
|
||||||
var lineJoin = shape.lineJoin();
|
var lineJoin = shape.attrs.lineJoin;
|
||||||
if (lineJoin) {
|
if (lineJoin) {
|
||||||
this.setAttr('lineJoin', lineJoin);
|
this.setAttr('lineJoin', lineJoin);
|
||||||
}
|
}
|
||||||
|
20
src/Node.ts
20
src/Node.ts
@ -1732,7 +1732,13 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
if (transformsEnabled === 'all') {
|
if (transformsEnabled === 'all') {
|
||||||
at.multiply(this.getTransform());
|
at.multiply(this.getTransform());
|
||||||
} else if (transformsEnabled === 'position') {
|
} else if (transformsEnabled === 'position') {
|
||||||
at.translate(this.x() - this.offsetX(), this.y() - this.offsetY());
|
// use "attrs" directly, because it is a bit faster
|
||||||
|
const x = this.attrs.x || 0;
|
||||||
|
const y = this.attrs.y || 0;
|
||||||
|
const offsetX = this.attrs.offsetX || 0;
|
||||||
|
const offsetY = this.attrs.offsetY || 0;
|
||||||
|
|
||||||
|
at.translate(x - offsetX, y - offsetY);
|
||||||
}
|
}
|
||||||
at.dirty = false;
|
at.dirty = false;
|
||||||
return at;
|
return at;
|
||||||
@ -1808,12 +1814,12 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
var x = this.x(),
|
var x = this.x(),
|
||||||
y = this.y(),
|
y = this.y(),
|
||||||
rotation = Konva.getAngle(this.rotation()),
|
rotation = Konva.getAngle(this.rotation()),
|
||||||
scaleX = this.scaleX(),
|
scaleX = this.attrs.scaleX ?? 1,
|
||||||
scaleY = this.scaleY(),
|
scaleY = this.attrs.scaleY ?? 1,
|
||||||
skewX = this.skewX(),
|
skewX = this.attrs.skewX || 0,
|
||||||
skewY = this.skewY(),
|
skewY = this.attrs.skewY || 0,
|
||||||
offsetX = this.offsetX(),
|
offsetX = this.attrs.offsetX || 0,
|
||||||
offsetY = this.offsetY();
|
offsetY = this.attrs.offsetY || 0;
|
||||||
|
|
||||||
if (x !== 0 || y !== 0) {
|
if (x !== 0 || y !== 0) {
|
||||||
m.translate(x, y);
|
m.translate(x, y);
|
||||||
|
@ -463,7 +463,8 @@ export class Shape<Config extends ShapeConfig = ShapeConfig> extends Node<
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// force skip buffer canvas
|
// force skip buffer canvas
|
||||||
if (!this.perfectDrawEnabled()) {
|
const perfectDrawEnabled = this.attrs.perfectDrawEnabled ?? true;
|
||||||
|
if (!perfectDrawEnabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const hasFill = forceFill || this.hasFill();
|
const hasFill = forceFill || this.hasFill();
|
||||||
@ -579,9 +580,8 @@ export class Shape<Config extends ShapeConfig = ShapeConfig> extends Node<
|
|||||||
canvas = can || layer.getCanvas(),
|
canvas = can || layer.getCanvas(),
|
||||||
context = canvas.getContext() as SceneContext,
|
context = canvas.getContext() as SceneContext,
|
||||||
cachedCanvas = this._getCanvasCache(),
|
cachedCanvas = this._getCanvasCache(),
|
||||||
drawFunc = this.sceneFunc(),
|
drawFunc = this.getSceneFunc(),
|
||||||
hasShadow = this.hasShadow(),
|
hasShadow = this.hasShadow(),
|
||||||
hasStroke = this.hasStroke(),
|
|
||||||
stage,
|
stage,
|
||||||
bufferCanvas,
|
bufferCanvas,
|
||||||
bufferContext;
|
bufferContext;
|
||||||
|
@ -39,16 +39,16 @@ export class Image extends Shape<ImageConfig> {
|
|||||||
return super._useBufferCanvas(true);
|
return super._useBufferCanvas(true);
|
||||||
}
|
}
|
||||||
_sceneFunc(context) {
|
_sceneFunc(context) {
|
||||||
var width = this.width(),
|
var width = this.getWidth(),
|
||||||
height = this.height(),
|
height = this.getHeight(),
|
||||||
image = this.image(),
|
image = this.attrs.image,
|
||||||
cropWidth,
|
cropWidth,
|
||||||
cropHeight,
|
cropHeight,
|
||||||
params;
|
params;
|
||||||
|
|
||||||
if (image) {
|
if (image) {
|
||||||
cropWidth = this.cropWidth();
|
cropWidth = this.attrs.cropWidth;
|
||||||
cropHeight = this.cropHeight();
|
cropHeight = this.attrs.cropHeight;
|
||||||
if (cropWidth && cropHeight) {
|
if (cropWidth && cropHeight) {
|
||||||
params = [
|
params = [
|
||||||
image,
|
image,
|
||||||
@ -87,12 +87,10 @@ export class Image extends Shape<ImageConfig> {
|
|||||||
context.fillStrokeShape(this);
|
context.fillStrokeShape(this);
|
||||||
}
|
}
|
||||||
getWidth() {
|
getWidth() {
|
||||||
var image = this.image();
|
return this.attrs.width ?? (this.image()?.width || 0);
|
||||||
return this.attrs.width ?? (image ? image.width : 0);
|
|
||||||
}
|
}
|
||||||
getHeight() {
|
getHeight() {
|
||||||
var image = this.image();
|
return this.attrs.height ?? (this.image()?.height || 0);
|
||||||
return this.attrs.height ?? (image ? image.height : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,6 +93,8 @@
|
|||||||
x: 10,
|
x: 10,
|
||||||
y: 10,
|
y: 10,
|
||||||
perfectDrawEnabled: false,
|
perfectDrawEnabled: false,
|
||||||
|
width: wabbitTexture.width,
|
||||||
|
height: wabbitTexture.height,
|
||||||
});
|
});
|
||||||
|
|
||||||
bunny.speedX = Math.random() * 10;
|
bunny.speedX = Math.random() * 10;
|
||||||
@ -101,7 +103,22 @@
|
|||||||
bunnys.push(bunny);
|
bunnys.push(bunny);
|
||||||
layer.add(bunny);
|
layer.add(bunny);
|
||||||
}
|
}
|
||||||
layer.draw();
|
// layer.draw();
|
||||||
|
// console.clear();
|
||||||
|
// bunnys.forEach((b) => {
|
||||||
|
// b.position({
|
||||||
|
// x: Math.random() * window.innerWidth,
|
||||||
|
// y: Math.random() * window.innerHeight,
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// layer.draw();
|
||||||
|
// bunnys.forEach((b) => {
|
||||||
|
// b.position({
|
||||||
|
// x: Math.random() * window.innerWidth,
|
||||||
|
// y: Math.random() * window.innerHeight,
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
// layer.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTouchStart(event) {
|
function onTouchStart(event) {
|
||||||
@ -124,6 +141,8 @@
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
perfectDrawEnabled: false,
|
perfectDrawEnabled: false,
|
||||||
|
width: wabbitTexture.width,
|
||||||
|
height: wabbitTexture.height,
|
||||||
});
|
});
|
||||||
bunny.speedX = Math.random() * 10;
|
bunny.speedX = Math.random() * 10;
|
||||||
bunny.speedY = Math.random() * 10 - 5;
|
bunny.speedY = Math.random() * 10 - 5;
|
||||||
|
Loading…
Reference in New Issue
Block a user