[mutter/wip/garnacho/wayland-emulated-output-transform: 32/34] backends/native: Refactor onscreen creation into separate function



commit dfda0b43594afa2322e766b9a59523ddf4855e0b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 1 03:47:11 2016 +0200

    backends/native: Refactor onscreen creation into separate function
    
    And use the right size, regarless of view transform.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745079

 src/backends/native/meta-renderer-native.c |   92 +++++++++++++++++++--------
 1 files changed, 65 insertions(+), 27 deletions(-)
---
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index f894fdd..1fdcbd3 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -850,6 +850,43 @@ meta_renderer_native_get_monitor_info_transform (MetaRenderer    *renderer,
                                                       monitor_info->outputs[0]->crtc);
 }
 
+static gboolean
+meta_renderer_native_create_onscreen (MetaRendererNative    *renderer,
+                                      CoglContext           *context,
+                                      MetaMonitorTransform   transform,
+                                      gint                   view_width,
+                                      gint                   view_height,
+                                      CoglOnscreen         **onscreen,
+                                      GError               **error)
+{
+  CoglOnscreen *new_onscreen;
+  gint width, height;
+
+  if (meta_monitor_transform_is_rotated (transform))
+    {
+      width = view_height;
+      height = view_width;
+    }
+  else
+    {
+      width = view_width;
+      height = view_height;
+    }
+
+  new_onscreen = cogl_onscreen_new (context, width, height);
+  cogl_onscreen_set_swap_throttled (new_onscreen,
+                                    _clutter_get_sync_to_vblank ());
+
+  if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (new_onscreen), error))
+    {
+      cogl_object_unref (new_onscreen);
+      return FALSE;
+    }
+
+  *onscreen = new_onscreen;
+  return TRUE;
+}
+
 gboolean
 meta_renderer_native_set_legacy_view_size (MetaRendererNative *renderer_native,
                                            MetaRendererView   *view,
@@ -1008,8 +1045,7 @@ meta_renderer_native_create_legacy_view (MetaRendererNative *renderer_native)
   MetaBackend *backend = meta_get_backend ();
   MetaMonitorManager *monitor_manager =
     meta_backend_get_monitor_manager (backend);
-  CoglOnscreen *onscreen;
-  CoglFramebuffer *framebuffer;
+  CoglOnscreen *onscreen = NULL;
   ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
   CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
   cairo_rectangle_int_t view_layout = { 0 };
@@ -1023,22 +1059,23 @@ meta_renderer_native_create_legacy_view (MetaRendererNative *renderer_native)
                                         &view_layout.width,
                                         &view_layout.height);
 
-  onscreen = cogl_onscreen_new (cogl_context,
-                                view_layout.width,
-                                view_layout.height);
-  cogl_onscreen_set_swap_throttled (onscreen,
-                                    _clutter_get_sync_to_vblank ());
-
-  framebuffer = COGL_FRAMEBUFFER (onscreen);
-  if (!cogl_framebuffer_allocate (framebuffer, &error))
-    meta_fatal ("Failed to allocate onscreen framebuffer: %s\n",
-                error->message);
+  if (!meta_renderer_native_create_onscreen (renderer_native,
+                                             cogl_context,
+                                             META_MONITOR_TRANSFORM_NORMAL,
+                                             view_layout.width,
+                                             view_layout.height,
+                                             &onscreen,
+                                             &error))
+    {
+      meta_fatal ("Failed to allocate onscreen framebuffer: %s\n",
+                  error->message);
+    }
 
   view = g_object_new (META_TYPE_RENDERER_VIEW,
                        "layout", &view_layout,
-                       "framebuffer", framebuffer,
+                       "framebuffer", onscreen,
                        NULL);
-  cogl_object_unref (framebuffer);
+  cogl_object_unref (onscreen);
 
   meta_onscreen_native_set_view (onscreen, view);
 
@@ -1053,31 +1090,32 @@ meta_renderer_native_create_view (MetaRenderer    *renderer,
   ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
   CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
   MetaMonitorTransform transform;
-  CoglOnscreen *onscreen;
-  CoglFramebuffer *framebuffer;
+  CoglOnscreen *onscreen = NULL;
   MetaRendererView *view;
   GError *error = NULL;
 
   transform = meta_renderer_native_get_monitor_info_transform (renderer,
                                                                monitor_info);
-  onscreen = cogl_onscreen_new (cogl_context,
-                                monitor_info->rect.width,
-                                monitor_info->rect.height);
-  cogl_onscreen_set_swap_throttled (onscreen,
-                                    _clutter_get_sync_to_vblank ());
 
-  framebuffer = COGL_FRAMEBUFFER (onscreen);
-  if (!cogl_framebuffer_allocate (framebuffer, &error))
-    meta_fatal ("Failed to allocate onscreen framebuffer: %s\n",
-                error->message);
+  if (!meta_renderer_native_create_onscreen (META_RENDERER_NATIVE (renderer),
+                                             cogl_context,
+                                             transform,
+                                             monitor_info->rect.width,
+                                             monitor_info->rect.height,
+                                             &onscreen,
+                                             &error))
+    {
+      meta_fatal ("Failed to allocate onscreen framebuffer: %s\n",
+                  error->message);
+    }
 
   view = g_object_new (META_TYPE_RENDERER_VIEW,
                        "layout", &monitor_info->rect,
-                       "framebuffer", framebuffer,
+                       "framebuffer", onscreen,
                        "monitor-info", monitor_info,
                        "transform", transform,
                        NULL);
-  cogl_object_unref (framebuffer);
+  cogl_object_unref (onscreen);
 
   meta_onscreen_native_set_view (onscreen, view);
 


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