Skip to content

Commit

Permalink
test: try to fix scaling cachecanvas
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Apr 1, 2024
1 parent 373d409 commit ab01a1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
32 changes: 22 additions & 10 deletions packages/engine-render/src/components/sheets/spreadsheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,14 @@ export class Spreadsheet extends SheetComponent {
};
}


isForceDirty(): boolean {
return this._forceDirty;
}

makeForceDirty(state = true) {
this.makeDirty(state);
console.log('!!!_forceDirty', state);
this._forceDirty = state;
}

Expand Down Expand Up @@ -321,18 +327,18 @@ export class Spreadsheet extends SheetComponent {

const dh = bottom - top + columnHeaderHeight;

if (diffBounds.length === 0 || (diffX === 0 && diffY === 0) || this._forceDirty) {
if (this.isDirty() || this._forceDirty) {
if (diffBounds.length === 0 || (diffX === 0 && diffY === 0) || this.isForceDirty()) {
if (this.isDirty() || this.isForceDirty()) {
this._cacheCanvas.clear();
cacheCtx.setTransform(mainCtx.getTransform());
this._draw(cacheCtx, bounds);
this._forceDirty = false;
// this._forceDirty = false;
}
this._applyCache(mainCtx, left, top, dw, dh, left, top, dw, dh);
} else {
// 一直 true 的话,会有残影出现
// if (this.isViewPortDirty(viewPortKey)) {
if (this.isDirty()) {
if (this.isViewPortDirty(viewPortKey)) {
console.time('viewMainscroll');

cacheCtx.save();
Expand Down Expand Up @@ -388,18 +394,20 @@ export class Spreadsheet extends SheetComponent {
const dw = right - left + rowHeaderWidth;
const dh = bottom - top + columnHeaderHeight;

if (diffBounds.length === 0 || (diffX === 0 && diffY === 0) || this._forceDirty) {
console.time('viewMainTop_clear');
if (this.isViewPortDirty(viewPortKey) || this._forceDirty) {
if (diffBounds.length === 0 || (diffX === 0 && diffY === 0) || this.isForceDirty()) {
console.time('!!!viewMainTop_clear');
// if (this.isViewPortDirty(viewPortKey) || this.isForceDirty()) {
if (this.isDirty() || this._forceDirty) {
this._cacheCanvasTop.clear();
cacheCtxTop.setTransform(mainCtx.getTransform());
this._draw(cacheCtxTop, bounds);

this._forceDirty = false;
}
this._applyCacheFreeze(mainCtx, this._cacheCanvasTop, left, top, dw, dh, left, top, dw, dh);
console.timeEnd('viewMainTop_clear');
console.timeEnd('!!!viewMainTop_clear');
} else {
if (this.isDirty()) {
if (this.isViewPortDirty(viewPortKey)) {
console.time('viewMainTop_diff')
cacheCtxTop.save();
cacheCtxTop.setTransform(1, 0, 0, 1, 0, 0);
Expand Down Expand Up @@ -594,10 +602,14 @@ export class Spreadsheet extends SheetComponent {

private _addMakeDirtyToScroll() {
this._hasScrollViewportOperator(this, (viewport: Viewport) => {
// 只有 viewMain 才会进入这里
console.log('!!!!!_addMakeDirtyToScroll', viewport.viewPortKey);
viewport.onScrollBeforeObserver.add((eventData) => {
// this.makeDirty(true);
// eventData.viewport
this.markViewPortDirty(false, eventData.viewport?.viewPortKey);
console.log('!!_hasScrollViewportOperator', eventData.viewport?.viewPortKey);
// this.markViewPortDirty(true, eventData.viewport?.viewPortKey);
this.markViewPortDirty(true);
});
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/engine-render/src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export class Layer extends Disposable {

private _draw(mainCtx: UniverRenderingContext, isMaxLayer: boolean) {
this._scene.getViewports()?.forEach((vp) => vp.render(mainCtx, this.getObjectsByOrder(), isMaxLayer));
console.log('!!!layer_forcedirty')
this.getObjectsByOrder().forEach( o => {
o.makeDirty?.(false);
})
}

private _applyCache(ctx?: UniverRenderingContext) {
Expand Down

0 comments on commit ab01a1a

Please sign in to comment.