From 1abd930c56b6f9e5f1861c3351723814ce41459c Mon Sep 17 00:00:00 2001 From: Dor Askayo Date: Fri, 10 Jul 2020 18:40:07 +0300 Subject: [PATCH] backends/native: Introduce MetaRendererViewNative MetaRendererViewNative is a MetaRendererView which contains logic specific to views of the native backend. It will be used by following commits. In the future, per-view logic from MetaRendererNative can be moved to MetaRendererViewNative where it makes more sense to have it. Part-of: --- src/backends/meta-renderer-view.c | 46 +++++++++++++------ src/backends/meta-renderer-view.h | 11 +++-- src/backends/native/meta-renderer-native.c | 34 +++++++------- .../native/meta-renderer-view-native.c | 43 +++++++++++++++++ .../native/meta-renderer-view-native.h | 34 ++++++++++++++ src/meson.build | 2 + 6 files changed, 136 insertions(+), 34 deletions(-) create mode 100644 src/backends/native/meta-renderer-view-native.c create mode 100644 src/backends/native/meta-renderer-view-native.h diff --git a/src/backends/meta-renderer-view.c b/src/backends/meta-renderer-view.c index 6064f2c82..b974fcbde 100644 --- a/src/backends/meta-renderer-view.c +++ b/src/backends/meta-renderer-view.c @@ -49,28 +49,32 @@ enum static GParamSpec *obj_props[PROP_LAST]; -struct _MetaRendererView +typedef struct _MetaRendererViewPrivate { - MetaStageView parent; - MetaMonitorTransform transform; MetaCrtc *crtc; -}; +} MetaRendererViewPrivate; -G_DEFINE_TYPE (MetaRendererView, meta_renderer_view, - META_TYPE_STAGE_VIEW) +G_DEFINE_TYPE_WITH_PRIVATE (MetaRendererView, meta_renderer_view, + META_TYPE_STAGE_VIEW) MetaMonitorTransform meta_renderer_view_get_transform (MetaRendererView *view) { - return view->transform; + MetaRendererViewPrivate *priv = + meta_renderer_view_get_instance_private (view); + + return priv->transform; } MetaCrtc * meta_renderer_view_get_crtc (MetaRendererView *view) { - return view->crtc; + MetaRendererViewPrivate *priv = + meta_renderer_view_get_instance_private (view); + + return priv->crtc; } static void @@ -78,10 +82,13 @@ meta_renderer_view_get_offscreen_transformation_matrix (ClutterStageView *view, graphene_matrix_t *matrix) { MetaRendererView *renderer_view = META_RENDERER_VIEW (view); + MetaRendererViewPrivate *priv = + meta_renderer_view_get_instance_private (renderer_view); graphene_matrix_init_identity (matrix); + meta_monitor_transform_transform_matrix ( - meta_monitor_transform_invert (renderer_view->transform), matrix); + meta_monitor_transform_invert (priv->transform), matrix); } static void @@ -102,9 +109,11 @@ meta_renderer_view_transform_rect_to_onscreen (ClutterStageView *view cairo_rectangle_int_t *dst_rect) { MetaRendererView *renderer_view = META_RENDERER_VIEW (view); + MetaRendererViewPrivate *priv = + meta_renderer_view_get_instance_private (renderer_view); return meta_rectangle_transform (src_rect, - renderer_view->transform, + priv->transform, dst_width, dst_height, dst_rect); @@ -114,10 +123,13 @@ static void meta_renderer_view_set_transform (MetaRendererView *view, MetaMonitorTransform transform) { - if (view->transform == transform) + MetaRendererViewPrivate *priv = + meta_renderer_view_get_instance_private (view); + + if (priv->transform == transform) return; - view->transform = transform; + priv->transform = transform; clutter_stage_view_invalidate_offscreen_blit_pipeline (CLUTTER_STAGE_VIEW (view)); } @@ -128,14 +140,16 @@ meta_renderer_view_get_property (GObject *object, GParamSpec *pspec) { MetaRendererView *view = META_RENDERER_VIEW (object); + MetaRendererViewPrivate *priv = + meta_renderer_view_get_instance_private (view); switch (prop_id) { case PROP_TRANSFORM: - g_value_set_uint (value, view->transform); + g_value_set_uint (value, priv->transform); break; case PROP_CRTC: - g_value_set_object (value, view->crtc); + g_value_set_object (value, priv->crtc); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -150,6 +164,8 @@ meta_renderer_view_set_property (GObject *object, GParamSpec *pspec) { MetaRendererView *view = META_RENDERER_VIEW (object); + MetaRendererViewPrivate *priv = + meta_renderer_view_get_instance_private (view); switch (prop_id) { @@ -157,7 +173,7 @@ meta_renderer_view_set_property (GObject *object, meta_renderer_view_set_transform (view, g_value_get_uint (value)); break; case PROP_CRTC: - view->crtc = g_value_get_object (value); + priv->crtc = g_value_get_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); diff --git a/src/backends/meta-renderer-view.h b/src/backends/meta-renderer-view.h index d0030838d..7c4858af6 100644 --- a/src/backends/meta-renderer-view.h +++ b/src/backends/meta-renderer-view.h @@ -24,9 +24,14 @@ #define META_TYPE_RENDERER_VIEW (meta_renderer_view_get_type ()) META_EXPORT_TEST -G_DECLARE_FINAL_TYPE (MetaRendererView, meta_renderer_view, - META, RENDERER_VIEW, - MetaStageView) +G_DECLARE_DERIVABLE_TYPE (MetaRendererView, meta_renderer_view, + META, RENDERER_VIEW, + MetaStageView) + +struct _MetaRendererViewClass +{ + MetaStageViewClass parent_class; +}; MetaMonitorTransform meta_renderer_view_get_transform (MetaRendererView *view); diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 1278edf00..1a3195166 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -62,6 +62,7 @@ #include "backends/native/meta-render-device-gbm.h" #include "backends/native/meta-render-device-surfaceless.h" #include "backends/native/meta-renderer-native-private.h" +#include "backends/native/meta-renderer-view-native.h" #include "cogl/cogl.h" #include "core/boxes-private.h" @@ -1258,7 +1259,7 @@ meta_renderer_native_create_view (MetaRenderer *renderer, int onscreen_width; int onscreen_height; MetaRectangle view_layout; - MetaRendererView *view; + MetaRendererViewNative *view_native; EGLSurface egl_surface; GError *error = NULL; @@ -1371,26 +1372,27 @@ meta_renderer_native_create_view (MetaRenderer *renderer, meta_rectangle_from_graphene_rect (&crtc_config->layout, META_ROUNDING_STRATEGY_ROUND, &view_layout); - view = g_object_new (META_TYPE_RENDERER_VIEW, - "name", meta_output_get_name (output), - "stage", meta_backend_get_stage (backend), - "layout", &view_layout, - "crtc", crtc, - "scale", scale, - "framebuffer", framebuffer, - "offscreen", offscreen, - "use-shadowfb", use_shadowfb, - "transform", view_transform, - "refresh-rate", crtc_mode_info->refresh_rate, - "vblank-duration-us", crtc_mode_info->vblank_duration_us, - NULL); + view_native = g_object_new (META_TYPE_RENDERER_VIEW_NATIVE, + "name", meta_output_get_name (output), + "stage", meta_backend_get_stage (backend), + "layout", &view_layout, + "crtc", crtc, + "scale", scale, + "framebuffer", framebuffer, + "offscreen", offscreen, + "use-shadowfb", use_shadowfb, + "transform", view_transform, + "refresh-rate", crtc_mode_info->refresh_rate, + "vblank-duration-us", crtc_mode_info->vblank_duration_us, + NULL); if (META_IS_ONSCREEN_NATIVE (framebuffer)) { CoglDisplayEGL *cogl_display_egl; CoglOnscreenEgl *onscreen_egl; - meta_onscreen_native_set_view (COGL_ONSCREEN (framebuffer), view); + meta_onscreen_native_set_view (COGL_ONSCREEN (framebuffer), + META_RENDERER_VIEW (view_native)); /* Ensure we don't point to stale surfaces when creating the offscreen */ cogl_display_egl = cogl_display->winsys; @@ -1402,7 +1404,7 @@ meta_renderer_native_create_view (MetaRenderer *renderer, cogl_display_egl->egl_context); } - return view; + return META_RENDERER_VIEW (view_native); } static void diff --git a/src/backends/native/meta-renderer-view-native.c b/src/backends/native/meta-renderer-view-native.c new file mode 100644 index 000000000..e64a1476a --- /dev/null +++ b/src/backends/native/meta-renderer-view-native.c @@ -0,0 +1,43 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2020-2022 Dor Askayo + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: + * Dor Askayo + */ + +#include "backends/native/meta-renderer-view-native.h" + +struct _MetaRendererViewNative +{ + MetaRendererView parent; +}; + +G_DEFINE_TYPE (MetaRendererViewNative, meta_renderer_view_native, + META_TYPE_RENDERER_VIEW) + +static void +meta_renderer_view_native_class_init (MetaRendererViewNativeClass *klass) +{ +} + +static void +meta_renderer_view_native_init (MetaRendererViewNative *view_native) +{ +} diff --git a/src/backends/native/meta-renderer-view-native.h b/src/backends/native/meta-renderer-view-native.h new file mode 100644 index 000000000..34c37939c --- /dev/null +++ b/src/backends/native/meta-renderer-view-native.h @@ -0,0 +1,34 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2020-2022 Dor Askayo + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: + * Dor Askayo + */ + +#ifndef META_RENDERER_VIEW_NATIVE_H +#define META_RENDERER_VIEW_NATIVE_H + +#include "backends/meta-renderer-view.h" + +#define META_TYPE_RENDERER_VIEW_NATIVE (meta_renderer_view_native_get_type ()) +G_DECLARE_FINAL_TYPE (MetaRendererViewNative, meta_renderer_view_native, + META, RENDERER_VIEW_NATIVE, MetaRendererView) + +#endif /* META_RENDERER_VIEW_NATIVE_H */ diff --git a/src/meson.build b/src/meson.build index 13dd8492f..0bb5c6ce7 100644 --- a/src/meson.build +++ b/src/meson.build @@ -813,6 +813,8 @@ if have_native_backend 'backends/native/meta-renderer-native-private.h', 'backends/native/meta-renderer-native.c', 'backends/native/meta-renderer-native.h', + 'backends/native/meta-renderer-view-native.c', + 'backends/native/meta-renderer-view-native.h', 'backends/native/meta-seat-impl.c', 'backends/native/meta-seat-impl.h', 'backends/native/meta-seat-native.c',