Skip to main content
Version: Phaser v4.0.0-rc.6

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:

  1. A spare DrawingContext that has the same dimensions.

  2. A spare DrawingContext that has not been used recently, resized.

  3. A new DrawingContext, within the maximum pool size.

  4. The oldest spare DrawingContext, resized.

  5. 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

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe 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:

nametypeoptionaldescription
drawingContextPhaser.Renderer.WebGL.DrawingContextNoThe 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:

nametypeoptionaldescription
widthnumberYesThe width of the DrawingContext.
heightnumberYesThe 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:

nametypeoptionaldescription
maxAgenumberNoThe 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:

nametypeoptionaldescription
maxPoolSizenumberNoThe maximum number of DrawingContexts to store.

Source: src/renderer/webgl/DrawingContextPool.js#L236
Since: 4.0.0