зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1635362 [Wayland] Split mozcontainer implementation for X11 and Wayland, r=jhorak
Differential Revision: https://phabricator.services.mozilla.com/D73794
This commit is contained in:
Родитель
112b719169
Коммит
9273e0a347
|
@ -0,0 +1,376 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#include "MozContainer.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#include <stdio.h>
|
||||
#ifdef MOZ_WAYLAND
|
||||
# include "gfxPlatformGtk.h"
|
||||
#endif
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
# include <atk/atk.h>
|
||||
# include "maiRedundantObjectFactory.h"
|
||||
#endif
|
||||
|
||||
#undef LOG
|
||||
#ifdef MOZ_LOGGING
|
||||
# include "mozilla/Logging.h"
|
||||
# include "nsTArray.h"
|
||||
# include "Units.h"
|
||||
extern mozilla::LazyLogModule gWidgetLog;
|
||||
# define LOG(args) MOZ_LOG(gWidgetLog, mozilla::LogLevel::Debug, args)
|
||||
#else
|
||||
# define LOG(args)
|
||||
#endif /* MOZ_LOGGING */
|
||||
|
||||
/* init methods */
|
||||
static void moz_container_class_init(MozContainerClass* klass);
|
||||
static void moz_container_init(MozContainer* container);
|
||||
|
||||
/* widget class methods */
|
||||
static void moz_container_map(GtkWidget* widget);
|
||||
static void moz_container_unmap(GtkWidget* widget);
|
||||
static void moz_container_size_allocate(GtkWidget* widget,
|
||||
GtkAllocation* allocation);
|
||||
void moz_container_realize(GtkWidget* widget);
|
||||
|
||||
/* container class methods */
|
||||
static void moz_container_remove(GtkContainer* container,
|
||||
GtkWidget* child_widget);
|
||||
static void moz_container_forall(GtkContainer* container,
|
||||
gboolean include_internals,
|
||||
GtkCallback callback, gpointer callback_data);
|
||||
static void moz_container_add(GtkContainer* container, GtkWidget* widget);
|
||||
|
||||
typedef struct _MozContainerChild MozContainerChild;
|
||||
|
||||
struct _MozContainerChild {
|
||||
GtkWidget* widget;
|
||||
gint x;
|
||||
gint y;
|
||||
};
|
||||
|
||||
static void moz_container_allocate_child(MozContainer* container,
|
||||
MozContainerChild* child);
|
||||
static MozContainerChild* moz_container_get_child(MozContainer* container,
|
||||
GtkWidget* child);
|
||||
|
||||
/* public methods */
|
||||
|
||||
GType moz_container_get_type(void) {
|
||||
static GType moz_container_type = 0;
|
||||
|
||||
if (!moz_container_type) {
|
||||
static GTypeInfo moz_container_info = {
|
||||
sizeof(MozContainerClass), /* class_size */
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc)moz_container_class_init, /* class_init */
|
||||
NULL, /* class_destroy */
|
||||
NULL, /* class_data */
|
||||
sizeof(MozContainer), /* instance_size */
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc)moz_container_init, /* instance_init */
|
||||
NULL, /* value_table */
|
||||
};
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
moz_container_info.class_init =
|
||||
(GClassInitFunc)moz_container_wayland_class_init;
|
||||
}
|
||||
#endif
|
||||
|
||||
moz_container_type =
|
||||
g_type_register_static(GTK_TYPE_CONTAINER, "MozContainer",
|
||||
&moz_container_info, static_cast<GTypeFlags>(0));
|
||||
#ifdef ACCESSIBILITY
|
||||
/* Set a factory to return accessible object with ROLE_REDUNDANT for
|
||||
* MozContainer, so that gail won't send focus notification for it */
|
||||
atk_registry_set_factory_type(atk_get_default_registry(),
|
||||
moz_container_type,
|
||||
mai_redundant_object_factory_get_type());
|
||||
#endif
|
||||
}
|
||||
|
||||
return moz_container_type;
|
||||
}
|
||||
|
||||
GtkWidget* moz_container_new(void) {
|
||||
MozContainer* container;
|
||||
|
||||
container =
|
||||
static_cast<MozContainer*>(g_object_new(MOZ_CONTAINER_TYPE, nullptr));
|
||||
|
||||
return GTK_WIDGET(container);
|
||||
}
|
||||
|
||||
void moz_container_put(MozContainer* container, GtkWidget* child_widget, gint x,
|
||||
gint y) {
|
||||
MozContainerChild* child;
|
||||
|
||||
child = g_new(MozContainerChild, 1);
|
||||
|
||||
child->widget = child_widget;
|
||||
child->x = x;
|
||||
child->y = y;
|
||||
|
||||
/* printf("moz_container_put %p %p %d %d\n", (void *)container,
|
||||
(void *)child_widget, x, y); */
|
||||
|
||||
container->children = g_list_append(container->children, child);
|
||||
|
||||
/* we assume that the caller of this function will have already set
|
||||
the parent GdkWindow because we can have many anonymous children. */
|
||||
gtk_widget_set_parent(child_widget, GTK_WIDGET(container));
|
||||
}
|
||||
|
||||
void moz_container_class_init(MozContainerClass* klass) {
|
||||
/*GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
|
||||
GtkContainerClass* container_class = GTK_CONTAINER_CLASS(klass);
|
||||
GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass);
|
||||
|
||||
widget_class->map = moz_container_map;
|
||||
widget_class->unmap = moz_container_unmap;
|
||||
widget_class->realize = moz_container_realize;
|
||||
widget_class->size_allocate = moz_container_size_allocate;
|
||||
|
||||
container_class->remove = moz_container_remove;
|
||||
container_class->forall = moz_container_forall;
|
||||
container_class->add = moz_container_add;
|
||||
}
|
||||
|
||||
void moz_container_init(MozContainer* container) {
|
||||
gtk_widget_set_can_focus(GTK_WIDGET(container), TRUE);
|
||||
gtk_container_set_resize_mode(GTK_CONTAINER(container), GTK_RESIZE_IMMEDIATE);
|
||||
gtk_widget_set_redraw_on_allocate(GTK_WIDGET(container), FALSE);
|
||||
#ifdef MOZ_WAYLAND
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
moz_container_wayland_init(&container->wl_container);
|
||||
}
|
||||
#endif
|
||||
LOG(("%s [%p]\n", __FUNCTION__, (void*)container));
|
||||
}
|
||||
|
||||
void moz_container_map(GtkWidget* widget) {
|
||||
MozContainer* container;
|
||||
GList* tmp_list;
|
||||
GtkWidget* tmp_child;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
container = MOZ_CONTAINER(widget);
|
||||
|
||||
gtk_widget_set_mapped(widget, TRUE);
|
||||
|
||||
tmp_list = container->children;
|
||||
while (tmp_list) {
|
||||
tmp_child = ((MozContainerChild*)tmp_list->data)->widget;
|
||||
|
||||
if (gtk_widget_get_visible(tmp_child)) {
|
||||
if (!gtk_widget_get_mapped(tmp_child)) gtk_widget_map(tmp_child);
|
||||
}
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
gdk_window_show(gtk_widget_get_window(widget));
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_unmap(GtkWidget* widget) {
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
|
||||
gtk_widget_set_mapped(widget, FALSE);
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
gdk_window_hide(gtk_widget_get_window(widget));
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_realize(GtkWidget* widget) {
|
||||
GdkWindow* parent = gtk_widget_get_parent_window(widget);
|
||||
GdkWindow* window;
|
||||
|
||||
gtk_widget_set_realized(widget, TRUE);
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask = GDK_WA_VISUAL | GDK_WA_X | GDK_WA_Y;
|
||||
GtkAllocation allocation;
|
||||
|
||||
gtk_widget_get_allocation(widget, &allocation);
|
||||
attributes.event_mask = gtk_widget_get_events(widget);
|
||||
attributes.x = allocation.x;
|
||||
attributes.y = allocation.y;
|
||||
attributes.width = allocation.width;
|
||||
attributes.height = allocation.height;
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
MozContainer* container = MOZ_CONTAINER(widget);
|
||||
attributes.visual =
|
||||
container->force_default_visual
|
||||
? gdk_screen_get_system_visual(gtk_widget_get_screen(widget))
|
||||
: gtk_widget_get_visual(widget);
|
||||
|
||||
window = gdk_window_new(parent, &attributes, attributes_mask);
|
||||
|
||||
LOG(("moz_container_realize() [%p] GdkWindow %p\n", (void*)container,
|
||||
(void*)window));
|
||||
|
||||
gdk_window_set_user_data(window, widget);
|
||||
} else {
|
||||
window = parent;
|
||||
g_object_ref(window);
|
||||
}
|
||||
|
||||
gtk_widget_set_window(widget, window);
|
||||
}
|
||||
|
||||
void moz_container_size_allocate(GtkWidget* widget, GtkAllocation* allocation) {
|
||||
MozContainer* container;
|
||||
GList* tmp_list;
|
||||
GtkAllocation tmp_allocation;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
|
||||
LOG(("moz_container_size_allocate [%p] %d,%d -> %d x %d\n", (void*)widget,
|
||||
allocation->x, allocation->y, allocation->width, allocation->height));
|
||||
|
||||
/* short circuit if you can */
|
||||
container = MOZ_CONTAINER(widget);
|
||||
gtk_widget_get_allocation(widget, &tmp_allocation);
|
||||
if (!container->children && tmp_allocation.x == allocation->x &&
|
||||
tmp_allocation.y == allocation->y &&
|
||||
tmp_allocation.width == allocation->width &&
|
||||
tmp_allocation.height == allocation->height) {
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_widget_set_allocation(widget, allocation);
|
||||
|
||||
tmp_list = container->children;
|
||||
|
||||
while (tmp_list) {
|
||||
MozContainerChild* child = static_cast<MozContainerChild*>(tmp_list->data);
|
||||
|
||||
moz_container_allocate_child(container, child);
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if (gtk_widget_get_has_window(widget) && gtk_widget_get_realized(widget)) {
|
||||
gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x,
|
||||
allocation->y, allocation->width,
|
||||
allocation->height);
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_remove(GtkContainer* container, GtkWidget* child_widget) {
|
||||
MozContainerChild* child;
|
||||
MozContainer* moz_container;
|
||||
GdkWindow* parent_window;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(container));
|
||||
g_return_if_fail(GTK_IS_WIDGET(child_widget));
|
||||
|
||||
moz_container = MOZ_CONTAINER(container);
|
||||
|
||||
child = moz_container_get_child(moz_container, child_widget);
|
||||
g_return_if_fail(child);
|
||||
|
||||
/* gtk_widget_unparent will remove the parent window (as well as the
|
||||
* parent widget), but, in Mozilla's window hierarchy, the parent window
|
||||
* may need to be kept because it may be part of a GdkWindow sub-hierarchy
|
||||
* that is being moved to another MozContainer.
|
||||
*
|
||||
* (In a conventional GtkWidget hierarchy, GdkWindows being reparented
|
||||
* would have their own GtkWidget and that widget would be the one being
|
||||
* reparented. In Mozilla's hierarchy, the parent_window needs to be
|
||||
* retained so that the GdkWindow sub-hierarchy is maintained.)
|
||||
*/
|
||||
parent_window = gtk_widget_get_parent_window(child_widget);
|
||||
if (parent_window) g_object_ref(parent_window);
|
||||
|
||||
gtk_widget_unparent(child_widget);
|
||||
|
||||
if (parent_window) {
|
||||
/* The child_widget will always still exist because g_signal_emit,
|
||||
* which invokes this function, holds a reference.
|
||||
*
|
||||
* If parent_window is the container's root window then it will not be
|
||||
* the parent_window if the child_widget is placed in another
|
||||
* container.
|
||||
*/
|
||||
if (parent_window != gtk_widget_get_window(GTK_WIDGET(container)))
|
||||
gtk_widget_set_parent_window(child_widget, parent_window);
|
||||
|
||||
g_object_unref(parent_window);
|
||||
}
|
||||
|
||||
moz_container->children = g_list_remove(moz_container->children, child);
|
||||
g_free(child);
|
||||
}
|
||||
|
||||
void moz_container_forall(GtkContainer* container, gboolean include_internals,
|
||||
GtkCallback callback, gpointer callback_data) {
|
||||
MozContainer* moz_container;
|
||||
GList* tmp_list;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(container));
|
||||
g_return_if_fail(callback != NULL);
|
||||
|
||||
moz_container = MOZ_CONTAINER(container);
|
||||
|
||||
tmp_list = moz_container->children;
|
||||
while (tmp_list) {
|
||||
MozContainerChild* child;
|
||||
child = static_cast<MozContainerChild*>(tmp_list->data);
|
||||
tmp_list = tmp_list->next;
|
||||
(*callback)(child->widget, callback_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void moz_container_allocate_child(MozContainer* container,
|
||||
MozContainerChild* child) {
|
||||
GtkAllocation allocation;
|
||||
|
||||
gtk_widget_get_allocation(child->widget, &allocation);
|
||||
allocation.x = child->x;
|
||||
allocation.y = child->y;
|
||||
|
||||
gtk_widget_size_allocate(child->widget, &allocation);
|
||||
}
|
||||
|
||||
MozContainerChild* moz_container_get_child(MozContainer* container,
|
||||
GtkWidget* child_widget) {
|
||||
GList* tmp_list;
|
||||
|
||||
tmp_list = container->children;
|
||||
while (tmp_list) {
|
||||
MozContainerChild* child;
|
||||
|
||||
child = static_cast<MozContainerChild*>(tmp_list->data);
|
||||
tmp_list = tmp_list->next;
|
||||
|
||||
if (child->widget == child_widget) return child;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void moz_container_add(GtkContainer* container, GtkWidget* widget) {
|
||||
moz_container_put(MOZ_CONTAINER(container), widget, 0, 0);
|
||||
}
|
||||
|
||||
void moz_container_force_default_visual(MozContainer* container) {
|
||||
container->force_default_visual = true;
|
||||
}
|
|
@ -8,12 +8,13 @@
|
|||
#ifndef __MOZ_CONTAINER_H__
|
||||
#define __MOZ_CONTAINER_H__
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
# include "MozContainerWayland.h"
|
||||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#ifdef MOZ_WAYLAND
|
||||
# include "mozilla/Mutex.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MozContainer
|
||||
|
@ -64,38 +65,13 @@
|
|||
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;
|
||||
#ifdef MOZ_WAYLAND
|
||||
MozContainerWayland wl_container;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _MozContainerClass {
|
||||
|
@ -108,24 +84,4 @@ 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__ */
|
|
@ -0,0 +1,502 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#include "MozContainer.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#include "nsWaylandDisplay.h"
|
||||
#include "gfxPlatformGtk.h"
|
||||
#include <wayland-egl.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#undef LOG
|
||||
#ifdef MOZ_LOGGING
|
||||
|
||||
# include "mozilla/Logging.h"
|
||||
# include "nsTArray.h"
|
||||
# include "Units.h"
|
||||
extern mozilla::LazyLogModule gWidgetWaylandLog;
|
||||
# define LOGWAYLAND(args) \
|
||||
MOZ_LOG(gWidgetWaylandLog, mozilla::LogLevel::Debug, args)
|
||||
#else
|
||||
# define LOGWAYLAND(args)
|
||||
#endif /* MOZ_LOGGING */
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::widget;
|
||||
|
||||
// Declaration from nsWindow, we don't want to include whole nsWindow.h file
|
||||
// here just for it.
|
||||
wl_region* CreateOpaqueRegionWayland(int aX, int aY, int aWidth, int aHeight,
|
||||
bool aSubtractCorners);
|
||||
|
||||
/* init methods */
|
||||
static void moz_container_wayland_destroy(GtkWidget* widget);
|
||||
|
||||
/* widget class methods */
|
||||
static void moz_container_wayland_map(GtkWidget* widget);
|
||||
static gboolean moz_container_wayland_map_event(GtkWidget* widget,
|
||||
GdkEventAny* event);
|
||||
static void moz_container_wayland_unmap(GtkWidget* widget);
|
||||
static void moz_container_wayland_size_allocate(GtkWidget* widget,
|
||||
GtkAllocation* allocation);
|
||||
|
||||
// Imlemented in MozContainer.cpp
|
||||
void moz_container_realize(GtkWidget* widget);
|
||||
|
||||
static void moz_container_wayland_move_locked(MozContainer* container, int dx,
|
||||
int dy) {
|
||||
LOGWAYLAND(("moz_container_wayland_move_locked [%p] %d,%d\n",
|
||||
(void*)container, dx, dy));
|
||||
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
|
||||
wl_container->subsurface_dx = dx;
|
||||
wl_container->subsurface_dy = dy;
|
||||
wl_container->surface_position_needs_update = true;
|
||||
|
||||
// Wayland subsurface is not created yet.
|
||||
if (!wl_container->subsurface) {
|
||||
return;
|
||||
}
|
||||
|
||||
// wl_subsurface_set_position is actually property of parent surface
|
||||
// which is effective when parent surface is commited.
|
||||
wl_subsurface_set_position(wl_container->subsurface,
|
||||
wl_container->subsurface_dx,
|
||||
wl_container->subsurface_dy);
|
||||
wl_container->surface_position_needs_update = false;
|
||||
|
||||
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
|
||||
if (window) {
|
||||
GdkRectangle rect = (GdkRectangle){0, 0, gdk_window_get_width(window),
|
||||
gdk_window_get_height(window)};
|
||||
gdk_window_invalidate_rect(window, &rect, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void moz_container_wayland_move(MozContainer* container, int dx,
|
||||
int dy) {
|
||||
MutexAutoLock lock(*container->wl_container.container_lock);
|
||||
LOGWAYLAND(
|
||||
("moz_container_wayland_move [%p] %d,%d\n", (void*)container, dx, dy));
|
||||
moz_container_wayland_move_locked(container, dx, dy);
|
||||
}
|
||||
|
||||
// This is called from layout/compositor code only with
|
||||
// size equal to GL rendering context. Otherwise there are
|
||||
// rendering artifacts as wl_egl_window size does not match
|
||||
// GL rendering pipeline setup.
|
||||
void moz_container_wayland_egl_window_set_size(MozContainer* container,
|
||||
int width, int height) {
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
MutexAutoLock lock(*wl_container->container_lock);
|
||||
if (wl_container->eglwindow) {
|
||||
wl_egl_window_resize(wl_container->eglwindow, width, height, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_wayland_class_init(MozContainerClass* klass) {
|
||||
/*GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
|
||||
GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass);
|
||||
|
||||
widget_class->map = moz_container_wayland_map;
|
||||
widget_class->map_event = moz_container_wayland_map_event;
|
||||
widget_class->destroy = moz_container_wayland_destroy;
|
||||
widget_class->unmap = moz_container_wayland_unmap;
|
||||
widget_class->realize = moz_container_realize;
|
||||
widget_class->size_allocate = moz_container_wayland_size_allocate;
|
||||
}
|
||||
|
||||
void moz_container_wayland_init(MozContainerWayland* container) {
|
||||
container->surface = nullptr;
|
||||
container->subsurface = nullptr;
|
||||
container->eglwindow = nullptr;
|
||||
container->frame_callback_handler = nullptr;
|
||||
container->frame_callback_handler_surface_id = -1;
|
||||
container->ready_to_draw = false;
|
||||
container->opaque_region_needs_update = false;
|
||||
container->opaque_region_subtract_corners = false;
|
||||
container->opaque_region_fullscreen = false;
|
||||
container->surface_needs_clear = true;
|
||||
container->subsurface_dx = 0;
|
||||
container->subsurface_dy = 0;
|
||||
container->surface_position_needs_update = 0;
|
||||
container->initial_draw_cbs.clear();
|
||||
container->container_lock = new mozilla::Mutex("MozContainer lock");
|
||||
}
|
||||
|
||||
static void moz_container_wayland_destroy(GtkWidget* widget) {
|
||||
MozContainerWayland* container = &MOZ_CONTAINER(widget)->wl_container;
|
||||
delete container->container_lock;
|
||||
container->container_lock = nullptr;
|
||||
}
|
||||
|
||||
void moz_container_wayland_add_initial_draw_callback(
|
||||
MozContainer* container, const std::function<void(void)>& initial_draw_cb) {
|
||||
container->wl_container.initial_draw_cbs.push_back(initial_draw_cb);
|
||||
}
|
||||
|
||||
wl_surface* moz_gtk_widget_get_wl_surface(GtkWidget* aWidget) {
|
||||
static auto sGdkWaylandWindowGetWlSurface = (wl_surface * (*)(GdkWindow*))
|
||||
dlsym(RTLD_DEFAULT, "gdk_wayland_window_get_wl_surface");
|
||||
|
||||
GdkWindow* window = gtk_widget_get_window(aWidget);
|
||||
wl_surface* surface = sGdkWaylandWindowGetWlSurface(window);
|
||||
|
||||
LOGWAYLAND(("moz_gtk_widget_get_wl_surface [%p] wl_surface %p ID %d\n",
|
||||
(void*)aWidget, (void*)surface,
|
||||
surface ? wl_proxy_get_id((struct wl_proxy*)surface) : -1));
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
static void moz_container_wayland_frame_callback_handler(
|
||||
void* data, struct wl_callback* callback, uint32_t time) {
|
||||
MozContainerWayland* wl_container = &MOZ_CONTAINER(data)->wl_container;
|
||||
|
||||
LOGWAYLAND(
|
||||
("%s [%p] frame_callback_handler %p ready_to_draw %d (set to true)"
|
||||
" initial_draw callback %zd\n",
|
||||
__FUNCTION__, (void*)MOZ_CONTAINER(data),
|
||||
(void*)wl_container->frame_callback_handler, wl_container->ready_to_draw,
|
||||
wl_container->initial_draw_cbs.size()));
|
||||
|
||||
g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
|
||||
wl_container->frame_callback_handler_surface_id = -1;
|
||||
|
||||
if (!wl_container->ready_to_draw) {
|
||||
wl_container->ready_to_draw = true;
|
||||
for (auto const& cb : wl_container->initial_draw_cbs) {
|
||||
cb();
|
||||
}
|
||||
wl_container->initial_draw_cbs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
static const struct wl_callback_listener moz_container_frame_listener = {
|
||||
moz_container_wayland_frame_callback_handler};
|
||||
|
||||
static void moz_container_wayland_request_parent_frame_callback(
|
||||
MozContainer* container) {
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
|
||||
wl_surface* gtk_container_surface =
|
||||
moz_gtk_widget_get_wl_surface(GTK_WIDGET(container));
|
||||
int gtk_container_surface_id =
|
||||
gtk_container_surface
|
||||
? wl_proxy_get_id((struct wl_proxy*)gtk_container_surface)
|
||||
: -1;
|
||||
|
||||
LOGWAYLAND(
|
||||
("%s [%p] frame_callback_handler %p "
|
||||
"frame_callback_handler_surface_id %d\n",
|
||||
__FUNCTION__, (void*)container, wl_container->frame_callback_handler,
|
||||
wl_container->frame_callback_handler_surface_id));
|
||||
|
||||
if (wl_container->frame_callback_handler &&
|
||||
wl_container->frame_callback_handler_surface_id ==
|
||||
gtk_container_surface_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there's pending frame callback, delete it.
|
||||
if (wl_container->frame_callback_handler) {
|
||||
g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
|
||||
}
|
||||
|
||||
if (gtk_container_surface) {
|
||||
wl_container->frame_callback_handler_surface_id = gtk_container_surface_id;
|
||||
wl_container->frame_callback_handler =
|
||||
wl_surface_frame(gtk_container_surface);
|
||||
wl_callback_add_listener(wl_container->frame_callback_handler,
|
||||
&moz_container_frame_listener, container);
|
||||
} else {
|
||||
wl_container->frame_callback_handler_surface_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean moz_container_wayland_map_event(GtkWidget* widget,
|
||||
GdkEventAny* event) {
|
||||
MozContainerWayland* wl_container = &MOZ_CONTAINER(widget)->wl_container;
|
||||
|
||||
LOGWAYLAND(("%s begin [%p] ready_to_draw %d\n", __FUNCTION__,
|
||||
(void*)MOZ_CONTAINER(widget), wl_container->ready_to_draw));
|
||||
|
||||
if (wl_container->ready_to_draw) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
moz_container_wayland_request_parent_frame_callback(MOZ_CONTAINER(widget));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void moz_container_wayland_unmap_internal(MozContainer* container) {
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
MutexAutoLock lock(*wl_container->container_lock);
|
||||
|
||||
g_clear_pointer(&wl_container->eglwindow, wl_egl_window_destroy);
|
||||
g_clear_pointer(&wl_container->subsurface, wl_subsurface_destroy);
|
||||
g_clear_pointer(&wl_container->surface, wl_surface_destroy);
|
||||
g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
|
||||
wl_container->frame_callback_handler_surface_id = -1;
|
||||
|
||||
wl_container->surface_needs_clear = true;
|
||||
wl_container->ready_to_draw = false;
|
||||
|
||||
LOGWAYLAND(("%s [%p]\n", __FUNCTION__, (void*)container));
|
||||
}
|
||||
|
||||
void moz_container_wayland_map(GtkWidget* widget) {
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
gtk_widget_set_mapped(widget, TRUE);
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
gdk_window_show(gtk_widget_get_window(widget));
|
||||
moz_container_wayland_map_event(widget, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_wayland_unmap(GtkWidget* widget) {
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
|
||||
gtk_widget_set_mapped(widget, FALSE);
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
gdk_window_hide(gtk_widget_get_window(widget));
|
||||
moz_container_wayland_unmap_internal(MOZ_CONTAINER(widget));
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_wayland_size_allocate(GtkWidget* widget,
|
||||
GtkAllocation* allocation) {
|
||||
MozContainer* container;
|
||||
GtkAllocation tmp_allocation;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
|
||||
LOGWAYLAND(("moz_container_wayland_size_allocate [%p] %d,%d -> %d x %d\n",
|
||||
(void*)widget, allocation->x, allocation->y, allocation->width,
|
||||
allocation->height));
|
||||
|
||||
/* short circuit if you can */
|
||||
container = MOZ_CONTAINER(widget);
|
||||
gtk_widget_get_allocation(widget, &tmp_allocation);
|
||||
if (!container->children && tmp_allocation.x == allocation->x &&
|
||||
tmp_allocation.y == allocation->y &&
|
||||
tmp_allocation.width == allocation->width &&
|
||||
tmp_allocation.height == allocation->height) {
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_widget_set_allocation(widget, allocation);
|
||||
|
||||
if (gtk_widget_get_has_window(widget) && gtk_widget_get_realized(widget)) {
|
||||
gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x,
|
||||
allocation->y, allocation->width,
|
||||
allocation->height);
|
||||
// We need to position our subsurface according to GdkWindow
|
||||
// when offset changes (GdkWindow is maximized for instance).
|
||||
// see gtk-clutter-embed.c for reference.
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
moz_container_wayland_move(MOZ_CONTAINER(widget), allocation->x,
|
||||
allocation->y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void moz_container_wayland_set_opaque_region_locked(
|
||||
MozContainer* container) {
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
|
||||
if (!wl_container->opaque_region_needs_update || !wl_container->surface) {
|
||||
return;
|
||||
}
|
||||
|
||||
GtkAllocation allocation;
|
||||
gtk_widget_get_allocation(GTK_WIDGET(container), &allocation);
|
||||
|
||||
// Set region to mozcontainer for normal state only
|
||||
if (!wl_container->opaque_region_fullscreen) {
|
||||
wl_region* region =
|
||||
CreateOpaqueRegionWayland(0, 0, allocation.width, allocation.height,
|
||||
wl_container->opaque_region_subtract_corners);
|
||||
wl_surface_set_opaque_region(wl_container->surface, region);
|
||||
wl_region_destroy(region);
|
||||
} else {
|
||||
wl_surface_set_opaque_region(wl_container->surface, nullptr);
|
||||
}
|
||||
|
||||
wl_container->opaque_region_needs_update = false;
|
||||
}
|
||||
|
||||
static void moz_container_wayland_set_opaque_region(MozContainer* container) {
|
||||
MutexAutoLock lock(*container->wl_container.container_lock);
|
||||
moz_container_wayland_set_opaque_region_locked(container);
|
||||
}
|
||||
|
||||
static int moz_gtk_widget_get_scale_factor(MozContainer* container) {
|
||||
static auto sGtkWidgetGetScaleFactor =
|
||||
(gint(*)(GtkWidget*))dlsym(RTLD_DEFAULT, "gtk_widget_get_scale_factor");
|
||||
return sGtkWidgetGetScaleFactor
|
||||
? sGtkWidgetGetScaleFactor(GTK_WIDGET(container))
|
||||
: 1;
|
||||
}
|
||||
|
||||
static void moz_container_wayland_set_scale_factor_locked(
|
||||
MozContainer* container) {
|
||||
if (!container->wl_container.surface) {
|
||||
return;
|
||||
}
|
||||
wl_surface_set_buffer_scale(container->wl_container.surface,
|
||||
moz_gtk_widget_get_scale_factor(container));
|
||||
}
|
||||
|
||||
void moz_container_wayland_set_scale_factor(MozContainer* container) {
|
||||
MutexAutoLock lock(*container->wl_container.container_lock);
|
||||
moz_container_wayland_set_scale_factor_locked(container);
|
||||
}
|
||||
|
||||
static struct wl_surface* moz_container_wayland_get_surface_locked(
|
||||
MozContainer* container, nsWaylandDisplay* aWaylandDisplay) {
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
|
||||
LOGWAYLAND(("%s [%p] surface %p ready_to_draw %d\n", __FUNCTION__,
|
||||
(void*)container, (void*)wl_container->surface,
|
||||
wl_container->ready_to_draw));
|
||||
|
||||
if (!wl_container->surface) {
|
||||
if (!wl_container->ready_to_draw) {
|
||||
moz_container_wayland_request_parent_frame_callback(container);
|
||||
return nullptr;
|
||||
}
|
||||
wl_surface* parent_surface =
|
||||
moz_gtk_widget_get_wl_surface(GTK_WIDGET(container));
|
||||
if (!parent_surface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Available as of GTK 3.8+
|
||||
struct wl_compositor* compositor = aWaylandDisplay->GetCompositor();
|
||||
wl_container->surface = wl_compositor_create_surface(compositor);
|
||||
if (!wl_container->surface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wl_container->subsurface =
|
||||
wl_subcompositor_get_subsurface(aWaylandDisplay->GetSubcompositor(),
|
||||
wl_container->surface, parent_surface);
|
||||
if (!wl_container->subsurface) {
|
||||
g_clear_pointer(&wl_container->surface, wl_surface_destroy);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
|
||||
gint x, y;
|
||||
gdk_window_get_position(window, &x, &y);
|
||||
moz_container_wayland_move_locked(container, x, y);
|
||||
wl_subsurface_set_desync(wl_container->subsurface);
|
||||
|
||||
// Route input to parent wl_surface owned by Gtk+ so we get input
|
||||
// events from Gtk+.
|
||||
wl_region* region = wl_compositor_create_region(compositor);
|
||||
wl_surface_set_input_region(wl_container->surface, region);
|
||||
wl_region_destroy(region);
|
||||
|
||||
wl_surface_commit(wl_container->surface);
|
||||
wl_display_flush(aWaylandDisplay->GetDisplay());
|
||||
|
||||
LOGWAYLAND(("%s [%p] created surface %p\n", __FUNCTION__, (void*)container,
|
||||
(void*)wl_container->surface));
|
||||
}
|
||||
|
||||
if (wl_container->surface_position_needs_update) {
|
||||
moz_container_wayland_move_locked(container, wl_container->subsurface_dx,
|
||||
wl_container->subsurface_dy);
|
||||
}
|
||||
|
||||
moz_container_wayland_set_opaque_region_locked(container);
|
||||
moz_container_wayland_set_scale_factor_locked(container);
|
||||
|
||||
return wl_container->surface;
|
||||
}
|
||||
|
||||
struct wl_surface* moz_container_wayland_get_surface(MozContainer* container) {
|
||||
GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(container));
|
||||
nsWaylandDisplay* waylandDisplay = WaylandDisplayGet(display);
|
||||
|
||||
LOGWAYLAND(("%s [%p] surface %p\n", __FUNCTION__, (void*)container,
|
||||
(void*)container->wl_container.surface));
|
||||
|
||||
MutexAutoLock lock(*container->wl_container.container_lock);
|
||||
return moz_container_wayland_get_surface_locked(container, waylandDisplay);
|
||||
}
|
||||
|
||||
struct wl_egl_window* moz_container_wayland_get_egl_window(
|
||||
MozContainer* container, int scale) {
|
||||
GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(container));
|
||||
nsWaylandDisplay* waylandDisplay = WaylandDisplayGet(display);
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
|
||||
LOGWAYLAND(("%s [%p] eglwindow %p\n", __FUNCTION__, (void*)container,
|
||||
(void*)wl_container->eglwindow));
|
||||
|
||||
MutexAutoLock lock(*wl_container->container_lock);
|
||||
|
||||
// Always call moz_container_get_wl_surface() to ensure underlying
|
||||
// container->surface has correct scale and position.
|
||||
wl_surface* surface =
|
||||
moz_container_wayland_get_surface_locked(container, waylandDisplay);
|
||||
if (!surface) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!wl_container->eglwindow) {
|
||||
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
|
||||
wl_container->eglwindow =
|
||||
wl_egl_window_create(surface, gdk_window_get_width(window) * scale,
|
||||
gdk_window_get_height(window) * scale);
|
||||
|
||||
LOGWAYLAND(("%s [%p] created eglwindow %p\n", __FUNCTION__,
|
||||
(void*)container, (void*)wl_container->eglwindow));
|
||||
}
|
||||
|
||||
return wl_container->eglwindow;
|
||||
}
|
||||
|
||||
gboolean moz_container_wayland_has_egl_window(MozContainer* container) {
|
||||
return container->wl_container.eglwindow ? true : false;
|
||||
}
|
||||
|
||||
gboolean moz_container_wayland_surface_needs_clear(MozContainer* container) {
|
||||
int ret = container->wl_container.surface_needs_clear;
|
||||
container->wl_container.surface_needs_clear = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void moz_container_wayland_update_opaque_region(MozContainer* container,
|
||||
bool aSubtractCorners,
|
||||
bool aFullScreen) {
|
||||
MozContainerWayland* wl_container = &container->wl_container;
|
||||
wl_container->opaque_region_needs_update = true;
|
||||
wl_container->opaque_region_subtract_corners = aSubtractCorners;
|
||||
wl_container->opaque_region_fullscreen = aFullScreen;
|
||||
|
||||
// When GL compositor / WebRender is used,
|
||||
// moz_container_wayland_get_egl_window() is called only once when window
|
||||
// is created or resized so update opaque region now.
|
||||
if (moz_container_wayland_has_egl_window(container)) {
|
||||
moz_container_wayland_set_opaque_region(container);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean moz_container_wayland_can_draw(MozContainer* container) {
|
||||
return container ? container->wl_container.ready_to_draw : false;
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/* -*- 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_WAYLAND_H__
|
||||
#define __MOZ_CONTAINER_WAYLAND_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "mozilla/Mutex.h"
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* Workaround for bug at wayland-util.h,
|
||||
* present in wayland-devel < 1.12
|
||||
*/
|
||||
struct wl_surface;
|
||||
struct wl_subsurface;
|
||||
|
||||
struct MozContainerWayland {
|
||||
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;
|
||||
};
|
||||
|
||||
struct _MozContainer;
|
||||
struct _MozContainerClass;
|
||||
typedef struct _MozContainer MozContainer;
|
||||
typedef struct _MozContainerClass MozContainerClass;
|
||||
|
||||
void moz_container_wayland_class_init(MozContainerClass* klass);
|
||||
void moz_container_wayland_init(MozContainerWayland* container);
|
||||
|
||||
struct wl_surface* moz_container_wayland_get_surface(MozContainer* container);
|
||||
struct wl_egl_window* moz_container_wayland_get_egl_window(
|
||||
MozContainer* container, int scale);
|
||||
|
||||
gboolean moz_container_wayland_has_egl_window(MozContainer* container);
|
||||
gboolean moz_container_wayland_surface_needs_clear(MozContainer* container);
|
||||
void moz_container_wayland_move_resize(MozContainer* container, int dx, int dy,
|
||||
int width, int height);
|
||||
void moz_container_wayland_egl_window_set_size(MozContainer* container,
|
||||
int width, int height);
|
||||
void moz_container_wayland_set_scale_factor(MozContainer* container);
|
||||
void moz_container_wayland_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_wayland_update_opaque_region(MozContainer* container,
|
||||
bool aSubtractCorners,
|
||||
bool aFullScreen);
|
||||
gboolean moz_container_wayland_can_draw(MozContainer* container);
|
||||
|
||||
#endif /* __MOZ_CONTAINER_WAYLAND_H__ */
|
|
@ -115,7 +115,7 @@ void WaylandVsyncSource::WaylandDisplay::Notify() {
|
|||
}
|
||||
|
||||
void WaylandVsyncSource::WaylandDisplay::SetupFrameCallback() {
|
||||
struct wl_surface* surface = moz_container_get_wl_surface(mContainer);
|
||||
struct wl_surface* surface = moz_container_wayland_get_surface(mContainer);
|
||||
if (!surface) {
|
||||
// We don't have a surface, either due to being called before it was made
|
||||
// available in the mozcontainer, or after it was destroyed. We're all done
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozcontainer.h"
|
||||
#include "MozContainer.h"
|
||||
#include "VsyncSource.h"
|
||||
#include "base/thread.h"
|
||||
#include "nsWaylandDisplay.h"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/Tools.h"
|
||||
#include "gfxPlatform.h"
|
||||
#include "mozcontainer.h"
|
||||
#include "MozContainer.h"
|
||||
#include "nsTArray.h"
|
||||
#include "base/message_loop.h" // for MessageLoop
|
||||
#include "base/task.h" // for NewRunnableMethod, etc
|
||||
|
|
|
@ -20,7 +20,7 @@ if CONFIG['MOZ_WAYLAND']:
|
|||
DIRS += ['wayland', 'mozwayland']
|
||||
|
||||
EXPORTS += [
|
||||
'mozcontainer.h',
|
||||
'MozContainer.h',
|
||||
'nsGTKToolkit.h',
|
||||
'nsIImageToPixbuf.h',
|
||||
]
|
||||
|
@ -31,7 +31,7 @@ EXPORTS.mozilla += [
|
|||
|
||||
UNIFIED_SOURCES += [
|
||||
'IMContextWrapper.cpp',
|
||||
'mozcontainer.cpp',
|
||||
'MozContainer.cpp',
|
||||
'MPRISServiceHandler.cpp',
|
||||
'NativeKeyBindings.cpp',
|
||||
'nsAppShell.cpp',
|
||||
|
@ -100,12 +100,14 @@ if CONFIG['MOZ_X11']:
|
|||
|
||||
if CONFIG['MOZ_WAYLAND']:
|
||||
UNIFIED_SOURCES += [
|
||||
'MozContainerWayland.cpp',
|
||||
'nsClipboardWayland.cpp',
|
||||
'nsWaylandDisplay.cpp',
|
||||
'WaylandDMABufSurface.cpp',
|
||||
'WindowSurfaceWayland.cpp',
|
||||
]
|
||||
EXPORTS.mozilla.widget += [
|
||||
'MozContainerWayland.h',
|
||||
'nsWaylandDisplay.h',
|
||||
'WaylandDMABufSurface.h',
|
||||
]
|
||||
|
|
|
@ -1,778 +0,0 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#include "mozcontainer.h"
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#ifdef MOZ_WAYLAND
|
||||
# include "nsWaylandDisplay.h"
|
||||
# include "gfxPlatformGtk.h"
|
||||
# include <wayland-egl.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
# include <atk/atk.h>
|
||||
# include "maiRedundantObjectFactory.h"
|
||||
#endif
|
||||
|
||||
#undef LOG
|
||||
#ifdef MOZ_LOGGING
|
||||
|
||||
# include "mozilla/Logging.h"
|
||||
# include "nsTArray.h"
|
||||
# include "Units.h"
|
||||
extern mozilla::LazyLogModule gWidgetLog;
|
||||
extern mozilla::LazyLogModule gWidgetWaylandLog;
|
||||
# define LOG(args) MOZ_LOG(gWidgetLog, mozilla::LogLevel::Debug, args)
|
||||
# define LOGWAYLAND(args) \
|
||||
MOZ_LOG(gWidgetWaylandLog, mozilla::LogLevel::Debug, args)
|
||||
#else
|
||||
# define LOG(args)
|
||||
# define LOGWAYLAND(args)
|
||||
#endif /* MOZ_LOGGING */
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::widget;
|
||||
|
||||
// Declaration from nsWindow, we don't want to include whole nsWindow.h file
|
||||
// here just for it.
|
||||
wl_region* CreateOpaqueRegionWayland(int aX, int aY, int aWidth, int aHeight,
|
||||
bool aSubtractCorners);
|
||||
#endif
|
||||
|
||||
/* init methods */
|
||||
static void moz_container_class_init(MozContainerClass* klass);
|
||||
static void moz_container_init(MozContainer* container);
|
||||
#if defined(MOZ_WAYLAND)
|
||||
static void moz_container_destroy(GtkWidget* widget);
|
||||
#endif
|
||||
|
||||
/* widget class methods */
|
||||
static void moz_container_map(GtkWidget* widget);
|
||||
#if defined(MOZ_WAYLAND)
|
||||
static gboolean moz_container_map_wayland(GtkWidget* widget,
|
||||
GdkEventAny* event);
|
||||
#endif
|
||||
static void moz_container_unmap(GtkWidget* widget);
|
||||
static void moz_container_realize(GtkWidget* widget);
|
||||
static void moz_container_size_allocate(GtkWidget* widget,
|
||||
GtkAllocation* allocation);
|
||||
|
||||
/* container class methods */
|
||||
static void moz_container_remove(GtkContainer* container,
|
||||
GtkWidget* child_widget);
|
||||
static void moz_container_forall(GtkContainer* container,
|
||||
gboolean include_internals,
|
||||
GtkCallback callback, gpointer callback_data);
|
||||
static void moz_container_add(GtkContainer* container, GtkWidget* widget);
|
||||
|
||||
typedef struct _MozContainerChild MozContainerChild;
|
||||
|
||||
struct _MozContainerChild {
|
||||
GtkWidget* widget;
|
||||
gint x;
|
||||
gint y;
|
||||
};
|
||||
|
||||
static void moz_container_allocate_child(MozContainer* container,
|
||||
MozContainerChild* child);
|
||||
static MozContainerChild* moz_container_get_child(MozContainer* container,
|
||||
GtkWidget* child);
|
||||
|
||||
/* public methods */
|
||||
|
||||
GType moz_container_get_type(void) {
|
||||
static GType moz_container_type = 0;
|
||||
|
||||
if (!moz_container_type) {
|
||||
static GTypeInfo moz_container_info = {
|
||||
sizeof(MozContainerClass), /* class_size */
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc)moz_container_class_init, /* class_init */
|
||||
NULL, /* class_destroy */
|
||||
NULL, /* class_data */
|
||||
sizeof(MozContainer), /* instance_size */
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc)moz_container_init, /* instance_init */
|
||||
NULL, /* value_table */
|
||||
};
|
||||
|
||||
moz_container_type =
|
||||
g_type_register_static(GTK_TYPE_CONTAINER, "MozContainer",
|
||||
&moz_container_info, static_cast<GTypeFlags>(0));
|
||||
#ifdef ACCESSIBILITY
|
||||
/* Set a factory to return accessible object with ROLE_REDUNDANT for
|
||||
* MozContainer, so that gail won't send focus notification for it */
|
||||
atk_registry_set_factory_type(atk_get_default_registry(),
|
||||
moz_container_type,
|
||||
mai_redundant_object_factory_get_type());
|
||||
#endif
|
||||
}
|
||||
|
||||
return moz_container_type;
|
||||
}
|
||||
|
||||
GtkWidget* moz_container_new(void) {
|
||||
MozContainer* container;
|
||||
|
||||
container =
|
||||
static_cast<MozContainer*>(g_object_new(MOZ_CONTAINER_TYPE, nullptr));
|
||||
|
||||
return GTK_WIDGET(container);
|
||||
}
|
||||
|
||||
void moz_container_put(MozContainer* container, GtkWidget* child_widget, gint x,
|
||||
gint y) {
|
||||
MozContainerChild* child;
|
||||
|
||||
child = g_new(MozContainerChild, 1);
|
||||
|
||||
child->widget = child_widget;
|
||||
child->x = x;
|
||||
child->y = y;
|
||||
|
||||
/* printf("moz_container_put %p %p %d %d\n", (void *)container,
|
||||
(void *)child_widget, x, y); */
|
||||
|
||||
container->children = g_list_append(container->children, child);
|
||||
|
||||
/* we assume that the caller of this function will have already set
|
||||
the parent GdkWindow because we can have many anonymous children. */
|
||||
gtk_widget_set_parent(child_widget, GTK_WIDGET(container));
|
||||
}
|
||||
|
||||
#if defined(MOZ_WAYLAND)
|
||||
static void moz_container_move_locked(MozContainer* container, int dx, int dy) {
|
||||
LOGWAYLAND(
|
||||
("moz_container_move_locked [%p] %d,%d\n", (void*)container, dx, dy));
|
||||
|
||||
container->subsurface_dx = dx;
|
||||
container->subsurface_dy = dy;
|
||||
container->surface_position_needs_update = true;
|
||||
|
||||
// Wayland subsurface is not created yet.
|
||||
if (!container->subsurface) {
|
||||
return;
|
||||
}
|
||||
|
||||
// wl_subsurface_set_position is actually property of parent surface
|
||||
// which is effective when parent surface is commited.
|
||||
wl_subsurface_set_position(container->subsurface, container->subsurface_dx,
|
||||
container->subsurface_dy);
|
||||
container->surface_position_needs_update = false;
|
||||
|
||||
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
|
||||
if (window) {
|
||||
GdkRectangle rect = (GdkRectangle){0, 0, gdk_window_get_width(window),
|
||||
gdk_window_get_height(window)};
|
||||
gdk_window_invalidate_rect(window, &rect, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void moz_container_move(MozContainer* container, int dx, int dy) {
|
||||
MutexAutoLock lock(*container->container_lock);
|
||||
LOGWAYLAND(("moz_container_move [%p] %d,%d\n", (void*)container, dx, dy));
|
||||
moz_container_move_locked(container, dx, dy);
|
||||
}
|
||||
|
||||
// This is called from layout/compositor code only with
|
||||
// size equal to GL rendering context. Otherwise there are
|
||||
// rendering artifacts as wl_egl_window size does not match
|
||||
// GL rendering pipeline setup.
|
||||
void moz_container_egl_window_set_size(MozContainer* container, int width,
|
||||
int height) {
|
||||
MutexAutoLock lock(*container->container_lock);
|
||||
if (container->eglwindow) {
|
||||
wl_egl_window_resize(container->eglwindow, width, height, 0, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void moz_container_class_init(MozContainerClass* klass) {
|
||||
/*GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); */
|
||||
GtkContainerClass* container_class = GTK_CONTAINER_CLASS(klass);
|
||||
GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass);
|
||||
|
||||
widget_class->map = moz_container_map;
|
||||
#if defined(MOZ_WAYLAND)
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
widget_class->map_event = moz_container_map_wayland;
|
||||
widget_class->destroy = moz_container_destroy;
|
||||
}
|
||||
#endif
|
||||
widget_class->unmap = moz_container_unmap;
|
||||
widget_class->realize = moz_container_realize;
|
||||
widget_class->size_allocate = moz_container_size_allocate;
|
||||
|
||||
container_class->remove = moz_container_remove;
|
||||
container_class->forall = moz_container_forall;
|
||||
container_class->add = moz_container_add;
|
||||
}
|
||||
|
||||
void moz_container_init(MozContainer* container) {
|
||||
gtk_widget_set_can_focus(GTK_WIDGET(container), TRUE);
|
||||
gtk_container_set_resize_mode(GTK_CONTAINER(container), GTK_RESIZE_IMMEDIATE);
|
||||
gtk_widget_set_redraw_on_allocate(GTK_WIDGET(container), FALSE);
|
||||
|
||||
#if defined(MOZ_WAYLAND)
|
||||
container->surface = nullptr;
|
||||
container->subsurface = nullptr;
|
||||
container->eglwindow = nullptr;
|
||||
container->frame_callback_handler = nullptr;
|
||||
container->frame_callback_handler_surface_id = -1;
|
||||
// We can draw to x11 window any time.
|
||||
container->ready_to_draw = gfxPlatformGtk::GetPlatform()->IsX11Display();
|
||||
container->opaque_region_needs_update = false;
|
||||
container->opaque_region_subtract_corners = false;
|
||||
container->opaque_region_fullscreen = false;
|
||||
container->surface_needs_clear = true;
|
||||
container->subsurface_dx = 0;
|
||||
container->subsurface_dy = 0;
|
||||
container->surface_position_needs_update = 0;
|
||||
container->initial_draw_cbs.clear();
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
container->container_lock = new mozilla::Mutex("MozContainer lock");
|
||||
}
|
||||
#endif
|
||||
|
||||
LOG(("%s [%p]\n", __FUNCTION__, (void*)container));
|
||||
}
|
||||
|
||||
#if defined(MOZ_WAYLAND)
|
||||
static void moz_container_destroy(GtkWidget* widget) {
|
||||
MozContainer* container = MOZ_CONTAINER(widget);
|
||||
delete container->container_lock;
|
||||
container->container_lock = nullptr;
|
||||
}
|
||||
|
||||
void moz_container_add_initial_draw_callback(
|
||||
MozContainer* container, const std::function<void(void)>& initial_draw_cb) {
|
||||
container->initial_draw_cbs.push_back(initial_draw_cb);
|
||||
}
|
||||
|
||||
wl_surface* moz_gtk_widget_get_wl_surface(GtkWidget* aWidget) {
|
||||
static auto sGdkWaylandWindowGetWlSurface = (wl_surface * (*)(GdkWindow*))
|
||||
dlsym(RTLD_DEFAULT, "gdk_wayland_window_get_wl_surface");
|
||||
|
||||
GdkWindow* window = gtk_widget_get_window(aWidget);
|
||||
wl_surface* surface = sGdkWaylandWindowGetWlSurface(window);
|
||||
|
||||
LOGWAYLAND(("moz_gtk_widget_get_wl_surface [%p] wl_surface %p ID %d\n",
|
||||
(void*)aWidget, (void*)surface,
|
||||
surface ? wl_proxy_get_id((struct wl_proxy*)surface) : -1));
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
static void moz_container_frame_callback_handler(void* data,
|
||||
struct wl_callback* callback,
|
||||
uint32_t time) {
|
||||
MozContainer* container = MOZ_CONTAINER(data);
|
||||
|
||||
LOGWAYLAND(
|
||||
("%s [%p] frame_callback_handler %p ready_to_draw %d (set to true)"
|
||||
" initial_draw callback %zd\n",
|
||||
__FUNCTION__, (void*)container, (void*)container->frame_callback_handler,
|
||||
container->ready_to_draw, container->initial_draw_cbs.size()));
|
||||
|
||||
g_clear_pointer(&container->frame_callback_handler, wl_callback_destroy);
|
||||
container->frame_callback_handler_surface_id = -1;
|
||||
|
||||
if (!container->ready_to_draw) {
|
||||
container->ready_to_draw = true;
|
||||
for (auto const& cb : container->initial_draw_cbs) {
|
||||
cb();
|
||||
}
|
||||
container->initial_draw_cbs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
static const struct wl_callback_listener moz_container_frame_listener = {
|
||||
moz_container_frame_callback_handler};
|
||||
|
||||
static void moz_container_request_parent_frame_callback(
|
||||
MozContainer* container) {
|
||||
wl_surface* gtk_container_surface =
|
||||
moz_gtk_widget_get_wl_surface(GTK_WIDGET(container));
|
||||
int gtk_container_surface_id =
|
||||
gtk_container_surface
|
||||
? wl_proxy_get_id((struct wl_proxy*)gtk_container_surface)
|
||||
: -1;
|
||||
|
||||
LOGWAYLAND(
|
||||
("%s [%p] frame_callback_handler %p "
|
||||
"frame_callback_handler_surface_id %d\n",
|
||||
__FUNCTION__, (void*)container, container->frame_callback_handler,
|
||||
container->frame_callback_handler_surface_id));
|
||||
|
||||
if (container->frame_callback_handler &&
|
||||
container->frame_callback_handler_surface_id ==
|
||||
gtk_container_surface_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there's pending frame callback, delete it.
|
||||
if (container->frame_callback_handler) {
|
||||
g_clear_pointer(&container->frame_callback_handler, wl_callback_destroy);
|
||||
}
|
||||
|
||||
if (gtk_container_surface) {
|
||||
container->frame_callback_handler_surface_id = gtk_container_surface_id;
|
||||
container->frame_callback_handler = wl_surface_frame(gtk_container_surface);
|
||||
wl_callback_add_listener(container->frame_callback_handler,
|
||||
&moz_container_frame_listener, container);
|
||||
} else {
|
||||
container->frame_callback_handler_surface_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean moz_container_map_wayland(GtkWidget* widget,
|
||||
GdkEventAny* event) {
|
||||
MozContainer* container = MOZ_CONTAINER(widget);
|
||||
|
||||
LOGWAYLAND(("%s begin [%p] ready_to_draw %d\n", __FUNCTION__,
|
||||
(void*)container, container->ready_to_draw));
|
||||
|
||||
if (container->ready_to_draw) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
moz_container_request_parent_frame_callback(MOZ_CONTAINER(widget));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void moz_container_unmap_wayland(MozContainer* container) {
|
||||
MutexAutoLock lock(*container->container_lock);
|
||||
|
||||
g_clear_pointer(&container->eglwindow, wl_egl_window_destroy);
|
||||
g_clear_pointer(&container->subsurface, wl_subsurface_destroy);
|
||||
g_clear_pointer(&container->surface, wl_surface_destroy);
|
||||
g_clear_pointer(&container->frame_callback_handler, wl_callback_destroy);
|
||||
container->frame_callback_handler_surface_id = -1;
|
||||
|
||||
container->surface_needs_clear = true;
|
||||
container->ready_to_draw = false;
|
||||
|
||||
LOGWAYLAND(("%s [%p]\n", __FUNCTION__, (void*)container));
|
||||
}
|
||||
#endif
|
||||
|
||||
void moz_container_map(GtkWidget* widget) {
|
||||
MozContainer* container;
|
||||
GList* tmp_list;
|
||||
GtkWidget* tmp_child;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
container = MOZ_CONTAINER(widget);
|
||||
|
||||
gtk_widget_set_mapped(widget, TRUE);
|
||||
|
||||
tmp_list = container->children;
|
||||
while (tmp_list) {
|
||||
tmp_child = ((MozContainerChild*)tmp_list->data)->widget;
|
||||
|
||||
if (gtk_widget_get_visible(tmp_child)) {
|
||||
if (!gtk_widget_get_mapped(tmp_child)) gtk_widget_map(tmp_child);
|
||||
}
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
gdk_window_show(gtk_widget_get_window(widget));
|
||||
#if defined(MOZ_WAYLAND)
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
moz_container_map_wayland(widget, nullptr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_unmap(GtkWidget* widget) {
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
|
||||
gtk_widget_set_mapped(widget, FALSE);
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
gdk_window_hide(gtk_widget_get_window(widget));
|
||||
#if defined(MOZ_WAYLAND)
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
moz_container_unmap_wayland(MOZ_CONTAINER(widget));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_realize(GtkWidget* widget) {
|
||||
GdkWindow* parent = gtk_widget_get_parent_window(widget);
|
||||
GdkWindow* window;
|
||||
|
||||
gtk_widget_set_realized(widget, TRUE);
|
||||
|
||||
if (gtk_widget_get_has_window(widget)) {
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask = GDK_WA_VISUAL | GDK_WA_X | GDK_WA_Y;
|
||||
GtkAllocation allocation;
|
||||
|
||||
gtk_widget_get_allocation(widget, &allocation);
|
||||
attributes.event_mask = gtk_widget_get_events(widget);
|
||||
attributes.x = allocation.x;
|
||||
attributes.y = allocation.y;
|
||||
attributes.width = allocation.width;
|
||||
attributes.height = allocation.height;
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
MozContainer* container = MOZ_CONTAINER(widget);
|
||||
attributes.visual =
|
||||
container->force_default_visual
|
||||
? gdk_screen_get_system_visual(gtk_widget_get_screen(widget))
|
||||
: gtk_widget_get_visual(widget);
|
||||
|
||||
window = gdk_window_new(parent, &attributes, attributes_mask);
|
||||
|
||||
LOG(("moz_container_realize() [%p] GdkWindow %p\n", (void*)container,
|
||||
(void*)window));
|
||||
|
||||
gdk_window_set_user_data(window, widget);
|
||||
} else {
|
||||
window = parent;
|
||||
g_object_ref(window);
|
||||
}
|
||||
|
||||
gtk_widget_set_window(widget, window);
|
||||
}
|
||||
|
||||
void moz_container_size_allocate(GtkWidget* widget, GtkAllocation* allocation) {
|
||||
MozContainer* container;
|
||||
GList* tmp_list;
|
||||
GtkAllocation tmp_allocation;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(widget));
|
||||
|
||||
LOG(("moz_container_size_allocate [%p] %d,%d -> %d x %d\n", (void*)widget,
|
||||
allocation->x, allocation->y, allocation->width, allocation->height));
|
||||
|
||||
/* short circuit if you can */
|
||||
container = MOZ_CONTAINER(widget);
|
||||
gtk_widget_get_allocation(widget, &tmp_allocation);
|
||||
if (!container->children && tmp_allocation.x == allocation->x &&
|
||||
tmp_allocation.y == allocation->y &&
|
||||
tmp_allocation.width == allocation->width &&
|
||||
tmp_allocation.height == allocation->height) {
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_widget_set_allocation(widget, allocation);
|
||||
|
||||
tmp_list = container->children;
|
||||
|
||||
while (tmp_list) {
|
||||
MozContainerChild* child = static_cast<MozContainerChild*>(tmp_list->data);
|
||||
|
||||
moz_container_allocate_child(container, child);
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if (gtk_widget_get_has_window(widget) && gtk_widget_get_realized(widget)) {
|
||||
gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x,
|
||||
allocation->y, allocation->width,
|
||||
allocation->height);
|
||||
#if defined(MOZ_WAYLAND)
|
||||
// We need to position our subsurface according to GdkWindow
|
||||
// when offset changes (GdkWindow is maximized for instance).
|
||||
// see gtk-clutter-embed.c for reference.
|
||||
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
|
||||
moz_container_move(MOZ_CONTAINER(widget), allocation->x, allocation->y);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void moz_container_remove(GtkContainer* container, GtkWidget* child_widget) {
|
||||
MozContainerChild* child;
|
||||
MozContainer* moz_container;
|
||||
GdkWindow* parent_window;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(container));
|
||||
g_return_if_fail(GTK_IS_WIDGET(child_widget));
|
||||
|
||||
moz_container = MOZ_CONTAINER(container);
|
||||
|
||||
child = moz_container_get_child(moz_container, child_widget);
|
||||
g_return_if_fail(child);
|
||||
|
||||
/* gtk_widget_unparent will remove the parent window (as well as the
|
||||
* parent widget), but, in Mozilla's window hierarchy, the parent window
|
||||
* may need to be kept because it may be part of a GdkWindow sub-hierarchy
|
||||
* that is being moved to another MozContainer.
|
||||
*
|
||||
* (In a conventional GtkWidget hierarchy, GdkWindows being reparented
|
||||
* would have their own GtkWidget and that widget would be the one being
|
||||
* reparented. In Mozilla's hierarchy, the parent_window needs to be
|
||||
* retained so that the GdkWindow sub-hierarchy is maintained.)
|
||||
*/
|
||||
parent_window = gtk_widget_get_parent_window(child_widget);
|
||||
if (parent_window) g_object_ref(parent_window);
|
||||
|
||||
gtk_widget_unparent(child_widget);
|
||||
|
||||
if (parent_window) {
|
||||
/* The child_widget will always still exist because g_signal_emit,
|
||||
* which invokes this function, holds a reference.
|
||||
*
|
||||
* If parent_window is the container's root window then it will not be
|
||||
* the parent_window if the child_widget is placed in another
|
||||
* container.
|
||||
*/
|
||||
if (parent_window != gtk_widget_get_window(GTK_WIDGET(container)))
|
||||
gtk_widget_set_parent_window(child_widget, parent_window);
|
||||
|
||||
g_object_unref(parent_window);
|
||||
}
|
||||
|
||||
moz_container->children = g_list_remove(moz_container->children, child);
|
||||
g_free(child);
|
||||
}
|
||||
|
||||
void moz_container_forall(GtkContainer* container, gboolean include_internals,
|
||||
GtkCallback callback, gpointer callback_data) {
|
||||
MozContainer* moz_container;
|
||||
GList* tmp_list;
|
||||
|
||||
g_return_if_fail(IS_MOZ_CONTAINER(container));
|
||||
g_return_if_fail(callback != NULL);
|
||||
|
||||
moz_container = MOZ_CONTAINER(container);
|
||||
|
||||
tmp_list = moz_container->children;
|
||||
while (tmp_list) {
|
||||
MozContainerChild* child;
|
||||
child = static_cast<MozContainerChild*>(tmp_list->data);
|
||||
tmp_list = tmp_list->next;
|
||||
(*callback)(child->widget, callback_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void moz_container_allocate_child(MozContainer* container,
|
||||
MozContainerChild* child) {
|
||||
GtkAllocation allocation;
|
||||
|
||||
gtk_widget_get_allocation(child->widget, &allocation);
|
||||
allocation.x = child->x;
|
||||
allocation.y = child->y;
|
||||
|
||||
gtk_widget_size_allocate(child->widget, &allocation);
|
||||
}
|
||||
|
||||
MozContainerChild* moz_container_get_child(MozContainer* container,
|
||||
GtkWidget* child_widget) {
|
||||
GList* tmp_list;
|
||||
|
||||
tmp_list = container->children;
|
||||
while (tmp_list) {
|
||||
MozContainerChild* child;
|
||||
|
||||
child = static_cast<MozContainerChild*>(tmp_list->data);
|
||||
tmp_list = tmp_list->next;
|
||||
|
||||
if (child->widget == child_widget) return child;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void moz_container_add(GtkContainer* container, GtkWidget* widget) {
|
||||
moz_container_put(MOZ_CONTAINER(container), widget, 0, 0);
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
static void moz_container_set_opaque_region_locked(MozContainer* container) {
|
||||
if (!container->opaque_region_needs_update || !container->surface) {
|
||||
return;
|
||||
}
|
||||
|
||||
GtkAllocation allocation;
|
||||
gtk_widget_get_allocation(GTK_WIDGET(container), &allocation);
|
||||
|
||||
// Set region to mozcontainer for normal state only
|
||||
if (!container->opaque_region_fullscreen) {
|
||||
wl_region* region =
|
||||
CreateOpaqueRegionWayland(0, 0, allocation.width, allocation.height,
|
||||
container->opaque_region_subtract_corners);
|
||||
wl_surface_set_opaque_region(container->surface, region);
|
||||
wl_region_destroy(region);
|
||||
} else {
|
||||
wl_surface_set_opaque_region(container->surface, nullptr);
|
||||
}
|
||||
|
||||
container->opaque_region_needs_update = false;
|
||||
}
|
||||
|
||||
static void moz_container_set_opaque_region(MozContainer* container) {
|
||||
MutexAutoLock lock(*container->container_lock);
|
||||
moz_container_set_opaque_region_locked(container);
|
||||
}
|
||||
|
||||
static int moz_gtk_widget_get_scale_factor(MozContainer* container) {
|
||||
static auto sGtkWidgetGetScaleFactor =
|
||||
(gint(*)(GtkWidget*))dlsym(RTLD_DEFAULT, "gtk_widget_get_scale_factor");
|
||||
return sGtkWidgetGetScaleFactor
|
||||
? sGtkWidgetGetScaleFactor(GTK_WIDGET(container))
|
||||
: 1;
|
||||
}
|
||||
|
||||
static void moz_container_set_scale_factor_locked(MozContainer* container) {
|
||||
if (!container->surface) {
|
||||
return;
|
||||
}
|
||||
wl_surface_set_buffer_scale(container->surface,
|
||||
moz_gtk_widget_get_scale_factor(container));
|
||||
}
|
||||
|
||||
void moz_container_set_scale_factor(MozContainer* container) {
|
||||
MutexAutoLock lock(*container->container_lock);
|
||||
moz_container_set_scale_factor_locked(container);
|
||||
}
|
||||
|
||||
static struct wl_surface* moz_container_get_wl_surface_locked(
|
||||
MozContainer* container, nsWaylandDisplay* aWaylandDisplay) {
|
||||
LOGWAYLAND(("%s [%p] surface %p ready_to_draw %d\n", __FUNCTION__,
|
||||
(void*)container, (void*)container->surface,
|
||||
container->ready_to_draw));
|
||||
|
||||
if (!container->surface) {
|
||||
if (!container->ready_to_draw) {
|
||||
moz_container_request_parent_frame_callback(container);
|
||||
return nullptr;
|
||||
}
|
||||
wl_surface* parent_surface =
|
||||
moz_gtk_widget_get_wl_surface(GTK_WIDGET(container));
|
||||
if (!parent_surface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Available as of GTK 3.8+
|
||||
struct wl_compositor* compositor = aWaylandDisplay->GetCompositor();
|
||||
container->surface = wl_compositor_create_surface(compositor);
|
||||
if (!container->surface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
container->subsurface =
|
||||
wl_subcompositor_get_subsurface(aWaylandDisplay->GetSubcompositor(),
|
||||
container->surface, parent_surface);
|
||||
if (!container->subsurface) {
|
||||
g_clear_pointer(&container->surface, wl_surface_destroy);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
|
||||
gint x, y;
|
||||
gdk_window_get_position(window, &x, &y);
|
||||
moz_container_move_locked(container, x, y);
|
||||
wl_subsurface_set_desync(container->subsurface);
|
||||
|
||||
// Route input to parent wl_surface owned by Gtk+ so we get input
|
||||
// events from Gtk+.
|
||||
wl_region* region = wl_compositor_create_region(compositor);
|
||||
wl_surface_set_input_region(container->surface, region);
|
||||
wl_region_destroy(region);
|
||||
|
||||
wl_surface_commit(container->surface);
|
||||
wl_display_flush(aWaylandDisplay->GetDisplay());
|
||||
|
||||
LOGWAYLAND(("%s [%p] created surface %p\n", __FUNCTION__, (void*)container,
|
||||
(void*)container->surface));
|
||||
}
|
||||
|
||||
if (container->surface_position_needs_update) {
|
||||
moz_container_move_locked(container, container->subsurface_dx,
|
||||
container->subsurface_dy);
|
||||
}
|
||||
|
||||
moz_container_set_opaque_region_locked(container);
|
||||
moz_container_set_scale_factor_locked(container);
|
||||
|
||||
return container->surface;
|
||||
}
|
||||
|
||||
struct wl_surface* moz_container_get_wl_surface(MozContainer* container) {
|
||||
GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(container));
|
||||
nsWaylandDisplay* waylandDisplay = WaylandDisplayGet(display);
|
||||
|
||||
LOGWAYLAND(("%s [%p] surface %p\n", __FUNCTION__, (void*)container,
|
||||
(void*)container->surface));
|
||||
|
||||
MutexAutoLock lock(*container->container_lock);
|
||||
return moz_container_get_wl_surface_locked(container, waylandDisplay);
|
||||
}
|
||||
|
||||
struct wl_egl_window* moz_container_get_wl_egl_window(MozContainer* container,
|
||||
int scale) {
|
||||
GdkDisplay* display = gtk_widget_get_display(GTK_WIDGET(container));
|
||||
nsWaylandDisplay* waylandDisplay = WaylandDisplayGet(display);
|
||||
|
||||
LOGWAYLAND(("%s [%p] eglwindow %p\n", __FUNCTION__, (void*)container,
|
||||
(void*)container->eglwindow));
|
||||
|
||||
MutexAutoLock lock(*container->container_lock);
|
||||
|
||||
// Always call moz_container_get_wl_surface() to ensure underlying
|
||||
// container->surface has correct scale and position.
|
||||
wl_surface* surface =
|
||||
moz_container_get_wl_surface_locked(container, waylandDisplay);
|
||||
if (!surface) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!container->eglwindow) {
|
||||
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(container));
|
||||
container->eglwindow =
|
||||
wl_egl_window_create(surface, gdk_window_get_width(window) * scale,
|
||||
gdk_window_get_height(window) * scale);
|
||||
|
||||
LOGWAYLAND(("%s [%p] created eglwindow %p\n", __FUNCTION__,
|
||||
(void*)container, (void*)container->eglwindow));
|
||||
}
|
||||
|
||||
return container->eglwindow;
|
||||
}
|
||||
|
||||
gboolean moz_container_has_wl_egl_window(MozContainer* container) {
|
||||
return container->eglwindow ? true : false;
|
||||
}
|
||||
|
||||
gboolean moz_container_surface_needs_clear(MozContainer* container) {
|
||||
int ret = container->surface_needs_clear;
|
||||
container->surface_needs_clear = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void moz_container_update_opaque_region(MozContainer* container,
|
||||
bool aSubtractCorners,
|
||||
bool aFullScreen) {
|
||||
container->opaque_region_needs_update = true;
|
||||
container->opaque_region_subtract_corners = aSubtractCorners;
|
||||
container->opaque_region_fullscreen = aFullScreen;
|
||||
|
||||
// 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 (moz_container_has_wl_egl_window(container)) {
|
||||
moz_container_set_opaque_region(container);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void moz_container_force_default_visual(MozContainer* container) {
|
||||
container->force_default_visual = true;
|
||||
}
|
|
@ -279,7 +279,7 @@ void nsAppShell::ScheduleNativeEventCallback() {
|
|||
bool nsAppShell::ProcessNextNativeEvent(bool mayWait) {
|
||||
bool ret = g_main_context_iteration(nullptr, mayWait);
|
||||
#ifdef MOZ_WAYLAND
|
||||
WaylandDispatchDisplays();
|
||||
mozilla::widget::WaylandDispatchDisplays();
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -658,7 +658,7 @@ bool nsRetrievalContextWayland::HasSelectionSupport(void) {
|
|||
|
||||
nsRetrievalContextWayland::nsRetrievalContextWayland(void)
|
||||
: mInitialized(false),
|
||||
mDisplay(WaylandDisplayGet()),
|
||||
mDisplay(mozilla::widget::WaylandDisplayGet()),
|
||||
mActiveOffers(g_hash_table_new(NULL, NULL)),
|
||||
mClipboardOffer(nullptr),
|
||||
mPrimaryOffer(nullptr),
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "mozcontainer.h"
|
||||
#include "MozContainer.h"
|
||||
|
||||
#include "nsFilePicker.h"
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#include "mozcontainer.h"
|
||||
#include "MozContainer.h"
|
||||
#include "nsIPrintSettings.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsPrintDialogGTK.h"
|
||||
|
|
|
@ -2258,7 +2258,8 @@ void* nsWindow::GetNativeData(uint32_t aDataType) {
|
|||
}
|
||||
#ifdef MOZ_WAYLAND
|
||||
if (mContainer) {
|
||||
return moz_container_get_wl_egl_window(mContainer, GdkScaleFactor());
|
||||
return moz_container_wayland_get_egl_window(mContainer,
|
||||
GdkScaleFactor());
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
|
@ -2586,7 +2587,9 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) {
|
|||
// Windows that are not visible will be painted after they become visible.
|
||||
if (!mGdkWindow || mIsFullyObscured || !mHasMappedToplevel) return FALSE;
|
||||
#ifdef MOZ_WAYLAND
|
||||
if (mContainer && !mContainer->ready_to_draw) return FALSE;
|
||||
if (!moz_container_wayland_can_draw(mContainer)) {
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
nsIWidgetListener* listener = GetListener();
|
||||
|
@ -3911,8 +3914,8 @@ void nsWindow::OnScaleChanged(GtkAllocation* aAllocation) {
|
|||
#ifdef MOZ_WAYLAND
|
||||
// We need to update scale and opaque region when scale of egl window
|
||||
// is changed.
|
||||
if (mContainer && moz_container_has_wl_egl_window(mContainer)) {
|
||||
moz_container_set_scale_factor(mContainer);
|
||||
if (mContainer && moz_container_wayland_has_egl_window(mContainer)) {
|
||||
moz_container_wayland_set_scale_factor(mContainer);
|
||||
LayoutDeviceIntRegion tmpRegion;
|
||||
UpdateOpaqueRegion(tmpRegion);
|
||||
}
|
||||
|
@ -4359,10 +4362,11 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
|
|||
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_wayland_add_initial_draw_callback(
|
||||
mContainer, [self]() -> void {
|
||||
self->mNeedsCompositorResume = true;
|
||||
self->MaybeResumeCompositor();
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -4833,7 +4837,7 @@ void nsWindow::NativeMoveResize() {
|
|||
void nsWindow::PauseRemoteRenderer() {
|
||||
#ifdef MOZ_WAYLAND
|
||||
if (!mIsDestroyed) {
|
||||
if (mContainer && moz_container_has_wl_egl_window(mContainer)) {
|
||||
if (mContainer && moz_container_wayland_has_egl_window(mContainer)) {
|
||||
// Because wl_egl_window is destroyed on moz_container_unmap(),
|
||||
// the current compositor cannot use it anymore. To avoid crash,
|
||||
// pause the compositor and destroy EGLSurface & resume the compositor
|
||||
|
@ -4844,10 +4848,11 @@ void nsWindow::PauseRemoteRenderer() {
|
|||
remoteRenderer->SendPause();
|
||||
// Re-request initial draw callback
|
||||
RefPtr<nsWindow> self(this);
|
||||
moz_container_add_initial_draw_callback(mContainer, [self]() -> void {
|
||||
self->mNeedsCompositorResume = true;
|
||||
self->MaybeResumeCompositor();
|
||||
});
|
||||
moz_container_wayland_add_initial_draw_callback(
|
||||
mContainer, [self]() -> void {
|
||||
self->mNeedsCompositorResume = true;
|
||||
self->MaybeResumeCompositor();
|
||||
});
|
||||
} else {
|
||||
DestroyLayerManager();
|
||||
}
|
||||
|
@ -4888,7 +4893,7 @@ void nsWindow::WaylandStartVsync() {
|
|||
// The widget is going to be shown, so reconfigure the surface
|
||||
// of our vsync source.
|
||||
RefPtr<nsWindow> self(this);
|
||||
moz_container_add_initial_draw_callback(mContainer, [self]() -> void {
|
||||
moz_container_wayland_add_initial_draw_callback(mContainer, [self]() -> void {
|
||||
WaylandVsyncSource::WaylandDisplay& display =
|
||||
static_cast<WaylandVsyncSource::WaylandDisplay&>(
|
||||
self->mWaylandVsyncSource->GetGlobalDisplay());
|
||||
|
@ -7855,7 +7860,7 @@ void nsWindow::GetCompositorWidgetInitData(
|
|||
#ifdef MOZ_WAYLAND
|
||||
wl_surface* nsWindow::GetWaylandSurface() {
|
||||
if (mContainer) {
|
||||
return moz_container_get_wl_surface(MOZ_CONTAINER(mContainer));
|
||||
return moz_container_wayland_get_surface(MOZ_CONTAINER(mContainer));
|
||||
}
|
||||
|
||||
NS_WARNING(
|
||||
|
@ -7866,7 +7871,7 @@ wl_surface* nsWindow::GetWaylandSurface() {
|
|||
|
||||
bool nsWindow::WaylandSurfaceNeedsClear() {
|
||||
if (mContainer) {
|
||||
return moz_container_surface_needs_clear(MOZ_CONTAINER(mContainer));
|
||||
return moz_container_wayland_surface_needs_clear(MOZ_CONTAINER(mContainer));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -8167,8 +8172,8 @@ nsresult nsWindow::ResetPrefersReducedMotionOverrideForTest() {
|
|||
void nsWindow::SetEGLNativeWindowSize(
|
||||
const LayoutDeviceIntSize& aEGLWindowSize) {
|
||||
if (mContainer && !mIsX11Display) {
|
||||
moz_container_egl_window_set_size(mContainer, aEGLWindowSize.width,
|
||||
aEGLWindowSize.height);
|
||||
moz_container_wayland_egl_window_set_size(mContainer, aEGLWindowSize.width,
|
||||
aEGLWindowSize.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
# include "base/thread.h"
|
||||
# include "WaylandVsyncSource.h"
|
||||
#endif
|
||||
#include "mozcontainer.h"
|
||||
#include "MozContainer.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsIDragService.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче