ChromiumWebBrowser隐藏后未禁用WebGL时闪烁黑色

问题描述 投票:0回答:1

我试图将我的ChromiumWebBrowser隐藏在图像,视频等后面。但是,每次它从ChromiumWebBrowser变为空白面板或其他ChromiumWebBrowser之外的任何东西时,它都会闪烁黑色几帧。

Exemple of my problem

硬件:

  • i7-8559U
  • intel IRI plus图形655

Winform程序的CefSharp版本79.1.350

这是我尝试过的:

  • [BringToFront其他图片框
  • SendToback the ChromiumWebBrowser
  • 面板可见性
  • Panel doubleBuffed

我还启用了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();
    }
}

你们有什么解决办法吗?

winforms webgl cefsharp
1个回答
0
投票
这是我对任何感兴趣的人的最终代码

@ amaitland命令的命令链接

https://peter.sh/experiments/chromium-command-line-switches/#use-anglehttps://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(); } }

© www.soinside.com 2019 - 2024. All rights reserved.