Closed Bug 1479181 Opened 6 years ago Closed 6 years ago

OOP Webextension panels on Linux: white background instead of transparency

Categories

(Core :: Graphics: WebRender, defect)

63 Branch
x86_64
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla63
Tracking Status
firefox-esr52 --- unaffected
firefox-esr60 --- unaffected
firefox61 --- unaffected
firefox62 --- unaffected
firefox63 --- disabled

People

(Reporter: mstanke, Assigned: sotaro)

References

Details

(Keywords: nightly-community, regression)

Attachments

(4 files, 10 obsolete files)

32.92 KB, image/png
Details
17.75 KB, image/png
Details
2.73 KB, patch
nical
: review+
jgilbert
: review+
Details | Diff | Splinter Review
5.54 KB, patch
sotaro
: review+
Details | Diff | Splinter Review
      No description provided.
STR:
1) Install an add-on, that has a toolbar button with a popup, when you click on it.
2) Enable WebRender (gfx.webrender.all).
3) Restart FF.
4) Click the toolbar button.
5) A white are is shown around the opened popup. Note it happens only for add-on button, not for Firefox ones (like hamburger menu or Library).

Running mozregression now to find the cause.
Has STR: --- → yes
Component: General → Graphics: WebRender
OS: Unspecified → Linux
Product: Firefox → Core
Hardware: Unspecified → x86_64
Version: 60 Branch → 63 Branch
With mozregression I came to commits from bug 1357487 and bug 1464938, both from :kmag. Is that possible those are really related?

> 34:21.93 INFO: No more inbound revisions, bisection finished.
> 34:21.93 INFO: Last good revision: 1c52d8baf78986cb9497d48b8b88291686a681ca
> 34:21.93 INFO: First bad revision: c034e7ddbacdbe80ec8ce5b844e4299fcac9287c
> 34:21.93 INFO: Pushlog:
> https://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?fromchange=1c52d8baf78986cb9497d48b8b88291686a681ca&tochange=c034e7ddbacdbe80ec8ce5b844e4299fcac9287c
Has Regression Range: --- → yes
Flags: needinfo?(kmaglione+bmo)
Keywords: regression
This is the linux version of bug 1444595.
See Also: → 1444595
Summary: White background area shown around add-ons toolbar button popup with WebRender enabled → OOP Webextension panels on Linux: white background instead of transparency
See Also: → 1357487
Flags: needinfo?(kmaglione+bmo)
Assignee: nobody → sotaro.ikeda.g
See Also: → 1478454
Implementation of nsBaseWidget::AllowWebRenderForThisWindow() seems to be related to the problem. The code is like the following. It allows webrender usage for "(WindowType() == eWindowType_popup && HasRemoteContent())" case. Then OOP webextensions seems to trigger the problem.

------------------------------------------------------------

bool
nsBaseWidget::AllowWebRenderForThisWindow()
{
  return WindowType() == eWindowType_toplevel ||
         WindowType() == eWindowType_child ||
         WindowType() == eWindowType_dialog ||
         (WindowType() == eWindowType_popup && HasRemoteContent());
}
It seems that rgba visual is not allocated with GLContextGLX::FindVisual() even when argument "useAlpha" is true.
Depends on: 1479680
It seems better to avoid to use webrender when widget uses AlphaVisual for now. glXChooseVisual() did not choose rgba visual even when GLX_ALPHA_SIZE was requested on my 2 Ubuntu PCs. And rgba visual by gdk_screen_get_rgba_visual did work with glx on my one Ubuntu PC.
It should be OK, since we already disabled webrender on Windows when a widget has transparency.
  https://dxr.mozilla.org/mozilla-central/source/widget/windows/nsWindow.cpp#8316
Attachment #8996517 - Attachment is obsolete: true
Attachment #8996518 - Flags: review?(nical.bugzilla)
Comment on attachment 8996518 [details] [diff] [review]
patch - Disable WebRender when widget uses AlphaVisual

