Skip to content

Commit

Permalink
chore: config
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Mar 30, 2024
1 parent af1c3dd commit d642fa7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/refresh/CanvasCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CanvasCache {
this.dx = dx;
this.dy = dy;
this.list = [];
const UNIT = config.canvasSize;
const UNIT = config.MAX_TEXTURE_SIZE;
for (let i = 0, len = Math.ceil(h / UNIT); i < len; i++) {
for (let j = 0, len2 = Math.ceil(w / UNIT); j < len2; j++) {
const width = j === len2 - 1 ? (w - j * UNIT) : UNIT;
Expand Down
14 changes: 6 additions & 8 deletions src/refresh/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import { Struct } from './struct';
import TextureCache from './TextureCache';
import CanvasCache from './CanvasCache';

export const DELTA_TIME = 16;

export type Merge = {
i: number;
lv: number;
Expand Down Expand Up @@ -271,7 +269,7 @@ export function genMerge(
if ((!visible || opacity <= 0) && !maskMode) {
continue;
}
if (!firstMerge && (Date.now() - startTime) > DELTA_TIME) {
if (!firstMerge && (Date.now() - startTime) > config.deltaTime) {
breakMerge = mergeList.slice(j);
break;
}
Expand Down Expand Up @@ -521,7 +519,7 @@ function genTotal(
const res = TextureCache.getEmptyInstance(gl, bbox);
const list = res.list;
let frameBuffer: WebGLFramebuffer | undefined;
const UNIT = config.canvasSize;
const UNIT = config.MAX_TEXTURE_SIZE;
const listRect: { x: number, y: number }[] = [];
// 要先按整数创建纹理块,再反向计算bbox(真实尺寸/scale),创建完再重新遍历按节点顺序渲染,因为有bgBlur存在
for (let i = 0, len = Math.ceil(h2 / UNIT); i < len; i++) {
Expand Down Expand Up @@ -865,7 +863,7 @@ function drawInSpreadBbox(
x: number, y: number, scale: number,
w2: number, h2: number,
) {
const UNIT = config.canvasSize;
const UNIT = config.MAX_TEXTURE_SIZE;
const listS = textureTarget.list;
const listT = temp.list;
let frameBuffer: WebGLFramebuffer | undefined;
Expand Down Expand Up @@ -949,7 +947,7 @@ function createInOverlay(
scale: number,
spread: number, // 不考虑scale
) {
const UNIT = config.canvasSize;
const UNIT = config.MAX_TEXTURE_SIZE;
const unit = UNIT - spread * scale * 2; // 去除spread的单位
const listO: {
bbox: Float64Array,
Expand Down Expand Up @@ -1730,7 +1728,7 @@ function genShadow(
// 先生成最终的尺寸结果,空白即可,后面的shadow依次绘入,最上层是图像本身
const res2 = TextureCache.getEmptyInstance(gl, bboxR2);
const listR2 = res2.list;
const UNIT = config.canvasSize;
const UNIT = config.MAX_TEXTURE_SIZE;
for (let i = 0, len = Math.ceil(h2 / UNIT); i < len; i++) {
for (let j = 0, len2 = Math.ceil(w2 / UNIT); j < len2; j++) {
const width = j === len2 - 1 ? (w2 - j * UNIT) : UNIT;
Expand Down Expand Up @@ -2015,7 +2013,7 @@ function genMask(
const summary = TextureCache.getEmptyInstance(gl, bbox);
const listS = summary.list;
let frameBuffer: WebGLFramebuffer | undefined;
const UNIT = config.canvasSize;
const UNIT = config.MAX_TEXTURE_SIZE;
const m = identity();
assignMatrix(m, matrix);
multiplyScale(m, 1 / scale);
Expand Down
3 changes: 1 addition & 2 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ export default {
debug: false,
offscreenCanvas: false,
tile: false,
canvasSize: 8192,
deltaTime: 16,
MAX_TEXTURE_SIZE: 8192,
MAX_TEXTURE_UNITS: 8,
MAX_VARYING_VECTORS: 15,
init(maxSize: number, maxUnits: number, maxVectors: number) {
this.MAX_TEXTURE_SIZE = maxSize;
this.MAX_TEXTURE_UNITS = maxUnits;
this.MAX_VARYING_VECTORS = maxVectors;
this.canvasSize = maxSize;
},
};

0 comments on commit d642fa7

Please sign in to comment.