import '../../../globals.js';
// Copyright 2020-2024, University of Colorado Boulder
/**
 * Base type for filters
 *
 * Filters have different ways of being applied, depending on what the platform supports AND what content is below.
 * These different ways have potentially different performance characteristics, and potentially quality differences.
 *
 * The current ways are:
 * - DOM element with CSS filter specified (can include mixed content and WebGL underneath, and this is used as a
 *   general fallback). NOTE: General color matrix support is NOT provided under this, we only have specific named
 *   filters that can be used.
 * - SVG filter elements (which are very flexible, a combination of filters may be combined into SVG filter elements).
 *   This only works if ALL of the content under the filter(s) can be placed in one SVG element, so a layerSplit or
 *   non-SVG content can prevent this from being used.
 * - Canvas filter attribute (similar to DOM CSS). Similar to DOM CSS, but not as accelerated (requires applying the
 *   filter by drawing into another Canvas). Chromium-based browsers seem to have issues with the color space used,
 *   so this can't be used on that platform. Additionally, this only works if ALL the content under the filter(s) can
 *   be placed in one Canvas, so a layerSplit or non-SVG content can prevent this from being used.
 * - Canvas ImageData. This is a fallback where we directly get, manipulate, and set pixel data in a Canvas (with the
 *   corresponding performance hit that it takes to CPU-process every pixel). Additionally, this only works if ALL the
 *   content under the filter(s) can   be placed in one Canvas, so a layerSplit or non-SVG content can prevent this from
 *   being used.
 *
 * Some filters may have slightly different appearances depending on the browser/platform/renderer.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import { Features, scenery, svgns } from '../imports.js';
let globalId = 1;
export default class Filter {
    constructor() {
        this.id = `filter${globalId++}`;
        this.filterRegionPercentageIncrease = 0;
    }
    isDOMCompatible() {
        // TODO: We can browser-check on things like color matrix? But we want to disallow things that we can't guarantee we https://github.com/phetsims/scenery/issues/1581
        // can support?
        return false;
    }
    isSVGCompatible() {
        return false;
    }
    isCanvasCompatible() {
        return Features.canvasFilter ? this.isDOMCompatible() : false;
    }
    isWebGLCompatible() {
        return false;
    }
    /**
     * Returns a string form of this object
     */
    toString() {
        return this.id;
    }
    /**
     * Applies a color matrix effect into an existing SVG filter.
     */
    static applyColorMatrix(matrixValues, svgFilter, inName, resultName) {
        const feColorMatrix = document.createElementNS(svgns, 'feColorMatrix');
        feColorMatrix.setAttribute('type', 'matrix');
        feColorMatrix.setAttribute('values', matrixValues);
        feColorMatrix.setAttribute('in', inName);
        // Since the DOM effects are done with sRGB and we can't manipulate that, we'll instead adjust SVG to apply the
        // effects in sRGB so that we have consistency
        feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB');
        if (resultName) {
            feColorMatrix.setAttribute('result', resultName);
        }
        svgFilter.appendChild(feColorMatrix);
    }
}
scenery.register('Filter', Filter);
//# sourceMappingURL=Filter.js.map