MetaSurfaceActorWayland: Only NULL check surface on class vfuncs

The only time the surface pointer (priv->surface) may be NULL is when
the surface is unmanaged but still painting, possibly due to a unmap
animation or the like, so only guard handle this situation in the entry
points that may come from the stage painting.

https://bugzilla.gnome.org/show_bug.cgi?id=763431
This commit is contained in:
Jonas Ådahl 2016-01-18 16:56:27 +08:00
parent bca041b68e
commit 26815d68f6

View File

@ -93,15 +93,13 @@ meta_surface_actor_wayland_is_unredirected (MetaSurfaceActor *actor)
} }
double double
meta_surface_actor_wayland_get_scale (MetaSurfaceActorWayland *actor) meta_surface_actor_wayland_get_scale (MetaSurfaceActorWayland *self)
{ {
MetaSurfaceActorWaylandPrivate *priv = meta_surface_actor_wayland_get_instance_private (actor); MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self);
MetaWaylandSurface *surface = priv->surface;
MetaWindow *window; MetaWindow *window;
int output_scale = 1; int output_scale = 1;
if (!surface) g_assert (surface);
return 1;
window = meta_wayland_surface_get_toplevel_window (surface); window = meta_wayland_surface_get_toplevel_window (surface);
@ -109,7 +107,7 @@ meta_surface_actor_wayland_get_scale (MetaSurfaceActorWayland *actor)
if (window && window->client_type != META_WINDOW_CLIENT_TYPE_X11) if (window && window->client_type != META_WINDOW_CLIENT_TYPE_X11)
output_scale = meta_window_wayland_get_main_monitor_scale (window); output_scale = meta_window_wayland_get_main_monitor_scale (window);
return (double)output_scale / (double)priv->surface->scale; return (double) output_scale / (double) surface->scale;
} }
static void static void
@ -121,6 +119,8 @@ logical_to_actor_position (MetaSurfaceActorWayland *self,
MetaWindow *toplevel_window; MetaWindow *toplevel_window;
int monitor_scale = 1; int monitor_scale = 1;
g_assert (surface);
toplevel_window = meta_wayland_surface_get_toplevel_window (surface); toplevel_window = meta_wayland_surface_get_toplevel_window (surface);
if (toplevel_window) if (toplevel_window)
monitor_scale = meta_window_wayland_get_main_monitor_scale (toplevel_window); monitor_scale = meta_window_wayland_get_main_monitor_scale (toplevel_window);
@ -137,11 +137,14 @@ meta_surface_actor_wayland_get_subsurface_rect (MetaSurfaceActorWayland *self,
{ {
MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self); MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self);
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface); MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
CoglTexture *texture = buffer->texture; CoglTexture *texture;
MetaWindow *toplevel_window; MetaWindow *toplevel_window;
int monitor_scale; int monitor_scale;
float x, y; float x, y;
g_assert (surface);
texture = buffer->texture;
toplevel_window = meta_wayland_surface_get_toplevel_window (surface); toplevel_window = meta_wayland_surface_get_toplevel_window (surface);
monitor_scale = meta_window_wayland_get_main_monitor_scale (toplevel_window); monitor_scale = meta_window_wayland_get_main_monitor_scale (toplevel_window);
@ -162,6 +165,8 @@ meta_surface_actor_wayland_sync_subsurface_state (MetaSurfaceActorWayland *self)
int x = surface->offset_x + surface->sub.x; int x = surface->offset_x + surface->sub.x;
int y = surface->offset_y + surface->sub.y; int y = surface->offset_y + surface->sub.y;
g_assert (surface);
window = meta_wayland_surface_get_toplevel_window (surface); window = meta_wayland_surface_get_toplevel_window (surface);
if (window && window->client_type == META_WINDOW_CLIENT_TYPE_X11) if (window && window->client_type == META_WINDOW_CLIENT_TYPE_X11)
{ {
@ -184,6 +189,8 @@ meta_surface_actor_wayland_sync_state (MetaSurfaceActorWayland *self)
meta_surface_actor_get_texture (META_SURFACE_ACTOR (self)); meta_surface_actor_get_texture (META_SURFACE_ACTOR (self));
double texture_scale; double texture_scale;
g_assert (surface);
/* Given the surface's window type and what output the surface actor has the /* Given the surface's window type and what output the surface actor has the
* largest region, scale the actor with the determined scale. */ * largest region, scale the actor with the determined scale. */
texture_scale = meta_surface_actor_wayland_get_scale (self); texture_scale = meta_surface_actor_wayland_get_scale (self);
@ -238,9 +245,12 @@ void
meta_surface_actor_wayland_sync_state_recursive (MetaSurfaceActorWayland *self) meta_surface_actor_wayland_sync_state_recursive (MetaSurfaceActorWayland *self)
{ {
MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self); MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self);
MetaWindow *window = meta_wayland_surface_get_toplevel_window (surface); MetaWindow *window;
GList *iter; GList *iter;
g_assert (surface);
window = meta_wayland_surface_get_toplevel_window (surface);
meta_surface_actor_wayland_sync_state (self); meta_surface_actor_wayland_sync_state (self);
if (window && window->client_type != META_WINDOW_CLIENT_TYPE_X11) if (window && window->client_type != META_WINDOW_CLIENT_TYPE_X11)
@ -301,8 +311,8 @@ meta_surface_actor_wayland_add_frame_callbacks (MetaSurfaceActorWayland *self,
static MetaWindow * static MetaWindow *
meta_surface_actor_wayland_get_window (MetaSurfaceActor *actor) meta_surface_actor_wayland_get_window (MetaSurfaceActor *actor)
{ {
MetaSurfaceActorWaylandPrivate *priv = meta_surface_actor_wayland_get_instance_private (META_SURFACE_ACTOR_WAYLAND (actor)); MetaSurfaceActorWayland *self = META_SURFACE_ACTOR_WAYLAND (actor);
MetaWaylandSurface *surface = priv->surface; MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self);
if (!surface) if (!surface)
return NULL; return NULL;
@ -311,15 +321,26 @@ meta_surface_actor_wayland_get_window (MetaSurfaceActor *actor)
} }
static void static void
meta_surface_actor_wayland_get_preferred_width (ClutterActor *self, meta_surface_actor_wayland_get_preferred_width (ClutterActor *actor,
gfloat for_height, gfloat for_height,
gfloat *min_width_p, gfloat *min_width_p,
gfloat *natural_width_p) gfloat *natural_width_p)
{ {
MetaShapedTexture *stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self)); MetaSurfaceActorWayland *self = META_SURFACE_ACTOR_WAYLAND (actor);
double scale = meta_surface_actor_wayland_get_scale (META_SURFACE_ACTOR_WAYLAND (self)); MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self);
MetaShapedTexture *stex;
double scale;
clutter_actor_get_preferred_width (CLUTTER_ACTOR (stex), for_height, min_width_p, natural_width_p); if (surface)
scale = meta_surface_actor_wayland_get_scale (self);
else
scale = 1.0;
stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self));
clutter_actor_get_preferred_width (CLUTTER_ACTOR (stex),
for_height,
min_width_p,
natural_width_p);
if (min_width_p) if (min_width_p)
*min_width_p *= scale; *min_width_p *= scale;
@ -329,15 +350,26 @@ meta_surface_actor_wayland_get_preferred_width (ClutterActor *self,
} }
static void static void
meta_surface_actor_wayland_get_preferred_height (ClutterActor *self, meta_surface_actor_wayland_get_preferred_height (ClutterActor *actor,
gfloat for_width, gfloat for_width,
gfloat *min_height_p, gfloat *min_height_p,
gfloat *natural_height_p) gfloat *natural_height_p)
{ {
MetaShapedTexture *stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self)); MetaSurfaceActorWayland *self = META_SURFACE_ACTOR_WAYLAND (actor);
double scale = meta_surface_actor_wayland_get_scale (META_SURFACE_ACTOR_WAYLAND (self)); MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (self);
MetaShapedTexture *stex;
double scale;
clutter_actor_get_preferred_height (CLUTTER_ACTOR (stex), for_width, min_height_p, natural_height_p); if (surface)
scale = meta_surface_actor_wayland_get_scale (self);
else
scale = 1.0;
stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self));
clutter_actor_get_preferred_height (CLUTTER_ACTOR (stex),
for_width,
min_height_p,
natural_height_p);
if (min_height_p) if (min_height_p)
*min_height_p *= scale; *min_height_p *= scale;