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

Chore: Cleanup useContextAlpha deprecation #8866

Merged
merged 3 commits into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/app/src/Application.ts
Expand Up @@ -70,9 +70,7 @@ export class Application<VIEW extends ICanvas = ICanvas>
* @param {number} [options.width=800] - The width of the renderers view.
* @param {number} [options.height=600] - The height of the renderers view.
* @param {PIXI.ICanvas} [options.view] - The canvas to use as a view, optional.
* @param {boolean} [options.useContextAlpha=true] - Pass-through value for canvas' context `alpha` property.
* If you want to set transparency, please use `backgroundAlpha`. This option is for cases where the
* canvas needs to be opaque, possibly for performance reasons on some older devices.
* @param {boolean} [options.premultipliedAlpha=true] - Set to `false` to disable premultipliedAlpha.
* @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
* resolutions other than 1.
* @param {boolean} [options.antialias=false] - Sets antialias
Expand Down
11 changes: 8 additions & 3 deletions packages/canvas-renderer/src/CanvasRenderer.ts
Expand Up @@ -164,9 +164,6 @@ export class CanvasRenderer extends SystemManager<CanvasRenderer> implements IRe
* @param {number} [options.width=800] - the width of the screen
* @param {number} [options.height=600] - the height of the screen
* @param {PIXI.ICanvas} [options.view] - the canvas to use as a view, optional
* @param {boolean} [options.useContextAlpha=true] - Pass-through value for canvas' context `alpha` property.
* If you want to set transparency, please use `backgroundAlpha`. This option is for cases where the
* canvas needs to be opaque, possibly for performance reasons on some older devices.
* @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
* resolutions other than 1
* @param {boolean} [options.antialias=false] - sets antialias
Expand Down Expand Up @@ -215,6 +212,14 @@ export class CanvasRenderer extends SystemManager<CanvasRenderer> implements IRe

this.setup(systemConfig);

if ('useContextAlpha' in options)
{
// #if _DEBUG
deprecation('7.0.0', 'options.useContextAlpha is deprecated, use options.backgroundAlpha instead');
// #endif
options.backgroundAlpha = options.useContextAlpha === false ? 1 : options.backgroundAlpha;
}

// convert our big blob of options into system specific ones..
const startupOptions: StartupOptions = {
hello: options.hello,
Expand Down
21 changes: 14 additions & 7 deletions packages/core/src/Renderer.ts
Expand Up @@ -286,9 +286,7 @@ export class Renderer extends SystemManager<Renderer> implements IRenderer
* @param {number} [options.width=800] - The width of the screen.
* @param {number} [options.height=600] - The height of the screen.
* @param {PIXI.ICanvas} [options.view] - The canvas to use as a view, optional.
* @param {boolean} [options.useContextAlpha=true] - Pass-through value for canvas' context `alpha` property.
* If you want to set transparency, please use `backgroundAlpha`. This option is for cases where the
* canvas needs to be opaque, possibly for performance reasons on some older devices.
* @param {boolean} [options.premultipliedAlpha=true] - Set to `false` to disable premultipliedAlpha.
* @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
* resolutions other than 1.
* @param {boolean} [options.antialias=false] - Sets antialias. If not available natively then FXAA
Expand Down Expand Up @@ -368,6 +366,16 @@ export class Renderer extends SystemManager<Renderer> implements IRenderer

this.setup(systemConfig);

if ('useContextAlpha' in options)
{
// #if _DEBUG
// eslint-disable-next-line max-len
deprecation('7.0.0', 'options.useContextAlpha is deprecated, use options.premultipliedAlpha and options.backgroundAlpha instead');
// #endif
options.premultipliedAlpha = options.useContextAlpha && options.useContextAlpha !== 'notMultiplied';
options.backgroundAlpha = options.useContextAlpha === false ? 1 : options.backgroundAlpha;
}

// new options!
const startupOptions: StartupOptions = {
hello: options.hello,
Expand All @@ -388,8 +396,7 @@ export class Renderer extends SystemManager<Renderer> implements IRenderer
antialias: options.antialias,
context: options.context,
powerPreference: options.powerPreference,
premultipliedAlpha: options.premultipliedAlpha
?? (options.useContextAlpha && options.useContextAlpha !== 'notMultiplied'),
premultipliedAlpha: options.premultipliedAlpha,
preserveDrawingBuffer: options.preserveDrawingBuffer,
},
};
Expand Down Expand Up @@ -547,7 +554,7 @@ export class Renderer extends SystemManager<Renderer> implements IRenderer
{
// #if _DEBUG
// eslint-disable-next-line max-len
deprecation('7.0.0', 'renderer.useContextAlpha has been deprecated, please use renderer.background.clearBeforeRender instead.');
deprecation('7.0.0', 'renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead.');
// #endif

return this.background.clearBeforeRender;
Expand All @@ -563,7 +570,7 @@ export class Renderer extends SystemManager<Renderer> implements IRenderer
{
// #if _DEBUG
// eslint-disable-next-line max-len
deprecation('7.0.0', 'Renderer#useContextAlpha has been deprecated, please use Renderer#context.premultipliedAlpha instead.');
deprecation('7.0.0', 'renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead.');
// #endif

return this.context.useContextAlpha;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/context/ContextSystem.ts
Expand Up @@ -134,7 +134,7 @@ export class ContextSystem implements ISystem<ContextOptions>
else
{
const alpha = this.renderer.background.alpha < 1;
const premultipliedAlpha = options.premultipliedAlpha ?? true;
const premultipliedAlpha = options.premultipliedAlpha;

this.preserveDrawingBuffer = options.preserveDrawingBuffer;
this.useContextAlpha = options.useContextAlpha;
Expand Down
8 changes: 5 additions & 3 deletions packages/settings/src/settings.ts
Expand Up @@ -16,7 +16,9 @@ export interface IRenderOptions
backgroundColor: number | string;
background?: number | string;
backgroundAlpha: number;
useContextAlpha: boolean | 'notMultiplied';
premultipliedAlpha: boolean;
/** @deprecated */
useContextAlpha?: boolean | 'notMultiplied';
clearBeforeRender: boolean;
preserveDrawingBuffer: boolean;
width: number;
Expand Down Expand Up @@ -169,7 +171,7 @@ export const settings: ISettings = {
* @property {PIXI.ICanvas} [view=null] -
* @property {boolean} [antialias=false] -
* @property {boolean} [autoDensity=false] -
* @property {boolean} [useContextAlpha=true] -
* @property {boolean} [premultipliedAlpha=true] -
* @property {number} [backgroundColor=0x000000] -
* @property {number} [backgroundAlpha=1] -
* @property {boolean} [clearBeforeRender=true] -
Expand All @@ -185,7 +187,7 @@ export const settings: ISettings = {
autoDensity: false,
backgroundColor: 0x000000,
backgroundAlpha: 1,
useContextAlpha: true,
premultipliedAlpha: true,
clearBeforeRender: true,
preserveDrawingBuffer: false,
width: 800,
Expand Down