Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Prepare, Extract to Systems #8427

Merged
merged 4 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/canvas-extract/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare namespace GlobalMixins
{
interface CanvasRenderer
{
readonly extract: import('@pixi/canvas-extract').CanvasExtract;
}
}
8 changes: 4 additions & 4 deletions packages/canvas-extract/src/CanvasExtract.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ExtensionMetadata, ExtensionType, RenderTexture } from '@pixi/core';
import { ExtensionType, RenderTexture } from '@pixi/core';
import { CanvasRenderTarget } from '@pixi/utils';
import { Rectangle } from '@pixi/math';
import { CanvasRenderer } from '@pixi/canvas-renderer';
import type { DisplayObject } from '@pixi/display';
import type { BaseRenderTexture } from '@pixi/core';
import type { BaseRenderTexture, ISystem, ExtensionMetadata } from '@pixi/core';

const TEMP_RECT = new Rectangle();

Expand All @@ -14,12 +14,12 @@ const TEMP_RECT = new Rectangle();
* @class
* @memberof PIXI
*/
export class CanvasExtract
export class CanvasExtract implements ISystem
{
/** @ignore */
static extension: ExtensionMetadata = {
name: 'extract',
type: ExtensionType.CanvasRendererPlugin,
type: ExtensionType.CanvasRendererSystem,
};

/** A reference to the current renderer */
Expand Down
8 changes: 4 additions & 4 deletions packages/canvas-extract/test/CanvasExtract.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('CanvasExtract', () =>
{
const renderer = new CanvasRenderer();

expect(renderer.plugins.extract).toBeInstanceOf(CanvasExtract);
expect(renderer.extract).toBeInstanceOf(CanvasExtract);

renderer.destroy();
});
Expand All @@ -27,7 +27,7 @@ describe('CanvasExtract', () =>
{
const renderer = new CanvasRenderer();
const sprite = new Sprite(Texture.WHITE);
const extract = renderer.plugins.extract as CanvasExtract;
const extract = renderer.extract as CanvasExtract;

expect(extract.canvas(sprite)).toBeInstanceOf(HTMLCanvasElement);
expect(extract.base64(sprite)).toBeString();
Expand All @@ -41,7 +41,7 @@ describe('CanvasExtract', () =>
it('should extract with no arguments', () =>
{
const renderer = new CanvasRenderer();
const extract = renderer.plugins.extract as CanvasExtract;
const extract = renderer.extract as CanvasExtract;

expect(extract.canvas()).toBeInstanceOf(HTMLCanvasElement);
expect(extract.base64()).toBeString();
Expand All @@ -54,7 +54,7 @@ describe('CanvasExtract', () =>
it('should extract a render texture', () =>
{
const renderer = new CanvasRenderer();
const extract = renderer.plugins.extract as CanvasExtract;
const extract = renderer.extract as CanvasExtract;
const renderTexture = RenderTexture.create({ width: 10, height: 10 });
const sprite = new Sprite(Texture.WHITE);

Expand Down
7 changes: 7 additions & 0 deletions packages/canvas-prepare/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare namespace GlobalMixins
{
interface CanvasRenderer
{
readonly prepare: import('@pixi/canvas-prepare').CanvasPrepare;
}
}
7 changes: 4 additions & 3 deletions packages/canvas-prepare/src/CanvasPrepare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseTexture, IRenderer, ExtensionMetadata, ExtensionType } from '@pixi/core';
import { BaseTexture, ExtensionType } from '@pixi/core';
import { BasePrepare } from '@pixi/prepare';

import type { ISystem, ExtensionMetadata, IRenderer } from '@pixi/core';
import type { CanvasRenderer } from '@pixi/canvas-renderer';
import type { IDisplayObjectExtended } from '@pixi/prepare';

Expand Down Expand Up @@ -52,12 +53,12 @@ function uploadBaseTextures(prepare: IRenderer | BasePrepare, item: IDisplayObje
* @extends PIXI.BasePrepare
* @memberof PIXI
*/
export class CanvasPrepare extends BasePrepare
export class CanvasPrepare extends BasePrepare implements ISystem
{
/** @ignore */
static extension: ExtensionMetadata = {
name: 'prepare',
type: ExtensionType.CanvasRendererPlugin,
type: ExtensionType.CanvasRendererSystem,
};

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/canvas-renderer/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ declare namespace GlobalMixins
{
forceCanvas?: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface CanvasRenderer
{

}
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
13 changes: 5 additions & 8 deletions packages/canvas-renderer/src/CanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Matrix, Rectangle } from '@pixi/math';
import type { DisplayObject } from '@pixi/display';
import type {
IRendererOptions,
IRendererPlugin,
IRendererPlugins,
IRendererRenderOptions
} from '@pixi/core';
Expand All @@ -28,10 +27,8 @@ import { CanvasObjectRendererSystem } from './CanvasObjectRendererSystem';
import { settings } from '@pixi/settings';
import { deprecation } from '@pixi/utils';

export interface ICanvasRendererPluginConstructor
{
new (renderer: CanvasRenderer, options?: any): IRendererPlugin;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CanvasRenderer extends GlobalMixins.CanvasRenderer {}

/**
* The CanvasRenderer draws the scene and all its content onto a 2d canvas.
Expand All @@ -56,11 +53,13 @@ export interface ICanvasRendererPluginConstructor
* | {@link PIXI.EventSystem} | This manages UI events. |
* | {@link PIXI.GenerateTextureSystem} | This adds the ability to generate textures from any PIXI.DisplayObject |
*
* | Pixi high level Systems | Set of Pixi specific systems designed to work with Pixi objects |
* | PixiJS High-Level Systems | Set of specific systems designed to work with PixiJS objects |
* | ------------------------------------ | ----------------------------------------------------------------------------- |
* | {@link PIXI.CanvasContextSystem} | This manages the canvas `2d` contexts and their state |
* | {@link PIXI.CanvasMaskSystem} | This manages masking operations. |
* | {@link PIXI.CanvasRenderSystem} | This adds the ability to render a PIXI.DisplayObject |
* | {@link PIXI.CanvasExtract} | This extracts image data from a PIXI.DisplayObject |
* | {@link PIXI.CanvasPrepare} | This prepares a PIXI.DisplayObject async for rendering |
*
* The breadth of the API surface provided by the renderer is contained within these systems.
* @class
Expand Down Expand Up @@ -559,9 +558,7 @@ export class CanvasRenderer extends SystemManager<CanvasRenderer> implements IRe
* @member {object} plugins
* @readonly
* @property {PIXI.AccessibilityManager} accessibility Support tabbing interactive elements.
* @property {PIXI.CanvasExtract} extract Extract image data from renderer.
* @property {PIXI.InteractionManager} interaction Handles mouse, touch and pointer events.
* @property {PIXI.CanvasPrepare} prepare Pre-render display objects.
*/
}

Expand Down
12 changes: 12 additions & 0 deletions packages/core/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ declare namespace GlobalMixins
{

}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Renderer
{

}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface IRendererPlugins
{

}
}
9 changes: 7 additions & 2 deletions packages/core/src/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import { SystemManager } from './system/SystemManager';
import { IRenderableObject, IRenderer, IRendererOptions, IRendererRenderOptions, IRenderingContext } from './IRenderer';
import { StartupOptions, StartupSystem } from './startup/StartupSystem';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Renderer extends GlobalMixins.Renderer {}

/**
* The Renderer draws the scene and all its content onto a WebGL enabled canvas.
*
Expand Down Expand Up @@ -63,9 +66,9 @@ import { StartupOptions, StartupSystem } from './startup/StartupSystem';
* | {@link PIXI.TextureGCSystem} | This will automatically remove textures from the GPU if they are not used. |
* | {@link PIXI.MultisampleSystem} | This manages the multisample const on the WEbGL Renderer |
*
* | Pixi high level Systems | Set of Pixi specific systems designed to work with Pixi objects |
* | PixiJS High-Level Systems | Set of specific systems designed to work with PixiJS objects |
* | ------------------------------------ | ----------------------------------------------------------------------------- |
* | {@link PIXI.RenderSystem} | This adds the ability to render a PIXI.DisplayObject |
* | {@link PIXI.RenderSystem} | This adds the ability to render a PIXI.DisplayObject |
* | {@link PIXI.GenerateTextureSystem} | This adds the ability to generate textures from any PIXI.DisplayObject |
* | {@link PIXI.ProjectionSystem} | This manages the `projectionMatrix`, used by shaders to get NDC coordinates. |
* | {@link PIXI.RenderTextureSystem} | This manages render-textures, which are an abstraction over framebuffers. |
Expand All @@ -74,6 +77,8 @@ import { StartupOptions, StartupSystem } from './startup/StartupSystem';
* | {@link PIXI.StencilSystem} | This handles stencil masking, and is used internally by {@link MaskSystem} |
* | {@link PIXI.FilterSystem} | This manages the filtering pipeline for post-processing effects. |
* | {@link PIXI.BatchSystem} | This manages object renderers that defer rendering until a flush. |
* | {@link PIXI.Prepare} | This manages uploading assets to the GPU. |
* | {@link PIXI.Extract} | This extracts image data from display objects. |
*
* The breadth of the API surface provided by the renderer is contained within these systems.
* @memberof PIXI
Expand Down
Empty file.
37 changes: 25 additions & 12 deletions packages/core/src/plugin/PluginSystem.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import { deprecation } from '@pixi/utils';
import { ExtensionMetadata, ExtensionType } from '../extensions';
import { IRenderer } from '../IRenderer';
import { Renderer } from '../Renderer';
import { ISystem } from '../system/ISystem';

export interface IRendererPlugin
{
destroy(): void;
}

export interface IRendererPlugins
export interface IRendererPlugins extends GlobalMixins.IRendererPlugins
{
[key: string]: any;
}

export interface IRendererPluginConstructor<R extends IRenderer = Renderer>
{
new (renderer: R, options?: any): IRendererPlugin;
}

/**
* Manages the functionality that allows users to extend pixi functionality via additional plugins.
* @memberof PIXI
Expand Down Expand Up @@ -51,6 +41,29 @@ export class PluginSystem implements ISystem
* @member {object}
*/
this.plugins = {};

// #if _DEBUG
Object.defineProperties(this.plugins, {
extract: {
enumerable: false,
get()
{
deprecation('7.0.0', 'renderer.plugins.extract has moved to renderer.extract');

return (renderer as any).extract;
},
},
prepare: {
enumerable: false,
get()
{
deprecation('7.0.0', 'renderer.plugins.prepare has moved to renderer.prepare');

return (renderer as any).prepare;
},
},
});
// #endif
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/extract/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare namespace GlobalMixins
{
interface Renderer
{
readonly extract: import('@pixi/extract').Extract;
}
}
8 changes: 4 additions & 4 deletions packages/extract/src/Extract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CanvasRenderTarget } from '@pixi/utils';
import { Rectangle } from '@pixi/math';
import { ExtensionMetadata, ExtensionType, RenderTexture } from '@pixi/core';
import { ExtensionType, RenderTexture } from '@pixi/core';

import type { Renderer, IRendererPlugin } from '@pixi/core';
import type { Renderer, ISystem, ExtensionMetadata } from '@pixi/core';
import { DisplayObject } from '@pixi/display';

const TEMP_RECT = new Rectangle();
Expand All @@ -29,12 +29,12 @@ const BYTES_PER_PIXEL = 4;
* @memberof PIXI
*/

export class Extract implements IRendererPlugin
export class Extract implements ISystem
{
/** @ignore */
static extension: ExtensionMetadata = {
name: 'extract',
type: ExtensionType.RendererPlugin,
type: ExtensionType.RendererSystem,
};

private renderer: Renderer;
Expand Down
7 changes: 4 additions & 3 deletions packages/extract/test/Extract.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Extract', () =>
const renderer = new Renderer();

expect(renderer.plugins.extract).toBeInstanceOf(Extract);
expect(renderer.extract).toBeInstanceOf(Extract);

renderer.destroy();
});
Expand All @@ -25,7 +26,7 @@ describe('Extract', () =>
{
const renderer = new Renderer();
const sprite = new Sprite(Texture.WHITE);
const extract = renderer.plugins.extract as Extract;
const extract = renderer.extract as Extract;
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved

expect(extract.canvas(sprite)).toBeInstanceOf(HTMLCanvasElement);
expect(extract.base64(sprite)).toBeString();
Expand All @@ -39,7 +40,7 @@ describe('Extract', () =>
it('should extract with no arguments', () =>
{
const renderer = new Renderer();
const extract = renderer.plugins.extract as Extract;
const extract = renderer.extract as Extract;
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved

expect(extract.canvas(undefined)).toBeInstanceOf(HTMLCanvasElement);
expect(extract.base64(undefined)).toBeString();
Expand All @@ -52,7 +53,7 @@ describe('Extract', () =>
it('should extract a render texture', () =>
{
const renderer = new Renderer();
const extract = renderer.plugins.extract as Extract;
const extract = renderer.extract as Extract;
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved
const renderTexture = RenderTexture.create({ width: 10, height: 10 });
const sprite = new Sprite(Texture.WHITE);
const frame = new Rectangle(1, 2, 5, 6);
Expand Down
7 changes: 7 additions & 0 deletions packages/prepare/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare namespace GlobalMixins
{
interface Renderer
{
readonly prepare: import('@pixi/prepare').Prepare;
}
}
8 changes: 4 additions & 4 deletions packages/prepare/src/Prepare.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseTexture, ExtensionMetadata, ExtensionType } from '@pixi/core';
import { BaseTexture, ExtensionType } from '@pixi/core';
import { Graphics } from '@pixi/graphics';
import { BasePrepare, IDisplayObjectExtended } from './BasePrepare';

import type { Renderer, IRenderer } from '@pixi/core';
import type { Renderer, IRenderer, ISystem, ExtensionMetadata } from '@pixi/core';

/**
* Built-in hook to upload PIXI.Texture objects to the GPU.
Expand Down Expand Up @@ -118,12 +118,12 @@ function findGraphics(item: IDisplayObjectExtended, queue: Array<any>): boolean
* });
* @memberof PIXI
*/
export class Prepare extends BasePrepare
export class Prepare extends BasePrepare implements ISystem
{
/** @ignore */
static extension: ExtensionMetadata = {
name: 'prepare',
type: ExtensionType.RendererPlugin,
type: ExtensionType.RendererSystem,
};

/**
Expand Down