"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.copyToCanvas = void 0;
var performance_1 = require("../../utils/performance");
/** @ignore */
var copyToCanvas = function (sourceCanvas, getDestinationById) { return function (destinationId) {
    doCopy(sourceCanvas, getDestinationById, destinationId);
}; };
exports.copyToCanvas = copyToCanvas;
var doCopy = function (sourceCanvas, getDestinationById, destinationId) {
    var _a;
    var mark = performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.CopyToCanvasStart, {
        parentContextId: destinationId,
        level: performance_1.EPerformanceDebugLevel.Verbose
    });
    var destination = getDestinationById(destinationId);
    var sciChartSurface = destination === null || destination === void 0 ? void 0 : destination.sciChartSurface;
    var destinationCanvas = destination === null || destination === void 0 ? void 0 : destination.sciChartSurface.domCanvas2D;
    if (destinationCanvas) {
        var destinationCanvasContext = destinationCanvas.getContext("2d");
        destinationCanvasContext.globalCompositeOperation = "copy";
        destinationCanvasContext.drawImage(sourceCanvas, 0, 0, destinationCanvas.width, destinationCanvas.height, 0, 0, destinationCanvas.width, destinationCanvas.height);
        performance_1.PerformanceDebugHelper.mark(performance_1.EPerformanceMarkType.CopyToCanvasEnd, {
            contextId: sciChartSurface.id,
            parentContextId: destinationId,
            relatedId: (_a = mark === null || mark === void 0 ? void 0 : mark.detail) === null || _a === void 0 ? void 0 : _a.relatedId,
            level: performance_1.EPerformanceDebugLevel.Verbose
        });
        var isInvalidated = sciChartSurface.isInvalidated;
        sciChartSurface.renderedToDestination.raiseEvent(isInvalidated);
    }
};
