DrawingContextPool
A pool of DrawingContexts.
This class is used internally by the WebGLRenderer to manage DrawingContexts.
It attempts to reuse DrawingContexts efficiently. When get is called,
it will return a DrawingContext of the given dimensions,
using the following priority:
-
A spare DrawingContext that has the same dimensions.
-
A spare DrawingContext that has not been used recently, resized.
-
A new DrawingContext, within the maximum pool size.
-
The oldest spare DrawingContext, resized.
-
A new DrawingContext, exceeding the maximum pool size.
We assume that DrawingContexts of a given size are likely to be reused
from frame to frame, so we try to preserve them for greater efficiency.
Constructor
new DrawingContextPool(renderer)
Parameters
| name | type | optional | description |
|---|---|---|---|
| renderer | Phaser.Renderer.WebGL.WebGLRenderer | No | The renderer that owns this DrawingContextPool. |
Scope: static
Source: src/renderer/webgl/DrawingContextPool.js#L10
Since: 4.0.0
Public Members
agePool
agePool: Array.<Phaser.Renderer.WebGL.DrawingContext>
Description:
The pool of DrawingContexts by age.
This is an array of DrawingContexts, oldest first.
Source: src/renderer/webgl/DrawingContextPool.js#L67
Since: 4.0.0
maxAge
maxAge: number
Description:
The maximum age of a DrawingContext in milliseconds.
After this time, the DrawingContext will be available for resizing.
Source: src/renderer/webgl/DrawingContextPool.js#L46
Since: 4.0.0
maxPoolSize
maxPoolSize: number
Description:
The maximum number of DrawingContexts to store.
This is not a hard limit, but the pool will attempt to
reuse DrawingContexts rather than create new ones.
Source: src/renderer/webgl/DrawingContextPool.js#L56
Since: 4.0.0
renderer
renderer: Phaser.Renderer.WebGL.WebGLRenderer
Description:
The renderer that owns this DrawingContextPool.
Source: src/renderer/webgl/DrawingContextPool.js#L37
Since: 4.0.0
sizePool
sizePool: object
Description:
The pool of DrawingContexts by size.
This is an object with keys of the form ${width}x${height}.
Each value is an array of DrawingContexts.
Source: src/renderer/webgl/DrawingContextPool.js#L77
Since: 4.0.0
Public Methods
add
<instance> add(drawingContext)
Description:
Adds a DrawingContext to the pool.
This is used by a DrawingContext to signal that it is available for reuse.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| drawingContext | Phaser.Renderer.WebGL.DrawingContext | No | The DrawingContext to add to the pool. |
Source: src/renderer/webgl/DrawingContextPool.js#L89
Since: 4.0.0
clear
<instance> clear()
Description:
Clears the DrawingContextPool. This will not destroy any DrawingContexts
that are currently in use.
Source: src/renderer/webgl/DrawingContextPool.js#L248
Since: 4.0.0
get
<instance> get([width], [height])
Description:
Returns a DrawingContext of the given dimensions.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| width | number | Yes | The width of the DrawingContext. |
| height | number | Yes | The height of the DrawingContext. |
Returns: Phaser.Renderer.WebGL.DrawingContext - The DrawingContext.
Source: src/renderer/webgl/DrawingContextPool.js#L118
Since: 4.0.0
prune
<instance> prune()
Description:
Prunes the DrawingContextPool down to the maximum pool size.
Oldest DrawingContexts will be destroyed first.
This will not destroy any DrawingContexts that are currently in use.
Source: src/renderer/webgl/DrawingContextPool.js#L266
Since: 4.0.0
setMaxAge
<instance> setMaxAge(maxAge)
Description:
Sets the maximum age of a DrawingContext in milliseconds.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| maxAge | number | No | The maximum age of a DrawingContext in milliseconds. |
Source: src/renderer/webgl/DrawingContextPool.js#L224
Since: 4.0.0
setMaxPoolSize
<instance> setMaxPoolSize(maxPoolSize)
Description:
Sets the maximum number of DrawingContexts to store.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| maxPoolSize | number | No | The maximum number of DrawingContexts to store. |
Source: src/renderer/webgl/DrawingContextPool.js#L236
Since: 4.0.0