Review of attachment 8996518 [details] [diff] [review]:
-----------------------------------------------------------------

::: widget/gtk/nsWindow.cpp
@@ +3734,5 @@
>  
> +        // Disable WebRender when widget uses AlphaVisual.
> +        // glXChooseVisual would not choose rgba visual even when GLX_ALPHA_SIZE
> +        // is requested. And rgba visual by gdk_screen_get_rgba_visual would
> +        // not work with glx.

I find it really odd that we aren't able to get an alpha channel. From reading around it looks like there's something nvidia related, and also I wonder if we are actually getting a visual with alpha but not selecting the right framebuffer config, since we don't seem to request ay alpha channel when calling fChooseFBConfig.

I'm fine with this workaround but could you add to this comment that we can probably make this work with alpha in some cases if we spend some more time investigating?
Attachment #8996518 - Flags: review?(nical.bugzilla) → review+
(In reply to Nicolas Silva [:nical] from comment #14)
> Comment on attachment 8996518 [details] [diff] [review]
> patch - Disable WebRender when widget uses AlphaVisual
> 
> Review of attachment 8996518 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: widget/gtk/nsWindow.cpp
> @@ +3734,5 @@
> >  
> > +        // Disable WebRender when widget uses AlphaVisual.
> > +        // glXChooseVisual would not choose rgba visual even when GLX_ALPHA_SIZE
> > +        // is requested. And rgba visual by gdk_screen_get_rgba_visual would
> > +        // not work with glx.
> 
> I find it really odd that we aren't able to get an alpha channel. From
> reading around it looks like there's something nvidia related, and also I
> wonder if we are actually getting a visual with alpha but not selecting the
> right framebuffer config, since we don't seem to request ay alpha channel
> when calling fChooseFBConfig.
> 
> I'm fine with this workaround but could you add to this comment that we can
> probably make this work with alpha in some cases if we spend some more time
> investigating?

Nicolas, I already investigated that and it's at https://bugzilla.mozilla.org/show_bug.cgi?id=1478454#c29

Would be great if you can comment there.
Flags: needinfo?(nical.bugzilla)
(In reply to Martin Stránský [:stransky] from comment #15)
> > I'm fine with this workaround but could you add to this comment that we can
> > probably make this work with alpha in some cases if we spend some more time
> > investigating?

Also a simple fix here is to just use the visual from X drawable as it's selected/configured at nsWidnow::Create():

https://dxr.mozilla.org/mozilla-central/rev/085cdfb90903d4985f0de1dc7786522d9fb45596/widget/gtk/nsWindow.cpp#3739
Comment on attachment 8996518 [details] [diff] [review]
patch - Disable WebRender when widget uses AlphaVisual

IMHO this patch does not address the core cause which is visual mismatch at AreCompatibleVisuals().
Attached patch copy visual patch (obsolete) — Splinter Review
This simple patch just copies WebRender compatible visual from Xwindow. The correct visual was selected at nsWidow::Create() so there's no need to configure it again.
(In reply to Martin Stránský [:stransky] from comment #18)
> Created attachment 8996656 [details] [diff] [review]
> copy visual patch
> 
> This simple patch just copies WebRender compatible visual from Xwindow. The correct visual was selected at nsWidow::Create() so there's no need to configure it again.

Proprietary Nvidia driver:
My local build indicates that you have just fixed bug 1478454, but there's a black background around the panel (OpenGL and Basic have transparency). Still better than Basic.
And I noticed this in my terminal:
> (firefox:14060): Gtk-WARNING **: 14:21:27.899: Theme parsing error: <data>:1:34: Expected ')' in color definition
Nouveau, latest m-c:
mozregression --launch af6a7edf0069 --pref gfx.webrender.all:true gfx.webrender.debug.profiler:true -a https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/

uBlock's panel has a black background instead of transparency around it (and it uses WR because there's a WR profiler in it). 
My local build from comment 19 looks the same, so comment 18 as fix for bug 1478454 wouldn't break anything.
Comment on attachment 8996518 [details] [diff] [review]
patch - Disable WebRender when widget uses AlphaVisual

Review of attachment 8996518 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks a lot for shimming in Martin. You definitely have a better understanding of this stuff than me, I'll make sure add you to the loop for other widget related reviews that come my way.
What you are saying makes a lot of sense. I tried your patch and it improves the situation a lot for the test case I have handy. I still see white where the widget should be transparent but I suspect that will go away with another of sotaro's patches that make us use the right clear color.

Sotaro, since we have something to try, let's explore this before we drop transparent widgets altogether.
Attachment #8996518 - Flags: review+
I already noticed the problem of attachment 8996656 [details] [diff] [review] during investigating this bug and confirmed that it did not address the transparency problem on my 2 linux pcs.

It could address the caused failure of creating GLXContext by visual mismatch. But it does not address the problem of allocating rgba visual.
I did not include the change of attachment 8996656 [details] [diff] [review] in attachment 8996518 [details] [diff] [review] since it is not related to rgba visual allocation problem and when attachment 8996518 [details] [diff] [review] was applied, I did not see the visual mismatch on my 2 linux pcs. Then visual mismatch could be handled as a different problem.
So during investigating this bug, I locally applied same change of attachment 8996656 [details] [diff] [review]. But it was not included to attachment 8996518 [details] [diff] [review] because of comment 23.
Some people see this problem even without WebRender: bug 1479135 (OpenGL itself is fine for me.)
It seems that glXChooseVisual() seems not provide a visual that is requested by gecko. The following document has a description "glXChooseVisual is implemented as a client-side utility using only XGetVisualInfo and glXGetConfig."

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glXChooseVisual.xml

Then, it seems that we could address the problem by using XGetVisualInfo and glXGetConfig.
I locally confirmed that Comment 26 address the problem for me.
Attachment #8996518 - Attachment is obsolete: true
Attachment #8996942 - Attachment description: patch - Remove glXChooseVisual() usage → patch part 2 - Remove glXChooseVisual() usage
See Also: → 1479135
FYI: glxinfo will print all available visuals, you can easily check which visual is selected and if that selection is correct. But the same visual has to be used for drawable (xid) of nsWindow and for glxContext, we'll get BadMatch X error otherwise.
:stransky, thanks for the info!

In this bug, I work for fixing the problem of visual selection in GLContextGLX::FindVisual(). And intentionally, I did not work for fixing bad match in this bug.

attachment 8996656 [details] [diff] [review] that you created, addresses the bat mach. Can you create a new bug for fixing the bad match?
Flags: needinfo?(stransky)
Attachment #8996929 - Flags: review?(nical.bugzilla)
Attachment #8996942 - Flags: review?(nical.bugzilla)
(In reply to Sotaro Ikeda [:sotaro] from comment #33)
> :stransky, thanks for the info!
> 
> In this bug, I work for fixing the problem of visual selection in
> GLContextGLX::FindVisual(). And intentionally, I did not work for fixing bad
> match in this bug.

Sure. I did the visual comparsion and the only difference is the depth. 0x051 is selected by FindVisual and 0x0e6 is chosen by your patch. 0x0e6 works fine with transparent windows, co the 32-bit depth seems to be the trick here.

0x051 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0e6 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None

So as your patch is functional I wonder if we can do something less intrusive and without hardcoding the rgb masks.

> attachment 8996656 [details] [diff] [review] that you created, addresses the
> bat mach. Can you create a new bug for fixing the bad match?

It's already filed, Bug 1478454 (don't be confused by NVIDA here).
Flags: needinfo?(stransky)
It seems that we could remove the hardcoding by using default visual, like chromium does in the following.

XVisualInfo GLVisualPickerGLX::PickBestSystemVisual(
    const std::vector<XVisualInfo>& visuals) const {
  Visual* default_visual = DefaultVisual(display_, DefaultScreen(display_));
  auto it = std::find_if(visuals.begin(), visuals.end(),
                         [default_visual](const XVisualInfo& visual_info) {
                           return visual_info.visual == default_visual;
                         });
  DCHECK(it != visuals.end());

  const XVisualInfo& default_visual_info = *it;
  std::vector<XVisualInfo> filtered_visuals;
  std::copy_if(
      visuals.begin(), visuals.end(), std::back_inserter(filtered_visuals),
      [&default_visual_info](const XVisualInfo& visual_info) {
        const XVisualInfo& v1 = visual_info;
        const XVisualInfo& v2 = default_visual_info;
        return v1.c_class == v2.c_class && v1.depth == v2.depth &&
               v1.red_mask == v2.red_mask && v1.green_mask == v2.green_mask &&
               v1.blue_mask == v2.blue_mask &&
               v1.colormap_size == v2.colormap_size &&
               v1.bits_per_rgb == v2.bits_per_rgb;
      });
  return PickBestGlVisual(filtered_visuals, IsArgbVisual(default_visual_info));
}
Remove hardcoded mask values.
Attachment #8996942 - Attachment is obsolete: true
Attachment #8996942 - Flags: review?(nical.bugzilla)
Attachment #8996971 - Flags: review?(nical.bugzilla)
(In reply to Martin Stránský [:stransky] from comment #34)

> 0x051 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
> 0x0e6 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None

I think I understand what's going on here and why we have an alpha visual but the result is not transparent. The first selected visual (0x51) has 32-bit depth color buffer with RGBA but maps to only 24-bit depth X window surface - the X11 depth is only 24 so the alpha is discarded in X.
Comment on attachment 8996971 [details] [diff] [review]
patch part 2 - Remove glXChooseVisual() usage

IMHO this should be reviewed by gl peer. But let me comment it a bit:

-    XVisualInfo* visuals = sGLXLibrary.fChooseVisual(display, screen, attribs);
-    if (!visuals) {
+    XVisualInfo visualTemplate;
+    visualTemplate.screen = screen;

I think more template values can be passed here (depth for instance).

+   // Get default visual
+
+   Visual* defaultVisual = DefaultVisual(display, screen);
+   auto it = std::find_if(visuals.begin(), visuals.end(),
+                         [defaultVisual](const XVisualInfo& visualInfo) {
+                           return visualInfo.visual == defaultVisual;
+                         });
+
+   MOZ_ASSERT(it != visuals.end());
+   if (it == visuals.end()) {
+        return false;
+   }
+   const XVisualInfo& defaultVisualInfo = *it;
+   const int depth = useAlpha ? 32 : 24;
+
+    // Get visuals that are compatible to default visual.
+
+    std::vector<XVisualInfo> compatibleVisuals;
+
+    std::copy_if(
+        visuals.begin(), visuals.end(), std::back_inserter(compatibleVisuals),
+        [&defaultVisualInfo, depth](const XVisualInfo& visual) {
+            return visual.depth == depth &&
+                   visual.c_class == defaultVisualInfo.c_class &&
+                   visual.red_mask == defaultVisualInfo.red_mask &&
+                   visual.green_mask == defaultVisualInfo.green_mask &&
+                   visual.blue_mask == defaultVisualInfo.blue_mask;
+        });

AFAIK there's no need to compare bit mask of DefaultVisual. We just need to make sure we have 32-bit X visual depth (visual.depth) for transparent surfaces and 8 bit R G B (A) components along the 24bit depth buffer.

-                mHasAlphaVisual = true;
+                mHasAlphaVisual = needsAlphaVisual;

That's really not relevant here as it controls shape masks for non-composting WM. If you don't mind I'd put that to an extra patch.
Flags: needinfo?(nical.bugzilla)
Comment on attachment 8996656 [details] [diff] [review]
copy visual patch

No need to fix it here.
Attachment #8996656 - Attachment is obsolete: true
(In reply to Martin Stránský [:stransky] from comment #39)
> -                mHasAlphaVisual = true;
> +                mHasAlphaVisual = needsAlphaVisual;
> 
> That's really not relevant here as it controls shape masks for
> non-composting WM. If you don't mind I'd put that to an extra patch.

Filed as Bug 1480409
Attachment #8996929 - Flags: review?(nical.bugzilla) → review+
(In reply to Martin Stránský [:stransky] from comment #39)
> Comment on attachment 8996971 [details] [diff] [review]
> patch part 2 - Remove glXChooseVisual() usage
> 
> IMHO this should be reviewed by gl peer. But let me comment it a bit:
> 
> -    XVisualInfo* visuals = sGLXLibrary.fChooseVisual(display, screen,
> attribs);
> -    if (!visuals) {
> +    XVisualInfo visualTemplate;
> +    visualTemplate.screen = screen;
> 
> I think more template values can be passed here (depth for instance).

Passing more template values did not affect to the result. And chromium also pass only screen. Then it seems that there are no need to pass the more values.

> +    std::copy_if(
> +        visuals.begin(), visuals.end(),
> std::back_inserter(compatibleVisuals),
> +        [&defaultVisualInfo, depth](const XVisualInfo& visual) {
> +            return visual.depth == depth &&
> +                   visual.c_class == defaultVisualInfo.c_class &&
> +                   visual.red_mask == defaultVisualInfo.red_mask &&
> +                   visual.green_mask == defaultVisualInfo.green_mask &&
> +                   visual.blue_mask == defaultVisualInfo.blue_mask;
> +        });
> 
> AFAIK there's no need to compare bit mask of DefaultVisual. We just need to
> make sure we have 32-bit X visual depth (visual.depth) for transparent
> surfaces and 8 bit R G B (A) components along the 24bit depth buffer.

I will remove the mask check.

> 
> -                mHasAlphaVisual = true;
> +                mHasAlphaVisual = needsAlphaVisual;
> 
> That's really not relevant here as it controls shape masks for
> non-composting WM. If you don't mind I'd put that to an extra patch.

Yea, it is not related to the patch. I will remove it.
Apply the comments.
Attachment #8996971 - Attachment is obsolete: true
Attachment #8996971 - Flags: review?(nical.bugzilla)
Attachment #8997208 - Attachment is obsolete: true
Comment on attachment 8996929 [details] [diff] [review]
patch part 1 - Expose glxGetConfig() in GLXLibrary

:jgilbert, can you review the patches?
Attachment #8996929 - Flags: review?(jgilbert)
Attachment #8997209 - Flags: review?(jgilbert)
Attachment #8996929 - Flags: review?(jgilbert) → review+
Comment on attachment 8997209 [details] [diff] [review]
patch part 2 - Remove glXChooseVisual() usage

Review of attachment 8997209 [details] [diff] [review]:
-----------------------------------------------------------------

Let me know what you think of these recommendations.

::: gfx/gl/GLContextProviderGLX.cpp
@@ +908,5 @@
> +    std::vector<XVisualInfo> visuals;
> +    for (int i = 0; i < visualsLen; i++) {
> +      visuals.push_back(xVisuals[i]);
> +    }
> +    XFree(xVisuals);

For ranged-for syntax:
https://dxr.mozilla.org/mozilla-central/source/mfbt/Range.h
For memory management:
https://dxr.mozilla.org/mozilla-central/source/mfbt/ScopeExit.h

@@ +914,5 @@
> +
> +   // Get default visual
> +
> +   Visual* defaultVisual = DefaultVisual(display, screen);
> +   auto it = std::find_if(visuals.begin(), visuals.end(),

const auto

@@ +915,5 @@
> +   // Get default visual
> +
> +   Visual* defaultVisual = DefaultVisual(display, screen);
> +   auto it = std::find_if(visuals.begin(), visuals.end(),
> +                         [defaultVisual](const XVisualInfo& visualInfo) {

Just capture with [&] if the lambda is stack-scoped.

@@ +919,5 @@
> +                         [defaultVisual](const XVisualInfo& visualInfo) {
> +                           return visualInfo.visual == defaultVisual;
> +                         });
> +
> +   MOZ_ASSERT(it != visuals.end());

Just `MOZ_ASSERT(false)` inside `if (it == visuals.end())` instead of repeating the conditional here.

@@ +922,5 @@
> +
> +   MOZ_ASSERT(it != visuals.end());
> +   if (it == visuals.end()) {
> +        return false;
> +   }

Consider:
const Range visualInfos(xVisuals, xVisuals+visualsLen);
const auto defaultVisualInfo = [&]() -> const XVisualInfo* {
    for (const auto& cur : visualInfos) {
        if (cur.visual == defaultVisual)
            return &cur;
    }
    return nullptr;
}();
if (!defaultVisualInfo)
    return false;

@@ +923,5 @@
> +   MOZ_ASSERT(it != visuals.end());
> +   if (it == visuals.end()) {
> +        return false;
> +   }
> +   const XVisualInfo& defaultVisualInfo = *it;

I think this would be more clear as:
const auto defaultVisualInfo = [&]() -> const XVisualInfo* {
  for (const auto& visualInfo : visuals) {
    if (visualInfo.visual == defaultVisual)
      return visualInfo

@@ +924,5 @@
> +   if (it == visuals.end()) {
> +        return false;
> +   }
> +   const XVisualInfo& defaultVisualInfo = *it;
> +   const int depth = useAlpha ? 32 : 24;

s/depth/bpp/

@@ +935,5 @@
> +        visuals.begin(), visuals.end(), std::back_inserter(compatibleVisuals),
> +        [&defaultVisualInfo, depth](const XVisualInfo& visual) {
> +            return visual.depth == depth &&
> +                   visual.c_class == defaultVisualInfo.c_class;
> +        });

This is one extra line:
for (const auto& x : visuals) {
  if (x.depth == depth &&
      x.c_class == defaultVisualInfo.c_class)
  {
    compatibleVisuals.push_back(x);
  }
}

@@ +942,5 @@
> +
> +    const int resquestedAlphaSize = useAlpha ? 8 : 0;
> +    const int resquestedDepthSize = useWebRender ? 24 : 0;
> +
> +    for (auto& visual : compatibleVisuals) {

So you're gathering all the compatible visuals, and then looping over them to choose the one you want.
Merge these two loops, looping over /all/ visuals, skipping ones that aren't compatible, and then skipping ones that don't match our needs.

@@ +945,5 @@
> +
> +    for (auto& visual : compatibleVisuals) {
> +        int supportsGl, doubleBuffer, redSize, greenSize, blueSize, alphaSize, depthSize;
> +        if (!sGLXLibrary.fGetConfig(display, &visual, LOCAL_GLX_USE_GL, &supportsGl) &&
> +            supportsGl &&

const auto fnConfigMatches = [&](const int pname, const int expected) {
  int actual;
  if (!sGLXLibrary.fGetConfig(display, &visual, pname, &actual))
    return false;
  return actual == expected;
};

if (fnConfigMatches(LOCAL_GLX_USE_GL, 1) &&
    fnConfigMatches(LOCAL_GLX_RED_SIZE, 8)...
Attachment #8997209 - Flags: review?(jgilbert) → review-
(In reply to Jeff Gilbert [:jgilbert] from comment #47)
> Comment on attachment 8997209 [details] [diff] [review]
> patch part 2 - Remove glXChooseVisual() usage
> 
> Review of attachment 8997209 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Let me know what you think of these recommendations.

Thanks for the advice:) They make the patch cleaner.

> 
> ::: gfx/gl/GLContextProviderGLX.cpp
> @@ +908,5 @@
> > +    std::vector<XVisualInfo> visuals;
> > +    for (int i = 0; i < visualsLen; i++) {
> > +      visuals.push_back(xVisuals[i]);
> > +    }
> > +    XFree(xVisuals);
> 
> For ranged-for syntax:
> https://dxr.mozilla.org/mozilla-central/source/mfbt/Range.h
> For memory management:
> https://dxr.mozilla.org/mozilla-central/source/mfbt/ScopeExit.h

I will update in a next patch.

> 
> @@ +914,5 @@
> > +
> > +   // Get default visual
> > +
> > +   Visual* defaultVisual = DefaultVisual(display, screen);
> > +   auto it = std::find_if(visuals.begin(), visuals.end(),
> 
> const auto


I will update in a next patch.

> 
> @@ +915,5 @@
> > +   // Get default visual
> > +
> > +   Visual* defaultVisual = DefaultVisual(display, screen);
> > +   auto it = std::find_if(visuals.begin(), visuals.end(),
> > +                         [defaultVisual](const XVisualInfo& visualInfo) {
> 
> Just capture with [&] if the lambda is stack-scoped.

I will update in a next patch.

> 
> @@ +919,5 @@
> > +                         [defaultVisual](const XVisualInfo& visualInfo) {
> > +                           return visualInfo.visual == defaultVisual;
> > +                         });
> > +
> > +   MOZ_ASSERT(it != visuals.end());
> 
> Just `MOZ_ASSERT(false)` inside `if (it == visuals.end())` instead of
> repeating the conditional here.

I will update in a next patch.

> 
> @@ +922,5 @@
> > +
> > +   MOZ_ASSERT(it != visuals.end());
> > +   if (it == visuals.end()) {
> > +        return false;
> > +   }
> 
> Consider:
> const Range visualInfos(xVisuals, xVisuals+visualsLen);
> const auto defaultVisualInfo = [&]() -> const XVisualInfo* {
>     for (const auto& cur : visualInfos) {
>         if (cur.visual == defaultVisual)
>             return &cur;
>     }
>     return nullptr;
> }();
> if (!defaultVisualInfo)
>     return false;

I will update in a next patch.

> 
> @@ +923,5 @@
> > +   MOZ_ASSERT(it != visuals.end());
> > +   if (it == visuals.end()) {
> > +        return false;
> > +   }
> > +   const XVisualInfo& defaultVisualInfo = *it;
> 
> I think this would be more clear as:
> const auto defaultVisualInfo = [&]() -> const XVisualInfo* {
>   for (const auto& visualInfo : visuals) {
>     if (visualInfo.visual == defaultVisual)
>       return visualInfo

I will update in a next patch.

> 
> @@ +924,5 @@
> > +   if (it == visuals.end()) {
> > +        return false;
> > +   }
> > +   const XVisualInfo& defaultVisualInfo = *it;
> > +   const int depth = useAlpha ? 32 : 24;
> 
> s/depth/bpp/

I will update in a next patch.

> 
> @@ +935,5 @@
> > +        visuals.begin(), visuals.end(), std::back_inserter(compatibleVisuals),
> > +        [&defaultVisualInfo, depth](const XVisualInfo& visual) {
> > +            return visual.depth == depth &&
> > +                   visual.c_class == defaultVisualInfo.c_class;
> > +        });
> 
> This is one extra line:
> for (const auto& x : visuals) {
>   if (x.depth == depth &&
>       x.c_class == defaultVisualInfo.c_class)
>   {
>     compatibleVisuals.push_back(x);
>   }
> }


This part will be removed when the two loops is merged.

> 
> @@ +942,5 @@
> > +
> > +    const int resquestedAlphaSize = useAlpha ? 8 : 0;
> > +    const int resquestedDepthSize = useWebRender ? 24 : 0;
> > +
> > +    for (auto& visual : compatibleVisuals) {
> 
> So you're gathering all the compatible visuals, and then looping over them
> to choose the one you want.
> Merge these two loops, looping over /all/ visuals, skipping ones that aren't
> compatible, and then skipping ones that don't match our needs.

I will update in a next patch.

> 
> @@ +945,5 @@
> > +
> > +    for (auto& visual : compatibleVisuals) {
> > +        int supportsGl, doubleBuffer, redSize, greenSize, blueSize, alphaSize, depthSize;
> > +        if (!sGLXLibrary.fGetConfig(display, &visual, LOCAL_GLX_USE_GL, &supportsGl) &&
> > +            supportsGl &&
> 
> const auto fnConfigMatches = [&](const int pname, const int expected) {
>   int actual;
>   if (!sGLXLibrary.fGetConfig(display, &visual, pname, &actual))
>     return false;
>   return actual == expected;
> };
> 
> if (fnConfigMatches(LOCAL_GLX_USE_GL, 1) &&
>     fnConfigMatches(LOCAL_GLX_RED_SIZE, 8)...

I will update in a next patch. glXGetConfig() returns 0 on success.
Comment on attachment 8997289 [details] [diff] [review]
patch part 2 - Remove glXChooseVisual() usage

:jgilbert, can you review the patch again?
Attachment #8997289 - Flags: review?(jgilbert)
Is bug 1478454 related to this?
Flags: needinfo?(sotaro.ikeda.g)
(In reply to Jeff Gilbert [:jgilbert] from comment #52)
> Is bug 1478454 related to this?

It is related but orthogonal problem. This bug is for fixing how to choose visual. bug 1478454 is for fixing the GlxContext creation failure by bad match error. I did not see the bad match error when attachment 8997289 [details] [diff] [review] is applied.

As in Comment 34 and Comment 22, the bad match error is going to be addressed in bug 1478454.
Flags: needinfo?(sotaro.ikeda.g)
Comment on attachment 8997289 [details] [diff] [review]
patch part 2 - Remove glXChooseVisual() usage

Review of attachment 8997289 [details] [diff] [review]:
-----------------------------------------------------------------

Great, thanks!

::: gfx/gl/GLContextProviderGLX.cpp
@@ +952,5 @@
> +            fnConfigMatches(LOCAL_GLX_RED_SIZE, 8) &&
> +            fnConfigMatches(LOCAL_GLX_GREEN_SIZE, 8) &&
> +            fnConfigMatches(LOCAL_GLX_BLUE_SIZE, 8) &&
> +            fnConfigMatches(LOCAL_GLX_ALPHA_SIZE, alphaSize) &&
> +            fnConfigMatches(LOCAL_GLX_DEPTH_SIZE, depthSize)) {

Prefer { on its own line for multi-line conditionals like this.
Attachment #8997289 - Flags: review?(jgilbert) → review+
(In reply to Jeff Gilbert [:jgilbert] from comment #56)
> Comment on attachment 8997289 [details] [diff] [review]
> patch part 2 - Remove glXChooseVisual() usage
> 
> Review of attachment 8997289 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Great, thanks!
> 
> ::: gfx/gl/GLContextProviderGLX.cpp
> @@ +952,5 @@
> > +            fnConfigMatches(LOCAL_GLX_RED_SIZE, 8) &&
> > +            fnConfigMatches(LOCAL_GLX_GREEN_SIZE, 8) &&
> > +            fnConfigMatches(LOCAL_GLX_BLUE_SIZE, 8) &&
> > +            fnConfigMatches(LOCAL_GLX_ALPHA_SIZE, alphaSize) &&
> > +            fnConfigMatches(LOCAL_GLX_DEPTH_SIZE, depthSize)) {
> 
> Prefer { on its own line for multi-line conditionals like this.

Thanks for the review! I will update in a next patch.
Apply the comment.
Attachment #8997289 - Attachment is obsolete: true
Attachment #8998079 - Flags: review+
Pushed by sikeda@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/e6764dc17395
part 1 - Expose glxGetConfig() in GLXLibrary r=jgilbert
https://hg.mozilla.org/integration/mozilla-inbound/rev/d745e4118de7
part 2 - Remove glXChooseVisual() usage r=jgilbert
https://hg.mozilla.org/mozilla-central/rev/e6764dc17395
https://hg.mozilla.org/mozilla-central/rev/d745e4118de7
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
I cannot reproduce the issue in Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0 ID:20180807100107 anymore. good work!
Status: RESOLVED → VERIFIED
Depends on: 1485101
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: