[mutter/wip/garnacho/wayland-emulated-output-transform: 11/13] backends/native: Add back texture for the transformed MetaRendererViews



commit c597e458c91448adbc8985ece9543fc38bebc35a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 1 03:48:30 2016 +0200

    backends/native: Add back texture for the transformed MetaRendererViews
    
    The texture is only created if the view is transformed at the software level,
    otherwise the texture is NULL, and rendering happens on the onscreen.

 src/backends/native/meta-renderer-native.c |   71 ++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 48a5dba..b875b25 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -908,6 +908,36 @@ meta_renderer_native_create_onscreen (MetaRendererNative    *renderer,
   return TRUE;
 }
 
+static gboolean
+meta_renderer_native_maybe_create_texture (MetaRendererNative    *renderer,
+                                           CoglContext           *context,
+                                           MetaMonitorTransform   transform,
+                                           gint                   view_width,
+                                           gint                   view_height,
+                                           CoglTexture2D        **texture,
+                                           GError               **error)
+{
+  CoglTexture2D *tex;
+
+  *texture = NULL;
+
+  if (transform == META_MONITOR_TRANSFORM_NORMAL)
+    return TRUE;
+
+  tex = cogl_texture_2d_new_with_size (context, view_width, view_height);
+  cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex), FALSE);
+
+  if (!cogl_texture_allocate (COGL_TEXTURE (tex), error))
+    {
+      cogl_object_unref (tex);
+      return FALSE;
+    }
+
+  *texture = tex;
+
+  return TRUE;
+}
+
 gboolean
 meta_renderer_native_set_legacy_view_size (MetaRendererNative *renderer_native,
                                            MetaRendererView   *view,
@@ -941,6 +971,7 @@ meta_renderer_native_set_legacy_view_size (MetaRendererNative *renderer_native,
       EGLSurface new_egl_surface;
       cairo_rectangle_int_t view_layout;
       MetaMonitorTransform transform;
+      CoglTexture2D *texture = NULL;
 
       /*
        * Ensure we don't have any pending flips that will want
@@ -989,6 +1020,14 @@ meta_renderer_native_set_legacy_view_size (MetaRendererNative *renderer_native,
                                      egl_onscreen->egl_surface,
                                      egl_display->egl_context);
 
+      if (!meta_renderer_native_maybe_create_texture (renderer_native,
+                                                      cogl_context,
+                                                      transform,
+                                                      width, height,
+                                                      &texture,
+                                                      error))
+        return FALSE;
+
       view_layout = (cairo_rectangle_int_t) {
         .width = width,
         .height = height
@@ -996,12 +1035,15 @@ meta_renderer_native_set_legacy_view_size (MetaRendererNative *renderer_native,
       g_object_set (G_OBJECT (view),
                     "layout", &view_layout,
                     "transform", transform,
+                    "back-texture", texture,
                     NULL);
 
       if (!meta_monitor_transform_is_rotated (transform))
         _cogl_framebuffer_winsys_update_size (framebuffer, width, height);
       else
         _cogl_framebuffer_winsys_update_size (framebuffer, height, width);
+
+      g_clear_pointer (&texture, cogl_object_unref);
     }
 
   meta_renderer_native_queue_modes_reset (renderer_native);
@@ -1078,6 +1120,7 @@ meta_renderer_native_create_legacy_view (MetaRendererNative *renderer_native)
   CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
   cairo_rectangle_int_t view_layout = { 0 };
   MetaMonitorTransform transform;
+  CoglTexture2D *texture;
   MetaRendererView *view;
   GError *error = NULL;
 
@@ -1089,6 +1132,17 @@ meta_renderer_native_create_legacy_view (MetaRendererNative *renderer_native)
                                         &view_layout.width,
                                         &view_layout.height);
 
+  if (!meta_renderer_native_maybe_create_texture (renderer_native,
+                                                  cogl_context,
+                                                  transform,
+                                                  view_layout.width,
+                                                  view_layout.height,
+                                                  &texture,
+                                                  &error))
+    {
+      meta_fatal ("Failed to allocate back buffer texture: %s\n",
+                  error->message);
+    }
 
   if (!meta_renderer_native_create_onscreen (renderer_native,
                                              cogl_context,
@@ -1105,9 +1159,11 @@ meta_renderer_native_create_legacy_view (MetaRendererNative *renderer_native)
   view = g_object_new (META_TYPE_RENDERER_VIEW,
                        "layout", &view_layout,
                        "framebuffer", onscreen,
+                       "back-texture", texture,
                        "transform", transform,
                        NULL);
   cogl_object_unref (onscreen);
+  g_clear_pointer (&texture, cogl_object_unref);
 
   meta_onscreen_native_set_view (onscreen, view);
 
@@ -1123,12 +1179,25 @@ meta_renderer_native_create_view (MetaRenderer    *renderer,
   CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
   MetaMonitorTransform transform;
   CoglOnscreen *onscreen;
+  CoglTexture2D *texture = NULL;
   MetaRendererView *view;
   GError *error = NULL;
 
   transform = meta_renderer_native_get_monitor_info_transform (renderer,
                                                                monitor_info);
 
+  if (!meta_renderer_native_maybe_create_texture (META_RENDERER_NATIVE (renderer),
+                                                  cogl_context,
+                                                  transform,
+                                                  monitor_info->rect.width,
+                                                  monitor_info->rect.height,
+                                                  &texture,
+                                                  &error))
+    {
+      meta_fatal ("Failed to allocate back buffer texture: %s\n",
+                  error->message);
+    }
+
   if (!meta_renderer_native_create_onscreen (META_RENDERER_NATIVE (renderer),
                                              cogl_context,
                                              transform,
@@ -1146,8 +1215,10 @@ meta_renderer_native_create_view (MetaRenderer    *renderer,
                        "framebuffer", onscreen,
                        "monitor-info", monitor_info,
                        "transform", transform,
+                       "back-texture", texture,
                        NULL);
   cogl_object_unref (onscreen);
+  g_clear_pointer (&texture, cogl_object_unref);
 
   meta_onscreen_native_set_view (onscreen, view);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]