ChromiumWebBrowser 在不禁用 WebGL 的情况下隐藏后闪黑

ChromiumWebBrowser flash black after hiding without disabling WebGL

我试图将我的 ChromiumWebBrowser 隐藏在图像、视频等后面...但每次它从 ChromiumWebBrowser 更改为空白面板或另一个 ChromiumWebBrowser 以外的任何其他内容时,它都会闪烁黑色几帧。

Exemple of my problem

硬件:

用于 Winform 程序的 CefSharp 版本 79.1.350

这是我尝试过的:

我也启用了Cef.EnableHighDPISupport();但没有成功。

到目前为止唯一有效的方法是添加 SetOffScreenRenderingBestPerformanceArgs();

但不幸的是,它禁用了 WebGL 实现 :/ 我想保留它以备后用。

static class Program
{
    /// <summary>
    /// Point d'entrée principal de l'application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Cef.EnableHighDPISupport();
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

 public partial class Form1 : Form
{

    private static ChromiumWebBrowser chrome;
    private PictureBox ImageBox = new PictureBox();

    private Panel pPictureBox = new Panel();
    private Panel pChromium = new Panel();
    Timer timer = new Timer();
    public Form1()
    {

        InitializeComponent();

        this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);

        ImageBox.Image = Properties.Resources._3080;
        ImageBox.SizeMode = PictureBoxSizeMode.StretchImage;
        pPictureBox.Controls.Add(ImageBox);
        ImageBox.Dock = DockStyle.Fill;

        pPictureBox.Dock = DockStyle.Fill;
        pPictureBox.Size = this.Size;
        this.Controls.Add(pPictureBox); 
        pPictureBox.BringToFront();

        InitializeChromium();

        timer.Interval = 7000;
        timer.Start();
        timer.Tick += Timer_Tick;
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
        if (pChromium.Visible)
        {
            pChromium.Hide();   
        }
        else
        {
            pChromium.Show();
        }
    }

    private void InitializeChromium()
    {


        pChromium.Dock = DockStyle.Fill;
        pChromium.Size = this.Size;
        CefSettings settings = new CefSettings();

        //Work but disable WebGL
        //settings.SetOffScreenRenderingBestPerformanceArgs();

        //settings.DisableGpuAcceleration();
        Cef.Initialize(settings);

        chrome = new ChromiumWebBrowser("https://www.apple.com/ca/airpods-pro/");

        pChromium.Controls.Add(chrome);
        this.Controls.Add(pChromium);

        chrome.Dock = DockStyle.Fill;

        pChromium.BringToFront();
    }

    private void InitializeComponent()
    {
        this.SuspendLayout();
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.Color.White;
        this.ClientSize = new System.Drawing.Size(1904, 1041);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);

    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        Cef.Shutdown();
    }
}

你们有什么解决办法吗?

这是我的最终代码,供任何感兴趣的人使用

@amaitland 推荐的命令链接

https://peter.sh/experiments/chromium-command-line-switches/#use-angle https://peter.sh/experiments/chromium-command-line-switches/#in-process-gpu

这两个命令单独工作

Cef.EnableHighDPISupport();不是必需的,但被推荐

static void Main()
    {
        Cef.EnableHighDPISupport();
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

public partial class Form1 : Form
{

    private static ChromiumWebBrowser chrome;
    private PictureBox ImageBox = new PictureBox();

    private Panel pPictureBox = new Panel();
    private Panel pChromium = new Panel();
    Timer timer = new Timer();
    public Form1()
    {

        InitializeComponent();

        this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);

        //any image here
        ImageBox.Image = Properties.Resources._3080;
        ImageBox.SizeMode = PictureBoxSizeMode.StretchImage;
        pPictureBox.Controls.Add(ImageBox);
        ImageBox.Dock = DockStyle.Fill;

        pPictureBox.Dock = DockStyle.Fill;
        pPictureBox.Size = this.Size;
        this.Controls.Add(pPictureBox);
        pPictureBox.BringToFront();

        InitializeChromium();

        timer.Interval = 7000;
        timer.Start();
        timer.Tick += Timer_Tick;
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
        if (pChromium.Visible)
        {
            pChromium.Hide();
        }
        else
        {
            pChromium.Show();
        }
    }

    private void InitializeChromium()
    {


        pChromium.Dock = DockStyle.Fill;
        pChromium.Size = this.Size;
        CefSettings settings = new CefSettings();


        //-------------------------------------------------------------------------

        settings.CefCommandLineArgs.Add("in-process-gpu");

        //got best FPS with this renderer on "my machine"
        settings.CefCommandLineArgs.Add("use-angle", "gl");

        //-------------------------------------------------------------------------

        //Work but disable WebGL
        //settings.SetOffScreenRenderingBestPerformanceArgs();
        //settings.DisableGpuAcceleration();
        Cef.Initialize(settings);

        chrome = new ChromiumWebBrowser("https://alteredqualia.com/three/examples/webgl_pasta.html");

        pChromium.Controls.Add(chrome);
        this.Controls.Add(pChromium);

        chrome.Dock = DockStyle.Fill;

        pChromium.BringToFront();
    }

    private void InitializeComponent()
    {
        this.SuspendLayout();
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.Color.White;
        this.ClientSize = new System.Drawing.Size(1904, 1041);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);

    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        Cef.Shutdown();
    }
}