Support transparent window in Views framework (follow up issue #2315)

#267 Open
Repository
trendmicro-consumer
Branch
transparent
Repository
chromiumembedded
Branch
master

Bitbucket cannot automatically merge this request.

The commits that make up this pull request have been removed.

Bitbucket cannot automatically merge this request due to conflicts.

Review the conflicts on the Overview tab. You can then either decline the request or merge it manually on your local system using the following commands:

git checkout master
git remote add trendmicro-consumer/cef https://bitbucket.org/trendmicro-consumer/cef.git
git fetch trendmicro-consumer/cef
git merge --no-ff -m 'Merged in trendmicro-consumer/cef/transparent (pull request #267)' remotes/trendmicro-consumer/cef/transparent
Author
  1. Andy Tzeng
Reviewers
Description

Hi Team,

What I need is very similar to the issue #2315. I would like to provide my changes for the case.

First of all, the requirement I have is to create a non-rectangular window. One solution is implementing OSR to have parent window with transparent background. Another solution is creating a translucent window via Views frameworks, which is what this PR did.

The major changes are:

  1. Configure opacity to views::Widget::InitParams::TRANSLUCENT_WINDOW while initializing the Widget controlled by CefWindowDelegate::IsTranslucent()
  2. Set the background color of CefWindow to transparent if above is configured
  3. Configure CefSettings.transparent_painting to true. It controls accepting alpha component while configuring the background in CefContext::GetBackgroundColor(). It is required for deciding the default background of WebView in renderer.

CefSettings.windowless_rendering_enabled is renamed to CefSettings.transparent_painting because I consider the flag only controlling the background color calculation logic.

I created a testing page using the Views framework as below:

The page can be launched by

cefclient --use-views --transparent-painting-enabled --hide-frame --hide-controls

Thank you for any feedback/comments in advance.

Comments (9)

  1. Alex Maitland

    CefSettings.windowless_rendering_enabled is renamed to CefSettings.transparent_painting because I consider the flag only controlling the background color calculation logic.

    This is incorrect, there are cases where windowless_rendering_enabled is required to apply specific command line arguments, like recently it was used to specifically disable the Viz Compositor.This property should remain untouched in my opinion

    1. Andy Tzeng author

      I saw there are two windowless_rendering_enabled. One is in CefWindowInfo, it almost controls everything regarding OSR. Another one is in CefSettings, which appears in CefBrowserHost (for configure checking) and CefContext (for color calculation)

      That’s why I have this idea. Not sure whether anything I missing and misunderstanding.

  2. Czarek Tomczak

    PR #136 enables transparency in windowed mode. Does this PR allow transparency in windowed mode as well, or only in off-screen rendering mode with the use of Views framework?

    1. Andy Tzeng author

      This PR targets transparent window opened by CefWindow in Views framework (called it views mode in the following). It is not work for either windowed mode or off-screen rendering mode. The transparent effect is configured by the ui::views::Widget init parameter which provided by Views framework. Therefore, the scoped limits to views mode only.

      By the way, I've reviewed the change in PR #136. The changes look like targeting CefWindow of Views framework as well. I don't think it can work as expected in windowed mode.

    1. Andy Tzeng author

      Windows only

      I have Mac environment, but Views framework is not work in Mac OS. Hence, I did not test it. Sorry that I haven’t tested it on Linux because my major working system is Mac OS and Windows. I will try Linux later once I get the Linux environment ready.

    2. Benjamín de la Fuente Ranea

      I’ve tested this modifications both in Windows and Linux and they really work. I think this is a very efficient way to have a transparent HTML overlay, better than using off-screen rendering mode for simple cases.

      1. Benjamín de la Fuente Ranea

        I’ve found that in Linux you have to use the command line flag --use-gl=desktop to enable transparency. This is true since CEF version 4183 and applies to CEF 4240. It seems to be related to this chromium issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1122224#c14

        Furthermore, in CEF 4183 linux transparency is not working because chromium has rewrite X11 using the underlying xcb layer and some code needed for transparency were dropped (ej. colormaps for XCreateWindow). But this is already fixed and in CEF 4240 this is working again with no problem.