Bug 1618493 [Wayland] Set opaque region for accelerated window immediately, r=jhorak"

Recently opaque region is set when wl_surface is obtained by renderer/compositor.
It does not work as GL/WebRender get wl_surface only once and creates egl_window
on top of it so the opaque region is never updated.

Differential Revision: https://phabricator.services.mozilla.com/D64583

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Stransky 2020-02-27 16:39:32 +00:00
parent 88355d1bf8
commit b432a2a607
4 changed files with 29 additions and 10 deletions

View File

@ -227,6 +227,7 @@ void moz_container_init(MozContainer* container) {
container->subsurface_dy = 0;
container->surface_position_needs_update = 0;
container->initial_draw_cbs.clear();
container->is_accelerated = false;
#endif
LOG(("%s [%p]\n", __FUNCTION__, (void*)container));
@ -571,6 +572,10 @@ static void moz_container_add(GtkContainer* container, GtkWidget* widget) {
#ifdef MOZ_WAYLAND
static void moz_container_set_opaque_region(MozContainer* container) {
if (!container->opaque_region_needs_update || !container->surface) {
return;
}
GtkAllocation allocation;
gtk_widget_get_allocation(GTK_WIDGET(container), &allocation);
@ -580,6 +585,7 @@ static void moz_container_set_opaque_region(MozContainer* container) {
container->opaque_region_subtract_corners);
wl_surface_set_opaque_region(container->surface, region);
wl_region_destroy(region);
container->opaque_region_needs_update = false;
}
struct wl_surface* moz_container_get_wl_surface(MozContainer* container) {
@ -631,11 +637,7 @@ struct wl_surface* moz_container_get_wl_surface(MozContainer* container) {
container->subsurface_dy);
}
if (container->opaque_region_needs_update) {
moz_container_set_opaque_region(container);
container->opaque_region_needs_update = false;
}
moz_container_set_opaque_region(container);
return container->surface;
}
@ -678,6 +680,17 @@ void moz_container_update_opaque_region(MozContainer* container,
bool aSubtractCorners) {
container->opaque_region_needs_update = true;
container->opaque_region_subtract_corners = aSubtractCorners;
// When GL compositor / WebRender is used,
// moz_container_get_wl_egl_window() is called only once when window
// is created or resized so update opaque region now.
if (container->is_accelerated) {
moz_container_set_opaque_region(container);
}
}
void moz_container_set_accelerated(MozContainer* container) {
container->is_accelerated = true;
}
#endif

View File

@ -86,6 +86,7 @@ struct _MozContainer {
gboolean surface_needs_clear;
gboolean ready_to_draw;
std::vector<std::function<void(void)>> initial_draw_cbs;
gboolean is_accelerated;
#endif
gboolean force_default_visual;
};
@ -118,6 +119,7 @@ void moz_container_add_initial_draw_callback(
wl_surface* moz_gtk_widget_get_wl_surface(GtkWidget* aWidget);
void moz_container_update_opaque_region(MozContainer* container,
bool aSubtractCorners);
void moz_container_set_accelerated(MozContainer* container);
#endif
#endif /* __MOZ_CONTAINER_H__ */

View File

@ -474,6 +474,8 @@ nsWindow::nsWindow() {
mWindowScaleFactorChanged = true;
mWindowScaleFactor = 1;
mIsAccelerated = false;
}
nsWindow::~nsWindow() {
@ -3848,8 +3850,8 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
bool useWebRender =
gfx::gfxVars::UseWebRender() && AllowWebRenderForThisWindow();
bool shouldAccelerate = ComputeShouldAccelerate();
MOZ_ASSERT(shouldAccelerate | !useWebRender);
mIsAccelerated = ComputeShouldAccelerate();
MOZ_ASSERT(mIsAccelerated | !useWebRender);
if (mWindowType == eWindowType_toplevel) {
// We enable titlebar rendering for toplevel windows only.
@ -3873,7 +3875,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
// Wayland uses ARGB visual by default
needsAlphaVisual = true;
} else if (mCSDSupportLevel != CSD_SUPPORT_NONE) {
if (shouldAccelerate) {
if (mIsAccelerated) {
needsAlphaVisual = true;
} else {
// We want to draw a transparent titlebar but we can't use
@ -3893,7 +3895,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
// Use GL/WebRender compatible visual only when it is necessary, since
// the visual consumes more memory.
if (mIsX11Display && shouldAccelerate) {
if (mIsX11Display && mIsAccelerated) {
auto display = GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(mShell));
auto screen = gtk_widget_get_screen(mShell);
int screenNumber = GDK_SCREEN_XNUMBER(screen);
@ -4043,13 +4045,14 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
GtkWidget* container = moz_container_new();
mContainer = MOZ_CONTAINER(container);
#ifdef MOZ_WAYLAND
if (!mIsX11Display && ComputeShouldAccelerate()) {
if (!mIsX11Display && mIsAccelerated) {
mCompositorInitiallyPaused = true;
RefPtr<nsWindow> self(this);
moz_container_add_initial_draw_callback(mContainer, [self]() -> void {
self->mNeedsCompositorResume = true;
self->MaybeResumeCompositor();
});
moz_container_set_accelerated(mContainer);
}
#endif

View File

@ -478,6 +478,7 @@ class nsWindow final : public nsBaseWidget {
#endif
bool mWindowScaleFactorChanged;
int mWindowScaleFactor;
bool mIsAccelerated;
private:
void DestroyChildWindows();