gecko-dev/widget/gtk/mozcontainer.h
Martin Stransky 42d551312e Bug 1628583 [Wayland] Use mutex to access mozcontainer wayland internals, r=jhorak
Mozcontainer is accessed from various threads - Main/Compositor/Renderer - which causes races
when wayland surfaces are created/deleted/updated so we need to control it.

Differential Revision: https://phabricator.services.mozilla.com/D71737
2020-04-24 17:19:15 +00:00

132 lines
4.9 KiB
C++

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __MOZ_CONTAINER_H__
#define __MOZ_CONTAINER_H__
#include <gtk/gtk.h>
#include <functional>
#include <vector>
#ifdef MOZ_WAYLAND
# include "mozilla/Mutex.h"
#endif
/*
* MozContainer
*
* This class serves three purposes in the nsIWidget implementation.
*
* - It provides objects to receive signals from GTK for events on native
* windows.
*
* - It provides GdkWindow to draw content on Wayland or when Gtk+ renders
* client side decorations to mShell.
*
* - It provides a container parent for GtkWidgets. The only GtkWidgets
* that need this in Mozilla are the GtkSockets for windowed plugins (Xt
* and XEmbed).
*
* Note that the window hierarchy in Mozilla differs from conventional
* GtkWidget hierarchies.
*
* Mozilla's hierarchy exists through the GdkWindow hierarchy, and all child
* GdkWindows (within a child nsIWidget hierarchy) belong to one MozContainer
* GtkWidget. If the MozContainer is unrealized or its GdkWindows are
* destroyed for some other reason, then the hierarchy no longer exists. (In
* conventional GTK clients, the hierarchy is recorded by the GtkWidgets, and
* so can be re-established after destruction of the GdkWindows.)
*
* One consequence of this is that the MozContainer does not know which of its
* GdkWindows should parent child GtkWidgets. (Conventional GtkContainers
* determine which GdkWindow to assign child GtkWidgets.)
*
* Therefore, when adding a child GtkWidget to a MozContainer,
* gtk_widget_set_parent_window should be called on the child GtkWidget before
* it is realized.
*/
#define MOZ_CONTAINER_TYPE (moz_container_get_type())
#define MOZ_CONTAINER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), MOZ_CONTAINER_TYPE, MozContainer))
#define MOZ_CONTAINER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), MOZ_CONTAINER_TYPE, MozContainerClass))
#define IS_MOZ_CONTAINER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), MOZ_CONTAINER_TYPE))
#define IS_MOZ_CONTAINER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), MOZ_CONTAINER_TYPE))
#define MOZ_CONTAINER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), MOZ_CONTAINER_TYPE, MozContainerClass))
typedef struct _MozContainer MozContainer;
typedef struct _MozContainerClass MozContainerClass;
/* Workaround for bug at wayland-util.h,
* present in wayland-devel < 1.12
*/
#ifdef MOZ_WAYLAND
struct wl_surface;
struct wl_subsurface;
#endif
struct _MozContainer {
GtkContainer container;
GList* children;
#ifdef MOZ_WAYLAND
struct wl_surface* surface;
struct wl_subsurface* subsurface;
int subsurface_dx, subsurface_dy;
struct wl_egl_window* eglwindow;
struct wl_callback* frame_callback_handler;
int frame_callback_handler_surface_id;
gboolean opaque_region_needs_update;
gboolean opaque_region_subtract_corners;
gboolean opaque_region_fullscreen;
gboolean surface_position_needs_update;
gboolean surface_needs_clear;
gboolean ready_to_draw;
std::vector<std::function<void(void)>> initial_draw_cbs;
// mozcontainer is used from Compositor and Rendering threads
// so we need to control access to mozcontainer where wayland internals
// are used directly.
mozilla::Mutex* container_lock;
#endif
gboolean force_default_visual;
};
struct _MozContainerClass {
GtkContainerClass parent_class;
};
GType moz_container_get_type(void);
GtkWidget* moz_container_new(void);
void moz_container_put(MozContainer* container, GtkWidget* child_widget, gint x,
gint y);
void moz_container_force_default_visual(MozContainer* container);
#ifdef MOZ_WAYLAND
struct wl_surface* moz_container_get_wl_surface(MozContainer* container);
struct wl_egl_window* moz_container_get_wl_egl_window(MozContainer* container,
int scale);
gboolean moz_container_has_wl_egl_window(MozContainer* container);
gboolean moz_container_surface_needs_clear(MozContainer* container);
void moz_container_move_resize(MozContainer* container, int dx, int dy,
int width, int height);
void moz_container_egl_window_set_size(MozContainer* container, int width,
int height);
void moz_container_set_scale_factor(MozContainer* container);
void moz_container_add_initial_draw_callback(
MozContainer* container, const std::function<void(void)>& initial_draw_cb);
wl_surface* moz_gtk_widget_get_wl_surface(GtkWidget* aWidget);
void moz_container_update_opaque_region(MozContainer* container,
bool aSubtractCorners,
bool aFullScreen);
#endif
#endif /* __MOZ_CONTAINER_H__ */