@leafer/renderer 1.5.3 → 1.6.0
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 +33 -29
- package/types/index.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/renderer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
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.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
28
|
+
"@leafer/interface": "1.6.0"
|
|
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,13 @@ 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
|
+
if (this.changed && this.canvas.view) this.render()
|
|
68
|
+
this.target.emit(RenderEvent.NEXT)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
63
72
|
public render(callback?: IFunction): void {
|
|
64
73
|
if (!(this.running && this.canvas.view)) return this.update()
|
|
65
74
|
|
|
@@ -70,7 +79,6 @@ export class Renderer implements IRenderer {
|
|
|
70
79
|
debug.log(target.innerName, '--->')
|
|
71
80
|
|
|
72
81
|
try {
|
|
73
|
-
if (!target.isApp) target.app.emit(RenderEvent.CHILD_START, target)
|
|
74
82
|
this.emitRender(RenderEvent.START)
|
|
75
83
|
this.renderOnce(callback)
|
|
76
84
|
this.emitRender(RenderEvent.END, this.totalBounds)
|
|
@@ -146,23 +154,15 @@ export class Renderer implements IRenderer {
|
|
|
146
154
|
|
|
147
155
|
public clipRender(block: IBounds): void {
|
|
148
156
|
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)
|
|
157
|
+
const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds)
|
|
154
158
|
|
|
155
159
|
canvas.save()
|
|
156
160
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
bounds.spread(10 + 1 / this.canvas.pixelRatio).ceil()
|
|
161
|
-
canvas.clearWorld(bounds, true)
|
|
162
|
-
canvas.clipWorld(bounds, true)
|
|
163
|
-
}
|
|
161
|
+
bounds.spread(Renderer.clipSpread).ceil()
|
|
162
|
+
canvas.clearWorld(bounds, true)
|
|
163
|
+
canvas.clipWorld(bounds, true)
|
|
164
164
|
|
|
165
|
-
this.__render(bounds, includes, realBounds)
|
|
165
|
+
this.__render(bounds, block.includes(this.target.__world), realBounds)
|
|
166
166
|
canvas.restore()
|
|
167
167
|
|
|
168
168
|
Run.end(t)
|
|
@@ -181,26 +181,20 @@ export class Renderer implements IRenderer {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
protected __render(bounds: IBounds, includes?: boolean, realBounds?: IBounds,): void {
|
|
184
|
-
const options: IRenderOptions =
|
|
184
|
+
const { canvas } = this, options: IRenderOptions = includes ? { includes } : { bounds, includes }
|
|
185
185
|
|
|
186
|
-
if (this.needFill)
|
|
187
|
-
if (Debug.showRepaint)
|
|
186
|
+
if (this.needFill) canvas.fillWorld(bounds, this.config.fill)
|
|
187
|
+
if (Debug.showRepaint) Debug.drawRepaint(canvas, bounds)
|
|
188
188
|
|
|
189
|
-
this.target.__render(
|
|
189
|
+
this.target.__render(canvas, options)
|
|
190
190
|
|
|
191
191
|
this.renderBounds = realBounds = realBounds || bounds
|
|
192
192
|
this.renderOptions = options
|
|
193
193
|
this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds)
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
if (Debug.showBoundsView) this.renderBoundsView(options)
|
|
197
|
-
this.canvas.updateRender(realBounds)
|
|
195
|
+
canvas.updateRender(realBounds)
|
|
198
196
|
}
|
|
199
197
|
|
|
200
|
-
public renderHitView(_options: IRenderOptions): void { }
|
|
201
|
-
|
|
202
|
-
public renderBoundsView(_options: IRenderOptions): void { }
|
|
203
|
-
|
|
204
198
|
public addBlock(block: IBounds): void {
|
|
205
199
|
if (!this.updateBlocks) this.updateBlocks = []
|
|
206
200
|
this.updateBlocks.push(block)
|
|
@@ -217,17 +211,27 @@ export class Renderer implements IRenderer {
|
|
|
217
211
|
}
|
|
218
212
|
|
|
219
213
|
protected __requestRender(): void {
|
|
214
|
+
const target = this.target as ILeaferBase
|
|
215
|
+
if (target.parentApp) return target.parentApp.renderer.update(false) // App 模式下统一走 app 控制渲染帧
|
|
220
216
|
if (this.requestTime) return
|
|
221
217
|
|
|
222
218
|
const requestTime = this.requestTime = Date.now()
|
|
223
219
|
Platform.requestRender(() => {
|
|
220
|
+
|
|
224
221
|
this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)))
|
|
225
222
|
this.requestTime = 0
|
|
226
223
|
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
|
|
224
|
+
if (target.isApp) {
|
|
225
|
+
target.emit(RenderEvent.CHILD_START, target);
|
|
226
|
+
(target.children as ILeaferBase[]).forEach(leafer => {
|
|
227
|
+
leafer.renderer.FPS = this.FPS
|
|
228
|
+
leafer.renderer.checkRender()
|
|
229
|
+
})
|
|
230
|
+
target.emit(RenderEvent.CHILD_END, target)
|
|
230
231
|
}
|
|
232
|
+
|
|
233
|
+
this.checkRender()
|
|
234
|
+
|
|
231
235
|
})
|
|
232
236
|
}
|
|
233
237
|
|
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,6 +26,7 @@ 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;
|
|
@@ -32,8 +34,6 @@ declare class Renderer implements IRenderer {
|
|
|
32
34
|
clipRender(block: IBounds): void;
|
|
33
35
|
fullRender(): void;
|
|
34
36
|
protected __render(bounds: IBounds, includes?: boolean, realBounds?: IBounds): void;
|
|
35
|
-
renderHitView(_options: IRenderOptions): void;
|
|
36
|
-
renderBoundsView(_options: IRenderOptions): void;
|
|
37
37
|
addBlock(block: IBounds): void;
|
|
38
38
|
mergeBlocks(): void;
|
|
39
39
|
protected __requestRender(): void;
|