@leafer/renderer 1.5.3 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/Renderer.ts +38 -33
- package/types/index.d.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/renderer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "@leafer/renderer",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.
|
|
25
|
+
"@leafer/core": "1.6.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
28
|
+
"@leafer/interface": "1.6.1"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/Renderer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILeaf, ILeaferCanvas, IRenderer, IRendererConfig, IEventListenerId, IBounds, IFunction, IRenderOptions } from '@leafer/interface'
|
|
1
|
+
import { ILeaf, ILeaferBase, ILeaferCanvas, IRenderer, IRendererConfig, IEventListenerId, IBounds, IFunction, IRenderOptions } from '@leafer/interface'
|
|
2
2
|
import { LayoutEvent, RenderEvent, ResizeEvent, ImageManager, Bounds, DataHelper, Platform, Debug, Run } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
|
|
@@ -26,6 +26,8 @@ export class Renderer implements IRenderer {
|
|
|
26
26
|
maxFPS: 60
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
static clipSpread = 10
|
|
30
|
+
|
|
29
31
|
protected renderBounds: IBounds
|
|
30
32
|
protected renderOptions: IRenderOptions
|
|
31
33
|
protected totalBounds: IBounds
|
|
@@ -60,6 +62,23 @@ export class Renderer implements IRenderer {
|
|
|
60
62
|
this.target.emit(LayoutEvent.REQUEST)
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
public checkRender(): void {
|
|
66
|
+
if (this.running) {
|
|
67
|
+
const { target } = this
|
|
68
|
+
if (target.isApp) {
|
|
69
|
+
target.emit(RenderEvent.CHILD_START, target);
|
|
70
|
+
(target.children as ILeaferBase[]).forEach(leafer => {
|
|
71
|
+
leafer.renderer.FPS = this.FPS
|
|
72
|
+
leafer.renderer.checkRender()
|
|
73
|
+
})
|
|
74
|
+
target.emit(RenderEvent.CHILD_END, target)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (this.changed && this.canvas.view) this.render()
|
|
78
|
+
this.target.emit(RenderEvent.NEXT)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
63
82
|
public render(callback?: IFunction): void {
|
|
64
83
|
if (!(this.running && this.canvas.view)) return this.update()
|
|
65
84
|
|
|
@@ -70,7 +89,6 @@ export class Renderer implements IRenderer {
|
|
|
70
89
|
debug.log(target.innerName, '--->')
|
|
71
90
|
|
|
72
91
|
try {
|
|
73
|
-
if (!target.isApp) target.app.emit(RenderEvent.CHILD_START, target)
|
|
74
92
|
this.emitRender(RenderEvent.START)
|
|
75
93
|
this.renderOnce(callback)
|
|
76
94
|
this.emitRender(RenderEvent.END, this.totalBounds)
|
|
@@ -146,23 +164,15 @@ export class Renderer implements IRenderer {
|
|
|
146
164
|
|
|
147
165
|
public clipRender(block: IBounds): void {
|
|
148
166
|
const t = Run.start('PartRender')
|
|
149
|
-
const { canvas } = this
|
|
150
|
-
|
|
151
|
-
const bounds = block.getIntersect(canvas.bounds)
|
|
152
|
-
const includes = block.includes(this.target.__world)
|
|
153
|
-
const realBounds = new Bounds(bounds)
|
|
167
|
+
const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds)
|
|
154
168
|
|
|
155
169
|
canvas.save()
|
|
156
170
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil()
|
|
161
|
-
canvas.clearWorld(bounds, true)
|
|
162
|
-
canvas.clipWorld(bounds, true)
|
|
163
|
-
}
|
|
171
|
+
bounds.spread(Renderer.clipSpread).ceil()
|
|
172
|
+
canvas.clearWorld(bounds, true)
|
|
173
|
+
canvas.clipWorld(bounds, true)
|
|
164
174
|
|
|
165
|
-
this.__render(bounds,
|
|
175
|
+
this.__render(bounds, realBounds)
|
|
166
176
|
canvas.restore()
|
|
167
177
|
|
|
168
178
|
Run.end(t)
|
|
@@ -174,33 +184,27 @@ export class Renderer implements IRenderer {
|
|
|
174
184
|
|
|
175
185
|
canvas.save()
|
|
176
186
|
canvas.clear()
|
|
177
|
-
this.__render(canvas.bounds
|
|
187
|
+
this.__render(canvas.bounds)
|
|
178
188
|
canvas.restore()
|
|
179
189
|
|
|
180
190
|
Run.end(t)
|
|
181
191
|
}
|
|
182
192
|
|
|
183
|
-
protected __render(bounds: IBounds,
|
|
184
|
-
const
|
|
193
|
+
protected __render(bounds: IBounds, realBounds?: IBounds): void {
|
|
194
|
+
const { canvas } = this, includes = bounds.includes(this.target.__world), options: IRenderOptions = includes ? { includes } : { bounds, includes }
|
|
185
195
|
|
|
186
|
-
if (this.needFill)
|
|
187
|
-
if (Debug.showRepaint)
|
|
196
|
+
if (this.needFill) canvas.fillWorld(bounds, this.config.fill)
|
|
197
|
+
if (Debug.showRepaint) Debug.drawRepaint(canvas, bounds)
|
|
188
198
|
|
|
189
|
-
this.target.__render(
|
|
199
|
+
this.target.__render(canvas, options)
|
|
190
200
|
|
|
191
201
|
this.renderBounds = realBounds = realBounds || bounds
|
|
192
202
|
this.renderOptions = options
|
|
193
203
|
this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds)
|
|
194
204
|
|
|
195
|
-
|
|
196
|
-
if (Debug.showBoundsView) this.renderBoundsView(options)
|
|
197
|
-
this.canvas.updateRender(realBounds)
|
|
205
|
+
canvas.updateRender(realBounds)
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
public renderHitView(_options: IRenderOptions): void { }
|
|
201
|
-
|
|
202
|
-
public renderBoundsView(_options: IRenderOptions): void { }
|
|
203
|
-
|
|
204
208
|
public addBlock(block: IBounds): void {
|
|
205
209
|
if (!this.updateBlocks) this.updateBlocks = []
|
|
206
210
|
this.updateBlocks.push(block)
|
|
@@ -217,17 +221,18 @@ export class Renderer implements IRenderer {
|
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
protected __requestRender(): void {
|
|
220
|
-
|
|
224
|
+
const target = this.target as ILeaferBase
|
|
225
|
+
if (this.requestTime || !target) return
|
|
226
|
+
if (target.parentApp) return target.parentApp.requestRender(false) // App 模式下统一走 app 控制渲染帧
|
|
221
227
|
|
|
222
228
|
const requestTime = this.requestTime = Date.now()
|
|
223
229
|
Platform.requestRender(() => {
|
|
230
|
+
|
|
224
231
|
this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)))
|
|
225
232
|
this.requestTime = 0
|
|
226
233
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this.target.emit(RenderEvent.NEXT)
|
|
230
|
-
}
|
|
234
|
+
this.checkRender()
|
|
235
|
+
|
|
231
236
|
})
|
|
232
237
|
}
|
|
233
238
|
|
package/types/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare class Renderer implements IRenderer {
|
|
|
14
14
|
changed: boolean;
|
|
15
15
|
ignore: boolean;
|
|
16
16
|
config: IRendererConfig;
|
|
17
|
+
static clipSpread: number;
|
|
17
18
|
protected renderBounds: IBounds;
|
|
18
19
|
protected renderOptions: IRenderOptions;
|
|
19
20
|
protected totalBounds: IBounds;
|
|
@@ -25,15 +26,14 @@ declare class Renderer implements IRenderer {
|
|
|
25
26
|
stop(): void;
|
|
26
27
|
update(change?: boolean): void;
|
|
27
28
|
requestLayout(): void;
|
|
29
|
+
checkRender(): void;
|
|
28
30
|
render(callback?: IFunction): void;
|
|
29
31
|
renderAgain(): void;
|
|
30
32
|
renderOnce(callback?: IFunction): void;
|
|
31
33
|
partRender(): void;
|
|
32
34
|
clipRender(block: IBounds): void;
|
|
33
35
|
fullRender(): void;
|
|
34
|
-
protected __render(bounds: IBounds,
|
|
35
|
-
renderHitView(_options: IRenderOptions): void;
|
|
36
|
-
renderBoundsView(_options: IRenderOptions): void;
|
|
36
|
+
protected __render(bounds: IBounds, realBounds?: IBounds): void;
|
|
37
37
|
addBlock(block: IBounds): void;
|
|
38
38
|
mergeBlocks(): void;
|
|
39
39
|
protected __requestRender(): void;
|