From 2f23c0174d2a4ee9defcb9b22c84ac257685a350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Sat, 14 Jun 2025 06:10:23 +0300 Subject: [PATCH] Inline {enable,disable}ImageSmoothing usages The method isn't as complex as it used to be, and is only used in two places. It is simpler to have it inlined instead. --- src/js/core/buffer_utils.js | 24 ++---------------------- src/js/game/core.js | 14 +++----------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/js/core/buffer_utils.js b/src/js/core/buffer_utils.js index 86114744..c21108a5 100644 --- a/src/js/core/buffer_utils.js +++ b/src/js/core/buffer_utils.js @@ -4,23 +4,6 @@ import { fastArrayDelete } from "./utils"; const logger = createLogger("buffer_utils"); -/** - * Enables images smoothing on a context - * @param {CanvasRenderingContext2D} context - */ -export function enableImageSmoothing(context) { - context.imageSmoothingEnabled = true; - context.imageSmoothingQuality = globalConfig.smoothing.quality; -} - -/** - * Disables image smoothing on a context - * @param {CanvasRenderingContext2D} context - */ -export function disableImageSmoothing(context) { - context.imageSmoothingEnabled = false; -} - /** * @typedef {{ * canvas: HTMLCanvasElement, @@ -175,11 +158,8 @@ export function makeOffscreenBuffer(w, h, { smooth = true, reusable = true, labe // @ts-ignore canvas.label = label; - if (smooth) { - enableImageSmoothing(context); - } else { - disableImageSmoothing(context); - } + context.imageSmoothingEnabled = smooth; + context.imageSmoothingQuality = globalConfig.smoothing.quality; if (reusable) { registerCanvas(canvas, context); diff --git a/src/js/game/core.js b/src/js/game/core.js index eb4ec008..9147778f 100644 --- a/src/js/game/core.js +++ b/src/js/game/core.js @@ -2,12 +2,7 @@ import { Application } from "../application"; /* typehints:end */ import { BufferMaintainer } from "../core/buffer_maintainer"; -import { - disableImageSmoothing, - enableImageSmoothing, - getBufferStats, - registerCanvas, -} from "../core/buffer_utils"; +import { getBufferStats, registerCanvas } from "../core/buffer_utils"; import { globalConfig } from "../core/config"; import { getDeviceDPI, resizeHighDPICanvas } from "../core/dpi_manager"; import { DrawParameters } from "../core/draw_parameters"; @@ -244,11 +239,8 @@ export class GameCore { // Oof, use :not() instead canvas.classList.toggle("unsmoothed", !globalConfig.smoothing.smoothMainCanvas); - if (globalConfig.smoothing.smoothMainCanvas) { - enableImageSmoothing(context); - } else { - disableImageSmoothing(context); - } + context.imageSmoothingEnabled = globalConfig.smoothing.smoothMainCanvas; + context.imageSmoothingQuality = globalConfig.smoothing.quality; this.root.canvas = canvas; this.root.context = context;