import JionTool from "./JionTool";

export default class ShareCanvas {

    public constructor() {
        this.shareCanvas = Laya.Browser.window.sharedCanvas;
        this.sprite = new Laya.Sprite();
        this.sprite.zOrder = 1008;
        this.sprite.pos(0, 0);
        this.sprite.cacheAs = "normal";
        Laya.stage.addChild(this.sprite);
        this.t2d = new Laya.Texture2D();
        this.tex = new Laya.Texture(this.t2d);
    }
    private width: number = 0;
    private height: number = 0;
    private t2d: Laya.Texture2D;
    private tex: Laya.Texture;
    private sprite: Laya.Sprite;
    private shareCanvas: any;
    private ctx: any;
    public InitData(w: number = 720, h: number = 1559) {
        this.width = Laya.stage.width;
        this.height = Laya.stage.height;
        this.shareCanvas.width = w;
        this.shareCanvas.height = h;
    }

    public show() {
        Laya.timer.frameLoop(10, this, this.update);
        this.sprite.visible = true;
    }

    public hide() {
        Laya.timer.clear(this, this.update);
        this.sprite.visible = false;
    }

    public update() {
        this.drawWebgl();
       // JionTool.updateCtx();
    }

    private drawWebgl() {
        this.t2d.loadImageSource(this.shareCanvas);
        this.tex.setTo(this.t2d);
        // let te2d = new Laya.Texture2D();
        // te2d.loadImageSource(this.shareCanvas);
        // let texe = new Laya.Texture(te2d);
        this.sprite.graphics.clear();
        this.sprite.graphics.drawTexture(this.tex, 0, 0, this.tex.width, this.tex.height);
    }

    private draw2d() {
        this.ctx.drawImage(this.shareCanvas, 0, 0, this.shareCanvas.width, this.shareCanvas.height);
    }



}