<p dir="ltr">This one is also a good idea. Removes code duplication and keeps the surface size calculations in compositor.c where they belong.<br>
--Jason Ekstrand</p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>></p>
<div class="gmail_quote">On Nov 26, 2013 11:20 AM, "Jonny Lamb" <<a href="mailto:jonny.lamb@collabora.co.uk">jonny.lamb@collabora.co.uk</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Pekka Paalanen <<a href="mailto:pekka.paalanen@collabora.co.uk">pekka.paalanen@collabora.co.uk</a>><br>
<br>
Replace the two functions getting the intended surface dimensions from<br>
the surface's buffer and buffer transformation parameters by a single<br>
function that just set the surface size according to all the buffer<br>
state.<br>
<br>
The old functions were always called in pairs, and always assigned to<br>
the surface dimension variables.<br>
<br>
This function also deals with a NULL buffer by setting the dimensions to<br>
zero, just like the callers used to do.<br>
<br>
The new function has no users outside this source file, so do not export<br>
it. This basically unexports the old functions.<br>
---<br>
src/compositor.c | 52 +++++++++++++++++-----------------------------------<br>
src/compositor.h | 4 ----<br>
2 files changed, 17 insertions(+), 39 deletions(-)<br>
<br>
diff --git a/src/compositor.c b/src/compositor.c<br>
index b6f2966..bead369 100644<br>
--- a/src/compositor.c<br>
+++ b/src/compositor.c<br>
@@ -1141,40 +1141,33 @@ weston_surface_is_mapped(struct weston_surface *surface)<br>
return 0;<br>
}<br>
<br>
-WL_EXPORT int32_t<br>
-weston_surface_buffer_width(struct weston_surface *surface)<br>
+static void<br>
+weston_surface_set_size_from_buffer(struct weston_surface *surface)<br>
{<br>
- int32_t width;<br>
- switch (surface->buffer_viewport.transform) {<br>
- case WL_OUTPUT_TRANSFORM_90:<br>
- case WL_OUTPUT_TRANSFORM_270:<br>
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:<br>
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:<br>
- width = surface->buffer_ref.buffer->height;<br>
- break;<br>
- default:<br>
- width = surface->buffer_ref.buffer->width;<br>
- break;<br>
+ int32_t width, height;<br>
+<br>
+ if (!surface->buffer_ref.buffer) {<br>
+ surface->width = 0;<br>
+ surface->height = 0;<br>
+ return;<br>
}<br>
- return width / surface->buffer_viewport.scale;<br>
-}<br>
<br>
-WL_EXPORT int32_t<br>
-weston_surface_buffer_height(struct weston_surface *surface)<br>
-{<br>
- int32_t height;<br>
switch (surface->buffer_viewport.transform) {<br>
case WL_OUTPUT_TRANSFORM_90:<br>
case WL_OUTPUT_TRANSFORM_270:<br>
case WL_OUTPUT_TRANSFORM_FLIPPED_90:<br>
case WL_OUTPUT_TRANSFORM_FLIPPED_270:<br>
+ width = surface->buffer_ref.buffer->height;<br>
height = surface->buffer_ref.buffer->width;<br>
- break;<br>
+ break;<br>
default:<br>
+ width = surface->buffer_ref.buffer->width;<br>
height = surface->buffer_ref.buffer->height;<br>
- break;<br>
+ break;<br>
}<br>
- return height / surface->buffer_viewport.scale;<br>
+<br>
+ surface->width = width / surface->buffer_viewport.scale;<br>
+ surface->height = height / surface->buffer_viewport.scale;<br>
}<br>
<br>
WL_EXPORT uint32_t<br>
@@ -1970,13 +1963,7 @@ weston_surface_commit(struct weston_surface *surface)<br>
if (surface->pending.buffer || surface->pending.newly_attached)<br>
weston_surface_attach(surface, surface->pending.buffer);<br>
<br>
- surface->width = 0;<br>
- surface->height = 0;<br>
- if (surface->buffer_ref.buffer) {<br>
- /* This already includes the buffer scale */<br>
- surface->width = weston_surface_buffer_width(surface);<br>
- surface->height = weston_surface_buffer_height(surface);<br>
- }<br>
+ weston_surface_set_size_from_buffer(surface);<br>
<br>
if (surface->configure && surface->pending.newly_attached)<br>
surface->configure(surface,<br>
@@ -2203,12 +2190,7 @@ weston_subsurface_commit_from_cache(struct weston_subsurface *sub)<br>
weston_surface_attach(surface, sub->cached.buffer_ref.buffer);<br>
weston_buffer_reference(&sub->cached.buffer_ref, NULL);<br>
<br>
- surface->width = 0;<br>
- surface->height = 0;<br>
- if (surface->buffer_ref.buffer) {<br>
- surface->width = weston_surface_buffer_width(surface);<br>
- surface->height = weston_surface_buffer_height(surface);<br>
- }<br>
+ weston_surface_set_size_from_buffer(surface);<br>
<br>
if (surface->configure && sub->cached.newly_attached)<br>
surface->configure(surface, sub->cached.sx, sub-><a href="http://cached.sy" target="_blank">cached.sy</a>,<br>
diff --git a/src/compositor.h b/src/compositor.h<br>
index e445dc3..e31d7db 100644<br>
--- a/src/compositor.h<br>
+++ b/src/compositor.h<br>
@@ -918,10 +918,6 @@ void<br>
weston_view_from_global_fixed(struct weston_view *view,<br>
wl_fixed_t x, wl_fixed_t y,<br>
wl_fixed_t *vx, wl_fixed_t *vy);<br>
-int32_t<br>
-weston_surface_buffer_width(struct weston_surface *surface);<br>
-int32_t<br>
-weston_surface_buffer_height(struct weston_surface *surface);<br>
<br>
WL_EXPORT void<br>
weston_surface_to_buffer_float(struct weston_surface *surface,<br>
--<br>
1.8.4.2<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</blockquote></div>